1 /* Copyright (C) 2011 Trend Micro Inc. All rights reserved.
3 * OSSEC HIDS is a free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License (version 2) as
5 * published by the FSF - Free Software Foundation.
7 * Note that this license applies to the source code, as well as
8 * decoders, rules and any other data file included with OSSEC (unless
9 * otherwise specified).
11 * This program is distributed in the hope that it will be useful, but
12 * is provided AS IS, WITHOUT ANY WARRANTY; without even the implied
13 * warranty of MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, and
14 * NON-INFRINGEMENT. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 * In addition, as a special exception, the copyright holders give
20 * permission to link the code of portions of this program with the
21 * OpenSSL library under certain conditions as described in each
22 * individual source file, and distribute linked combinations
25 * You must obey the GNU General Public License in all respects
26 * for all of the code used other than OpenSSL. If you modify
27 * file(s) with this exception, you may extend this exception to your
28 * version of the file(s), but you are not obligated to do so. If you
29 * do not wish to do so, delete this exception statement from your
30 * version. If you delete this exception statement from all source
31 * files in the program, then also delete it here.
35 #include <sys/types.h>
38 #include <sys/param.h>
40 #include <sys/select.h>
41 #include <sys/utsname.h>
53 #include <netinet/in.h>
54 #include <arpa/inet.h>
55 #include <sys/socket.h>
58 #include <openssl/ssl.h>
59 #include <openssl/err.h>
60 #include <openssl/bio.h>
62 #define TEST "GET / HTTP/1.0\r\n\r\n\r\n"
65 int main(int argc, char **argv)
68 int sock = 0, portnum, ret = 0;
69 char *host = NULL, *port = "443";
76 while ((c = getopt(argc, argv, "h:p:")) != -1) {
82 portnum = atoi(optarg);
83 if (portnum <= 0 || portnum >= 65536) {
96 SSL_load_error_strings();
97 OpenSSL_add_all_algorithms();
98 bio_err = BIO_new_fp(stderr, BIO_NOCLOSE);
101 sslmeth = SSLv23_method();
102 ctx = SSL_CTX_new(sslmeth);
104 printf("CTX ERROR\n");
109 printf("ERROR - host not set.\n");
113 /* Connect via TCP */
114 sock = OS_ConnectTCP(port, host);
116 printf("connect error\n");
120 /* Connect the SSL socket */
122 sbio = BIO_new_socket(sock, BIO_NOCLOSE);
123 SSL_set_bio(ssl, sbio, sbio);
124 ret = SSL_connect(ssl);
126 printf("SSL connect error\n");
127 ERR_print_errors_fp(stderr);
131 printf("Connected!\n");
133 ret = SSL_write(ssl, TEST, sizeof(TEST));
135 printf("SSL write error\n");
136 ERR_print_errors_fp(stderr);
142 ret = SSL_read(ssl, buf, sizeof(buf) - 1);
143 printf("ret: %d\n", ret);
144 switch (SSL_get_error(ssl, ret)) {
147 printf("no error: %s\n", buf);
149 case SSL_ERROR_ZERO_RETURN:
150 printf("no return\n");
153 case SSL_ERROR_SYSCALL:
155 "SSL Error: Premature close\n");
159 printf("default error\n");