diff options
author | cinap_lenrek <cinap_lenrek@localhost> | 2011-05-03 09:56:35 +0000 |
---|---|---|
committer | cinap_lenrek <cinap_lenrek@localhost> | 2011-05-03 09:56:35 +0000 |
commit | 3a742c699f6806c1145aea5149bf15de15a0afd7 (patch) | |
tree | a5e78c8189a2c13e2d122afd9c4cb76f4a13858a /sys/src/ape/lib/openssl/demos/maurice/loadkeys.c | |
parent | bfc9eceaa64730e0d6912b0251d323f5c0c2e813 (diff) |
add zlib, bzlib and openssl ape ports
Diffstat (limited to 'sys/src/ape/lib/openssl/demos/maurice/loadkeys.c')
-rw-r--r-- | sys/src/ape/lib/openssl/demos/maurice/loadkeys.c | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/sys/src/ape/lib/openssl/demos/maurice/loadkeys.c b/sys/src/ape/lib/openssl/demos/maurice/loadkeys.c new file mode 100644 index 000000000..82fd22a95 --- /dev/null +++ b/sys/src/ape/lib/openssl/demos/maurice/loadkeys.c @@ -0,0 +1,72 @@ +/* NOCW */ +/* + Please read the README file for condition of use, before + using this software. + + Maurice Gittens <mgittens@gits.nl> January 1997 + +*/ + +#include <unistd.h> +#include <stdio.h> +#include <netinet/in.h> +#include <fcntl.h> +#include <strings.h> +#include <stdlib.h> + +#include <openssl/rsa.h> +#include <openssl/evp.h> +#include <openssl/objects.h> +#include <openssl/x509.h> +#include <openssl/err.h> +#include <openssl/pem.h> +#include <openssl/ssl.h> + +EVP_PKEY * ReadPublicKey(const char *certfile) +{ + FILE *fp = fopen (certfile, "r"); + X509 *x509; + EVP_PKEY *pkey; + + if (!fp) + return NULL; + + x509 = PEM_read_X509(fp, NULL, 0, NULL); + + if (x509 == NULL) + { + ERR_print_errors_fp (stderr); + return NULL; + } + + fclose (fp); + + pkey=X509_extract_key(x509); + + X509_free(x509); + + if (pkey == NULL) + ERR_print_errors_fp (stderr); + + return pkey; +} + +EVP_PKEY *ReadPrivateKey(const char *keyfile) +{ + FILE *fp = fopen(keyfile, "r"); + EVP_PKEY *pkey; + + if (!fp) + return NULL; + + pkey = PEM_read_PrivateKey(fp, NULL, 0, NULL); + + fclose (fp); + + if (pkey == NULL) + ERR_print_errors_fp (stderr); + + return pkey; +} + + |