BZ #60: SecureRandom.nextBytes() throws InternalError: URLSeedGenerator file:/dev/random generated exception: Invalid argument

Status fields:

creation_ts:2008-03-30 15:04
component:native
version:default branch
rep_platform:All
op_sys:All
bug_status:RESOLVED
resolution:FIXED
reporter:twisti@complang.tuwien.ac.at
This simple testcase:

        SecureRandom sr = new SecureRandom();
        byte[] seed = new byte[20];
        sr.nextBytes(seed);

throws this exception with OpenJDK libraries:

$ cacao -Djava.security.egd=file:/dev/random test
LOG: [0x30021cf0] JVM_InitializeSocketLibrary: IMPLEMENT ME!
Exception in thread "main" java.lang.InternalError: URLSeedGenerator file:/dev/random
generated exception: Invalid argument
        at
sun.security.provider.SeedGenerator$URLSeedGenerator.getSeedByte(SeedGenerator.java:471)
        at sun.security.provider.SeedGenerator.getSeedBytes(SeedGenerator.java:140)
        at sun.security.provider.SeedGenerator.generateSeed(SeedGenerator.java:135)
        at sun.security.provider.SecureRandom.engineGenerateSeed(SecureRandom.java:131)
        at sun.security.provider.SecureRandom.engineNextBytes(SecureRandom.java:188)
        at java.security.SecureRandom.nextBytes(SecureRandom.java:450)
        at test.main(test.java:69)

Comment #1 by twisti@complang.tuwien.ac.at on 2008-03-30 22:32:33

I investigated this bug more deeply and this is a more common problem: we don't use
OpenJDK's HPI.  I have already started to fix that.  A patch is coming soon.

Comment #2 by twisti@complang.tuwien.ac.at on 2008-03-31 17:12:16

This changeset:

http://mips.complang.tuwien.ac.at/hg/cacao/rev/fceac7c38a1b

adds the initialization and usage of the HPI.  The bug is fixed.