aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormilo <milo@r0ot.me>2011-03-09 12:48:39 +0100
committermilo <milo@r0ot.me>2011-04-14 14:05:43 +0200
commit5f54eff0be06ca1bbb0c3d8781bf85c411126a5f (patch)
tree9b4280b5f9e350a53d66a8f37100bac6a3f59d58
parent43ebdbfe467c238170059c3235b6c513e7e4dc66 (diff)
downloadlibssh-5f54eff0be06ca1bbb0c3d8781bf85c411126a5f.tar.gz
libssh-5f54eff0be06ca1bbb0c3d8781bf85c411126a5f.tar.xz
libssh-5f54eff0be06ca1bbb0c3d8781bf85c411126a5f.zip
[pki] Added b64decode_rsa_privatekey() function
-rw-r--r--src/keyfiles.c72
1 files changed, 72 insertions, 0 deletions
diff --git a/src/keyfiles.c b/src/keyfiles.c
index 3c0a3e6..20af816 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;