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.
8 #define pr_fmt(fmt) "MSCODE: "fmt
9 #include <linux/kernel.h>
11 #include <linux/slab.h>
13 #include <linux/err.h>
14 #include <linux/oid_registry.h>
15 #include <crypto/pkcs7.h>
17 #include <crypto/mscode.h>
19 #include "verify_pefile.h"
21 #include "mscode.asn1.h"
24 * Parse a Microsoft Individual Code Signing blob
26 int mscode_parse(void *_ctx, const void *content_data, size_t data_len,
29 struct pefile_context *ctx = _ctx;
31 content_data -= asn1hdrlen;
32 data_len += asn1hdrlen;
33 pr_devel("Data: %zu [%*ph]\n", data_len, (unsigned)(data_len),
36 return asn1_ber_decoder(&mscode_decoder, ctx, content_data, data_len);
40 * Check the content type OID
42 int mscode_note_content_type(void *context, size_t hdrlen,
44 const void *value, size_t vlen)
48 oid = look_up_OID(value, vlen);
52 sprint_oid(value, vlen, buffer, sizeof(buffer));
53 pr_err("Unknown OID: %s\n", buffer);
58 * pesign utility had a bug where it was putting
59 * OID_msIndividualSPKeyPurpose instead of OID_msPeImageDataObjId
62 if (oid != OID_msPeImageDataObjId &&
63 oid != OID_msIndividualSPKeyPurpose) {
64 pr_err("Unexpected content type OID %u\n", oid);
72 * Note the digest algorithm OID
74 int mscode_note_digest_algo(void *context, size_t hdrlen,
76 const void *value, size_t vlen)
78 struct pefile_context *ctx = context;
82 oid = look_up_OID(value, vlen);
85 ctx->digest_algo = "md4";
88 ctx->digest_algo = "md5";
91 ctx->digest_algo = "sha1";
94 ctx->digest_algo = "sha256";
97 ctx->digest_algo = "sha384";
100 ctx->digest_algo = "sha512";
103 ctx->digest_algo = "sha224";
107 sprint_oid(value, vlen, buffer, sizeof(buffer));
108 pr_err("Unknown OID: %s\n", buffer);
112 pr_err("Unsupported content type: %u\n", oid);
120 * Note the digest we're guaranteeing with this certificate
122 int mscode_note_digest(void *context, size_t hdrlen,
124 const void *value, size_t vlen)
126 struct pefile_context *ctx = context;
128 ctx->digest = kmemdup(value, vlen, GFP_KERNEL);
132 ctx->digest_len = vlen;