aboutsummaryrefslogtreecommitdiff
path: root/src/keys.c
diff options
context:
space:
mode:
authorAndreas Schneider <asn@cryptomilk.org>2011-08-16 17:47:29 +0200
committerAndreas Schneider <asn@cryptomilk.org>2011-08-16 17:47:29 +0200
commita40f1d85972986c8baa2e32fe666c7bf19423045 (patch)
tree3ab53e1142f4d6656e2bfb378f2b1f93c3360def /src/keys.c
parentc940918821db41909ac99b16483a7c853c1bafcd (diff)
downloadlibssh-a40f1d85972986c8baa2e32fe666c7bf19423045.tar.gz
libssh-a40f1d85972986c8baa2e32fe666c7bf19423045.tar.xz
libssh-a40f1d85972986c8baa2e32fe666c7bf19423045.zip
pki: Make publickey_from_string a legacy function.
Diffstat (limited to 'src/keys.c')
-rw-r--r--src/keys.c199
1 files changed, 0 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.
*