1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ 2 /* 3 * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) 4 * 5 * This library is free software: you can redistribute it and/or modify it 6 * under the terms of the GNU Lesser General Public License as published by 7 * the Free Software Foundation. 8 * 9 * This library is distributed in the hope that it will be useful, but 10 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 11 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 12 * for more details. 13 * 14 * You should have received a copy of the GNU Lesser General Public License 15 * along with this library. If not, see <http://www.gnu.org/licenses/>. 16 * 17 * Authors: Jeffrey Stedfast <fejj@ximian.com> 18 */ 19 20 #if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION) 21 #error "Only <camel/camel.h> can be included directly." 22 #endif 23 24 #ifndef CAMEL_CERTDB_H 25 #define CAMEL_CERTDB_H 26 27 #include <stdio.h> 28 #include <glib-object.h> 29 30 /* Standard GObject macros */ 31 #define CAMEL_TYPE_CERTDB \ 32 (camel_certdb_get_type ()) 33 #define CAMEL_CERTDB(obj) \ 34 (G_TYPE_CHECK_INSTANCE_CAST \ 35 ((obj), CAMEL_TYPE_CERTDB, CamelCertDB)) 36 #define CAMEL_CERTDB_CLASS(cls) \ 37 (G_TYPE_CHECK_CLASS_CAST \ 38 ((cls), CAMEL_TYPE_CERTDB, CamelCertDBClass)) 39 #define CAMEL_IS_CERTDB(obj) \ 40 (G_TYPE_CHECK_INSTANCE_TYPE \ 41 ((obj), CAMEL_TYPE_CERTDB)) 42 #define CAMEL_IS_CERTDB_CLASS(cls) \ 43 (G_TYPE_CHECK_CLASS_TYPE \ 44 ((cls), CAMEL_TYPE_CERTDB)) 45 #define CAMEL_CERTDB_GET_CLASS(obj) \ 46 (G_TYPE_INSTANCE_GET_CLASS \ 47 ((obj), CAMEL_TYPE_CERTDB, CamelCertDBClass)) 48 49 G_BEGIN_DECLS 50 51 typedef struct _CamelCertDB CamelCertDB; 52 typedef struct _CamelCertDBClass CamelCertDBClass; 53 typedef struct _CamelCertDBPrivate CamelCertDBPrivate; 54 55 typedef enum { 56 CAMEL_CERT_TRUST_UNKNOWN, 57 CAMEL_CERT_TRUST_NEVER, 58 CAMEL_CERT_TRUST_MARGINAL, 59 CAMEL_CERT_TRUST_FULLY, 60 CAMEL_CERT_TRUST_ULTIMATE, 61 CAMEL_CERT_TRUST_TEMPORARY 62 } CamelCertTrust; 63 64 typedef struct { 65 volatile gint refcount; 66 67 gchar *issuer; 68 gchar *subject; 69 gchar *hostname; 70 gchar *fingerprint; 71 72 CamelCertTrust trust; 73 GBytes *rawcert; /* loaded on demand, with camel_cert_load_cert_file() */ 74 } CamelCert; 75 76 struct _CamelCertDB { 77 GObject parent; 78 CamelCertDBPrivate *priv; 79 }; 80 81 struct _CamelCertDBClass { 82 GObjectClass parent_class; 83 84 gint (*header_load) (CamelCertDB *certdb, 85 FILE *istream); 86 gint (*header_save) (CamelCertDB *certdb, 87 FILE *ostream); 88 89 CamelCert * (*cert_load) (CamelCertDB *certdb, 90 FILE *istream); 91 gint (*cert_save) (CamelCertDB *certdb, 92 CamelCert *cert, 93 FILE *ostream); 94 95 /* Padding for future expansion */ 96 gpointer reserved[20]; 97 }; 98 99 GType camel_cert_get_type (void) G_GNUC_CONST; 100 CamelCert * camel_cert_new (void); 101 CamelCert * camel_cert_ref (CamelCert *cert); 102 void camel_cert_unref (CamelCert *cert); 103 gboolean camel_cert_load_cert_file (CamelCert *cert, 104 GError **error); 105 gboolean camel_cert_save_cert_file (CamelCert *cert, 106 const GByteArray *der_data, 107 GError **error); 108 109 GType camel_certdb_get_type (void) G_GNUC_CONST; 110 CamelCertDB * camel_certdb_new (void); 111 void camel_certdb_set_default (CamelCertDB *certdb); 112 CamelCertDB * camel_certdb_get_default (void); 113 void camel_certdb_set_filename (CamelCertDB *certdb, 114 const gchar *filename); 115 gint camel_certdb_load (CamelCertDB *certdb); 116 gint camel_certdb_save (CamelCertDB *certdb); 117 void camel_certdb_touch (CamelCertDB *certdb); 118 119 /* The lookup key was changed from fingerprint to hostname to fix bug 606181. */ 120 121 /* Get the certificate for the given hostname, if any. */ 122 CamelCert * camel_certdb_get_host (CamelCertDB *certdb, 123 const gchar *hostname, 124 const gchar *fingerprint); 125 126 /* Store cert for cert->hostname, replacing any existing certificate for the 127 * same hostname. */ 128 void camel_certdb_put (CamelCertDB *certdb, 129 CamelCert *cert); 130 131 /* Remove any user-accepted certificate for the given hostname. */ 132 void camel_certdb_remove_host (CamelCertDB *certdb, 133 const gchar *hostname, 134 const gchar *fingerprint); 135 136 void camel_certdb_clear (CamelCertDB *certdb); 137 138 GSList * camel_certdb_list_certs (CamelCertDB *certdb); 139 140 G_END_DECLS 141 142 #endif /* CAMEL_CERTDB_H */ 143