]>
Commit | Line | Data |
---|---|---|
d02b48c6 RE |
1 | /* NOCW */ |
2 | /* | |
3 | Please read the README file for condition of use, before | |
4 | using this software. | |
5 | ||
6 | Maurice Gittens <mgittens@gits.nl> January 1997 | |
7 | ||
8 | */ | |
9 | ||
10 | #include <unistd.h> | |
11 | #include <stdio.h> | |
12 | #include <netinet/in.h> | |
13 | #include <fcntl.h> | |
14 | #include <strings.h> | |
15 | #include <stdlib.h> | |
16 | ||
ec577822 BM |
17 | #include <openssl/rsa.h> |
18 | #include <openssl/evp.h> | |
19 | #include <openssl/objects.h> | |
20 | #include <openssl/x509.h> | |
21 | #include <openssl/err.h> | |
22 | #include <openssl/pem.h> | |
23 | #include <openssl/ssl.h> | |
d02b48c6 RE |
24 | |
25 | EVP_PKEY * ReadPublicKey(const char *certfile) | |
26 | { | |
27 | FILE *fp = fopen (certfile, "r"); | |
28 | X509 *x509; | |
29 | EVP_PKEY *pkey; | |
30 | ||
31 | if (!fp) | |
32 | return NULL; | |
33 | ||
cb7fd76f | 34 | x509 = PEM_read_X509(fp, NULL, 0, NULL); |
d02b48c6 RE |
35 | |
36 | if (x509 == NULL) | |
37 | { | |
38 | ERR_print_errors_fp (stderr); | |
39 | return NULL; | |
40 | } | |
41 | ||
42 | fclose (fp); | |
43 | ||
44 | pkey=X509_extract_key(x509); | |
45 | ||
46 | X509_free(x509); | |
47 | ||
48 | if (pkey == NULL) | |
49 | ERR_print_errors_fp (stderr); | |
50 | ||
51 | return pkey; | |
52 | } | |
53 | ||
54 | EVP_PKEY *ReadPrivateKey(const char *keyfile) | |
55 | { | |
56 | FILE *fp = fopen(keyfile, "r"); | |
57 | EVP_PKEY *pkey; | |
58 | ||
59 | if (!fp) | |
60 | return NULL; | |
61 | ||
cb7fd76f | 62 | pkey = PEM_read_PrivateKey(fp, NULL, 0, NULL); |
d02b48c6 RE |
63 | |
64 | fclose (fp); | |
65 | ||
66 | if (pkey == NULL) | |
67 | ERR_print_errors_fp (stderr); | |
68 | ||
69 | return pkey; | |
70 | } | |
71 | ||
72 |