]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - crypto/asymmetric_keys/pkcs7_key_type.c
perf xyarray: Fix wrong processing when closing evsel fd
[mirror_ubuntu-artful-kernel.git] / crypto / asymmetric_keys / pkcs7_key_type.c
CommitLineData
22d01afb
DH
1/* Testing module to load key from trusted PKCS#7 message
2 *
3 * Copyright (C) 2014 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
5 *
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.
10 */
11
12#define pr_fmt(fmt) "PKCS7key: "fmt
13#include <linux/key.h>
8f3438cc 14#include <linux/err.h>
88775588 15#include <linux/module.h>
e68503bd 16#include <linux/verification.h>
22d01afb 17#include <linux/key-type.h>
22d01afb 18#include <keys/user-type.h>
22d01afb 19
772111ab
DH
20MODULE_LICENSE("GPL");
21MODULE_DESCRIPTION("PKCS#7 testing key type");
22
99db4435
DH
23static unsigned pkcs7_usage;
24module_param_named(usage, pkcs7_usage, uint, S_IWUSR | S_IRUGO);
25MODULE_PARM_DESC(pkcs7_usage,
26 "Usage to specify when verifying the PKCS#7 message");
27
22d01afb 28/*
e68503bd 29 * Retrieve the PKCS#7 message content.
22d01afb 30 */
e68503bd
DH
31static int pkcs7_view_content(void *ctx, const void *data, size_t len,
32 size_t asn1hdrlen)
22d01afb 33{
e68503bd
DH
34 struct key_preparsed_payload *prep = ctx;
35 const void *saved_prep_data;
36 size_t saved_prep_datalen;
22d01afb
DH
37 int ret;
38
22d01afb
DH
39 saved_prep_data = prep->data;
40 saved_prep_datalen = prep->datalen;
22d01afb 41 prep->data = data;
e68503bd
DH
42 prep->datalen = len;
43
1ca72c96 44 ret = user_preparse(prep);
e68503bd 45
22d01afb
DH
46 prep->data = saved_prep_data;
47 prep->datalen = saved_prep_datalen;
22d01afb
DH
48 return ret;
49}
50
e68503bd
DH
51/*
52 * Preparse a PKCS#7 wrapped and validated data blob.
53 */
54static int pkcs7_preparse(struct key_preparsed_payload *prep)
55{
56 enum key_being_used_for usage = pkcs7_usage;
57
58 if (usage >= NR__KEY_BEING_USED_FOR) {
59 pr_err("Invalid usage type %d\n", usage);
60 return -EINVAL;
61 }
62
63 return verify_pkcs7_signature(NULL, 0,
64 prep->data, prep->datalen,
3c8f2278 65 (void *)1UL, usage,
e68503bd
DH
66 pkcs7_view_content, prep);
67}
68
22d01afb
DH
69/*
70 * user defined keys take an arbitrary string as the description and an
71 * arbitrary blob of data as the payload
72 */
63d2551e 73static struct key_type key_type_pkcs7 = {
22d01afb 74 .name = "pkcs7_test",
1ca72c96
DH
75 .preparse = pkcs7_preparse,
76 .free_preparse = user_free_preparse,
77 .instantiate = generic_key_instantiate,
22d01afb
DH
78 .revoke = user_revoke,
79 .destroy = user_destroy,
80 .describe = user_describe,
81 .read = user_read,
82};
83
84/*
85 * Module stuff
86 */
87static int __init pkcs7_key_init(void)
88{
89 return register_key_type(&key_type_pkcs7);
90}
91
92static void __exit pkcs7_key_cleanup(void)
93{
94 unregister_key_type(&key_type_pkcs7);
95}
96
97module_init(pkcs7_key_init);
98module_exit(pkcs7_key_cleanup);