From e339f7589ec73c2972f1d3213cfb0132500c8181 Mon Sep 17 00:00:00 2001 From: Markus Friedl Date: Wed, 11 Jan 2012 18:36:56 +0100 Subject: [PATCH] key_verify now returns 0 on success and < 0 on error (used to return 1 on success 0 on failed signatures and -1 on error) --- ssh/auth2-pubkey.c | 2 +- ssh/kexdhc.c | 2 +- ssh/kexgexc.c | 2 +- ssh/key.c | 3 +-- ssh/monitor.c | 10 +++++----- 5 files changed, 9 insertions(+), 10 deletions(-) diff --git a/ssh/auth2-pubkey.c b/ssh/auth2-pubkey.c index 5beb104..ac37cc5 100644 --- a/ssh/auth2-pubkey.c +++ b/ssh/auth2-pubkey.c @@ -145,7 +145,7 @@ userauth_pubkey(struct ssh *ssh) authenticated = 0; if (PRIVSEP(user_key_allowed(authctxt->pw, key)) && PRIVSEP(sshkey_verify(key, sig, slen, buffer_ptr(&b), - buffer_len(&b), datafellows)) == 1) + buffer_len(&b), datafellows)) == 0) authenticated = 1; buffer_free(&b); xfree(sig); diff --git a/ssh/kexdhc.c b/ssh/kexdhc.c index 5399d5d..6272310 100644 --- a/ssh/kexdhc.c +++ b/ssh/kexdhc.c @@ -164,7 +164,7 @@ input_kex_dh(int type, u_int32_t seq, struct ssh *ssh) DH_free(kexdhc_state->dh); if (sshkey_verify(server_host_key, signature, slen, hash, hashlen, - datafellows) != 1) + datafellows) != 0) fatal("key_verify failed for server_host_key"); sshkey_free(server_host_key); xfree(signature); diff --git a/ssh/kexgexc.c b/ssh/kexgexc.c index 5552e37..6e20c40 100644 --- a/ssh/kexgexc.c +++ b/ssh/kexgexc.c @@ -236,7 +236,7 @@ input_kex_dh_gex_reply(int type, u_int32_t seq, struct ssh *ssh) BN_clear_free(dh_server_pub); if (sshkey_verify(server_host_key, signature, slen, hash, - hashlen, datafellows) != 1) + hashlen, datafellows) != 0) fatal("key_verify failed for server_host_key"); sshkey_free(server_host_key); xfree(signature); diff --git a/ssh/key.c b/ssh/key.c index c317adb..0b4d9bb 100644 --- a/ssh/key.c +++ b/ssh/key.c @@ -1748,8 +1748,7 @@ sshkey_sign(const struct sshkey *key, } /* - * key_verify returns 1 for a correct signature, 0 for an incorrect signature - * and -1 on error. + * ssh_key_verify returns 0 for a correct signature and < 0 on error. */ int sshkey_verify(const struct sshkey *key, diff --git a/ssh/monitor.c b/ssh/monitor.c index 05d5c53..1a4ec65 100644 --- a/ssh/monitor.c +++ b/ssh/monitor.c @@ -1035,7 +1035,7 @@ mm_answer_keyverify(int sock, Buffer *m) struct sshkey *key; u_char *signature, *data, *blob; u_int signaturelen, datalen, bloblen; - int r, verified = 0, valid_data = 0; + int r, valid_data = 0; blob = buffer_get_string(m, &bloblen); signature = buffer_get_string(m, &signaturelen); @@ -1063,10 +1063,10 @@ mm_answer_keyverify(int sock, Buffer *m) if (!valid_data) fatal("%s: bad signature data blob", __func__); - verified = sshkey_verify(key, signature, signaturelen, data, datalen, + r = sshkey_verify(key, signature, signaturelen, data, datalen, datafellows); debug3("%s: key %p signature %s", - __func__, key, (verified == 1) ? "verified" : "unverified"); + __func__, key, (r == 0) ? "verified" : "unverified"); sshkey_free(key); xfree(blob); @@ -1078,10 +1078,10 @@ mm_answer_keyverify(int sock, Buffer *m) monitor_reset_key_state(); buffer_clear(m); - buffer_put_int(m, verified); + buffer_put_int(m, r); mm_request_send(sock, MONITOR_ANS_KEYVERIFY, m); - return (verified == 1); + return (r==0); } static void