2008-07-04 [colin] 3.5.0cvs5
[claws.git] / src / common / ssl_certificate.h
1 /*
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
5  *
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.
10  *
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.
15  *
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/>.
18  * 
19  */
20
21 #ifndef __SSL_CERTIFICATE_H__
22 #define __SSL_CERTIFICATE_H__
23
24 #ifdef HAVE_CONFIG_H
25 #  include "config.h"
26 #endif
27
28 #if (defined(USE_OPENSSL) || defined (USE_GNUTLS))
29 #if USE_OPENSSL
30 #include <openssl/ssl.h>
31 #include <openssl/objects.h>
32 #else
33 #include <gnutls/gnutls.h>
34 #include <gnutls/x509.h>
35 #endif
36
37 #include <glib.h>
38
39 #define SSLCERT_ASK_HOOKLIST "sslcert_ask"
40 #define SSLCERT_GET_CLIENT_CERT_HOOKLIST "sslcert_get_client_cert"
41 #define SSL_CERT_GET_PASSWORD "sslcert_get_password"
42
43 typedef struct _SSLCertificate SSLCertificate;
44
45 struct _SSLCertificate
46 {
47 #if USE_OPENSSL
48         X509 *x509_cert;
49 #else
50         gnutls_x509_crt x509_cert;
51 #endif
52         gchar *host;
53         gushort port;
54         gchar *fingerprint;
55 #if USE_GNUTLS
56         guint status;
57 #endif
58 };
59
60 typedef struct _SSLCertHookData SSLCertHookData;
61
62 struct _SSLCertHookData
63 {
64         SSLCertificate *cert;
65         SSLCertificate *old_cert;
66         gboolean expired;
67         gboolean accept;
68 };
69
70 SSLCertificate *ssl_certificate_find (gchar *host, gushort port, const gchar *fingerprint);
71 SSLCertificate *ssl_certificate_find_lookup (gchar *host, gushort port, const gchar *fingerprint, gboolean lookup);
72 #if USE_OPENSSL
73 gboolean ssl_certificate_check (X509 *x509_cert, gchar *fqdn, gchar *host, gushort port);
74 #else
75 gboolean ssl_certificate_check (gnutls_x509_crt x509_cert, guint status, gchar *fqdn, gchar *host, gushort port);
76 #endif
77 void ssl_certificate_destroy(SSLCertificate *cert);
78 void ssl_certificate_delete_from_disk(SSLCertificate *cert);
79 char * readable_fingerprint(unsigned char *src, int len);
80 #if USE_OPENSSL
81 char *ssl_certificate_check_signer (X509 *cert);
82 time_t asn1toTime(ASN1_TIME *asn1Time);
83 #else
84 char *ssl_certificate_check_signer (gnutls_x509_crt cert, guint status);
85 #endif
86
87 #if USE_OPENSSL
88 X509 *ssl_certificate_get_x509_from_pem_file(const gchar *file);
89 EVP_PKEY *ssl_certificate_get_pkey_from_pem_file(const gchar *file);
90 void ssl_certificate_get_x509_and_pkey_from_p12_file(const gchar *file, 
91                         const gchar *password, X509 **x509, EVP_PKEY **pkey);
92 #endif
93 #ifdef USE_GNUTLS
94 gnutls_x509_crt ssl_certificate_get_x509_from_pem_file(const gchar *file);
95 gnutls_x509_privkey ssl_certificate_get_pkey_from_pem_file(const gchar *file);
96 void ssl_certificate_get_x509_and_pkey_from_p12_file(const gchar *file, 
97                         const gchar *password, gnutls_x509_crt *crt, gnutls_x509_privkey *key);
98 size_t gnutls_i2d_X509(gnutls_x509_crt x509_cert, unsigned char **output);
99 size_t gnutls_i2d_PrivateKey(gnutls_x509_privkey pkey, unsigned char **output);
100 #endif
101 #endif /* USE_OPENSSL */
102 #endif /* SSL_CERTIFICATE_H */