2 * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2007 Colin Leroy <colin@colino.net>
4 * and the Claws Mail team
6 * This program 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 3 of the License, or
9 * (at your option) any later version.
11 * This program 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, see <http://www.gnu.org/licenses/>.
25 #if (defined(USE_OPENSSL) || defined (USE_GNUTLS))
27 #include <openssl/ssl.h>
29 #include <gnutls/gnutls.h>
30 #include <gnutls/x509.h>
31 #include <gnutls/pkcs12.h>
36 #include <sys/types.h>
39 #include <glib/gi18n.h>
41 # include <winsock2.h>
43 # include <sys/socket.h>
44 # include <netinet/in.h>
46 #endif /* G_OS_WIN32 */
47 #include "ssl_certificate.h"
54 static GHashTable *warned_expired = NULL;
56 gboolean prefs_common_unsafe_ssl_certs(void);
58 static gchar *get_certificate_path(const gchar *host, const gchar *port, const gchar *fp)
60 if (fp != NULL && prefs_common_unsafe_ssl_certs())
61 return g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
62 "certs", G_DIR_SEPARATOR_S,
63 host, ".", port, ".", fp, ".cert", NULL);
65 return g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
66 "certs", G_DIR_SEPARATOR_S,
67 host, ".", port, ".cert", NULL);
71 static SSLCertificate *ssl_certificate_new_lookup(X509 *x509_cert, gchar *host, gushort port, gboolean lookup);
73 static SSLCertificate *ssl_certificate_new_lookup(gnutls_x509_crt x509_cert, gchar *host, gushort port, gboolean lookup);
77 time_t asn1toTime(ASN1_TIME *asn1Time)
82 if (asn1Time == NULL || asn1Time->length < 13)
85 memset(&tm, 0, sizeof(tm));
87 #define N2(n) ((asn1Time->data[n]-'0')*10 + asn1Time->data[(n)+1]-'0')
89 #define CPY(f,n) (tm.f=N2(n))
94 tm.tm_year += 100; /* Sux */
105 if (asn1Time->data[12] != 'Z')
107 if (asn1Time->length < 17)
110 offset=N2(13)*3600+N2(15)*60;
112 if (asn1Time->data[12] == '-')
119 return mktime(&tm)-offset;
123 static char * get_fqdn(char *host)
127 struct addrinfo hints, *res;
132 if (host == NULL || strlen(host) == 0)
135 memset(&hints, 0, sizeof(hints));
136 hints.ai_flags = AI_CANONNAME;
137 hints.ai_family = AF_UNSPEC;
138 hints.ai_socktype = SOCK_STREAM;
139 hints.ai_protocol = IPPROTO_TCP;
141 gai_err = getaddrinfo(host, NULL, &hints, &res);
143 g_warning("getaddrinfo for %s failed: %s\n",
144 host, gai_strerror(gai_err));
145 return g_strdup(host);
148 if (res->ai_canonname && strlen(res->ai_canonname)) {
149 gchar *fqdn = g_strdup(res->ai_canonname);
154 return g_strdup(host);
157 return g_strdup(host);
160 hp = my_gethostbyname(host);
162 return g_strdup(host); /*caller should free*/
164 return g_strdup(hp->h_name);
168 char * readable_fingerprint(unsigned char *src, int len)
179 tmp2 = g_strdup_printf("%s:%02X", ret, src[i]);
181 tmp2 = g_strdup_printf("%02X", src[i]);
183 ret = g_strdup(tmp2);
191 static gnutls_x509_crt x509_crt_copy(gnutls_x509_crt src)
196 gnutls_x509_crt dest;
198 if (gnutls_x509_crt_init(&dest) != 0) {
199 g_warning("couldn't gnutls_x509_crt_init\n");
203 if (gnutls_x509_crt_export(src, GNUTLS_X509_FMT_DER, NULL, &size)
204 != GNUTLS_E_SHORT_MEMORY_BUFFER) {
205 g_warning("couldn't gnutls_x509_crt_export to get size\n");
206 gnutls_x509_crt_deinit(dest);
210 tmp.data = malloc(size);
211 memset(tmp.data, 0, size);
212 ret = gnutls_x509_crt_export(src, GNUTLS_X509_FMT_DER, tmp.data, &size);
215 ret = gnutls_x509_crt_import(dest, &tmp, GNUTLS_X509_FMT_DER);
217 g_warning("couldn't gnutls_x509_crt_import for real (%d %s)\n", ret, gnutls_strerror(ret));
218 gnutls_x509_crt_deinit(dest);
222 g_warning("couldn't gnutls_x509_crt_export for real (%d %s)\n", ret, gnutls_strerror(ret));
223 gnutls_x509_crt_deinit(dest);
233 static SSLCertificate *ssl_certificate_new_lookup(X509 *x509_cert, gchar *host, gushort port, gboolean lookup)
235 static SSLCertificate *ssl_certificate_new_lookup(gnutls_x509_crt x509_cert, gchar *host, gushort port, gboolean lookup)
238 SSLCertificate *cert = g_new0(SSLCertificate, 1);
244 unsigned char md[128];
246 if (host == NULL || x509_cert == NULL) {
247 ssl_certificate_destroy(cert);
251 cert->x509_cert = X509_dup(x509_cert);
253 cert->x509_cert = x509_crt_copy(x509_cert);
254 cert->status = (guint)-1;
257 cert->host = get_fqdn(host);
259 cert->host = g_strdup(host);
264 X509_digest(cert->x509_cert, EVP_md5(), md, &n);
265 cert->fingerprint = readable_fingerprint(md, (int)n);
268 gnutls_x509_crt_get_fingerprint(cert->x509_cert, GNUTLS_DIG_MD5, md, &n);
269 cert->fingerprint = readable_fingerprint(md, (int)n);
275 static void gnutls_i2d_X509_fp(FILE *fp, gnutls_x509_crt x509_cert)
277 char output[10*1024];
278 size_t cert_size = 10*1024;
281 if ((r = gnutls_x509_crt_export(x509_cert, GNUTLS_X509_FMT_DER, output, &cert_size)) < 0) {
282 g_warning("couldn't export cert %s (%zd)\n", gnutls_strerror(r), cert_size);
285 debug_print("writing %zd bytes\n",cert_size);
286 if (fwrite(&output, 1, cert_size, fp) < cert_size) {
287 g_warning("failed to write cert\n");
291 size_t gnutls_i2d_X509(gnutls_x509_crt x509_cert, unsigned char **output)
293 size_t cert_size = 10*1024;
299 *output = malloc(cert_size);
301 if ((r = gnutls_x509_crt_export(x509_cert, GNUTLS_X509_FMT_DER, *output, &cert_size)) < 0) {
302 g_warning("couldn't export cert %s (%zd)\n", gnutls_strerror(r), cert_size);
310 size_t gnutls_i2d_PrivateKey(gnutls_x509_privkey pkey, unsigned char **output)
312 size_t key_size = 10*1024;
318 *output = malloc(key_size);
320 if ((r = gnutls_x509_privkey_export(pkey, GNUTLS_X509_FMT_DER, *output, &key_size)) < 0) {
321 g_warning("couldn't export key %s (%zd)\n", gnutls_strerror(r), key_size);
329 static gnutls_x509_crt gnutls_d2i_X509_fp(FILE *fp, int format)
331 gnutls_x509_crt cert = NULL;
335 if (fstat(fileno(fp), &s) < 0) {
339 tmp.data = malloc(s.st_size);
340 memset(tmp.data, 0, s.st_size);
341 tmp.size = s.st_size;
342 if (fread (tmp.data, 1, s.st_size, fp) < s.st_size) {
348 gnutls_x509_crt_init(&cert);
349 if ((r = gnutls_x509_crt_import(cert, &tmp, (format == 0)?GNUTLS_X509_FMT_DER:GNUTLS_X509_FMT_PEM)) < 0) {
350 debug_print("cert import failed: %s\n", gnutls_strerror(r));
351 gnutls_x509_crt_deinit(cert);
355 debug_print("got cert! %p\n", cert);
359 static gnutls_x509_privkey gnutls_d2i_key_fp(FILE *fp, int format)
361 gnutls_x509_privkey key = NULL;
365 if (fstat(fileno(fp), &s) < 0) {
369 tmp.data = malloc(s.st_size);
370 memset(tmp.data, 0, s.st_size);
371 tmp.size = s.st_size;
372 if (fread (tmp.data, 1, s.st_size, fp) < s.st_size) {
378 gnutls_x509_privkey_init(&key);
379 if ((r = gnutls_x509_privkey_import(key, &tmp, (format == 0)?GNUTLS_X509_FMT_DER:GNUTLS_X509_FMT_PEM)) < 0) {
380 debug_print("key import failed: %s\n", gnutls_strerror(r));
381 gnutls_x509_privkey_deinit(key);
385 debug_print("got key! %p\n", key);
389 static gnutls_pkcs12_t gnutls_d2i_PKCS12_fp(FILE *fp, int format)
391 gnutls_pkcs12_t p12 = NULL;
395 if (fstat(fileno(fp), &s) < 0) {
399 tmp.data = malloc(s.st_size);
400 memset(tmp.data, 0, s.st_size);
401 tmp.size = s.st_size;
402 if (fread (tmp.data, 1, s.st_size, fp) < s.st_size) {
408 gnutls_pkcs12_init(&p12);
410 if ((r = gnutls_pkcs12_import(p12, &tmp, (format == 0)?GNUTLS_X509_FMT_DER:GNUTLS_X509_FMT_PEM,0)) < 0) {
411 g_warning("p12 import failed: %s\n", gnutls_strerror(r));
412 gnutls_pkcs12_deinit(p12);
416 debug_print("got p12! %p\n", p12);
422 static void ssl_certificate_save (SSLCertificate *cert)
427 file = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
428 "certs", G_DIR_SEPARATOR_S, NULL);
430 if (!is_dir_exist(file))
434 port = g_strdup_printf("%d", cert->port);
435 file = get_certificate_path(cert->host, port, cert->fingerprint);
438 fp = g_fopen(file, "wb");
441 debug_print("Can't save certificate !\n");
445 gnutls_i2d_X509_fp(fp, cert->x509_cert);
447 i2d_X509_fp(fp, cert->x509_cert);
454 void ssl_certificate_destroy(SSLCertificate *cert)
461 X509_free(cert->x509_cert);
463 gnutls_x509_crt_deinit(cert->x509_cert);
466 g_free(cert->fingerprint);
471 void ssl_certificate_delete_from_disk(SSLCertificate *cert)
475 buf = g_strdup_printf("%d", cert->port);
476 file = get_certificate_path(cert->host, buf, cert->fingerprint);
482 SSLCertificate *ssl_certificate_find (gchar *host, gushort port, const gchar *fingerprint)
484 return ssl_certificate_find_lookup (host, port, fingerprint, TRUE);
487 SSLCertificate *ssl_certificate_find_lookup (gchar *host, gushort port, const gchar *fingerprint, gboolean lookup)
492 SSLCertificate *cert = NULL;
496 gnutls_x509_crt tmp_x509;
499 gboolean must_rename = FALSE;
502 fqdn_host = get_fqdn(host);
504 fqdn_host = g_strdup(host);
506 buf = g_strdup_printf("%d", port);
508 if (fingerprint != NULL) {
509 file = get_certificate_path(fqdn_host, buf, fingerprint);
510 fp = g_fopen(file, "rb");
513 /* see if we have the old one */
514 debug_print("didn't get %s\n", file);
516 file = get_certificate_path(fqdn_host, buf, NULL);
517 fp = g_fopen(file, "rb");
520 debug_print("got %s\n", file);
521 must_rename = (fingerprint != NULL);
524 debug_print("got %s first try\n", file);
534 if ((tmp_x509 = d2i_X509_fp(fp, 0)) != NULL) {
536 if ((tmp_x509 = gnutls_d2i_X509_fp(fp, 0)) != NULL) {
538 cert = ssl_certificate_new_lookup(tmp_x509, fqdn_host, port, lookup);
539 debug_print("got cert %p\n", cert);
543 gnutls_x509_crt_deinit(tmp_x509);
550 gchar *old = get_certificate_path(fqdn_host, buf, NULL);
551 gchar *new = get_certificate_path(fqdn_host, buf, fingerprint);
552 if (strcmp(old, new))
553 move_file(old, new, TRUE);
563 static gboolean ssl_certificate_compare (SSLCertificate *cert_a, SSLCertificate *cert_b)
566 if (cert_a == NULL || cert_b == NULL)
568 else if (!X509_cmp(cert_a->x509_cert, cert_b->x509_cert))
575 size_t cert_size_a = 0, cert_size_b = 0;
578 if (cert_a == NULL || cert_b == NULL)
581 if ((r = gnutls_x509_crt_export(cert_a->x509_cert, GNUTLS_X509_FMT_DER, NULL, &cert_size_a))
582 != GNUTLS_E_SHORT_MEMORY_BUFFER) {
583 g_warning("couldn't gnutls_x509_crt_export to get size a %s\n", gnutls_strerror(r));
587 if ((r = gnutls_x509_crt_export(cert_b->x509_cert, GNUTLS_X509_FMT_DER, NULL, &cert_size_b))
588 != GNUTLS_E_SHORT_MEMORY_BUFFER) {
589 g_warning("couldn't gnutls_x509_crt_export to get size b %s\n", gnutls_strerror(r));
593 output_a = malloc(cert_size_a);
594 output_b = malloc(cert_size_b);
595 if ((r = gnutls_x509_crt_export(cert_a->x509_cert, GNUTLS_X509_FMT_DER, output_a, &cert_size_a)) < 0) {
596 g_warning("couldn't gnutls_x509_crt_export a %s\n", gnutls_strerror(r));
601 if ((r = gnutls_x509_crt_export(cert_b->x509_cert, GNUTLS_X509_FMT_DER, output_b, &cert_size_b)) < 0) {
602 g_warning("couldn't gnutls_x509_crt_export b %s\n", gnutls_strerror(r));
607 if (cert_size_a != cert_size_b) {
608 g_warning("size differ %zd %zd\n", cert_size_a, cert_size_b);
613 if (memcmp(output_a, output_b, cert_size_a)) {
614 g_warning("contents differ\n");
627 char *ssl_certificate_check_signer (X509 *cert)
629 X509_STORE_CTX store_ctx;
630 X509_STORE *store = SSL_CTX_get_cert_store(ssl_get_ctx());
631 char *err_msg = NULL;
634 g_print("Can't create X509_STORE\n");
638 X509_STORE_CTX_init (&store_ctx, store, cert, NULL);
640 if(!X509_verify_cert (&store_ctx)) {
641 err_msg = g_strdup(X509_verify_cert_error_string(
642 X509_STORE_CTX_get_error(&store_ctx)));
643 debug_print("Can't check signer: %s\n", err_msg);
644 X509_STORE_CTX_cleanup (&store_ctx);
648 X509_STORE_CTX_cleanup (&store_ctx);
652 char *ssl_certificate_check_signer (gnutls_x509_crt cert, guint status)
654 if (status == (guint)-1)
655 return g_strdup(_("Uncheckable"));
657 if (status & GNUTLS_CERT_INVALID) {
658 if (gnutls_x509_crt_check_issuer(cert, cert))
659 return g_strdup(_("Self-signed certificate"));
661 if (status & GNUTLS_CERT_REVOKED)
662 return g_strdup(_("Revoked certificate"));
663 if (status & GNUTLS_CERT_SIGNER_NOT_FOUND)
664 return g_strdup(_("No certificate issuer found"));
665 if (status & GNUTLS_CERT_SIGNER_NOT_CA)
666 return g_strdup(_("Certificate issuer is not a CA"));
674 gboolean ssl_certificate_check (X509 *x509_cert, gchar *fqdn, gchar *host, gushort port)
676 gboolean ssl_certificate_check (gnutls_x509_crt x509_cert, guint status, gchar *fqdn, gchar *host, gushort port)
679 SSLCertificate *current_cert = NULL;
680 SSLCertificate *known_cert;
681 SSLCertHookData cert_hook_data;
682 gchar *fqdn_host = NULL;
689 unsigned char md[128];
692 fqdn_host = g_strdup(fqdn);
694 fqdn_host = get_fqdn(host);
696 g_warning("no host!\n");
700 current_cert = ssl_certificate_new_lookup(x509_cert, fqdn_host, port, FALSE);
702 if (current_cert == NULL) {
703 debug_print("Buggy certificate !\n");
709 current_cert->status = status;
713 X509_digest(x509_cert, EVP_md5(), md, &n);
714 fingerprint = readable_fingerprint(md, (int)n);
717 gnutls_x509_crt_get_fingerprint(x509_cert, GNUTLS_DIG_MD5, md, &n);
718 fingerprint = readable_fingerprint(md, n);
721 known_cert = ssl_certificate_find_lookup (fqdn_host, port, fingerprint, FALSE);
726 if (known_cert == NULL) {
727 cert_hook_data.cert = current_cert;
728 cert_hook_data.old_cert = NULL;
729 cert_hook_data.expired = FALSE;
730 cert_hook_data.accept = FALSE;
732 hooks_invoke(SSLCERT_ASK_HOOKLIST, &cert_hook_data);
734 if (!cert_hook_data.accept) {
735 ssl_certificate_destroy(current_cert);
738 ssl_certificate_save(current_cert);
739 ssl_certificate_destroy(current_cert);
742 } else if (!ssl_certificate_compare (current_cert, known_cert)) {
743 cert_hook_data.cert = current_cert;
744 cert_hook_data.old_cert = known_cert;
745 cert_hook_data.expired = FALSE;
746 cert_hook_data.accept = FALSE;
748 hooks_invoke(SSLCERT_ASK_HOOKLIST, &cert_hook_data);
750 if (!cert_hook_data.accept) {
751 ssl_certificate_destroy(current_cert);
752 ssl_certificate_destroy(known_cert);
755 ssl_certificate_save(current_cert);
756 ssl_certificate_destroy(current_cert);
757 ssl_certificate_destroy(known_cert);
761 } else if (asn1toTime(X509_get_notAfter(current_cert->x509_cert)) < time(NULL)) {
763 } else if (gnutls_x509_crt_get_expiration_time(current_cert->x509_cert) < time(NULL)) {
765 gchar *tmp = g_strdup_printf("%s:%d", current_cert->host, current_cert->port);
767 if (warned_expired == NULL)
768 warned_expired = g_hash_table_new(g_str_hash, g_str_equal);
770 if (g_hash_table_lookup(warned_expired, tmp)) {
772 ssl_certificate_destroy(current_cert);
773 ssl_certificate_destroy(known_cert);
777 cert_hook_data.cert = current_cert;
778 cert_hook_data.old_cert = NULL;
779 cert_hook_data.expired = TRUE;
780 cert_hook_data.accept = FALSE;
782 hooks_invoke(SSLCERT_ASK_HOOKLIST, &cert_hook_data);
784 if (!cert_hook_data.accept) {
786 ssl_certificate_destroy(current_cert);
787 ssl_certificate_destroy(known_cert);
790 g_hash_table_insert(warned_expired, tmp, GINT_TO_POINTER(1));
791 ssl_certificate_destroy(current_cert);
792 ssl_certificate_destroy(known_cert);
797 ssl_certificate_destroy(current_cert);
798 ssl_certificate_destroy(known_cert);
803 X509 *ssl_certificate_get_x509_from_pem_file(const gchar *file)
808 if (is_file_exist(file)) {
809 FILE *fp = g_fopen(file, "r");
811 x509 = PEM_read_X509(fp, NULL, NULL, NULL);
816 log_error(LOG_PROTOCOL, "Can not open certificate file %s\n", file);
821 static int ssl_pkey_password_cb(char *buf, int max_len, int flag, void *pwd)
826 EVP_PKEY *ssl_certificate_get_pkey_from_pem_file(const gchar *file)
828 EVP_PKEY *pkey = NULL;
831 if (is_file_exist(file)) {
832 FILE *fp = g_fopen(file, "r");
834 pkey = PEM_read_PrivateKey(fp, NULL, ssl_pkey_password_cb, NULL);
839 log_error(LOG_PROTOCOL, "Can not open private key file %s\n", file);
844 void ssl_certificate_get_x509_and_pkey_from_p12_file(const gchar *file, const gchar *password,
845 X509 **x509, EVP_PKEY **pkey)
854 if (is_file_exist(file)) {
855 FILE *fp = g_fopen(file, "r");
857 p12 = d2i_PKCS12_fp(fp, NULL);
861 log_error(LOG_PROTOCOL, "Can not open certificate file %s\n", file);
864 if (PKCS12_parse(p12, password, pkey, x509, NULL) == 1) {
865 /* we got the correct password */
868 hooks_invoke(SSL_CERT_GET_PASSWORD, &tmp);
869 if (PKCS12_parse(p12, tmp, pkey, x509, NULL) == 1) {
870 debug_print("got p12\n");
872 log_error(LOG_PROTOCOL, "%s\n", ERR_error_string(ERR_get_error(),NULL));
881 gnutls_x509_crt ssl_certificate_get_x509_from_pem_file(const gchar *file)
883 gnutls_x509_crt x509 = NULL;
887 if (is_file_exist(file)) {
888 FILE *fp = g_fopen(file, "r");
890 x509 = gnutls_d2i_X509_fp(fp, 1);
895 log_error(LOG_PROTOCOL, "Can not open certificate file %s\n", file);
900 gnutls_x509_privkey ssl_certificate_get_pkey_from_pem_file(const gchar *file)
902 gnutls_x509_privkey key = NULL;
906 if (is_file_exist(file)) {
907 FILE *fp = g_fopen(file, "r");
909 key = gnutls_d2i_key_fp(fp, 1);
914 log_error(LOG_PROTOCOL, "Can not open key file %s\n", file);
919 /* From GnuTLS lib/gnutls_x509.c */
921 parse_pkcs12 (gnutls_pkcs12_t p12,
922 const char *password,
923 gnutls_x509_privkey * key,
924 gnutls_x509_crt_t * cert)
926 gnutls_pkcs12_bag bag = NULL;
935 ret = gnutls_pkcs12_bag_init (&bag);
942 ret = gnutls_pkcs12_get_bag (p12, index, bag);
943 if (ret == GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE)
950 ret = gnutls_pkcs12_bag_get_type (bag, 0);
956 if (ret == GNUTLS_BAG_ENCRYPTED)
958 ret = gnutls_pkcs12_bag_decrypt (bag, password);
965 elements_in_bag = gnutls_pkcs12_bag_get_count (bag);
966 if (elements_in_bag < 0)
971 for (i = 0; i < elements_in_bag; i++)
976 type = gnutls_pkcs12_bag_get_type (bag, i);
982 ret = gnutls_pkcs12_bag_get_data (bag, i, &data);
990 case GNUTLS_BAG_PKCS8_ENCRYPTED_KEY:
991 case GNUTLS_BAG_PKCS8_KEY:
992 ret = gnutls_x509_privkey_init (key);
998 ret = gnutls_x509_privkey_import_pkcs8
999 (*key, &data, GNUTLS_X509_FMT_DER, password,
1000 type == GNUTLS_BAG_PKCS8_KEY ? GNUTLS_PKCS_PLAIN : 0);
1007 case GNUTLS_BAG_CERTIFICATE:
1008 ret = gnutls_x509_crt_init (cert);
1015 gnutls_x509_crt_import (*cert, &data, GNUTLS_X509_FMT_DER);
1022 case GNUTLS_BAG_ENCRYPTED:
1023 /* XXX Bother to recurse one level down? Unlikely to
1024 use the same password anyway. */
1025 case GNUTLS_BAG_EMPTY:
1032 gnutls_pkcs12_bag_deinit (bag);
1039 gnutls_pkcs12_bag_deinit (bag);
1043 void ssl_certificate_get_x509_and_pkey_from_p12_file(const gchar *file, const gchar *password,
1044 gnutls_x509_crt *x509, gnutls_x509_privkey *pkey)
1046 gnutls_pkcs12_t p12 = NULL;
1055 if (is_file_exist(file)) {
1056 FILE *fp = g_fopen(file, "r");
1058 p12 = gnutls_d2i_PKCS12_fp(fp, 0);
1062 log_error(LOG_PROTOCOL, "Can not open certificate file %s\n", file);
1065 if ((r = parse_pkcs12(p12, password, pkey, x509)) == 0) {
1066 debug_print("got p12\n");
1068 log_error(LOG_PROTOCOL, "%s\n", gnutls_strerror(r));
1070 gnutls_pkcs12_deinit(p12);
1074 #endif /* USE_OPENSSL */