Skip to content

Latest commit

 

History

95 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

Implementing SSL/TLS

My progress through the book Implementing SSL/TLS Using Cryptography and PKI by Joshua Davies.

Tip

Decode hex with CyberChef.

Environment

Build the whole project with CMake

# generate the build system
cmake -S ./ -B ./build
# build the main project
cmake --build ./build
# build just one target
cmake --build ./build [-t <webserver|http|base64|hex|des|aes>]

Compile & Test Manually

GCC Options

HTTP Client/Server

# linux can omit linking ws2_32
gcc -o webserver.exe ./src/webserver/webserver.c -lws2_32
gcc -o http.exe ./src/http/http.c -lws2_32
  1. Start the webserver listening on port 80
./build/ssl-tls/webserver/Debug/webserver.exe
  1. In a new terminal make a request with the http client to http://localhost/test
./build/ssl-tls/http/Debug/http.exe http://localhost/test
# Connecting to host 'localhost'
# Retrieving document: 'test'
# HTTP/1.1 200 Success
# Connection: Close
# Content-Type:text/html

# <html><head><title>Test Page</title></head><body>Nothing here</body></html>

# shutting down.
  1. Quit the webserver
CTRL[CMD]+C

Note

DES is intended to be used as a library. Yet, a test routine is included that can be enabled with the compiler option -DTEST_DES.

# Manual compilation
gcc -DTEST_DES -g -o des -Isrc/lib/hex -Isrc/lib/utility src/lib/hex/hex.c src/lib/utility/utility.c src/lib/des/des.c

Important

DES is an 8 byte block cipher. Hence, the key and initialization vector (iv) must be 8 bytes and the input must be a multiple of 8 bytes.

# DES
# ./des.exe [-e|-d] <key> <iv> <input>
./des.exe -e password initialz abcdefgh
# 71828547387b18e5
./des.exe -d password initialz 0x71828547387b18e5
# 6162636465666768

Note

DES3 uses a 24 byte ($8*3$) key.

# DES3
./des -e twentyfourcharacterinput initialz abcdefgh
# c0c48bc47e87ce17
./des -d twentyfourcharacterinput initialz 0xc0c48bc47e87ce17
# 6162636465666768
# Manual compilation
gcc -DTEST_AES -g -o aes -Isrc/lib/hex -Isrc/lib/utility src/lib/aes/aes.c src/lib/utility/utility.c src/lib/hex/hex.c

CLI Usage

# encrypt
./aes -e passwordpassword initialzinitialz abcdefghabcdefgh 
# eb4703ae3d8212c64c5a91ccc2c4078f

# decrypt
./aes -d passwordpassword initialzinitialz 0xeb4703ae3d8212c64c5a91ccc2c4078f
# 61626364656667686162636465666768

Compare to OpenSSL

# encryption
printf 'abcdefghabcdefgh' | openssl enc -aes-128-cbc -K 70617373776f726470617373776f7264 -iv 696e697469616c7a696e697469616c7a -nopad -nosalt | xxd -p
# eb4703ae3d8212c64c5a91ccc2c4078f

# decryption
printf 'eb4703ae3d8212c64c5a91ccc2c4078f' | xxd -r -p | openssl enc -d -aes-128-cbc -K 70617373776f726470617373776f7264 -iv 696e697469616c7a696e697469616c7a -nopad -nosalt | xxd -p
# 61626364656667686162636465666768

Other Ciphers

  • blowfish
  • twofish
  • FEAL
  • LOKI
  • Camelia

About

"Implementing SSL/TLS Using Cryptography and PKI" by Joshua Davies - code listing progress

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Contributors

Languages