[openssh-commits] [openssh] 05/06: upstream: refactor ECDSA-SK verification a little ahead of adding
git+noreply at mindrot.org
git+noreply at mindrot.org
Mon Jun 22 16:28:19 AEST 2020
This is an automated email from the git hooks/post-receive script.
djm pushed a commit to branch master
in repository openssh.
commit 64bc121097f377142f1387ffb2df7592c49935af
Author: djm at openbsd.org <djm at openbsd.org>
Date: Mon Jun 22 05:56:23 2020 +0000
upstream: refactor ECDSA-SK verification a little ahead of adding
support for FIDO webauthn signature verification support; ok markus@
OpenBSD-Commit-ID: c9f478fd8e0c1bd17e511ce8694f010d8e32043e
---
ssh-ecdsa-sk.c | 46 ++++++++++++++++++++++++----------------------
1 file changed, 24 insertions(+), 22 deletions(-)
diff --git a/ssh-ecdsa-sk.c b/ssh-ecdsa-sk.c
index 981d60d7..dcf605ba 100644
--- a/ssh-ecdsa-sk.c
+++ b/ssh-ecdsa-sk.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ssh-ecdsa-sk.c,v 1.5 2019/11/26 03:04:27 djm Exp $ */
+/* $OpenBSD: ssh-ecdsa-sk.c,v 1.6 2020/06/22 05:56:23 djm Exp $ */
/*
* Copyright (c) 2000 Markus Friedl. All rights reserved.
* Copyright (c) 2010 Damien Miller. All rights reserved.
@@ -83,17 +83,24 @@ ssh_ecdsa_sk_verify(const struct sshkey *key,
/* fetch signature */
if ((b = sshbuf_from(signature, signaturelen)) == NULL)
return SSH_ERR_ALLOC_FAIL;
- if (sshbuf_get_cstring(b, &ktype, NULL) != 0 ||
- sshbuf_froms(b, &sigbuf) != 0 ||
+ if ((details = calloc(1, sizeof(*details))) == NULL) {
+ ret = SSH_ERR_ALLOC_FAIL;
+ goto out;
+ }
+ if (sshbuf_get_cstring(b, &ktype, NULL) != 0) {
+ ret = SSH_ERR_INVALID_FORMAT;
+ goto out;
+ }
+ if (strcmp(ktype, "sk-ecdsa-sha2-nistp256 at openssh.com") != 0) {
+ ret = SSH_ERR_INVALID_FORMAT;
+ goto out;
+ }
+ if (sshbuf_froms(b, &sigbuf) != 0 ||
sshbuf_get_u8(b, &sig_flags) != 0 ||
sshbuf_get_u32(b, &sig_counter) != 0) {
ret = SSH_ERR_INVALID_FORMAT;
goto out;
}
- if (strcmp(sshkey_ssh_name_plain(key), ktype) != 0) {
- ret = SSH_ERR_KEY_TYPE_MISMATCH;
- goto out;
- }
if (sshbuf_len(b) != 0) {
ret = SSH_ERR_UNEXPECTED_TRAILING_DATA;
goto out;
@@ -105,12 +112,8 @@ ssh_ecdsa_sk_verify(const struct sshkey *key,
ret = SSH_ERR_INVALID_FORMAT;
goto out;
}
- if ((sig = ECDSA_SIG_new()) == NULL) {
- ret = SSH_ERR_ALLOC_FAIL;
- goto out;
- }
- if (!ECDSA_SIG_set0(sig, sig_r, sig_s)) {
- ret = SSH_ERR_LIBCRYPTO_ERROR;
+ if (sshbuf_len(sigbuf) != 0) {
+ ret = SSH_ERR_UNEXPECTED_TRAILING_DATA;
goto out;
}
#ifdef DEBUG_SK
@@ -123,13 +126,16 @@ ssh_ecdsa_sk_verify(const struct sshkey *key,
fprintf(stderr, "%s: sig_flags = 0x%02x, sig_counter = %u\n",
__func__, sig_flags, sig_counter);
#endif
+ if ((sig = ECDSA_SIG_new()) == NULL) {
+ ret = SSH_ERR_ALLOC_FAIL;
+ goto out;
+ }
+ if (!ECDSA_SIG_set0(sig, sig_r, sig_s)) {
+ ret = SSH_ERR_LIBCRYPTO_ERROR;
+ goto out;
+ }
sig_r = sig_s = NULL; /* transferred */
- if (sshbuf_len(sigbuf) != 0) {
- ret = SSH_ERR_UNEXPECTED_TRAILING_DATA;
- goto out;
- }
-
/* Reconstruct data that was supposedly signed */
if ((original_signed = sshbuf_new()) == NULL) {
ret = SSH_ERR_ALLOC_FAIL;
@@ -158,10 +164,6 @@ ssh_ecdsa_sk_verify(const struct sshkey *key,
if ((ret = ssh_digest_buffer(SSH_DIGEST_SHA256, original_signed,
sighash, sizeof(sighash))) != 0)
goto out;
- if ((details = calloc(1, sizeof(*details))) == NULL) {
- ret = SSH_ERR_ALLOC_FAIL;
- goto out;
- }
details->sk_counter = sig_counter;
details->sk_flags = sig_flags;
#ifdef DEBUG_SK
--
To stop receiving notification emails like this one, please contact
djm at mindrot.org.
More information about the openssh-commits
mailing list