Created
March 31, 2015 11:06
-
-
Save Ge0/59d7466bb87dcaba4885 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <stdint.h> | |
#include <tls.h> | |
int main(int argc, char** argv) { | |
char buf[8192]; | |
tls_init(); | |
struct tls_config* tlsconf = tls_config_new(); | |
printf("tls_config_set_ciphers(): %d\n", tls_config_set_ciphers(tlsconf, "DEFAULT")); | |
printf("tls_config_set_ca_file(): %d\n", tls_config_set_ca_file(tlsconf, "./rootCA.pem")); | |
tls_config_set_protocols(tlsconf, TLS_PROTOCOL_TLSv1_0|TLS_PROTOCOL_TLSv1_1|TLS_PROTOCOL_TLSv1_2); | |
tls_config_insecure_noverifyhost(tlsconf); | |
tls_config_insecure_noverifycert(tlsconf); | |
struct tls* tlsclient = tls_client(); | |
tls_configure(tlsclient, tlsconf); | |
printf("Status: %d\n", tls_connect(tlsclient, "google.com", "443")); | |
size_t outlen; | |
char req[] = "GET / HTTP/1.1\r\n" | |
"Host: google.com\r\n" | |
"Connection: close\r\n\r\n"; | |
tls_write(tlsclient, req, sizeof(req), &outlen); | |
printf("Written %d bytes.\n", outlen); | |
int ret = tls_read(tlsclient, buf, sizeof(buf)-1, &outlen); | |
while(ret >= 0) { | |
buf[outlen] = '\0'; | |
ret = tls_read(tlsclient, buf, sizeof(buf)-1, &outlen); | |
} | |
tls_close(tlsclient); | |
tls_free(tlsclient); | |
tls_config_free(tlsconf); | |
//tls_quit(); | |
return EXIT_SUCCESS; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment