-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Populate DataHash key size in SslConnectionInfo #4169
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -364,7 +364,7 @@ enum class SSL_DataHashAlgorithm : int64_t | |
| #endif | ||
| }; | ||
|
|
||
| static HashAlgorithmType MapHashAlgorithmType(const SSL_CIPHER* cipher) | ||
| static void GetHashAlgorithmTypeAndSize(const SSL_CIPHER* cipher, HashAlgorithmType* dataHashAlg, DataHashSize* hashKeySize) | ||
| { | ||
| unsigned long mac; | ||
| #if HAVE_SSL_CIPHER_SPLIT_ALGORITHMS | ||
|
|
@@ -377,42 +377,59 @@ static HashAlgorithmType MapHashAlgorithmType(const SSL_CIPHER* cipher) | |
| SSL_DataHashAlgorithm sslMac = static_cast<SSL_DataHashAlgorithm>(mac); | ||
| switch (sslMac) | ||
| { | ||
| case SSL_DataHashAlgorithm::SSL_MD5: | ||
| return HashAlgorithmType::Md5; | ||
| case SSL_DataHashAlgorithm::SSL_MD5: | ||
| *dataHashAlg = HashAlgorithmType::Md5; | ||
| *hashKeySize = DataHashSize::MD5_HashKeySize; | ||
| return; | ||
|
|
||
| case SSL_DataHashAlgorithm::SSL_SHA1: | ||
| return HashAlgorithmType::Sha1; | ||
| case SSL_DataHashAlgorithm::SSL_SHA1: | ||
| *dataHashAlg = HashAlgorithmType::Sha1; | ||
| *hashKeySize = DataHashSize::SHA1_HashKeySize; | ||
| return; | ||
|
|
||
| #if HAVE_SSL_CIPHER_SPLIT_ALGORITHMS | ||
| case SSL_DataHashAlgorithm::SSL_GOST94: | ||
| return HashAlgorithmType::SSL_GOST94; | ||
|
|
||
| case SSL_DataHashAlgorithm::SSL_GOST89MAC: | ||
| return HashAlgorithmType::SSL_GOST89; | ||
|
|
||
| case SSL_DataHashAlgorithm::SSL_SHA256: | ||
| return HashAlgorithmType::SSL_SHA256; | ||
|
|
||
| case SSL_DataHashAlgorithm::SSL_SHA384: | ||
| return HashAlgorithmType::SSL_SHA384; | ||
|
|
||
| case SSL_DataHashAlgorithm::SSL_AEAD: | ||
| return HashAlgorithmType::SSL_AEAD; | ||
| case SSL_DataHashAlgorithm::SSL_GOST94: | ||
| *dataHashAlg = HashAlgorithmType::SSL_GOST94; | ||
| *hashKeySize = DataHashSize::GOST_HashKeySize; | ||
| return; | ||
|
|
||
| case SSL_DataHashAlgorithm::SSL_GOST89MAC: | ||
| *dataHashAlg = HashAlgorithmType::SSL_GOST89; | ||
| *hashKeySize = DataHashSize::GOST_HashKeySize; | ||
| return; | ||
|
|
||
| case SSL_DataHashAlgorithm::SSL_SHA256: | ||
| *dataHashAlg = HashAlgorithmType::SSL_SHA256; | ||
| *hashKeySize = DataHashSize::SHA256_HashKeySize; | ||
| return; | ||
|
|
||
| case SSL_DataHashAlgorithm::SSL_SHA384: | ||
| *dataHashAlg = HashAlgorithmType::SSL_SHA384; | ||
| *hashKeySize = DataHashSize::SHA384_HashKeySize; | ||
| return; | ||
|
|
||
| case SSL_DataHashAlgorithm::SSL_AEAD: | ||
| *dataHashAlg = HashAlgorithmType::SSL_AEAD; | ||
| *hashKeySize = DataHashSize::Default; | ||
| return; | ||
| #endif | ||
| } | ||
|
|
||
| return HashAlgorithmType::None; | ||
| *dataHashAlg = HashAlgorithmType::None; | ||
| *hashKeySize = DataHashSize::Default; | ||
| return; | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about the default case where sslMac doesn't match any of these?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will add at end to return 0 for rest of the cases. |
||
|
|
||
| extern "C" int32_t GetSslConnectionInfo(SSL* ssl, | ||
| CipherAlgorithmType* dataCipherAlg, | ||
| ExchangeAlgorithmType* keyExchangeAlg, | ||
| CipherAlgorithmType* dataCipherAlg, | ||
| ExchangeAlgorithmType* keyExchangeAlg, | ||
| HashAlgorithmType* dataHashAlg, | ||
| int32_t* dataKeySize) | ||
| int32_t* dataKeySize, | ||
| DataHashSize* hashKeySize) | ||
| { | ||
| const SSL_CIPHER* cipher; | ||
|
|
||
| if (!ssl || !dataCipherAlg || !keyExchangeAlg || !dataHashAlg || !dataKeySize) | ||
| if (!ssl || !dataCipherAlg || !keyExchangeAlg || !dataHashAlg || !dataKeySize || !hashKeySize) | ||
| { | ||
| goto err; | ||
| } | ||
|
|
@@ -425,8 +442,8 @@ extern "C" int32_t GetSslConnectionInfo(SSL* ssl, | |
|
|
||
| *dataCipherAlg = MapCipherAlgorithmType(cipher); | ||
| *keyExchangeAlg = MapExchangeAlgorithmType(cipher); | ||
| *dataHashAlg = MapHashAlgorithmType(cipher); | ||
| *dataKeySize = cipher->alg_bits; | ||
| GetHashAlgorithmTypeAndSize(cipher, dataHashAlg, hashKeySize); | ||
|
|
||
| return 1; | ||
|
|
||
|
|
@@ -441,6 +458,8 @@ extern "C" int32_t GetSslConnectionInfo(SSL* ssl, | |
| *dataHashAlg = HashAlgorithmType::None; | ||
| if (dataKeySize) | ||
| *dataKeySize = 0; | ||
| if (hashKeySize) | ||
| *hashKeySize = DataHashSize::Default; | ||
|
|
||
| return 0; | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -66,7 +66,7 @@ public static SecurityStatusPal DecryptMessage(SafeDeleteContext securityContext | |
|
|
||
| public static SafeFreeContextBufferChannelBinding QueryContextChannelBinding(SafeDeleteContext phContext, ChannelBindingKind attribute) | ||
| { | ||
| // TODO (Issue #3362) To be implemented | ||
| // TODO (Issue #3954) To be implemented | ||
| throw NotImplemented.ByDesignWithMessage(SR.net_MethodNotImplementedException); | ||
| } | ||
|
|
||
|
|
@@ -75,19 +75,9 @@ public static void QueryContextStreamSizes(SafeDeleteContext securityContext, ou | |
| streamSizes = new StreamSizes(); | ||
| } | ||
|
|
||
| public static int QueryContextConnectionInfo(SafeDeleteContext securityContext, out SslConnectionInfo connectionInfo) | ||
| public static void QueryContextConnectionInfo(SafeDeleteContext securityContext, out SslConnectionInfo connectionInfo) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we're no longer returning an int, any reason not to change the out parameter to be the return value?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a PAL function, so the signature needs to match Windows. (Windows currently has a void return). If we did this we would need to update the Windows PAL function and the call site. (Not saying that we can't do that though...)
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's why I like PAL interfaces vs PAL static implicit call conventions, personally. |
||
| { | ||
| connectionInfo = null; | ||
| try | ||
| { | ||
| connectionInfo = new SslConnectionInfo(securityContext.SslContext); | ||
|
|
||
| return 0; | ||
| } | ||
| catch | ||
| { | ||
| return -1; | ||
| } | ||
| connectionInfo = new SslConnectionInfo(securityContext.SslContext); | ||
| } | ||
|
|
||
| private static SecurityStatusPal HandshakeInternal(SafeFreeCredentials credential, ref SafeDeleteContext context, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we update the
// TODO (Issue #3362) map key sizescomment below?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems openssl doesnot provide a way to return a exchangekey size.. in dtls1_send_server_key_exchange and similar function for other sslProtocols , it internally calculates the key exchange size and generate key.. It is not a constant either that we can hardcode and return.
That's why its still pending .. not sure how to fix this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this would be good to note in the code. Also opening an issue for this and using that number in the TODO comment is a good idea since #3362 is closed and #4128 is going to come through and just delete these TODO comments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems this todo we cannot proceed in , we have already done the investigations around. So just making a note for this. No point of opening another TODO.
Will delete this TODO comment.