summaryrefslogtreecommitdiffstats
path: root/src/legacy.c
diff options
context:
space:
mode:
authorAndreas Schneider <asn@cryptomilk.org>2011-08-22 11:23:33 +0200
committerAndreas Schneider <asn@cryptomilk.org>2011-08-22 11:23:33 +0200
commitca9b01af991d1e7080bef2bb8c9540538eb0df12 (patch)
tree366afdfe80e0546e809b849e6f637cfa955cba79 /src/legacy.c
parentd0d9e6261110e680447c7473bf42072b285c38e9 (diff)
downloadlibssh-ca9b01af991d1e7080bef2bb8c9540538eb0df12.tar.gz
libssh-ca9b01af991d1e7080bef2bb8c9540538eb0df12.tar.xz
libssh-ca9b01af991d1e7080bef2bb8c9540538eb0df12.zip
pki: Migrate signature functions to legacy code.
Diffstat (limited to 'src/legacy.c')
-rw-r--r--src/legacy.c85
1 files changed, 85 insertions, 0 deletions
diff --git a/src/legacy.c b/src/legacy.c
index 681ed0f..25ae53b 100644
--- a/src/legacy.c
+++ b/src/legacy.c
@@ -429,6 +429,91 @@ ssh_string publickey_to_string(ssh_public_key pubkey) {
return key_blob;
}
+
+ssh_string signature_to_string(SIGNATURE *sign)
+{
+ ssh_signature sig;
+ ssh_string sig_blob;
+ int rc;
+
+ if (sign == NULL) {
+ return NULL;
+ }
+
+ sig = ssh_signature_new();
+ if (sig == NULL) {
+ return NULL;
+ }
+
+ sig->type = sign->type;
+ sig->dsa_sig = sign->dsa_sign;
+ sig->rsa_sig = sign->rsa_sign;
+
+ rc = ssh_pki_export_signature_blob(sig, &sig_blob);
+ sig->dsa_sig = NULL;
+ sig->rsa_sig = NULL;
+ ssh_signature_free(sig);
+ if (rc < 0) {
+ return NULL;
+ }
+
+ return sig_blob;
+}
+
+SIGNATURE *signature_from_string(ssh_session session,
+ ssh_string signature,
+ ssh_public_key pubkey,
+ int needed_type)
+{
+ SIGNATURE *sign;
+ ssh_signature sig;
+ ssh_key key;
+ int rc;
+
+ if (session == NULL || signature == NULL || pubkey == NULL) {
+ return NULL;
+ }
+
+ key = ssh_key_new();
+ if (key == NULL) {
+ return NULL;
+ }
+
+ key->type = pubkey->type;
+ key->type_c = pubkey->type_c;
+ key->flags = SSH_KEY_FLAG_PUBLIC;
+ key->dsa = pubkey->dsa_pub;
+ key->rsa = pubkey->rsa_pub;
+
+ rc = ssh_pki_import_signature_blob(signature, key, &sig);
+ key->dsa = NULL;
+ key->rsa = NULL;
+ ssh_key_free(key);
+ if (rc < 0) {
+ return NULL;
+ }
+
+ if ((enum ssh_keytypes_e)needed_type != sig->type) {
+ ssh_signature_free(sig);
+ return NULL;
+ }
+
+ sign = malloc(sizeof(struct signature_struct));
+ if (sign == NULL) {
+ ssh_signature_free(sig);
+ return NULL;
+ }
+
+ sign->type = sig->type;
+ sign->dsa_sign = sig->dsa_sig;
+ sig->dsa_sig = NULL;
+ sign->rsa_sign = sig->rsa_sig;
+ sig->rsa_sig = NULL;
+
+ ssh_signature_free(sig);
+ return sign;
+}
+
/****************************************************************************
* SERVER SUPPORT
****************************************************************************/