bug-guix
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#23605: /dev/urandom not seeded across reboots


From: Ludovic Courtès
Subject: bug#23605: /dev/urandom not seeded across reboots
Date: Wed, 25 May 2016 18:54:58 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux)

Leo Famulari <address@hidden> skribis:

> On Tue, May 24, 2016 at 02:24:59PM +0200, Ludovic Courtès wrote:

[...]

>> Instead of spawning ‘cat’, we can do:
>> 
>>   (when (file-exists? #$%random-seed-file)
>>     (call-with-input-file #$%random-seed-file
>>       (lambda (seed)
>>         (call-with-output-file "/dev/urandom"
>>           (lambda (random)
>>             (dump-port seed random))))))
>>   #t   ;service successfully “started”
>
> I think I've done this correctly, as attached, but I can't test it yet
> since I still get an error: "service: Wrong number of arguments in form
> (service urandom-seed-service-type)".

Yes, it’s:

  (service TYPE VALUE)

but I think there’s no meaningful value for this service, so you could
do:

  (service urandom-seed-service-type #f)

[...]

> +(define (urandom-seed-shepherd-service)
> +  "Return a shepherd service for the /dev/urandom seed."
> +  (list (shepherd-service
> +         (documentation "Preserve entropy across reboots for /dev/urandom.")

I think you’ll need to specify that additional modules are needed (for
‘make-bytevector’, ‘put-bytevector’, etc.):

  (shepherd-service
    ;; …
    (modules `((rnrs bytevectors)
               (rnrs io ports)
               ,@%default-modules)))

(See (gnu services shepherd) for the definition of ‘%default-modules’.)

> +         (stop #~(lambda _
> +                   (let ((buf (make-bytevector 512)))
> +                     (call-with-input-file "/dev/urandom"
> +                       (lambda (urandom)
> +                         (get-bytevector-n! urandom buf 0 512)
> +                           (call-with-output-file #$%random-seed-file
                             ^^
Misleading indent here.

> +                             (lambda (seed)
> +                               (dump-port buf seed)))

‘dump-port’ from (guix build utils) takes an input port as its 1st
argument, and an output port as its 2nd argument.  Here BUF is a
bytevector, not a port.

So instead, this should be:

  (lambda (seed)
    (put-bytevector seed buf))

Sounds like you’re pretty much there!  :-)

Thanks,
Ludo’.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]