return 1;
}
W3_Library_Init();
- struct W3* w3 = W3_Create(false, argv[1], 80);
+ struct W3* w3 = W3_Create(true, argv[1], 443);
}
struct W3* W3_Create(bool ssl, const char* hostname, int port){
__W3_Debug("Create", "Creating a struct");
struct W3* w3 = malloc(sizeof(*w3));
- w3->sock = __W3_DNS_Connect(hostname, ssl, port);
+ w3->sock = __W3_DNS_Connect(hostname, ssl, port
+#ifdef SSL_SUPPORT
+ ,
+ &w3->ssl,
+ &w3->ssl_ctx
+#endif
+ );
return w3;
}
#include <stdbool.h>
#include <unistd.h>
-int __W3_DNS_Connect(const char* hostname, bool ssl, uint16_t port){
+#ifdef SSL_SUPPORT
+#include <openssl/ssl.h>
+#endif
+
+int __W3_DNS_Connect(const char* hostname, bool ssl, uint16_t port
+#ifdef SSL_SUPPORT
+ ,
+ void** o_ssl,
+ void** o_ctx
+#endif
+){
__W3_Debug("DNS-Connect", "Resolving");
struct addrinfo hints;
struct addrinfo* result;
return -1; /* Failed to connect */
}
__W3_Debug("Connect", "Conencted");
+#ifdef SSL_SUPPORT
+ if(ssl){
+ __W3_Debug("SSL", "Initializing");
+ const SSL_METHOD* method = TLSv1_2_client_method();
+ *o_ctx = SSL_CTX_new(method);
+ *o_ssl = SSL_new(*o_ctx);
+ SSL_set_fd(*o_ssl, sock);
+ if(SSL_connect(*o_ssl) != 1){
+ SSL_CTX_free(*o_ctx);
+ SSL_free(*o_ssl);
+ *o_ctx = NULL;
+ *o_ssl = NULL;
+ close(sock);
+ sock = -1;
+
+ }else{
+ __W3_Debug("SSL", "Connected");
+ }
+ }
+#endif
+ return sock;
}
#include <stdint.h>
#include <stdbool.h>
-int __W3_DNS_Connect(const char* hostname, bool ssl, uint16_t port);
+int __W3_DNS_Connect(const char* hostname, bool ssl, uint16_t port
+#ifdef SSL_SUPPORT
+ ,
+ void** o_ssl,
+ void** o_ctx
+#endif
+);
#endif