From 6b67e43f8463aa2ea0672d901e587a22a595ed7a Mon Sep 17 00:00:00 2001 From: rtm516 Date: Sun, 15 Oct 2023 21:51:06 +0100 Subject: [PATCH] Update AesKeyProducer.java (#4211) --- .../floodgate/crypto/AesKeyProducer.java | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/common/src/main/java/org/geysermc/floodgate/crypto/AesKeyProducer.java b/common/src/main/java/org/geysermc/floodgate/crypto/AesKeyProducer.java index 77dd46fde..4fae21b32 100644 --- a/common/src/main/java/org/geysermc/floodgate/crypto/AesKeyProducer.java +++ b/common/src/main/java/org/geysermc/floodgate/crypto/AesKeyProducer.java @@ -55,19 +55,20 @@ public final class AesKeyProducer implements KeyProducer { } private SecureRandom secureRandom() throws NoSuchAlgorithmException { - // use Windows-PRNG for windows (default impl is SHA1PRNG) - if (System.getProperty("os.name").startsWith("Windows")) { - return SecureRandom.getInstance("Windows-PRNG"); - } else { - try { + try { + // use Windows-PRNG for windows (default impl is SHA1PRNG) + if (System.getProperty("os.name").startsWith("Windows")) { + return SecureRandom.getInstance("Windows-PRNG"); + } else { // NativePRNG (which should be the default on unix-systems) can still block your // system. Even though it isn't as bad as NativePRNGBlocking, we still try to // prevent that if possible return SecureRandom.getInstance("NativePRNGNonBlocking"); - } catch (NoSuchAlgorithmException ignored) { - // at this point we just have to go with the default impl even if it blocks - return new SecureRandom(); + } + } catch (NoSuchAlgorithmException ignored) { + // Fall back to the default impl as we couldn't load any others + return new SecureRandom(); } } }