Skip to content

Commit 47bbf26

Browse files
authored
MONGOCRYPT-865 check resulting length of SecKeyCreateSignature (#1129)
check resulting length of `SecKeyCreateSignature`
1 parent b55cf35 commit 47bbf26

3 files changed

Lines changed: 6 additions & 3 deletions

File tree

kms-message/src/kms_crypto.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ kms_sha256_hmac (void *ctx,
5858
size_t len,
5959
unsigned char *hash_out);
6060

61+
#define KMS_SIGN_RSAES_PKCS1_V1_5_OUTLEN 256
6162
/* signature_out must be a preallocated buffer of 256 bytes (or greater). */
6263
bool
6364
kms_sign_rsaes_pkcs1_v1_5 (void *sign_ctx,

kms-message/src/kms_crypto_apple.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,9 @@ kms_sign_rsaes_pkcs1_v1_5 (void *unused_ctx,
142142
if (!signature_ref) {
143143
goto cleanup;
144144
}
145+
if (CFDataGetLength(signature_ref) != KMS_SIGN_RSAES_PKCS1_V1_5_OUTLEN) {
146+
goto cleanup;
147+
}
145148
memcpy (signature_out,
146149
CFDataGetBytePtr (signature_ref),
147150
(size_t) CFDataGetLength (signature_ref));

kms-message/src/kms_gcp_request.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
/* Set a default expiration of 5 minutes for JSON Web Tokens (GCP allows up to
2424
* one hour) */
2525
#define JWT_EXPIRATION_SECS 5 * 60
26-
#define SIGNATURE_LEN 256
2726

2827
kms_request_t *
2928
kms_gcp_request_oauth_new (const char *host,
@@ -87,7 +86,7 @@ kms_gcp_request_oauth_new (const char *host,
8786
req->crypto.sign_ctx = opt->crypto.sign_ctx;
8887
}
8988

90-
jwt_signature = calloc (1, SIGNATURE_LEN);
89+
jwt_signature = calloc (1, KMS_SIGN_RSAES_PKCS1_V1_5_OUTLEN);
9190
KMS_ASSERT (jwt_signature);
9291
if (!req->crypto.sign_rsaes_pkcs1_v1_5 (
9392
req->crypto.sign_ctx,
@@ -101,7 +100,7 @@ kms_gcp_request_oauth_new (const char *host,
101100
}
102101

103102
jwt_signature_b64url =
104-
kms_message_raw_to_b64url (jwt_signature, SIGNATURE_LEN);
103+
kms_message_raw_to_b64url (jwt_signature, KMS_SIGN_RSAES_PKCS1_V1_5_OUTLEN);
105104
if (!jwt_signature_b64url) {
106105
KMS_ERROR (req, "Failed to base64url encode JWT signature");
107106
goto done;

0 commit comments

Comments
 (0)