Skip to content

Commit f629999

Browse files
committed
update ecc_import_x509()
1 parent 21fa9cd commit f629999

File tree

2 files changed

+13
-38
lines changed

2 files changed

+13
-38
lines changed

src/pk/asn1/x509/x509_decode_public_key_from_certificate.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
@param parameters_len [in/out] The number of parameters to include
3434
@param callback The callback
3535
@param ctx The context passed to the callback
36-
@return CRYPT_OK on success
36+
@return CRYPT_OK on success, CRYPT_NOP if no SubjectPublicKeyInfo was found
3737
*/
3838
int x509_decode_public_key_from_certificate(const unsigned char *in, unsigned long inlen,
3939
enum ltc_oid_id algorithm, ltc_asn1_type param_type,
@@ -59,7 +59,7 @@ int x509_decode_public_key_from_certificate(const unsigned char *in, unsigned lo
5959
if ((err = der_decode_sequence_flexi(in, &tmp_inlen, &decoded_list)) == CRYPT_OK) {
6060
l = decoded_list;
6161

62-
err = CRYPT_INVALID_ARG;
62+
err = CRYPT_NOP;
6363

6464
/* Move 2 levels up in the tree
6565
SEQUENCE
@@ -86,12 +86,16 @@ int x509_decode_public_key_from_certificate(const unsigned char *in, unsigned lo
8686
if ((l->type == LTC_ASN1_SEQUENCE)
8787
&& (l->data != NULL)
8888
&& LOOKS_LIKE_SPKI(l->child)) {
89-
err = x509_decode_subject_public_key_info(l->data, l->size,
90-
algorithm, tmpbuf, &tmpbuf_len,
91-
param_type, parameters, parameters_len);
92-
if (err == CRYPT_OK) {
93-
err = callback(tmpbuf, tmpbuf_len, ctx);
94-
goto LBL_OUT;
89+
if (algorithm == PKA_EC) {
90+
err = ecc_import_subject_public_key_info(l->data, l->size, ctx);
91+
} else {
92+
err = x509_decode_subject_public_key_info(l->data, l->size,
93+
algorithm, tmpbuf, &tmpbuf_len,
94+
param_type, parameters, parameters_len);
95+
if (err == CRYPT_OK) {
96+
err = callback(tmpbuf, tmpbuf_len, ctx);
97+
goto LBL_OUT;
98+
}
9599
}
96100
}
97101
l = l->next;

src/pk/ecc/ecc_import_x509.c

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -112,36 +112,7 @@ int ecc_import_subject_public_key_info(const unsigned char *in, unsigned long in
112112
*/
113113
int ecc_import_x509(const unsigned char *in, unsigned long inlen, ecc_key *key)
114114
{
115-
int err;
116-
unsigned long len;
117-
ltc_asn1_list *decoded_list = NULL, *l;
118-
119-
LTC_ARGCHK(in != NULL);
120-
LTC_ARGCHK(key != NULL);
121-
122-
len = inlen;
123-
if ((err = der_decode_sequence_flexi(in, &len, &decoded_list)) == CRYPT_OK) {
124-
err = CRYPT_ERROR;
125-
l = decoded_list;
126-
if (l->type == LTC_ASN1_SEQUENCE &&
127-
l->child && l->child->type == LTC_ASN1_SEQUENCE) {
128-
l = l->child->child;
129-
while (l) {
130-
if (l->type == LTC_ASN1_SEQUENCE && l->data &&
131-
l->child && l->child->type == LTC_ASN1_SEQUENCE &&
132-
l->child->child && l->child->child->type == LTC_ASN1_OBJECT_IDENTIFIER &&
133-
l->child->next && l->child->next->type == LTC_ASN1_BIT_STRING) {
134-
err = ecc_import_subject_public_key_info(l->data, l->size, key);
135-
goto LBL_DONE;
136-
}
137-
l = l->next;
138-
}
139-
}
140-
}
141-
142-
LBL_DONE:
143-
if (decoded_list) der_free_sequence_flexi(decoded_list);
144-
return err;
115+
return x509_decode_public_key_from_certificate(in, inlen, PKA_EC, LTC_ASN1_EOL, NULL, NULL, NULL, key);
145116
}
146117

147118
#endif /* LTC_MECC */

0 commit comments

Comments
 (0)