Annotation of src/usr.bin/ssh/sshsig.h, Revision 1.8
1.1 djm 1: /*
2: * Copyright (c) 2019 Google LLC
3: *
4: * Permission to use, copy, modify, and distribute this software for any
5: * purpose with or without fee is hereby granted, provided that the above
6: * copyright notice and this permission notice appear in all copies.
7: *
8: * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9: * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10: * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11: * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12: * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13: * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14: * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15: */
16:
17: #ifndef SSHSIG_H
18: #define SSHSIG_H
19:
20: struct sshbuf;
21: struct sshkey;
1.3 djm 22: struct sshsigopt;
1.5 djm 23: struct sshkey_sig_details;
1.1 djm 24:
25: typedef int sshsig_signer(struct sshkey *, u_char **, size_t *,
1.8 ! djm 26: const u_char *, size_t, const char *, const char *, const char *,
! 27: u_int, void *);
1.1 djm 28:
1.2 djm 29: /* Buffer-oriented API */
30:
1.1 djm 31: /*
1.2 djm 32: * Creates a detached SSH signature for a given buffer.
1.1 djm 33: * Returns 0 on success or a negative SSH_ERR_* error code on failure.
34: * out is populated with the detached signature, or NULL on failure.
35: */
1.2 djm 36: int sshsig_signb(struct sshkey *key, const char *hashalg,
1.8 ! djm 37: const char *sk_provider, const char *sk_pin, const struct sshbuf *message,
1.4 djm 38: const char *sig_namespace, struct sshbuf **out,
39: sshsig_signer *signer, void *signer_ctx);
1.1 djm 40:
41: /*
1.2 djm 42: * Verifies that a detached signature is valid and optionally returns key
43: * used to sign via argument.
44: * Returns 0 on success or a negative SSH_ERR_* error code on failure.
45: */
46: int sshsig_verifyb(struct sshbuf *signature,
47: const struct sshbuf *message, const char *sig_namespace,
1.5 djm 48: struct sshkey **sign_keyp, struct sshkey_sig_details **sig_details);
1.2 djm 49:
50: /* File/FD-oriented API */
51:
52: /*
1.1 djm 53: * Creates a detached SSH signature for a given file.
54: * Returns 0 on success or a negative SSH_ERR_* error code on failure.
55: * out is populated with the detached signature, or NULL on failure.
56: */
57: int sshsig_sign_fd(struct sshkey *key, const char *hashalg,
1.8 ! djm 58: const char *sk_provider, const char *sk_pin,
! 59: int fd, const char *sig_namespace,
1.4 djm 60: struct sshbuf **out, sshsig_signer *signer, void *signer_ctx);
1.1 djm 61:
62: /*
63: * Verifies that a detached signature over a file is valid and optionally
64: * returns key used to sign via argument.
65: * Returns 0 on success or a negative SSH_ERR_* error code on failure.
66: */
67: int sshsig_verify_fd(struct sshbuf *signature, int fd,
1.5 djm 68: const char *sig_namespace, struct sshkey **sign_keyp,
69: struct sshkey_sig_details **sig_details);
1.2 djm 70:
71: /* Utility functions */
1.1 djm 72:
73: /*
74: * Return a base64 encoded "ASCII armoured" version of a raw signature.
75: */
76: int sshsig_armor(const struct sshbuf *blob, struct sshbuf **out);
77:
78: /*
79: * Decode a base64 encoded armoured signature to a raw signature.
80: */
81: int sshsig_dearmor(struct sshbuf *sig, struct sshbuf **out);
82:
83: /*
84: * Checks whether a particular key/principal/namespace is permitted by
85: * an allowed_keys file. Returns 0 on success.
86: */
87: int sshsig_check_allowed_keys(const char *path, const struct sshkey *sign_key,
88: const char *principal, const char *ns);
1.3 djm 89:
90: /* Parse zero or more allowed_keys signature options */
91: struct sshsigopt *sshsigopt_parse(const char *opts,
92: const char *path, u_long linenum, const char **errstrp);
93:
94: /* Free signature options */
95: void sshsigopt_free(struct sshsigopt *opts);
1.1 djm 96:
1.6 djm 97: /* Get public key from signature */
1.7 djm 98: int sshsig_get_pubkey(struct sshbuf *signature, struct sshkey **pubkey);
1.6 djm 99:
100: /* Find principal in allowed_keys file, given a sshkey. Returns
101: * 0 on success.
102: */
1.7 djm 103: int sshsig_find_principals(const char *path, const struct sshkey *sign_key,
1.6 djm 104: char **principal);
105:
1.1 djm 106: #endif /* SSHSIG_H */