comparison libpurple/plugins/ssl/ssl-gnutls.c @ 19494:280c6ec32ca6

- Yet More TODO whacking - Return value checking in x509_common_name and x509_issuer_dn
author William Ehlhardt <williamehlhardt@gmail.com>
date Mon, 20 Aug 2007 03:21:37 +0000
parents e147c3a821dd
children 7589b218f89a
comparison
equal deleted inserted replaced
19493:e147c3a821dd 19494:280c6ec32ca6
794 g_return_val_if_fail(crt, NULL); 794 g_return_val_if_fail(crt, NULL);
795 g_return_val_if_fail(crt->scheme == &x509_gnutls, NULL); 795 g_return_val_if_fail(crt->scheme == &x509_gnutls, NULL);
796 796
797 cert_dat = X509_GET_GNUTLS_DATA(crt); 797 cert_dat = X509_GET_GNUTLS_DATA(crt);
798 798
799 /* TODO: Note return values? */
800
801 /* Figure out the length of the Distinguished Name */ 799 /* Figure out the length of the Distinguished Name */
802 /* Claim that the buffer is size 0 so GnuTLS just tells us how much 800 /* Claim that the buffer is size 0 so GnuTLS just tells us how much
803 space it needs */ 801 space it needs */
804 dn_size = 0; 802 dn_size = 0;
805 gnutls_x509_crt_get_issuer_dn(cert_dat, dn, &dn_size); 803 gnutls_x509_crt_get_issuer_dn(cert_dat, dn, &dn_size);
806 804
807 /* Now allocate and get the Distinguished Name */ 805 /* Now allocate and get the Distinguished Name */
808 dn = g_new0(gchar, dn_size); 806 dn = g_new0(gchar, dn_size);
809 gnutls_x509_crt_get_issuer_dn(cert_dat, dn, &dn_size); 807 if (0 != gnutls_x509_crt_get_issuer_dn(cert_dat, dn, &dn_size)) {
808 purple_debug_error("gnutls/x509",
809 "Failed to get issuer's Distinguished "
810 "Name\n");
811 g_free(dn);
812 return NULL;
813 }
810 814
811 return dn; 815 return dn;
812 } 816 }
813 817
814 static gchar * 818 static gchar *
815 x509_common_name (PurpleCertificate *crt) 819 x509_common_name (PurpleCertificate *crt)
816 { 820 {
817 gnutls_x509_crt_t cert_dat; 821 gnutls_x509_crt_t cert_dat;
818 gchar *cn = NULL; 822 gchar *cn = NULL;
819 size_t cn_size; 823 size_t cn_size;
824 int ret;
820 825
821 g_return_val_if_fail(crt, NULL); 826 g_return_val_if_fail(crt, NULL);
822 g_return_val_if_fail(crt->scheme == &x509_gnutls, NULL); 827 g_return_val_if_fail(crt->scheme == &x509_gnutls, NULL);
823 828
824 cert_dat = X509_GET_GNUTLS_DATA(crt); 829 cert_dat = X509_GET_GNUTLS_DATA(crt);
825 830
826 /* TODO: Note return values? */
827
828 /* Figure out the length of the Common Name */ 831 /* Figure out the length of the Common Name */
829 /* Claim that the buffer is size 0 so GnuTLS just tells us how much 832 /* Claim that the buffer is size 0 so GnuTLS just tells us how much
830 space it needs */ 833 space it needs */
831 cn_size = 0; 834 cn_size = 0;
832 gnutls_x509_crt_get_dn_by_oid(cert_dat, 835 gnutls_x509_crt_get_dn_by_oid(cert_dat,
835 0, /* Not in raw mode */ 838 0, /* Not in raw mode */
836 cn, &cn_size); 839 cn, &cn_size);
837 840
838 /* Now allocate and get the Common Name */ 841 /* Now allocate and get the Common Name */
839 cn = g_new0(gchar, cn_size); 842 cn = g_new0(gchar, cn_size);
840 gnutls_x509_crt_get_dn_by_oid(cert_dat, 843 ret = gnutls_x509_crt_get_dn_by_oid(cert_dat,
841 GNUTLS_OID_X520_COMMON_NAME, 844 GNUTLS_OID_X520_COMMON_NAME,
842 0, /* First CN found, please */ 845 0, /* First CN found, please */
843 0, /* Not in raw mode */ 846 0, /* Not in raw mode */
844 cn, &cn_size); 847 cn, &cn_size);
848 if (ret != 0) {
849 purple_debug_error("gnutls/x509",
850 "Failed to get Common Name\n");
851 g_free(cn);
852 return NULL;
853 }
854
845 855
846 return cn; 856 return cn;
847 } 857 }
848 858
849 static gboolean 859 static gboolean
890 900
891 return TRUE; 901 return TRUE;
892 } 902 }
893 903
894 /* X.509 certificate operations provided by this plugin */ 904 /* X.509 certificate operations provided by this plugin */
895 /* TODO: Flesh this out! */
896 static PurpleCertificateScheme x509_gnutls = { 905 static PurpleCertificateScheme x509_gnutls = {
897 "x509", /* Scheme name */ 906 "x509", /* Scheme name */
898 N_("X.509 Certificates"), /* User-visible scheme name */ 907 N_("X.509 Certificates"), /* User-visible scheme name */
899 x509_import_from_file, /* Certificate import function */ 908 x509_import_from_file, /* Certificate import function */
900 x509_export_certificate, /* Certificate export function */ 909 x509_export_certificate, /* Certificate export function */
937 946
938 /* Init GNUTLS now so others can use it even if sslconn never does */ 947 /* Init GNUTLS now so others can use it even if sslconn never does */
939 ssl_gnutls_init_gnutls(); 948 ssl_gnutls_init_gnutls();
940 949
941 /* Register that we're providing an X.509 CertScheme */ 950 /* Register that we're providing an X.509 CertScheme */
942 /* @TODO : error checking */
943 purple_certificate_register_scheme( &x509_gnutls ); 951 purple_certificate_register_scheme( &x509_gnutls );
944 952
945 return TRUE; 953 return TRUE;
946 #else 954 #else
947 return FALSE; 955 return FALSE;