World of Wisdom is a CLI tool that allows you to get a random quote from a variety of sources.
This solution is used Challenge–response approach to verify the client.
This approach has chosen because it is simple, secure and stateless in the implementation.
- The client connects to the server.
- The server generates an arbitrary random data and sends it back to the client with difficulty for proof of work.
- The client uses brute-force to find the NONCE number and the DIFFICULTY condition.
- Once the puzzle is solved, the client sends NONCE and computed HASH back to the server.
- The server verifies the NONCE and HASH and sends the quote to the client.
The data is transmitted in gob format.
The protocol consists of two sections:
Field | Size | Description |
---|---|---|
Header | 4 bytes | Contains the length of the data section |
Payload | based on the header | Contains the data itself |
type Challenge struct {
Difficulty int
Data []byte
}
This structure is used to send the challenge to the client.
type Solution struct {
Nonce int
Hash []byte
}
This structure is used to send the solution to the server.
type Quote struct {
Text string
}
This structure is used to send the quote to the client.
To build the docker image, you will need to run the following command:
make docker/build
- To run the project, you will need to have Docker installed.
- Run the following command to run the project:
make run
The output should look like this:
docker-compose up -d
[+] Running 2/2
✔ Network app_testapp Created 0.1s
✔ Container app-server-1 Started 0.5s
docker-compose run client
[+] Running 1/0
✔ Container app-server-1 Running 0.0s
[*] Received quote: "Beware of false knowledge; it is more dangerous than ignorance"
docker-compose down
[+] Running 2/2
✔ Container app-server-1 Removed 0.1s
✔ Network app_testapp Removed
To run the tests, you will need to run the following command:
make test
Note: To run the tests you need installed GO locally.