Bug 26097

Summary: rng.service: "No pkcs11 slots available"
Product: Mageia Reporter: Bjarne Thomsen <bjarne.thomsen>
Component: RPM PackagesAssignee: Mageia Bug Squad <bugsquad>
Status: RESOLVED WORKSFORME QA Contact:
Severity: normal    
Priority: Normal CC: lewyssmith, tmb
Version: 7   
Target Milestone: ---   
Hardware: x86_64   
OS: Linux   
URL: https://blog.hqcodeshop.fi/archives/441-Adding-a-source-of-randomness-to-a-Linux.html
Whiteboard:
Source RPM: rng-tools-6.7-1.mga7.src.rpm CVE:
Status comment:

Description Bjarne Thomsen 2020-01-17 11:49:10 CET
Description of problem:
I tried to follow the prescription in the URL to to obtain the entropy source from a new TrueRNG V3 USB-stick. But a problem appeared right from the start:
rngd[16964]: Initalizing available sources
rngd[16964]: Failed to init entropy source hwrng
rngd[16964]: Enabling RDSEED rng support
rngd[16964]: Initalizing entropy source rdrand
rngd[16964]: No pkcs11 slots available
rngd[16964]: Failed to init entropy source pkcs11
It was impossible to follow the prescription due to "No pkcs11 slots available".
I am not sure, if this is a bug, or how to make a slot available.

Version-Release number of selected component (if applicable):
systemd-241-8.4.mga7.src.rpm
5.4.12-desktop-1.mga7

How reproducible: Always


Steps to Reproduce:
1.
2.
3.
Comment 1 Bjarne Thomsen 2020-01-17 23:14:32 CET
I have possibly found the cause of the strange message "No pkcs11 slots available". I had been experimenting with the packages pcsc-lite and opensc, but had forgotten about it. These with libraries have now been uninstalled.
I can now restart the rngd without getting any errors.
The two last messages from "systemctl status rngd" are now:
PKCS11 Engine /usr/lib64/opensc-pkcs11.so Error: No such file or directory
Failed to init entropy source pkcs11

Does this imply that the correct working of rngd requires an Error!
Comment 2 Thomas Backlund 2020-01-17 23:56:39 CET
Well, you need opensc (and its lib)

CC: (none) => tmb

Comment 3 Bjarne Thomsen 2020-01-18 00:40:06 CET
I tried to re-install opensc with lib. Now I again get:
No pkcs11 slots available
Failed to init entropy source pkcs11

Furthermore, the prescription in the URL did not work. Quoting:
The only change I made was to have the ExecStart-line say as:
ExecStart=/sbin/rngd -f --rng-device=/dev/TrueRNG --fill-watermark=4000

The device /dev/TrueRNG does work.
Comment 4 Thomas Backlund 2020-01-18 00:47:57 CET
Have you followed the instructions to setup udev rules and so on ?
Comment 5 Bjarne Thomsen 2020-01-18 01:20:34 CET
Yes, it just makes a symlink:
ls -l /dev/TrueRNG:
lrwxrwxrwx 1 root root 7 Jan 17 22:38 /dev/TrueRNG -> ttyACM0

Yes, I followed the prescription with opensc/library installed.
I have not yet tried without installing opensc.
Why should I install opensc, when I have no SmartCard?
I actually had the idéa that it could be used with Yubico keys, but this is not the way to go. This is why opensc was installed in the first place.
Comment 6 Bjarne Thomsen 2020-01-18 01:35:11 CET
Niel Horman: bug fix update on Dec 16 2019:
"Enhance logging to more clearly indicate which entropy source is issuing a given log message"

Yes, "dd if=/dev/TrueRNG of=random.bytes bs=64 count=1024" did work.
Comment 7 Bjarne Thomsen 2020-01-18 13:41:49 CET
I have tested Niel Horman's prescription without opensc+lib. It looks interesting:
systemctl restart rngd
cat /proc/sys/kernel/random/entropy_avail
4036
It should display a number greater than 4000 and smaller than 4096.
However, after some time I obtain:
cat /proc/sys/kernel/random/entropy_avail
3887
It looks as if some numbers are removed from the bottom of the pool at regular intervals. However, if I now repeat:
systemctl restart rngd
4033

This seems to indicate that the source of randomness has not permanently been replaced by /dev/TrueRNG, but "systemctl restart rngd" must be run at regular intervals.
Is that where opensc+lib comes into the picture? Do I need a SmartCard configured to manage the entropy pool at regular intervals? I am confused.
Comment 8 Bjarne Thomsen 2020-01-18 18:25:14 CET
This problem is solved. I found "rngd --list":
Available and enabled entropy sources:
2: Intel RDRAND Instruction RNG (rdrand)

My hardware does not have a /dev/hwrng, so i cannot be substituted with /dev/TrueRNG.
My hardware does not have a SmartCard reader, so it cannot use the pksc11 source.

To use TrueRNG requires a box with another hardware source.
Bad for me ..
Comment 9 Thomas Backlund 2020-01-18 18:45:39 CET
Try this:

copy the /usr/lib/systemd/system/rngd.service to /etc/systemd/system/rngd.service

then edit /etc/systemd/system/rngd.service

And under [Service] add the line:
Environment=HRNGDEVICE=/dev/TrueRNG

and try to restart the service, does it work then ?
Comment 10 Bjarne Thomsen 2020-01-18 19:46:58 CET
[Service]
Environment=HRNGDEVICE=/dev/TrueRNG
ExecStart=/sbin/rngd -f --fill-watermark=4000

and then I restarted
systemctl restart rngd
cat /proc/sys/kernel/random/entropy_avail

but that is how it was before. How kan I se, that the source is not
2: Intel RDRAND Instruction RNG (rdrand)

Should I try to put in a "--exclude 2" like this
ExecStart=/sbin/rngd -f --exclude 2 --fill-watermark=4000

or should it be --exclude=2
Comment 11 Bjarne Thomsen 2020-01-18 19:58:49 CET
The "--exclude 2" does not make any difference.
It is still "Initalizing entropy source rdrand".
How can I see if it uses TrueRNG or rdrand?
Comment 12 Bjarne Thomsen 2020-01-18 20:58:22 CET
I have moved the TrueRNG to a small Intel NUC8-i5.
On that box hwrng exists as device 0. The rngd starts with hwrng initializing.
This also happens after I substituted with /dev/TrueRNG in /etc/systemd/sustem/
So my USB-TrueRNG seems to be working on the NUC8i5 box.
Comment 13 Lewis Smith 2020-01-20 20:23:46 CET
I had not forgotten this bug, but it is far beyond my ken, so had no idea what to suggest nor whom to ask. So thanks to Thomas for jumping in; even though the suggestions did not resolve the issue. And to you Bjarne for finding a solution.

> To use TrueRNG requires a box with another hardware source (c8)
> So my USB-TrueRNG seems to be working on the NUC8i5 box (c12)
Would you agree to close the bug?

CC: (none) => lewyssmith

Comment 14 Bjarne Thomsen 2020-01-20 21:09:02 CET
The real question is if a pool of TrueRNG entropies are needed considering the many cryptographically strong hash functions available. This was not the case 30 years ago but the situation has changed.
Comment 15 Lewis Smith 2020-01-22 21:16:41 CET
This can always be re-opened if needed.

Status: NEW => RESOLVED
Resolution: (none) => WORKSFORME