ssl_certificate.h (2688B)
1 /* 2 * Claws Mail -- a GTK based, lightweight, and fast e-mail client 3 * Copyright (C) 1999-2012 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 #include <gnutls/gnutls.h> 25 #include <gnutls/x509.h> 26 27 #include <glib.h> 28 29 #define SSLCERT_ASK_HOOKLIST "sslcert_ask" 30 #define SSLCERT_GET_CLIENT_CERT_HOOKLIST "sslcert_get_client_cert" 31 #define SSL_CERT_GET_PASSWORD "sslcert_get_password" 32 33 typedef struct _SSLCertificate SSLCertificate; 34 35 struct _SSLCertificate 36 { 37 gnutls_x509_crt_t x509_cert; 38 gchar *host; 39 gushort port; 40 gchar *fingerprint; 41 guint status; 42 }; 43 44 typedef struct _SSLCertHookData SSLCertHookData; 45 46 struct _SSLCertHookData 47 { 48 SSLCertificate *cert; 49 SSLCertificate *old_cert; 50 gboolean expired; 51 gboolean accept; 52 }; 53 54 SSLCertificate *ssl_certificate_find (const gchar *host, gushort port, const gchar *fingerprint); 55 gboolean ssl_certificate_check (gnutls_x509_crt_t x509_cert, guint status, const gchar *host, gushort port, gboolean accept_if_valid); 56 gboolean ssl_certificate_check_chain(gnutls_x509_crt_t *certs, gint chain_len, const gchar *host, gushort port, gboolean accept_if_valid); 57 void ssl_certificate_destroy(SSLCertificate *cert); 58 void ssl_certificate_delete_from_disk(SSLCertificate *cert); 59 char * readable_fingerprint(unsigned char *src, int len); 60 char *ssl_certificate_check_signer (SSLCertificate *cert, guint status); 61 62 gnutls_x509_crt_t ssl_certificate_get_x509_from_pem_file(const gchar *file); 63 gnutls_x509_privkey_t ssl_certificate_get_pkey_from_pem_file(const gchar *file); 64 void ssl_certificate_get_x509_and_pkey_from_p12_file(const gchar *file, 65 const gchar *password, gnutls_x509_crt_t *crt, gnutls_x509_privkey_t *key); 66 size_t gnutls_i2d_X509(gnutls_x509_crt_t x509_cert, unsigned char **output); 67 size_t gnutls_i2d_PrivateKey(gnutls_x509_privkey_t pkey, unsigned char **output); 68 gboolean ssl_certificate_check_subject_cn(SSLCertificate *cert); 69 gchar *ssl_certificate_get_subject_cn(SSLCertificate *cert); 70 #endif /* SSL_CERTIFICATE_H */