| 1 |
|
| 2 | |
| 3 | *
|
| 4 | * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
|
| 5 | * Written by David Howells ([email protected])
|
| 6 |
|
| 7 |
|
| 8 | #ifndef _LINUX_KEY_TYPE_H
|
| 9 | #define _LINUX_KEY_TYPE_H
|
| 10 |
|
| 11 | #include <linux/key.h>
|
| 12 | #include <linux/errno.h>
|
| 13 |
|
| 14 | #ifdef CONFIG_KEYS
|
| 15 |
|
| 16 | struct kernel_pkey_query;
|
| 17 | struct kernel_pkey_params;
|
| 18 |
|
| 19 | |
| 20 | * Pre-parsed payload, used by key add, update and instantiate.
|
| 21 | *
|
| 22 | * This struct will be cleared and data and datalen will be set with the data
|
| 23 | * and length parameters from the caller and quotalen will be set from
|
| 24 | * def_datalen from the key type. Then if the preparse() op is provided by the
|
| 25 | * key type, that will be called. Then the struct will be passed to the
|
| 26 | * instantiate() or the update() op.
|
| 27 | *
|
| 28 | * If the preparse() op is given, the free_preparse() op will be called to
|
| 29 | * clear the contents.
|
| 30 |
|
| 31 | struct key_preparsed_payload {
|
| 32 | const char *orig_description;
|
| 33 | char *description;
|
| 34 | union key_payload payload;
|
| 35 | const void *data;
|
| 36 | size_t datalen;
|
| 37 | size_t quotalen;
|
| 38 | time64_t expiry;
|
| 39 | } __randomize_layout;
|
| 40 |
|
| 41 | typedef int (*request_key_actor_t)(struct key *auth_key, void *aux);
|
| 42 |
|
| 43 | |
| 44 | * Preparsed matching criterion.
|
| 45 |
|
| 46 | struct key_match_data {
|
| 47 | |
| 48 | * overridden by type->match_preparse(). Should return true if a match
|
| 49 | * is found and false if not.
|
| 50 |
|
| 51 | bool (*cmp)(const struct key *key,
|
| 52 | const struct key_match_data *match_data);
|
| 53 |
|
| 54 | const void *raw_data;
|
| 55 | void *preparsed;
|
| 56 | unsigned lookup_type;
|
| 57 | #define KEYRING_SEARCH_LOOKUP_DIRECT 0x0000
|
| 58 | #define KEYRING_SEARCH_LOOKUP_ITERATE 0x0001
|
| 59 | };
|
| 60 |
|
| 61 | |
| 62 | * kernel managed key type definition
|
| 63 |
|
| 64 | struct key_type {
|
| 65 |
|
| 66 | const char *name;
|
| 67 |
|
| 68 | |
| 69 | * - this can be used instead of calling key_payload_reserve(), that
|
| 70 | * function only needs to be called if the real datalen is different
|
| 71 |
|
| 72 | size_t def_datalen;
|
| 73 |
|
| 74 | unsigned int flags;
|
| 75 | #define KEY_TYPE_NET_DOMAIN 0x00000001
|
| 76 | #define KEY_TYPE_INSTANT_REAP 0x00000002
|
| 77 |
|
| 78 |
|
| 79 | int (*vet_description)(const char *description);
|
| 80 |
|
| 81 | |
| 82 | * generating a proposed description and payload that will be handed to
|
| 83 | * the instantiate() and update() ops.
|
| 84 |
|
| 85 | int (*preparse)(struct key_preparsed_payload *prep);
|
| 86 |
|
| 87 | |
| 88 |
|
| 89 | void (*free_preparse)(struct key_preparsed_payload *prep);
|
| 90 |
|
| 91 | |
| 92 | * - this method should call key_payload_reserve() to determine if the
|
| 93 | * user's quota will hold the payload
|
| 94 |
|
| 95 | int (*instantiate)(struct key *key, struct key_preparsed_payload *prep);
|
| 96 |
|
| 97 | |
| 98 | * - this method should call key_payload_reserve() to recalculate the
|
| 99 | * quota consumption
|
| 100 | * - the key must be locked against read when modifying
|
| 101 |
|
| 102 | int (*update)(struct key *key, struct key_preparsed_payload *prep);
|
| 103 |
|
| 104 | |
| 105 | * data to be preparsed can be found in match_data->raw_data.
|
| 106 | * The lookup type can also be set by this function.
|
| 107 |
|
| 108 | int (*match_preparse)(struct key_match_data *match_data);
|
| 109 |
|
| 110 | |
| 111 | * Free preparsed match data (optional). This should be supplied if
|
| 112 | * ->match_preparse() is supplied.
|
| 113 |
|
| 114 | void (*match_free)(struct key_match_data *match_data);
|
| 115 |
|
| 116 | |
| 117 | * Clear some of the data from a key on revocation (optional).
|
| 118 | * - the key's semaphore will be write-locked by the caller
|
| 119 |
|
| 120 | void (*revoke)(struct key *key);
|
| 121 |
|
| 122 |
|
| 123 | void (*destroy)(struct key *key);
|
| 124 |
|
| 125 |
|
| 126 | void (*describe)(const struct key *key, struct seq_file *p);
|
| 127 |
|
| 128 | |
| 129 | * - permission checks will be done by the caller
|
| 130 | * - the key's semaphore will be readlocked by the caller
|
| 131 | * - should return the amount of data that could be read, no matter how
|
| 132 | * much is copied into the buffer
|
| 133 | * - shouldn't do the copy if the buffer is NULL
|
| 134 |
|
| 135 | long (*read)(const struct key *key, char *buffer, size_t buflen);
|
| 136 |
|
| 137 | |
| 138 | * /sbin/request-key (optional)
|
| 139 | * - key is the key to instantiate
|
| 140 | * - authkey is the authority to assume when instantiating this key
|
| 141 | * - op is the operation to be done, usually "create"
|
| 142 | * - the call must not return until the instantiation process has run
|
| 143 | * its course
|
| 144 |
|
| 145 | request_key_actor_t request_key;
|
| 146 |
|
| 147 | |
| 148 | *
|
| 149 | * - NULL is a valid return value (meaning the requested restriction
|
| 150 | * is known but will never block addition of a key)
|
| 151 | * - should return -EINVAL if the restriction is unknown
|
| 152 |
|
| 153 | struct key_restriction *(*lookup_restriction)(const char *params);
|
| 154 |
|
| 155 |
|
| 156 | int (*asym_query)(const struct kernel_pkey_params *params,
|
| 157 | struct kernel_pkey_query *info);
|
| 158 | int (*asym_eds_op)(struct kernel_pkey_params *params,
|
| 159 | const void *in, void *out);
|
| 160 | int (*asym_verify_signature)(struct kernel_pkey_params *params,
|
| 161 | const void *in, const void *in2);
|
| 162 |
|
| 163 |
|
| 164 | struct list_head link;
|
| 165 | struct lock_class_key lock_class;
|
| 166 | } __randomize_layout;
|
| 167 |
|
| 168 | extern struct key_type key_type_keyring;
|
| 169 |
|
| 170 | extern int register_key_type(struct key_type *ktype);
|
| 171 | extern void unregister_key_type(struct key_type *ktype);
|
| 172 |
|
| 173 | extern int key_payload_reserve(struct key *key, size_t datalen);
|
| 174 | extern int key_instantiate_and_link(struct key *key,
|
| 175 | const void *data,
|
| 176 | size_t datalen,
|
| 177 | struct key *keyring,
|
| 178 | struct key *authkey);
|
| 179 | extern int key_reject_and_link(struct key *key,
|
| 180 | unsigned timeout,
|
| 181 | unsigned error,
|
| 182 | struct key *keyring,
|
| 183 | struct key *authkey);
|
| 184 | extern void complete_request_key(struct key *authkey, int error);
|
| 185 |
|
| 186 | static inline int key_negate_and_link(struct key *key,
|
| 187 | unsigned timeout,
|
| 188 | struct key *keyring,
|
| 189 | struct key *authkey)
|
| 190 | {
|
| 191 | return key_reject_and_link(key, timeout, ENOKEY, keyring, authkey);
|
| 192 | }
|
| 193 |
|
| 194 | extern int generic_key_instantiate(struct key *key, struct key_preparsed_payload *prep);
|
| 195 |
|
| 196 | #endif
|
| 197 | #endif
|