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     
00253     void (*_purple_reserved1)(void);
00254     void (*_purple_reserved2)(void);
00255     void (*_purple_reserved3)(void);
00256     void (*_purple_reserved4)(void);
00257 };
00258 
00268 struct _PurpleCertificateVerifier
00269 {
00275     gchar *scheme_name;
00276 
00278     gchar *name;
00279     
00290     void (* start_verification)(PurpleCertificateVerificationRequest *vrq);
00291 
00300     void (* destroy_request)(PurpleCertificateVerificationRequest *vrq);
00301 
00302     void (*_purple_reserved1)(void);
00303     void (*_purple_reserved2)(void);
00304     void (*_purple_reserved3)(void);
00305     void (*_purple_reserved4)(void);
00306 };
00307 
00313 struct _PurpleCertificateVerificationRequest
00314 {
00316     PurpleCertificateVerifier *verifier;
00321     PurpleCertificateScheme *scheme;
00322 
00328     gchar *subject_name;
00329     
00335     GList *cert_chain;
00336     
00338     gpointer data;
00339 
00341     PurpleCertificateVerifiedCallback cb;
00343     gpointer cb_data;
00344 };
00345 
00346 /*****************************************************************************/
00348 /*****************************************************************************/
00374 void
00375 purple_certificate_verify (PurpleCertificateVerifier *verifier,
00376                const gchar *subject_name, GList *cert_chain,
00377                PurpleCertificateVerifiedCallback cb,
00378                gpointer cb_data);
00379 
00387 void
00388 purple_certificate_verify_complete(PurpleCertificateVerificationRequest *vrq,
00389                    PurpleCertificateVerificationStatus st);
00390 
00393 /*****************************************************************************/
00395 /*****************************************************************************/
00404 PurpleCertificate *
00405 purple_certificate_copy(PurpleCertificate *crt);
00406 
00413 GList *
00414 purple_certificate_copy_list(GList *crt_list);
00415 
00421 void
00422 purple_certificate_destroy (PurpleCertificate *crt);
00423 
00429 void
00430 purple_certificate_destroy_list (GList * crt_list);
00431 
00442 gboolean
00443 purple_certificate_signed_by(PurpleCertificate *crt, PurpleCertificate *issuer);
00444 
00457 gboolean
00458 purple_certificate_check_signature_chain(GList *chain);
00459 
00467 PurpleCertificate *
00468 purple_certificate_import(PurpleCertificateScheme *scheme, const gchar *filename);
00469 
00477 gboolean
00478 purple_certificate_export(const gchar *filename, PurpleCertificate *crt);
00479 
00480 
00489 GByteArray *
00490 purple_certificate_get_fingerprint_sha1(PurpleCertificate *crt);
00491 
00498 gchar *
00499 purple_certificate_get_unique_id(PurpleCertificate *crt);
00500 
00508 gchar *
00509 purple_certificate_get_issuer_unique_id(PurpleCertificate *crt);
00510 
00520 gchar *
00521 purple_certificate_get_subject_name(PurpleCertificate *crt);
00522 
00529 gboolean
00530 purple_certificate_check_subject_name(PurpleCertificate *crt, const gchar *name);
00531 
00542 gboolean
00543 purple_certificate_get_times(PurpleCertificate *crt, time_t *activation, time_t *expiration);
00544 
00547 /*****************************************************************************/
00549 /*****************************************************************************/
00562 gchar *
00563 purple_certificate_pool_mkpath(PurpleCertificatePool *pool, const gchar *id);
00564 
00574 gboolean
00575 purple_certificate_pool_usable(PurpleCertificatePool *pool);
00576 
00585 PurpleCertificateScheme *
00586 purple_certificate_pool_get_scheme(PurpleCertificatePool *pool);
00587 
00594 gboolean
00595 purple_certificate_pool_contains(PurpleCertificatePool *pool, const gchar *id);
00596 
00603 PurpleCertificate *
00604 purple_certificate_pool_retrieve(PurpleCertificatePool *pool, const gchar *id);
00605 
00616 gboolean
00617 purple_certificate_pool_store(PurpleCertificatePool *pool, const gchar *id, PurpleCertificate *crt);
00618 
00626 gboolean
00627 purple_certificate_pool_delete(PurpleCertificatePool *pool, const gchar *id);
00628 
00636 GList *
00637 purple_certificate_pool_get_idlist(PurpleCertificatePool *pool);
00638 
00644 void
00645 purple_certificate_pool_destroy_idlist(GList *idlist);
00646 
00649 /*****************************************************************************/
00651 /*****************************************************************************/
00657 void
00658 purple_certificate_init(void);
00659 
00663 void
00664 purple_certificate_uninit(void);
00665 
00669 gpointer
00670 purple_certificate_get_handle(void);
00671 
00676 PurpleCertificateScheme *
00677 purple_certificate_find_scheme(const gchar *name);
00678 
00685 GList *
00686 purple_certificate_get_schemes(void);
00687 
00696 gboolean
00697 purple_certificate_register_scheme(PurpleCertificateScheme *scheme);
00698 
00706 gboolean
00707 purple_certificate_unregister_scheme(PurpleCertificateScheme *scheme);
00708 
00714 PurpleCertificateVerifier *
00715 purple_certificate_find_verifier(const gchar *scheme_name, const gchar *ver_name);
00716 
00723 GList *
00724 purple_certificate_get_verifiers(void);
00725 
00732 gboolean
00733 purple_certificate_register_verifier(PurpleCertificateVerifier *vr);
00734 
00741 gboolean
00742 purple_certificate_unregister_verifier(PurpleCertificateVerifier *vr);
00743 
00749 PurpleCertificatePool *
00750 purple_certificate_find_pool(const gchar *scheme_name, const gchar *pool_name);
00751 
00758 GList *
00759 purple_certificate_get_pools(void);
00760 
00767 gboolean
00768 purple_certificate_register_pool(PurpleCertificatePool *pool);
00769 
00776 gboolean
00777 purple_certificate_unregister_pool(PurpleCertificatePool *pool);
00778 
00788 void
00789 purple_certificate_display_x509(PurpleCertificate *crt);
00790 
00796 void purple_certificate_add_ca_search_path(const char *path);
00797 
00798 #ifdef __cplusplus
00799 }
00800 #endif /* __cplusplus */
00801 
00802 #endif /* _PURPLE_CERTIFICATE_H */