mirror of
https://git.libssh.org/projects/libssh.git
synced 2025-08-08 19:02:06 +03:00
pki: Add ssh_pki_do_sign_agent().
This commit is contained in:
@@ -80,6 +80,9 @@ ssh_key ssh_pki_publickey_from_privatekey(const ssh_key privkey);
|
|||||||
/* SSH Signing Functions */
|
/* SSH Signing Functions */
|
||||||
ssh_string ssh_pki_do_sign(ssh_session session, ssh_buffer sigbuf,
|
ssh_string ssh_pki_do_sign(ssh_session session, ssh_buffer sigbuf,
|
||||||
ssh_key privatekey);
|
ssh_key privatekey);
|
||||||
|
ssh_string ssh_pki_do_sign_agent(ssh_session session,
|
||||||
|
struct ssh_buffer_struct *buf,
|
||||||
|
const ssh_key pubkey);
|
||||||
|
|
||||||
/* Temporary functions, to be removed after migration to ssh_key */
|
/* Temporary functions, to be removed after migration to ssh_key */
|
||||||
ssh_public_key ssh_pki_convert_key_to_publickey(ssh_key key);
|
ssh_public_key ssh_pki_convert_key_to_publickey(ssh_key key);
|
||||||
|
53
src/pki.c
53
src/pki.c
@@ -48,6 +48,7 @@
|
|||||||
#include "libssh/keys.h"
|
#include "libssh/keys.h"
|
||||||
#include "libssh/buffer.h"
|
#include "libssh/buffer.h"
|
||||||
#include "libssh/misc.h"
|
#include "libssh/misc.h"
|
||||||
|
#include "libssh/agent.h"
|
||||||
|
|
||||||
void ssh_pki_log(const char *format, ...)
|
void ssh_pki_log(const char *format, ...)
|
||||||
{
|
{
|
||||||
@@ -1028,6 +1029,58 @@ ssh_string ssh_pki_do_sign(ssh_session session, ssh_buffer sigbuf,
|
|||||||
return signature;
|
return signature;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef _WIN32
|
||||||
|
ssh_string ssh_pki_do_sign_agent(ssh_session session,
|
||||||
|
struct ssh_buffer_struct *buf,
|
||||||
|
const ssh_key pubkey) {
|
||||||
|
struct ssh_crypto_struct *crypto;
|
||||||
|
ssh_string session_id;
|
||||||
|
ssh_string sig_blob;
|
||||||
|
ssh_buffer sig_buf;
|
||||||
|
int rc;
|
||||||
|
|
||||||
|
if (session->current_crypto) {
|
||||||
|
crypto = session->current_crypto;
|
||||||
|
} else {
|
||||||
|
crypto = session->next_crypto;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* prepend session identifier */
|
||||||
|
session_id = ssh_string_new(crypto->digest_len);
|
||||||
|
if (session_id == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
ssh_string_fill(session_id, crypto->session_id, crypto->digest_len);
|
||||||
|
|
||||||
|
sig_buf = ssh_buffer_new();
|
||||||
|
if (sig_buf == NULL) {
|
||||||
|
ssh_string_free(session_id);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
rc = buffer_add_ssh_string(sig_buf, session_id);
|
||||||
|
if (rc < 0) {
|
||||||
|
ssh_string_free(session_id);
|
||||||
|
ssh_buffer_free(sig_buf);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
ssh_string_free(session_id);
|
||||||
|
|
||||||
|
/* append out buffer */
|
||||||
|
if (buffer_add_buffer(sig_buf, buf) < 0) {
|
||||||
|
ssh_buffer_free(sig_buf);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* create signature */
|
||||||
|
sig_blob = ssh_agent_sign_data(session, pubkey, sig_buf);
|
||||||
|
|
||||||
|
ssh_buffer_free(sig_buf);
|
||||||
|
|
||||||
|
return sig_blob;
|
||||||
|
}
|
||||||
|
#endif /* _WIN32 */
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
|
Reference in New Issue
Block a user