libssh 0.7.2

- Main Page
- Related Pages
- Modules
- Data Structures
- Files

- File List

pki.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_H_
22 #define PKI_H_
23
24 #include "libssh/priv.h"
25 #ifdef HAVE_OPENSSL_EC_H
26 #include <openssl/ec.h>
27 #endif
28 #ifdef HAVE_OPENSSL_ECDSA_H
29 #include <openssl/ecdsa.h>
30 #endif
31
32 #include "libssh/crypto.h"
33 #include "libssh/ed25519.h"
34
35 #define MAX_PUBKEY_SIZE 0x100000 /* 1M */
36 #define MAX_PRIVKEY_SIZE 0x400000 /* 4M */
37
38 #define SSH_KEY_FLAG_EMPTY 0x0
39 #define SSH_KEY_FLAG_PUBLIC 0x0001
40 #define SSH_KEY_FLAG_PRIVATE 0x0002
41
42 struct ssh_key_struct {
43 enum ssh_keytypes_e type;
44 int flags;
45 const char *type_c; /* Don't free it ! it is static */
46 int ecdsa_nid;
47 #ifdef HAVE_LIBGCRYPT
48 gcry_sexp_t dsa;
49 gcry_sexp_t rsa;
50 void *ecdsa;
51 #elif HAVE_LIBCRYPTO
52 DSA *dsa;
53 RSA *rsa;
54 #ifdef HAVE_OPENSSL_ECC
55 EC_KEY *ecdsa;
56 #else
57 void *ecdsa;
58 #endif /* HAVE_OPENSSL_EC_H */
59 #endif
60 ed25519_pubkey *ed25519_pubkey;
61 ed25519_privkey *ed25519_privkey;
62 void *cert;
63 };
64
65 struct ssh_signature_struct {
66 enum ssh_keytypes_e type;
67 const char *type_c;
68 #ifdef HAVE_LIBGCRYPT
69 gcry_sexp_t dsa_sig;
70 gcry_sexp_t rsa_sig;
71 void *ecdsa_sig;
72 #elif defined HAVE_LIBCRYPTO
73 DSA_SIG *dsa_sig;
74 ssh_string rsa_sig;
75 # ifdef HAVE_OPENSSL_ECC
76 ECDSA_SIG *ecdsa_sig;
77 # else
78 void *ecdsa_sig;
79 # endif
80 #endif
81 ed25519_signature *ed25519_sig;
82 };
83
84 typedef struct ssh_signature_struct *ssh_signature;
85
86 /* SSH Key Functions */
87 ssh_key ssh_key_dup(const ssh_key key);
88 void ssh_key_clean (ssh_key key);
89
90 /* SSH Signature Functions */
91 ssh_signature ssh_signature_new(void);
92 void ssh_signature_free(ssh_signature sign);
93
94 int ssh_pki_export_signature_blob(const ssh_signature sign,
95 ssh_string *sign_blob);
96 int ssh_pki_import_signature_blob(const ssh_string sig_blob,
97 const ssh_key pubkey,
98 ssh_signature *psig);
99 int ssh_pki_signature_verify_blob(ssh_session session,
100 ssh_string sig_blob,
101 const ssh_key key,
102 unsigned char *digest,
103 size_t dlen);
104
105 /* SSH Public Key Functions */
106 int ssh_pki_export_pubkey_blob(const ssh_key key,
107 ssh_string *pblob);
108 int ssh_pki_import_pubkey_blob(const ssh_string key_blob,
109 ssh_key *pkey);
110 int ssh_pki_export_pubkey_rsa1(const ssh_key key,
111 const char *host,
112 char *rsa1,
113 size_t rsa1_len);
114
115 /* SSH Signing Functions */
116 ssh_string ssh_pki_do_sign(ssh_session session, ssh_buffer sigbuf,
117 const ssh_key privatekey);
118 ssh_string ssh_pki_do_sign_agent(ssh_session session,
119 struct ssh_buffer_struct *buf,
120 const ssh_key pubkey);
121 ssh_string ssh_srv_pki_do_sign_sessionid(ssh_session session,
122 const ssh_key privkey);
123
124 /* Temporary functions, to be removed after migration to ssh_key */
125 ssh_public_key ssh_pki_convert_key_to_publickey(const ssh_key key);
126 ssh_private_key ssh_pki_convert_key_to_privatekey(const ssh_key key);
127
128 #endif /* PKI_H_ */
ssh_key_clean
void ssh_key_clean(ssh_key key)
clean up the key and deallocate all existing keys
Definition: pki.c:146