This repository was archived by the owner on Jan 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Populate DataHash key size in SslConnectionInfo #4169
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev
Previous commit
Fixed PR Comments and Synced code
- Loading branch information
commit 02e3992cf5f11d7fc50debe4a16c4cb9527461e8
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -364,57 +364,7 @@ enum class SSL_DataHashAlgorithm : int64_t | |
| #endif | ||
| }; | ||
|
|
||
| class SSL_DataHashSize | ||
| { | ||
| public: | ||
| static const int32_t MD5_HashKeySize = 128; | ||
| static const int32_t SHA1_HashKeySize = 160; | ||
| static const int32_t SHA256_HashKeySize = 256; | ||
| static const int32_t SHA384_HashKeySize = 384; | ||
| static const int32_t GOST_HashKeySize = 256; | ||
| }; | ||
|
|
||
| static HashAlgorithmType MapHashAlgorithmType(const SSL_CIPHER* cipher) | ||
| { | ||
| unsigned long mac; | ||
| #if HAVE_SSL_CIPHER_SPLIT_ALGORITHMS | ||
| mac = cipher->algorithm_mac; | ||
| #else | ||
| const unsigned long SSL_MAC_MASK = 0x00c00000L; | ||
| mac = cipher->algorithms & SSL_MAC_MASK; | ||
| #endif | ||
|
|
||
| SSL_DataHashAlgorithm sslMac = static_cast<SSL_DataHashAlgorithm>(mac); | ||
| switch (sslMac) | ||
| { | ||
| case SSL_DataHashAlgorithm::SSL_MD5: | ||
| return HashAlgorithmType::Md5; | ||
|
|
||
| case SSL_DataHashAlgorithm::SSL_SHA1: | ||
| return HashAlgorithmType::Sha1; | ||
|
|
||
| #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; | ||
| #endif | ||
| } | ||
|
|
||
| return HashAlgorithmType::None; | ||
| } | ||
|
|
||
| static int32_t GetHashKeySize(const SSL_CIPHER* cipher) | ||
| static void GetHashAlgorithmTypeAndSize(const SSL_CIPHER* cipher, HashAlgorithmType* dataHashAlg, DataHashSize* hashKeySize) | ||
| { | ||
| unsigned long mac; | ||
| #if HAVE_SSL_CIPHER_SPLIT_ALGORITHMS | ||
|
|
@@ -428,35 +378,58 @@ static int32_t GetHashKeySize(const SSL_CIPHER* cipher) | |
| switch (sslMac) | ||
| { | ||
| case SSL_DataHashAlgorithm::SSL_MD5: | ||
| return SSL_DataHashSize::MD5_HashKeySize; | ||
| *dataHashAlg = HashAlgorithmType::Md5; | ||
| *hashKeySize = DataHashSize::MD5_HashKeySize; | ||
| return; | ||
|
|
||
| case SSL_DataHashAlgorithm::SSL_SHA1: | ||
| return SSL_DataHashSize::SHA1_HashKeySize; | ||
| *dataHashAlg = HashAlgorithmType::Sha1; | ||
| *hashKeySize = DataHashSize::SHA1_HashKeySize; | ||
| return; | ||
|
|
||
| #if HAVE_SSL_CIPHER_SPLIT_ALGORITHMS | ||
| case SSL_DataHashAlgorithm::SSL_GOST94: | ||
| return SSL_DataHashSize::GOST_HashKeySize; | ||
| *dataHashAlg = HashAlgorithmType::SSL_GOST94; | ||
| *hashKeySize = DataHashSize::GOST_HashKeySize; | ||
| return; | ||
|
|
||
| case SSL_DataHashAlgorithm::SSL_GOST89MAC: | ||
| return SSL_DataHashSize::GOST_HashKeySize; | ||
| *dataHashAlg = HashAlgorithmType::SSL_GOST89; | ||
| *hashKeySize = DataHashSize::GOST_HashKeySize; | ||
| return; | ||
|
|
||
| case SSL_DataHashAlgorithm::SSL_SHA256: | ||
| return SSL_DataHashSize::SHA256_HashKeySize; | ||
| *dataHashAlg = HashAlgorithmType::SSL_SHA256; | ||
| *hashKeySize = DataHashSize::SHA256_HashKeySize; | ||
| return; | ||
|
|
||
| case SSL_DataHashAlgorithm::SSL_SHA384: | ||
| return SSL_DataHashSize::SHA384_HashKeySize; | ||
| *dataHashAlg = HashAlgorithmType::SSL_SHA384; | ||
| *hashKeySize = DataHashSize::SHA384_HashKeySize; | ||
| return; | ||
|
|
||
| case SSL_DataHashAlgorithm::SSL_AEAD: | ||
| return 0; | ||
| *dataHashAlg = HashAlgorithmType::SSL_AEAD; | ||
| *hashKeySize = DataHashSize::Default; | ||
| return; | ||
| #endif | ||
| } | ||
|
|
||
| *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, HashAlgorithmType* dataHashAlg, int32_t* dataKeySize, int32_t* hashKeySize) | ||
| extern "C" int32_t GetSslConnectionInfo(SSL* ssl, | ||
| CipherAlgorithmType* dataCipherAlg, | ||
| ExchangeAlgorithmType* keyExchangeAlg, | ||
| HashAlgorithmType* dataHashAlg, | ||
| int32_t* dataKeySize, | ||
| DataHashSize* hashKeySize) | ||
| { | ||
| const SSL_CIPHER* cipher; | ||
|
|
||
| if (!ssl || !dataCipherAlg || !keyExchangeAlg || !dataHashAlg || !dataKeySize) | ||
| if (!ssl || !dataCipherAlg || !keyExchangeAlg || !dataHashAlg || !dataKeySize || !hashKeySize) | ||
| { | ||
| goto err; | ||
| } | ||
|
|
@@ -469,9 +442,8 @@ extern "C" int32_t GetSslConnectionInfo(SSL* ssl, CipherAlgorithmType* dataCiphe | |
|
|
||
| *dataCipherAlg = MapCipherAlgorithmType(cipher); | ||
| *keyExchangeAlg = MapExchangeAlgorithmType(cipher); | ||
| *dataHashAlg = MapHashAlgorithmType(cipher); | ||
| *dataKeySize = cipher->alg_bits; | ||
| *hashKeySize = GetHashKeySize(cipher); | ||
| GetHashAlgorithmTypeAndSize(cipher, dataHashAlg, hashKeySize); | ||
|
|
||
| return 1; | ||
|
|
||
|
|
@@ -486,6 +458,8 @@ extern "C" int32_t GetSslConnectionInfo(SSL* ssl, CipherAlgorithmType* dataCiphe | |
| *dataHashAlg = HashAlgorithmType::None; | ||
| if (dataKeySize) | ||
| *dataKeySize = 0; | ||
| if (hashKeySize) | ||
| *hashKeySize = DataHashSize::Default; | ||
|
|
||
| return 0; | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.