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(void *_ctx
, const void *content_data
, size_t data_len
,
27 struct pefile_context
*ctx
= _ctx
;
29 content_data
-= asn1hdrlen
;
30 data_len
+= asn1hdrlen
;
31 pr_devel("Data: %zu [%*ph]\n", data_len
, (unsigned)(data_len
),
34 return asn1_ber_decoder(&mscode_decoder
, ctx
, content_data
, data_len
);
38 * Check the content type OID
40 int mscode_note_content_type(void *context
, size_t hdrlen
,
42 const void *value
, size_t vlen
)
46 oid
= look_up_OID(value
, vlen
);
50 sprint_oid(value
, vlen
, buffer
, sizeof(buffer
));
51 pr_err("Unknown OID: %s\n", buffer
);
56 * pesign utility had a bug where it was putting
57 * OID_msIndividualSPKeyPurpose instead of OID_msPeImageDataObjId
60 if (oid
!= OID_msPeImageDataObjId
&&
61 oid
!= OID_msIndividualSPKeyPurpose
) {
62 pr_err("Unexpected content type OID %u\n", oid
);
70 * Note the digest algorithm OID
72 int mscode_note_digest_algo(void *context
, size_t hdrlen
,
74 const void *value
, size_t vlen
)
76 struct pefile_context
*ctx
= context
;
80 oid
= look_up_OID(value
, vlen
);
83 ctx
->digest_algo
= "md4";
86 ctx
->digest_algo
= "md5";
89 ctx
->digest_algo
= "sha1";
92 ctx
->digest_algo
= "sha256";
95 ctx
->digest_algo
= "sha384";
98 ctx
->digest_algo
= "sha512";
101 ctx
->digest_algo
= "sha224";
105 sprint_oid(value
, vlen
, buffer
, sizeof(buffer
));
106 pr_err("Unknown OID: %s\n", buffer
);
110 pr_err("Unsupported content type: %u\n", oid
);
118 * Note the digest we're guaranteeing with this certificate
120 int mscode_note_digest(void *context
, size_t hdrlen
,
122 const void *value
, size_t vlen
)
124 struct pefile_context
*ctx
= context
;
126 ctx
->digest
= kmemdup(value
, vlen
, GFP_KERNEL
);
127 return ctx
->digest
? 0 : -ENOMEM
;