|
Matthew Barnes |
cf6100 |
--- evolution-data-server-1.10.1/camel/camel-tcp-stream-ssl.c.camel-certdb-nss-cert-get 2007-04-09 08:42:48.000000000 -0400
|
|
Matthew Barnes |
cf6100 |
+++ evolution-data-server-1.10.1/camel/camel-tcp-stream-ssl.c 2007-05-09 21:41:38.000000000 -0400
|
|
Matthew Barnes |
cf6100 |
@@ -679,63 +679,47 @@
|
|
Matthew Barnes |
cf6100 |
CamelCert *
|
|
Matthew Barnes |
cf6100 |
camel_certdb_nss_cert_get(CamelCertDB *certdb, CERTCertificate *cert)
|
|
Matthew Barnes |
cf6100 |
{
|
|
Matthew Barnes |
cf6100 |
- char *fingerprint, *path;
|
|
Matthew Barnes |
cf6100 |
+ char *fingerprint;
|
|
Matthew Barnes |
cf6100 |
CamelCert *ccert;
|
|
Matthew Barnes |
cf6100 |
- struct stat st;
|
|
Matthew Barnes |
cf6100 |
- size_t nread;
|
|
Matthew Barnes |
cf6100 |
- ssize_t n;
|
|
Matthew Barnes |
cf6100 |
- int fd;
|
|
Matthew Barnes |
cf6100 |
-
|
|
Matthew Barnes |
cf6100 |
+
|
|
Matthew Barnes |
cf6100 |
fingerprint = cert_fingerprint (cert);
|
|
Matthew Barnes |
cf6100 |
ccert = camel_certdb_get_cert (certdb, fingerprint);
|
|
Matthew Barnes |
cf6100 |
if (ccert == NULL) {
|
|
Matthew Barnes |
cf6100 |
g_free (fingerprint);
|
|
Matthew Barnes |
cf6100 |
return ccert;
|
|
Matthew Barnes |
cf6100 |
}
|
|
Matthew Barnes |
cf6100 |
-
|
|
Matthew Barnes |
cf6100 |
+
|
|
Matthew Barnes |
cf6100 |
if (ccert->rawcert == NULL) {
|
|
Matthew Barnes |
cf6100 |
-#ifndef G_OS_WIN32
|
|
Matthew Barnes |
cf6100 |
- path = g_strdup_printf ("%s/.camel_certs/%s", getenv ("HOME"), fingerprint);
|
|
Matthew Barnes |
cf6100 |
-#else
|
|
Matthew Barnes |
cf6100 |
- path = g_build_filename (g_get_home_dir (), ".camel_certs", fingerprint, NULL);
|
|
Matthew Barnes |
cf6100 |
-#endif
|
|
Matthew Barnes |
cf6100 |
- if (g_stat (path, &st) == -1
|
|
Matthew Barnes |
cf6100 |
- || (fd = g_open (path, O_RDONLY | O_BINARY, 0)) == -1) {
|
|
Matthew Barnes |
cf6100 |
- g_warning ("could not load cert %s: %s", path, strerror (errno));
|
|
Matthew Barnes |
cf6100 |
- g_free (fingerprint);
|
|
Matthew Barnes |
cf6100 |
- g_free (path);
|
|
Matthew Barnes |
cf6100 |
- camel_cert_set_trust (certdb, ccert, CAMEL_CERT_TRUST_UNKNOWN);
|
|
Matthew Barnes |
cf6100 |
+ GByteArray *array;
|
|
Matthew Barnes |
cf6100 |
+ gchar *filename;
|
|
Matthew Barnes |
cf6100 |
+ gchar *contents;
|
|
Matthew Barnes |
cf6100 |
+ gsize length;
|
|
Matthew Barnes |
cf6100 |
+ GError *error = NULL;
|
|
Matthew Barnes |
cf6100 |
+
|
|
Matthew Barnes |
cf6100 |
+ filename = g_build_filename (
|
|
Matthew Barnes |
cf6100 |
+ g_get_home_dir (), ".camel_certs", fingerprint, NULL);
|
|
Matthew Barnes |
cf6100 |
+ g_file_get_contents (filename, &contents, &length, &error);
|
|
Matthew Barnes |
cf6100 |
+ if (error != NULL) {
|
|
Matthew Barnes |
cf6100 |
+ g_warning (
|
|
Matthew Barnes |
cf6100 |
+ "Could not load cert %s: %s",
|
|
Matthew Barnes |
cf6100 |
+ filename, error->message);
|
|
Matthew Barnes |
cf6100 |
+ g_error_free (error);
|
|
Matthew Barnes |
cf6100 |
+
|
|
Matthew Barnes |
cf6100 |
+ camel_cert_set_trust (
|
|
Matthew Barnes |
cf6100 |
+ certdb, ccert, CAMEL_CERT_TRUST_UNKNOWN);
|
|
Matthew Barnes |
cf6100 |
camel_certdb_touch (certdb);
|
|
Matthew Barnes |
cf6100 |
-
|
|
Matthew Barnes |
cf6100 |
- return ccert;
|
|
Matthew Barnes |
cf6100 |
- }
|
|
Matthew Barnes |
cf6100 |
- g_free(path);
|
|
Matthew Barnes |
cf6100 |
-
|
|
Matthew Barnes |
cf6100 |
- ccert->rawcert = g_byte_array_new ();
|
|
Matthew Barnes |
cf6100 |
- g_byte_array_set_size (ccert->rawcert, st.st_size);
|
|
Matthew Barnes |
cf6100 |
-
|
|
Matthew Barnes |
cf6100 |
- nread = 0;
|
|
Matthew Barnes |
cf6100 |
- do {
|
|
Matthew Barnes |
cf6100 |
- do {
|
|
Matthew Barnes |
cf6100 |
- n = read (fd, ccert->rawcert->data + nread, st.st_size - nread);
|
|
Matthew Barnes |
cf6100 |
- } while (n == -1 && errno == EINTR);
|
|
Matthew Barnes |
cf6100 |
-
|
|
Matthew Barnes |
cf6100 |
- if (n > 0)
|
|
Matthew Barnes |
cf6100 |
- nread += n;
|
|
Matthew Barnes |
cf6100 |
- } while (nread < st.st_size && n != -1);
|
|
Matthew Barnes |
cf6100 |
-
|
|
Matthew Barnes |
cf6100 |
- close (fd);
|
|
Matthew Barnes |
cf6100 |
-
|
|
Matthew Barnes |
cf6100 |
- if (nread != st.st_size) {
|
|
Matthew Barnes |
cf6100 |
- g_warning ("cert size read truncated %s: %u != %ld", path, nread, st.st_size);
|
|
Matthew Barnes |
cf6100 |
- g_byte_array_free(ccert->rawcert, TRUE);
|
|
Matthew Barnes |
cf6100 |
- ccert->rawcert = NULL;
|
|
Matthew Barnes |
cf6100 |
- g_free(fingerprint);
|
|
Matthew Barnes |
cf6100 |
- camel_cert_set_trust(certdb, ccert, CAMEL_CERT_TRUST_UNKNOWN);
|
|
Matthew Barnes |
cf6100 |
- camel_certdb_touch(certdb);
|
|
Matthew Barnes |
cf6100 |
+ g_free (fingerprint);
|
|
Matthew Barnes |
cf6100 |
+ g_free (filename);
|
|
Matthew Barnes |
cf6100 |
|
|
Matthew Barnes |
cf6100 |
return ccert;
|
|
Matthew Barnes |
cf6100 |
}
|
|
Matthew Barnes |
cf6100 |
+ g_free (filename);
|
|
Matthew Barnes |
cf6100 |
+
|
|
Matthew Barnes |
cf6100 |
+ array = g_byte_array_sized_new (length);
|
|
Matthew Barnes |
cf6100 |
+ g_byte_array_append (array, (guint8 *) contents, length);
|
|
Matthew Barnes |
cf6100 |
+ g_free (contents);
|
|
Matthew Barnes |
cf6100 |
+
|
|
Matthew Barnes |
cf6100 |
+ ccert->rawcert = array;
|
|
Matthew Barnes |
cf6100 |
}
|
|
Matthew Barnes |
cf6100 |
|
|
Matthew Barnes |
cf6100 |
g_free(fingerprint);
|