summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAndreas Schneider <asn@cryptomilk.org>2011-08-16 17:54:10 +0200
committerAndreas Schneider <asn@cryptomilk.org>2011-08-16 17:54:10 +0200
commit9b84464748d5d4cd67b7868a6cfba5664a169503 (patch)
tree9ee1e76a53f891a9ca8e21c7f974a425c8e1eff1 /src
parenta40f1d85972986c8baa2e32fe666c7bf19423045 (diff)
downloadlibssh-9b84464748d5d4cd67b7868a6cfba5664a169503.tar.gz
libssh-9b84464748d5d4cd67b7868a6cfba5664a169503.tar.xz
libssh-9b84464748d5d4cd67b7868a6cfba5664a169503.zip
pki: Make publickey_to_string a legacy function.
Diffstat (limited to 'src')
-rw-r--r--src/keys.c233
-rw-r--r--src/legacy.c23
2 files changed, 23 insertions, 233 deletions
diff --git a/src/keys.c b/src/keys.c
index 9fb76ef..479f41f 100644
--- a/src/keys.c
+++ b/src/keys.c
@@ -264,239 +264,6 @@ error:
return NULL;
}
-#ifdef HAVE_LIBGCRYPT
-static int dsa_public_to_string(gcry_sexp_t key, ssh_buffer buffer) {
-#elif defined HAVE_LIBCRYPTO
-static int dsa_public_to_string(DSA *key, ssh_buffer buffer) {
-#endif
- ssh_string p = NULL;
- ssh_string q = NULL;
- ssh_string g = NULL;
- ssh_string n = NULL;
-
- int rc = -1;
-
-#ifdef HAVE_LIBGCRYPT
- const char *tmp = NULL;
- size_t size;
- gcry_sexp_t sexp;
-
- sexp = gcry_sexp_find_token(key, "p", 0);
- if (sexp == NULL) {
- goto error;
- }
- tmp = gcry_sexp_nth_data(sexp, 1, &size);
- p = ssh_string_new(size);
- if (p == NULL) {
- goto error;
- }
- ssh_string_fill(p, (char *) tmp, size);
- gcry_sexp_release(sexp);
-
- sexp = gcry_sexp_find_token(key, "q", 0);
- if (sexp == NULL) {
- goto error;
- }
- tmp = gcry_sexp_nth_data(sexp, 1, &size);
- q = ssh_string_new(size);
- if (q == NULL) {
- goto error;
- }
- ssh_string_fill(q, (char *) tmp, size);
- gcry_sexp_release(sexp);
-
- sexp = gcry_sexp_find_token(key, "g", 0);
- if (sexp == NULL) {
- goto error;
- }
- tmp = gcry_sexp_nth_data(sexp, 1, &size);
- g = ssh_string_new(size);
- if (g == NULL) {
- goto error;
- }
- ssh_string_fill(g, (char *) tmp, size);
- gcry_sexp_release(sexp);
-
- sexp = gcry_sexp_find_token(key, "y", 0);
- if (sexp == NULL) {
- goto error;
- }
- tmp = gcry_sexp_nth_data(sexp, 1, &size);
- n = ssh_string_new(size);
- if (n == NULL) {
- goto error;
- }
- ssh_string_fill(n, (char *) tmp, size);
-
-#elif defined HAVE_LIBCRYPTO
- p = make_bignum_string(key->p);
- q = make_bignum_string(key->q);
- g = make_bignum_string(key->g);
- n = make_bignum_string(key->pub_key);
- if (p == NULL || q == NULL || g == NULL || n == NULL) {
- goto error;
- }
-#endif /* HAVE_LIBCRYPTO */
- if (buffer_add_ssh_string(buffer, p) < 0) {
- goto error;
- }
- if (buffer_add_ssh_string(buffer, q) < 0) {
- goto error;
- }
- if (buffer_add_ssh_string(buffer, g) < 0) {
- goto error;
- }
- if (buffer_add_ssh_string(buffer, n) < 0) {
- goto error;
- }
-
- rc = 0;
-error:
-#ifdef HAVE_LIBGCRYPT
- gcry_sexp_release(sexp);
-#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(n);
- ssh_string_free(n);
-
- return rc;
-#if defined(HAVE_LIBGCRYPT) || defined(HAVE_LIBCRYPTO)
-}
-#endif
-
-#ifdef HAVE_LIBGCRYPT
-static int rsa_public_to_string(gcry_sexp_t key, ssh_buffer buffer) {
-#elif defined HAVE_LIBCRYPTO
-static int rsa_public_to_string(RSA *key, ssh_buffer buffer) {
-#endif
-
- ssh_string e = NULL;
- ssh_string n = NULL;
-
- int rc = -1;
-
-#ifdef HAVE_LIBGCRYPT
- const char *tmp;
- size_t size;
- gcry_sexp_t sexp;
-
- sexp = gcry_sexp_find_token(key, "n", 0);
- if (sexp == NULL) {
- goto error;
- }
- tmp = gcry_sexp_nth_data(sexp, 1, &size);
- n = ssh_string_new(size);
- if (n == NULL) {
- goto error;
- }
- ssh_string_fill(n, (char *) tmp, size);
- gcry_sexp_release(sexp);
-
- sexp = gcry_sexp_find_token(key, "e", 0);
- if (sexp == NULL) {
- goto error;
- }
- tmp = gcry_sexp_nth_data(sexp, 1, &size);
- e = ssh_string_new(size);
- if (e == NULL) {
- goto error;
- }
- ssh_string_fill(e, (char *) tmp, size);
-
-#elif defined HAVE_LIBCRYPTO
- e = make_bignum_string(key->e);
- n = make_bignum_string(key->n);
- if (e == NULL || n == NULL) {
- goto error;
- }
-#endif
-
- if (buffer_add_ssh_string(buffer, e) < 0) {
- goto error;
- }
- if (buffer_add_ssh_string(buffer, n) < 0) {
- goto error;
- }
-
- rc = 0;
-error:
-#ifdef HAVE_LIBGCRYPT
- gcry_sexp_release(sexp);
-#endif
-
- ssh_string_burn(e);
- ssh_string_free(e);
- ssh_string_burn(n);
- ssh_string_free(n);
-
- return rc;
-#if defined(HAVE_LIBGCRYPT) || defined(HAVE_LIBCRYPTO)
-}
-#endif
-
-/**
- * @brief Convert a public_key object into a a SSH string.
- *
- * @param[in] key The public key to convert.
- *
- * @returns An allocated SSH String containing the public key, NULL
- * on error.
- *
- * @see string_free()
- */
-ssh_string publickey_to_string(ssh_public_key key) {
- ssh_string type = NULL;
- ssh_string ret = NULL;
- ssh_buffer buf = NULL;
-
- buf = ssh_buffer_new();
- if (buf == NULL) {
- return NULL;
- }
-
- type = ssh_string_from_char(key->type_c);
- if (type == NULL) {
- goto error;
- }
-
- if (buffer_add_ssh_string(buf, type) < 0) {
- goto error;
- }
-
- switch (key->type) {
- case SSH_KEYTYPE_DSS:
- if (dsa_public_to_string(key->dsa_pub, buf) < 0) {
- goto error;
- }
- break;
- case SSH_KEYTYPE_RSA:
- case SSH_KEYTYPE_RSA1:
- if (rsa_public_to_string(key->rsa_pub, buf) < 0) {
- goto error;
- }
- break;
- }
-
- ret = ssh_string_new(buffer_get_rest_len(buf));
- if (ret == NULL) {
- goto error;
- }
-
- ssh_string_fill(ret, buffer_get_rest(buf), buffer_get_rest_len(buf));
-error:
- ssh_buffer_free(buf);
- if(type != NULL)
- ssh_string_free(type);
-
- return ret;
-}
-
/* Signature decoding functions */
ssh_string signature_to_string(SIGNATURE *sign) {
unsigned char buffer[40] = {0};
diff --git a/src/legacy.c b/src/legacy.c
index c021a4b..ac9ace1 100644
--- a/src/legacy.c
+++ b/src/legacy.c
@@ -381,6 +381,29 @@ ssh_public_key publickey_from_string(ssh_session session, ssh_string pubkey_s) {
return pubkey;
}
+ssh_string publickey_to_string(ssh_public_key pubkey) {
+ ssh_key key;
+ ssh_string key_blob;
+
+ key = ssh_key_new();
+ if (key == NULL) {
+ return NULL;
+ }
+
+ key->type = pubkey->type;
+ key->type_c = pubkey->type_c;
+
+ key->dsa = pubkey->dsa_pub;
+ key->rsa = pubkey->rsa_pub;
+
+ key_blob = ssh_pki_publickey_to_blob(key);
+
+ key->dsa = NULL;
+ key->rsa = NULL;
+ ssh_key_free(key);
+
+ return key_blob;
+}
/****************************************************************************
* SERVER SUPPORT
****************************************************************************/