libssh 0.11.0
The SSH library
Loading...
Searching...
No Matches
pki_priv.h
1/*
2 * This file is part of the SSH Library
3 *
4 * Copyright (c) 2010 by Aris Adamantiadis
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#ifndef PKI_PRIV_H_
22#define PKI_PRIV_H_
23
24#include "libssh/pki.h"
25
26#ifdef __cplusplus
27extern "C" {
28#endif
29
30/* defined in bcrypt_pbkdf.c */
31int bcrypt_pbkdf(const char *pass,
32 size_t passlen,
33 const uint8_t *salt,
34 size_t saltlen,
35 uint8_t *key,
36 size_t keylen,
37 unsigned int rounds);
38
39#define RSA_HEADER_BEGIN "-----BEGIN RSA PRIVATE KEY-----"
40#define RSA_HEADER_END "-----END RSA PRIVATE KEY-----"
41#define ECDSA_HEADER_BEGIN "-----BEGIN EC PRIVATE KEY-----"
42#define ECDSA_HEADER_END "-----END EC PRIVATE KEY-----"
43#define OPENSSH_HEADER_BEGIN "-----BEGIN OPENSSH PRIVATE KEY-----"
44#define OPENSSH_HEADER_END "-----END OPENSSH PRIVATE KEY-----"
45/* Magic defined in OpenSSH/PROTOCOL.key */
46#define OPENSSH_AUTH_MAGIC "openssh-key-v1"
47
48/* Determine type of ssh key. */
49enum ssh_key_e {
50 SSH_KEY_PUBLIC = 0,
51 SSH_KEY_PRIVATE
52};
53
54void pki_key_clean(ssh_key key);
55
56int pki_key_ecdsa_nid_from_name(const char *name);
57const char *pki_key_ecdsa_nid_to_name(int nid);
58const char *ssh_key_signature_to_char(enum ssh_keytypes_e type,
59 enum ssh_digest_e hash_type);
60enum ssh_digest_e ssh_key_type_to_hash(ssh_session session,
61 enum ssh_keytypes_e type);
62
63/* SSH Key Functions */
64ssh_key pki_key_dup_common_init(const ssh_key key, int demote);
65ssh_key pki_key_dup(const ssh_key key, int demote);
66int pki_key_generate_rsa(ssh_key key, int parameter);
67int pki_key_generate_ecdsa(ssh_key key, int parameter);
68int pki_key_generate_ed25519(ssh_key key);
69
70int pki_key_compare(const ssh_key k1,
71 const ssh_key k2,
72 enum ssh_keycmp_e what);
73
74int pki_key_check_hash_compatible(ssh_key key,
75 enum ssh_digest_e hash_type);
76/* SSH Private Key Functions */
77enum ssh_keytypes_e pki_privatekey_type_from_string(const char *privkey);
78ssh_key pki_private_key_from_base64(const char *b64_key,
79 const char *passphrase,
80 ssh_auth_callback auth_fn,
81 void *auth_data);
82
83ssh_string pki_private_key_to_pem(const ssh_key key,
84 const char *passphrase,
85 ssh_auth_callback auth_fn,
86 void *auth_data);
87int pki_import_privkey_buffer(enum ssh_keytypes_e type,
88 ssh_buffer buffer,
89 ssh_key *pkey);
90
91/* SSH Public Key Functions */
92int pki_pubkey_build_rsa(ssh_key key,
93 ssh_string e,
94 ssh_string n);
95int pki_pubkey_build_ecdsa(ssh_key key, int nid, ssh_string e);
96ssh_string pki_key_to_blob(const ssh_key key, enum ssh_key_e type);
97
98/* SSH Private Key Functions */
99int pki_privkey_build_rsa(ssh_key key,
100 ssh_string n,
101 ssh_string e,
102 ssh_string d,
103 ssh_string iqmp,
104 ssh_string p,
105 ssh_string q);
106int pki_privkey_build_ecdsa(ssh_key key,
107 int nid,
108 ssh_string e,
109 ssh_string exp);
110
111/* SSH Signature Functions */
112ssh_signature pki_sign_data(const ssh_key privkey,
113 enum ssh_digest_e hash_type,
114 const unsigned char *input,
115 size_t input_len);
116int pki_verify_data_signature(ssh_signature signature,
117 const ssh_key pubkey,
118 const unsigned char *input,
119 size_t input_len);
120ssh_string pki_signature_to_blob(const ssh_signature sign);
121ssh_signature pki_signature_from_blob(const ssh_key pubkey,
122 const ssh_string sig_blob,
123 enum ssh_keytypes_e type,
124 enum ssh_digest_e hash_type);
125
126/* SSH Signing Functions */
127ssh_signature pki_do_sign(const ssh_key privkey,
128 const unsigned char *input,
129 size_t input_len,
130 enum ssh_digest_e hash_type);
131ssh_signature pki_do_sign_hash(const ssh_key privkey,
132 const unsigned char *hash,
133 size_t hlen,
134 enum ssh_digest_e hash_type);
135#ifndef HAVE_LIBCRYPTO
136int pki_ed25519_sign(const ssh_key privkey, ssh_signature sig,
137 const unsigned char *hash, size_t hlen);
138int pki_ed25519_verify(const ssh_key pubkey, ssh_signature sig,
139 const unsigned char *hash, size_t hlen);
140#endif /* HAVE_LIBCRYPTO */
141int pki_ed25519_key_cmp(const ssh_key k1,
142 const ssh_key k2,
143 enum ssh_keycmp_e what);
144int pki_ed25519_key_dup(ssh_key new_key, const ssh_key key);
145int pki_ed25519_public_key_to_blob(ssh_buffer buffer, ssh_key key);
146int pki_ed25519_private_key_to_blob(ssh_buffer buffer, const ssh_key privkey);
147ssh_string pki_ed25519_signature_to_blob(ssh_signature sig);
148int pki_signature_from_ed25519_blob(ssh_signature sig, ssh_string sig_blob);
149int pki_privkey_build_ed25519(ssh_key key,
150 ssh_string pubkey,
151 ssh_string privkey);
152int pki_pubkey_build_ed25519(ssh_key key, ssh_string pubkey);
153
154/* PKI Container OpenSSH */
155ssh_key ssh_pki_openssh_pubkey_import(const char *text_key);
156ssh_key ssh_pki_openssh_privkey_import(const char *text_key,
157 const char *passphrase, ssh_auth_callback auth_fn, void *auth_data);
158ssh_string ssh_pki_openssh_privkey_export(const ssh_key privkey,
159 const char *passphrase, ssh_auth_callback auth_fn, void *auth_data);
160
161#ifdef WITH_PKCS11_URI
162/* URI Function */
163int pki_uri_import(const char *uri_name, ssh_key *key, enum ssh_key_e key_type);
164#endif /* WITH_PKCS11_URI */
165
166bool ssh_key_size_allowed_rsa(int min_size, ssh_key key);
167
168/* Security Key Helper Functions */
169int pki_buffer_pack_sk_priv_data(ssh_buffer buffer, const ssh_key key);
170int pki_buffer_unpack_sk_priv_data(ssh_buffer buffer, ssh_key key);
171int pki_sk_signature_buffer_prepare(const ssh_key key,
172 const ssh_signature sig,
173 const unsigned char *input,
174 size_t input_len,
175 ssh_buffer *sk_buffer_out);
176
177#ifdef __cplusplus
178}
179#endif
180
181#endif /* PKI_PRIV_H_ */
int(* ssh_auth_callback)(const char *prompt, char *buf, size_t len, int echo, int verify, void *userdata)
SSH authentication callback for password and publickey auth.
Definition libssh.h:702
const char * ssh_key_signature_to_char(enum ssh_keytypes_e type, enum ssh_digest_e hash_type)
Convert a signature type to a string.
Definition pki.c:365
enum ssh_digest_e ssh_key_type_to_hash(ssh_session session, enum ssh_keytypes_e type)
Convert a key type to a hash type. This is usually unambiguous for all the key types,...
Definition pki.c:628
int pki_sk_signature_buffer_prepare(const ssh_key key, const ssh_signature sig, const unsigned char *input, size_t input_len, ssh_buffer *sk_buffer_out)
Prepare buffer for FIDO2/U2F security key signature verification.
Definition pki.c:3022