pkcs7_parser.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672
  1. /* PKCS#7 parser
  2. *
  3. * Copyright (C) 2012 Red Hat, Inc. All Rights Reserved.
  4. * Written by David Howells (dhowells@redhat.com)
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public Licence
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the Licence, or (at your option) any later version.
  10. */
  11. #define pr_fmt(fmt) "PKCS7: "fmt
  12. #include <linux/kernel.h>
  13. #include <linux/export.h>
  14. #include <linux/slab.h>
  15. #include <linux/err.h>
  16. #include <linux/oid_registry.h>
  17. #include "public_key.h"
  18. #include "pkcs7_parser.h"
  19. #include "pkcs7-asn1.h"
  20. struct pkcs7_parse_context {
  21. struct pkcs7_message *msg; /* Message being constructed */
  22. struct pkcs7_signed_info *sinfo; /* SignedInfo being constructed */
  23. struct pkcs7_signed_info **ppsinfo;
  24. struct x509_certificate *certs; /* Certificate cache */
  25. struct x509_certificate **ppcerts;
  26. unsigned long data; /* Start of data */
  27. enum OID last_oid; /* Last OID encountered */
  28. unsigned x509_index;
  29. unsigned sinfo_index;
  30. const void *raw_serial;
  31. unsigned raw_serial_size;
  32. unsigned raw_issuer_size;
  33. const void *raw_issuer;
  34. const void *raw_skid;
  35. unsigned raw_skid_size;
  36. bool expect_skid;
  37. };
  38. /*
  39. * Free a signed information block.
  40. */
  41. static void pkcs7_free_signed_info(struct pkcs7_signed_info *sinfo)
  42. {
  43. if (sinfo) {
  44. mpi_free(sinfo->sig.mpi[0]);
  45. kfree(sinfo->sig.digest);
  46. kfree(sinfo->signing_cert_id);
  47. kfree(sinfo);
  48. }
  49. }
  50. /**
  51. * pkcs7_free_message - Free a PKCS#7 message
  52. * @pkcs7: The PKCS#7 message to free
  53. */
  54. void pkcs7_free_message(struct pkcs7_message *pkcs7)
  55. {
  56. struct x509_certificate *cert;
  57. struct pkcs7_signed_info *sinfo;
  58. if (pkcs7) {
  59. while (pkcs7->certs) {
  60. cert = pkcs7->certs;
  61. pkcs7->certs = cert->next;
  62. x509_free_certificate(cert);
  63. }
  64. while (pkcs7->crl) {
  65. cert = pkcs7->crl;
  66. pkcs7->crl = cert->next;
  67. x509_free_certificate(cert);
  68. }
  69. while (pkcs7->signed_infos) {
  70. sinfo = pkcs7->signed_infos;
  71. pkcs7->signed_infos = sinfo->next;
  72. pkcs7_free_signed_info(sinfo);
  73. }
  74. kfree(pkcs7);
  75. }
  76. }
  77. EXPORT_SYMBOL_GPL(pkcs7_free_message);
  78. /*
  79. * Check authenticatedAttributes are provided or not provided consistently.
  80. */
  81. static int pkcs7_check_authattrs(struct pkcs7_message *msg)
  82. {
  83. struct pkcs7_signed_info *sinfo;
  84. bool want;
  85. sinfo = msg->signed_infos;
  86. if (sinfo->authattrs) {
  87. want = true;
  88. msg->have_authattrs = true;
  89. }
  90. for (sinfo = sinfo->next; sinfo; sinfo = sinfo->next)
  91. if (!!sinfo->authattrs != want)
  92. goto inconsistent;
  93. return 0;
  94. inconsistent:
  95. pr_warn("Inconsistently supplied authAttrs\n");
  96. return -EINVAL;
  97. }
  98. /**
  99. * pkcs7_parse_message - Parse a PKCS#7 message
  100. * @data: The raw binary ASN.1 encoded message to be parsed
  101. * @datalen: The size of the encoded message
  102. */
  103. struct pkcs7_message *pkcs7_parse_message(const void *data, size_t datalen)
  104. {
  105. struct pkcs7_parse_context *ctx;
  106. struct pkcs7_message *msg = ERR_PTR(-ENOMEM);
  107. int ret;
  108. ctx = kzalloc(sizeof(struct pkcs7_parse_context), GFP_KERNEL);
  109. if (!ctx)
  110. goto out_no_ctx;
  111. ctx->msg = kzalloc(sizeof(struct pkcs7_message), GFP_KERNEL);
  112. if (!ctx->msg)
  113. goto out_no_msg;
  114. ctx->sinfo = kzalloc(sizeof(struct pkcs7_signed_info), GFP_KERNEL);
  115. if (!ctx->sinfo)
  116. goto out_no_sinfo;
  117. ctx->data = (unsigned long)data;
  118. ctx->ppcerts = &ctx->certs;
  119. ctx->ppsinfo = &ctx->msg->signed_infos;
  120. /* Attempt to decode the signature */
  121. ret = asn1_ber_decoder(&pkcs7_decoder, ctx, data, datalen);
  122. if (ret < 0) {
  123. msg = ERR_PTR(ret);
  124. goto out;
  125. }
  126. ret = pkcs7_check_authattrs(ctx->msg);
  127. if (ret < 0)
  128. goto out;
  129. msg = ctx->msg;
  130. ctx->msg = NULL;
  131. out:
  132. while (ctx->certs) {
  133. struct x509_certificate *cert = ctx->certs;
  134. ctx->certs = cert->next;
  135. x509_free_certificate(cert);
  136. }
  137. pkcs7_free_signed_info(ctx->sinfo);
  138. out_no_sinfo:
  139. pkcs7_free_message(ctx->msg);
  140. out_no_msg:
  141. kfree(ctx);
  142. out_no_ctx:
  143. return msg;
  144. }
  145. EXPORT_SYMBOL_GPL(pkcs7_parse_message);
  146. /**
  147. * pkcs7_get_content_data - Get access to the PKCS#7 content
  148. * @pkcs7: The preparsed PKCS#7 message to access
  149. * @_data: Place to return a pointer to the data
  150. * @_data_len: Place to return the data length
  151. * @want_wrapper: True if the ASN.1 object header should be included in the data
  152. *
  153. * Get access to the data content of the PKCS#7 message, including, optionally,
  154. * the header of the ASN.1 object that contains it. Returns -ENODATA if the
  155. * data object was missing from the message.
  156. */
  157. int pkcs7_get_content_data(const struct pkcs7_message *pkcs7,
  158. const void **_data, size_t *_data_len,
  159. bool want_wrapper)
  160. {
  161. size_t wrapper;
  162. if (!pkcs7->data)
  163. return -ENODATA;
  164. wrapper = want_wrapper ? pkcs7->data_hdrlen : 0;
  165. *_data = pkcs7->data - wrapper;
  166. *_data_len = pkcs7->data_len + wrapper;
  167. return 0;
  168. }
  169. EXPORT_SYMBOL_GPL(pkcs7_get_content_data);
  170. /*
  171. * Note an OID when we find one for later processing when we know how
  172. * to interpret it.
  173. */
  174. int pkcs7_note_OID(void *context, size_t hdrlen,
  175. unsigned char tag,
  176. const void *value, size_t vlen)
  177. {
  178. struct pkcs7_parse_context *ctx = context;
  179. ctx->last_oid = look_up_OID(value, vlen);
  180. if (ctx->last_oid == OID__NR) {
  181. char buffer[50];
  182. sprint_oid(value, vlen, buffer, sizeof(buffer));
  183. printk("PKCS7: Unknown OID: [%lu] %s\n",
  184. (unsigned long)value - ctx->data, buffer);
  185. }
  186. return 0;
  187. }
  188. /*
  189. * Note the digest algorithm for the signature.
  190. */
  191. int pkcs7_sig_note_digest_algo(void *context, size_t hdrlen,
  192. unsigned char tag,
  193. const void *value, size_t vlen)
  194. {
  195. struct pkcs7_parse_context *ctx = context;
  196. switch (ctx->last_oid) {
  197. case OID_md4:
  198. ctx->sinfo->sig.pkey_hash_algo = HASH_ALGO_MD4;
  199. break;
  200. case OID_md5:
  201. ctx->sinfo->sig.pkey_hash_algo = HASH_ALGO_MD5;
  202. break;
  203. case OID_sha1:
  204. ctx->sinfo->sig.pkey_hash_algo = HASH_ALGO_SHA1;
  205. break;
  206. case OID_sha256:
  207. ctx->sinfo->sig.pkey_hash_algo = HASH_ALGO_SHA256;
  208. break;
  209. case OID_sha384:
  210. ctx->sinfo->sig.pkey_hash_algo = HASH_ALGO_SHA384;
  211. break;
  212. case OID_sha512:
  213. ctx->sinfo->sig.pkey_hash_algo = HASH_ALGO_SHA512;
  214. break;
  215. case OID_sha224:
  216. ctx->sinfo->sig.pkey_hash_algo = HASH_ALGO_SHA224;
  217. default:
  218. printk("Unsupported digest algo: %u\n", ctx->last_oid);
  219. return -ENOPKG;
  220. }
  221. return 0;
  222. }
  223. /*
  224. * Note the public key algorithm for the signature.
  225. */
  226. int pkcs7_sig_note_pkey_algo(void *context, size_t hdrlen,
  227. unsigned char tag,
  228. const void *value, size_t vlen)
  229. {
  230. struct pkcs7_parse_context *ctx = context;
  231. switch (ctx->last_oid) {
  232. case OID_rsaEncryption:
  233. ctx->sinfo->sig.pkey_algo = PKEY_ALGO_RSA;
  234. break;
  235. default:
  236. printk("Unsupported pkey algo: %u\n", ctx->last_oid);
  237. return -ENOPKG;
  238. }
  239. return 0;
  240. }
  241. /*
  242. * We only support signed data [RFC2315 sec 9].
  243. */
  244. int pkcs7_check_content_type(void *context, size_t hdrlen,
  245. unsigned char tag,
  246. const void *value, size_t vlen)
  247. {
  248. struct pkcs7_parse_context *ctx = context;
  249. if (ctx->last_oid != OID_signed_data) {
  250. pr_warn("Only support pkcs7_signedData type\n");
  251. return -EINVAL;
  252. }
  253. return 0;
  254. }
  255. /*
  256. * Note the SignedData version
  257. */
  258. int pkcs7_note_signeddata_version(void *context, size_t hdrlen,
  259. unsigned char tag,
  260. const void *value, size_t vlen)
  261. {
  262. struct pkcs7_parse_context *ctx = context;
  263. unsigned version;
  264. if (vlen != 1)
  265. goto unsupported;
  266. ctx->msg->version = version = *(const u8 *)value;
  267. switch (version) {
  268. case 1:
  269. /* PKCS#7 SignedData [RFC2315 sec 9.1]
  270. * CMS ver 1 SignedData [RFC5652 sec 5.1]
  271. */
  272. break;
  273. case 3:
  274. /* CMS ver 3 SignedData [RFC2315 sec 5.1] */
  275. break;
  276. default:
  277. goto unsupported;
  278. }
  279. return 0;
  280. unsupported:
  281. pr_warn("Unsupported SignedData version\n");
  282. return -EINVAL;
  283. }
  284. /*
  285. * Note the SignerInfo version
  286. */
  287. int pkcs7_note_signerinfo_version(void *context, size_t hdrlen,
  288. unsigned char tag,
  289. const void *value, size_t vlen)
  290. {
  291. struct pkcs7_parse_context *ctx = context;
  292. unsigned version;
  293. if (vlen != 1)
  294. goto unsupported;
  295. version = *(const u8 *)value;
  296. switch (version) {
  297. case 1:
  298. /* PKCS#7 SignerInfo [RFC2315 sec 9.2]
  299. * CMS ver 1 SignerInfo [RFC5652 sec 5.3]
  300. */
  301. if (ctx->msg->version != 1)
  302. goto version_mismatch;
  303. ctx->expect_skid = false;
  304. break;
  305. case 3:
  306. /* CMS ver 3 SignerInfo [RFC2315 sec 5.3] */
  307. if (ctx->msg->version == 1)
  308. goto version_mismatch;
  309. ctx->expect_skid = true;
  310. break;
  311. default:
  312. goto unsupported;
  313. }
  314. return 0;
  315. unsupported:
  316. pr_warn("Unsupported SignerInfo version\n");
  317. return -EINVAL;
  318. version_mismatch:
  319. pr_warn("SignedData-SignerInfo version mismatch\n");
  320. return -EBADMSG;
  321. }
  322. /*
  323. * Extract a certificate and store it in the context.
  324. */
  325. int pkcs7_extract_cert(void *context, size_t hdrlen,
  326. unsigned char tag,
  327. const void *value, size_t vlen)
  328. {
  329. struct pkcs7_parse_context *ctx = context;
  330. struct x509_certificate *x509;
  331. if (tag != ((ASN1_UNIV << 6) | ASN1_CONS_BIT | ASN1_SEQ)) {
  332. pr_debug("Cert began with tag %02x at %lu\n",
  333. tag, (unsigned long)ctx - ctx->data);
  334. return -EBADMSG;
  335. }
  336. /* We have to correct for the header so that the X.509 parser can start
  337. * from the beginning. Note that since X.509 stipulates DER, there
  338. * probably shouldn't be an EOC trailer - but it is in PKCS#7 (which
  339. * stipulates BER).
  340. */
  341. value -= hdrlen;
  342. vlen += hdrlen;
  343. if (((u8*)value)[1] == 0x80)
  344. vlen += 2; /* Indefinite length - there should be an EOC */
  345. x509 = x509_cert_parse(value, vlen);
  346. if (IS_ERR(x509))
  347. return PTR_ERR(x509);
  348. x509->index = ++ctx->x509_index;
  349. pr_debug("Got cert %u for %s\n", x509->index, x509->subject);
  350. pr_debug("- fingerprint %*phN\n", x509->id->len, x509->id->data);
  351. *ctx->ppcerts = x509;
  352. ctx->ppcerts = &x509->next;
  353. return 0;
  354. }
  355. /*
  356. * Save the certificate list
  357. */
  358. int pkcs7_note_certificate_list(void *context, size_t hdrlen,
  359. unsigned char tag,
  360. const void *value, size_t vlen)
  361. {
  362. struct pkcs7_parse_context *ctx = context;
  363. pr_devel("Got cert list (%02x)\n", tag);
  364. *ctx->ppcerts = ctx->msg->certs;
  365. ctx->msg->certs = ctx->certs;
  366. ctx->certs = NULL;
  367. ctx->ppcerts = &ctx->certs;
  368. return 0;
  369. }
  370. /*
  371. * Note the content type.
  372. */
  373. int pkcs7_note_content(void *context, size_t hdrlen,
  374. unsigned char tag,
  375. const void *value, size_t vlen)
  376. {
  377. struct pkcs7_parse_context *ctx = context;
  378. if (ctx->last_oid != OID_data &&
  379. ctx->last_oid != OID_msIndirectData) {
  380. pr_warn("Unsupported data type %d\n", ctx->last_oid);
  381. return -EINVAL;
  382. }
  383. ctx->msg->data_type = ctx->last_oid;
  384. return 0;
  385. }
  386. /*
  387. * Extract the data from the message and store that and its content type OID in
  388. * the context.
  389. */
  390. int pkcs7_note_data(void *context, size_t hdrlen,
  391. unsigned char tag,
  392. const void *value, size_t vlen)
  393. {
  394. struct pkcs7_parse_context *ctx = context;
  395. pr_debug("Got data\n");
  396. ctx->msg->data = value;
  397. ctx->msg->data_len = vlen;
  398. ctx->msg->data_hdrlen = hdrlen;
  399. return 0;
  400. }
  401. /*
  402. * Parse authenticated attributes.
  403. */
  404. int pkcs7_sig_note_authenticated_attr(void *context, size_t hdrlen,
  405. unsigned char tag,
  406. const void *value, size_t vlen)
  407. {
  408. struct pkcs7_parse_context *ctx = context;
  409. struct pkcs7_signed_info *sinfo = ctx->sinfo;
  410. enum OID content_type;
  411. pr_devel("AuthAttr: %02x %zu [%*ph]\n", tag, vlen, (unsigned)vlen, value);
  412. switch (ctx->last_oid) {
  413. case OID_contentType:
  414. if (__test_and_set_bit(sinfo_has_content_type, &sinfo->aa_set))
  415. goto repeated;
  416. content_type = look_up_OID(value, vlen);
  417. if (content_type != ctx->msg->data_type) {
  418. pr_warn("Mismatch between global data type (%d) and sinfo %u (%d)\n",
  419. ctx->msg->data_type, sinfo->index,
  420. content_type);
  421. return -EBADMSG;
  422. }
  423. return 0;
  424. case OID_signingTime:
  425. if (__test_and_set_bit(sinfo_has_signing_time, &sinfo->aa_set))
  426. goto repeated;
  427. /* Should we check that the signing time is consistent
  428. * with the signer's X.509 cert?
  429. */
  430. return x509_decode_time(&sinfo->signing_time,
  431. hdrlen, tag, value, vlen);
  432. case OID_messageDigest:
  433. if (__test_and_set_bit(sinfo_has_message_digest, &sinfo->aa_set))
  434. goto repeated;
  435. if (tag != ASN1_OTS)
  436. return -EBADMSG;
  437. sinfo->msgdigest = value;
  438. sinfo->msgdigest_len = vlen;
  439. return 0;
  440. case OID_smimeCapabilites:
  441. if (__test_and_set_bit(sinfo_has_smime_caps, &sinfo->aa_set))
  442. goto repeated;
  443. if (ctx->msg->data_type != OID_msIndirectData) {
  444. pr_warn("S/MIME Caps only allowed with Authenticode\n");
  445. return -EKEYREJECTED;
  446. }
  447. return 0;
  448. /* Microsoft SpOpusInfo seems to be contain cont[0] 16-bit BE
  449. * char URLs and cont[1] 8-bit char URLs.
  450. *
  451. * Microsoft StatementType seems to contain a list of OIDs that
  452. * are also used as extendedKeyUsage types in X.509 certs.
  453. */
  454. case OID_msSpOpusInfo:
  455. if (__test_and_set_bit(sinfo_has_ms_opus_info, &sinfo->aa_set))
  456. goto repeated;
  457. goto authenticode_check;
  458. case OID_msStatementType:
  459. if (__test_and_set_bit(sinfo_has_ms_statement_type, &sinfo->aa_set))
  460. goto repeated;
  461. authenticode_check:
  462. if (ctx->msg->data_type != OID_msIndirectData) {
  463. pr_warn("Authenticode AuthAttrs only allowed with Authenticode\n");
  464. return -EKEYREJECTED;
  465. }
  466. /* I'm not sure how to validate these */
  467. return 0;
  468. default:
  469. return 0;
  470. }
  471. repeated:
  472. /* We permit max one item per AuthenticatedAttribute and no repeats */
  473. pr_warn("Repeated/multivalue AuthAttrs not permitted\n");
  474. return -EKEYREJECTED;
  475. }
  476. /*
  477. * Note the set of auth attributes for digestion purposes [RFC2315 sec 9.3]
  478. */
  479. int pkcs7_sig_note_set_of_authattrs(void *context, size_t hdrlen,
  480. unsigned char tag,
  481. const void *value, size_t vlen)
  482. {
  483. struct pkcs7_parse_context *ctx = context;
  484. struct pkcs7_signed_info *sinfo = ctx->sinfo;
  485. if (!test_bit(sinfo_has_content_type, &sinfo->aa_set) ||
  486. !test_bit(sinfo_has_message_digest, &sinfo->aa_set) ||
  487. (ctx->msg->data_type == OID_msIndirectData &&
  488. !test_bit(sinfo_has_ms_opus_info, &sinfo->aa_set))) {
  489. pr_warn("Missing required AuthAttr\n");
  490. return -EBADMSG;
  491. }
  492. if (ctx->msg->data_type != OID_msIndirectData &&
  493. test_bit(sinfo_has_ms_opus_info, &sinfo->aa_set)) {
  494. pr_warn("Unexpected Authenticode AuthAttr\n");
  495. return -EBADMSG;
  496. }
  497. /* We need to switch the 'CONT 0' to a 'SET OF' when we digest */
  498. sinfo->authattrs = value - (hdrlen - 1);
  499. sinfo->authattrs_len = vlen + (hdrlen - 1);
  500. return 0;
  501. }
  502. /*
  503. * Note the issuing certificate serial number
  504. */
  505. int pkcs7_sig_note_serial(void *context, size_t hdrlen,
  506. unsigned char tag,
  507. const void *value, size_t vlen)
  508. {
  509. struct pkcs7_parse_context *ctx = context;
  510. ctx->raw_serial = value;
  511. ctx->raw_serial_size = vlen;
  512. return 0;
  513. }
  514. /*
  515. * Note the issuer's name
  516. */
  517. int pkcs7_sig_note_issuer(void *context, size_t hdrlen,
  518. unsigned char tag,
  519. const void *value, size_t vlen)
  520. {
  521. struct pkcs7_parse_context *ctx = context;
  522. ctx->raw_issuer = value;
  523. ctx->raw_issuer_size = vlen;
  524. return 0;
  525. }
  526. /*
  527. * Note the issuing cert's subjectKeyIdentifier
  528. */
  529. int pkcs7_sig_note_skid(void *context, size_t hdrlen,
  530. unsigned char tag,
  531. const void *value, size_t vlen)
  532. {
  533. struct pkcs7_parse_context *ctx = context;
  534. pr_devel("SKID: %02x %zu [%*ph]\n", tag, vlen, (unsigned)vlen, value);
  535. ctx->raw_skid = value;
  536. ctx->raw_skid_size = vlen;
  537. return 0;
  538. }
  539. /*
  540. * Note the signature data
  541. */
  542. int pkcs7_sig_note_signature(void *context, size_t hdrlen,
  543. unsigned char tag,
  544. const void *value, size_t vlen)
  545. {
  546. struct pkcs7_parse_context *ctx = context;
  547. MPI mpi;
  548. BUG_ON(ctx->sinfo->sig.pkey_algo != PKEY_ALGO_RSA);
  549. mpi = mpi_read_raw_data(value, vlen);
  550. if (!mpi)
  551. return -ENOMEM;
  552. ctx->sinfo->sig.mpi[0] = mpi;
  553. ctx->sinfo->sig.nr_mpi = 1;
  554. return 0;
  555. }
  556. /*
  557. * Note a signature information block
  558. */
  559. int pkcs7_note_signed_info(void *context, size_t hdrlen,
  560. unsigned char tag,
  561. const void *value, size_t vlen)
  562. {
  563. struct pkcs7_parse_context *ctx = context;
  564. struct pkcs7_signed_info *sinfo = ctx->sinfo;
  565. struct asymmetric_key_id *kid;
  566. if (ctx->msg->data_type == OID_msIndirectData && !sinfo->authattrs) {
  567. pr_warn("Authenticode requires AuthAttrs\n");
  568. return -EBADMSG;
  569. }
  570. /* Generate cert issuer + serial number key ID */
  571. if (!ctx->expect_skid) {
  572. kid = asymmetric_key_generate_id(ctx->raw_serial,
  573. ctx->raw_serial_size,
  574. ctx->raw_issuer,
  575. ctx->raw_issuer_size);
  576. } else {
  577. kid = asymmetric_key_generate_id(ctx->raw_skid,
  578. ctx->raw_skid_size,
  579. "", 0);
  580. }
  581. if (IS_ERR(kid))
  582. return PTR_ERR(kid);
  583. pr_devel("SINFO KID: %u [%*phN]\n", kid->len, kid->len, kid->data);
  584. sinfo->signing_cert_id = kid;
  585. sinfo->index = ++ctx->sinfo_index;
  586. *ctx->ppsinfo = sinfo;
  587. ctx->ppsinfo = &sinfo->next;
  588. ctx->sinfo = kzalloc(sizeof(struct pkcs7_signed_info), GFP_KERNEL);
  589. if (!ctx->sinfo)
  590. return -ENOMEM;
  591. return 0;
  592. }