1
1

pki_crypto: Add ecdsa support for key duplication.

Этот коммит содержится в:
Andreas Schneider 2011-08-30 09:36:06 +02:00
родитель a0e3facac7
Коммит 6901e25085

Просмотреть файл

@ -30,6 +30,14 @@
#include <openssl/err.h> #include <openssl/err.h>
#include <openssl/rsa.h> #include <openssl/rsa.h>
#ifdef HAVE_OPENSSL_EC_H
#include <openssl/ec.h>
#endif
#ifdef HAVE_OPENSSL_ECDSA_H
#include <openssl/ecdsa.h>
#endif
#include "libssh/priv.h" #include "libssh/priv.h"
#include "libssh/libssh.h" #include "libssh/libssh.h"
#include "libssh/buffer.h" #include "libssh/buffer.h"
@ -200,6 +208,29 @@ ssh_key pki_key_dup(const ssh_key key, int demote)
break; break;
case SSH_KEYTYPE_ECDSA: case SSH_KEYTYPE_ECDSA:
/* privkey -> pubkey */
if (demote && ssh_key_is_private(key)) {
const EC_POINT *p;
int ok;
new->ecdsa = EC_KEY_new_by_curve_name(key->ecdsa_nid);
if (new->ecdsa == NULL) {
goto fail;
}
p = EC_KEY_get0_public_key(key->ecdsa);
if (p == NULL) {
goto fail;
}
ok = EC_KEY_set_public_key(new->ecdsa, p);
if (!ok) {
goto fail;
}
} else {
new->ecdsa = EC_KEY_dup(key->ecdsa);
}
break;
case SSH_KEYTYPE_UNKNOWN: case SSH_KEYTYPE_UNKNOWN:
ssh_key_free(new); ssh_key_free(new);
return NULL; return NULL;