Sign inSign up

weevenetwork/dev-random

By weevenetwork

•Updated about 4 years ago

Ingress module mounting the dev/random device to generate a SHA256 hash string

Image
0

1.8K

weevenetwork/dev-random repository overview

⁠dev-random

nameDev Random Ingress
typeingress
versionv1.0.0
docker imageweevenetwork/dev-random⁠
tagsDocker, Weeve, MVP
authorsMarcus Jones

⁠Description

This module and project demonstrates a docker container mounting a device from the host, reading data, and processing data from that device.

⁠Features

  • Simple and lightweight for testing
  • Strict assertions in shell script for parameters and volumes

⁠Technical implementation

⁠Ingress module description

The simple ingress module mounts the linux random device to generate and forward a random hash string.

⁠Random data device

The /dev/urandom device node in linux generates unlimited random bytes of data. The data is generated from the entropy pool.

Bytes can be collected in various ways, just as from any file;

The dd utility can read and convert data from a file. The following command would read 3 bytes of data.

random="$(dd if=/dev/urandom bs=3 count=1)"

The head utility can read lines of a file. The following command would read 4096 bytes of data.

random=$(head -n 4096 /dev/urandom)

⁠Generate hash string

The sha256sum utility hashes input. The utility outputs a - characture which can be cut for a clean output.

echo My data | sha256sum | cut -f 1 -d " "

⁠Package into JSON payload

The jq utility can be used to package data into a JSON structure. The following command would place a variable $randomstring into the key value pair.

JSON_STRING=$( jq -n -r --arg hs "$randomstring" '{"random hash": $hs}' )

⁠Send as HTTP post

The curl utility is used to send HTTP data as a POST request. To avoid escaping newline and space characters, the payload (-d) is piped in.

echo $JSON_STRING | curl -d @- -H "Content-Type: application/json" -X POST http://url:port

⁠Developing

Recommend to install the docker-pushrm⁠ plugin to publish READEM.md files.

docker login

⁠Testing

# In one terminal;
NETWORK_NAME=dtestnet
docker network create $NETWORK_NAME
docker run --network=$NETWORK_NAME --rm -e PORT=4000 -e LOG_HTTP_BODY=true -e LOG_HTTP_HEADERS=true --name echo jmalloc/echo-server
# In second terminal;
NETWORK_NAME=dtestnet
VOLUME_HOST=/dev/urandom
VOLUME_CONTAINER=/mnt/random
APP_NAME=dev-random
ACCOUNT_NAME=weevenetwork
EGRESS_URL=echo:4000
docker run --network=$NETWORK_NAME --rm --volume $VOLUME_HOST:$VOLUME_CONTAINER -e EGRESS_URL=$EGRESS_URL -e VOLUME_CONTAINER=/mnt/random $ACCOUNT_NAME/$APP_NAME --hash sha256 --interval=2

Tag summary

Content type

Image

Digest

sha256:7b8da2d07…

Size

6.9 MB

Last updated

about 4 years ago

docker pull weevenetwork/dev-random:v1.0.0