2019-05-20 20:08:01 +03:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
2012-09-22 02:24:55 +04:00
|
|
|
/* Asymmetric public-key algorithm definitions
|
|
|
|
*
|
2020-06-15 09:50:08 +03:00
|
|
|
* See Documentation/crypto/asymmetric-keys.rst
|
2012-09-22 02:24:55 +04: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-09 19:47:07 +03:00
|
|
|
#include <linux/keyctl.h>
|
2019-04-11 18:51:17 +03:00
|
|
|
#include <linux/oid_registry.h>
|
2018-10-09 19:47:07 +03:00
|
|
|
|
2012-09-22 02:24:55 +04: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-02 21:08:53 +03:00
|
|
|
void *key;
|
|
|
|
u32 keylen;
|
2019-04-11 18:51:17 +03:00
|
|
|
enum OID algo;
|
|
|
|
void *params;
|
|
|
|
u32 paramlen;
|
2018-10-09 19:47:31 +03:00
|
|
|
bool key_is_private;
|
2016-03-04 00:49:27 +03:00
|
|
|
const char *id_type;
|
|
|
|
const char *pkey_algo;
|
2012-09-22 02:24:55 +04:00
|
|
|
};
|
|
|
|
|
2016-04-06 18:13:33 +03:00
|
|
|
extern void public_key_free(struct public_key *key);
|
2012-09-22 02:24:55 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Public key cryptography signature data
|
|
|
|
*/
|
|
|
|
struct public_key_signature {
|
2021-11-09 18:16:49 +03:00
|
|
|
struct asymmetric_key_id *auth_ids[3];
|
2016-02-02 21:08:53 +03:00
|
|
|
u8 *s; /* Signature */
|
2012-09-22 02:24:55 +04:00
|
|
|
u8 *digest;
|
2021-08-19 15:37:10 +03:00
|
|
|
u32 s_size; /* Number of bytes in signature */
|
|
|
|
u32 digest_size; /* Number of bytes in digest */
|
2016-03-04 00:49:27 +03:00
|
|
|
const char *pkey_algo;
|
|
|
|
const char *hash_algo;
|
2018-10-09 19:47:07 +03:00
|
|
|
const char *encoding;
|
2020-09-20 19:21:02 +03:00
|
|
|
const void *data;
|
|
|
|
unsigned int data_size;
|
2012-09-22 02:24:55 +04:00
|
|
|
};
|
|
|
|
|
2016-04-06 18:13:33 +03:00
|
|
|
extern void public_key_signature_free(struct public_key_signature *sig);
|
|
|
|
|
2016-02-02 21:08:53 +03:00
|
|
|
extern struct asymmetric_key_subtype public_key_subtype;
|
2016-04-06 18:13:33 +03:00
|
|
|
|
2012-09-22 02:25:04 +04: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 18:14:26 +03:00
|
|
|
struct key_type;
|
|
|
|
union key_payload;
|
|
|
|
|
2016-08-30 21:33:13 +03: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 18:14:26 +03:00
|
|
|
const struct key_type *type,
|
2016-08-30 21:33:13 +03: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 18:14:26 +03:00
|
|
|
|
2016-06-28 02:45:16 +03: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 02:42:45 +03: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-09 19:47:07 +03: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 02:25:04 +04:00
|
|
|
|
2016-02-02 21:08:53 +03:00
|
|
|
int public_key_verify_signature(const struct public_key *pkey,
|
|
|
|
const struct public_key_signature *sig);
|
|
|
|
|
2012-09-22 02:24:55 +04:00
|
|
|
#endif /* _LINUX_PUBLIC_KEY_H */
|