2 #include <openssl/bio.h>
3 #include <openssl/ssl.h>
4 #include <openssl/err.h>
12 ERR_load_crypto_strings();
13 ERR_load_SSL_strings();
14 SSL_load_error_strings();
24 opensslconnect(char *host)
38 ctx = SSL_CTX_new(SSLv23_client_method());
39 sbio = BIO_new_ssl_connect(ctx);
40 BIO_get_ssl(sbio, &ssl);
41 SSL_set_mode(ssl, SSL_MODE_AUTO_RETRY);
43 snprint(buf, sizeof buf, "%s:https", host);
44 BIO_set_conn_hostname(sbio, buf);
46 if(BIO_do_connect(sbio) <= 0 || BIO_do_handshake(sbio) <= 0){
47 ERR_error_string_n(ERR_get_error(), buf, sizeof buf);
49 werrstr("openssl: %s", buf);
53 pfd = emalloc(sizeof *pfd);
59 opensslclose(Pfd *pfd)
63 BIO_free_all(pfd->sbio);
68 opensslwrite(Pfd *pfd, void *v, int n)
76 if((m = BIO_write(pfd->sbio, p+total, n-total)) <= 0){
87 opensslread(Pfd *pfd, void *v, int n)
89 return BIO_read(pfd->sbio, v, n);