932affe8d5a52c806d05f96b8d9108f41a2a9c5b
[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
41 typedef struct _SSLCertificate SSLCertificate;
42
43 struct _SSLCertificate
44 {
45 #if USE_OPENSSL
46         X509 *x509_cert;
47 #else
48         gnutls_x509_crt x509_cert;
49 #endif
50         gchar *host;
51         gushort port;
52         gchar *fingerprint;
53 #if USE_GNUTLS
54         guint status;
55 #endif
56 };
57
58 typedef struct _SSLCertHookData SSLCertHookData;
59
60 struct _SSLCertHookData
61 {
62         SSLCertificate *cert;
63         SSLCertificate *old_cert;
64         gboolean expired;
65         gboolean accept;
66 };
67
68 SSLCertificate *ssl_certificate_find (gchar *host, gushort port, const gchar *fingerprint);
69 SSLCertificate *ssl_certificate_find_lookup (gchar *host, gushort port, const gchar *fingerprint, gboolean lookup);
70 #if USE_OPENSSL
71 gboolean ssl_certificate_check (X509 *x509_cert, gchar *fqdn, gchar *host, gushort port);
72 #else
73 gboolean ssl_certificate_check (gnutls_x509_crt x509_cert, guint status, gchar *fqdn, gchar *host, gushort port);
74 #endif
75 void ssl_certificate_destroy(SSLCertificate *cert);
76 void ssl_certificate_delete_from_disk(SSLCertificate *cert);
77 char * readable_fingerprint(unsigned char *src, int len);
78 #if USE_OPENSSL
79 char *ssl_certificate_check_signer (X509 *cert);
80 time_t asn1toTime(ASN1_TIME *asn1Time);
81 #else
82 char *ssl_certificate_check_signer (gnutls_x509_crt cert, guint status);
83 #endif
84
85 #endif /* USE_OPENSSL */
86 #endif /* SSL_CERTIFICATE_H */