EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Intermittent "connection lost" error using TElHTTPSClient

Also by EldoS: Rethync
The cross-platform framework that simplifies synchronizing data between mobile and desktop applications and servers and cloud storages
#14512
Posted: 09/20/2010 14:26:30
by Sean Ferris (Basic support level)
Joined: 09/20/2010
Posts: 4

Hi all,


Using SBB 7.2.169 with Delphi 7. Using TElHTTPSClient to connect to a host and experiencing intermittent "connection lost" errors.

Determined that the error is happening during the TLS handshake. Sometimes, after SBB sends the ClientKeyExchange message, the remote server simply closes the connection. Found that this only happens when the length of the encrypted PMS (using RSA) is 255 bytes. Normally this is 256 bytes (for 2048 bit key), but I see that SBUtils.LIntToPointerTrunc causes this data to be truncated to 255 bytes if the first byte is 0.

I don't know much about the nitty-gritty of this encryption, but this truncation behaviour sure looks to be by-design, giving me suspicion that there is a problem with the host. Is this a known problem with certain servers? Has anyone else experienced a similar problem (and had any luck fixing/working around it)?


Thanks,
#14513
Posted: 09/20/2010 14:40:50
by Ken Ivanov (EldoS Corp.)

Thank you for contacting us.

Could you please specify the name of the software that runs on a server side?
#14515
Posted: 09/20/2010 16:49:56
by Sean Ferris (Basic support level)
Joined: 09/20/2010
Posts: 4

Server is running IIS 6.0 on Windows Server 2003.
#14520
Posted: 09/21/2010 05:36:46
by Ken Ivanov (EldoS Corp.)

Thank you. We will try to reproduce the issue here in our environment.
#14546
Posted: 09/22/2010 21:56:00
by Ken Ivanov (EldoS Corp.)

It appears that you are pretty right. Both IIS6 and IIS7 (unlike all the other implementations we've done the tests with) terminate SSL/TLS negotiation if the client key exchange value is not aligned to the length of the public key from server's certificate. TLS RFC does not give any hint on how exactly the encrypted value should be encoded, however, a "good practice" for writers is to encode such values in the shortest ("optimal") way, and for readers to accept both "optimal" and "non-optimal" encodings.

I assume we will prepare a kind of workaround for this IIS feature in the future SecureBlackbox build update.
#14559
Posted: 09/23/2010 11:45:58
by Sean Ferris (Basic support level)
Joined: 09/20/2010
Posts: 4

Awesome, thanks so much for investigating! I look forward to a new build!

Until then, I just tweaked SBRSA.Encrypt to prevent the truncation (calling LIntToPointer instead of LIntToPointerTrunc) and this seems to resolve the problem.
#14560
Posted: 09/23/2010 12:01:48
by Ken Ivanov (EldoS Corp.)

Quote
Until then, I just tweaked SBRSA.Encrypt to prevent the truncation (calling LIntToPointer instead of LIntToPointerTrunc) and this seems to resolve the problem.

It just seems. This tweak may lead to various side issues in other components. It would be more reasonable to modify the code of TElSecureClient.TLS1SendClientKeyExchange() method in the following way:
Code
      if (FTLS1CurrentCipherSuite.KeyExchangeAlgorithm = kaRSA) then
      begin
        Crypto := TElRSAPublicKeyCrypto.Create(nil);
        try
          Crypto.KeyMaterial := FRSAParams;
          Crypto.CryptoType := rsapktPKCS1;
          EncPMSLen := 0;
          Crypto.Encrypt(@FTLS1PreMasterSecret[0], 48, nil, EncPMSLen);
          SetLength(EncPMS, EncPMSLen);
          Crypto.Encrypt(@FTLS1PreMasterSecret[0], 48, @EncPMS[0], EncPMSLen);
          // Add the following checkup:
          ModLen := Length(FRSAParams.PublicModulus);
          if EncPMSLen < ModLen then
          begin
            SetLength(EncPMS, ModLen);
            Move(EncPMS[0], EncPMS[ModLen - EncPMSLen], EncPMSLen);
            FillChar(EncPMS[0], ModLen - EncPMSLen, 0);
            EncPMSLen := ModLen;
          end;
        end;
      finally
        FreeAndNil(Crypto);
      end;
    end


The same modifications should be introduced to TElSecureClient.SSL3SendClientKeyExchange() method as well.
#14561
Posted: 09/23/2010 12:37:07
by Sean Ferris (Basic support level)
Joined: 09/20/2010
Posts: 4

Applied the suggested changes instead, seems to work just as well. Thanks again!
Also by EldoS: CallbackRegistry
A component to monitor and control Windows registry access and create virtual registry keys.

Reply

Statistics

Topic viewed 1875 times

Number of guests: 5, registered members: 0, in total hidden: 0




|

Back to top

As of July 15, 2016 EldoS Corporation will operate as a division of /n software inc. For more information, please read the announcement.

Got it!