int main(int argc, char** argv) { char* host_and_port = argv[1]; char* store_path = "/etc/ssl/certs/"; char store_type = 'd'; char connection_type = 'e'; char buffer[4096]; buffer[0] = 0; BIO* bio; SSL_CTX* ctx = NULL; SSL* ssl = NULL; init_openssl(); if ((bio = connect_encrypted(host_and_port, store_path, store_type, &ctx, &ssl)) == NULL) return (EXIT_FAILURE); HeartbeatMessage * hbmsg = malloc(sizeof(HeartbeatMessage)); hbmsg->type = 1; hbmsg->payload_length = 0xffff; BIO_write(bio,hbmsg,sizeof(HeartbeatMessage)); int err = 0; while(1) { err = BIO_read(bio,buffer,4*1024); if (err <= 0) break; fwrite(buffer,1,err,stdout); fflush(stdout); } return (EXIT_SUCCESS); }
/** * Main SSL demonstration code entry point */ int main(int argc, char** argv) { // char* host_and_port = argv[1]; /* localhost:4422 */ // char* server_request = argv[2]; /* "GET / \r\n\r\n" */ // char* store_path = argv[3]; /* /home/user/projects/sslclient/certificate.pem */ // char store_type = argv[4][0]; /* f = file, anything else is a directory structure */ // char connection_type = argv[5][0]; /* e = encrypted, anything else is unencrypted */ char buffer[4096]; buffer[0] = 0; BIO* bio; SSL_CTX* ctx = NULL; SSL* ssl = NULL; /* initilise the OpenSSL library */ init_openssl(); /* encrypted link */ /* if (connection_type == 'e') { if ((bio = connect_encrypted(host_and_port, store_path, store_type, &ctx, &ssl)) == NULL) return (EXIT_FAILURE); }*/ /* unencrypted link */ //else if ((bio = connect_unencrypted(host_and_port)) == NULL) //return (EXIT_FAILURE); if ((bio = connect_encrypted("127.0.0.1:7543" , &ctx , &ssl)) == NULL) return (EXIT_FAILURE); char* server_request = "GET / \r\n\r\n"; write_to_stream(bio, server_request, strlen(server_request)); read_from_stream(bio, buffer, 4096); printf("%s\r\n", buffer); if (close_connection(bio) == 0) return (EXIT_FAILURE); /* clean up the SSL context resources for the encrypted link */ //if (connection_type == 'e') SSL_CTX_free(ctx); return (EXIT_SUCCESS); }