libssh: pki_priv.h Source File

libssh 0.10.4 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/* defined in bcrypt_pbkdf.c */
27int bcrypt_pbkdf(const char *pass,
28 size_t passlen,
29 const uint8_t *salt,
30 size_t saltlen,
31 uint8_t *key,
32 size_t keylen,
33 unsigned int rounds);
34
35#define RSA_HEADER_BEGIN "-----BEGIN RSA PRIVATE KEY-----"
36#define RSA_HEADER_END "-----END RSA PRIVATE KEY-----"
37#define DSA_HEADER_BEGIN "-----BEGIN DSA PRIVATE KEY-----"
38#define DSA_HEADER_END "-----END DSA PRIVATE KEY-----"
39#define ECDSA_HEADER_BEGIN "-----BEGIN EC PRIVATE KEY-----"
40#define ECDSA_HEADER_END "-----END EC PRIVATE KEY-----"
41#define OPENSSH_HEADER_BEGIN "-----BEGIN OPENSSH PRIVATE KEY-----"
42#define OPENSSH_HEADER_END "-----END OPENSSH PRIVATE KEY-----"
43/* Magic defined in OpenSSH/PROTOCOL.key */
44#define OPENSSH_AUTH_MAGIC "openssh-key-v1"
45
46/* Determine type of ssh key. */
47enum ssh_key_e {
48 SSH_KEY_PUBLIC = 0,
49 SSH_KEY_PRIVATE
50};
51
52void pki_key_clean(ssh_key key);
53
54int pki_key_ecdsa_nid_from_name(const char *name);
55const char *pki_key_ecdsa_nid_to_name(int nid);
56const char *ssh_key_signature_to_char(enum ssh_keytypes_e type,
57 enum ssh_digest_e hash_type);
58enum ssh_digest_e ssh_key_type_to_hash(ssh_session session,
59 enum ssh_keytypes_e type);
60
61/* SSH Key Functions */
62 ssh_key pki_key_dup(const ssh_key key, int demote);
63int pki_key_generate_rsa(ssh_key key, int parameter);
64int pki_key_generate_dss(ssh_key key, int parameter);
65int pki_key_generate_ecdsa(ssh_key key, int parameter);
66int pki_key_generate_ed25519(ssh_key key);
67
68int pki_key_compare(const ssh_key k1,
69 const ssh_key k2,
70 enum ssh_keycmp_e what);
71
72int pki_key_check_hash_compatible(ssh_key key,
73 enum ssh_digest_e hash_type);
74/* SSH Private Key Functions */
75enum ssh_keytypes_e pki_privatekey_type_from_string(const char *privkey);
76 ssh_key pki_private_key_from_base64(const char *b64_key,
77 const char *passphrase,
78 ssh_auth_callback auth_fn,
79 void *auth_data);
80
81 ssh_string pki_private_key_to_pem(const ssh_key key,
82 const char *passphrase,
83 ssh_auth_callback auth_fn,
84 void *auth_data);
85int pki_import_privkey_buffer(enum ssh_keytypes_e type,
86 ssh_buffer buffer,
87 ssh_key *pkey);
88
89/* SSH Public Key Functions */
90int pki_pubkey_build_dss(ssh_key key,
91 ssh_string p,
92 ssh_string q,
93 ssh_string g,
94 ssh_string pubkey);
95int pki_pubkey_build_rsa(ssh_key key,
96 ssh_string e,
97 ssh_string n);
98int pki_pubkey_build_ecdsa(ssh_key key, int nid, ssh_string e);
99 ssh_string pki_publickey_to_blob(const ssh_key key);
100
101/* SSH Private Key Functions */
102int pki_privkey_build_dss(ssh_key key,
103 ssh_string p,
104 ssh_string q,
105 ssh_string g,
106 ssh_string pubkey,
107 ssh_string privkey);
108int pki_privkey_build_rsa(ssh_key key,
109 ssh_string n,
110 ssh_string e,
111 ssh_string d,
112 ssh_string iqmp,
113 ssh_string p,
114 ssh_string q);
115int pki_privkey_build_ecdsa(ssh_key key,
116 int nid,
117 ssh_string e,
118 ssh_string exp);
119 ssh_string pki_publickey_to_blob(const ssh_key key);
120
121/* SSH Signature Functions */
122 ssh_signature pki_sign_data(const ssh_key privkey,
123 enum ssh_digest_e hash_type,
124 const unsigned char *input,
125 size_t input_len);
126int pki_verify_data_signature(ssh_signature signature,
127 const ssh_key pubkey,
128 const unsigned char *input,
129 size_t input_len);
130 ssh_string pki_signature_to_blob(const ssh_signature sign);
131 ssh_signature pki_signature_from_blob(const ssh_key pubkey,
132 const ssh_string sig_blob,
133 enum ssh_keytypes_e type,
134 enum ssh_digest_e hash_type);
135
136/* SSH Signing Functions */
137 ssh_signature pki_do_sign(const ssh_key privkey,
138 const unsigned char *input,
139 size_t input_len,
140 enum ssh_digest_e hash_type);
141 ssh_signature pki_do_sign_hash(const ssh_key privkey,
142 const unsigned char *hash,
143 size_t hlen,
144 enum ssh_digest_e hash_type);
145int pki_ed25519_sign(const ssh_key privkey, ssh_signature sig,
146 const unsigned char *hash, size_t hlen);
147int pki_ed25519_verify(const ssh_key pubkey, ssh_signature sig,
148 const unsigned char *hash, size_t hlen);
149int pki_ed25519_key_cmp(const ssh_key k1,
150 const ssh_key k2,
151 enum ssh_keycmp_e what);
152int pki_ed25519_key_dup(ssh_key new, const ssh_key key);
153int pki_ed25519_public_key_to_blob(ssh_buffer buffer, ssh_key key);
154 ssh_string pki_ed25519_signature_to_blob(ssh_signature sig);
155int pki_signature_from_ed25519_blob(ssh_signature sig, ssh_string sig_blob);
156int pki_privkey_build_ed25519(ssh_key key,
157 ssh_string pubkey,
158 ssh_string privkey);
159
160/* PKI Container OpenSSH */
161 ssh_key ssh_pki_openssh_pubkey_import(const char *text_key);
162 ssh_key ssh_pki_openssh_privkey_import(const char *text_key,
163 const char *passphrase, ssh_auth_callback auth_fn, void *auth_data);
164 ssh_string ssh_pki_openssh_privkey_export(const ssh_key privkey,
165 const char *passphrase, ssh_auth_callback auth_fn, void *auth_data);
166
167/* URI Function */
168int pki_uri_import(const char *uri_name, ssh_key *key, enum ssh_key_e key_type);
169
170bool ssh_key_size_allowed_rsa(int min_size, ssh_key key);
171#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:674
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:228
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:440
ssh_buffer_struct
Definition: buffer.c:47
ssh_key_struct
Definition: pki.h:54
ssh_session_struct
Definition: session.h:110
ssh_signature_struct
Definition: pki.h:97
ssh_string_struct
Definition: string.h:29