blob: 487db116c1747641501880c5901ff1245d13e7d4 [file] [log] [blame]
djm@openbsd.org2a9c9f72019-09-03 08:34:19 +00001/*
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
20struct sshbuf;
21struct sshkey;
djm@openbsd.orgbab6feb2019-09-05 04:55:32 +000022struct sshsigopt;
djm@openbsd.org2a9c9f72019-09-03 08:34:19 +000023
24typedef int sshsig_signer(struct sshkey *, u_char **, size_t *,
djm@openbsd.org9a14c642019-10-31 21:23:19 +000025 const u_char *, size_t, const char *, const char *, u_int, void *);
djm@openbsd.org2a9c9f72019-09-03 08:34:19 +000026
djm@openbsd.orgd637c4a2019-09-03 08:35:27 +000027/* Buffer-oriented API */
28
djm@openbsd.org2a9c9f72019-09-03 08:34:19 +000029/*
djm@openbsd.orgd637c4a2019-09-03 08:35:27 +000030 * Creates a detached SSH signature for a given buffer.
djm@openbsd.org2a9c9f72019-09-03 08:34:19 +000031 * Returns 0 on success or a negative SSH_ERR_* error code on failure.
32 * out is populated with the detached signature, or NULL on failure.
33 */
djm@openbsd.orgd637c4a2019-09-03 08:35:27 +000034int sshsig_signb(struct sshkey *key, const char *hashalg,
djm@openbsd.org9a14c642019-10-31 21:23:19 +000035 const char *sk_provider, const struct sshbuf *message,
36 const char *sig_namespace, struct sshbuf **out,
37 sshsig_signer *signer, void *signer_ctx);
djm@openbsd.org2a9c9f72019-09-03 08:34:19 +000038
39/*
djm@openbsd.orgd637c4a2019-09-03 08:35:27 +000040 * Verifies that a detached signature is valid and optionally returns key
41 * used to sign via argument.
42 * Returns 0 on success or a negative SSH_ERR_* error code on failure.
43 */
44int sshsig_verifyb(struct sshbuf *signature,
45 const struct sshbuf *message, const char *sig_namespace,
46 struct sshkey **sign_keyp);
47
48/* File/FD-oriented API */
49
50/*
djm@openbsd.org2a9c9f72019-09-03 08:34:19 +000051 * Creates a detached SSH signature for a given file.
52 * Returns 0 on success or a negative SSH_ERR_* error code on failure.
53 * out is populated with the detached signature, or NULL on failure.
54 */
55int sshsig_sign_fd(struct sshkey *key, const char *hashalg,
djm@openbsd.org9a14c642019-10-31 21:23:19 +000056 const char *sk_provider, int fd, const char *sig_namespace,
57 struct sshbuf **out, sshsig_signer *signer, void *signer_ctx);
djm@openbsd.org2a9c9f72019-09-03 08:34:19 +000058
59/*
djm@openbsd.org2a9c9f72019-09-03 08:34:19 +000060 * Verifies that a detached signature over a file is valid and optionally
61 * returns key used to sign via argument.
62 * Returns 0 on success or a negative SSH_ERR_* error code on failure.
63 */
64int sshsig_verify_fd(struct sshbuf *signature, int fd,
65 const char *sig_namespace, struct sshkey **sign_keyp);
66
djm@openbsd.orgd637c4a2019-09-03 08:35:27 +000067/* Utility functions */
68
djm@openbsd.org2a9c9f72019-09-03 08:34:19 +000069/*
70 * Return a base64 encoded "ASCII armoured" version of a raw signature.
71 */
72int sshsig_armor(const struct sshbuf *blob, struct sshbuf **out);
73
74/*
75 * Decode a base64 encoded armoured signature to a raw signature.
76 */
77int sshsig_dearmor(struct sshbuf *sig, struct sshbuf **out);
78
79/*
80 * Checks whether a particular key/principal/namespace is permitted by
81 * an allowed_keys file. Returns 0 on success.
82 */
83int sshsig_check_allowed_keys(const char *path, const struct sshkey *sign_key,
84 const char *principal, const char *ns);
85
djm@openbsd.orgbab6feb2019-09-05 04:55:32 +000086/* Parse zero or more allowed_keys signature options */
87struct sshsigopt *sshsigopt_parse(const char *opts,
88 const char *path, u_long linenum, const char **errstrp);
89
90/* Free signature options */
91void sshsigopt_free(struct sshsigopt *opts);
92
djm@openbsd.org2a9c9f72019-09-03 08:34:19 +000093#endif /* SSHSIG_H */