xref: /netbsd-src/crypto/external/bsd/openssh/dist/ssh-sk.h (revision 6929eb32139561ee50773ef06c88a36b4f4d8e51)
1*6929eb32Schristos /* $OpenBSD: ssh-sk.h,v 1.11 2021/10/28 02:54:18 djm Exp $ */
218504831Schristos /*
318504831Schristos  * Copyright (c) 2019 Google LLC
418504831Schristos  *
518504831Schristos  * Permission to use, copy, modify, and distribute this software for any
618504831Schristos  * purpose with or without fee is hereby granted, provided that the above
718504831Schristos  * copyright notice and this permission notice appear in all copies.
818504831Schristos  *
918504831Schristos  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
1018504831Schristos  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
1118504831Schristos  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
1218504831Schristos  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
1318504831Schristos  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
1418504831Schristos  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
1518504831Schristos  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1618504831Schristos  */
1718504831Schristos 
1818504831Schristos #ifndef _SSH_SK_H
1918504831Schristos #define _SSH_SK_H 1
2018504831Schristos 
2118504831Schristos struct sshbuf;
2218504831Schristos struct sshkey;
2318504831Schristos struct sk_option;
2418504831Schristos 
2518504831Schristos /* Version of protocol expected from ssh-sk-helper */
2618504831Schristos #define SSH_SK_HELPER_VERSION		5
2718504831Schristos 
2818504831Schristos /* ssh-sk-helper messages */
2918504831Schristos #define SSH_SK_HELPER_ERROR		0	/* Only valid H->C */
3018504831Schristos #define SSH_SK_HELPER_SIGN		1
3118504831Schristos #define SSH_SK_HELPER_ENROLL		2
3218504831Schristos #define SSH_SK_HELPER_LOAD_RESIDENT	3
3318504831Schristos 
34*6929eb32Schristos struct sshsk_resident_key {
35*6929eb32Schristos 	struct sshkey *key;
36*6929eb32Schristos 	uint8_t *user_id;
37*6929eb32Schristos 	size_t user_id_len;
38*6929eb32Schristos };
39*6929eb32Schristos 
4018504831Schristos /*
4118504831Schristos  * Enroll (generate) a new security-key hosted private key of given type
4218504831Schristos  * via the specified provider middleware.
4318504831Schristos  * If challenge_buf is NULL then a random 256 bit challenge will be used.
4418504831Schristos  *
4518504831Schristos  * Returns 0 on success or a ssherr.h error code on failure.
4618504831Schristos  *
4718504831Schristos  * If successful and the attest_data buffer is not NULL then attestation
4818504831Schristos  * information is placed there.
4918504831Schristos  */
5018504831Schristos int sshsk_enroll(int type, const char *provider_path, const char *device,
5118504831Schristos     const char *application, const char *userid, uint8_t flags,
5218504831Schristos     const char *pin, struct sshbuf *challenge_buf,
5318504831Schristos     struct sshkey **keyp, struct sshbuf *attest);
5418504831Schristos 
5518504831Schristos /*
5618504831Schristos  * Calculate an ECDSA_SK or ED25519_SK signature using the specified key
5718504831Schristos  * and provider middleware.
5818504831Schristos  *
5918504831Schristos  * Returns 0 on success or a ssherr.h error code on failure.
6018504831Schristos  */
6118504831Schristos int sshsk_sign(const char *provider_path, struct sshkey *key,
6218504831Schristos     u_char **sigp, size_t *lenp, const u_char *data, size_t datalen,
6318504831Schristos     u_int compat, const char *pin);
6418504831Schristos 
6518504831Schristos /*
6618504831Schristos  * Enumerates and loads all SSH-compatible resident keys from a security
6718504831Schristos  * key.
6818504831Schristos  *
6918504831Schristos  * Returns 0 on success or a ssherr.h error code on failure.
7018504831Schristos  */
7118504831Schristos int sshsk_load_resident(const char *provider_path, const char *device,
72*6929eb32Schristos     const char *pin, u_int flags, struct sshsk_resident_key ***srksp,
73*6929eb32Schristos     size_t *nsrksp);
74*6929eb32Schristos 
75*6929eb32Schristos /* Free an array of sshsk_resident_key (as returned from sshsk_load_resident) */
76*6929eb32Schristos void sshsk_free_resident_keys(struct sshsk_resident_key **srks, size_t nsrks);
7718504831Schristos 
7818504831Schristos #endif /* _SSH_SK_H */
7918504831Schristos 
80