pkcs7_parser.c 16 KB

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