aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormilo <milo@r0ot.me>2011-03-09 12:48:39 +0100
committermilo <milo@r0ot.me>2011-03-17 11:41:50 +0100
commit733ed067897059d1774fff2f82f221fde1b8202d (patch)
tree428c5e658a8c58ce10ef4b0fc9ac67ef8991dac9 /src
parent131f09405ae1f8432c215793d33cec4d2b1d06fa (diff)
downloadlibssh-733ed067897059d1774fff2f82f221fde1b8202d.tar.gz
libssh-733ed067897059d1774fff2f82f221fde1b8202d.tar.xz
libssh-733ed067897059d1774fff2f82f221fde1b8202d.zip
[pki] Added b64decode_rsa_privatekey() function
Diffstat (limited to 'src')
-rw-r--r--src/keyfiles.c72
1 files changed, 72 insertions, 0 deletions
diff --git a/src/keyfiles.c b/src/keyfiles.c
index 638e282..e2f6f24 100644
--- a/src/keyfiles.c
+++ b/src/keyfiles.c
@@ -598,6 +598,78 @@ static ssh_buffer privatekey_file_to_buffer(FILE *fp, int type,
return out;
}
+static int b64decode_rsa_privatekey(const char *pkey, gcry_sexp_t *r,
+ ssh_auth_callback cb, void *userdata, const char *desc) {
+ ssh_string n = NULL;
+ ssh_string e = NULL;
+ ssh_string d = NULL;
+ ssh_string p = NULL;
+ ssh_string q = NULL;
+ ssh_string unused1 = NULL;
+ ssh_string unused2 = NULL;
+ ssh_string u = NULL;
+ ssh_string v = NULL;
+ ssh_buffer buffer = NULL;
+ int rc = 1;
+
+ buffer = privatekey_string_to_buffer(pkey, SSH_KEYTYPE_RSA, 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;
+ }
+
+ n = asn1_get_int(buffer);
+ e = asn1_get_int(buffer);
+ d = asn1_get_int(buffer);
+ q = asn1_get_int(buffer);
+ p = asn1_get_int(buffer);
+ unused1 = asn1_get_int(buffer);
+ unused2 = asn1_get_int(buffer);
+ u = asn1_get_int(buffer);
+
+ ssh_buffer_free(buffer);
+
+ if (n == NULL || e == NULL || d == NULL || p == NULL || q == NULL ||
+ unused1 == NULL || unused2 == NULL|| u == NULL) {
+ rc = 0;
+ goto error;
+ }
+
+ if (gcry_sexp_build(r, NULL,
+ "(private-key(rsa(n %b)(e %b)(d %b)(p %b)(q %b)(u %b)))",
+ ntohl(n->size), n->string,
+ ntohl(e->size), e->string,
+ ntohl(d->size), d->string,
+ ntohl(p->size), p->string,
+ ntohl(q->size), q->string,
+ ntohl(u->size), u->string)) {
+ rc = 0;
+ }
+
+error:
+ ssh_string_free(n);
+ ssh_string_free(e);
+ ssh_string_free(d);
+ ssh_string_free(p);
+ ssh_string_free(q);
+ ssh_string_free(unused1);
+ ssh_string_free(unused2);
+ ssh_string_free(u);
+ ssh_string_free(v);
+
+ return rc;
+}
+
static int read_rsa_privatekey(FILE *fp, gcry_sexp_t *r,
ssh_auth_callback cb, void *userdata, const char *desc) {
ssh_string n = NULL;