@@ -305,127 +305,6 @@ int X509_check_private_key(X509 *x, const EVP_PKEY *k) {
305
305
return 0 ;
306
306
}
307
307
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
-
429
308
// Not strictly speaking an "up_ref" as a STACK doesn't have a reference
430
309
// count but it has the same effect by duping the STACK and upping the ref of
431
310
// each X509 structure.
0 commit comments