pkcs15: fix encoding of 'SubjectPublicKeyInfo'
This commit is contained in:
parent
dd5115bc02
commit
8000564239
|
@ -49,12 +49,6 @@ static const struct sc_asn1_entry c_asn1_pkinfo[C_ASN1_PKINFO_ATTR_SIZE] = {
|
|||
{ NULL, 0, 0, 0, NULL, NULL }
|
||||
};
|
||||
|
||||
#define C_ASN1_SPKI_ATTR_SIZE 2
|
||||
static const struct sc_asn1_entry c_asn1_spki[C_ASN1_SPKI_ATTR_SIZE] = {
|
||||
{ "subjectPublicKeyInfo", SC_ASN1_STRUCT, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, 0, NULL, NULL },
|
||||
{ NULL, 0, 0, 0, NULL, NULL }
|
||||
};
|
||||
|
||||
#define C_ASN1_COM_KEY_ATTR_SIZE 6
|
||||
static const struct sc_asn1_entry c_asn1_com_key_attr[C_ASN1_COM_KEY_ATTR_SIZE] = {
|
||||
{ "iD", SC_ASN1_PKCS15_ID, SC_ASN1_TAG_OCTET_STRING, 0, NULL, NULL },
|
||||
|
@ -159,6 +153,7 @@ static const struct sc_asn1_entry c_asn1_pubkey[C_ASN1_PUBKEY_SIZE] = {
|
|||
};
|
||||
|
||||
int sc_pkcs15_copy_pubkey_from_spki_object(sc_context_t *ctx, const u8 *buf, size_t buflen,sc_pkcs15_pubkey_t *pubkey);
|
||||
int sc_pkcs15_pubkey_from_spki_object(sc_context_t *ctx, const u8 *buf, size_t buflen, sc_pkcs15_pubkey_t ** outpubkey);
|
||||
|
||||
int
|
||||
sc_pkcs15_decode_pubkey_direct_value(struct sc_pkcs15_card *p15card, struct sc_pkcs15_object *obj)
|
||||
|
@ -194,7 +189,7 @@ sc_pkcs15_decode_pubkey_direct_value(struct sc_pkcs15_card *p15card, struct sc_p
|
|||
memcpy(info->direct.spki.value, obj->content.value, obj->content.len);
|
||||
info->direct.spki.len = obj->content.len;
|
||||
|
||||
rv = sc_pkcs15_pubkey_from_spki(ctx, &pubkey, info->direct.spki.value, info->direct.spki.len, 0);
|
||||
rv = sc_pkcs15_pubkey_from_spki_object(ctx, info->direct.spki.value, info->direct.spki.len, &pubkey);
|
||||
LOG_TEST_RET(ctx, rv, "Failed to decode 'SPKI' direct value");
|
||||
|
||||
rv = sc_pkcs15_encode_pubkey(ctx, pubkey, &info->direct.raw.value, &info->direct.raw.len);
|
||||
|
@ -917,10 +912,11 @@ sc_pkcs15_read_pubkey(struct sc_pkcs15_card *p15card, const struct sc_pkcs15_obj
|
|||
}
|
||||
pubkey->algorithm = algorithm;
|
||||
|
||||
/* starting from SPKI direct value: in a compact form it presents complete public key data */
|
||||
/* starting from SPKI direct value
|
||||
in a compact form it presents complete public key data */
|
||||
if (info->direct.spki.value && info->direct.spki.len) {
|
||||
sc_log(ctx, "Using direct SPKI value, tag 0x%X", *(info->direct.spki.value));
|
||||
r = sc_pkcs15_pubkey_from_spki(ctx, &pubkey, info->direct.spki.value, info->direct.spki.len, 0);
|
||||
r = sc_pkcs15_pubkey_from_spki_object(ctx, info->direct.spki.value, info->direct.spki.len, &pubkey);
|
||||
LOG_TEST_RET(ctx, r, "Failed to decode 'SPKI' direct value");
|
||||
}
|
||||
else if (info->direct.raw.value && info->direct.raw.len) {
|
||||
|
@ -1170,12 +1166,11 @@ sc_pkcs15_pubkey_from_spki(struct sc_context *ctx, struct sc_pkcs15_pubkey **out
|
|||
struct sc_pkcs15_pubkey *pubkey = NULL;
|
||||
struct sc_pkcs15_der pk = { NULL, 0 };
|
||||
struct sc_algorithm_id pk_alg;
|
||||
struct sc_asn1_entry asn1_spki[C_ASN1_SPKI_ATTR_SIZE];
|
||||
struct sc_asn1_entry asn1_pkinfo[C_ASN1_PKINFO_ATTR_SIZE];
|
||||
unsigned char *tmp_buf = NULL;
|
||||
int r;
|
||||
|
||||
sc_log(ctx, "sc_pkcs15_pubkey_from_spki %p:%d", buf, buflen);
|
||||
sc_log(ctx, "sc_pkcs15_pubkey_from_spki %p:%d %s", buf, buflen, sc_dump_hex(buf, buflen));
|
||||
|
||||
tmp_buf = malloc(buflen);
|
||||
if (!tmp_buf)
|
||||
|
@ -1190,14 +1185,12 @@ sc_pkcs15_pubkey_from_spki(struct sc_context *ctx, struct sc_pkcs15_pubkey **out
|
|||
if (pubkey == NULL)
|
||||
LOG_FUNC_RETURN(ctx, SC_ERROR_OUT_OF_MEMORY);
|
||||
|
||||
sc_copy_asn1_entry(c_asn1_spki, asn1_spki);
|
||||
sc_copy_asn1_entry(c_asn1_pkinfo, asn1_pkinfo);
|
||||
|
||||
sc_format_asn1_entry(asn1_pkinfo + 0, &pk_alg, NULL, 0);
|
||||
sc_format_asn1_entry(asn1_pkinfo + 1, &pk.value, &pk.len, 0);
|
||||
sc_format_asn1_entry(asn1_spki + 0, asn1_pkinfo, NULL, 0);
|
||||
|
||||
r = sc_asn1_decode(ctx, asn1_spki, tmp_buf, buflen, NULL, NULL);
|
||||
r = sc_asn1_decode(ctx, asn1_pkinfo, tmp_buf, buflen, NULL, NULL);
|
||||
LOG_TEST_RET(ctx, r, "ASN.1 parsing of subjectPubkeyInfo failed");
|
||||
|
||||
pubkey->alg_id = calloc(1, sizeof(struct sc_algorithm_id));
|
||||
|
@ -1255,7 +1248,7 @@ sc_pkcs15_pubkey_from_spki_object(sc_context_t *ctx, const u8 *buf, size_t bufle
|
|||
int r;
|
||||
sc_pkcs15_pubkey_t * pubkey = NULL;
|
||||
struct sc_asn1_entry asn1_spki[] = {
|
||||
{ "PublicKeyInfo",SC_ASN1_CALLBACK, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, 0, sc_pkcs15_pubkey_from_spki, &pubkey},
|
||||
{ "subjectPublicKeyInfo", SC_ASN1_CALLBACK, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, 0, sc_pkcs15_pubkey_from_spki, &pubkey},
|
||||
{ NULL, 0, 0, 0, NULL, NULL } };
|
||||
|
||||
*outpubkey = NULL;
|
||||
|
|
Loading…
Reference in New Issue