forked from enlightenment/efl
parent
2b247bc166
commit
cde6146361
|
@ -116,11 +116,9 @@ eet_identity_open(const char *certificate_file,
|
||||||
#ifdef HAVE_SIGNATURE
|
#ifdef HAVE_SIGNATURE
|
||||||
/* Signature declarations */
|
/* Signature declarations */
|
||||||
Eet_Key *key = NULL;
|
Eet_Key *key = NULL;
|
||||||
FILE *fp = NULL;
|
|
||||||
# ifdef HAVE_GNUTLS
|
# ifdef HAVE_GNUTLS
|
||||||
/* Gnutls private declarations */
|
/* Gnutls private declarations */
|
||||||
int fd = -1;
|
Eina_File *f;
|
||||||
struct stat st;
|
|
||||||
void *data = NULL;
|
void *data = NULL;
|
||||||
gnutls_datum_t load_file = { NULL, 0 };
|
gnutls_datum_t load_file = { NULL, 0 };
|
||||||
char pass[1024];
|
char pass[1024];
|
||||||
|
@ -138,59 +136,47 @@ eet_identity_open(const char *certificate_file,
|
||||||
goto on_error;
|
goto on_error;
|
||||||
|
|
||||||
/* Mmap certificate_file */
|
/* Mmap certificate_file */
|
||||||
if (!(fp = fopen(certificate_file, "r")))
|
f = eina_file_open(certificate_file, 0);
|
||||||
goto on_error;
|
if (!f)
|
||||||
|
|
||||||
if ((fd = fileno(fp)) == -1)
|
|
||||||
goto on_error;
|
|
||||||
|
|
||||||
if (fstat(fd, &st))
|
|
||||||
goto on_error;
|
goto on_error;
|
||||||
|
|
||||||
/* let's make mmap safe and just get 0 pages for IO erro */
|
/* let's make mmap safe and just get 0 pages for IO erro */
|
||||||
eina_mmap_safety_enabled_set(EINA_TRUE);
|
eina_mmap_safety_enabled_set(EINA_TRUE);
|
||||||
|
|
||||||
if ((data =
|
data = eina_file_map_all(f, EINA_FILE_SEQUENTIAL);
|
||||||
mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0)) == MAP_FAILED)
|
if (!data) goto on_error;
|
||||||
goto on_error;
|
|
||||||
|
|
||||||
/* Import the certificate in Eet_Key structure */
|
/* Import the certificate in Eet_Key structure */
|
||||||
load_file.data = data;
|
load_file.data = data;
|
||||||
load_file.size = st.st_size;
|
load_file.size = eina_file_size_get(f);;
|
||||||
if (gnutls_x509_crt_import(key->certificate, &load_file,
|
if (gnutls_x509_crt_import(key->certificate, &load_file,
|
||||||
GNUTLS_X509_FMT_PEM) < 0)
|
GNUTLS_X509_FMT_PEM) < 0)
|
||||||
goto on_error;
|
goto on_error;
|
||||||
|
|
||||||
if (munmap(data, st.st_size))
|
eina_file_map_free(f, data);
|
||||||
goto on_error;
|
|
||||||
|
|
||||||
/* Reset values */
|
/* Reset values */
|
||||||
fclose(fp);
|
eina_file_close(f);
|
||||||
fp = NULL;
|
f = NULL;
|
||||||
data = NULL;
|
data = NULL;
|
||||||
load_file.data = NULL;
|
load_file.data = NULL;
|
||||||
load_file.size = 0;
|
load_file.size = 0;
|
||||||
|
|
||||||
/* Mmap private_key_file */
|
/* Mmap private_key_file */
|
||||||
if (!(fp = fopen(private_key_file, "r")))
|
f = eina_file_open(private_key_file, 0);
|
||||||
goto on_error;
|
if (!f)
|
||||||
|
|
||||||
if ((fd = fileno(fp)) == -1)
|
|
||||||
goto on_error;
|
|
||||||
|
|
||||||
if (fstat(fd, &st))
|
|
||||||
goto on_error;
|
goto on_error;
|
||||||
|
|
||||||
/* let's make mmap safe and just get 0 pages for IO erro */
|
/* let's make mmap safe and just get 0 pages for IO erro */
|
||||||
eina_mmap_safety_enabled_set(EINA_TRUE);
|
eina_mmap_safety_enabled_set(EINA_TRUE);
|
||||||
|
|
||||||
if ((data =
|
data = eina_file_map_all(f, EINA_FILE_SEQUENTIAL);
|
||||||
mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0)) == MAP_FAILED)
|
if (!data)
|
||||||
goto on_error;
|
goto on_error;
|
||||||
|
|
||||||
/* Import the private key in Eet_Key structure */
|
/* Import the private key in Eet_Key structure */
|
||||||
load_file.data = data;
|
load_file.data = data;
|
||||||
load_file.size = st.st_size;
|
load_file.size = eina_file_size_get(f);;
|
||||||
/* Try to directly import the PEM encoded private key */
|
/* Try to directly import the PEM encoded private key */
|
||||||
if (gnutls_x509_privkey_import(key->private_key, &load_file,
|
if (gnutls_x509_privkey_import(key->private_key, &load_file,
|
||||||
GNUTLS_X509_FMT_PEM) < 0)
|
GNUTLS_X509_FMT_PEM) < 0)
|
||||||
|
@ -210,16 +196,14 @@ eet_identity_open(const char *certificate_file,
|
||||||
goto on_error;
|
goto on_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (munmap(data, st.st_size))
|
eina_file_map_free(f, data);
|
||||||
goto on_error;
|
eina_file_close(f);
|
||||||
|
|
||||||
fclose(fp);
|
|
||||||
|
|
||||||
return key;
|
return key;
|
||||||
|
|
||||||
on_error:
|
on_error:
|
||||||
if (fp)
|
if (data) eina_file_map_free(f, data);
|
||||||
fclose(fp);
|
if (f) eina_file_close(f);
|
||||||
|
|
||||||
if (key)
|
if (key)
|
||||||
{
|
{
|
||||||
|
@ -232,11 +216,9 @@ on_error:
|
||||||
free(key);
|
free(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data)
|
|
||||||
munmap(data, st.st_size);
|
|
||||||
|
|
||||||
# else /* ifdef HAVE_GNUTLS */
|
# else /* ifdef HAVE_GNUTLS */
|
||||||
/* Openssl private declarations */
|
/* Openssl private declarations */
|
||||||
|
FILE *fp;
|
||||||
EVP_PKEY *pkey = NULL;
|
EVP_PKEY *pkey = NULL;
|
||||||
X509 *cert = NULL;
|
X509 *cert = NULL;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue