Exemplo n.º 1
0
int main (int argc, char *argv[]) {
	ELF_LOADED_SIG
	int  msock;			/* master server socket		*/
	int  ssock;			/* master server socket		*/
	int  portN;			/* port number to listen */
	/*if (argc != 2) {
		usage (argv[0]);
	}
	portN = atoi (argv[1]);*/
	portN = 10000;
	msock = serversock (SOCK_STREAM, portN, 5);

	struct sockaddr_in fromAddr;	/* the from address of a client	*/
	unsigned int  fromAddrLen;		/* from-address length          */
	fromAddrLen = sizeof (fromAddr);
	printf ("Waiting for connection\n");
	ssock = accept (msock, (struct sockaddr *) &fromAddr, &fromAddrLen);
	if (ssock < 0) {
		if (errno != EINTR) {
			errmesg ("accept error\n");
		}
	}
	printf ("Connection recv'd\n");
	while (doServer (ssock) > 0) {};

	close (ssock);
	close (msock);
	
	return 0;
} // end fn main
Exemplo n.º 2
0
int main (int argc, char *argv[]) {
	ELF_LOADED_SIG
	
	SSL_library_init ();
	SSL_load_error_strings ();
	SSL_METHOD *meth = TLSv1_method ();
	SSL_CTX *ctx = SSL_CTX_new (meth);
	if (!ctx) {
		ERR_print_errors_fp (stderr);
		exit (1);
	}
	
	/* Load the server certificate into the SSL_CTX structure */
    if (SSL_CTX_use_certificate_file (ctx, CERT_F, SSL_FILETYPE_PEM) <= 0) {
		ERR_print_errors_fp (stderr);
		exit (1);
	}

  	/* Load the private-key corresponding to the server certificate */
   if (SSL_CTX_use_PrivateKey_file (ctx, KEY_F, SSL_FILETYPE_PEM) <= 0) {
		ERR_print_errors_fp (stderr);
		exit (1);
	}
	
	/* Check if the server certificate and private-key matches */
	if (!SSL_CTX_check_private_key (ctx) ) {
		errmesg ("Private key does not match the certificate public key");
	}
	
	int  msock;			/* master server socket		*/
	int  ssock;			/* master server socket		*/
	int  portN;			/* port number to listen */
	/*if (argc != 2) {
		usage (argv[0]);
	}
	portN = atoi (argv[1]);*/
	portN = 10000;
	msock = serversock (SOCK_STREAM, portN, 5);

	struct sockaddr_in fromAddr;	/* the from address of a client	*/
	unsigned int  fromAddrLen;		/* from-address length          */
	fromAddrLen = sizeof (fromAddr);
	//printf ("Waiting for connection\n");
	putchar ('1');	putchar ('\n');
	ssock = -1;
	if ((ssock = accept (msock, (struct sockaddr *) &fromAddr, &fromAddrLen) ) < 0) {
		//if (errno != EINTR) {
		errmesg ("accept error");
	}
	//printf ("Connection recv'd\n");
	putchar ('2');	putchar ('a');	putchar ('\n');
	SSL* ssl = NULL;
	if ((ssl = SSL_new (ctx) ) == NULL) {
		errmesg ("SSL_new error");
	}
	if (SSL_set_fd (ssl, ssock) == 0) {
		errmesg ("SSL_set_fd error");
	}
	int ret = 0;
	if ((ret = SSL_accept (ssl) ) != 1) {
		int err = SSL_get_error (ssl, ret);
		// SSL_get_error()
   		//printf("SSL connection using %s\n", SSL_get_cipher (ssl));
		if (ret == 0) {
			// The TLS/SSL handshake was not successful but was shut down controlled and by the specifications of the TLS/SSL protocol. 
			//errmesg ("SSL_accept error, proto or shutdown");
		}
		if (ret < 0) {
			SSL_errmsg (ssl, err);
		}
		fprintf (stderr, "ret: %d, SSL_get_error: %d\n", ret, err);
		errmesg ("SSL_accept error");
	}
	
	putchar ('2');	putchar ('b');	putchar ('\n');
	while (doServerSSL (ssl) > 0) {};
	putchar ('8');	putchar ('\n');

	SSL_shutdown (ssl);
	close (ssock);
	SSL_free (ssl);
	SSL_CTX_free (ctx);
	close (msock);
	
	return 0;
} // end fn main
Exemplo n.º 3
0
int main (int argc, char *argv[]) {
	ELF_LOADED_SIG
	
	SSL_library_init ();
	SSL_load_error_strings ();
	SSL_METHOD *meth = TLSv1_method ();
	SSL_CTX *ctx = SSL_CTX_new (meth);
	if (!ctx) {
		ERR_print_errors_fp (stderr);
      exit (1);
	}
	
	/* Load the server certificate into the SSL_CTX structure */
    if (SSL_CTX_use_certificate_file (ctx, CERT_F, SSL_FILETYPE_PEM) <= 0) {
		 ERR_print_errors_fp (stderr);
		 exit (1);
   }

  	/* Load the private-key corresponding to the server certificate */
   if (SSL_CTX_use_PrivateKey_file (ctx, KEY_F, SSL_FILETYPE_PEM) <= 0) {
   	ERR_print_errors_fp (stderr);
		exit (1);
	}
	
	/* Check if the server certificate and private-key matches */
	if (!SSL_CTX_check_private_key (ctx) ) {
		fprintf (stderr,"Private key does not match the certificate public key\n");
		exit (1);
	}
	
	int  msock;			/* master server socket		*/
	int  ssock;			/* master server socket		*/
	int  portN;			/* port number to listen */
	/*if (argc != 2) {
		usage (argv[0]);
	}
	portN = atoi (argv[1]);*/
	portN = 10000;
	msock = serversock (SOCK_STREAM, portN, 5);

	struct sockaddr_in fromAddr;	/* the from address of a client	*/
	unsigned int  fromAddrLen;		/* from-address length          */
	fromAddrLen = sizeof (fromAddr);
	printf ("Waiting for connection\n");
	ssock = accept (msock, (struct sockaddr *) &fromAddr, &fromAddrLen);
	if (ssock < 0) {
		if (errno != EINTR) {
			errmesg ("accept error\n");
		}
	}
	printf ("Connection recv'd\n");
	SSL* ssl = SSL_new (ctx);
	SSL_set_fd (ssl, ssock);
	int err = SSL_accept (ssl);
   printf("SSL connection using %s\n", SSL_get_cipher (ssl));
	printf("The SSL client does not have certificate.\n");
	
	while (doServerSSL (ssl) > 0) {};

	SSL_shutdown (ssl);
	close (ssock);
	SSL_free (ssl);
	SSL_CTX_free (ctx);
	close (msock);
	
	return 0;
} // end fn main