libssh: pki_priv.h Source File

libssh 0.11.1 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(const ssh_key key, int demote);
65int pki_key_generate_rsa(ssh_key key, int parameter);
66int pki_key_generate_ecdsa(ssh_key key, int parameter);
67int pki_key_generate_ed25519(ssh_key key);
68
69int pki_key_compare(const ssh_key k1,
70 const ssh_key k2,
71 enum ssh_keycmp_e what);
72
73int pki_key_check_hash_compatible(ssh_key key,
74 enum ssh_digest_e hash_type);
75/* SSH Private Key Functions */
76enum ssh_keytypes_e pki_privatekey_type_from_string(const char *privkey);
77ssh_key pki_private_key_from_base64(const char *b64_key,
78 const char *passphrase,
79 ssh_auth_callback auth_fn,
80 void *auth_data);
81
82ssh_string pki_private_key_to_pem(const ssh_key key,
83 const char *passphrase,
84 ssh_auth_callback auth_fn,
85 void *auth_data);
86int pki_import_privkey_buffer(enum ssh_keytypes_e type,
87 ssh_buffer buffer,
88 ssh_key *pkey);
89
90/* SSH Public Key Functions */
91int pki_pubkey_build_rsa(ssh_key key,
92 ssh_string e,
93 ssh_string n);
94int pki_pubkey_build_ecdsa(ssh_key key, int nid, ssh_string e);
95ssh_string pki_key_to_blob(const ssh_key key, enum ssh_key_e type);
96
97/* SSH Private Key Functions */
98int pki_privkey_build_rsa(ssh_key key,
99 ssh_string n,
100 ssh_string e,
101 ssh_string d,
102 ssh_string iqmp,
103 ssh_string p,
104 ssh_string q);
105int pki_privkey_build_ecdsa(ssh_key key,
106 int nid,
107 ssh_string e,
108 ssh_string exp);
109
110/* SSH Signature Functions */
111ssh_signature pki_sign_data(const ssh_key privkey,
112 enum ssh_digest_e hash_type,
113 const unsigned char *input,
114 size_t input_len);
115int pki_verify_data_signature(ssh_signature signature,
116 const ssh_key pubkey,
117 const unsigned char *input,
118 size_t input_len);
119ssh_string pki_signature_to_blob(const ssh_signature sign);
120ssh_signature pki_signature_from_blob(const ssh_key pubkey,
121 const ssh_string sig_blob,
122 enum ssh_keytypes_e type,
123 enum ssh_digest_e hash_type);
124
125/* SSH Signing Functions */
126ssh_signature pki_do_sign(const ssh_key privkey,
127 const unsigned char *input,
128 size_t input_len,
129 enum ssh_digest_e hash_type);
130ssh_signature pki_do_sign_hash(const ssh_key privkey,
131 const unsigned char *hash,
132 size_t hlen,
133 enum ssh_digest_e hash_type);
134#ifndef HAVE_LIBCRYPTO
135int pki_ed25519_sign(const ssh_key privkey, ssh_signature sig,
136 const unsigned char *hash, size_t hlen);
137int pki_ed25519_verify(const ssh_key pubkey, ssh_signature sig,
138 const unsigned char *hash, size_t hlen);
139#endif /* HAVE_LIBCRYPTO */
140int pki_ed25519_key_cmp(const ssh_key k1,
141 const ssh_key k2,
142 enum ssh_keycmp_e what);
143int pki_ed25519_key_dup(ssh_key new_key, const ssh_key key);
144int pki_ed25519_public_key_to_blob(ssh_buffer buffer, ssh_key key);
145int pki_ed25519_private_key_to_blob(ssh_buffer buffer, const ssh_key privkey);
146ssh_string pki_ed25519_signature_to_blob(ssh_signature sig);
147int pki_signature_from_ed25519_blob(ssh_signature sig, ssh_string sig_blob);
148int pki_privkey_build_ed25519(ssh_key key,
149 ssh_string pubkey,
150 ssh_string privkey);
151
152/* PKI Container OpenSSH */
153ssh_key ssh_pki_openssh_pubkey_import(const char *text_key);
154ssh_key ssh_pki_openssh_privkey_import(const char *text_key,
155 const char *passphrase, ssh_auth_callback auth_fn, void *auth_data);
156ssh_string ssh_pki_openssh_privkey_export(const ssh_key privkey,
157 const char *passphrase, ssh_auth_callback auth_fn, void *auth_data);
158
159#ifdef WITH_PKCS11_URI
160/* URI Function */
161int pki_uri_import(const char *uri_name, ssh_key *key, enum ssh_key_e key_type);
162#endif /* WITH_PKCS11_URI */
163
164bool ssh_key_size_allowed_rsa(int min_size, ssh_key key);
165#ifdef __cplusplus
166}
167#endif
168
169#endif /* PKI_PRIV_H_ */
ssh_auth_callback
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:699
ssh_key_signature_to_char
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:216
ssh_key_type_to_hash
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:424