aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Schneider <asn@cryptomilk.org>2011-09-05 11:02:23 +0200
committerAndreas Schneider <asn@cryptomilk.org>2011-09-05 11:28:19 +0200
commit808c7a9be4f110605e76ea5678bf0b1986cc9b38 (patch)
tree75823375575323a4b59aa6f9b381a0e3e0e2c183
parent6901e25085f8924f9d83e12107c05f935bd24287 (diff)
downloadlibssh-808c7a9be4f110605e76ea5678bf0b1986cc9b38.tar.gz
libssh-808c7a9be4f110605e76ea5678bf0b1986cc9b38.tar.xz
libssh-808c7a9be4f110605e76ea5678bf0b1986cc9b38.zip
pki: Add ssh_pki_export_pubkey_rsa1().
-rw-r--r--include/libssh/pki.h4
-rw-r--r--include/libssh/pki_priv.h4
-rw-r--r--src/pki.c8
-rw-r--r--src/pki_crypto.c29
-rw-r--r--src/pki_gcrypt.c45
5 files changed, 90 insertions, 0 deletions
diff --git a/include/libssh/pki.h b/include/libssh/pki.h
index 04aa3b1f..d4cc8503 100644
--- a/include/libssh/pki.h
+++ b/include/libssh/pki.h
@@ -85,6 +85,10 @@ int ssh_pki_export_pubkey_blob(const ssh_key key,
ssh_string *pblob);
int ssh_pki_import_pubkey_blob(const ssh_string key_blob,
ssh_key *pkey);
+int ssh_pki_export_pubkey_rsa1(const ssh_key key,
+ const char *host,
+ char *rsa1,
+ size_t rsa1_len);
/* SSH Signing Functions */
ssh_string ssh_pki_do_sign(ssh_session session, ssh_buffer sigbuf,
diff --git a/include/libssh/pki_priv.h b/include/libssh/pki_priv.h
index f90d7c86..d1ffa8a0 100644
--- a/include/libssh/pki_priv.h
+++ b/include/libssh/pki_priv.h
@@ -49,6 +49,10 @@ int pki_pubkey_build_rsa(ssh_key key,
ssh_string e,
ssh_string n);
ssh_string pki_publickey_to_blob(const ssh_key key);
+int pki_export_pubkey_rsa1(const ssh_key key,
+ const char *host,
+ char *rsa1,
+ size_t rsa1_len);
/* SSH Signature Functions */
ssh_string pki_signature_to_blob(const ssh_signature sign);
diff --git a/src/pki.c b/src/pki.c
index 935f3680..3dd27ed3 100644
--- a/src/pki.c
+++ b/src/pki.c
@@ -958,6 +958,14 @@ int ssh_pki_export_pubkey_file(const ssh_key key,
return SSH_OK;
}
+int ssh_pki_export_pubkey_rsa1(const ssh_key key,
+ const char *host,
+ char *rsa1,
+ size_t rsa1_len)
+{
+ return pki_export_pubkey_rsa1(key, host, rsa1, rsa1_len);
+}
+
int ssh_pki_export_signature_blob(const ssh_signature sig,
ssh_string *sig_blob)
{
diff --git a/src/pki_crypto.c b/src/pki_crypto.c
index 29e589f1..32ee13d1 100644
--- a/src/pki_crypto.c
+++ b/src/pki_crypto.c
@@ -519,6 +519,35 @@ fail:
return NULL;
}
+int pki_export_pubkey_rsa1(const ssh_key key,
+ const char *host,
+ char *rsa1,
+ size_t rsa1_len)
+{
+ char *e;
+ char *n;
+ int rsa_size = RSA_size(key->rsa);
+
+ e = bignum_bn2dec(key->rsa->e);
+ if (e == NULL) {
+ return SSH_ERROR;
+ }
+
+ n = bignum_bn2dec(key->rsa->n);
+ if (n == NULL) {
+ OPENSSL_free(e);
+ return SSH_ERROR;
+ }
+
+ snprintf(rsa1, rsa1_len,
+ "%s %d %s %s\n",
+ host, rsa_size << 3, e, n);
+ OPENSSL_free(e);
+ OPENSSL_free(n);
+
+ return SSH_OK;
+}
+
/**
* @internal
*
diff --git a/src/pki_gcrypt.c b/src/pki_gcrypt.c
index cf770611..6f3cd957 100644
--- a/src/pki_gcrypt.c
+++ b/src/pki_gcrypt.c
@@ -1145,6 +1145,51 @@ fail:
return NULL;
}
+int pki_export_pubkey_rsa1(const ssh_key key,
+ const char *host,
+ char *rsa1,
+ size_t rsa1_len)
+{
+ gcry_sexp_t sexp;
+ int rsa_size;
+ bignum b;
+ char *e, *n;
+
+ sexp = gcry_sexp_find_token(key->rsa, "e", 0);
+ if (sexp == NULL) {
+ return SSH_ERROR;
+ }
+ b = gcry_sexp_nth_mpi(sexp, 1, GCRYMPI_FMT_USG);
+ gcry_sexp_release(sexp);
+ if (b == NULL) {
+ return SSH_ERROR;
+ }
+ e = bignum_bn2dec(b);
+
+ sexp = gcry_sexp_find_token(key->rsa, "n", 0);
+ if (sexp == NULL) {
+ SAFE_FREE(e);
+ return SSH_ERROR;
+ }
+ b = gcry_sexp_nth_mpi(sexp, 1, GCRYMPI_FMT_USG);
+ gcry_sexp_release(sexp);
+ if (b == NULL) {
+ SAFE_FREE(e);
+ return SSH_ERROR;
+ }
+ n = bignum_bn2dec(b);
+
+ rsa_size = (gcry_pk_get_nbits(key->rsa) + 7) / 8;
+
+ snprintf(rsa1, rsa1_len,
+ "%s %d %s %s\n",
+ host, rsa_size << 3, e, n);
+ SAFE_FREE(e);
+ SAFE_FREE(n);
+
+ return SSH_OK;
+}
+
ssh_string pki_signature_to_blob(const ssh_signature sig)
{
char buffer[40] = {0};