1 1.1.1.2 christos /* $OpenBSD: ssh-sk.h,v 1.11 2021/10/28 02:54:18 djm Exp $ */ 2 1.1 christos /* 3 1.1 christos * Copyright (c) 2019 Google LLC 4 1.1 christos * 5 1.1 christos * Permission to use, copy, modify, and distribute this software for any 6 1.1 christos * purpose with or without fee is hereby granted, provided that the above 7 1.1 christos * copyright notice and this permission notice appear in all copies. 8 1.1 christos * 9 1.1 christos * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 1.1 christos * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 1.1 christos * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 1.1 christos * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 1.1 christos * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 1.1 christos * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 1.1 christos * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 1.1 christos */ 17 1.1 christos 18 1.1 christos #ifndef _SSH_SK_H 19 1.1 christos #define _SSH_SK_H 1 20 1.1 christos 21 1.1 christos struct sshbuf; 22 1.1 christos struct sshkey; 23 1.1 christos struct sk_option; 24 1.1 christos 25 1.1 christos /* Version of protocol expected from ssh-sk-helper */ 26 1.1 christos #define SSH_SK_HELPER_VERSION 5 27 1.1 christos 28 1.1 christos /* ssh-sk-helper messages */ 29 1.1 christos #define SSH_SK_HELPER_ERROR 0 /* Only valid H->C */ 30 1.1 christos #define SSH_SK_HELPER_SIGN 1 31 1.1 christos #define SSH_SK_HELPER_ENROLL 2 32 1.1 christos #define SSH_SK_HELPER_LOAD_RESIDENT 3 33 1.1 christos 34 1.1.1.2 christos struct sshsk_resident_key { 35 1.1.1.2 christos struct sshkey *key; 36 1.1.1.2 christos uint8_t *user_id; 37 1.1.1.2 christos size_t user_id_len; 38 1.1.1.2 christos }; 39 1.1.1.2 christos 40 1.1 christos /* 41 1.1 christos * Enroll (generate) a new security-key hosted private key of given type 42 1.1 christos * via the specified provider middleware. 43 1.1 christos * If challenge_buf is NULL then a random 256 bit challenge will be used. 44 1.1 christos * 45 1.1 christos * Returns 0 on success or a ssherr.h error code on failure. 46 1.1 christos * 47 1.1 christos * If successful and the attest_data buffer is not NULL then attestation 48 1.1 christos * information is placed there. 49 1.1 christos */ 50 1.1 christos int sshsk_enroll(int type, const char *provider_path, const char *device, 51 1.1 christos const char *application, const char *userid, uint8_t flags, 52 1.1 christos const char *pin, struct sshbuf *challenge_buf, 53 1.1 christos struct sshkey **keyp, struct sshbuf *attest); 54 1.1 christos 55 1.1 christos /* 56 1.1 christos * Calculate an ECDSA_SK or ED25519_SK signature using the specified key 57 1.1 christos * and provider middleware. 58 1.1 christos * 59 1.1 christos * Returns 0 on success or a ssherr.h error code on failure. 60 1.1 christos */ 61 1.1 christos int sshsk_sign(const char *provider_path, struct sshkey *key, 62 1.1 christos u_char **sigp, size_t *lenp, const u_char *data, size_t datalen, 63 1.1 christos u_int compat, const char *pin); 64 1.1 christos 65 1.1 christos /* 66 1.1 christos * Enumerates and loads all SSH-compatible resident keys from a security 67 1.1 christos * key. 68 1.1 christos * 69 1.1 christos * Returns 0 on success or a ssherr.h error code on failure. 70 1.1 christos */ 71 1.1 christos int sshsk_load_resident(const char *provider_path, const char *device, 72 1.1.1.2 christos const char *pin, u_int flags, struct sshsk_resident_key ***srksp, 73 1.1.1.2 christos size_t *nsrksp); 74 1.1.1.2 christos 75 1.1.1.2 christos /* Free an array of sshsk_resident_key (as returned from sshsk_load_resident) */ 76 1.1.1.2 christos void sshsk_free_resident_keys(struct sshsk_resident_key **srks, size_t nsrks); 77 1.1 christos 78 1.1 christos #endif /* _SSH_SK_H */ 79 1.1 christos 80