xref: /freebsd/crypto/openssh/ssh-sk.h (revision 1323ec57)
1*1323ec57SEd Maste /* $OpenBSD: ssh-sk.h,v 1.11 2021/10/28 02:54:18 djm Exp $ */
219261079SEd Maste /*
319261079SEd Maste  * Copyright (c) 2019 Google LLC
419261079SEd Maste  *
519261079SEd Maste  * Permission to use, copy, modify, and distribute this software for any
619261079SEd Maste  * purpose with or without fee is hereby granted, provided that the above
719261079SEd Maste  * copyright notice and this permission notice appear in all copies.
819261079SEd Maste  *
919261079SEd Maste  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
1019261079SEd Maste  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
1119261079SEd Maste  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
1219261079SEd Maste  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
1319261079SEd Maste  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
1419261079SEd Maste  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
1519261079SEd Maste  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1619261079SEd Maste  */
1719261079SEd Maste 
1819261079SEd Maste #ifndef _SSH_SK_H
1919261079SEd Maste #define _SSH_SK_H 1
2019261079SEd Maste 
2119261079SEd Maste struct sshbuf;
2219261079SEd Maste struct sshkey;
2319261079SEd Maste struct sk_option;
2419261079SEd Maste 
2519261079SEd Maste /* Version of protocol expected from ssh-sk-helper */
2619261079SEd Maste #define SSH_SK_HELPER_VERSION		5
2719261079SEd Maste 
2819261079SEd Maste /* ssh-sk-helper messages */
2919261079SEd Maste #define SSH_SK_HELPER_ERROR		0	/* Only valid H->C */
3019261079SEd Maste #define SSH_SK_HELPER_SIGN		1
3119261079SEd Maste #define SSH_SK_HELPER_ENROLL		2
3219261079SEd Maste #define SSH_SK_HELPER_LOAD_RESIDENT	3
3319261079SEd Maste 
34*1323ec57SEd Maste struct sshsk_resident_key {
35*1323ec57SEd Maste 	struct sshkey *key;
36*1323ec57SEd Maste 	uint8_t *user_id;
37*1323ec57SEd Maste 	size_t user_id_len;
38*1323ec57SEd Maste };
39*1323ec57SEd Maste 
4019261079SEd Maste /*
4119261079SEd Maste  * Enroll (generate) a new security-key hosted private key of given type
4219261079SEd Maste  * via the specified provider middleware.
4319261079SEd Maste  * If challenge_buf is NULL then a random 256 bit challenge will be used.
4419261079SEd Maste  *
4519261079SEd Maste  * Returns 0 on success or a ssherr.h error code on failure.
4619261079SEd Maste  *
4719261079SEd Maste  * If successful and the attest_data buffer is not NULL then attestation
4819261079SEd Maste  * information is placed there.
4919261079SEd Maste  */
5019261079SEd Maste int sshsk_enroll(int type, const char *provider_path, const char *device,
5119261079SEd Maste     const char *application, const char *userid, uint8_t flags,
5219261079SEd Maste     const char *pin, struct sshbuf *challenge_buf,
5319261079SEd Maste     struct sshkey **keyp, struct sshbuf *attest);
5419261079SEd Maste 
5519261079SEd Maste /*
5619261079SEd Maste  * Calculate an ECDSA_SK or ED25519_SK signature using the specified key
5719261079SEd Maste  * and provider middleware.
5819261079SEd Maste  *
5919261079SEd Maste  * Returns 0 on success or a ssherr.h error code on failure.
6019261079SEd Maste  */
6119261079SEd Maste int sshsk_sign(const char *provider_path, struct sshkey *key,
6219261079SEd Maste     u_char **sigp, size_t *lenp, const u_char *data, size_t datalen,
6319261079SEd Maste     u_int compat, const char *pin);
6419261079SEd Maste 
6519261079SEd Maste /*
6619261079SEd Maste  * Enumerates and loads all SSH-compatible resident keys from a security
6719261079SEd Maste  * key.
6819261079SEd Maste  *
6919261079SEd Maste  * Returns 0 on success or a ssherr.h error code on failure.
7019261079SEd Maste  */
7119261079SEd Maste int sshsk_load_resident(const char *provider_path, const char *device,
72*1323ec57SEd Maste     const char *pin, u_int flags, struct sshsk_resident_key ***srksp,
73*1323ec57SEd Maste     size_t *nsrksp);
74*1323ec57SEd Maste 
75*1323ec57SEd Maste /* Free an array of sshsk_resident_key (as returned from sshsk_load_resident) */
76*1323ec57SEd Maste void sshsk_free_resident_keys(struct sshsk_resident_key **srks, size_t nsrks);
7719261079SEd Maste 
7819261079SEd Maste #endif /* _SSH_SK_H */
7919261079SEd Maste 
80