Mercurial > pidgin
comparison libpurple/plugins/ssl/ssl-gnutls.c @ 32819:2c6510167895 default tip
propagate from branch 'im.pidgin.pidgin.2.x.y' (head 3315c5dfbd0ad16511bdcf865e5b07c02d07df24)
to branch 'im.pidgin.pidgin' (head cbd1eda6bcbf0565ae7766396bb8f6f419cb6a9a)
author | Elliott Sales de Andrade <qulogic@pidgin.im> |
---|---|
date | Sat, 02 Jun 2012 02:30:49 +0000 |
parents | 298080cecdc5 |
children |
comparison
equal
deleted
inserted
replaced
32818:01ff09d4a463 | 32819:2c6510167895 |
---|---|
1140 } | 1140 } |
1141 | 1141 |
1142 return success; | 1142 return success; |
1143 } | 1143 } |
1144 | 1144 |
1145 static GByteArray * | |
1146 x509_get_der_data(PurpleCertificate *crt) | |
1147 { | |
1148 gnutls_x509_crt crt_dat; | |
1149 GByteArray *data; | |
1150 size_t len; | |
1151 int ret; | |
1152 | |
1153 crt_dat = X509_GET_GNUTLS_DATA(crt); | |
1154 g_return_val_if_fail(crt_dat, NULL); | |
1155 | |
1156 /* Obtain the output size required */ | |
1157 len = 0; | |
1158 ret = gnutls_x509_crt_export(crt_dat, GNUTLS_X509_FMT_DER, NULL, &len); | |
1159 g_return_val_if_fail(ret == GNUTLS_E_SHORT_MEMORY_BUFFER, NULL); | |
1160 | |
1161 /* Now allocate a buffer and *really* export it */ | |
1162 data = g_byte_array_sized_new(len); | |
1163 data->len = len; | |
1164 ret = gnutls_x509_crt_export(crt_dat, GNUTLS_X509_FMT_DER, data->data, &len); | |
1165 if (ret != 0) { | |
1166 purple_debug_error("gnutls/x509", | |
1167 "Failed to export cert to buffer with code %d\n", | |
1168 ret); | |
1169 g_byte_array_free(data, TRUE); | |
1170 return NULL; | |
1171 } | |
1172 | |
1173 return data; | |
1174 } | |
1175 | |
1176 static gchar * | |
1177 x509_display_string(PurpleCertificate *crt) | |
1178 { | |
1179 gchar *sha_asc; | |
1180 GByteArray *sha_bin; | |
1181 gchar *cn; | |
1182 time_t activation, expiration; | |
1183 gchar *activ_str, *expir_str; | |
1184 gchar *text; | |
1185 | |
1186 /* Pull out the SHA1 checksum */ | |
1187 sha_bin = x509_sha1sum(crt); | |
1188 sha_asc = purple_base16_encode_chunked(sha_bin->data, sha_bin->len); | |
1189 | |
1190 /* Get the cert Common Name */ | |
1191 /* TODO: Will break on CA certs */ | |
1192 cn = x509_common_name(crt); | |
1193 | |
1194 /* Get the certificate times */ | |
1195 /* TODO: Check the times against localtime */ | |
1196 /* TODO: errorcheck? */ | |
1197 if (!x509_times(crt, &activation, &expiration)) { | |
1198 purple_debug_error("certificate", | |
1199 "Failed to get certificate times!\n"); | |
1200 activation = expiration = 0; | |
1201 } | |
1202 activ_str = g_strdup(ctime(&activation)); | |
1203 expir_str = g_strdup(ctime(&expiration)); | |
1204 | |
1205 /* Make messages */ | |
1206 text = g_strdup_printf(_("Common name: %s\n\n" | |
1207 "Fingerprint (SHA1): %s\n\n" | |
1208 "Activation date: %s\n" | |
1209 "Expiration date: %s\n"), | |
1210 cn ? cn : "(null)", | |
1211 sha_asc ? sha_asc : "(null)", | |
1212 activ_str ? activ_str : "(null)", | |
1213 expir_str ? expir_str : "(null)"); | |
1214 | |
1215 /* Cleanup */ | |
1216 g_free(cn); | |
1217 g_free(sha_asc); | |
1218 g_free(activ_str); | |
1219 g_free(expir_str); | |
1220 g_byte_array_free(sha_bin, TRUE); | |
1221 | |
1222 return text; | |
1223 } | |
1224 | |
1145 /* X.509 certificate operations provided by this plugin */ | 1225 /* X.509 certificate operations provided by this plugin */ |
1146 static PurpleCertificateScheme x509_gnutls = { | 1226 static PurpleCertificateScheme x509_gnutls = { |
1147 "x509", /* Scheme name */ | 1227 "x509", /* Scheme name */ |
1148 N_("X.509 Certificates"), /* User-visible scheme name */ | 1228 N_("X.509 Certificates"), /* User-visible scheme name */ |
1149 x509_import_from_file, /* Certificate import function */ | 1229 x509_import_from_file, /* Certificate import function */ |
1156 x509_issuer_dn, /* Issuer Unique ID */ | 1236 x509_issuer_dn, /* Issuer Unique ID */ |
1157 x509_common_name, /* Subject name */ | 1237 x509_common_name, /* Subject name */ |
1158 x509_check_name, /* Check subject name */ | 1238 x509_check_name, /* Check subject name */ |
1159 x509_times, /* Activation/Expiration time */ | 1239 x509_times, /* Activation/Expiration time */ |
1160 x509_importcerts_from_file, /* Multiple certificates import function */ | 1240 x509_importcerts_from_file, /* Multiple certificates import function */ |
1161 | 1241 x509_get_der_data, /* Binary DER data */ |
1162 NULL, | 1242 x509_display_string, /* Display representation */ |
1163 NULL, | 1243 |
1164 NULL | 1244 NULL |
1165 | 1245 |
1166 }; | 1246 }; |
1167 | 1247 |
1168 static PurpleSslOps ssl_ops = | 1248 static PurpleSslOps ssl_ops = |