Skip to content

Commit 75c9959

Browse files
davidbennebeid
authored andcommitted
Remove the last of the Suite B code.
Update-Note: Suite B flags in the X.509 stack are no longer supported. This isn't expected to affect anything but bindings wrapping unused options. Change-Id: Ia0770e545d34e041ab995e80ea11b4dd4a5e47ef Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/53329 Reviewed-by: Bob Beck <[email protected]> Commit-Queue: David Benjamin <[email protected]> (cherry picked from commit 81587d369990f1f07f9d821c0c27f74adbaa8482)
1 parent acc6150 commit 75c9959

File tree

4 files changed

+0
-173
lines changed

4 files changed

+0
-173
lines changed

crypto/x509/x509_cmp.c

-121
Original file line numberDiff line numberDiff line change
@@ -305,127 +305,6 @@ int X509_check_private_key(X509 *x, const EVP_PKEY *k) {
305305
return 0;
306306
}
307307

308-
// Check a suite B algorithm is permitted: pass in a public key and the NID
309-
// of its signature (or 0 if no signature). The pflags is a pointer to a
310-
// flags field which must contain the suite B verification flags.
311-
312-
static int check_suite_b(EVP_PKEY *pkey, int sign_nid, unsigned long *pflags) {
313-
const EC_GROUP *grp = NULL;
314-
int curve_nid;
315-
if (pkey && pkey->type == EVP_PKEY_EC) {
316-
grp = EC_KEY_get0_group(pkey->pkey.ec);
317-
}
318-
if (!grp) {
319-
return X509_V_ERR_SUITE_B_INVALID_ALGORITHM;
320-
}
321-
curve_nid = EC_GROUP_get_curve_name(grp);
322-
// Check curve is consistent with LOS
323-
if (curve_nid == NID_secp384r1) { // P-384
324-
// Check signature algorithm is consistent with curve.
325-
if (sign_nid != -1 && sign_nid != NID_ecdsa_with_SHA384) {
326-
return X509_V_ERR_SUITE_B_INVALID_SIGNATURE_ALGORITHM;
327-
}
328-
if (!(*pflags & X509_V_FLAG_SUITEB_192_LOS)) {
329-
return X509_V_ERR_SUITE_B_LOS_NOT_ALLOWED;
330-
}
331-
// If we encounter P-384 we cannot use P-256 later
332-
*pflags &= ~X509_V_FLAG_SUITEB_128_LOS_ONLY;
333-
} else if (curve_nid == NID_X9_62_prime256v1) { // P-256
334-
if (sign_nid != -1 && sign_nid != NID_ecdsa_with_SHA256) {
335-
return X509_V_ERR_SUITE_B_INVALID_SIGNATURE_ALGORITHM;
336-
}
337-
if (!(*pflags & X509_V_FLAG_SUITEB_128_LOS_ONLY)) {
338-
return X509_V_ERR_SUITE_B_LOS_NOT_ALLOWED;
339-
}
340-
} else {
341-
return X509_V_ERR_SUITE_B_INVALID_CURVE;
342-
}
343-
344-
return X509_V_OK;
345-
}
346-
347-
int X509_chain_check_suiteb(int *perror_depth, X509 *x, STACK_OF(X509) *chain,
348-
unsigned long flags) {
349-
int rv, sign_nid;
350-
size_t i;
351-
EVP_PKEY *pk = NULL;
352-
unsigned long tflags;
353-
if (!(flags & X509_V_FLAG_SUITEB_128_LOS)) {
354-
return X509_V_OK;
355-
}
356-
tflags = flags;
357-
// If no EE certificate passed in must be first in chain
358-
if (x == NULL) {
359-
x = sk_X509_value(chain, 0);
360-
i = 1;
361-
} else {
362-
i = 0;
363-
}
364-
365-
if (X509_get_version(x) != X509_VERSION_3) {
366-
rv = X509_V_ERR_SUITE_B_INVALID_VERSION;
367-
// Correct error depth
368-
i = 0;
369-
goto end;
370-
}
371-
372-
pk = X509_get_pubkey(x);
373-
// Check EE key only
374-
rv = check_suite_b(pk, -1, &tflags);
375-
if (rv != X509_V_OK) {
376-
// Correct error depth
377-
i = 0;
378-
goto end;
379-
}
380-
for (; i < sk_X509_num(chain); i++) {
381-
sign_nid = X509_get_signature_nid(x);
382-
x = sk_X509_value(chain, i);
383-
if (X509_get_version(x) != X509_VERSION_3) {
384-
rv = X509_V_ERR_SUITE_B_INVALID_VERSION;
385-
goto end;
386-
}
387-
EVP_PKEY_free(pk);
388-
pk = X509_get_pubkey(x);
389-
rv = check_suite_b(pk, sign_nid, &tflags);
390-
if (rv != X509_V_OK) {
391-
goto end;
392-
}
393-
}
394-
395-
// Final check: root CA signature
396-
rv = check_suite_b(pk, X509_get_signature_nid(x), &tflags);
397-
end:
398-
if (pk) {
399-
EVP_PKEY_free(pk);
400-
}
401-
if (rv != X509_V_OK) {
402-
// Invalid signature or LOS errors are for previous cert
403-
if ((rv == X509_V_ERR_SUITE_B_INVALID_SIGNATURE_ALGORITHM ||
404-
rv == X509_V_ERR_SUITE_B_LOS_NOT_ALLOWED) &&
405-
i) {
406-
i--;
407-
}
408-
// If we have LOS error and flags changed then we are signing P-384
409-
// with P-256. Use more meaninggul error.
410-
if (rv == X509_V_ERR_SUITE_B_LOS_NOT_ALLOWED && flags != tflags) {
411-
rv = X509_V_ERR_SUITE_B_CANNOT_SIGN_P_384_WITH_P_256;
412-
}
413-
if (perror_depth) {
414-
*perror_depth = i;
415-
}
416-
}
417-
return rv;
418-
}
419-
420-
int X509_CRL_check_suiteb(X509_CRL *crl, EVP_PKEY *pk, unsigned long flags) {
421-
int sign_nid;
422-
if (!(flags & X509_V_FLAG_SUITEB_128_LOS)) {
423-
return X509_V_OK;
424-
}
425-
sign_nid = OBJ_obj2nid(crl->crl->sig_alg->algorithm);
426-
return check_suite_b(pk, sign_nid, &flags);
427-
}
428-
429308
// Not strictly speaking an "up_ref" as a STACK doesn't have a reference
430309
// count but it has the same effect by duping the STACK and upping the ref of
431310
// each X509 structure.

crypto/x509/x509_txt.c

-13
Original file line numberDiff line numberDiff line change
@@ -168,19 +168,6 @@ const char *X509_verify_cert_error_string(long err) {
168168
case X509_V_ERR_CRL_PATH_VALIDATION_ERROR:
169169
return "CRL path validation error";
170170

171-
case X509_V_ERR_SUITE_B_INVALID_VERSION:
172-
return "Suite B: certificate version invalid";
173-
case X509_V_ERR_SUITE_B_INVALID_ALGORITHM:
174-
return "Suite B: invalid public key algorithm";
175-
case X509_V_ERR_SUITE_B_INVALID_CURVE:
176-
return "Suite B: invalid ECC curve";
177-
case X509_V_ERR_SUITE_B_INVALID_SIGNATURE_ALGORITHM:
178-
return "Suite B: invalid signature algorithm";
179-
case X509_V_ERR_SUITE_B_LOS_NOT_ALLOWED:
180-
return "Suite B: curve not allowed for this LOS";
181-
case X509_V_ERR_SUITE_B_CANNOT_SIGN_P_384_WITH_P_256:
182-
return "Suite B: cannot sign P-384 with P-256";
183-
184171
case X509_V_ERR_HOSTNAME_MISMATCH:
185172
return "Hostname mismatch";
186173
case X509_V_ERR_EMAIL_MISMATCH:

crypto/x509/x509_vfy.c

-20
Original file line numberDiff line numberDiff line change
@@ -457,17 +457,6 @@ int X509_verify_cert(X509_STORE_CTX *ctx) {
457457
goto end;
458458
}
459459

460-
int err = X509_chain_check_suiteb(&ctx->error_depth, NULL, ctx->chain,
461-
ctx->param->flags);
462-
if (err != X509_V_OK) {
463-
ctx->error = err;
464-
ctx->current_cert = sk_X509_value(ctx->chain, ctx->error_depth);
465-
ok = ctx->verify_cb(0, ctx);
466-
if (!ok) {
467-
goto end;
468-
}
469-
}
470-
471460
// At this point, we have a chain and need to verify it
472461
if (ctx->verify != NULL) {
473462
ok = ctx->verify(ctx);
@@ -1646,15 +1635,6 @@ static int check_crl(X509_STORE_CTX *ctx, X509_CRL *crl) {
16461635
goto err;
16471636
}
16481637
} else {
1649-
int rv;
1650-
rv = X509_CRL_check_suiteb(crl, ikey, ctx->param->flags);
1651-
if (rv != X509_V_OK) {
1652-
ctx->error = rv;
1653-
ok = ctx->verify_cb(0, ctx);
1654-
if (!ok) {
1655-
goto err;
1656-
}
1657-
}
16581638
// Verify CRL signature
16591639
if (X509_CRL_verify(crl, ikey) <= 0) {
16601640
ctx->error = X509_V_ERR_CRL_SIGNATURE_FAILURE;

include/openssl/x509.h

-19
Original file line numberDiff line numberDiff line change
@@ -1759,11 +1759,6 @@ OPENSSL_EXPORT X509_CRL *X509_CRL_diff(X509_CRL *base, X509_CRL *newer,
17591759
OPENSSL_EXPORT int X509_REQ_check_private_key(X509_REQ *x509, EVP_PKEY *pkey);
17601760

17611761
OPENSSL_EXPORT int X509_check_private_key(X509 *x509, const EVP_PKEY *pkey);
1762-
OPENSSL_EXPORT int X509_chain_check_suiteb(int *perror_depth, X509 *x,
1763-
STACK_OF(X509) *chain,
1764-
unsigned long flags);
1765-
OPENSSL_EXPORT int X509_CRL_check_suiteb(X509_CRL *crl, EVP_PKEY *pk,
1766-
unsigned long flags);
17671762

17681763
OPENSSL_EXPORT int X509_issuer_and_serial_cmp(const X509 *a, const X509 *b);
17691764

@@ -2410,14 +2405,6 @@ OPENSSL_EXPORT void X509_STORE_CTX_set_depth(X509_STORE_CTX *ctx, int depth);
24102405
#define X509_V_ERR_UNSUPPORTED_NAME_SYNTAX 53
24112406
#define X509_V_ERR_CRL_PATH_VALIDATION_ERROR 54
24122407

2413-
// Suite B mode algorithm violation
2414-
#define X509_V_ERR_SUITE_B_INVALID_VERSION 56
2415-
#define X509_V_ERR_SUITE_B_INVALID_ALGORITHM 57
2416-
#define X509_V_ERR_SUITE_B_INVALID_CURVE 58
2417-
#define X509_V_ERR_SUITE_B_INVALID_SIGNATURE_ALGORITHM 59
2418-
#define X509_V_ERR_SUITE_B_LOS_NOT_ALLOWED 60
2419-
#define X509_V_ERR_SUITE_B_CANNOT_SIGN_P_384_WITH_P_256 61
2420-
24212408
// Host, email and IP check errors
24222409
#define X509_V_ERR_HOSTNAME_MISMATCH 62
24232410
#define X509_V_ERR_EMAIL_MISMATCH 63
@@ -2464,12 +2451,6 @@ OPENSSL_EXPORT void X509_STORE_CTX_set_depth(X509_STORE_CTX *ctx, int depth);
24642451
#define X509_V_FLAG_CHECK_SS_SIGNATURE 0x4000
24652452
// Use trusted store first
24662453
#define X509_V_FLAG_TRUSTED_FIRST 0x8000
2467-
// Suite B 128 bit only mode: not normally used
2468-
#define X509_V_FLAG_SUITEB_128_LOS_ONLY 0x10000
2469-
// Suite B 192 bit only mode
2470-
#define X509_V_FLAG_SUITEB_192_LOS 0x20000
2471-
// Suite B 128 bit mode allowing 192 bit algorithms
2472-
#define X509_V_FLAG_SUITEB_128_LOS 0x30000
24732454

24742455
// Allow partial chains if at least one certificate is in trusted store
24752456
#define X509_V_FLAG_PARTIAL_CHAIN 0x80000

0 commit comments

Comments
 (0)