pki: Add ssh_pki_import_pubkey_base64().

This commit is contained in:
Andreas Schneider
2011-08-07 19:53:03 +02:00
parent f81444bd57
commit bec483bc18
5 changed files with 217 additions and 0 deletions

View File

@@ -36,6 +36,7 @@
#include "libssh/callbacks.h"
#include "libssh/pki.h"
#include "libssh/keys.h"
#include "libssh/dh.h"
static int pem_get_password(char *buf, int size, int rwflag, void *userdata) {
ssh_session session = userdata;
@@ -162,6 +163,50 @@ fail:
return NULL;
}
int pki_pubkey_build_dss(ssh_key key,
ssh_string p,
ssh_string q,
ssh_string g,
ssh_string pubkey) {
key->dsa = DSA_new();
if (key->dsa == NULL) {
return SSH_ERROR;
}
key->dsa->p = make_string_bn(p);
key->dsa->q = make_string_bn(q);
key->dsa->g = make_string_bn(g);
key->dsa->pub_key = make_string_bn(pubkey);
if (key->dsa->p == NULL ||
key->dsa->q == NULL ||
key->dsa->g == NULL ||
key->dsa->pub_key == NULL) {
DSA_free(key->dsa);
return SSH_ERROR;
}
return SSH_OK;
}
int pki_pubkey_build_rsa(ssh_key key,
ssh_string e,
ssh_string n) {
key->rsa = RSA_new();
if (key->rsa == NULL) {
return SSH_ERROR;
}
key->rsa->e = make_string_bn(e);
key->rsa->n = make_string_bn(n);
if (key->rsa->e == NULL ||
key->rsa->n == NULL) {
RSA_free(key->rsa);
return SSH_ERROR;
}
return SSH_OK;
}
ssh_key pki_publickey_from_privatekey(ssh_key privkey) {
ssh_key pubkey = NULL;