aboutsummaryrefslogtreecommitdiffstats
path: root/src/charon/lib/crypto/x509.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/charon/lib/crypto/x509.c')
-rwxr-xr-xsrc/charon/lib/crypto/x509.c43
1 files changed, 11 insertions, 32 deletions
diff --git a/src/charon/lib/crypto/x509.c b/src/charon/lib/crypto/x509.c
index 86a595618..91f9f191e 100755
--- a/src/charon/lib/crypto/x509.c
+++ b/src/charon/lib/crypto/x509.c
@@ -28,13 +28,11 @@
#include "x509.h"
#include <daemon.h>
-#include <asn1/asn1.h>
#include <asn1/oid.h>
+#include <asn1/asn1.h>
+#include <asn1/pem.h>
#include <utils/logger_manager.h>
-typedef const char *err_t; /* error message, or NULL for success */
-
-
#define BUF_LEN 512
#define RSA_MIN_OCTETS (512 / 8)
#define RSA_MIN_OCTETS_UGH "RSA modulus too small for security: less than 512 bits"
@@ -905,33 +903,14 @@ x509_t *x509_create_from_chunk(chunk_t chunk)
*/
x509_t *x509_create_from_file(char *filename)
{
- struct stat stb;
- FILE *file;
- char *buffer;
- chunk_t chunk;
-
- if (stat(filename, &stb) == -1)
- {
- return NULL;
- }
-
- buffer = alloca(stb.st_size);
-
- file = fopen(filename, "r");
- if (file == NULL)
- {
- return NULL;
- }
-
- if (fread(buffer, stb.st_size, 1, file) == -1)
- {
- fclose(file);
+ bool pgp = FALSE;
+ chunk_t chunk = CHUNK_INITIALIZER;
+ x509_t *cert = NULL;
+
+ if (!pem_asn1_load_file(filename, "", "certificate", &chunk, &pgp))
return NULL;
- }
- fclose(file);
-
- chunk.ptr = buffer;
- chunk.len = stb.st_size;
-
- return x509_create_from_chunk(chunk);
+
+ cert = x509_create_from_chunk(chunk);
+ free(chunk.ptr);
+ return cert;
}