3 * Copyright (C) 2011 Trend Micro Inc. All rights reserved.
5 * OSSEC HIDS is a free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License (version 2) as
7 * published by the FSF - Free Software Foundation.
9 * Note that this license applies to the source code, as well as
10 * decoders, rules and any other data file included with OSSEC (unless
11 * otherwise specified).
13 * This program is distributed in the hope that it will be useful, but
14 * is provided AS IS, WITHOUT ANY WARRANTY; without even the implied
15 * warranty of MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, and
16 * NON-INFRINGEMENT. See the GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 * In addition, as a special exception, the copyright holders give
22 * permission to link the code of portions of this program with the
23 * OpenSSL library under certain conditions as described in each
24 * individual source file, and distribute linked combinations
27 * You must obey the GNU General Public License in all respects
28 * for all of the code used other than OpenSSL. If you modify
29 * file(s) with this exception, you may extend this exception to your
30 * version of the file(s), but you are not obligated to do so. If you
31 * do not wish to do so, delete this exception statement from your
32 * version. If you delete this exception statement from all source
33 * files in the program, then also delete it here.
37 #include <sys/types.h>
40 #include <sys/param.h>
44 #include <sys/select.h>
45 #include <sys/utsname.h>
57 #include <netinet/in.h>
58 #include <arpa/inet.h>
59 #include <sys/socket.h>
63 #include <openssl/ssl.h>
64 #include <openssl/err.h>
65 #include <openssl/bio.h>
68 #define TEST "GET / HTTP/1.0\r\n\r\n\r\n"
70 int main(int argc, char **argv)
73 int sock = 0, port = 443, ret = 0;
80 struct sockaddr_in addr;
83 while((c = getopt(argc, argv, "h:p:")) != -1)
91 if(port <= 0 || port >= 65536)
105 SSL_load_error_strings();
106 OpenSSL_add_all_algorithms();
107 bio_err = BIO_new_fp(stderr,BIO_NOCLOSE);
110 sslmeth = SSLv23_method();
111 ctx = SSL_CTX_new(sslmeth);
114 printf("CTX ERROR\n");
120 printf("ERROR - host not set.\n");
124 /* Connecting via TCP */
125 sock = socket(AF_INET,SOCK_STREAM, IPPROTO_TCP);
128 printf("sock error\n");
132 memset(&addr,0,sizeof(addr));
133 addr.sin_addr.s_addr = inet_addr(host);
134 addr.sin_family=AF_INET;
135 addr.sin_port=htons(port);
136 if(connect(sock,(struct sockaddr *)&addr, sizeof(addr)) < 0)
138 printf("connect error\n");
144 /* Connecting the SSL socket */
146 sbio = BIO_new_socket(sock, BIO_NOCLOSE);
147 SSL_set_bio(ssl, sbio, sbio);
148 ret = SSL_connect(ssl);
151 printf("SSL connect error\n");
152 ERR_print_errors_fp(stderr);
156 printf("Connected!\n");
159 ret=SSL_write(ssl,TEST, sizeof(TEST));
162 printf("SSL write error\n");
163 ERR_print_errors_fp(stderr);
170 ret = SSL_read(ssl,buf,sizeof(buf) -1);
171 printf("ret: %d\n", ret);
172 switch(SSL_get_error(ssl,ret))
176 printf("no error: %s\n", buf);
178 case SSL_ERROR_ZERO_RETURN:
179 printf("no returen\n");
182 case SSL_ERROR_SYSCALL:
184 "SSL Error: Premature close\n");
188 printf("default error\n");