diff options
author | djm@openbsd.org <djm@openbsd.org> | 2018-03-03 03:01:50 +0000 |
---|---|---|
committer | Damien Miller <djm@mindrot.org> | 2018-03-03 14:20:47 +1100 |
commit | 26074380767e639ef89321610e146ae11016b385 (patch) | |
tree | 6fdb86b276ff10473c0f0f5277de4fc47a3c579c /sshconnect2.c | |
parent | f493d2b0b66fb003ed29f31dd66ff1aeb64be1fc (diff) |
upstream: warn when the agent returns a signature type that was
different to what was requested. This might happen when an old/non-OpenSSH
agent is asked to make a rsa-sha2-256/512 signature but only supports
ssh-rsa. bz#2799 feedback and ok markus@
OpenBSD-Commit-ID: 760c0f9438c5c58abc16b5f98008ff2d95cb13ce
Diffstat (limited to 'sshconnect2.c')
-rw-r--r-- | sshconnect2.c | 41 |
1 files changed, 34 insertions, 7 deletions
diff --git a/sshconnect2.c b/sshconnect2.c index 8138e46e0..2f0a57fac 100644 --- a/sshconnect2.c +++ b/sshconnect2.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: sshconnect2.c,v 1.268 2018/02/07 22:52:45 dtucker Exp $ */ | 1 | /* $OpenBSD: sshconnect2.c,v 1.269 2018/03/03 03:01:50 djm Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2000 Markus Friedl. All rights reserved. | 3 | * Copyright (c) 2000 Markus Friedl. All rights reserved. |
4 | * Copyright (c) 2008 Damien Miller. All rights reserved. | 4 | * Copyright (c) 2008 Damien Miller. All rights reserved. |
@@ -1002,17 +1002,44 @@ key_sign_encode(const struct sshkey *key) | |||
1002 | return key_ssh_name(key); | 1002 | return key_ssh_name(key); |
1003 | } | 1003 | } |
1004 | 1004 | ||
1005 | /* | ||
1006 | * Some agents will return ssh-rsa signatures when asked to make a | ||
1007 | * rsa-sha2-* signature. Check what they actually gave back and warn the | ||
1008 | * user if the agent has returned an unexpected type. | ||
1009 | */ | ||
1010 | static int | ||
1011 | check_sigtype(const struct sshkey *key, const u_char *sig, size_t len) | ||
1012 | { | ||
1013 | int r; | ||
1014 | char *sigtype = NULL; | ||
1015 | const char *alg = key_sign_encode(key); | ||
1016 | |||
1017 | if ((r = sshkey_sigtype(sig, len, &sigtype)) != 0) | ||
1018 | return r; | ||
1019 | if (strcmp(sigtype, alg) != 0) { | ||
1020 | logit("warning: agent returned different signature type %s " | ||
1021 | "(expected %s)", sigtype, alg); | ||
1022 | } | ||
1023 | free(sigtype); | ||
1024 | /* Incorrect signature types aren't an error ... yet */ | ||
1025 | return 0; | ||
1026 | } | ||
1027 | |||
1005 | static int | 1028 | static int |
1006 | identity_sign(struct identity *id, u_char **sigp, size_t *lenp, | 1029 | identity_sign(struct identity *id, u_char **sigp, size_t *lenp, |
1007 | const u_char *data, size_t datalen, u_int compat) | 1030 | const u_char *data, size_t datalen, u_int compat) |
1008 | { | 1031 | { |
1009 | struct sshkey *prv; | 1032 | struct sshkey *prv; |
1010 | int ret; | 1033 | int r; |
1011 | 1034 | ||
1012 | /* the agent supports this key */ | 1035 | /* the agent supports this key */ |
1013 | if (id->key != NULL && id->agent_fd != -1) | 1036 | if (id->key != NULL && id->agent_fd != -1) { |
1014 | return ssh_agent_sign(id->agent_fd, id->key, sigp, lenp, | 1037 | if ((r = ssh_agent_sign(id->agent_fd, id->key, sigp, lenp, |
1015 | data, datalen, key_sign_encode(id->key), compat); | 1038 | data, datalen, key_sign_encode(id->key), compat)) != 0 || |
1039 | (r = check_sigtype(id->key, *sigp, *lenp)) != 0) | ||
1040 | return r; | ||
1041 | return 0; | ||
1042 | } | ||
1016 | 1043 | ||
1017 | /* | 1044 | /* |
1018 | * we have already loaded the private key or | 1045 | * we have already loaded the private key or |
@@ -1031,10 +1058,10 @@ identity_sign(struct identity *id, u_char **sigp, size_t *lenp, | |||
1031 | __func__, id->filename); | 1058 | __func__, id->filename); |
1032 | return SSH_ERR_KEY_NOT_FOUND; | 1059 | return SSH_ERR_KEY_NOT_FOUND; |
1033 | } | 1060 | } |
1034 | ret = sshkey_sign(prv, sigp, lenp, data, datalen, | 1061 | r = sshkey_sign(prv, sigp, lenp, data, datalen, |
1035 | key_sign_encode(prv), compat); | 1062 | key_sign_encode(prv), compat); |
1036 | sshkey_free(prv); | 1063 | sshkey_free(prv); |
1037 | return (ret); | 1064 | return r; |
1038 | } | 1065 | } |
1039 | 1066 | ||
1040 | static int | 1067 | static int |