aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/keys.c199
-rw-r--r--src/legacy.c29
2 files changed, 29 insertions, 199 deletions
diff --git a/src/keys.c b/src/keys.c
index a3d772a7..9fb76efd 100644
--- a/src/keys.c
+++ b/src/keys.c
@@ -44,159 +44,6 @@
* @{
*/
-ssh_public_key publickey_make_dss(ssh_session session, ssh_buffer buffer) {
- ssh_string p = NULL;
- ssh_string q = NULL;
- ssh_string g = NULL;
- ssh_string pubkey = NULL;
- ssh_public_key key = NULL;
-
- key = malloc(sizeof(struct ssh_public_key_struct));
- if (key == NULL) {
- ssh_buffer_free(buffer);
- return NULL;
- }
-
- key->type = SSH_KEYTYPE_DSS;
- key->type_c = ssh_type_to_char(key->type);
-
- p = buffer_get_ssh_string(buffer);
- q = buffer_get_ssh_string(buffer);
- g = buffer_get_ssh_string(buffer);
- pubkey = buffer_get_ssh_string(buffer);
-
- ssh_buffer_free(buffer); /* we don't need it anymore */
-
- if (p == NULL || q == NULL || g == NULL || pubkey == NULL) {
- ssh_set_error(session, SSH_FATAL, "Invalid DSA public key");
- goto error;
- }
-
-#ifdef HAVE_LIBGCRYPT
- gcry_sexp_build(&key->dsa_pub, NULL,
- "(public-key(dsa(p %b)(q %b)(g %b)(y %b)))",
- ssh_string_len(p), ssh_string_data(p),
- ssh_string_len(q), ssh_string_data(q),
- ssh_string_len(g), ssh_string_data(g),
- ssh_string_len(pubkey), ssh_string_data(pubkey));
- if (key->dsa_pub == NULL) {
- goto error;
- }
-#elif defined HAVE_LIBCRYPTO
-
- key->dsa_pub = DSA_new();
- if (key->dsa_pub == NULL) {
- goto error;
- }
- key->dsa_pub->p = make_string_bn(p);
- key->dsa_pub->q = make_string_bn(q);
- key->dsa_pub->g = make_string_bn(g);
- key->dsa_pub->pub_key = make_string_bn(pubkey);
- if (key->dsa_pub->p == NULL ||
- key->dsa_pub->q == NULL ||
- key->dsa_pub->g == NULL ||
- key->dsa_pub->pub_key == NULL) {
- goto error;
- }
-#endif /* HAVE_LIBCRYPTO */
-
-#ifdef DEBUG_CRYPTO
- ssh_print_hexa("p", ssh_string_data(p), ssh_string_len(p));
- ssh_print_hexa("q", ssh_string_data(q), ssh_string_len(q));
- ssh_print_hexa("g", ssh_string_data(g), ssh_string_len(g));
-#endif
-
- ssh_string_burn(p);
- ssh_string_free(p);
- ssh_string_burn(q);
- ssh_string_free(q);
- ssh_string_burn(g);
- ssh_string_free(g);
- ssh_string_burn(pubkey);
- ssh_string_free(pubkey);
-
- return key;
-error:
- ssh_string_burn(p);
- ssh_string_free(p);
- ssh_string_burn(q);
- ssh_string_free(q);
- ssh_string_burn(g);
- ssh_string_free(g);
- ssh_string_burn(pubkey);
- ssh_string_free(pubkey);
- publickey_free(key);
-
- return NULL;
-}
-
-ssh_public_key publickey_make_rsa(ssh_session session, ssh_buffer buffer,
- int type) {
- ssh_string e = NULL;
- ssh_string n = NULL;
- ssh_public_key key = NULL;
-
- key = malloc(sizeof(struct ssh_public_key_struct));
- if (key == NULL) {
- ssh_buffer_free(buffer);
- return NULL;
- }
-
- key->type = type;
- key->type_c = ssh_type_to_char(key->type);
-
- e = buffer_get_ssh_string(buffer);
- n = buffer_get_ssh_string(buffer);
-
- ssh_buffer_free(buffer); /* we don't need it anymore */
-
- if(e == NULL || n == NULL) {
- ssh_set_error(session, SSH_FATAL, "Invalid RSA public key");
- goto error;
- }
-#ifdef HAVE_LIBGCRYPT
- gcry_sexp_build(&key->rsa_pub, NULL,
- "(public-key(rsa(n %b)(e %b)))",
- ssh_string_len(n), ssh_string_data(n),
- ssh_string_len(e),ssh_string_data(e));
- if (key->rsa_pub == NULL) {
- goto error;
- }
-#elif HAVE_LIBCRYPTO
- key->rsa_pub = RSA_new();
- if (key->rsa_pub == NULL) {
- goto error;
- }
-
- key->rsa_pub->e = make_string_bn(e);
- key->rsa_pub->n = make_string_bn(n);
- if (key->rsa_pub->e == NULL ||
- key->rsa_pub->n == NULL) {
- goto error;
- }
-#endif
-
-#ifdef DEBUG_CRYPTO
- ssh_print_hexa("e", ssh_string_data(e), ssh_string_len(e));
- ssh_print_hexa("n", ssh_string_data(n), ssh_string_len(n));
-#endif
-
- ssh_string_burn(e);
- ssh_string_free(e);
- ssh_string_burn(n);
- ssh_string_free(n);
-
- return key;
-error:
- ssh_string_burn(e);
- ssh_string_free(e);
- ssh_string_burn(n);
- ssh_string_free(n);
- publickey_free(key);
-
- return NULL;
-}
-
void publickey_free(ssh_public_key key) {
if (key == NULL) {
return;
@@ -224,52 +71,6 @@ void publickey_free(ssh_public_key key) {
SAFE_FREE(key);
}
-ssh_public_key publickey_from_string(ssh_session session, ssh_string pubkey_s) {
- ssh_buffer tmpbuf = NULL;
- ssh_string type_s = NULL;
- char *type_c = NULL;
- int type;
-
- tmpbuf = ssh_buffer_new();
- if (tmpbuf == NULL) {
- return NULL;
- }
-
- if (buffer_add_data(tmpbuf, ssh_string_data(pubkey_s), ssh_string_len(pubkey_s)) < 0) {
- goto error;
- }
-
- type_s = buffer_get_ssh_string(tmpbuf);
- if (type_s == NULL) {
- ssh_set_error(session,SSH_FATAL,"Invalid public key format");
- goto error;
- }
-
- type_c = ssh_string_to_char(type_s);
- ssh_string_free(type_s);
- if (type_c == NULL) {
- goto error;
- }
-
- type = ssh_type_from_name(type_c);
- SAFE_FREE(type_c);
-
- switch (type) {
- case SSH_KEYTYPE_DSS:
- return publickey_make_dss(session, tmpbuf);
- case SSH_KEYTYPE_RSA:
- case SSH_KEYTYPE_RSA1:
- return publickey_make_rsa(session, tmpbuf, type);
- }
-
- ssh_set_error(session, SSH_FATAL, "Unknown public key protocol %s",
- ssh_type_to_char(type));
-
-error:
- ssh_buffer_free(tmpbuf);
- return NULL;
-}
-
/**
* @brief Make a public_key object out of a private_key object.
*
diff --git a/src/legacy.c b/src/legacy.c
index bdb98341..c021a4b5 100644
--- a/src/legacy.c
+++ b/src/legacy.c
@@ -352,6 +352,35 @@ int ssh_type_from_name(const char *name) {
return ssh_key_type_from_name(name);
}
+ssh_public_key publickey_from_string(ssh_session session, ssh_string pubkey_s) {
+ struct ssh_public_key_struct *pubkey;
+ ssh_key key;
+ int rc;
+
+ rc = ssh_pki_import_pubkey_blob(session, pubkey_s, &key);
+ if (rc < 0) {
+ return NULL;
+ }
+
+ pubkey = malloc(sizeof(struct ssh_public_key_struct));
+ if (pubkey == NULL) {
+ ssh_key_free(key);
+ return NULL;
+ }
+
+ pubkey->type = key->type;
+ pubkey->type_c = key->type_c;
+
+ pubkey->dsa_pub = key->dsa;
+ key->dsa = NULL;
+ pubkey->rsa_pub = key->rsa;
+ key->rsa = NULL;
+
+ ssh_key_free(key);
+
+ return pubkey;
+}
+
/****************************************************************************
* SERVER SUPPORT
****************************************************************************/