인디노트

Example of secure server-client program using OpenSSL in C 본문

인증기술/OpenSSL

Example of secure server-client program using OpenSSL in C

인디개발자 2018. 11. 3. 15:26

Example of secure server-client program using OpenSSL in C

In this example code, we will create a secure connection between client and server using the TLS1.2 protocol. In this communication, the client sends an XML request to the server which contains the username and password.

The server verifies the XML request, if it is valid then it sends a proper XML response to the client either give a message of Invalid Request.

Install the OpenSSL library, for the ubuntu use the below command.

sudo apt-get install libssldev

Before compiling the client and server program you will need a Certificate. You can generate your own certificate using the below command.

openssl req -x509 -nodes -days 365 -newkey rsa:1024 -keyout mycert.pem -out mycert.pem

Note: Here certificate name is mycert.pem.

Example Client code for TLS1.2 communication

Compile the Client : gcc -Wall -o client  Client.c -L/usr/lib -lssl -lcrypto
Run :   ./client <host_name> <port_number>

Example Server code for TLS1.2 communication

Compile the Server : gcc -Wall -o server Server.c -L/usr/lib -lssl -lcrypto
Run : sudo ./server <portnum>

How to run client server program?

Server run first, using the below command we will run the server and wait for the client request.

sudo ./server  8081

Note: In above command 8081 is the port number.

After that, we will run client using the below command and send the XML request.

./client  127.0.0.1 8081

Note: In above command,  127.0.0.1 is the local host IP and 8081 is the port number.

If the client sends a valid request as per the server then server give a proper response.

Client XML Request:

Server Response:

If the client sends an invalid request to the server then server give a response to an “Invalid message”.

Client XML Request:

Server Response:

“Invalid Message”

반응형

'인증기술 > OpenSSL' 카테고리의 다른 글

OpenSSL Client/Server  (0) 2018.11.11
SSL_CTX_use_certificate  (0) 2018.11.03
OS X 에서 64 비트 OpenSSL 컴파일 옵션  (0) 2018.11.03
certserial.c  (0) 2018.10.16
certrenewal  (0) 2018.10.15
Comments