|
10 | 10 | #ifdef LTC_DER |
11 | 11 |
|
12 | 12 | /** |
13 | | - Try to decode the public key from a X.509 certificate |
| 13 | + Process the public key from the SubjectPublicKeyInfo of a X.509 certificate |
14 | 14 | @param in The input buffer |
15 | 15 | @param inlen The length of the input buffer |
16 | 16 | @param algorithm One out of the enum #public_key_algorithms |
|
19 | 19 | @param parameters_len [in/out] The number of parameters to include |
20 | 20 | @param callback The callback |
21 | 21 | @param ctx The context passed to the callback |
22 | | - @return CRYPT_OK on success, |
23 | | - CRYPT_NOP if no SubjectPublicKeyInfo was found, |
24 | | - another error if decoding or memory allocation failed |
| 22 | + @return CRYPT_OK on success |
25 | 23 | */ |
26 | | -int x509_decode_public_key_from_certificate(const unsigned char *in, unsigned long inlen, |
27 | | - enum ltc_oid_id algorithm, ltc_asn1_type param_type, |
28 | | - ltc_asn1_list* parameters, unsigned long *parameters_len, |
29 | | - public_key_decode_cb callback, void *ctx) |
| 24 | +int x509_process_public_key_from_spki(const unsigned char *in, unsigned long inlen, |
| 25 | + enum ltc_oid_id algorithm, ltc_asn1_type param_type, |
| 26 | + ltc_asn1_list* parameters, unsigned long *parameters_len, |
| 27 | + public_key_decode_cb callback, void *ctx) |
30 | 28 | { |
31 | 29 | int err; |
32 | 30 | unsigned char *tmpbuf = NULL; |
33 | 31 | unsigned long tmpbuf_len; |
34 | | - ltc_asn1_list *decoded_list = NULL, *spki; |
35 | | - |
36 | | - LTC_ARGCHK(in != NULL); |
37 | | - LTC_ARGCHK(inlen != 0); |
38 | | - LTC_ARGCHK(callback != NULL); |
39 | 32 |
|
40 | | - if ((err = x509_decode_spki(in, inlen, &decoded_list, &spki)) != CRYPT_OK) { |
41 | | - return err; |
42 | | - } |
| 33 | + LTC_ARGCHK(in != NULL); |
| 34 | + LTC_ARGCHK(callback != NULL); |
43 | 35 |
|
44 | 36 | if (algorithm == LTC_OID_EC) { |
45 | | - err = callback(spki->data, spki->size, ctx); |
| 37 | + err = callback(in, inlen, ctx); |
46 | 38 | } else { |
47 | 39 |
|
48 | 40 | tmpbuf_len = inlen; |
49 | 41 | tmpbuf = XCALLOC(1, tmpbuf_len); |
50 | 42 | if (tmpbuf == NULL) { |
51 | | - err = CRYPT_MEM; |
52 | | - goto LBL_OUT; |
| 43 | + return CRYPT_MEM; |
53 | 44 | } |
54 | 45 |
|
55 | | - err = x509_decode_subject_public_key_info(spki->data, spki->size, |
| 46 | + err = x509_decode_subject_public_key_info(in, inlen, |
56 | 47 | algorithm, tmpbuf, &tmpbuf_len, |
57 | 48 | param_type, parameters, parameters_len); |
58 | 49 | if (err == CRYPT_OK) { |
59 | 50 | err = callback(tmpbuf, tmpbuf_len, ctx); |
60 | | - goto LBL_OUT; |
61 | 51 | } |
62 | 52 | } |
63 | 53 |
|
64 | | -LBL_OUT: |
65 | | - if (decoded_list) der_free_sequence_flexi(decoded_list); |
66 | 54 | if (tmpbuf != NULL) XFREE(tmpbuf); |
67 | 55 |
|
68 | 56 | return err; |
69 | 57 | } |
70 | 58 |
|
| 59 | +/** |
| 60 | + Try to decode the public key from a X.509 certificate |
| 61 | + @param in The input buffer |
| 62 | + @param inlen The length of the input buffer |
| 63 | + @param algorithm One out of the enum #public_key_algorithms |
| 64 | + @param param_type The parameters' type out of the enum ltc_asn1_type |
| 65 | + @param parameters The parameters to include |
| 66 | + @param parameters_len [in/out] The number of parameters to include |
| 67 | + @param callback The callback |
| 68 | + @param ctx The context passed to the callback |
| 69 | + @return CRYPT_OK on success, |
| 70 | + CRYPT_NOP if no SubjectPublicKeyInfo was found, |
| 71 | + another error if decoding or memory allocation failed |
| 72 | +*/ |
| 73 | +int x509_decode_public_key_from_certificate(const unsigned char *in, unsigned long inlen, |
| 74 | + enum ltc_oid_id algorithm, ltc_asn1_type param_type, |
| 75 | + ltc_asn1_list* parameters, unsigned long *parameters_len, |
| 76 | + public_key_decode_cb callback, void *ctx) |
| 77 | +{ |
| 78 | + int err; |
| 79 | + ltc_asn1_list *decoded_list; |
| 80 | + const ltc_asn1_list *spki; |
| 81 | + |
| 82 | + LTC_ARGCHK(in != NULL); |
| 83 | + LTC_ARGCHK(inlen != 0); |
| 84 | + LTC_ARGCHK(callback != NULL); |
| 85 | + |
| 86 | + if ((err = x509_decode_spki(in, inlen, &decoded_list, &spki)) != CRYPT_OK) { |
| 87 | + return err; |
| 88 | + } |
| 89 | + |
| 90 | + err = x509_process_public_key_from_spki(spki->data, spki->size, |
| 91 | + algorithm, param_type, |
| 92 | + parameters, parameters_len, |
| 93 | + callback, ctx); |
| 94 | + |
| 95 | + if (decoded_list) der_free_sequence_flexi(decoded_list); |
| 96 | + |
| 97 | + return err; |
| 98 | +} |
| 99 | + |
71 | 100 | #endif |
0 commit comments