pki: Add ssh_pki_export_pubkey_rsa1().
Этот коммит содержится в:
родитель
6901e25085
Коммит
808c7a9be4
@ -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,
|
||||
|
@ -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);
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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
|
||||
*
|
||||
|
@ -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};
|
||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user