Mercurial > pidgin
comparison libpurple/plugins/ssl/ssl-gnutls.c @ 18977:31bdbb82de7e
- Add purple_certificate_export and associated libpurple stuff
- Add certificate export support to GnuTLS x509 scheme
author | William Ehlhardt <williamehlhardt@gmail.com> |
---|---|
date | Fri, 29 Jun 2007 04:23:39 +0000 |
parents | 146907cd3b07 |
children | daeca1b9ebdb |
comparison
equal
deleted
inserted
replaced
18976:22481079895a | 18977:31bdbb82de7e |
---|---|
482 g_free(buf); | 482 g_free(buf); |
483 | 483 |
484 return crt; | 484 return crt; |
485 } | 485 } |
486 | 486 |
487 /** | |
488 * Exports a PEM-formatted X.509 certificate to the specified file. | |
489 * @param filename Filename to export to. Format will be PEM | |
490 * @param crt Certificate to export | |
491 * | |
492 * @return TRUE if success, otherwise FALSE | |
493 */ | |
494 static gboolean | |
495 x509_export_certificate(const gchar *filename, PurpleCertificate *crt) | |
496 { | |
497 gnutls_x509_crt_t crt_dat; /* GnuTLS cert struct */ | |
498 int ret; | |
499 gchar * out_buf; /* Data to output */ | |
500 size_t out_size; /* Output size */ | |
501 gboolean success = FALSE; | |
502 | |
503 /* Paranoia paranoia paranoia! */ | |
504 g_return_val_if_fail(filename, FALSE); | |
505 g_return_val_if_fail(crt, FALSE); | |
506 g_return_val_if_fail(crt->scheme == &x509_gnutls, FALSE); | |
507 g_return_val_if_fail(crt->data, FALSE); | |
508 | |
509 crt_dat = *( (gnutls_x509_crt_t *) crt->data); | |
510 | |
511 /* Obtain the output size required */ | |
512 ret = gnutls_x509_crt_export(crt_dat, GNUTLS_X509_FMT_PEM, | |
513 NULL, /* Provide no buffer yet */ | |
514 &out_size /* Put size here */ | |
515 ); | |
516 g_return_val_if_fail(ret == 0, FALSE); | |
517 | |
518 /* Now allocate a buffer and *really* export it */ | |
519 out_buf = g_new0(gchar, out_size); | |
520 ret = gnutls_x509_crt_export(crt_dat, GNUTLS_X509_FMT_PEM, | |
521 out_buf, /* Export to our new buffer */ | |
522 &out_size /* Put size here */ | |
523 ); | |
524 if (ret != 0) { | |
525 purple_debug_error("gnutls/x509", | |
526 "Failed to export cert to buffer with code %d\n", | |
527 ret); | |
528 g_free(out_buf); | |
529 return FALSE; | |
530 } | |
531 | |
532 /* Write it out to an actual file */ | |
533 success = purple_util_write_data_to_file(filename, | |
534 out_buf, | |
535 out_size); | |
536 | |
537 | |
538 g_free(out_buf); | |
539 g_return_val_if_fail(success, FALSE); | |
540 return success; | |
541 } | |
542 | |
487 /** Frees a Certificate | 543 /** Frees a Certificate |
488 * | 544 * |
489 * Destroys a Certificate's internal data structures and frees the pointer | 545 * Destroys a Certificate's internal data structures and frees the pointer |
490 * given. | 546 * given. |
491 * @param crt Certificate instance to be destroyed. It WILL NOT be destroyed | 547 * @param crt Certificate instance to be destroyed. It WILL NOT be destroyed |
655 /* TODO: Flesh this out! */ | 711 /* TODO: Flesh this out! */ |
656 static PurpleCertificateScheme x509_gnutls = { | 712 static PurpleCertificateScheme x509_gnutls = { |
657 "x509", /* Scheme name */ | 713 "x509", /* Scheme name */ |
658 N_("X.509 Certificates"), /* User-visible scheme name */ | 714 N_("X.509 Certificates"), /* User-visible scheme name */ |
659 x509_import_from_file, /* Certificate import function */ | 715 x509_import_from_file, /* Certificate import function */ |
716 x509_export_certificate, /* Certificate export function */ | |
660 x509_destroy_certificate, /* Destroy cert */ | 717 x509_destroy_certificate, /* Destroy cert */ |
661 x509_sha1sum, /* SHA1 fingerprint */ | 718 x509_sha1sum, /* SHA1 fingerprint */ |
662 NULL, /* Subject */ | 719 NULL, /* Subject */ |
663 NULL, /* Unique ID */ | 720 NULL, /* Unique ID */ |
664 NULL, /* Issuer Unique ID */ | 721 NULL, /* Issuer Unique ID */ |