forked from openssh/openssh-portable
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pass negotiated signing algorithm though to sshkey_verify() and check that the negotiated algorithm matches the type in the signature (only matters for RSA SHA1/SHA2 sigs). ok markus@ OpenBSD-Commit-ID: 735fb15bf4adc060d3bee9d047a4bcaaa81b1af9
- Loading branch information
Showing
19 changed files
with
58 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
/* $OpenBSD: clientloop.c,v 1.307 2017/11/25 05:58:47 dtucker Exp $ */ | ||
/* $OpenBSD: clientloop.c,v 1.308 2017/12/18 02:25:15 djm Exp $ */ | ||
/* | ||
* Author: Tatu Ylonen <[email protected]> | ||
* Copyright (c) 1995 Tatu Ylonen <[email protected]>, Espoo, Finland | ||
|
@@ -1934,7 +1934,8 @@ client_global_hostkeys_private_confirm(struct ssh *ssh, int type, | |
goto out; | ||
} | ||
if ((r = sshkey_verify(ctx->keys[i], sig, siglen, | ||
sshbuf_ptr(signdata), sshbuf_len(signdata), 0)) != 0) { | ||
sshbuf_ptr(signdata), sshbuf_len(signdata), | ||
ssh->kex->hostkey_alg, 0)) != 0) { | ||
error("%s: server gave bad signature for %s key %zu", | ||
__func__, sshkey_type(ctx->keys[i]), i); | ||
goto out; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
/* $OpenBSD: monitor.c,v 1.175 2017/10/05 15:52:03 djm Exp $ */ | ||
/* $OpenBSD: monitor.c,v 1.176 2017/12/18 02:25:15 djm Exp $ */ | ||
/* | ||
* Copyright 2002 Niels Provos <[email protected]> | ||
* Copyright 2002 Markus Friedl <[email protected]> | ||
|
@@ -1339,12 +1339,14 @@ mm_answer_keyverify(int sock, struct sshbuf *m) | |
{ | ||
struct sshkey *key; | ||
u_char *signature, *data, *blob; | ||
char *sigalg; | ||
size_t signaturelen, datalen, bloblen; | ||
int r, ret, valid_data = 0, encoded_ret; | ||
|
||
if ((r = sshbuf_get_string(m, &blob, &bloblen)) != 0 || | ||
(r = sshbuf_get_string(m, &signature, &signaturelen)) != 0 || | ||
(r = sshbuf_get_string(m, &data, &datalen)) != 0) | ||
(r = sshbuf_get_string(m, &data, &datalen)) != 0 || | ||
(r = sshbuf_get_cstring(m, &sigalg, NULL)) != 0) | ||
fatal("%s: buffer error: %s", __func__, ssh_err(r)); | ||
|
||
if (hostbased_cuser == NULL || hostbased_chost == NULL || | ||
|
@@ -1373,7 +1375,7 @@ mm_answer_keyverify(int sock, struct sshbuf *m) | |
fatal("%s: bad signature data blob", __func__); | ||
|
||
ret = sshkey_verify(key, signature, signaturelen, data, datalen, | ||
active_state->compat); | ||
sigalg, active_state->compat); | ||
debug3("%s: %s %p signature %s", __func__, auth_method, key, | ||
(ret == 0) ? "verified" : "unverified"); | ||
auth2_record_key(authctxt, ret == 0, key); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
/* $OpenBSD: monitor_wrap.c,v 1.95 2017/10/05 15:52:03 djm Exp $ */ | ||
/* $OpenBSD: monitor_wrap.c,v 1.96 2017/12/18 02:25:15 djm Exp $ */ | ||
/* | ||
* Copyright 2002 Niels Provos <[email protected]> | ||
* Copyright 2002 Markus Friedl <[email protected]> | ||
|
@@ -441,7 +441,7 @@ mm_key_allowed(enum mm_keytype type, const char *user, const char *host, | |
|
||
int | ||
mm_sshkey_verify(const struct sshkey *key, const u_char *sig, size_t siglen, | ||
const u_char *data, size_t datalen, u_int compat) | ||
const u_char *data, size_t datalen, const char *sigalg, u_int compat) | ||
{ | ||
Buffer m; | ||
u_char *blob; | ||
|
@@ -458,6 +458,7 @@ mm_sshkey_verify(const struct sshkey *key, const u_char *sig, size_t siglen, | |
buffer_put_string(&m, blob, len); | ||
buffer_put_string(&m, sig, siglen); | ||
buffer_put_string(&m, data, datalen); | ||
buffer_put_cstring(&m, sigalg); | ||
free(blob); | ||
|
||
mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_KEYVERIFY, &m); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
/* $OpenBSD: monitor_wrap.h,v 1.35 2017/05/31 08:09:45 markus Exp $ */ | ||
/* $OpenBSD: monitor_wrap.h,v 1.36 2017/12/18 02:25:15 djm Exp $ */ | ||
|
||
/* | ||
* Copyright 2002 Niels Provos <[email protected]> | ||
|
@@ -51,7 +51,7 @@ int mm_user_key_allowed(struct passwd *, struct sshkey *, int); | |
int mm_hostbased_key_allowed(struct passwd *, const char *, | ||
const char *, struct sshkey *); | ||
int mm_sshkey_verify(const struct sshkey *, const u_char *, size_t, | ||
const u_char *, size_t, u_int); | ||
const u_char *, size_t, const char *, u_int); | ||
|
||
#ifdef GSSAPI | ||
OM_uint32 mm_ssh_gssapi_server_ctx(Gssctxt **, gss_OID); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
/* $OpenBSD: serverloop.c,v 1.200 2017/12/10 05:55:29 dtucker Exp $ */ | ||
/* $OpenBSD: serverloop.c,v 1.201 2017/12/18 02:25:15 djm Exp $ */ | ||
/* | ||
* Author: Tatu Ylonen <[email protected]> | ||
* Copyright (c) 1995 Tatu Ylonen <[email protected]>, Espoo, Finland | ||
|
@@ -715,7 +715,8 @@ server_input_hostkeys_prove(struct ssh *ssh, struct sshbuf **respp) | |
ssh->kex->session_id, ssh->kex->session_id_len)) != 0 || | ||
(r = sshkey_puts(key, sigbuf)) != 0 || | ||
(r = ssh->kex->sign(key_prv, key_pub, &sig, &slen, | ||
sshbuf_ptr(sigbuf), sshbuf_len(sigbuf), NULL, 0)) != 0 || | ||
sshbuf_ptr(sigbuf), sshbuf_len(sigbuf), | ||
ssh->kex->hostkey_alg, 0)) != 0 || | ||
(r = sshbuf_put_string(resp, sig, slen)) != 0) { | ||
error("%s: couldn't prepare signature: %s", | ||
__func__, ssh_err(r)); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
/* $OpenBSD: ssh-keygen.c,v 1.308 2017/11/03 05:14:04 djm Exp $ */ | ||
/* $OpenBSD: ssh-keygen.c,v 1.309 2017/12/18 02:25:15 djm Exp $ */ | ||
/* | ||
* Author: Tatu Ylonen <[email protected]> | ||
* Copyright (c) 1994 Tatu Ylonen <[email protected]>, Espoo, Finland | ||
|
@@ -539,7 +539,7 @@ do_convert_private_ssh2_from_blob(u_char *blob, u_int blen) | |
|
||
/* try the key */ | ||
if (sshkey_sign(key, &sig, &slen, data, sizeof(data), NULL, 0) != 0 || | ||
sshkey_verify(key, sig, slen, data, sizeof(data), 0) != 0) { | ||
sshkey_verify(key, sig, slen, data, sizeof(data), NULL, 0) != 0) { | ||
sshkey_free(key); | ||
free(sig); | ||
return NULL; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
/* $OpenBSD: ssh-rsa.c,v 1.62 2017/07/01 13:50:45 djm Exp $ */ | ||
/* $OpenBSD: ssh-rsa.c,v 1.63 2017/12/18 02:25:15 djm Exp $ */ | ||
/* | ||
* Copyright (c) 2000, 2003 Markus Friedl <[email protected]> | ||
* | ||
|
@@ -198,9 +198,10 @@ ssh_rsa_sign(const struct sshkey *key, u_char **sigp, size_t *lenp, | |
|
||
int | ||
ssh_rsa_verify(const struct sshkey *key, | ||
const u_char *sig, size_t siglen, const u_char *data, size_t datalen) | ||
const u_char *sig, size_t siglen, const u_char *data, size_t datalen, | ||
const char *alg) | ||
{ | ||
char *ktype = NULL; | ||
char *sigtype = NULL; | ||
int hash_alg, ret = SSH_ERR_INTERNAL_ERROR; | ||
size_t len, diff, modlen, dlen; | ||
struct sshbuf *b = NULL; | ||
|
@@ -215,11 +216,17 @@ ssh_rsa_verify(const struct sshkey *key, | |
|
||
if ((b = sshbuf_from(sig, siglen)) == NULL) | ||
return SSH_ERR_ALLOC_FAIL; | ||
if (sshbuf_get_cstring(b, &ktype, NULL) != 0) { | ||
if (sshbuf_get_cstring(b, &sigtype, NULL) != 0) { | ||
ret = SSH_ERR_INVALID_FORMAT; | ||
goto out; | ||
} | ||
if ((hash_alg = rsa_hash_alg_from_ident(ktype)) == -1) { | ||
/* XXX djm: need cert types that reliably yield SHA-2 signatures */ | ||
if (alg != NULL && strcmp(alg, sigtype) != 0 && | ||
strcmp(alg, "[email protected]") != 0) { | ||
ret = SSH_ERR_SIGNATURE_INVALID; | ||
goto out; | ||
} | ||
if ((hash_alg = rsa_hash_alg_from_ident(sigtype)) == -1) { | ||
ret = SSH_ERR_KEY_TYPE_MISMATCH; | ||
goto out; | ||
} | ||
|
@@ -263,7 +270,7 @@ ssh_rsa_verify(const struct sshkey *key, | |
explicit_bzero(sigblob, len); | ||
free(sigblob); | ||
} | ||
free(ktype); | ||
free(sigtype); | ||
sshbuf_free(b); | ||
explicit_bzero(digest, sizeof(digest)); | ||
return ret; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters