int socket_switch2ssl(Socket_T S, Ssl_T ssl) { if(! (S->ssl= new_ssl_connection(NULL, ssl.version))) return FALSE; if(! embed_ssl_socket(S->ssl, S->socket)) return FALSE; if(ssl.certmd5 && !check_ssl_md5sum(S->ssl, ssl.certmd5)) { LogError("md5sum of certificate does not match!"); return FALSE; } return TRUE; }
/** * Open a socket against hostname:port with the given protocol. * This socket is sent through a ssl connection. * The protocol is normaly either SOCK_STREAM or SOCK_DGRAM. * @param hostname The host to open a socket at * @param port The port number to connect to * @param protocol Socket protocol to use (SOCK_STREAM|SOCK_DGRAM) * @param sslversion Version of the ssl layer auto, SSLv3, SSLv2 or TLS * @return The ssl connection or NULL if an error occured. */ ssl_connection *create_ssl_socket(char *hostname, int port, int protocol, int sslversion) { #ifdef HAVE_OPENSSL int socket; ssl_connection *ssl = new_ssl_connection(NULL, sslversion); ASSERT(hostname); if (!ssl_initilized) { start_ssl(); } if((socket= create_socket(hostname, port, protocol, NET_TIMEOUT)) == -1) { log("%s: create_ssl_socket(): Cannot connect!\n", prog); goto sslerror; } if (! embed_ssl_socket(ssl, socket)) { goto sslerror; } return ssl; sslerror: return NULL; #else return NULL; #endif }