runtime icon indicating copy to clipboard operation
runtime copied to clipboard

System.Net.Security related Pending PR coments/TODO

Open rajansingh10 opened this issue 11 years ago • 16 comments

  1. Interop.OpenSsl TODO - See if SSL_CTX_Set_quite_shutdown can be used

rajansingh10 avatar Sep 22 '15 06:09 rajansingh10

@rajansingh10, seems like a copy-paste error. There should be more unaddressed comments here

vijaykota avatar Sep 25 '15 09:09 vijaykota

  • [x] Interop.OpenSsl TODO - See if SSL_CTX_Set_quite_shutdown can be used
  • [ ] Trailer size requirement changes based on Protocol. Currently it's hard coded. (Interop.libssl_types.cs)
  • [x] SSL3_RT_MAX_COMPRESSED_LENGTH will depend on whether compression is allowed or not. (Interop.libssl_types.cs)
  • [x] AllocateSslContext - Set remote certificate options (Interop.OpenSsl.cs)
  • [x] Disconnect - check the SSL_shutdown error (Interop.OpenSsl.cs)
  • [x] BioRead/BioWrite - Should bio retry, investigate & fix? (Interop.OpenSsl.cs)
  • [x] SslCredKey - used a prime number here as it's a XOR. Figure out appropriate value. (_SslSessionsCache.cs)
  • [x] GetRemoteCertificate - Fetch remoteCertificateStore, if applicable for unix. (CertModule.cs)
  • [x] GetRequestCertificateAuthorities - populate issuers. (CertModule.cs)
  • [x] EnsureStoreOpened - Implement the method. (CertModule.cs)
  • [ ] SafeFreeContextBufferChannelBinding - Implement the class (SecuritySafeHandles.cs)
  • [x] SslConnectionInfo - map key sizes (SslConnectionInfo.cs)
  • [x] MapProtocol - Figure out correct value for default - (SslConnectionInfo.cs)
  • [x] MapCipherAlgorithmType/MapExchangeAlgorithmType/MapHashAlgorithmType - Handle other values - (SslConnectionInfo.cs)
  • [x] GetException - Implement the method. (SSPISecureChannelType.cs)
  • [x] AcquireCredentialsHandle - retVal is not getting released now, need to be fixed. (SSPISecureChannelType.cs)
  • [ ] QueryContextChannelBinding - Implement the method. (SSPISecureChannelType.cs)
  • [x] QueryContextIssuerList - Implement the method. (SSPISecureChannelType.cs)
  • [x] EncryptionPolicy stored in SafeFreeCredentials is unused
  • [x] Add error messages to *.resx files for localization.
  • [x] Use SslContext as a class rather than struct & use a GCHandle rather than allocating native memory every time. use safehandles inplace of intptr wherever applicable.
  • [x] Evaluate if various SSL methods in GetSslMethod of Openssl.cs, can be cached one time & use always.

rajansingh10 avatar Sep 28 '15 04:09 rajansingh10

@rajansingh10 Instead of adding new posts, please move all items to the first one by editing it (the pencil icon near the top right). Also, it's nice if you use the format to track what's already done:

  • [ ] Item1
  • [X] Item2
  • [ ] Item3

CIPop avatar Sep 28 '15 20:09 CIPop

updated the partial issues fixed..

shrutigarg avatar Oct 16 '15 19:10 shrutigarg

Using https://github.com/dotnet/corefx/issues/3954 to track the remaining

vijaykota avatar Oct 19 '15 08:10 vijaykota

@vijaykota, this issue was closed, but there are still TODO references to this issue in the code, and for things that don't appear to be covered by 3954.

stephentoub avatar Oct 21 '15 14:10 stephentoub

I've opened dotnet/corefx#4031 for SSL error handling in general. Along with the TODO check this error comment, I found another problem with the error handling -

There are 2 sets of error codes

  1. Those defined in err.h
  2. Those defined in ssl.h These two sets overlap, for example ERR_R_SYS_LIB = 2 and SSL_ERROR_WANT_READ = 2.

In Interop.OpenSsl.GetSslError, if the SslErrorCode returned from SSL_get_error (defined in ssl.h) is SSL_ERROR_SYSCALL, it calls ERR_get_error (defined in err.h), and casts that result to an SslErrorCode, which is incorrect since it will return a separate set of error codes.

But there are still other //TODO (Issue dotnet/corefx#3362) comments in the code that aren't strictly error handling.

eerhardt avatar Oct 21 '15 15:10 eerhardt

there are still TODO references to this issue in the code

There is no active coding/investigate work pending for these. So the comments need to be removed from the code. Created https://github.com/dotnet/corefx/issues/4128 to track this.

cc: @shrutigarg

vijaykota avatar Oct 26 '15 05:10 vijaykota

Even these? https://github.com/dotnet/corefx/blob/master/src/Common/src/Interop/Unix/libssl/SecuritySafeHandles.cs#L280-L283 https://github.com/dotnet/corefx/blob/master/src/System.Net.Security/src/System/Net/_SslSessionsCache.cs#L56 https://github.com/dotnet/corefx/blob/master/src/Native/System.Security.Cryptography.Native/pal_ssl.cpp#L561-L569

internal abstract class SafeFreeContextBufferChannelBinding : ChannelBinding
{
    // TODO (Issue dotnet/corefx#3362) To be implemented
}
    _HashCode ^= serverMode ? 5 : 7; //TODO (Issue dotnet/corefx#3362) used a prime number here as it's a XOR. Figure out appropriate value.
    if (trailer)
    {
        // TODO (Issue dotnet/corefx#3362) : Trailer size requirement is changing based on protocol
        //       SSL3/TLS1.0 - 68, TLS1.1 - 37 and TLS1.2 - 24
        //       Current usage is only to compute max input buffer size for
        //       encryption and so setting to the max

        *trailer = 68;
    }

eerhardt avatar Oct 26 '15 14:10 eerhardt

@bartonjs PTAL at the second issue (prime number in XOR).

CIPop avatar Oct 26 '15 17:10 CIPop

+1 on @eerhardt's comment: the issues should be closed after all code references have been resolved.

CIPop avatar Oct 26 '15 17:10 CIPop

@CIPop I'm not sure what you're asking me to look at?

bartonjs avatar Oct 26 '15 18:10 bartonjs

@CIPop I'm not sure what you're asking me to look at?

I think it is this: https://github.com/dotnet/corefx/blob/master/src/System.Net.Security/src/System/Net/_SslSessionsCache.cs#L56

    _HashCode ^= serverMode ? 5 : 7; //TODO (Issue dotnet/corefx#3362) used a prime number here as it's a XOR. Figure out appropriate value.

Is that code correct?

eerhardt avatar Oct 26 '15 19:10 eerhardt

Thanks @eerhardt. @bartonjs: That's the code that I'm referring to. If the code is correct as it is, then we can remove the comment.

CIPop avatar Oct 26 '15 20:10 CIPop

Even these?

Yes all of those as well except the ChannelBinding one. @rajansingh10 will shortly send a PR for removing that as part of CBT implementation. As mentioned, we are using 4128 for removing all the other outdated comments.

vijaykota avatar Oct 27 '15 05:10 vijaykota

@CIPop It's not necessarily my area of expertise, but I can offer advice.

  • The hash code starts off using the first 4 bytes of the thumbprint. Since that has a full-spectrum range and is itself a very chaotic input, the first couple of lines are good.
  • It then XORs in allowedProtocols, which is a value that is (for the most part) 0x0000 to 0x0800, that interacts only with thumbprint[1] and thumbprint[0].
    • At this point nothing's really bad, since it isn't undoing itself.
  • It then XORs in encryptionPolicy, which is 0, 1, or 2. This definitely only interacts with thumbprint[0].
    • Certain combinations of encryptionPolicy and allowedProtocols are indistinguishable, meaning they'll guaranteed share a bucket.
  • Then it XORs in either 5 or 7. This, again, only interacts with thumbprint[0].
    • Again, certain combinations of allowedProtocols and isServer are indistinguishable from each other, meaning they'll always share buckets (for the same cert).

If you want really good spread you'd steal some bytes out of a hash of thumbprint.Concat(allowedProtocols).Concat(encryptionPolicy).Concat(isServer)). But if you're really only ever having one set of options per certificate you've pretty much already done that, so it's possibly not worth changing.

bartonjs avatar Oct 27 '15 15:10 bartonjs