Blame view
crypto/asymmetric_keys/mscode_parser.c
2.71 KB
b4d0d230c treewide: Replace... |
1 |
// SPDX-License-Identifier: GPL-2.0-or-later |
4c0b4b1d1 pefile: Parse the... |
2 3 4 5 |
/* Parse a Microsoft Individual Code Signing blob * * Copyright (C) 2014 Red Hat, Inc. All Rights Reserved. * Written by David Howells (dhowells@redhat.com) |
4c0b4b1d1 pefile: Parse the... |
6 7 8 9 10 11 12 13 14 |
*/ #define pr_fmt(fmt) "MSCODE: "fmt #include <linux/kernel.h> #include <linux/slab.h> #include <linux/err.h> #include <linux/oid_registry.h> #include <crypto/pkcs7.h> #include "verify_pefile.h" |
4fa8bc949 kbuild: rename *-... |
15 |
#include "mscode.asn1.h" |
4c0b4b1d1 pefile: Parse the... |
16 17 18 19 |
/* * Parse a Microsoft Individual Code Signing blob */ |
e68503bd6 KEYS: Generalise ... |
20 21 |
int mscode_parse(void *_ctx, const void *content_data, size_t data_len, size_t asn1hdrlen) |
4c0b4b1d1 pefile: Parse the... |
22 |
{ |
e68503bd6 KEYS: Generalise ... |
23 |
struct pefile_context *ctx = _ctx; |
4c0b4b1d1 pefile: Parse the... |
24 |
|
e68503bd6 KEYS: Generalise ... |
25 26 |
content_data -= asn1hdrlen; data_len += asn1hdrlen; |
4c0b4b1d1 pefile: Parse the... |
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
pr_devel("Data: %zu [%*ph] ", data_len, (unsigned)(data_len), content_data); return asn1_ber_decoder(&mscode_decoder, ctx, content_data, data_len); } /* * Check the content type OID */ int mscode_note_content_type(void *context, size_t hdrlen, unsigned char tag, const void *value, size_t vlen) { enum OID oid; oid = look_up_OID(value, vlen); if (oid == OID__NR) { char buffer[50]; sprint_oid(value, vlen, buffer, sizeof(buffer)); pr_err("Unknown OID: %s ", buffer); return -EBADMSG; } |
dd7d66f21 pefile: Handle pe... |
52 53 54 55 56 57 58 |
/* * pesign utility had a bug where it was putting * OID_msIndividualSPKeyPurpose instead of OID_msPeImageDataObjId * So allow both OIDs. */ if (oid != OID_msPeImageDataObjId && oid != OID_msIndividualSPKeyPurpose) { |
4c0b4b1d1 pefile: Parse the... |
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
pr_err("Unexpected content type OID %u ", oid); return -EBADMSG; } return 0; } /* * Note the digest algorithm OID */ int mscode_note_digest_algo(void *context, size_t hdrlen, unsigned char tag, const void *value, size_t vlen) { struct pefile_context *ctx = context; char buffer[50]; enum OID oid; oid = look_up_OID(value, vlen); switch (oid) { case OID_md4: |
4e8ae72a7 X.509: Make algo ... |
81 |
ctx->digest_algo = "md4"; |
4c0b4b1d1 pefile: Parse the... |
82 83 |
break; case OID_md5: |
4e8ae72a7 X.509: Make algo ... |
84 |
ctx->digest_algo = "md5"; |
4c0b4b1d1 pefile: Parse the... |
85 86 |
break; case OID_sha1: |
4e8ae72a7 X.509: Make algo ... |
87 |
ctx->digest_algo = "sha1"; |
4c0b4b1d1 pefile: Parse the... |
88 89 |
break; case OID_sha256: |
4e8ae72a7 X.509: Make algo ... |
90 |
ctx->digest_algo = "sha256"; |
4c0b4b1d1 pefile: Parse the... |
91 |
break; |
07f081fb5 PKCS#7: Add OIDs ... |
92 |
case OID_sha384: |
4e8ae72a7 X.509: Make algo ... |
93 |
ctx->digest_algo = "sha384"; |
07f081fb5 PKCS#7: Add OIDs ... |
94 95 |
break; case OID_sha512: |
4e8ae72a7 X.509: Make algo ... |
96 |
ctx->digest_algo = "sha512"; |
07f081fb5 PKCS#7: Add OIDs ... |
97 98 |
break; case OID_sha224: |
4e8ae72a7 X.509: Make algo ... |
99 |
ctx->digest_algo = "sha224"; |
07f081fb5 PKCS#7: Add OIDs ... |
100 |
break; |
4c0b4b1d1 pefile: Parse the... |
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
case OID__NR: sprint_oid(value, vlen, buffer, sizeof(buffer)); pr_err("Unknown OID: %s ", buffer); return -EBADMSG; default: pr_err("Unsupported content type: %u ", oid); return -ENOPKG; } return 0; } /* * Note the digest we're guaranteeing with this certificate */ int mscode_note_digest(void *context, size_t hdrlen, unsigned char tag, const void *value, size_t vlen) { struct pefile_context *ctx = context; |
e68503bd6 KEYS: Generalise ... |
125 |
ctx->digest = kmemdup(value, vlen, GFP_KERNEL); |
d128471a1 pefile: Fix the f... |
126 127 128 129 130 131 |
if (!ctx->digest) return -ENOMEM; ctx->digest_len = vlen; return 0; |
4c0b4b1d1 pefile: Parse the... |
132 |
} |