pkcs7_parser.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673
  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 = false;
  85. sinfo = msg->signed_infos;
  86. if (!sinfo)
  87. goto inconsistent;
  88. if (sinfo->authattrs) {
  89. want = true;
  90. msg->have_authattrs = true;
  91. }
  92. for (sinfo = sinfo->next; sinfo; sinfo = sinfo->next)
  93. if (!!sinfo->authattrs != want)
  94. goto inconsistent;
  95. return 0;
  96. inconsistent:
  97. pr_warn("Inconsistently supplied authAttrs\n");
  98. return -EINVAL;
  99. }
  100. /**
  101. * pkcs7_parse_message - Parse a PKCS#7 message
  102. * @data: The raw binary ASN.1 encoded message to be parsed
  103. * @datalen: The size of the encoded message
  104. */
  105. struct pkcs7_message *pkcs7_parse_message(const void *data, size_t datalen)
  106. {
  107. struct pkcs7_parse_context *ctx;
  108. struct pkcs7_message *msg = ERR_PTR(-ENOMEM);
  109. int ret;
  110. ctx = kzalloc(sizeof(struct pkcs7_parse_context), GFP_KERNEL);
  111. if (!ctx)
  112. goto out_no_ctx;
  113. ctx->msg = kzalloc(sizeof(struct pkcs7_message), GFP_KERNEL);
  114. if (!ctx->msg)
  115. goto out_no_msg;
  116. ctx->sinfo = kzalloc(sizeof(struct pkcs7_signed_info), GFP_KERNEL);
  117. if (!ctx->sinfo)
  118. goto out_no_sinfo;
  119. ctx->data = (unsigned long)data;
  120. ctx->ppcerts = &ctx->certs;
  121. ctx->ppsinfo = &ctx->msg->signed_infos;
  122. /* Attempt to decode the signature */
  123. ret = asn1_ber_decoder(&pkcs7_decoder, ctx, data, datalen);
  124. if (ret < 0) {
  125. msg = ERR_PTR(ret);
  126. goto out;
  127. }
  128. ret = pkcs7_check_authattrs(ctx->msg);
  129. if (ret < 0)
  130. goto out;
  131. msg = ctx->msg;
  132. ctx->msg = NULL;
  133. out:
  134. while (ctx->certs) {
  135. struct x509_certificate *cert = ctx->certs;
  136. ctx->certs = cert->next;
  137. x509_free_certificate(cert);
  138. }
  139. pkcs7_free_signed_info(ctx->sinfo);
  140. out_no_sinfo:
  141. pkcs7_free_message(ctx->msg);
  142. out_no_msg:
  143. kfree(ctx);
  144. out_no_ctx:
  145. return msg;
  146. }
  147. EXPORT_SYMBOL_GPL(pkcs7_parse_message);
  148. /**
  149. * pkcs7_get_content_data - Get access to the PKCS#7 content
  150. * @pkcs7: The preparsed PKCS#7 message to access
  151. * @_data: Place to return a pointer to the data
  152. * @_data_len: Place to return the data length
  153. * @want_wrapper: True if the ASN.1 object header should be included in the data
  154. *
  155. * Get access to the data content of the PKCS#7 message, including, optionally,
  156. * the header of the ASN.1 object that contains it. Returns -ENODATA if the
  157. * data object was missing from the message.
  158. */
  159. int pkcs7_get_content_data(const struct pkcs7_message *pkcs7,
  160. const void **_data, size_t *_data_len,
  161. bool want_wrapper)
  162. {
  163. size_t wrapper;
  164. if (!pkcs7->data)
  165. return -ENODATA;
  166. wrapper = want_wrapper ? pkcs7->data_hdrlen : 0;
  167. *_data = pkcs7->data - wrapper;
  168. *_data_len = pkcs7->data_len + wrapper;
  169. return 0;
  170. }
  171. EXPORT_SYMBOL_GPL(pkcs7_get_content_data);
  172. /*
  173. * Note an OID when we find one for later processing when we know how
  174. * to interpret it.
  175. */
  176. int pkcs7_note_OID(void *context, size_t hdrlen,
  177. unsigned char tag,
  178. const void *value, size_t vlen)
  179. {
  180. struct pkcs7_parse_context *ctx = context;
  181. ctx->last_oid = look_up_OID(value, vlen);
  182. if (ctx->last_oid == OID__NR) {
  183. char buffer[50];
  184. sprint_oid(value, vlen, buffer, sizeof(buffer));
  185. printk("PKCS7: Unknown OID: [%lu] %s\n",
  186. (unsigned long)value - ctx->data, buffer);
  187. }
  188. return 0;
  189. }
  190. /*
  191. * Note the digest algorithm for the signature.
  192. */
  193. int pkcs7_sig_note_digest_algo(void *context, size_t hdrlen,
  194. unsigned char tag,
  195. const void *value, size_t vlen)
  196. {
  197. struct pkcs7_parse_context *ctx = context;
  198. switch (ctx->last_oid) {
  199. case OID_md4:
  200. ctx->sinfo->sig.pkey_hash_algo = HASH_ALGO_MD4;
  201. break;
  202. case OID_md5:
  203. ctx->sinfo->sig.pkey_hash_algo = HASH_ALGO_MD5;
  204. break;
  205. case OID_sha1:
  206. ctx->sinfo->sig.pkey_hash_algo = HASH_ALGO_SHA1;
  207. break;
  208. case OID_sha256:
  209. ctx->sinfo->sig.pkey_hash_algo = HASH_ALGO_SHA256;
  210. break;
  211. case OID_sha384:
  212. ctx->sinfo->sig.pkey_hash_algo = HASH_ALGO_SHA384;
  213. break;
  214. case OID_sha512:
  215. ctx->sinfo->sig.pkey_hash_algo = HASH_ALGO_SHA512;
  216. break;
  217. case OID_sha224:
  218. ctx->sinfo->sig.pkey_hash_algo = HASH_ALGO_SHA224;
  219. default:
  220. printk("Unsupported digest algo: %u\n", ctx->last_oid);
  221. return -ENOPKG;
  222. }
  223. return 0;
  224. }
  225. /*
  226. * Note the public key algorithm for the signature.
  227. */
  228. int pkcs7_sig_note_pkey_algo(void *context, size_t hdrlen,
  229. unsigned char tag,
  230. const void *value, size_t vlen)
  231. {
  232. struct pkcs7_parse_context *ctx = context;
  233. switch (ctx->last_oid) {
  234. case OID_rsaEncryption:
  235. ctx->sinfo->sig.pkey_algo = PKEY_ALGO_RSA;
  236. break;
  237. default:
  238. printk("Unsupported pkey algo: %u\n", ctx->last_oid);
  239. return -ENOPKG;
  240. }
  241. return 0;
  242. }
  243. /*
  244. * We only support signed data [RFC2315 sec 9].
  245. */
  246. int pkcs7_check_content_type(void *context, size_t hdrlen,
  247. unsigned char tag,
  248. const void *value, size_t vlen)
  249. {
  250. struct pkcs7_parse_context *ctx = context;
  251. if (ctx->last_oid != OID_signed_data) {
  252. pr_warn("Only support pkcs7_signedData type\n");
  253. return -EINVAL;
  254. }
  255. return 0;
  256. }
  257. /*
  258. * Note the SignedData version
  259. */
  260. int pkcs7_note_signeddata_version(void *context, size_t hdrlen,
  261. unsigned char tag,
  262. const void *value, size_t vlen)
  263. {
  264. struct pkcs7_parse_context *ctx = context;
  265. unsigned version;
  266. if (vlen != 1)
  267. goto unsupported;
  268. ctx->msg->version = version = *(const u8 *)value;
  269. switch (version) {
  270. case 1:
  271. /* PKCS#7 SignedData [RFC2315 sec 9.1]
  272. * CMS ver 1 SignedData [RFC5652 sec 5.1]
  273. */
  274. break;
  275. case 3:
  276. /* CMS ver 3 SignedData [RFC2315 sec 5.1] */
  277. break;
  278. default:
  279. goto unsupported;
  280. }
  281. return 0;
  282. unsupported:
  283. pr_warn("Unsupported SignedData version\n");
  284. return -EINVAL;
  285. }
  286. /*
  287. * Note the SignerInfo version
  288. */
  289. int pkcs7_note_signerinfo_version(void *context, size_t hdrlen,
  290. unsigned char tag,
  291. const void *value, size_t vlen)
  292. {
  293. struct pkcs7_parse_context *ctx = context;
  294. unsigned version;
  295. if (vlen != 1)
  296. goto unsupported;
  297. version = *(const u8 *)value;
  298. switch (version) {
  299. case 1:
  300. /* PKCS#7 SignerInfo [RFC2315 sec 9.2]
  301. * CMS ver 1 SignerInfo [RFC5652 sec 5.3]
  302. */
  303. if (ctx->msg->version != 1)
  304. goto version_mismatch;
  305. ctx->expect_skid = false;
  306. break;
  307. case 3:
  308. /* CMS ver 3 SignerInfo [RFC2315 sec 5.3] */
  309. if (ctx->msg->version == 1)
  310. goto version_mismatch;
  311. ctx->expect_skid = true;
  312. break;
  313. default:
  314. goto unsupported;
  315. }
  316. return 0;
  317. unsupported:
  318. pr_warn("Unsupported SignerInfo version\n");
  319. return -EINVAL;
  320. version_mismatch:
  321. pr_warn("SignedData-SignerInfo version mismatch\n");
  322. return -EBADMSG;
  323. }
  324. /*
  325. * Extract a certificate and store it in the context.
  326. */
  327. int pkcs7_extract_cert(void *context, size_t hdrlen,
  328. unsigned char tag,
  329. const void *value, size_t vlen)
  330. {
  331. struct pkcs7_parse_context *ctx = context;
  332. struct x509_certificate *x509;
  333. if (tag != ((ASN1_UNIV << 6) | ASN1_CONS_BIT | ASN1_SEQ)) {
  334. pr_debug("Cert began with tag %02x at %lu\n",
  335. tag, (unsigned long)ctx - ctx->data);
  336. return -EBADMSG;
  337. }
  338. /* We have to correct for the header so that the X.509 parser can start
  339. * from the beginning. Note that since X.509 stipulates DER, there
  340. * probably shouldn't be an EOC trailer - but it is in PKCS#7 (which
  341. * stipulates BER).
  342. */
  343. value -= hdrlen;
  344. vlen += hdrlen;
  345. if (((u8*)value)[1] == 0x80)
  346. vlen += 2; /* Indefinite length - there should be an EOC */
  347. x509 = x509_cert_parse(value, vlen);
  348. if (IS_ERR(x509))
  349. return PTR_ERR(x509);
  350. x509->index = ++ctx->x509_index;
  351. pr_debug("Got cert %u for %s\n", x509->index, x509->subject);
  352. pr_debug("- fingerprint %*phN\n", x509->id->len, x509->id->data);
  353. *ctx->ppcerts = x509;
  354. ctx->ppcerts = &x509->next;
  355. return 0;
  356. }
  357. /*
  358. * Save the certificate list
  359. */
  360. int pkcs7_note_certificate_list(void *context, size_t hdrlen,
  361. unsigned char tag,
  362. const void *value, size_t vlen)
  363. {
  364. struct pkcs7_parse_context *ctx = context;
  365. pr_devel("Got cert list (%02x)\n", tag);
  366. *ctx->ppcerts = ctx->msg->certs;
  367. ctx->msg->certs = ctx->certs;
  368. ctx->certs = NULL;
  369. ctx->ppcerts = &ctx->certs;
  370. return 0;
  371. }
  372. /*
  373. * Note the content type.
  374. */
  375. int pkcs7_note_content(void *context, size_t hdrlen,
  376. unsigned char tag,
  377. const void *value, size_t vlen)
  378. {
  379. struct pkcs7_parse_context *ctx = context;
  380. if (ctx->last_oid != OID_data &&
  381. ctx->last_oid != OID_msIndirectData) {
  382. pr_warn("Unsupported data type %d\n", ctx->last_oid);
  383. return -EINVAL;
  384. }
  385. ctx->msg->data_type = ctx->last_oid;
  386. return 0;
  387. }
  388. /*
  389. * Extract the data from the message and store that and its content type OID in
  390. * the context.
  391. */
  392. int pkcs7_note_data(void *context, size_t hdrlen,
  393. unsigned char tag,
  394. const void *value, size_t vlen)
  395. {
  396. struct pkcs7_parse_context *ctx = context;
  397. pr_debug("Got data\n");
  398. ctx->msg->data = value;
  399. ctx->msg->data_len = vlen;
  400. ctx->msg->data_hdrlen = hdrlen;
  401. return 0;
  402. }
  403. /*
  404. * Parse authenticated attributes.
  405. */
  406. int pkcs7_sig_note_authenticated_attr(void *context, size_t hdrlen,
  407. unsigned char tag,
  408. const void *value, size_t vlen)
  409. {
  410. struct pkcs7_parse_context *ctx = context;
  411. struct pkcs7_signed_info *sinfo = ctx->sinfo;
  412. enum OID content_type;
  413. pr_devel("AuthAttr: %02x %zu [%*ph]\n", tag, vlen, (unsigned)vlen, value);
  414. switch (ctx->last_oid) {
  415. case OID_contentType:
  416. if (__test_and_set_bit(sinfo_has_content_type, &sinfo->aa_set))
  417. goto repeated;
  418. content_type = look_up_OID(value, vlen);
  419. if (content_type != ctx->msg->data_type) {
  420. pr_warn("Mismatch between global data type (%d) and sinfo %u (%d)\n",
  421. ctx->msg->data_type, sinfo->index,
  422. content_type);
  423. return -EBADMSG;
  424. }
  425. return 0;
  426. case OID_signingTime:
  427. if (__test_and_set_bit(sinfo_has_signing_time, &sinfo->aa_set))
  428. goto repeated;
  429. /* Should we check that the signing time is consistent
  430. * with the signer's X.509 cert?
  431. */
  432. return x509_decode_time(&sinfo->signing_time,
  433. hdrlen, tag, value, vlen);
  434. case OID_messageDigest:
  435. if (__test_and_set_bit(sinfo_has_message_digest, &sinfo->aa_set))
  436. goto repeated;
  437. if (tag != ASN1_OTS)
  438. return -EBADMSG;
  439. sinfo->msgdigest = value;
  440. sinfo->msgdigest_len = vlen;
  441. return 0;
  442. case OID_smimeCapabilites:
  443. if (__test_and_set_bit(sinfo_has_smime_caps, &sinfo->aa_set))
  444. goto repeated;
  445. if (ctx->msg->data_type != OID_msIndirectData) {
  446. pr_warn("S/MIME Caps only allowed with Authenticode\n");
  447. return -EKEYREJECTED;
  448. }
  449. return 0;
  450. /* Microsoft SpOpusInfo seems to be contain cont[0] 16-bit BE
  451. * char URLs and cont[1] 8-bit char URLs.
  452. *
  453. * Microsoft StatementType seems to contain a list of OIDs that
  454. * are also used as extendedKeyUsage types in X.509 certs.
  455. */
  456. case OID_msSpOpusInfo:
  457. if (__test_and_set_bit(sinfo_has_ms_opus_info, &sinfo->aa_set))
  458. goto repeated;
  459. goto authenticode_check;
  460. case OID_msStatementType:
  461. if (__test_and_set_bit(sinfo_has_ms_statement_type, &sinfo->aa_set))
  462. goto repeated;
  463. authenticode_check:
  464. if (ctx->msg->data_type != OID_msIndirectData) {
  465. pr_warn("Authenticode AuthAttrs only allowed with Authenticode\n");
  466. return -EKEYREJECTED;
  467. }
  468. /* I'm not sure how to validate these */
  469. return 0;
  470. default:
  471. return 0;
  472. }
  473. repeated:
  474. /* We permit max one item per AuthenticatedAttribute and no repeats */
  475. pr_warn("Repeated/multivalue AuthAttrs not permitted\n");
  476. return -EKEYREJECTED;
  477. }
  478. /*
  479. * Note the set of auth attributes for digestion purposes [RFC2315 sec 9.3]
  480. */
  481. int pkcs7_sig_note_set_of_authattrs(void *context, size_t hdrlen,
  482. unsigned char tag,
  483. const void *value, size_t vlen)
  484. {
  485. struct pkcs7_parse_context *ctx = context;
  486. struct pkcs7_signed_info *sinfo = ctx->sinfo;
  487. if (!test_bit(sinfo_has_content_type, &sinfo->aa_set) ||
  488. !test_bit(sinfo_has_message_digest, &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. }