certificate.h

Go to the documentation of this file.
00001 
00008 /*
00009  *
00010  * purple
00011  *
00012  * Purple is the legal property of its developers, whose names are too numerous
00013  * to list here.  Please refer to the COPYRIGHT file distributed with this
00014  * source distribution.
00015  *
00016  * This program is free software; you can redistribute it and/or modify
00017  * it under the terms of the GNU General Public License as published by
00018  * the Free Software Foundation; either version 2 of the License, or
00019  * (at your option) any later version.
00020  *
00021  * This program is distributed in the hope that it will be useful,
00022  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00023  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00024  * GNU General Public License for more details.
00025  *
00026  * You should have received a copy of the GNU General Public License
00027  * along with this program; if not, write to the Free Software
00028  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
00029  */
00030 
00031 #ifndef _PURPLE_CERTIFICATE_H
00032 #define _PURPLE_CERTIFICATE_H
00033 
00034 #include <time.h>
00035 
00036 #include <glib.h>
00037 
00038 #ifdef __cplusplus
00039 extern "C" {
00040 #endif /* __cplusplus */
00041 
00042 
00043 typedef enum
00044 {
00045     PURPLE_CERTIFICATE_INVALID = 0,
00046     PURPLE_CERTIFICATE_VALID = 1
00047 } PurpleCertificateVerificationStatus;
00048 
00049 typedef struct _PurpleCertificate PurpleCertificate;
00050 typedef struct _PurpleCertificatePool PurpleCertificatePool;
00051 typedef struct _PurpleCertificateScheme PurpleCertificateScheme;
00052 typedef struct _PurpleCertificateVerifier PurpleCertificateVerifier;
00053 typedef struct _PurpleCertificateVerificationRequest PurpleCertificateVerificationRequest;
00054 
00060 typedef void (*PurpleCertificateVerifiedCallback)
00061         (PurpleCertificateVerificationStatus st,
00062          gpointer userdata);
00063 
00069 struct _PurpleCertificate
00070 {
00072     PurpleCertificateScheme * scheme;
00074     gpointer data;
00075 };
00076 
00083 struct _PurpleCertificatePool
00084 {
00086     gchar *scheme_name;
00088     gchar *name;
00089 
00095     gchar *fullname;
00096 
00098     gpointer data;
00099 
00107     gboolean (* init)(void);
00108 
00114     void (* uninit)(void);
00115 
00117     gboolean (* cert_in_pool)(const gchar *id);
00119     PurpleCertificate * (* get_cert)(const gchar *id);
00124     gboolean (* put_cert)(const gchar *id, PurpleCertificate *crt);
00126     gboolean (* delete_cert)(const gchar *id);
00127 
00129     GList * (* get_idlist)(void);
00130 
00131     void (*_purple_reserved1)(void);
00132     void (*_purple_reserved2)(void);
00133     void (*_purple_reserved3)(void);
00134     void (*_purple_reserved4)(void);
00135 };
00136 
00145 struct _PurpleCertificateScheme
00146 {
00152     gchar * name;
00153 
00159     gchar * fullname;
00160 
00167     PurpleCertificate * (* import_certificate)(const gchar * filename);
00168 
00177     gboolean (* export_certificate)(const gchar *filename, PurpleCertificate *crt);
00178 
00187     PurpleCertificate * (* copy_certificate)(PurpleCertificate *crt);
00188 
00198     void (* destroy_certificate)(PurpleCertificate * crt);
00199 
00202     gboolean (*signed_by)(PurpleCertificate *crt, PurpleCertificate *issuer);
00210     GByteArray * (* get_fingerprint_sha1)(PurpleCertificate *crt);
00211 
00219     gchar * (* get_unique_id)(PurpleCertificate *crt);
00220 
00228     gchar * (* get_issuer_unique_id)(PurpleCertificate *crt);
00229 
00241     gchar * (* get_subject_name)(PurpleCertificate *crt);
00242 
00248     gboolean (* check_subject_name)(PurpleCertificate *crt, const gchar *name);
00249 
00251     gboolean (* get_times)(PurpleCertificate *crt, time_t *activation, time_t *expiration);
00252 
00259     GSList * (* import_certificates)(const gchar * filename);
00260 
00261     void (*_purple_reserved1)(void);
00262     void (*_purple_reserved2)(void);
00263     void (*_purple_reserved3)(void);
00264 };
00265 
00275 struct _PurpleCertificateVerifier
00276 {
00282     gchar *scheme_name;
00283 
00285     gchar *name;
00286 
00297     void (* start_verification)(PurpleCertificateVerificationRequest *vrq);
00298 
00307     void (* destroy_request)(PurpleCertificateVerificationRequest *vrq);
00308 
00309     void (*_purple_reserved1)(void);
00310     void (*_purple_reserved2)(void);
00311     void (*_purple_reserved3)(void);
00312     void (*_purple_reserved4)(void);
00313 };
00314 
00320 struct _PurpleCertificateVerificationRequest
00321 {
00323     PurpleCertificateVerifier *verifier;
00328     PurpleCertificateScheme *scheme;
00329 
00335     gchar *subject_name;
00336 
00342     GList *cert_chain;
00343 
00345     gpointer data;
00346 
00348     PurpleCertificateVerifiedCallback cb;
00350     gpointer cb_data;
00351 };
00352 
00353 /*****************************************************************************/
00355 /*****************************************************************************/
00381 void
00382 purple_certificate_verify (PurpleCertificateVerifier *verifier,
00383                const gchar *subject_name, GList *cert_chain,
00384                PurpleCertificateVerifiedCallback cb,
00385                gpointer cb_data);
00386 
00394 void
00395 purple_certificate_verify_complete(PurpleCertificateVerificationRequest *vrq,
00396                    PurpleCertificateVerificationStatus st);
00397 
00400 /*****************************************************************************/
00402 /*****************************************************************************/
00411 PurpleCertificate *
00412 purple_certificate_copy(PurpleCertificate *crt);
00413 
00420 GList *
00421 purple_certificate_copy_list(GList *crt_list);
00422 
00428 void
00429 purple_certificate_destroy (PurpleCertificate *crt);
00430 
00436 void
00437 purple_certificate_destroy_list (GList * crt_list);
00438 
00449 gboolean
00450 purple_certificate_signed_by(PurpleCertificate *crt, PurpleCertificate *issuer);
00451 
00470 gboolean
00471 purple_certificate_check_signature_chain_with_failing(GList *chain,
00472         PurpleCertificate **failing);
00473 
00488 gboolean
00489 purple_certificate_check_signature_chain(GList *chain);
00490 
00498 PurpleCertificate *
00499 purple_certificate_import(PurpleCertificateScheme *scheme, const gchar *filename);
00500 
00508 GSList *
00509 purple_certificates_import(PurpleCertificateScheme *scheme, const gchar *filename);
00510 
00518 gboolean
00519 purple_certificate_export(const gchar *filename, PurpleCertificate *crt);
00520 
00521 
00530 GByteArray *
00531 purple_certificate_get_fingerprint_sha1(PurpleCertificate *crt);
00532 
00539 gchar *
00540 purple_certificate_get_unique_id(PurpleCertificate *crt);
00541 
00549 gchar *
00550 purple_certificate_get_issuer_unique_id(PurpleCertificate *crt);
00551 
00561 gchar *
00562 purple_certificate_get_subject_name(PurpleCertificate *crt);
00563 
00570 gboolean
00571 purple_certificate_check_subject_name(PurpleCertificate *crt, const gchar *name);
00572 
00583 gboolean
00584 purple_certificate_get_times(PurpleCertificate *crt, time_t *activation, time_t *expiration);
00585 
00588 /*****************************************************************************/
00590 /*****************************************************************************/
00603 gchar *
00604 purple_certificate_pool_mkpath(PurpleCertificatePool *pool, const gchar *id);
00605 
00615 gboolean
00616 purple_certificate_pool_usable(PurpleCertificatePool *pool);
00617 
00626 PurpleCertificateScheme *
00627 purple_certificate_pool_get_scheme(PurpleCertificatePool *pool);
00628 
00635 gboolean
00636 purple_certificate_pool_contains(PurpleCertificatePool *pool, const gchar *id);
00637 
00644 PurpleCertificate *
00645 purple_certificate_pool_retrieve(PurpleCertificatePool *pool, const gchar *id);
00646 
00657 gboolean
00658 purple_certificate_pool_store(PurpleCertificatePool *pool, const gchar *id, PurpleCertificate *crt);
00659 
00667 gboolean
00668 purple_certificate_pool_delete(PurpleCertificatePool *pool, const gchar *id);
00669 
00677 GList *
00678 purple_certificate_pool_get_idlist(PurpleCertificatePool *pool);
00679 
00685 void
00686 purple_certificate_pool_destroy_idlist(GList *idlist);
00687 
00690 /*****************************************************************************/
00692 /*****************************************************************************/
00698 void
00699 purple_certificate_init(void);
00700 
00704 void
00705 purple_certificate_uninit(void);
00706 
00710 gpointer
00711 purple_certificate_get_handle(void);
00712 
00717 PurpleCertificateScheme *
00718 purple_certificate_find_scheme(const gchar *name);
00719 
00726 GList *
00727 purple_certificate_get_schemes(void);
00728 
00737 gboolean
00738 purple_certificate_register_scheme(PurpleCertificateScheme *scheme);
00739 
00747 gboolean
00748 purple_certificate_unregister_scheme(PurpleCertificateScheme *scheme);
00749 
00755 PurpleCertificateVerifier *
00756 purple_certificate_find_verifier(const gchar *scheme_name, const gchar *ver_name);
00757 
00764 GList *
00765 purple_certificate_get_verifiers(void);
00766 
00773 gboolean
00774 purple_certificate_register_verifier(PurpleCertificateVerifier *vr);
00775 
00782 gboolean
00783 purple_certificate_unregister_verifier(PurpleCertificateVerifier *vr);
00784 
00790 PurpleCertificatePool *
00791 purple_certificate_find_pool(const gchar *scheme_name, const gchar *pool_name);
00792 
00799 GList *
00800 purple_certificate_get_pools(void);
00801 
00808 gboolean
00809 purple_certificate_register_pool(PurpleCertificatePool *pool);
00810 
00817 gboolean
00818 purple_certificate_unregister_pool(PurpleCertificatePool *pool);
00819 
00829 void
00830 purple_certificate_display_x509(PurpleCertificate *crt);
00831 
00837 void purple_certificate_add_ca_search_path(const char *path);
00838 
00839 #ifdef __cplusplus
00840 }
00841 #endif /* __cplusplus */
00842 
00843 #endif /* _PURPLE_CERTIFICATE_H */