Path: blob/master/crypto/asymmetric_keys/x509_cert_parser.c
26295 views
// SPDX-License-Identifier: GPL-2.0-or-later1/* X.509 certificate parser2*3* Copyright (C) 2012 Red Hat, Inc. All Rights Reserved.4* Written by David Howells ([email protected])5*/67#define pr_fmt(fmt) "X.509: "fmt8#include <linux/kernel.h>9#include <linux/export.h>10#include <linux/slab.h>11#include <linux/err.h>12#include <linux/oid_registry.h>13#include <crypto/public_key.h>14#include "x509_parser.h"15#include "x509.asn1.h"16#include "x509_akid.asn1.h"1718struct x509_parse_context {19struct x509_certificate *cert; /* Certificate being constructed */20unsigned long data; /* Start of data */21const void *key; /* Key data */22size_t key_size; /* Size of key data */23const void *params; /* Key parameters */24size_t params_size; /* Size of key parameters */25enum OID key_algo; /* Algorithm used by the cert's key */26enum OID last_oid; /* Last OID encountered */27enum OID sig_algo; /* Algorithm used to sign the cert */28u8 o_size; /* Size of organizationName (O) */29u8 cn_size; /* Size of commonName (CN) */30u8 email_size; /* Size of emailAddress */31u16 o_offset; /* Offset of organizationName (O) */32u16 cn_offset; /* Offset of commonName (CN) */33u16 email_offset; /* Offset of emailAddress */34unsigned raw_akid_size;35const void *raw_akid; /* Raw authorityKeyId in ASN.1 */36const void *akid_raw_issuer; /* Raw directoryName in authorityKeyId */37unsigned akid_raw_issuer_size;38};3940/*41* Free an X.509 certificate42*/43void x509_free_certificate(struct x509_certificate *cert)44{45if (cert) {46public_key_free(cert->pub);47public_key_signature_free(cert->sig);48kfree(cert->issuer);49kfree(cert->subject);50kfree(cert->id);51kfree(cert->skid);52kfree(cert);53}54}55EXPORT_SYMBOL_GPL(x509_free_certificate);5657/*58* Parse an X.509 certificate59*/60struct x509_certificate *x509_cert_parse(const void *data, size_t datalen)61{62struct x509_certificate *cert __free(x509_free_certificate);63struct x509_parse_context *ctx __free(kfree) = NULL;64struct asymmetric_key_id *kid;65long ret;6667cert = kzalloc(sizeof(struct x509_certificate), GFP_KERNEL);68if (!cert)69return ERR_PTR(-ENOMEM);70cert->pub = kzalloc(sizeof(struct public_key), GFP_KERNEL);71if (!cert->pub)72return ERR_PTR(-ENOMEM);73cert->sig = kzalloc(sizeof(struct public_key_signature), GFP_KERNEL);74if (!cert->sig)75return ERR_PTR(-ENOMEM);76ctx = kzalloc(sizeof(struct x509_parse_context), GFP_KERNEL);77if (!ctx)78return ERR_PTR(-ENOMEM);7980ctx->cert = cert;81ctx->data = (unsigned long)data;8283/* Attempt to decode the certificate */84ret = asn1_ber_decoder(&x509_decoder, ctx, data, datalen);85if (ret < 0)86return ERR_PTR(ret);8788/* Decode the AuthorityKeyIdentifier */89if (ctx->raw_akid) {90pr_devel("AKID: %u %*phN\n",91ctx->raw_akid_size, ctx->raw_akid_size, ctx->raw_akid);92ret = asn1_ber_decoder(&x509_akid_decoder, ctx,93ctx->raw_akid, ctx->raw_akid_size);94if (ret < 0) {95pr_warn("Couldn't decode AuthKeyIdentifier\n");96return ERR_PTR(ret);97}98}99100cert->pub->key = kmemdup(ctx->key, ctx->key_size, GFP_KERNEL);101if (!cert->pub->key)102return ERR_PTR(-ENOMEM);103104cert->pub->keylen = ctx->key_size;105106cert->pub->params = kmemdup(ctx->params, ctx->params_size, GFP_KERNEL);107if (!cert->pub->params)108return ERR_PTR(-ENOMEM);109110cert->pub->paramlen = ctx->params_size;111cert->pub->algo = ctx->key_algo;112113/* Grab the signature bits */114ret = x509_get_sig_params(cert);115if (ret < 0)116return ERR_PTR(ret);117118/* Generate cert issuer + serial number key ID */119kid = asymmetric_key_generate_id(cert->raw_serial,120cert->raw_serial_size,121cert->raw_issuer,122cert->raw_issuer_size);123if (IS_ERR(kid))124return ERR_CAST(kid);125cert->id = kid;126127/* Detect self-signed certificates */128ret = x509_check_for_self_signed(cert);129if (ret < 0)130return ERR_PTR(ret);131132return_ptr(cert);133}134EXPORT_SYMBOL_GPL(x509_cert_parse);135136/*137* Note an OID when we find one for later processing when we know how138* to interpret it.139*/140int x509_note_OID(void *context, size_t hdrlen,141unsigned char tag,142const void *value, size_t vlen)143{144struct x509_parse_context *ctx = context;145146ctx->last_oid = look_up_OID(value, vlen);147if (ctx->last_oid == OID__NR) {148char buffer[50];149sprint_oid(value, vlen, buffer, sizeof(buffer));150pr_debug("Unknown OID: [%lu] %s\n",151(unsigned long)value - ctx->data, buffer);152}153return 0;154}155156/*157* Save the position of the TBS data so that we can check the signature over it158* later.159*/160int x509_note_tbs_certificate(void *context, size_t hdrlen,161unsigned char tag,162const void *value, size_t vlen)163{164struct x509_parse_context *ctx = context;165166pr_debug("x509_note_tbs_certificate(,%zu,%02x,%ld,%zu)!\n",167hdrlen, tag, (unsigned long)value - ctx->data, vlen);168169ctx->cert->tbs = value - hdrlen;170ctx->cert->tbs_size = vlen + hdrlen;171return 0;172}173174/*175* Record the algorithm that was used to sign this certificate.176*/177int x509_note_sig_algo(void *context, size_t hdrlen, unsigned char tag,178const void *value, size_t vlen)179{180struct x509_parse_context *ctx = context;181182pr_debug("PubKey Algo: %u\n", ctx->last_oid);183184switch (ctx->last_oid) {185default:186return -ENOPKG; /* Unsupported combination */187188case OID_sha1WithRSAEncryption:189ctx->cert->sig->hash_algo = "sha1";190goto rsa_pkcs1;191192case OID_sha256WithRSAEncryption:193ctx->cert->sig->hash_algo = "sha256";194goto rsa_pkcs1;195196case OID_sha384WithRSAEncryption:197ctx->cert->sig->hash_algo = "sha384";198goto rsa_pkcs1;199200case OID_sha512WithRSAEncryption:201ctx->cert->sig->hash_algo = "sha512";202goto rsa_pkcs1;203204case OID_sha224WithRSAEncryption:205ctx->cert->sig->hash_algo = "sha224";206goto rsa_pkcs1;207208case OID_id_ecdsa_with_sha1:209ctx->cert->sig->hash_algo = "sha1";210goto ecdsa;211212case OID_id_rsassa_pkcs1_v1_5_with_sha3_256:213ctx->cert->sig->hash_algo = "sha3-256";214goto rsa_pkcs1;215216case OID_id_rsassa_pkcs1_v1_5_with_sha3_384:217ctx->cert->sig->hash_algo = "sha3-384";218goto rsa_pkcs1;219220case OID_id_rsassa_pkcs1_v1_5_with_sha3_512:221ctx->cert->sig->hash_algo = "sha3-512";222goto rsa_pkcs1;223224case OID_id_ecdsa_with_sha224:225ctx->cert->sig->hash_algo = "sha224";226goto ecdsa;227228case OID_id_ecdsa_with_sha256:229ctx->cert->sig->hash_algo = "sha256";230goto ecdsa;231232case OID_id_ecdsa_with_sha384:233ctx->cert->sig->hash_algo = "sha384";234goto ecdsa;235236case OID_id_ecdsa_with_sha512:237ctx->cert->sig->hash_algo = "sha512";238goto ecdsa;239240case OID_id_ecdsa_with_sha3_256:241ctx->cert->sig->hash_algo = "sha3-256";242goto ecdsa;243244case OID_id_ecdsa_with_sha3_384:245ctx->cert->sig->hash_algo = "sha3-384";246goto ecdsa;247248case OID_id_ecdsa_with_sha3_512:249ctx->cert->sig->hash_algo = "sha3-512";250goto ecdsa;251252case OID_gost2012Signature256:253ctx->cert->sig->hash_algo = "streebog256";254goto ecrdsa;255256case OID_gost2012Signature512:257ctx->cert->sig->hash_algo = "streebog512";258goto ecrdsa;259}260261rsa_pkcs1:262ctx->cert->sig->pkey_algo = "rsa";263ctx->cert->sig->encoding = "pkcs1";264ctx->sig_algo = ctx->last_oid;265return 0;266ecrdsa:267ctx->cert->sig->pkey_algo = "ecrdsa";268ctx->cert->sig->encoding = "raw";269ctx->sig_algo = ctx->last_oid;270return 0;271ecdsa:272ctx->cert->sig->pkey_algo = "ecdsa";273ctx->cert->sig->encoding = "x962";274ctx->sig_algo = ctx->last_oid;275return 0;276}277278/*279* Note the whereabouts and type of the signature.280*/281int x509_note_signature(void *context, size_t hdrlen,282unsigned char tag,283const void *value, size_t vlen)284{285struct x509_parse_context *ctx = context;286287pr_debug("Signature: alg=%u, size=%zu\n", ctx->last_oid, vlen);288289/*290* In X.509 certificates, the signature's algorithm is stored in two291* places: inside the TBSCertificate (the data that is signed), and292* alongside the signature. These *must* match.293*/294if (ctx->last_oid != ctx->sig_algo) {295pr_warn("signatureAlgorithm (%u) differs from tbsCertificate.signature (%u)\n",296ctx->last_oid, ctx->sig_algo);297return -EINVAL;298}299300if (strcmp(ctx->cert->sig->pkey_algo, "rsa") == 0 ||301strcmp(ctx->cert->sig->pkey_algo, "ecrdsa") == 0 ||302strcmp(ctx->cert->sig->pkey_algo, "ecdsa") == 0) {303/* Discard the BIT STRING metadata */304if (vlen < 1 || *(const u8 *)value != 0)305return -EBADMSG;306307value++;308vlen--;309}310311ctx->cert->raw_sig = value;312ctx->cert->raw_sig_size = vlen;313return 0;314}315316/*317* Note the certificate serial number318*/319int x509_note_serial(void *context, size_t hdrlen,320unsigned char tag,321const void *value, size_t vlen)322{323struct x509_parse_context *ctx = context;324ctx->cert->raw_serial = value;325ctx->cert->raw_serial_size = vlen;326return 0;327}328329/*330* Note some of the name segments from which we'll fabricate a name.331*/332int x509_extract_name_segment(void *context, size_t hdrlen,333unsigned char tag,334const void *value, size_t vlen)335{336struct x509_parse_context *ctx = context;337338switch (ctx->last_oid) {339case OID_commonName:340ctx->cn_size = vlen;341ctx->cn_offset = (unsigned long)value - ctx->data;342break;343case OID_organizationName:344ctx->o_size = vlen;345ctx->o_offset = (unsigned long)value - ctx->data;346break;347case OID_email_address:348ctx->email_size = vlen;349ctx->email_offset = (unsigned long)value - ctx->data;350break;351default:352break;353}354355return 0;356}357358/*359* Fabricate and save the issuer and subject names360*/361static int x509_fabricate_name(struct x509_parse_context *ctx, size_t hdrlen,362unsigned char tag,363char **_name, size_t vlen)364{365const void *name, *data = (const void *)ctx->data;366size_t namesize;367char *buffer;368369if (*_name)370return -EINVAL;371372/* Empty name string if no material */373if (!ctx->cn_size && !ctx->o_size && !ctx->email_size) {374buffer = kzalloc(1, GFP_KERNEL);375if (!buffer)376return -ENOMEM;377goto done;378}379380if (ctx->cn_size && ctx->o_size) {381/* Consider combining O and CN, but use only the CN if it is382* prefixed by the O, or a significant portion thereof.383*/384namesize = ctx->cn_size;385name = data + ctx->cn_offset;386if (ctx->cn_size >= ctx->o_size &&387memcmp(data + ctx->cn_offset, data + ctx->o_offset,388ctx->o_size) == 0)389goto single_component;390if (ctx->cn_size >= 7 &&391ctx->o_size >= 7 &&392memcmp(data + ctx->cn_offset, data + ctx->o_offset, 7) == 0)393goto single_component;394395buffer = kmalloc(ctx->o_size + 2 + ctx->cn_size + 1,396GFP_KERNEL);397if (!buffer)398return -ENOMEM;399400memcpy(buffer,401data + ctx->o_offset, ctx->o_size);402buffer[ctx->o_size + 0] = ':';403buffer[ctx->o_size + 1] = ' ';404memcpy(buffer + ctx->o_size + 2,405data + ctx->cn_offset, ctx->cn_size);406buffer[ctx->o_size + 2 + ctx->cn_size] = 0;407goto done;408409} else if (ctx->cn_size) {410namesize = ctx->cn_size;411name = data + ctx->cn_offset;412} else if (ctx->o_size) {413namesize = ctx->o_size;414name = data + ctx->o_offset;415} else {416namesize = ctx->email_size;417name = data + ctx->email_offset;418}419420single_component:421buffer = kmalloc(namesize + 1, GFP_KERNEL);422if (!buffer)423return -ENOMEM;424memcpy(buffer, name, namesize);425buffer[namesize] = 0;426427done:428*_name = buffer;429ctx->cn_size = 0;430ctx->o_size = 0;431ctx->email_size = 0;432return 0;433}434435int x509_note_issuer(void *context, size_t hdrlen,436unsigned char tag,437const void *value, size_t vlen)438{439struct x509_parse_context *ctx = context;440struct asymmetric_key_id *kid;441442ctx->cert->raw_issuer = value;443ctx->cert->raw_issuer_size = vlen;444445if (!ctx->cert->sig->auth_ids[2]) {446kid = asymmetric_key_generate_id(value, vlen, "", 0);447if (IS_ERR(kid))448return PTR_ERR(kid);449ctx->cert->sig->auth_ids[2] = kid;450}451452return x509_fabricate_name(ctx, hdrlen, tag, &ctx->cert->issuer, vlen);453}454455int x509_note_subject(void *context, size_t hdrlen,456unsigned char tag,457const void *value, size_t vlen)458{459struct x509_parse_context *ctx = context;460ctx->cert->raw_subject = value;461ctx->cert->raw_subject_size = vlen;462return x509_fabricate_name(ctx, hdrlen, tag, &ctx->cert->subject, vlen);463}464465/*466* Extract the parameters for the public key467*/468int x509_note_params(void *context, size_t hdrlen,469unsigned char tag,470const void *value, size_t vlen)471{472struct x509_parse_context *ctx = context;473474/*475* AlgorithmIdentifier is used three times in the x509, we should skip476* first and ignore third, using second one which is after subject and477* before subjectPublicKey.478*/479if (!ctx->cert->raw_subject || ctx->key)480return 0;481ctx->params = value - hdrlen;482ctx->params_size = vlen + hdrlen;483return 0;484}485486/*487* Extract the data for the public key algorithm488*/489int x509_extract_key_data(void *context, size_t hdrlen,490unsigned char tag,491const void *value, size_t vlen)492{493struct x509_parse_context *ctx = context;494enum OID oid;495496ctx->key_algo = ctx->last_oid;497switch (ctx->last_oid) {498case OID_rsaEncryption:499ctx->cert->pub->pkey_algo = "rsa";500break;501case OID_gost2012PKey256:502case OID_gost2012PKey512:503ctx->cert->pub->pkey_algo = "ecrdsa";504break;505case OID_id_ecPublicKey:506if (parse_OID(ctx->params, ctx->params_size, &oid) != 0)507return -EBADMSG;508509switch (oid) {510case OID_id_prime192v1:511ctx->cert->pub->pkey_algo = "ecdsa-nist-p192";512break;513case OID_id_prime256v1:514ctx->cert->pub->pkey_algo = "ecdsa-nist-p256";515break;516case OID_id_ansip384r1:517ctx->cert->pub->pkey_algo = "ecdsa-nist-p384";518break;519case OID_id_ansip521r1:520ctx->cert->pub->pkey_algo = "ecdsa-nist-p521";521break;522default:523return -ENOPKG;524}525break;526default:527return -ENOPKG;528}529530/* Discard the BIT STRING metadata */531if (vlen < 1 || *(const u8 *)value != 0)532return -EBADMSG;533ctx->key = value + 1;534ctx->key_size = vlen - 1;535return 0;536}537538/* The keyIdentifier in AuthorityKeyIdentifier SEQUENCE is tag(CONT,PRIM,0) */539#define SEQ_TAG_KEYID (ASN1_CONT << 6)540541/*542* Process certificate extensions that are used to qualify the certificate.543*/544int x509_process_extension(void *context, size_t hdrlen,545unsigned char tag,546const void *value, size_t vlen)547{548struct x509_parse_context *ctx = context;549struct asymmetric_key_id *kid;550const unsigned char *v = value;551552pr_debug("Extension: %u\n", ctx->last_oid);553554if (ctx->last_oid == OID_subjectKeyIdentifier) {555/* Get hold of the key fingerprint */556if (ctx->cert->skid || vlen < 3)557return -EBADMSG;558if (v[0] != ASN1_OTS || v[1] != vlen - 2)559return -EBADMSG;560v += 2;561vlen -= 2;562563ctx->cert->raw_skid_size = vlen;564ctx->cert->raw_skid = v;565kid = asymmetric_key_generate_id(v, vlen, "", 0);566if (IS_ERR(kid))567return PTR_ERR(kid);568ctx->cert->skid = kid;569pr_debug("subjkeyid %*phN\n", kid->len, kid->data);570return 0;571}572573if (ctx->last_oid == OID_keyUsage) {574/*575* Get hold of the keyUsage bit string576* v[1] is the encoding size577* (Expect either 0x02 or 0x03, making it 1 or 2 bytes)578* v[2] is the number of unused bits in the bit string579* (If >= 3 keyCertSign is missing when v[1] = 0x02)580* v[3] and possibly v[4] contain the bit string581*582* From RFC 5280 4.2.1.3:583* 0x04 is where keyCertSign lands in this bit string584* 0x80 is where digitalSignature lands in this bit string585*/586if (v[0] != ASN1_BTS)587return -EBADMSG;588if (vlen < 4)589return -EBADMSG;590if (v[2] >= 8)591return -EBADMSG;592if (v[3] & 0x80)593ctx->cert->pub->key_eflags |= 1 << KEY_EFLAG_DIGITALSIG;594if (v[1] == 0x02 && v[2] <= 2 && (v[3] & 0x04))595ctx->cert->pub->key_eflags |= 1 << KEY_EFLAG_KEYCERTSIGN;596else if (vlen > 4 && v[1] == 0x03 && (v[3] & 0x04))597ctx->cert->pub->key_eflags |= 1 << KEY_EFLAG_KEYCERTSIGN;598return 0;599}600601if (ctx->last_oid == OID_authorityKeyIdentifier) {602/* Get hold of the CA key fingerprint */603ctx->raw_akid = v;604ctx->raw_akid_size = vlen;605return 0;606}607608if (ctx->last_oid == OID_basicConstraints) {609/*610* Get hold of the basicConstraints611* v[1] is the encoding size612* (Expect 0x2 or greater, making it 1 or more bytes)613* v[2] is the encoding type614* (Expect an ASN1_BOOL for the CA)615* v[3] is the contents of the ASN1_BOOL616* (Expect 1 if the CA is TRUE)617* vlen should match the entire extension size618*/619if (v[0] != (ASN1_CONS_BIT | ASN1_SEQ))620return -EBADMSG;621if (vlen < 2)622return -EBADMSG;623if (v[1] != vlen - 2)624return -EBADMSG;625if (vlen >= 4 && v[1] != 0 && v[2] == ASN1_BOOL && v[3] == 1)626ctx->cert->pub->key_eflags |= 1 << KEY_EFLAG_CA;627return 0;628}629630return 0;631}632633/**634* x509_decode_time - Decode an X.509 time ASN.1 object635* @_t: The time to fill in636* @hdrlen: The length of the object header637* @tag: The object tag638* @value: The object value639* @vlen: The size of the object value640*641* Decode an ASN.1 universal time or generalised time field into a struct the642* kernel can handle and check it for validity. The time is decoded thus:643*644* [RFC5280 ยง4.1.2.5]645* CAs conforming to this profile MUST always encode certificate validity646* dates through the year 2049 as UTCTime; certificate validity dates in647* 2050 or later MUST be encoded as GeneralizedTime. Conforming648* applications MUST be able to process validity dates that are encoded in649* either UTCTime or GeneralizedTime.650*/651int x509_decode_time(time64_t *_t, size_t hdrlen,652unsigned char tag,653const unsigned char *value, size_t vlen)654{655static const unsigned char month_lengths[] = { 31, 28, 31, 30, 31, 30,65631, 31, 30, 31, 30, 31 };657const unsigned char *p = value;658unsigned year, mon, day, hour, min, sec, mon_len;659660#define dec2bin(X) ({ unsigned char x = (X) - '0'; if (x > 9) goto invalid_time; x; })661#define DD2bin(P) ({ unsigned x = dec2bin(P[0]) * 10 + dec2bin(P[1]); P += 2; x; })662663if (tag == ASN1_UNITIM) {664/* UTCTime: YYMMDDHHMMSSZ */665if (vlen != 13)666goto unsupported_time;667year = DD2bin(p);668if (year >= 50)669year += 1900;670else671year += 2000;672} else if (tag == ASN1_GENTIM) {673/* GenTime: YYYYMMDDHHMMSSZ */674if (vlen != 15)675goto unsupported_time;676year = DD2bin(p) * 100 + DD2bin(p);677if (year >= 1950 && year <= 2049)678goto invalid_time;679} else {680goto unsupported_time;681}682683mon = DD2bin(p);684day = DD2bin(p);685hour = DD2bin(p);686min = DD2bin(p);687sec = DD2bin(p);688689if (*p != 'Z')690goto unsupported_time;691692if (year < 1970 ||693mon < 1 || mon > 12)694goto invalid_time;695696mon_len = month_lengths[mon - 1];697if (mon == 2) {698if (year % 4 == 0) {699mon_len = 29;700if (year % 100 == 0) {701mon_len = 28;702if (year % 400 == 0)703mon_len = 29;704}705}706}707708if (day < 1 || day > mon_len ||709hour > 24 || /* ISO 8601 permits 24:00:00 as midnight tomorrow */710min > 59 ||711sec > 60) /* ISO 8601 permits leap seconds [X.680 46.3] */712goto invalid_time;713714*_t = mktime64(year, mon, day, hour, min, sec);715return 0;716717unsupported_time:718pr_debug("Got unsupported time [tag %02x]: '%*phN'\n",719tag, (int)vlen, value);720return -EBADMSG;721invalid_time:722pr_debug("Got invalid time [tag %02x]: '%*phN'\n",723tag, (int)vlen, value);724return -EBADMSG;725}726EXPORT_SYMBOL_GPL(x509_decode_time);727728int x509_note_not_before(void *context, size_t hdrlen,729unsigned char tag,730const void *value, size_t vlen)731{732struct x509_parse_context *ctx = context;733return x509_decode_time(&ctx->cert->valid_from, hdrlen, tag, value, vlen);734}735736int x509_note_not_after(void *context, size_t hdrlen,737unsigned char tag,738const void *value, size_t vlen)739{740struct x509_parse_context *ctx = context;741return x509_decode_time(&ctx->cert->valid_to, hdrlen, tag, value, vlen);742}743744/*745* Note a key identifier-based AuthorityKeyIdentifier746*/747int x509_akid_note_kid(void *context, size_t hdrlen,748unsigned char tag,749const void *value, size_t vlen)750{751struct x509_parse_context *ctx = context;752struct asymmetric_key_id *kid;753754pr_debug("AKID: keyid: %*phN\n", (int)vlen, value);755756if (ctx->cert->sig->auth_ids[1])757return 0;758759kid = asymmetric_key_generate_id(value, vlen, "", 0);760if (IS_ERR(kid))761return PTR_ERR(kid);762pr_debug("authkeyid %*phN\n", kid->len, kid->data);763ctx->cert->sig->auth_ids[1] = kid;764return 0;765}766767/*768* Note a directoryName in an AuthorityKeyIdentifier769*/770int x509_akid_note_name(void *context, size_t hdrlen,771unsigned char tag,772const void *value, size_t vlen)773{774struct x509_parse_context *ctx = context;775776pr_debug("AKID: name: %*phN\n", (int)vlen, value);777778ctx->akid_raw_issuer = value;779ctx->akid_raw_issuer_size = vlen;780return 0;781}782783/*784* Note a serial number in an AuthorityKeyIdentifier785*/786int x509_akid_note_serial(void *context, size_t hdrlen,787unsigned char tag,788const void *value, size_t vlen)789{790struct x509_parse_context *ctx = context;791struct asymmetric_key_id *kid;792793pr_debug("AKID: serial: %*phN\n", (int)vlen, value);794795if (!ctx->akid_raw_issuer || ctx->cert->sig->auth_ids[0])796return 0;797798kid = asymmetric_key_generate_id(value,799vlen,800ctx->akid_raw_issuer,801ctx->akid_raw_issuer_size);802if (IS_ERR(kid))803return PTR_ERR(kid);804805pr_debug("authkeyid %*phN\n", kid->len, kid->data);806ctx->cert->sig->auth_ids[0] = kid;807return 0;808}809810811