1
0
mirror of https://git.libssh.org/projects/libssh.git synced 2025-08-08 19:02:06 +03:00

pki: Use SHA-2 for session ID signing with ECDSA keys

Previously, SHA-1 was used always.

BUG: https://red.libssh.org/issues/148

Signed-off-by: Alan Dunn <amdunn@gmail.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
This commit is contained in:
Alan Dunn
2014-02-14 10:36:29 -06:00
committed by Andreas Schneider
parent 9c2127b798
commit 15f3988bc8

View File

@@ -1299,6 +1299,11 @@ int ssh_pki_signature_verify_blob(ssh_session session,
evp(key->ecdsa_nid, digest, dlen, ehash, &elen); evp(key->ecdsa_nid, digest, dlen, ehash, &elen);
#ifdef DEBUG_CRYPTO
ssh_print_hexa("Hash to be verified with ecdsa",
ehash, elen);
#endif
rc = pki_signature_verify(session, rc = pki_signature_verify(session,
sig, sig,
key, key,
@@ -1365,6 +1370,10 @@ ssh_string ssh_pki_do_sign(ssh_session session,
evp_update(ctx, buffer_get_rest(sigbuf), buffer_get_rest_len(sigbuf)); evp_update(ctx, buffer_get_rest(sigbuf), buffer_get_rest_len(sigbuf));
evp_final(ctx, ehash, &elen); evp_final(ctx, ehash, &elen);
#ifdef DEBUG_CRYPTO
ssh_print_hexa("Hash being signed", ehash, elen);
#endif
sig = pki_do_sign(privkey, ehash, elen); sig = pki_do_sign(privkey, ehash, elen);
#endif #endif
} else { } else {
@@ -1458,10 +1467,8 @@ ssh_string ssh_srv_pki_do_sign_sessionid(ssh_session session,
const ssh_key privkey) const ssh_key privkey)
{ {
struct ssh_crypto_struct *crypto; struct ssh_crypto_struct *crypto;
unsigned char hash[SHA_DIGEST_LEN] = {0};
ssh_signature sig; ssh_signature sig;
ssh_string sig_blob; ssh_string sig_blob;
SHACTX ctx;
int rc; int rc;
if (session == NULL || privkey == NULL || !ssh_key_is_private(privkey)) { if (session == NULL || privkey == NULL || !ssh_key_is_private(privkey)) {
@@ -1470,14 +1477,36 @@ ssh_string ssh_srv_pki_do_sign_sessionid(ssh_session session,
crypto = session->next_crypto ? session->next_crypto : crypto = session->next_crypto ? session->next_crypto :
session->current_crypto; session->current_crypto;
ctx = sha1_init();
if (ctx == NULL) {
return NULL;
}
if (crypto->secret_hash == NULL){ if (crypto->secret_hash == NULL){
ssh_set_error(session,SSH_FATAL,"Missing secret_hash"); ssh_set_error(session,SSH_FATAL,"Missing secret_hash");
return NULL; return NULL;
} }
if (privkey->type == SSH_KEYTYPE_ECDSA) {
#ifdef HAVE_ECC
unsigned char ehash[EVP_DIGEST_LEN] = {0};
uint32_t elen;
evp(privkey->ecdsa_nid, crypto->secret_hash, crypto->digest_len,
ehash, &elen);
#ifdef DEBUG_CRYPTO
ssh_print_hexa("Hash being signed", ehash, elen);
#endif
sig = pki_do_sign_sessionid(privkey, ehash, elen);
if (sig == NULL) {
return NULL;
}
#endif
} else {
unsigned char hash[SHA_DIGEST_LEN] = {0};
SHACTX ctx;
ctx = sha1_init();
if (ctx == NULL) {
return NULL;
}
sha1_update(ctx, crypto->secret_hash, crypto->digest_len); sha1_update(ctx, crypto->secret_hash, crypto->digest_len);
sha1_final(hash, ctx); sha1_final(hash, ctx);
@@ -1489,6 +1518,7 @@ ssh_string ssh_srv_pki_do_sign_sessionid(ssh_session session,
if (sig == NULL) { if (sig == NULL) {
return NULL; return NULL;
} }
}
rc = ssh_pki_export_signature_blob(sig, &sig_blob); rc = ssh_pki_export_signature_blob(sig, &sig_blob);
ssh_signature_free(sig); ssh_signature_free(sig);