Merge pull request #39 from manuel-domke/config
make systemd service configurable via /etc/infnoise.conf
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <ftdi.h>
|
||||
@@ -90,6 +91,7 @@ static uint32_t processBytes(uint8_t *keccakState, uint8_t *bytes, uint32_t entr
|
||||
outputBytes(dataOut, entropy/8u, entropy & 0x7u, opts);
|
||||
return entropy/8u;
|
||||
}
|
||||
|
||||
// Output 256*outputMultipler bytes.
|
||||
uint32_t numBits = opts->outputMultiplier*256u;
|
||||
uint32_t bytesWritten = 0u;
|
||||
@@ -314,6 +316,33 @@ int main(int argc, char **argv)
|
||||
}
|
||||
}
|
||||
|
||||
// read environment variables, not overriding command line options
|
||||
if (opts.serial == NULL) {
|
||||
if (getenv("INFNOISE_SERIAL") != NULL) {
|
||||
opts.serial = getenv("INFNOISE_SERIAL");
|
||||
}
|
||||
}
|
||||
|
||||
if (opts.debug == false) {
|
||||
if (getenv("INFNOISE_DEBUG") != NULL) {
|
||||
if (!strcmp("true",getenv("INFNOISE_DEBUG"))) {
|
||||
opts.debug = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (multiplierAssigned == false) {
|
||||
if (getenv("INFNOISE_MULTIPLIER") != NULL) {
|
||||
int tmpOutputMult = atoi(getenv("INFNOISE_MULTIPLIER"));
|
||||
if (tmpOutputMult < 0) {
|
||||
fputs("Multiplier must be >= 0\n", stderr);
|
||||
return 1;
|
||||
}
|
||||
multiplierAssigned = true;
|
||||
opts.outputMultiplier = tmpOutputMult;
|
||||
}
|
||||
}
|
||||
|
||||
if(!multiplierAssigned && opts.devRandom) {
|
||||
opts.outputMultiplier = 2u; // Don't throw away entropy when writing to /dev/random unless told to do so
|
||||
}
|
||||
@@ -322,12 +351,14 @@ int main(int argc, char **argv)
|
||||
listUSBDevices(&ftdic);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Optionally run in the background and optionally write a PID-file
|
||||
startDaemon(&opts);
|
||||
|
||||
if(opts.devRandom) {
|
||||
inmWriteEntropyStart(BUFLEN/8u, &opts);
|
||||
}
|
||||
|
||||
if(!inmHealthCheckStart(PREDICTION_BITS, DESIGN_K, &opts)) {
|
||||
fputs("Can't intialize health checker\n", stderr);
|
||||
return 1;
|
||||
|
||||
@@ -14,6 +14,7 @@ which start the service when the Infinite Noise TRNG is connected and also stops
|
||||
- `infnoise.openrc`: OpenRC, ?
|
||||
- `infnoise.conf`: Upstart, tested in Ubuntu 14.04, 16.04 (requires upstart install)
|
||||
- `infnoise.service`: Systemd, works for CentOS, Ubuntu, Debian, ArchLinux
|
||||
- `infnoise.service.bin`: Same as infnoise.service, binary path = /usr/bin/
|
||||
- `infnoise.service.sbin`: Same as infnoise.service, binary path = /usr/sbin/
|
||||
- `infnoise.service.bin`: Same as infnoise.service, binary path = /usr/bin/ - uses config file from /etc/infnoise.conf
|
||||
- `infnoise.service.sbin`: Same as infnoise.service, binary path = /usr/sbin/ - uses config file from /etc/infnoise.conf
|
||||
- `infnoise.conf.systemd`: Config file for the systemd service, to set multiplier and serial number of device
|
||||
- `75-infnoise.rules`: udev rule to be used together with the systemd service
|
||||
|
||||
12
software/init_scripts/infnoise.conf.systemd
Normal file
12
software/init_scripts/infnoise.conf.systemd
Normal file
@@ -0,0 +1,12 @@
|
||||
# systemd configuration file for the Infinite Noise TRNG
|
||||
|
||||
#INFNOISE_MULTIPLIER=10
|
||||
# keccak multiplier, default = 1
|
||||
|
||||
#INFNOISE_SERIAL=DO0032ZA
|
||||
# serial number of device, default: ""
|
||||
# use infnoise --list-devices to find out your serial number
|
||||
|
||||
#INFNOISE_DEBUG=true
|
||||
# debug mode, default: false
|
||||
# debug logging to syslog
|
||||
@@ -4,6 +4,7 @@ BindsTo=dev-infnoise.device
|
||||
After=dev-infnoise.device
|
||||
|
||||
[Service]
|
||||
EnvironmentFile=/etc/infnoise.conf
|
||||
Type=forking
|
||||
WorkingDirectory=/tmp
|
||||
ExecStart=/usr/bin/infnoise --dev-random --daemon --pidfile /var/run/infnoise.pid
|
||||
|
||||
@@ -4,6 +4,7 @@ BindsTo=dev-infnoise.device
|
||||
After=dev-infnoise.device
|
||||
|
||||
[Service]
|
||||
EnvironmentFile=/etc/infnoise.conf
|
||||
Type=forking
|
||||
WorkingDirectory=/tmp
|
||||
ExecStart=/usr/sbin/infnoise --dev-random --daemon --pidfile /var/run/infnoise.pid
|
||||
|
||||
Reference in New Issue
Block a user