[crac] RFR: Reseed secure random on checkpoint restore

Anton Kozlov akozlov at openjdk.java.net
Thu Dec 23 14:10:45 UTC 2021


On Fri, 17 Dec 2021 13:38:18 GMT, Alexey Bakhtin <abakhtin at openjdk.org> wrote:

> Proposed changes in the SecureRandom implementation allow invalidating and reseeding SHA1PRNG secure random during checkpoint/restore. SHA1PRNG can be invalidated and reseeded in case of being created with a default embedded seed generator. Also, SHA1PRNG is used as an additional seed generator to the SUN NativePRNG implementation, so it is desirable to have reseeded SHA1PRNG after restore.
> Two jtreg tests added: 
> - verify if no deadlocks introduced by checkpoint/restore
> - verify if SHA1PRNG is reseeded if created with default embedded seed generator

Changes requested by akozlov (Lead).

src/java.base/share/classes/sun/security/provider/SecureRandom.java line 267:

> 265:             SeedGenerator.generateSeed(b);
> 266:             seeder.engineSetSeed(b);
> 267:             seeder.clearStateOnCheckpoint = true;

This highlights that the `seeder` differs from any other SecureRandom. I would prefer `seeder` to be an object of a subclass of `SecureRandom`. This will also save us a field `isSeedGenerator` that is false for all except one object in the system.

src/java.base/share/classes/sun/security/provider/SecureRandom.java line 278:

> 276:     @Override
> 277:     public void engineNextBytes(byte[] result) {
> 278:         objLock.lock();

A minor drawback, the keyword in the method declaration makes the synchronization more explicit. An alternative is to retain the synchronization the on object monitor by e.g.


private boolean blocked = false;

public synchronized void engineNextBytes {
   while (blocked) {
     this.wait()
   }
   ...
}

public synchronized void beforeCheckpoint {
  blocked = true
  ...
}
public synchronized void afterRestore {
  ...
  blocked = false;
  this.notifyAll();
}


However, a dedicated ReentrantLock makes the implementation a bit shorter. So, up to you.

-------------

PR: https://git.openjdk.java.net/crac/pull/7


More information about the crac-dev mailing list