diff options
| author | Simon Rettberg | 2023-10-06 18:37:21 +0200 |
|---|---|---|
| committer | Simon Rettberg | 2023-10-06 18:37:21 +0200 |
| commit | 95a57769874a70456670984debc05084feb75f6b (patch) | |
| tree | 9943c86b682e1b1d21a0439637b3849840a50137 /src/crypto | |
| parent | [efi] Remove old RDRAND hack; now officially supported (diff) | |
| parent | [libc] Use wall clock time as seed for the (non-cryptographic) RNG (diff) | |
| download | ipxe-95a57769874a70456670984debc05084feb75f6b.tar.gz ipxe-95a57769874a70456670984debc05084feb75f6b.tar.xz ipxe-95a57769874a70456670984debc05084feb75f6b.zip | |
Merge branch 'master' into openslx
Diffstat (limited to 'src/crypto')
| -rw-r--r-- | src/crypto/asn1.c | 26 | ||||
| -rw-r--r-- | src/crypto/rsa.c | 19 |
2 files changed, 44 insertions, 1 deletions
diff --git a/src/crypto/asn1.c b/src/crypto/asn1.c index 549ee4d86..dc9d1c54d 100644 --- a/src/crypto/asn1.c +++ b/src/crypto/asn1.c @@ -590,6 +590,32 @@ int asn1_signature_algorithm ( const struct asn1_cursor *cursor, } /** + * Check ASN.1 OID-identified algorithm + * + * @v cursor ASN.1 object cursor + * @v expected Expected algorithm + * @ret rc Return status code + */ +int asn1_check_algorithm ( const struct asn1_cursor *cursor, + struct asn1_algorithm *expected ) { + struct asn1_algorithm *actual; + int rc; + + /* Parse algorithm */ + if ( ( rc = asn1_algorithm ( cursor, &actual ) ) != 0 ) + return rc; + + /* Check algorithm matches */ + if ( actual != expected ) { + DBGC ( cursor, "ASN1 %p algorithm %s does not match %s\n", + cursor, actual->name, expected->name ); + return -ENOTTY_ALGORITHM; + } + + return 0; +} + +/** * Parse ASN.1 GeneralizedTime * * @v cursor ASN.1 cursor diff --git a/src/crypto/rsa.c b/src/crypto/rsa.c index a38955744..16c67d822 100644 --- a/src/crypto/rsa.c +++ b/src/crypto/rsa.c @@ -164,7 +164,7 @@ static int rsa_parse_mod_exp ( struct asn1_cursor *modulus, int is_private; int rc; - /* Enter subjectPublicKeyInfo/RSAPrivateKey */ + /* Enter subjectPublicKeyInfo/privateKeyInfo/RSAPrivateKey */ memcpy ( &cursor, raw, sizeof ( cursor ) ); asn1_enter ( &cursor, ASN1_SEQUENCE ); @@ -177,6 +177,23 @@ static int rsa_parse_mod_exp ( struct asn1_cursor *modulus, /* Skip version */ asn1_skip_any ( &cursor ); + /* Enter privateKey, if present */ + if ( asn1_check_algorithm ( &cursor, + &rsa_encryption_algorithm ) == 0 ) { + + /* Skip privateKeyAlgorithm */ + asn1_skip_any ( &cursor ); + + /* Enter privateKey */ + asn1_enter ( &cursor, ASN1_OCTET_STRING ); + + /* Enter RSAPrivateKey */ + asn1_enter ( &cursor, ASN1_SEQUENCE ); + + /* Skip version */ + asn1_skip ( &cursor, ASN1_INTEGER ); + } + } else { /* Public key */ |
