2019-05-21 01:08:01 +08:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
2012-09-22 06:24:55 +08:00
|
|
|
/* Asymmetric public-key algorithm definitions
|
|
|
|
*
|
2020-06-15 14:50:08 +08:00
|
|
|
* See Documentation/crypto/asymmetric-keys.rst
|
2012-09-22 06:24:55 +08:00
|
|
|
*
|
|
|
|
* Copyright (C) 2012 Red Hat, Inc. All Rights Reserved.
|
|
|
|
* Written by David Howells (dhowells@redhat.com)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _LINUX_PUBLIC_KEY_H
|
|
|
|
#define _LINUX_PUBLIC_KEY_H
|
|
|
|
|
2018-10-10 00:47:07 +08:00
|
|
|
#include <linux/keyctl.h>
|
2019-04-11 23:51:17 +08:00
|
|
|
#include <linux/oid_registry.h>
|
2018-10-10 00:47:07 +08:00
|
|
|
|
2012-09-22 06:24:55 +08:00
|
|
|
/*
|
|
|
|
* Cryptographic data for the public-key subtype of the asymmetric key type.
|
|
|
|
*
|
|
|
|
* Note that this may include private part of the key as well as the public
|
|
|
|
* part.
|
|
|
|
*/
|
|
|
|
struct public_key {
|
2016-02-03 02:08:53 +08:00
|
|
|
void *key;
|
|
|
|
u32 keylen;
|
2019-04-11 23:51:17 +08:00
|
|
|
enum OID algo;
|
|
|
|
void *params;
|
|
|
|
u32 paramlen;
|
2018-10-10 00:47:31 +08:00
|
|
|
bool key_is_private;
|
2016-03-04 05:49:27 +08:00
|
|
|
const char *id_type;
|
|
|
|
const char *pkey_algo;
|
2012-09-22 06:24:55 +08:00
|
|
|
};
|
|
|
|
|
2016-04-06 23:13:33 +08:00
|
|
|
extern void public_key_free(struct public_key *key);
|
2012-09-22 06:24:55 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Public key cryptography signature data
|
|
|
|
*/
|
|
|
|
struct public_key_signature {
|
2016-04-06 23:13:33 +08:00
|
|
|
struct asymmetric_key_id *auth_ids[2];
|
2016-02-03 02:08:53 +08:00
|
|
|
u8 *s; /* Signature */
|
|
|
|
u32 s_size; /* Number of bytes in signature */
|
2012-09-22 06:24:55 +08:00
|
|
|
u8 *digest;
|
2016-02-03 02:09:03 +08:00
|
|
|
u8 digest_size; /* Number of bytes in digest */
|
2016-03-04 05:49:27 +08:00
|
|
|
const char *pkey_algo;
|
|
|
|
const char *hash_algo;
|
2018-10-10 00:47:07 +08:00
|
|
|
const char *encoding;
|
2012-09-22 06:24:55 +08:00
|
|
|
};
|
|
|
|
|
2016-04-06 23:13:33 +08:00
|
|
|
extern void public_key_signature_free(struct public_key_signature *sig);
|
|
|
|
|
2016-02-03 02:08:53 +08:00
|
|
|
extern struct asymmetric_key_subtype public_key_subtype;
|
2016-04-06 23:13:33 +08:00
|
|
|
|
2012-09-22 06:25:04 +08:00
|
|
|
struct key;
|
KEYS: Move the point of trust determination to __key_link()
Move the point at which a key is determined to be trustworthy to
__key_link() so that we use the contents of the keyring being linked in to
to determine whether the key being linked in is trusted or not.
What is 'trusted' then becomes a matter of what's in the keyring.
Currently, the test is done when the key is parsed, but given that at that
point we can only sensibly refer to the contents of the system trusted
keyring, we can only use that as the basis for working out the
trustworthiness of a new key.
With this change, a trusted keyring is a set of keys that once the
trusted-only flag is set cannot be added to except by verification through
one of the contained keys.
Further, adding a key into a trusted keyring, whilst it might grant
trustworthiness in the context of that keyring, does not automatically
grant trustworthiness in the context of a second keyring to which it could
be secondarily linked.
To accomplish this, the authentication data associated with the key source
must now be retained. For an X.509 cert, this means the contents of the
AuthorityKeyIdentifier and the signature data.
If system keyrings are disabled then restrict_link_by_builtin_trusted()
resolves to restrict_link_reject(). The integrity digital signature code
still works correctly with this as it was previously using
KEY_FLAG_TRUSTED_ONLY, which doesn't permit anything to be added if there
is no system keyring against which trust can be determined.
Signed-off-by: David Howells <dhowells@redhat.com>
2016-04-06 23:14:26 +08:00
|
|
|
struct key_type;
|
|
|
|
union key_payload;
|
|
|
|
|
2016-08-31 02:33:13 +08:00
|
|
|
extern int restrict_link_by_signature(struct key *dest_keyring,
|
KEYS: Move the point of trust determination to __key_link()
Move the point at which a key is determined to be trustworthy to
__key_link() so that we use the contents of the keyring being linked in to
to determine whether the key being linked in is trusted or not.
What is 'trusted' then becomes a matter of what's in the keyring.
Currently, the test is done when the key is parsed, but given that at that
point we can only sensibly refer to the contents of the system trusted
keyring, we can only use that as the basis for working out the
trustworthiness of a new key.
With this change, a trusted keyring is a set of keys that once the
trusted-only flag is set cannot be added to except by verification through
one of the contained keys.
Further, adding a key into a trusted keyring, whilst it might grant
trustworthiness in the context of that keyring, does not automatically
grant trustworthiness in the context of a second keyring to which it could
be secondarily linked.
To accomplish this, the authentication data associated with the key source
must now be retained. For an X.509 cert, this means the contents of the
AuthorityKeyIdentifier and the signature data.
If system keyrings are disabled then restrict_link_by_builtin_trusted()
resolves to restrict_link_reject(). The integrity digital signature code
still works correctly with this as it was previously using
KEY_FLAG_TRUSTED_ONLY, which doesn't permit anything to be added if there
is no system keyring against which trust can be determined.
Signed-off-by: David Howells <dhowells@redhat.com>
2016-04-06 23:14:26 +08:00
|
|
|
const struct key_type *type,
|
2016-08-31 02:33:13 +08:00
|
|
|
const union key_payload *payload,
|
|
|
|
struct key *trust_keyring);
|
KEYS: Move the point of trust determination to __key_link()
Move the point at which a key is determined to be trustworthy to
__key_link() so that we use the contents of the keyring being linked in to
to determine whether the key being linked in is trusted or not.
What is 'trusted' then becomes a matter of what's in the keyring.
Currently, the test is done when the key is parsed, but given that at that
point we can only sensibly refer to the contents of the system trusted
keyring, we can only use that as the basis for working out the
trustworthiness of a new key.
With this change, a trusted keyring is a set of keys that once the
trusted-only flag is set cannot be added to except by verification through
one of the contained keys.
Further, adding a key into a trusted keyring, whilst it might grant
trustworthiness in the context of that keyring, does not automatically
grant trustworthiness in the context of a second keyring to which it could
be secondarily linked.
To accomplish this, the authentication data associated with the key source
must now be retained. For an X.509 cert, this means the contents of the
AuthorityKeyIdentifier and the signature data.
If system keyrings are disabled then restrict_link_by_builtin_trusted()
resolves to restrict_link_reject(). The integrity digital signature code
still works correctly with this as it was previously using
KEY_FLAG_TRUSTED_ONLY, which doesn't permit anything to be added if there
is no system keyring against which trust can be determined.
Signed-off-by: David Howells <dhowells@redhat.com>
2016-04-06 23:14:26 +08:00
|
|
|
|
2016-06-28 07:45:16 +08:00
|
|
|
extern int restrict_link_by_key_or_keyring(struct key *dest_keyring,
|
|
|
|
const struct key_type *type,
|
|
|
|
const union key_payload *payload,
|
|
|
|
struct key *trusted);
|
|
|
|
|
2016-10-05 07:42:45 +08:00
|
|
|
extern int restrict_link_by_key_or_keyring_chain(struct key *trust_keyring,
|
|
|
|
const struct key_type *type,
|
|
|
|
const union key_payload *payload,
|
|
|
|
struct key *trusted);
|
|
|
|
|
2018-10-10 00:47:07 +08:00
|
|
|
extern int query_asymmetric_key(const struct kernel_pkey_params *,
|
|
|
|
struct kernel_pkey_query *);
|
|
|
|
|
|
|
|
extern int encrypt_blob(struct kernel_pkey_params *, const void *, void *);
|
|
|
|
extern int decrypt_blob(struct kernel_pkey_params *, const void *, void *);
|
|
|
|
extern int create_signature(struct kernel_pkey_params *, const void *, void *);
|
|
|
|
extern int verify_signature(const struct key *,
|
|
|
|
const struct public_key_signature *);
|
2012-09-22 06:25:04 +08:00
|
|
|
|
2016-02-03 02:08:53 +08:00
|
|
|
int public_key_verify_signature(const struct public_key *pkey,
|
|
|
|
const struct public_key_signature *sig);
|
|
|
|
|
2012-09-22 06:24:55 +08:00
|
|
|
#endif /* _LINUX_PUBLIC_KEY_H */
|