X-Git-Url: http://ftp.carnet.hr/carnet-debian/scm?p=ossec-hids.git;a=blobdiff_plain;f=src%2Fos_auth%2Fssl-test.c;h=b1ad7c7ada3783303a6e32a5803c5419540d6cb3;hp=09146d389064320d9efddeabbaca301892790e39;hb=3f728675941dc69d4e544d3a880a56240a6e394a;hpb=927951d1c1ad45ba9e7325f07d996154a91c911b diff --git a/src/os_auth/ssl-test.c b/src/os_auth/ssl-test.c index 09146d3..b1ad7c7 100644 --- a/src/os_auth/ssl-test.c +++ b/src/os_auth/ssl-test.c @@ -1,6 +1,4 @@ -/* - * - * Copyright (C) 2011 Trend Micro Inc. All rights reserved. +/* Copyright (C) 2011 Trend Micro Inc. All rights reserved. * * OSSEC HIDS is a free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License (version 2) as @@ -38,8 +36,6 @@ #include #include #include - - #include #include #include @@ -59,39 +55,35 @@ #include #include - #include #include #include - #define TEST "GET / HTTP/1.0\r\n\r\n\r\n" + int main(int argc, char **argv) { int c; - int sock = 0, port = 443, ret = 0; - char *host = NULL; + int sock = 0, portnum, ret = 0; + char *host = NULL, *port = "443"; SSL_CTX *ctx; SSL *ssl; SSL_METHOD *sslmeth; BIO *sbio; BIO *bio_err = 0; - struct sockaddr_in addr; - - while((c = getopt(argc, argv, "h:p:")) != -1) - { - switch(c){ + while ((c = getopt(argc, argv, "h:p:")) != -1) { + switch (c) { case 'h': host = optarg; break; case 'p': - port = atoi(optarg); - if(port <= 0 || port >= 65536) - { + portnum = atoi(optarg); + if (portnum <= 0 || portnum >= 65536) { exit(1); } + port = optarg; break; default: exit(1); @@ -99,55 +91,38 @@ int main(int argc, char **argv) } } - if(!bio_err) - { + if (!bio_err) { SSL_library_init(); SSL_load_error_strings(); OpenSSL_add_all_algorithms(); - bio_err = BIO_new_fp(stderr,BIO_NOCLOSE); + bio_err = BIO_new_fp(stderr, BIO_NOCLOSE); } sslmeth = SSLv23_method(); ctx = SSL_CTX_new(sslmeth); - if(!ctx) - { + if (!ctx) { printf("CTX ERROR\n"); exit(1); } - if(!host) - { + if (!host) { printf("ERROR - host not set.\n"); exit(1); } - /* Connecting via TCP */ - sock = socket(AF_INET,SOCK_STREAM, IPPROTO_TCP); - if(sock < 0) - { - printf("sock error\n"); - exit(1); - } - - memset(&addr,0,sizeof(addr)); - addr.sin_addr.s_addr = inet_addr(host); - addr.sin_family=AF_INET; - addr.sin_port=htons(port); - if(connect(sock,(struct sockaddr *)&addr, sizeof(addr)) < 0) - { + /* Connect via TCP */ + sock = OS_ConnectTCP(port, host); + if (sock <= 0) { printf("connect error\n"); exit(1); } - - - /* Connecting the SSL socket */ + /* Connect the SSL socket */ ssl = SSL_new(ctx); sbio = BIO_new_socket(sock, BIO_NOCLOSE); SSL_set_bio(ssl, sbio, sbio); ret = SSL_connect(ssl); - if(ret <= 0) - { + if (ret <= 0) { printf("SSL connect error\n"); ERR_print_errors_fp(stderr); exit(1); @@ -155,42 +130,39 @@ int main(int argc, char **argv) printf("Connected!\n"); - - ret=SSL_write(ssl,TEST, sizeof(TEST)); - if(ret < 0) - { + ret = SSL_write(ssl, TEST, sizeof(TEST)); + if (ret < 0) { printf("SSL write error\n"); ERR_print_errors_fp(stderr); exit(1); } - while(1) - { + while (1) { char buf[2048]; - ret = SSL_read(ssl,buf,sizeof(buf) -1); + ret = SSL_read(ssl, buf, sizeof(buf) - 1); printf("ret: %d\n", ret); - switch(SSL_get_error(ssl,ret)) - { - case SSL_ERROR_NONE: - buf[ret] = '\0'; - printf("no error: %s\n", buf); - break; - case SSL_ERROR_ZERO_RETURN: - printf("no returen\n"); - exit(1); - break; - case SSL_ERROR_SYSCALL: - fprintf(stderr, - "SSL Error: Premature close\n"); - exit(1); - break; - default: - printf("default error\n"); - exit(1); - break; - } + switch (SSL_get_error(ssl, ret)) { + case SSL_ERROR_NONE: + buf[ret] = '\0'; + printf("no error: %s\n", buf); + break; + case SSL_ERROR_ZERO_RETURN: + printf("no return\n"); + exit(1); + break; + case SSL_ERROR_SYSCALL: + fprintf(stderr, + "SSL Error: Premature close\n"); + exit(1); + break; + default: + printf("default error\n"); + exit(1); + break; + } } exit(0); } +