repo: tlswrap action: commit revision: path_from: revision_from: 966bd9ebdcf38b1964b01ca174668a3c267666d3: path_to: revision_to:
commit 966bd9ebdcf38b1964b01ca174668a3c267666d3 Author: epochDate: Mon Feb 28 01:44:39 2022 +0000 first diff --git a/Makefile b/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..7aa4ae06750169a947c4c699759af5520a2ce377 --- /dev/null +++ b/Makefile @@ -0,0 +1,3 @@ +sslwrap: CFLAGS=-pedantic -Wall +sslwrap: LDLIBS=-lssl -lcrypto +sslwrap: sslwrap.c diff --git a/sslwrap.c b/sslwrap.c new file mode 100644 index 0000000000000000000000000000000000000000..c4b338d7d183ed52dec5f25f98f3b85032c4decb --- /dev/null +++ b/sslwrap.c @@ -0,0 +1,264 @@ +#include +#include +#include +#include +#include +#include + +//#define FORCE_SNI + +int ssl_init(void) { +#if OPENSSL_VERSION_NUMBER>=0x10100000L + OPENSSL_init_ssl( + OPENSSL_INIT_LOAD_SSL_STRINGS + | OPENSSL_INIT_LOAD_CRYPTO_STRINGS + | OPENSSL_INIT_LOAD_CONFIG + , NULL); +#else + OPENSSL_config(NULL); + SSL_load_error_strings(); + SSL_library_init(); +#endif + return 0; +} + +void ssl_deinit() { + EVP_cleanup(); +} + +const char *servername; + +char *X509_NAME2text(X509_NAME *name) { + char *text; + BIO *bio; + int n; + bio=BIO_new(BIO_s_mem()); + if(!bio) + return 0; + X509_NAME_print_ex(bio, name, 0, + XN_FLAG_ONELINE & ~ASN1_STRFLGS_ESC_MSB & ~XN_FLAG_SPC_EQ); + n=BIO_pending(bio); + text=malloc((size_t)n+1); + n=BIO_read(bio, text, n); + if(n<0) { + BIO_free(bio); + free(text); + return 0; + } + text[n]='\0'; + BIO_free(bio); + return text; +} + +int convert_ASN1TIME(ASN1_TIME *t, char* buf, size_t len) +{ + int rc; + BIO *b = BIO_new(BIO_s_mem()); + rc = ASN1_TIME_print(b, t); + if (rc <= 0) { + BIO_free(b); + return EXIT_FAILURE; + } + rc = BIO_gets(b, buf, (int)len);//BIO_gets uses int for len I guess. + if (rc <= 0) { + BIO_free(b); + return EXIT_FAILURE; + } + BIO_free(b); + return EXIT_SUCCESS; +} + +void hex_encode(unsigned char *readbuf,void *writebuf, size_t len) { + for(size_t i=0;i -----END OF PAGE-----