From 9a21093ab8357dc0c48ad8d78091a5d1d4ec7316 Mon Sep 17 00:00:00 2001 From: milo Date: Wed, 9 Mar 2011 12:49:46 +0100 Subject: [PATCH] [pki] Added b64decode_dsa_privatekey() function --- src/keyfiles.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/src/keyfiles.c b/src/keyfiles.c index 20af8163..348e9008 100644 --- a/src/keyfiles.c +++ b/src/keyfiles.c @@ -791,6 +791,66 @@ static int read_dsa_privatekey(FILE *fp, gcry_sexp_t *r, ssh_auth_callback cb, rc = 0; } +error: + ssh_string_free(p); + ssh_string_free(q); + ssh_string_free(g); + ssh_string_free(y); + ssh_string_free(x); + ssh_string_free(v); + + return rc; +} + +static int b64decode_dsa_privatekey(const char *pkey, gcry_sexp_t *r, ssh_auth_callback cb, + void *userdata, const char *desc) { + ssh_buffer buffer = NULL; + ssh_string p = NULL; + ssh_string q = NULL; + ssh_string g = NULL; + ssh_string y = NULL; + ssh_string x = NULL; + ssh_string v = NULL; + int rc = 1; + + buffer = privatekey_string_to_buffer(pkey, SSH_KEYTYPE_DSS, cb, userdata, desc); + if (buffer == NULL) { + return 0; + } + + if (!asn1_check_sequence(buffer)) { + ssh_buffer_free(buffer); + return 0; + } + + v = asn1_get_int(buffer); + if (ntohl(v->size) != 1 || v->string[0] != 0) { + ssh_buffer_free(buffer); + return 0; + } + + p = asn1_get_int(buffer); + q = asn1_get_int(buffer); + g = asn1_get_int(buffer); + y = asn1_get_int(buffer); + x = asn1_get_int(buffer); + ssh_buffer_free(buffer); + + if (p == NULL || q == NULL || g == NULL || y == NULL || x == NULL) { + rc = 0; + goto error; + } + + if (gcry_sexp_build(r, NULL, + "(private-key(dsa(p %b)(q %b)(g %b)(y %b)(x %b)))", + ntohl(p->size), p->string, + ntohl(q->size), q->string, + ntohl(g->size), g->string, + ntohl(y->size), y->string, + ntohl(x->size), x->string)) { + rc = 0; + } + error: ssh_string_free(p); ssh_string_free(q);