2 * Copyright (C) 2004, 2005, 2006, 2008 Free Software Foundation
3 * Copyright (c) 2002 Andrew McDonald <andrew@mcdonald.org.uk>
5 * This file is part of GNUTLS-EXTRA.
7 * GNUTLS-EXTRA is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * GNUTLS-EXTRA is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include <gnutls/gnutls.h>
24 #include <openssl_compat.h>
28 #include <gnutls/openssl.h>
29 #include "../lib/gnutls_int.h"
30 #include "../lib/random.h"
31 #include "../lib/gnutls_hash_int.h"
33 /* Gnulib re-defines shutdown on mingw. We only use it as a variable
34 name, so restore the original name. */
37 /* XXX: See lib/gnutls_int.h. */
38 #define GNUTLS_POINTER_TO_INT(_) ((int) GNUTLS_POINTER_TO_INT_CAST (_))
39 #define GNUTLS_INT_TO_POINTER(_) ((void*) GNUTLS_POINTER_TO_INT_CAST (_))
41 /* WARNING: Error functions aren't currently thread-safe */
43 static int last_error
= 0;
45 /* Library initialisation functions */
48 SSL_library_init (void)
50 gnutls_global_init ();
51 /* NB: we haven't got anywhere to call gnutls_global_deinit() */
56 OpenSSL_add_all_algorithms (void)
61 /* SSL_CTX structure handling */
64 SSL_CTX_new (SSL_METHOD
* method
)
68 ctx
= (SSL_CTX
*) calloc (1, sizeof (SSL_CTX
));
75 SSL_CTX_free (SSL_CTX
* ctx
)
82 SSL_CTX_set_default_verify_paths (SSL_CTX
* ctx
)
88 SSL_CTX_use_certificate_file (SSL_CTX
* ctx
, const char *certfile
, int type
)
90 ctx
->certfile
= (char *) calloc (1, strlen (certfile
) + 1);
93 memcpy (ctx
->certfile
, certfile
, strlen (certfile
));
95 ctx
->certfile_type
= type
;
101 SSL_CTX_use_PrivateKey_file (SSL_CTX
* ctx
, const char *keyfile
, int type
)
103 ctx
->keyfile
= (char *) calloc (1, strlen (keyfile
) + 1);
106 memcpy (ctx
->keyfile
, keyfile
, strlen (keyfile
));
108 ctx
->keyfile_type
= type
;
115 SSL_CTX_set_verify (SSL_CTX
* ctx
, int verify_mode
,
116 int (*verify_callback
) (int, X509_STORE_CTX
*))
118 ctx
->verify_mode
= verify_mode
;
119 ctx
->verify_callback
= verify_callback
;
123 SSL_CTX_set_options (SSL_CTX
* ctx
, unsigned long options
)
125 return (ctx
->options
|= options
);
129 SSL_CTX_set_mode (SSL_CTX
* ctx
, long mode
)
135 SSL_CTX_set_cipher_list (SSL_CTX
* ctx
, const char *list
)
137 /* FIXME: ignore this for the moment */
138 /* We're going to have to parse the "list" string to do this */
139 /* It is a string, which in its simplest form is something like
140 "DES-CBC3-SHA:IDEA-CBC-MD5", but can be rather more complicated
141 (see OpenSSL's ciphers(1) manpage for details) */
147 /* SSL_CTX statistics */
150 SSL_CTX_sess_number (SSL_CTX
* ctx
)
156 SSL_CTX_sess_connect (SSL_CTX
* ctx
)
162 SSL_CTX_sess_connect_good (SSL_CTX
* ctx
)
168 SSL_CTX_sess_connect_renegotiate (SSL_CTX
* ctx
)
174 SSL_CTX_sess_accept (SSL_CTX
* ctx
)
180 SSL_CTX_sess_accept_good (SSL_CTX
* ctx
)
186 SSL_CTX_sess_accept_renegotiate (SSL_CTX
* ctx
)
192 SSL_CTX_sess_hits (SSL_CTX
* ctx
)
198 SSL_CTX_sess_misses (SSL_CTX
* ctx
)
204 SSL_CTX_sess_timeouts (SSL_CTX
* ctx
)
211 /* SSL structure handling */
214 SSL_new (SSL_CTX
* ctx
)
219 ssl
= (SSL
*) calloc (1, sizeof (SSL
));
223 err
= gnutls_certificate_allocate_credentials (&ssl
->gnutls_cred
);
231 gnutls_init (&ssl
->gnutls_state
, ctx
->method
->connend
);
233 gnutls_protocol_set_priority (ssl
->gnutls_state
,
234 ctx
->method
->protocol_priority
);
235 gnutls_cipher_set_priority (ssl
->gnutls_state
,
236 ctx
->method
->cipher_priority
);
237 gnutls_compression_set_priority (ssl
->gnutls_state
,
238 ctx
->method
->comp_priority
);
239 gnutls_kx_set_priority (ssl
->gnutls_state
, ctx
->method
->kx_priority
);
240 gnutls_mac_set_priority (ssl
->gnutls_state
, ctx
->method
->mac_priority
);
242 gnutls_credentials_set (ssl
->gnutls_state
, GNUTLS_CRD_CERTIFICATE
,
245 gnutls_certificate_set_x509_trust_file (ssl
->gnutls_cred
,
249 gnutls_certificate_set_x509_key_file (ssl
->gnutls_cred
,
250 ctx
->certfile
, ctx
->keyfile
,
253 ssl
->verify_mode
= ctx
->verify_mode
;
254 ssl
->verify_callback
= ctx
->verify_callback
;
256 ssl
->options
= ctx
->options
;
258 ssl
->rfd
= (gnutls_transport_ptr_t
) - 1;
259 ssl
->wfd
= (gnutls_transport_ptr_t
) - 1;
267 gnutls_certificate_free_credentials (ssl
->gnutls_cred
);
268 gnutls_deinit (ssl
->gnutls_state
);
273 SSL_load_error_strings (void)
278 SSL_get_error (SSL
* ssl
, int ret
)
281 return SSL_ERROR_NONE
;
283 return SSL_ERROR_ZERO_RETURN
;
287 SSL_set_fd (SSL
* ssl
, int fd
)
289 gnutls_transport_set_ptr (ssl
->gnutls_state
, GNUTLS_INT_TO_POINTER (fd
));
294 SSL_set_rfd (SSL
* ssl
, int fd
)
296 ssl
->rfd
= GNUTLS_INT_TO_POINTER (fd
);
298 if (ssl
->wfd
!= (gnutls_transport_ptr_t
) - 1)
299 gnutls_transport_set_ptr2 (ssl
->gnutls_state
, ssl
->rfd
, ssl
->wfd
);
305 SSL_set_wfd (SSL
* ssl
, int fd
)
307 ssl
->wfd
= GNUTLS_INT_TO_POINTER (fd
);
309 if (ssl
->rfd
!= (gnutls_transport_ptr_t
) - 1)
310 gnutls_transport_set_ptr2 (ssl
->gnutls_state
, ssl
->rfd
, ssl
->wfd
);
316 SSL_set_bio (SSL
* ssl
, BIO
* rbio
, BIO
* wbio
)
318 gnutls_transport_set_ptr2 (ssl
->gnutls_state
, rbio
->fd
, wbio
->fd
);
323 SSL_set_connect_state (SSL
* ssl
)
328 SSL_pending (SSL
* ssl
)
330 return gnutls_record_check_pending (ssl
->gnutls_state
);
334 SSL_set_verify (SSL
* ssl
, int verify_mode
,
335 int (*verify_callback
) (int, X509_STORE_CTX
*))
337 ssl
->verify_mode
= verify_mode
;
338 ssl
->verify_callback
= verify_callback
;
342 SSL_get_peer_certificate (SSL
* ssl
)
344 const gnutls_datum_t
*cert_list
;
345 int cert_list_size
= 0;
347 cert_list
= gnutls_certificate_get_peers (ssl
->gnutls_state
,
353 /* SSL connection open/close/read/write functions */
356 SSL_connect (SSL
* ssl
)
358 X509_STORE_CTX
*store
;
359 int cert_list_size
= 0;
362 int x_priority
[GNUTLS_MAX_ALGORITHM_NUM
];
363 /* take options into account before connecting */
365 memset (x_priority
, 0, sizeof (x_priority
));
366 if (ssl
->options
& SSL_OP_NO_TLSv1
)
369 i
< GNUTLS_MAX_ALGORITHM_NUM
&& x_priority
[i
] != 0; i
++, j
++)
371 if (ssl
->ctx
->method
->protocol_priority
[j
] == GNUTLS_TLS1
)
374 x_priority
[i
] = ssl
->ctx
->method
->protocol_priority
[j
];
376 if (i
< GNUTLS_MAX_ALGORITHM_NUM
)
378 gnutls_protocol_set_priority (ssl
->gnutls_state
,
379 ssl
->ctx
->method
->protocol_priority
);
382 err
= gnutls_handshake (ssl
->gnutls_state
);
383 ssl
->last_error
= err
;
391 store
= (X509_STORE_CTX
*) calloc (1, sizeof (X509_STORE_CTX
));
393 store
->cert_list
= gnutls_certificate_get_peers (ssl
->gnutls_state
,
396 if (ssl
->verify_callback
)
398 ssl
->verify_callback (1 /*FIXME*/, store
);
400 ssl
->state
= SSL_ST_OK
;
405 /* FIXME: deal with error from callback */
411 SSL_accept (SSL
* ssl
)
413 X509_STORE_CTX
*store
;
414 int cert_list_size
= 0;
417 int x_priority
[GNUTLS_MAX_ALGORITHM_NUM
];
418 /* take options into account before accepting */
420 memset (x_priority
, 0, sizeof (x_priority
));
421 if (ssl
->options
& SSL_OP_NO_TLSv1
)
424 i
< GNUTLS_MAX_ALGORITHM_NUM
&& x_priority
[i
] != 0; i
++, j
++)
426 if (ssl
->ctx
->method
->protocol_priority
[j
] == GNUTLS_TLS1
)
429 x_priority
[i
] = ssl
->ctx
->method
->protocol_priority
[j
];
431 if (i
< GNUTLS_MAX_ALGORITHM_NUM
)
433 gnutls_protocol_set_priority (ssl
->gnutls_state
,
434 ssl
->ctx
->method
->protocol_priority
);
437 /* FIXME: dh params, do we want client cert? */
439 err
= gnutls_handshake (ssl
->gnutls_state
);
440 ssl
->last_error
= err
;
448 store
= (X509_STORE_CTX
*) calloc (1, sizeof (X509_STORE_CTX
));
450 store
->cert_list
= gnutls_certificate_get_peers (ssl
->gnutls_state
,
453 if (ssl
->verify_callback
)
455 ssl
->verify_callback (1 /*FIXME*/, store
);
457 ssl
->state
= SSL_ST_OK
;
462 /* FIXME: deal with error from callback */
468 SSL_shutdown (SSL
* ssl
)
472 gnutls_bye (ssl
->gnutls_state
, GNUTLS_SHUT_WR
);
477 gnutls_bye (ssl
->gnutls_state
, GNUTLS_SHUT_RDWR
);
486 SSL_read (SSL
* ssl
, void *buf
, int len
)
490 ret
= gnutls_record_recv (ssl
->gnutls_state
, buf
, len
);
491 ssl
->last_error
= ret
;
503 SSL_write (SSL
* ssl
, const void *buf
, int len
)
507 ret
= gnutls_record_send (ssl
->gnutls_state
, buf
, len
);
508 ssl
->last_error
= ret
;
526 /* SSL_METHOD functions */
529 SSLv23_client_method (void)
532 m
= (SSL_METHOD
*) calloc (1, sizeof (SSL_METHOD
));
536 m
->protocol_priority
[0] = GNUTLS_TLS1
;
537 m
->protocol_priority
[1] = GNUTLS_SSL3
;
538 m
->protocol_priority
[2] = 0;
540 m
->cipher_priority
[0] = GNUTLS_CIPHER_AES_128_CBC
;
541 m
->cipher_priority
[1] = GNUTLS_CIPHER_3DES_CBC
;
542 m
->cipher_priority
[2] = GNUTLS_CIPHER_AES_256_CBC
;
543 #ifdef ENABLE_CAMELLIA
544 m
->cipher_priority
[3] = GNUTLS_CIPHER_CAMELLIA_128_CBC
;
545 m
->cipher_priority
[4] = GNUTLS_CIPHER_CAMELLIA_256_CBC
;
546 m
->cipher_priority
[5] = GNUTLS_CIPHER_ARCFOUR_128
;
547 m
->cipher_priority
[6] = 0;
549 m
->cipher_priority
[3] = GNUTLS_CIPHER_ARCFOUR_128
;
550 m
->cipher_priority
[4] = 0;
553 m
->comp_priority
[0] = GNUTLS_COMP_ZLIB
;
554 m
->comp_priority
[1] = GNUTLS_COMP_NULL
;
555 m
->comp_priority
[2] = 0;
557 m
->kx_priority
[0] = GNUTLS_KX_DHE_RSA
;
558 m
->kx_priority
[1] = GNUTLS_KX_RSA
;
559 m
->kx_priority
[2] = GNUTLS_KX_DHE_DSS
;
560 m
->kx_priority
[3] = 0;
562 m
->mac_priority
[0] = GNUTLS_MAC_SHA1
;
563 m
->mac_priority
[1] = GNUTLS_MAC_MD5
;
564 m
->mac_priority
[2] = 0;
566 m
->connend
= GNUTLS_CLIENT
;
572 SSLv23_server_method (void)
575 m
= (SSL_METHOD
*) calloc (1, sizeof (SSL_METHOD
));
579 m
->protocol_priority
[0] = GNUTLS_TLS1
;
580 m
->protocol_priority
[1] = GNUTLS_SSL3
;
581 m
->protocol_priority
[2] = 0;
583 m
->cipher_priority
[0] = GNUTLS_CIPHER_AES_128_CBC
;
584 m
->cipher_priority
[1] = GNUTLS_CIPHER_3DES_CBC
;
585 m
->cipher_priority
[2] = GNUTLS_CIPHER_AES_256_CBC
;
586 #ifdef ENABLE_CAMELLIA
587 m
->cipher_priority
[3] = GNUTLS_CIPHER_CAMELLIA_128_CBC
;
588 m
->cipher_priority
[4] = GNUTLS_CIPHER_CAMELLIA_256_CBC
;
589 m
->cipher_priority
[5] = GNUTLS_CIPHER_ARCFOUR_128
;
590 m
->cipher_priority
[6] = 0;
592 m
->cipher_priority
[3] = GNUTLS_CIPHER_ARCFOUR_128
;
593 m
->cipher_priority
[4] = 0;
596 m
->comp_priority
[0] = GNUTLS_COMP_ZLIB
;
597 m
->comp_priority
[1] = GNUTLS_COMP_NULL
;
598 m
->comp_priority
[2] = 0;
600 m
->kx_priority
[0] = GNUTLS_KX_DHE_RSA
;
601 m
->kx_priority
[1] = GNUTLS_KX_RSA
;
602 m
->kx_priority
[2] = GNUTLS_KX_DHE_DSS
;
603 m
->kx_priority
[3] = 0;
605 m
->mac_priority
[0] = GNUTLS_MAC_SHA1
;
606 m
->mac_priority
[1] = GNUTLS_MAC_MD5
;
607 m
->mac_priority
[2] = 0;
609 m
->connend
= GNUTLS_SERVER
;
615 SSLv3_client_method (void)
618 m
= (SSL_METHOD
*) calloc (1, sizeof (SSL_METHOD
));
622 m
->protocol_priority
[0] = GNUTLS_SSL3
;
623 m
->protocol_priority
[2] = 0;
625 m
->cipher_priority
[1] = GNUTLS_CIPHER_3DES_CBC
;
626 m
->cipher_priority
[2] = GNUTLS_CIPHER_ARCFOUR_128
;
627 m
->cipher_priority
[3] = 0;
629 m
->comp_priority
[0] = GNUTLS_COMP_ZLIB
;
630 m
->comp_priority
[1] = GNUTLS_COMP_NULL
;
631 m
->comp_priority
[2] = 0;
633 m
->kx_priority
[0] = GNUTLS_KX_DHE_RSA
;
634 m
->kx_priority
[1] = GNUTLS_KX_RSA
;
635 m
->kx_priority
[2] = GNUTLS_KX_DHE_DSS
;
636 m
->kx_priority
[3] = 0;
638 m
->mac_priority
[0] = GNUTLS_MAC_SHA1
;
639 m
->mac_priority
[1] = GNUTLS_MAC_MD5
;
640 m
->mac_priority
[2] = 0;
642 m
->connend
= GNUTLS_CLIENT
;
648 SSLv3_server_method (void)
651 m
= (SSL_METHOD
*) calloc (1, sizeof (SSL_METHOD
));
655 m
->protocol_priority
[0] = GNUTLS_SSL3
;
656 m
->protocol_priority
[2] = 0;
658 m
->cipher_priority
[1] = GNUTLS_CIPHER_3DES_CBC
;
659 m
->cipher_priority
[2] = GNUTLS_CIPHER_ARCFOUR_128
;
660 m
->cipher_priority
[3] = 0;
662 m
->comp_priority
[0] = GNUTLS_COMP_ZLIB
;
663 m
->comp_priority
[1] = GNUTLS_COMP_NULL
;
664 m
->comp_priority
[2] = 0;
666 m
->kx_priority
[0] = GNUTLS_KX_DHE_RSA
;
667 m
->kx_priority
[1] = GNUTLS_KX_RSA
;
668 m
->kx_priority
[2] = GNUTLS_KX_DHE_DSS
;
669 m
->kx_priority
[3] = 0;
671 m
->mac_priority
[0] = GNUTLS_MAC_SHA1
;
672 m
->mac_priority
[1] = GNUTLS_MAC_MD5
;
673 m
->mac_priority
[2] = 0;
675 m
->connend
= GNUTLS_SERVER
;
681 TLSv1_client_method (void)
684 m
= (SSL_METHOD
*) calloc (1, sizeof (SSL_METHOD
));
688 m
->protocol_priority
[0] = GNUTLS_TLS1
;
689 m
->protocol_priority
[1] = 0;
691 m
->cipher_priority
[0] = GNUTLS_CIPHER_AES_128_CBC
;
692 m
->cipher_priority
[1] = GNUTLS_CIPHER_3DES_CBC
;
693 m
->cipher_priority
[2] = GNUTLS_CIPHER_AES_256_CBC
;
694 #ifdef ENABLE_CAMELLIA
695 m
->cipher_priority
[3] = GNUTLS_CIPHER_CAMELLIA_128_CBC
;
696 m
->cipher_priority
[4] = GNUTLS_CIPHER_CAMELLIA_256_CBC
;
697 m
->cipher_priority
[5] = GNUTLS_CIPHER_ARCFOUR_128
;
698 m
->cipher_priority
[6] = 0;
700 m
->cipher_priority
[3] = GNUTLS_CIPHER_ARCFOUR_128
;
701 m
->cipher_priority
[4] = 0;
704 m
->comp_priority
[0] = GNUTLS_COMP_ZLIB
;
705 m
->comp_priority
[1] = GNUTLS_COMP_NULL
;
706 m
->comp_priority
[2] = 0;
708 m
->kx_priority
[0] = GNUTLS_KX_DHE_RSA
;
709 m
->kx_priority
[1] = GNUTLS_KX_RSA
;
710 m
->kx_priority
[2] = GNUTLS_KX_DHE_DSS
;
711 m
->kx_priority
[3] = 0;
713 m
->mac_priority
[0] = GNUTLS_MAC_SHA1
;
714 m
->mac_priority
[1] = GNUTLS_MAC_MD5
;
715 m
->mac_priority
[2] = 0;
717 m
->connend
= GNUTLS_CLIENT
;
723 TLSv1_server_method (void)
726 m
= (SSL_METHOD
*) calloc (1, sizeof (SSL_METHOD
));
730 m
->protocol_priority
[0] = GNUTLS_TLS1
;
731 m
->protocol_priority
[1] = 0;
733 m
->cipher_priority
[0] = GNUTLS_CIPHER_AES_128_CBC
;
734 m
->cipher_priority
[1] = GNUTLS_CIPHER_3DES_CBC
;
735 m
->cipher_priority
[2] = GNUTLS_CIPHER_AES_256_CBC
;
736 #ifdef ENABLE_CAMELLIA
737 m
->cipher_priority
[3] = GNUTLS_CIPHER_CAMELLIA_128_CBC
;
738 m
->cipher_priority
[4] = GNUTLS_CIPHER_CAMELLIA_256_CBC
;
739 m
->cipher_priority
[5] = GNUTLS_CIPHER_ARCFOUR_128
;
740 m
->cipher_priority
[6] = 0;
742 m
->cipher_priority
[3] = GNUTLS_CIPHER_ARCFOUR_128
;
743 m
->cipher_priority
[4] = 0;
746 m
->comp_priority
[0] = GNUTLS_COMP_ZLIB
;
747 m
->comp_priority
[1] = GNUTLS_COMP_NULL
;
748 m
->comp_priority
[2] = 0;
750 m
->kx_priority
[0] = GNUTLS_KX_DHE_RSA
;
751 m
->kx_priority
[1] = GNUTLS_KX_RSA
;
752 m
->kx_priority
[2] = GNUTLS_KX_DHE_DSS
;
753 m
->kx_priority
[3] = 0;
755 m
->mac_priority
[0] = GNUTLS_MAC_SHA1
;
756 m
->mac_priority
[1] = GNUTLS_MAC_MD5
;
757 m
->mac_priority
[2] = 0;
759 m
->connend
= GNUTLS_SERVER
;
765 /* SSL_CIPHER functions */
768 SSL_get_current_cipher (SSL
* ssl
)
773 ssl
->ciphersuite
.version
= gnutls_protocol_get_version (ssl
->gnutls_state
);
774 ssl
->ciphersuite
.cipher
= gnutls_cipher_get (ssl
->gnutls_state
);
775 ssl
->ciphersuite
.kx
= gnutls_kx_get (ssl
->gnutls_state
);
776 ssl
->ciphersuite
.mac
= gnutls_mac_get (ssl
->gnutls_state
);
777 ssl
->ciphersuite
.compression
= gnutls_compression_get (ssl
->gnutls_state
);
778 ssl
->ciphersuite
.cert
= gnutls_certificate_type_get (ssl
->gnutls_state
);
780 return &(ssl
->ciphersuite
);
784 SSL_CIPHER_get_name (SSL_CIPHER
* cipher
)
789 return gnutls_cipher_suite_get_name (cipher
->kx
,
790 cipher
->cipher
, cipher
->mac
);
794 SSL_CIPHER_get_bits (SSL_CIPHER
* cipher
, int *bits
)
801 bit_result
= (8 * gnutls_cipher_get_key_size (cipher
->cipher
));
810 SSL_CIPHER_get_version (SSL_CIPHER
* cipher
)
817 ret
= gnutls_protocol_get_name (cipher
->version
);
825 SSL_CIPHER_description (SSL_CIPHER
* cipher
, char *buf
, int size
)
839 tmpbuf
= (char *) malloc (128);
844 if (snprintf (tmpbuf
, tmpsize
, "%s %s %s %s",
845 gnutls_protocol_get_name (cipher
->version
),
846 gnutls_kx_get_name (cipher
->kx
),
847 gnutls_cipher_get_name (cipher
->cipher
),
848 gnutls_mac_get_name (cipher
->mac
)) == -1)
852 return (char*) "Buffer too small";
862 X509_get_subject_name (const X509
* cert
)
865 dn
= (gnutls_x509_dn
*) calloc (1, sizeof (gnutls_x509_dn
));
866 if (gnutls_x509_extract_certificate_dn (cert
, dn
) < 0)
875 X509_get_issuer_name (const X509
* cert
)
878 dn
= (gnutls_x509_dn
*) calloc (1, sizeof (gnutls_x509_dn
));
879 if (gnutls_x509_extract_certificate_issuer_dn (cert
, dn
) < 0)
888 X509_NAME_oneline (gnutls_x509_dn
* name
, char *buf
, int len
)
890 memset (buf
, 0, len
);
894 snprintf (buf
, len
- 1,
895 "C=%s, ST=%s, L=%s, O=%s, OU=%s, CN=%s/Email=%s",
896 name
->country
, name
->state_or_province_name
,
897 name
->locality_name
, name
->organization
,
898 name
->organizational_unit_name
, name
->common_name
, name
->email
);
903 X509_free (const X509
* cert
)
905 /* only get certificates as const items */
912 BIO_get_fd (gnutls_session_t gnutls_state
, int *fd
)
914 gnutls_transport_ptr_t tmp
= gnutls_transport_get_ptr (gnutls_state
);
915 *fd
= GNUTLS_POINTER_TO_INT (tmp
);
919 BIO_new_socket (int sock
, int close_flag
)
923 bio
= (BIO
*) malloc (sizeof (BIO
));
927 bio
->fd
= GNUTLS_INT_TO_POINTER (sock
);
940 ret
= -1 * last_error
;
947 ERR_error_string (unsigned long e
, char *buf
)
949 return gnutls_strerror (-1 * e
);
962 RAND_seed (const void *buf
, int num
)
967 RAND_bytes (unsigned char *buf
, int num
)
969 _gnutls_rnd (GNUTLS_RND_RANDOM
, buf
, num
);
974 RAND_pseudo_bytes (unsigned char *buf
, int num
)
976 _gnutls_rnd (GNUTLS_RND_NONCE
, buf
, num
);
981 RAND_file_name (char *buf
, size_t len
)
987 RAND_load_file (const char *name
, long maxbytes
)
993 RAND_write_file (const char *name
)
999 RAND_egd_bytes (const char *path
, int bytes
)
1006 /* message digest functions */
1009 MD5_Init (MD5_CTX
* ctx
)
1011 ctx
->handle
= gnutls_malloc (sizeof (digest_hd_st
));
1014 _gnutls_hash_init (ctx
->handle
, GNUTLS_DIG_MD5
);
1018 MD5_Update (MD5_CTX
* ctx
, const void *buf
, int len
)
1020 _gnutls_hash (ctx
->handle
, buf
, len
);
1024 MD5_Final (unsigned char *md
, MD5_CTX
* ctx
)
1026 _gnutls_hash_deinit (ctx
->handle
, md
);
1027 gnutls_free (ctx
->handle
);
1031 MD5 (const unsigned char *buf
, unsigned long len
, unsigned char *md
)
1036 _gnutls_hash_fast (GNUTLS_DIG_MD5
, buf
, len
, md
);
1042 RIPEMD160_Init (RIPEMD160_CTX
* ctx
)
1044 ctx
->handle
= gnutls_malloc (sizeof (digest_hd_st
));
1047 _gnutls_hash_init (ctx
->handle
, GNUTLS_DIG_RMD160
);
1051 RIPEMD160_Update (RIPEMD160_CTX
* ctx
, const void *buf
, int len
)
1053 _gnutls_hash (ctx
->handle
, buf
, len
);
1057 RIPEMD160_Final (unsigned char *md
, RIPEMD160_CTX
* ctx
)
1059 _gnutls_hash_deinit (ctx
->handle
, md
);
1060 gnutls_free (ctx
->handle
);
1064 RIPEMD160 (const unsigned char *buf
, unsigned long len
, unsigned char *md
)
1069 _gnutls_hash_fast (GNUTLS_DIG_RMD160
, buf
, len
, md
);