일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
- SSL
- 앱스토어
- MSYS2
- FIDO2
- MFA
- otpkey
- SSH
- 애플
- fido
- 인증
- MYSQL
- OSX
- albumbook
- SwiftUI
- appres
- OTP
- 2FA
- css
- kmip
- Xcode
- apple
- WebAuthn
- Android
- Nodejs
- 앨범북
- SWIFT
- git
- 앱리소스
- openssl
- 안드로이드
- Today
- Total
인디노트
Example of secure server-client program using OpenSSL in C 본문
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 libssl–dev
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.
Server Response:
If the client sends an invalid request to the server then server give a response to an “Invalid message”.
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 |