diff options
Diffstat (limited to 'src/daemon/https/tls/gnutls_x509.c')
-rw-r--r-- | src/daemon/https/tls/gnutls_x509.c | 38 |
1 files changed, 34 insertions, 4 deletions
diff --git a/src/daemon/https/tls/gnutls_x509.c b/src/daemon/https/tls/gnutls_x509.c index 35322db4..22ced8ce 100644 --- a/src/daemon/https/tls/gnutls_x509.c +++ b/src/daemon/https/tls/gnutls_x509.c | |||
@@ -42,7 +42,10 @@ | |||
42 | #include <debug.h> | 42 | #include <debug.h> |
43 | #include <x509_b64.h> | 43 | #include <x509_b64.h> |
44 | #include <gnutls_x509.h> | 44 | #include <gnutls_x509.h> |
45 | #include <read-file.h> | 45 | #include <sys/types.h> |
46 | #include <sys/stat.h> | ||
47 | #include <fcntl.h> | ||
48 | |||
46 | 49 | ||
47 | /* x509 */ | 50 | /* x509 */ |
48 | #include "common.h" | 51 | #include "common.h" |
@@ -602,6 +605,33 @@ read_key_mem (mhd_gtls_cert_credentials_t res, | |||
602 | return 0; | 605 | return 0; |
603 | } | 606 | } |
604 | 607 | ||
608 | static char * | ||
609 | read_file (const char *filename, size_t * length) | ||
610 | { | ||
611 | struct stat st; | ||
612 | char *out; | ||
613 | int fd; | ||
614 | |||
615 | fd = open (filename, O_RDONLY); | ||
616 | if (-1 == fd) | ||
617 | return NULL; | ||
618 | if (0 != fstat(fd, &st)) | ||
619 | goto ERR; | ||
620 | out = malloc(st.st_size); | ||
621 | if (out == NULL) | ||
622 | goto ERR; | ||
623 | if (st.st_size != read(fd, out, st.st_size)) | ||
624 | { | ||
625 | free(out); | ||
626 | goto ERR; | ||
627 | } | ||
628 | close(fd); | ||
629 | return out; | ||
630 | ERR: | ||
631 | close(fd); | ||
632 | return NULL; | ||
633 | } | ||
634 | |||
605 | /* Reads a certificate file | 635 | /* Reads a certificate file |
606 | */ | 636 | */ |
607 | static int | 637 | static int |
@@ -610,7 +640,7 @@ read_cert_file (mhd_gtls_cert_credentials_t res, | |||
610 | { | 640 | { |
611 | int ret; | 641 | int ret; |
612 | size_t size; | 642 | size_t size; |
613 | char *data = read_binary_file (certfile, &size); | 643 | char *data = read_file (certfile, &size); |
614 | 644 | ||
615 | if (data == NULL) | 645 | if (data == NULL) |
616 | { | 646 | { |
@@ -636,7 +666,7 @@ read_key_file (mhd_gtls_cert_credentials_t res, | |||
636 | { | 666 | { |
637 | int ret; | 667 | int ret; |
638 | size_t size; | 668 | size_t size; |
639 | char *data = read_binary_file (keyfile, &size); | 669 | char *data = read_file (keyfile, &size); |
640 | 670 | ||
641 | if (data == NULL) | 671 | if (data == NULL) |
642 | { | 672 | { |
@@ -1080,7 +1110,7 @@ MHD_gnutls_certificate_set_x509_trust_file (mhd_gtls_cert_credentials_t | |||
1080 | { | 1110 | { |
1081 | int ret, ret2; | 1111 | int ret, ret2; |
1082 | size_t size; | 1112 | size_t size; |
1083 | unsigned char *data = (unsigned char*) read_binary_file (cafile, &size); | 1113 | unsigned char *data = (unsigned char*) read_file (cafile, &size); |
1084 | 1114 | ||
1085 | if (data == NULL) | 1115 | if (data == NULL) |
1086 | { | 1116 | { |