1 /* Parse a Microsoft Individual Code Signing blob
3 * Copyright (C) 2014 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
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.
12 #define pr_fmt(fmt) "MSCODE: "fmt
13 #include <linux/kernel.h>
14 #include <linux/slab.h>
15 #include <linux/err.h>
16 #include <linux/oid_registry.h>
17 #include <crypto/pkcs7.h>
18 #include "verify_pefile.h"
19 #include "mscode-asn1.h"
22 * Parse a Microsoft Individual Code Signing blob
24 int mscode_parse(struct pefile_context *ctx)
26 const void *content_data;
30 ret = pkcs7_get_content_data(ctx->pkcs7, &content_data, &data_len, 1);
33 pr_debug("PKCS#7 message does not contain data\n");
37 pr_devel("Data: %zu [%*ph]\n", data_len, (unsigned)(data_len),
40 return asn1_ber_decoder(&mscode_decoder, ctx, content_data, data_len);
44 * Check the content type OID
46 int mscode_note_content_type(void *context, size_t hdrlen,
48 const void *value, size_t vlen)
52 oid = look_up_OID(value, vlen);
56 sprint_oid(value, vlen, buffer, sizeof(buffer));
57 pr_err("Unknown OID: %s\n", buffer);
62 * pesign utility had a bug where it was putting
63 * OID_msIndividualSPKeyPurpose instead of OID_msPeImageDataObjId
66 if (oid != OID_msPeImageDataObjId &&
67 oid != OID_msIndividualSPKeyPurpose) {
68 pr_err("Unexpected content type OID %u\n", oid);
76 * Note the digest algorithm OID
78 int mscode_note_digest_algo(void *context, size_t hdrlen,
80 const void *value, size_t vlen)
82 struct pefile_context *ctx = context;
86 oid = look_up_OID(value, vlen);
89 ctx->digest_algo = HASH_ALGO_MD4;
92 ctx->digest_algo = HASH_ALGO_MD5;
95 ctx->digest_algo = HASH_ALGO_SHA1;
98 ctx->digest_algo = HASH_ALGO_SHA256;
102 sprint_oid(value, vlen, buffer, sizeof(buffer));
103 pr_err("Unknown OID: %s\n", buffer);
107 pr_err("Unsupported content type: %u\n", oid);
115 * Note the digest we're guaranteeing with this certificate
117 int mscode_note_digest(void *context, size_t hdrlen,
119 const void *value, size_t vlen)
121 struct pefile_context *ctx = context;
124 ctx->digest_len = vlen;