|
@@ -1042,7 +1042,7 @@ class CRemoteBase: public CInterface
|
|
|
ssock.setown(createSecureSocket(socket.getClear(), ClientSocket));
|
|
|
int status = ssock->secure_connect();
|
|
|
if (status < 0)
|
|
|
- throw MakeStringException(-1, "Failure to establish secure connection");
|
|
|
+ throw createDafsException(DAFSERR_connection_failed, "Failure to establish secure connection");
|
|
|
socket.setown(ssock.getLink());
|
|
|
}
|
|
|
catch (IException *e)
|
|
@@ -2701,13 +2701,26 @@ ISocket *checkSocketSecure(ISocket *socket)
|
|
|
|
|
|
if ( (pport == securitySettings.daFileSrvSSLPort) && (!socket->isSecure()) )
|
|
|
{
|
|
|
- Owned<ISecureSocket> ssock;
|
|
|
#ifdef _USE_OPENSSL
|
|
|
- ssock.setown(createSecureSocket(LINK(socket), ClientSocket));
|
|
|
- int status = ssock->secure_connect();
|
|
|
- if (status < 0)
|
|
|
- throw createDafsException(DAFSERR_connection_failed,"Failure to establish secure connection");
|
|
|
- return ssock.getClear();
|
|
|
+ Owned<ISecureSocket> ssock;
|
|
|
+ try
|
|
|
+ {
|
|
|
+ ssock.setown(createSecureSocket(LINK(socket), ClientSocket));
|
|
|
+ int status = ssock->secure_connect();
|
|
|
+ if (status < 0)
|
|
|
+ throw createDafsException(DAFSERR_connection_failed, "Failure to establish secure connection");
|
|
|
+ return ssock.getClear();
|
|
|
+ }
|
|
|
+ catch (IException *e)
|
|
|
+ {
|
|
|
+ cleanupSocket(ssock);
|
|
|
+ ssock.clear();
|
|
|
+ cleanupSocket(socket);
|
|
|
+ StringBuffer eMsg;
|
|
|
+ e->errorMessage(eMsg);
|
|
|
+ e->Release();
|
|
|
+ throw createDafsException(DAFSERR_connection_failed, eMsg.str());
|
|
|
+ }
|
|
|
#else
|
|
|
throw createDafsException(DAFSERR_connection_failed,"Failure to establish secure connection: OpenSSL disabled in build");
|
|
|
#endif
|
|
@@ -2723,42 +2736,74 @@ ISocket *connectDafs(SocketEndpoint &ep, unsigned timeoutms)
|
|
|
if ( (securitySettings.connectMethod == SSLNone) || (securitySettings.connectMethod == SSLOnly) )
|
|
|
{
|
|
|
socket.setown(ISocket::connect_timeout(ep, timeoutms));
|
|
|
- return socket.getClear();
|
|
|
+ return checkSocketSecure(socket);
|
|
|
}
|
|
|
|
|
|
+ // SSLFirst or UnsecureFirst ...
|
|
|
+
|
|
|
unsigned newtimeout = timeoutms;
|
|
|
if (newtimeout > 5000)
|
|
|
newtimeout = 5000;
|
|
|
|
|
|
- bool tryAgain = false;
|
|
|
- try
|
|
|
+ int conAttempts = 2;
|
|
|
+ while (conAttempts > 0)
|
|
|
{
|
|
|
- socket.setown(ISocket::connect_timeout(ep, newtimeout));
|
|
|
- }
|
|
|
- catch (IJSOCK_Exception *e)
|
|
|
- {
|
|
|
- if (e->errorCode() == JSOCKERR_connection_failed)
|
|
|
+ conAttempts--;
|
|
|
+ bool connected = false;
|
|
|
+ try
|
|
|
+ {
|
|
|
+ socket.setown(ISocket::connect_timeout(ep, newtimeout));
|
|
|
+ connected = true;
|
|
|
+ newtimeout = timeoutms;
|
|
|
+ }
|
|
|
+ catch (IJSOCK_Exception *e)
|
|
|
+ {
|
|
|
+ if (e->errorCode() == JSOCKERR_connection_failed)
|
|
|
+ {
|
|
|
+ e->Release();
|
|
|
+ if (ep.port == securitySettings.daFileSrvSSLPort)
|
|
|
+ ep.port = securitySettings.daFileSrvPort;
|
|
|
+ else
|
|
|
+ ep.port = securitySettings.daFileSrvSSLPort;
|
|
|
+ if (!conAttempts)
|
|
|
+ throw;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ throw;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (connected)
|
|
|
{
|
|
|
- unsigned prevPort = ep.port;
|
|
|
- if (prevPort == securitySettings.daFileSrvSSLPort)
|
|
|
- ep.port = securitySettings.daFileSrvPort;
|
|
|
+ if (ep.port == securitySettings.daFileSrvSSLPort)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ return checkSocketSecure(socket);
|
|
|
+ }
|
|
|
+ catch (IDAFS_Exception *e)
|
|
|
+ {
|
|
|
+ connected = false;
|
|
|
+ if (e->errorCode() == DAFSERR_connection_failed)
|
|
|
+ {
|
|
|
+ // worth logging to help identify any ssl config issues ...
|
|
|
+ StringBuffer errmsg;
|
|
|
+ e->errorMessage(errmsg);
|
|
|
+ WARNLOG("%s", errmsg.str());
|
|
|
+ e->Release();
|
|
|
+ ep.port = securitySettings.daFileSrvPort;
|
|
|
+ if (!conAttempts)
|
|
|
+ throw;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ throw;
|
|
|
+ }
|
|
|
+ }
|
|
|
else
|
|
|
- ep.port = securitySettings.daFileSrvSSLPort;
|
|
|
- WARNLOG("Connect failed on port %d, retrying on port %d", prevPort, ep.port);
|
|
|
- tryAgain = true;
|
|
|
- e->Release();
|
|
|
+ return socket.getClear();
|
|
|
}
|
|
|
- else
|
|
|
- throw e;
|
|
|
}
|
|
|
|
|
|
- if (tryAgain)
|
|
|
- socket.setown(ISocket::connect_timeout(ep, timeoutms));
|
|
|
-
|
|
|
- if (socket)
|
|
|
- return checkSocketSecure(socket);
|
|
|
- else
|
|
|
- return nullptr;
|
|
|
+ throw createDafsException(DAFSERR_connection_failed, "Failed to establish connection with DaFileSrv");
|
|
|
}
|
|
|
|
|
|
unsigned getRemoteVersion(CRemoteFileIO &remoteFileIO, StringBuffer &ver)
|