aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndreas Schneider <asn@cryptomilk.org>2013-10-18 23:48:21 +0200
committerAndreas Schneider <asn@cryptomilk.org>2013-10-18 23:48:21 +0200
commitbd8ab422d02e12ba0b2460023c17a7c10441bf45 (patch)
tree00ebe3e73bdf7b72a568dd229c1e1cd3618637c7 /src
parent33890daf4104238ecf4216102abd0411eed17c43 (diff)
downloadlibssh-bd8ab422d02e12ba0b2460023c17a7c10441bf45.tar.gz
libssh-bd8ab422d02e12ba0b2460023c17a7c10441bf45.tar.xz
libssh-bd8ab422d02e12ba0b2460023c17a7c10441bf45.zip
pki_crpypto: Fix ecdsa signature to blob.
BUG: https://red.libssh.org/issues/118
Diffstat (limited to 'src')
-rw-r--r--src/pki_crypto.c38
1 files changed, 26 insertions, 12 deletions
diff --git a/src/pki_crypto.c b/src/pki_crypto.c
index 82fbe93b..1912f24d 100644
--- a/src/pki_crypto.c
+++ b/src/pki_crypto.c
@@ -1018,33 +1018,47 @@ ssh_string pki_signature_to_blob(const ssh_signature sig)
break;
case SSH_KEYTYPE_ECDSA:
#ifdef HAVE_OPENSSL_ECC
+ {
+ ssh_buffer b;
+ int rc;
+
+ b = ssh_buffer_new();
+ if (b == NULL) {
+ return NULL;
+ }
+
r = make_bignum_string(sig->ecdsa_sig->r);
if (r == NULL) {
+ ssh_buffer_free(b);
return NULL;
}
+ rc = buffer_add_ssh_string(b, r);
+ ssh_string_free(r);
+ if (rc < 0) {
+ ssh_buffer_free(b);
+ return NULL;
+ }
+
s = make_bignum_string(sig->ecdsa_sig->s);
if (s == NULL) {
- ssh_string_free(r);
+ ssh_buffer_free(b);
return NULL;
}
-
- memcpy(buffer,
- ((char *)ssh_string_data(r)) + ssh_string_len(r) - 20,
- 20);
- memcpy(buffer + 20,
- ((char *)ssh_string_data(s)) + ssh_string_len(s) - 20,
- 20);
-
- ssh_string_free(r);
+ rc = buffer_add_ssh_string(b, s);
ssh_string_free(s);
+ if (rc < 0) {
+ ssh_buffer_free(b);
+ return NULL;
+ }
- sig_blob = ssh_string_new(40);
+ sig_blob = ssh_string_new(buffer_get_rest_len(b));
if (sig_blob == NULL) {
return NULL;
}
- ssh_string_fill(sig_blob, buffer, 40);
+ ssh_string_fill(sig_blob, buffer_get_rest(b), buffer_get_rest_len(b));
break;
+ }
#endif
case SSH_KEYTYPE_UNKNOWN:
ssh_pki_log("Unknown signature key type: %s", sig->type_c);