-
Notifications
You must be signed in to change notification settings - Fork 497
Use a full-length key even with null ciphers #559
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
5 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -776,6 +776,26 @@ static inline int base_key_length(const srtp_cipher_type_t *cipher, | |
| } | ||
| } | ||
|
|
||
| /* Get the key length that the application should supply for the given cipher */ | ||
| static inline int full_key_length(const srtp_cipher_type_t *cipher) | ||
| { | ||
| switch (cipher->id) { | ||
| case SRTP_NULL_CIPHER: | ||
| case SRTP_AES_ICM_128: | ||
| return SRTP_AES_ICM_128_KEY_LEN_WSALT; | ||
| case SRTP_AES_ICM_192: | ||
| return SRTP_AES_ICM_192_KEY_LEN_WSALT; | ||
| case SRTP_AES_ICM_256: | ||
| return SRTP_AES_ICM_256_KEY_LEN_WSALT; | ||
| case SRTP_AES_GCM_128: | ||
| return SRTP_AES_GCM_128_KEY_LEN_WSALT; | ||
| case SRTP_AES_GCM_256: | ||
| return SRTP_AES_ICM_256_KEY_LEN_WSALT; | ||
| default: | ||
| return 0; | ||
| } | ||
| } | ||
|
|
||
| unsigned int srtp_validate_policy_master_keys(const srtp_policy_t *policy) | ||
| { | ||
| unsigned long i = 0; | ||
|
|
@@ -870,6 +890,7 @@ srtp_err_status_t srtp_stream_init_keys(srtp_stream_ctx_t *srtp, | |
| srtp_err_status_t stat; | ||
| srtp_kdf_t kdf; | ||
| uint8_t tmp_key[MAX_SRTP_KEY_LEN]; | ||
| int input_keylen, input_keylen_rtcp; | ||
| int kdf_keylen = 30, rtp_keylen, rtcp_keylen; | ||
| int rtp_base_key_len, rtp_salt_len; | ||
| int rtcp_base_key_len, rtcp_salt_len; | ||
|
|
@@ -906,6 +927,12 @@ srtp_err_status_t srtp_stream_init_keys(srtp_stream_ctx_t *srtp, | |
|
|
||
| session_keys->mki_size = master_key->mki_size; | ||
|
|
||
| input_keylen = full_key_length(session_keys->rtp_cipher->type); | ||
| input_keylen_rtcp = full_key_length(session_keys->rtcp_cipher->type); | ||
| if (input_keylen_rtcp > input_keylen) { | ||
| input_keylen = input_keylen_rtcp; | ||
| } | ||
|
|
||
| rtp_keylen = srtp_cipher_get_key_length(session_keys->rtp_cipher); | ||
| rtcp_keylen = srtp_cipher_get_key_length(session_keys->rtcp_cipher); | ||
| rtp_base_key_len = | ||
|
|
@@ -920,6 +947,11 @@ srtp_err_status_t srtp_stream_init_keys(srtp_stream_ctx_t *srtp, | |
| kdf_keylen = 46; /* AES-CTR mode is always used for KDF */ | ||
| } | ||
|
|
||
| if (input_keylen > kdf_keylen) { | ||
| kdf_keylen = 46; /* AES-CTR mode is always used for KDF */ | ||
| } | ||
|
|
||
| debug_print(mod_srtp, "input key len;: %d", input_keylen); | ||
|
||
| debug_print(mod_srtp, "srtp key len: %d", rtp_keylen); | ||
| debug_print(mod_srtp, "srtcp key len: %d", rtcp_keylen); | ||
| debug_print(mod_srtp, "base key len: %d", rtp_base_key_len); | ||
|
|
@@ -932,7 +964,7 @@ srtp_err_status_t srtp_stream_init_keys(srtp_stream_ctx_t *srtp, | |
| * the legacy CTR mode KDF, which uses a 112 bit master SALT. | ||
| */ | ||
| memset(tmp_key, 0x0, MAX_SRTP_KEY_LEN); | ||
| memcpy(tmp_key, key, (rtp_base_key_len + rtp_salt_len)); | ||
| memcpy(tmp_key, key, input_keylen); | ||
|
|
||
| /* initialize KDF state */ | ||
| #if defined(OPENSSL) && defined(OPENSSL_KDF) | ||
|
|
||
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
Shouldn't this be
SRTP_AES_GCM_256_KEY_LEN_WSALT?SRTP_AES_ICM_256_KEY_LEN_WSALTis32+14whileSRTP_AES_GCM_256_KEY_LEN_WSALTis32+12. This is causing SRTP/SRTCP errors in our WebRTC servers when GCM-256 is used.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.
Yes.
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.
Ack, thanks, I created a mini-PR in #562 that addresses the typo.