2021-07-23 03:37:52 +00:00
|
|
|
/* $OpenBSD: sshsig.h,v 1.10 2021/07/23 03:37:52 djm Exp $ */
|
2019-09-03 08:34:19 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2019 Google LLC
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SSHSIG_H
|
|
|
|
#define SSHSIG_H
|
|
|
|
|
|
|
|
struct sshbuf;
|
|
|
|
struct sshkey;
|
2019-09-05 04:55:32 +00:00
|
|
|
struct sshsigopt;
|
2019-11-25 00:51:37 +00:00
|
|
|
struct sshkey_sig_details;
|
2019-09-03 08:34:19 +00:00
|
|
|
|
|
|
|
typedef int sshsig_signer(struct sshkey *, u_char **, size_t *,
|
2020-08-27 01:06:18 +00:00
|
|
|
const u_char *, size_t, const char *, const char *, const char *,
|
|
|
|
u_int, void *);
|
2019-09-03 08:34:19 +00:00
|
|
|
|
2019-09-03 08:35:27 +00:00
|
|
|
/* Buffer-oriented API */
|
|
|
|
|
2019-09-03 08:34:19 +00:00
|
|
|
/*
|
2019-09-03 08:35:27 +00:00
|
|
|
* Creates a detached SSH signature for a given buffer.
|
2019-09-03 08:34:19 +00:00
|
|
|
* Returns 0 on success or a negative SSH_ERR_* error code on failure.
|
|
|
|
* out is populated with the detached signature, or NULL on failure.
|
|
|
|
*/
|
2019-09-03 08:35:27 +00:00
|
|
|
int sshsig_signb(struct sshkey *key, const char *hashalg,
|
2020-08-27 01:06:18 +00:00
|
|
|
const char *sk_provider, const char *sk_pin, const struct sshbuf *message,
|
2019-10-31 21:23:19 +00:00
|
|
|
const char *sig_namespace, struct sshbuf **out,
|
|
|
|
sshsig_signer *signer, void *signer_ctx);
|
2019-09-03 08:34:19 +00:00
|
|
|
|
2019-09-03 08:35:27 +00:00
|
|
|
/*
|
|
|
|
* Verifies that a detached signature is valid and optionally returns key
|
|
|
|
* used to sign via argument.
|
|
|
|
* Returns 0 on success or a negative SSH_ERR_* error code on failure.
|
|
|
|
*/
|
|
|
|
int sshsig_verifyb(struct sshbuf *signature,
|
|
|
|
const struct sshbuf *message, const char *sig_namespace,
|
2019-11-25 00:51:37 +00:00
|
|
|
struct sshkey **sign_keyp, struct sshkey_sig_details **sig_details);
|
2019-09-03 08:35:27 +00:00
|
|
|
|
|
|
|
/* File/FD-oriented API */
|
|
|
|
|
2019-09-03 08:34:19 +00:00
|
|
|
/*
|
|
|
|
* Creates a detached SSH signature for a given file.
|
|
|
|
* Returns 0 on success or a negative SSH_ERR_* error code on failure.
|
|
|
|
* out is populated with the detached signature, or NULL on failure.
|
|
|
|
*/
|
|
|
|
int sshsig_sign_fd(struct sshkey *key, const char *hashalg,
|
2020-08-27 01:06:18 +00:00
|
|
|
const char *sk_provider, const char *sk_pin,
|
|
|
|
int fd, const char *sig_namespace,
|
2019-10-31 21:23:19 +00:00
|
|
|
struct sshbuf **out, sshsig_signer *signer, void *signer_ctx);
|
2019-09-03 08:34:19 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Verifies that a detached signature over a file is valid and optionally
|
|
|
|
* returns key used to sign via argument.
|
|
|
|
* Returns 0 on success or a negative SSH_ERR_* error code on failure.
|
|
|
|
*/
|
|
|
|
int sshsig_verify_fd(struct sshbuf *signature, int fd,
|
2019-11-25 00:51:37 +00:00
|
|
|
const char *sig_namespace, struct sshkey **sign_keyp,
|
|
|
|
struct sshkey_sig_details **sig_details);
|
2019-09-03 08:34:19 +00:00
|
|
|
|
2019-09-03 08:35:27 +00:00
|
|
|
/* Utility functions */
|
|
|
|
|
2019-09-03 08:34:19 +00:00
|
|
|
/*
|
|
|
|
* Return a base64 encoded "ASCII armoured" version of a raw signature.
|
|
|
|
*/
|
|
|
|
int sshsig_armor(const struct sshbuf *blob, struct sshbuf **out);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Decode a base64 encoded armoured signature to a raw signature.
|
|
|
|
*/
|
|
|
|
int sshsig_dearmor(struct sshbuf *sig, struct sshbuf **out);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Checks whether a particular key/principal/namespace is permitted by
|
|
|
|
* an allowed_keys file. Returns 0 on success.
|
|
|
|
*/
|
|
|
|
int sshsig_check_allowed_keys(const char *path, const struct sshkey *sign_key,
|
2021-07-23 03:37:52 +00:00
|
|
|
const char *principal, const char *ns, uint64_t verify_time);
|
2019-09-03 08:34:19 +00:00
|
|
|
|
2019-09-05 04:55:32 +00:00
|
|
|
/* Parse zero or more allowed_keys signature options */
|
|
|
|
struct sshsigopt *sshsigopt_parse(const char *opts,
|
|
|
|
const char *path, u_long linenum, const char **errstrp);
|
|
|
|
|
|
|
|
/* Free signature options */
|
|
|
|
void sshsigopt_free(struct sshsigopt *opts);
|
|
|
|
|
2020-01-23 04:54:34 +00:00
|
|
|
/* Get public key from signature */
|
2020-01-23 23:31:52 +00:00
|
|
|
int sshsig_get_pubkey(struct sshbuf *signature, struct sshkey **pubkey);
|
2020-01-23 04:54:34 +00:00
|
|
|
|
|
|
|
/* Find principal in allowed_keys file, given a sshkey. Returns
|
|
|
|
* 0 on success.
|
|
|
|
*/
|
2020-01-23 23:31:52 +00:00
|
|
|
int sshsig_find_principals(const char *path, const struct sshkey *sign_key,
|
2021-07-23 03:37:52 +00:00
|
|
|
uint64_t verify_time, char **principal);
|
2020-01-23 04:54:34 +00:00
|
|
|
|
2019-09-03 08:34:19 +00:00
|
|
|
#endif /* SSHSIG_H */
|