x509asn1: make do_pubkey handle EC public keys

Closes #8757
This commit is contained in:
Sergey Markelov 2022-05-05 08:44:21 +02:00 committed by Daniel Stenberg
parent d7fb9ab7ce
commit 137a668e8c
No known key found for this signature in database
GPG Key ID: 5CC908FDB71E12C2

View File

@ -945,6 +945,24 @@ static int do_pubkey(struct Curl_easy *data, int certnum,
/* Generate all information records for the public key. */
if(strcasecompare(algo, "ecPublicKey")) {
/*
* ECC public key is all the data, a value of type BIT STRING mapped to
* OCTET STRING and should not be parsed as an ASN.1 value.
*/
const unsigned long len =
(unsigned long)((pubkey->end - pubkey->beg - 2) * 4);
if(!certnum)
infof(data, " ECC Public Key (%lu bits)", len);
if(data->set.ssl.certinfo) {
char q[sizeof(len) * 8 / 3 + 1];
msnprintf(q, sizeof(q), "%lu", len);
if(Curl_ssl_push_certinfo(data, certnum, "ECC Public Key", q))
return 1;
}
return do_pubkey_field(data, certnum, "ecPublicKey", pubkey);
}
/* Get the public key (single element). */
if(!getASN1Element(&pk, pubkey->beg + 1, pubkey->end))
return 1;
@ -971,14 +989,10 @@ static int do_pubkey(struct Curl_easy *data, int certnum,
if(!certnum)
infof(data, " RSA Public Key (%lu bits)", len);
if(data->set.ssl.certinfo) {
q = curl_maprintf("%lu", len);
if(q) {
CURLcode result =
Curl_ssl_push_certinfo(data, certnum, "RSA Public Key", q);
free((char *) q);
if(result)
return 1;
}
char r[sizeof(len) * 8 / 3 + 1];
msnprintf(r, sizeof(r), "%lu", len);
if(Curl_ssl_push_certinfo(data, certnum, "RSA Public Key", r))
return 1;
}
/* Generate coefficients. */
if(do_pubkey_field(data, certnum, "rsa(n)", &elem))