1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /* Parse a Microsoft Individual Code Signing blob
4 * Copyright (C) 2014 Red Hat, Inc. All Rights Reserved.
5 * Written by David Howells (dhowells@redhat.com)
8 #define pr_fmt(fmt) "MSCODE: "fmt
9 #include <linux/kernel.h>
10 #include <linux/slab.h>
11 #include <linux/err.h>
12 #include <linux/oid_registry.h>
13 #include <crypto/pkcs7.h>
14 #include "verify_pefile.h"
15 #include "mscode.asn1.h"
18 * Parse a Microsoft Individual Code Signing blob
20 int mscode_parse(void *_ctx, const void *content_data, size_t data_len,
23 struct pefile_context *ctx = _ctx;
25 content_data -= asn1hdrlen;
26 data_len += asn1hdrlen;
27 pr_devel("Data: %zu [%*ph]\n", data_len, (unsigned)(data_len),
30 return asn1_ber_decoder(&mscode_decoder, ctx, content_data, data_len);
34 * Check the content type OID
36 int mscode_note_content_type(void *context, size_t hdrlen,
38 const void *value, size_t vlen)
42 oid = look_up_OID(value, vlen);
46 sprint_oid(value, vlen, buffer, sizeof(buffer));
47 pr_err("Unknown OID: %s\n", buffer);
52 * pesign utility had a bug where it was putting
53 * OID_msIndividualSPKeyPurpose instead of OID_msPeImageDataObjId
56 if (oid != OID_msPeImageDataObjId &&
57 oid != OID_msIndividualSPKeyPurpose) {
58 pr_err("Unexpected content type OID %u\n", oid);
66 * Note the digest algorithm OID
68 int mscode_note_digest_algo(void *context, size_t hdrlen,
70 const void *value, size_t vlen)
72 struct pefile_context *ctx = context;
76 oid = look_up_OID(value, vlen);
79 ctx->digest_algo = "md4";
82 ctx->digest_algo = "md5";
85 ctx->digest_algo = "sha1";
88 ctx->digest_algo = "sha256";
91 ctx->digest_algo = "sha384";
94 ctx->digest_algo = "sha512";
97 ctx->digest_algo = "sha224";
101 sprint_oid(value, vlen, buffer, sizeof(buffer));
102 pr_err("Unknown OID: %s\n", buffer);
106 pr_err("Unsupported content type: %u\n", oid);
114 * Note the digest we're guaranteeing with this certificate
116 int mscode_note_digest(void *context, size_t hdrlen,
118 const void *value, size_t vlen)
120 struct pefile_context *ctx = context;
122 ctx->digest = kmemdup(value, vlen, GFP_KERNEL);
126 ctx->digest_len = vlen;