-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Use memcmp_constant_time for SHA-256 hash comparisons #1004
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
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 |
|---|---|---|
|
|
@@ -35,6 +35,7 @@ | |
|
|
||
| #if defined(ENABLE_CRYPTO_MBEDTLS) | ||
|
|
||
| #include "crypto.h" | ||
| #include "errlevel.h" | ||
| #include "ssl_backend.h" | ||
| #include "base64.h" | ||
|
|
@@ -1035,7 +1036,7 @@ tls_ctx_personalise_random(struct tls_root_ctx *ctx) | |
| msg(M_WARN, "WARNING: failed to personalise random"); | ||
| } | ||
|
|
||
| if (0 != memcmp(old_sha256_hash, sha256_hash, sizeof(sha256_hash))) | ||
| if (0 != memcmp_constant_time(old_sha256_hash, sha256_hash, sizeof(sha256_hash))) | ||
|
Contributor
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 also feels like applying "hashes must be compared with constant time" rather than any actual security scenario. |
||
| { | ||
| if (!mbed_ok(mbedtls_ctr_drbg_update(cd_ctx, sha256_hash, 32))) | ||
| { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,6 +37,7 @@ | |
| #include "manage.h" | ||
| #include "otime.h" | ||
| #include "run_command.h" | ||
| #include "crypto.h" | ||
| #include "ssl_verify.h" | ||
| #include "ssl_verify_backend.h" | ||
|
|
||
|
|
@@ -241,7 +242,7 @@ cert_hash_compare(const struct cert_hash_set *chs1, const struct cert_hash_set * | |
| continue; | ||
| } | ||
| else if (ch1 && ch2 | ||
| && !memcmp(ch1->sha256_hash, ch2->sha256_hash, sizeof(ch1->sha256_hash))) | ||
| && !memcmp_constant_time(ch1->sha256_hash, ch2->sha256_hash, sizeof(ch1->sha256_hash))) | ||
|
Contributor
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 only one that could maybe be constant time. But then again to have any chance of exploiting this one requires you to be able to generate arbitary certificates that are trusted by CA that is in use by OpenVPN to verify the client certificates. |
||
| { | ||
| continue; | ||
| } | ||
|
|
||
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.
This is a check if we can keep tun device open or not. The hash is really used to avoid storing all the old options to compare them.
I do not see a reason to make this a constant time check other than blindly applying "hashes must be compared with constant time"