diff options
author | djm@openbsd.org <djm@openbsd.org> | 2019-10-31 21:23:19 +0000 |
---|---|---|
committer | Damien Miller <djm@mindrot.org> | 2019-11-01 09:46:10 +1100 |
commit | 9a14c64c38fc14d0029f1c7bc70cf62cc7f0fdf9 (patch) | |
tree | d79bb8d66eeba8e353f18dac919cb65d0ad896c7 /sshsig.c | |
parent | 07da39f71d36fb547749a5b16aa8892e621a7e4a (diff) |
upstream: Refactor signing - use sshkey_sign for everything,
including the new U2F signatures.
Don't use sshsk_ecdsa_sign() directly, instead make it reachable via
sshkey_sign() like all other signature operations. This means that
we need to add a provider argument to sshkey_sign(), so most of this
change is mechanically adding that.
Suggested by / ok markus@
OpenBSD-Commit-ID: d5193a03fcfa895085d91b2b83d984a9fde76c8c
Diffstat (limited to 'sshsig.c')
-rw-r--r-- | sshsig.c | 21 |
1 files changed, 11 insertions, 10 deletions
@@ -151,8 +151,9 @@ done: | |||
151 | 151 | ||
152 | static int | 152 | static int |
153 | sshsig_wrap_sign(struct sshkey *key, const char *hashalg, | 153 | sshsig_wrap_sign(struct sshkey *key, const char *hashalg, |
154 | const struct sshbuf *h_message, const char *sig_namespace, | 154 | const char *sk_provider, const struct sshbuf *h_message, |
155 | struct sshbuf **out, sshsig_signer *signer, void *signer_ctx) | 155 | const char *sig_namespace, struct sshbuf **out, |
156 | sshsig_signer *signer, void *signer_ctx) | ||
156 | { | 157 | { |
157 | int r; | 158 | int r; |
158 | size_t slen = 0; | 159 | size_t slen = 0; |
@@ -184,14 +185,14 @@ sshsig_wrap_sign(struct sshkey *key, const char *hashalg, | |||
184 | if (signer != NULL) { | 185 | if (signer != NULL) { |
185 | if ((r = signer(key, &sig, &slen, | 186 | if ((r = signer(key, &sig, &slen, |
186 | sshbuf_ptr(tosign), sshbuf_len(tosign), | 187 | sshbuf_ptr(tosign), sshbuf_len(tosign), |
187 | sign_alg, 0, signer_ctx)) != 0) { | 188 | sign_alg, sk_provider, 0, signer_ctx)) != 0) { |
188 | error("Couldn't sign message: %s", ssh_err(r)); | 189 | error("Couldn't sign message: %s", ssh_err(r)); |
189 | goto done; | 190 | goto done; |
190 | } | 191 | } |
191 | } else { | 192 | } else { |
192 | if ((r = sshkey_sign(key, &sig, &slen, | 193 | if ((r = sshkey_sign(key, &sig, &slen, |
193 | sshbuf_ptr(tosign), sshbuf_len(tosign), | 194 | sshbuf_ptr(tosign), sshbuf_len(tosign), |
194 | sign_alg, 0)) != 0) { | 195 | sign_alg, sk_provider, 0)) != 0) { |
195 | error("Couldn't sign message: %s", ssh_err(r)); | 196 | error("Couldn't sign message: %s", ssh_err(r)); |
196 | goto done; | 197 | goto done; |
197 | } | 198 | } |
@@ -425,7 +426,7 @@ hash_buffer(const struct sshbuf *m, const char *hashalg, struct sshbuf **bp) | |||
425 | } | 426 | } |
426 | 427 | ||
427 | int | 428 | int |
428 | sshsig_signb(struct sshkey *key, const char *hashalg, | 429 | sshsig_signb(struct sshkey *key, const char *hashalg, const char *sk_provider, |
429 | const struct sshbuf *message, const char *sig_namespace, | 430 | const struct sshbuf *message, const char *sig_namespace, |
430 | struct sshbuf **out, sshsig_signer *signer, void *signer_ctx) | 431 | struct sshbuf **out, sshsig_signer *signer, void *signer_ctx) |
431 | { | 432 | { |
@@ -440,8 +441,8 @@ sshsig_signb(struct sshkey *key, const char *hashalg, | |||
440 | error("%s: hash_buffer failed: %s", __func__, ssh_err(r)); | 441 | error("%s: hash_buffer failed: %s", __func__, ssh_err(r)); |
441 | goto out; | 442 | goto out; |
442 | } | 443 | } |
443 | if ((r = sshsig_wrap_sign(key, hashalg, b, sig_namespace, out, | 444 | if ((r = sshsig_wrap_sign(key, hashalg, sk_provider, b, |
444 | signer, signer_ctx)) != 0) | 445 | sig_namespace, out, signer, signer_ctx)) != 0) |
445 | goto out; | 446 | goto out; |
446 | /* success */ | 447 | /* success */ |
447 | r = 0; | 448 | r = 0; |
@@ -551,7 +552,7 @@ hash_file(int fd, const char *hashalg, struct sshbuf **bp) | |||
551 | } | 552 | } |
552 | 553 | ||
553 | int | 554 | int |
554 | sshsig_sign_fd(struct sshkey *key, const char *hashalg, | 555 | sshsig_sign_fd(struct sshkey *key, const char *hashalg, const char *sk_provider, |
555 | int fd, const char *sig_namespace, struct sshbuf **out, | 556 | int fd, const char *sig_namespace, struct sshbuf **out, |
556 | sshsig_signer *signer, void *signer_ctx) | 557 | sshsig_signer *signer, void *signer_ctx) |
557 | { | 558 | { |
@@ -566,8 +567,8 @@ sshsig_sign_fd(struct sshkey *key, const char *hashalg, | |||
566 | error("%s: hash_file failed: %s", __func__, ssh_err(r)); | 567 | error("%s: hash_file failed: %s", __func__, ssh_err(r)); |
567 | return r; | 568 | return r; |
568 | } | 569 | } |
569 | if ((r = sshsig_wrap_sign(key, hashalg, b, sig_namespace, out, | 570 | if ((r = sshsig_wrap_sign(key, hashalg, sk_provider, b, |
570 | signer, signer_ctx)) != 0) | 571 | sig_namespace, out, signer, signer_ctx)) != 0) |
571 | goto out; | 572 | goto out; |
572 | /* success */ | 573 | /* success */ |
573 | r = 0; | 574 | r = 0; |