2 * Copyright (C) 2000,2001,2002 Nikos Mavroyanopoulos
4 * This file is part of GNUTLS.
6 * GNUTLS is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * GNUTLS 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
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
28 #define LIBGNUTLS_VERSION "@VERSION@"
33 #define GNUTLS_CIPHER_AES_128_CBC GNUTLS_CIPHER_RIJNDAEL_128_CBC
34 #define GNUTLS_CIPHER_AES_256_CBC GNUTLS_CIPHER_RIJNDAEL_256_CBC
35 #define GNUTLS_CIPHER_RIJNDAEL_CBC GNUTLS_CIPHER_RIJNDAEL_128_CBC
37 typedef enum GNUTLS_BulkCipherAlgorithm { GNUTLS_CIPHER_NULL=1, GNUTLS_CIPHER_ARCFOUR, GNUTLS_CIPHER_3DES_CBC, GNUTLS_CIPHER_RIJNDAEL_128_CBC, GNUTLS_CIPHER_TWOFISH_128_CBC, GNUTLS_CIPHER_RIJNDAEL_256_CBC } GNUTLS_BulkCipherAlgorithm;
39 typedef enum GNUTLS_KXAlgorithm { GNUTLS_KX_RSA=1, GNUTLS_KX_DHE_DSS, GNUTLS_KX_DHE_RSA, GNUTLS_KX_ANON_DH, GNUTLS_KX_SRP } GNUTLS_KXAlgorithm;
41 typedef enum GNUTLS_CredType { GNUTLS_CRD_CERTIFICATE=1, GNUTLS_CRD_ANON, GNUTLS_CRD_SRP } GNUTLS_CredType;
43 typedef enum GNUTLS_MACAlgorithm { GNUTLS_MAC_NULL=1, GNUTLS_MAC_MD5, GNUTLS_MAC_SHA } GNUTLS_MACAlgorithm;
44 typedef enum GNUTLS_DigestAlgorithm { GNUTLS_DIG_NULL=1, GNUTLS_DIG_MD5, GNUTLS_DIG_SHA } GNUTLS_DigestAlgorithm;
45 typedef enum GNUTLS_CompressionMethod { GNUTLS_COMP_NULL=1, GNUTLS_COMP_ZLIB } GNUTLS_CompressionMethod;
46 typedef enum GNUTLS_ConnectionEnd { GNUTLS_SERVER=1, GNUTLS_CLIENT } GNUTLS_ConnectionEnd;
47 typedef enum GNUTLS_AlertLevel { GNUTLS_AL_WARNING=1, GNUTLS_AL_FATAL } GNUTLS_AlertLevel;
48 typedef enum GNUTLS_AlertDescription { GNUTLS_A_CLOSE_NOTIFY, GNUTLS_A_UNEXPECTED_MESSAGE=10, GNUTLS_A_BAD_RECORD_MAC=20,
49 GNUTLS_A_DECRYPTION_FAILED, GNUTLS_A_RECORD_OVERFLOW, GNUTLS_A_DECOMPRESSION_FAILURE=30,
50 GNUTLS_A_HANDSHAKE_FAILURE=40, GNUTLS_A_SSL3_NO_CERTIFICATE=41,
51 GNUTLS_A_BAD_CERTIFICATE=42, GNUTLS_A_UNSUPPORTED_CERTIFICATE,
52 GNUTLS_A_CERTIFICATE_REVOKED, GNUTLS_A_CERTIFICATE_EXPIRED, GNUTLS_A_CERTIFICATE_UNKNOWN,
53 GNUTLS_A_ILLEGAL_PARAMETER, GNUTLS_A_UNKNOWN_CA, GNUTLS_A_ACCESS_DENIED, GNUTLS_A_DECODE_ERROR=50,
54 GNUTLS_A_DECRYPT_ERROR, GNUTLS_A_EXPORT_RESTRICTION=60, GNUTLS_A_PROTOCOL_VERSION=70,
55 GNUTLS_A_INSUFFICIENT_SECURITY, GNUTLS_A_INTERNAL_ERROR=80, GNUTLS_A_USER_CANCELED=90,
56 GNUTLS_A_NO_RENEGOTIATION=100
57 } GNUTLS_AlertDescription;
59 #define GNUTLS_CERT_EXPIRED 8
61 typedef enum GNUTLS_CertificateStatus {
62 GNUTLS_CERT_NOT_TRUSTED=2,
63 GNUTLS_CERT_INVALID=4,
64 GNUTLS_CERT_CORRUPTED=16,
65 GNUTLS_CERT_REVOKED=32
66 } GNUTLS_CertificateStatus;
68 typedef enum GNUTLS_CertificateRequest { GNUTLS_CERT_IGNORE, GNUTLS_CERT_REQUEST=1, GNUTLS_CERT_REQUIRE } GNUTLS_CertificateRequest;
70 typedef enum GNUTLS_OpenPGPKeyStatus { GNUTLS_OPENPGP_KEY,
71 GNUTLS_OPENPGP_KEY_FINGERPRINT
72 } GNUTLS_OpenPGPKeyStatus;
74 typedef enum GNUTLS_CloseRequest { GNUTLS_SHUT_RDWR=0, GNUTLS_SHUT_WR=1 } GNUTLS_CloseRequest;
76 typedef enum GNUTLS_Version { GNUTLS_SSL3=1, GNUTLS_TLS1 } GNUTLS_Version;
78 typedef enum GNUTLS_CertificateType { GNUTLS_CRT_X509=1, GNUTLS_CRT_OPENPGP
79 } GNUTLS_CertificateType;
81 typedef enum GNUTLS_X509_CertificateFmt { GNUTLS_X509_FMT_DER,
82 GNUTLS_X509_FMT_PEM } GNUTLS_X509_CertificateFmt;
84 typedef enum GNUTLS_PKAlgorithm { GNUTLS_PK_RSA = 1, GNUTLS_PK_DSA
87 /* If you want to change this, then also change the
88 * define in gnutls_int.h, and recompile.
90 #define GNUTLS_TRANSPORT_PTR int
92 typedef const int* GNUTLS_LIST;
94 struct GNUTLS_STATE_INT;
95 typedef struct GNUTLS_STATE_INT* GNUTLS_STATE;
97 struct GNUTLS_DH_PARAMS_INT;
98 typedef struct GNUTLS_DH_PARAMS_INT* GNUTLS_DH_PARAMS;
101 unsigned char * data;
105 /* internal functions */
107 int gnutls_init(GNUTLS_STATE * state, GNUTLS_ConnectionEnd con_end);
108 void gnutls_deinit(GNUTLS_STATE state);
109 int gnutls_bye( GNUTLS_STATE state, GNUTLS_CloseRequest how);
110 #define gnutls_close gnutls_bye
112 int gnutls_handshake( GNUTLS_STATE state);
113 int gnutls_rehandshake( GNUTLS_STATE state);
116 GNUTLS_AlertDescription gnutls_alert_get( GNUTLS_STATE state);
117 int gnutls_alert_send( GNUTLS_STATE, GNUTLS_AlertLevel, GNUTLS_AlertDescription);
118 int gnutls_alert_send_appropriate( GNUTLS_STATE state, int err);
119 const char* gnutls_alert_get_name( int alert);
121 /* get information on the current state */
122 GNUTLS_BulkCipherAlgorithm gnutls_cipher_get( GNUTLS_STATE state);
123 GNUTLS_KXAlgorithm gnutls_kx_get( GNUTLS_STATE state);
124 GNUTLS_MACAlgorithm gnutls_mac_get( GNUTLS_STATE state);
125 GNUTLS_CompressionMethod gnutls_compression_get( GNUTLS_STATE state);
126 GNUTLS_CertificateType gnutls_cert_type_get( GNUTLS_STATE state);
128 /* the name of the specified algorithms */
129 const char *gnutls_cipher_get_name( GNUTLS_BulkCipherAlgorithm);
130 const char *gnutls_mac_get_name( GNUTLS_MACAlgorithm);
131 const char *gnutls_compression_get_name( GNUTLS_CompressionMethod);
132 const char *gnutls_kx_get_name( GNUTLS_KXAlgorithm algorithm);
133 const char *gnutls_cert_type_get_name( GNUTLS_CertificateType type);
136 /* error functions */
137 int gnutls_error_is_fatal( int error);
139 void gnutls_perror( int error);
140 const char* gnutls_strerror( int error);
142 void gnutls_record_set_cbc_protection(GNUTLS_STATE state, int prot);
143 void gnutls_handshake_set_rsa_pms_check(GNUTLS_STATE state, int check);
144 ssize_t gnutls_record_send( GNUTLS_STATE state, const void *data, size_t sizeofdata);
145 ssize_t gnutls_record_recv( GNUTLS_STATE state, void *data, size_t sizeofdata);
146 #define gnutls_read gnutls_record_recv
147 #define gnutls_write gnutls_record_send
149 /* functions to set priority of cipher suites */
150 int gnutls_cipher_set_priority( GNUTLS_STATE state, GNUTLS_LIST);
151 int gnutls_mac_set_priority( GNUTLS_STATE state, GNUTLS_LIST);
152 int gnutls_compression_set_priority( GNUTLS_STATE state, GNUTLS_LIST);
153 int gnutls_kx_set_priority( GNUTLS_STATE state, GNUTLS_LIST);
154 int gnutls_protocol_set_priority( GNUTLS_STATE state, GNUTLS_LIST);
155 int gnutls_cert_type_set_priority( GNUTLS_STATE state, GNUTLS_LIST);
157 /* set our version - 0 for TLS 1.0 and 1 for SSL3 */
158 GNUTLS_Version gnutls_protocol_get_version(GNUTLS_STATE state);
160 const char *gnutls_protocol_get_name(GNUTLS_Version version);
165 int gnutls_session_set_data( GNUTLS_STATE state, void* session, int session_size);
166 int gnutls_session_get_data( GNUTLS_STATE state, void* session, int *session_size);
167 /* returns the session ID */
168 int gnutls_session_get_id( GNUTLS_STATE state, void* session, int *session_size);
170 /* checks if this session is a resumed one
172 int gnutls_session_is_resumed(GNUTLS_STATE state);
174 typedef int (*GNUTLS_DB_STORE_FUNC)(void*, gnutls_datum key, gnutls_datum data);
175 typedef int (*GNUTLS_DB_REMOVE_FUNC)(void*, gnutls_datum key);
176 typedef gnutls_datum (*GNUTLS_DB_RETR_FUNC)(void*, gnutls_datum key);
178 void gnutls_db_set_cache_expiration( GNUTLS_STATE state, int seconds);
180 int gnutls_db_set_name( GNUTLS_STATE state, const char* filename);
181 int gnutls_db_clean( GNUTLS_STATE state);
182 void gnutls_db_remove_session( GNUTLS_STATE state);
183 void gnutls_db_set_retrieve_func( GNUTLS_STATE, GNUTLS_DB_RETR_FUNC);
184 void gnutls_db_set_remove_func( GNUTLS_STATE, GNUTLS_DB_REMOVE_FUNC);
185 void gnutls_db_set_store_func( GNUTLS_STATE, GNUTLS_DB_STORE_FUNC);
186 void gnutls_db_set_ptr( GNUTLS_STATE, void* db_ptr);
187 void* gnutls_db_get_ptr( GNUTLS_STATE);
188 int gnutls_db_check_entry( GNUTLS_STATE state, gnutls_datum session_entry);
190 void gnutls_handshake_set_max_length( GNUTLS_STATE state, int max);
192 /* returns libgnutls version */
193 const char* gnutls_check_version( const char*);
195 /* Functions for setting/clearing credentials */
196 int gnutls_clear_creds( GNUTLS_STATE state);
197 /* cred is a structure defined by the kx algorithm */
198 int gnutls_cred_set( GNUTLS_STATE, GNUTLS_CredType type, void* cred);
200 /* Credential structures for SRP - used in gnutls_set_cred(); */
203 typedef struct DSTRUCT* GNUTLS_CERTIFICATE_CREDENTIALS;
204 typedef GNUTLS_CERTIFICATE_CREDENTIALS GNUTLS_CERTIFICATE_CLIENT_CREDENTIALS;
205 typedef GNUTLS_CERTIFICATE_CREDENTIALS GNUTLS_CERTIFICATE_SERVER_CREDENTIALS;
207 typedef struct DSTRUCT* GNUTLS_SRP_SERVER_CREDENTIALS;
208 typedef struct DSTRUCT* GNUTLS_SRP_CLIENT_CREDENTIALS;
210 typedef struct DSTRUCT* GNUTLS_ANON_SERVER_CREDENTIALS;
211 typedef struct DSTRUCT* GNUTLS_ANON_CLIENT_CREDENTIALS;
213 void gnutls_srp_free_client_sc( GNUTLS_SRP_CLIENT_CREDENTIALS sc);
214 int gnutls_srp_allocate_client_sc( GNUTLS_SRP_CLIENT_CREDENTIALS *sc);
215 int gnutls_srp_set_client_cred( GNUTLS_SRP_CLIENT_CREDENTIALS res, char *username, char* password);
217 void gnutls_srp_free_server_sc( GNUTLS_SRP_SERVER_CREDENTIALS sc);
218 int gnutls_srp_allocate_server_sc( GNUTLS_SRP_SERVER_CREDENTIALS *sc);
219 int gnutls_srp_set_server_cred_file( GNUTLS_SRP_SERVER_CREDENTIALS res, char *password_file, char* password_conf_file);
221 void gnutls_anon_free_server_sc( GNUTLS_ANON_SERVER_CREDENTIALS sc);
222 int gnutls_anon_allocate_server_sc( GNUTLS_ANON_SERVER_CREDENTIALS *sc);
223 int gnutls_anon_set_server_cred( GNUTLS_ANON_SERVER_CREDENTIALS res);
224 void gnutls_anon_set_server_dh_params( GNUTLS_ANON_SERVER_CREDENTIALS res, GNUTLS_DH_PARAMS);
226 void gnutls_anon_free_client_sc( GNUTLS_ANON_SERVER_CREDENTIALS sc);
227 int gnutls_anon_allocate_client_sc( GNUTLS_ANON_SERVER_CREDENTIALS *sc);
228 int gnutls_anon_set_client_cred( GNUTLS_ANON_SERVER_CREDENTIALS res);
231 /* CERTFILE is an x509 certificate in PEM form.
232 * KEYFILE is a pkcs-1 private key in PEM form (for RSA keys).
234 void gnutls_certificate_free_sc( GNUTLS_CERTIFICATE_CREDENTIALS sc);
235 int gnutls_certificate_allocate_sc( GNUTLS_CERTIFICATE_CREDENTIALS *sc);
237 int gnutls_certificate_set_dh_params(GNUTLS_CERTIFICATE_CREDENTIALS res, GNUTLS_DH_PARAMS);
239 int gnutls_certificate_set_x509_trust_file( GNUTLS_CERTIFICATE_CREDENTIALS res, char* CAFILE,
240 GNUTLS_X509_CertificateFmt);
241 int gnutls_certificate_set_x509_trust_mem(GNUTLS_CERTIFICATE_CREDENTIALS res,
242 const gnutls_datum *CA, GNUTLS_X509_CertificateFmt);
244 int gnutls_certificate_set_x509_key_file( GNUTLS_CERTIFICATE_CREDENTIALS res,
245 char *CERTFILE, char* KEYFILE, GNUTLS_X509_CertificateFmt);
246 int gnutls_certificate_set_x509_key_mem(GNUTLS_CERTIFICATE_CREDENTIALS res,
247 const gnutls_datum* CERT, const gnutls_datum* KEY,
248 GNUTLS_X509_CertificateFmt);
250 int gnutls_certificate_set_openpgp_key_file( GNUTLS_CERTIFICATE_CREDENTIALS res, char *CERTFILE, char* KEYFILE);
251 int gnutls_certificate_set_openpgp_key_mem( GNUTLS_CERTIFICATE_CREDENTIALS res,
252 const gnutls_datum* CERT, const gnutls_datum* KEY);
254 void gnutls_certificate_set_openpgp_keyserver(GNUTLS_CERTIFICATE_CREDENTIALS res,
255 char* keyserver, int port);
257 void gnutls_certificate_set_openpgp_trustdb(GNUTLS_CERTIFICATE_CREDENTIALS res,
260 int gnutls_certificate_set_openpgp_keyring_mem( GNUTLS_CERTIFICATE_CREDENTIALS res,
261 const char *data, size_t len);
263 int gnutls_certificate_set_openpgp_keyring_file( GNUTLS_CERTIFICATE_CREDENTIALS res, const char *name);
266 /* global state functions
268 /* In this version global_init accepts two files (pkix.asn, pkcs1.asn).
269 * This will not be the case in the final version. These files
270 * are located in the src/ directory of gnutls distribution.
272 int gnutls_global_init(void);
273 void gnutls_global_deinit(void);
275 int gnutls_dh_params_set( GNUTLS_DH_PARAMS, gnutls_datum prime, gnutls_datum generator, int bits);
276 int gnutls_dh_params_init( GNUTLS_DH_PARAMS*);
277 void gnutls_dh_params_deinit( GNUTLS_DH_PARAMS);
278 int gnutls_dh_params_generate( gnutls_datum* prime, gnutls_datum* generator, int bits);
280 typedef ssize_t (*GNUTLS_PULL_FUNC)(GNUTLS_TRANSPORT_PTR, void*, size_t);
281 typedef ssize_t (*GNUTLS_PUSH_FUNC)(GNUTLS_TRANSPORT_PTR, const void*, size_t);
282 void gnutls_transport_set_ptr(GNUTLS_STATE state, GNUTLS_TRANSPORT_PTR ptr);
283 GNUTLS_TRANSPORT_PTR gnutls_transport_get_ptr(GNUTLS_STATE state);
285 void gnutls_transport_set_lowat( GNUTLS_STATE state, int num);
287 typedef void (*GNUTLS_LOG_FUNC)( const char*);
289 void gnutls_transport_set_push_func( GNUTLS_STATE, GNUTLS_PUSH_FUNC push_func);
290 void gnutls_transport_set_pull_func( GNUTLS_STATE, GNUTLS_PULL_FUNC pull_func);
292 size_t gnutls_record_get_max_size( GNUTLS_STATE state);
293 ssize_t gnutls_record_set_max_size( GNUTLS_STATE state, size_t size);
295 size_t gnutls_record_check_pending(GNUTLS_STATE state);
297 void gnutls_openpgp_send_key(GNUTLS_STATE state, GNUTLS_OpenPGPKeyStatus status);
299 int gnutls_x509_fingerprint(GNUTLS_DigestAlgorithm algo, const gnutls_datum* data, char* result, size_t* result_size);
300 int gnutls_openpgp_fingerprint( const gnutls_datum* data, char* result, size_t* result_size);