Skip to content

Commit 39f16b2

Browse files
authored
Merge pull request #244 from pusher/clearClearKeyTODO
Remove clear key revisit TODO
2 parents 36747fd + ac42fb2 commit 39f16b2

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

src/main/java/com/pusher/client/crypto/nacl/SecretBoxOpener.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ a copy of this software and associated documentation files (the "Software"),
2626

2727
import static com.pusher.client.util.internal.Preconditions.checkArgument;
2828
import static com.pusher.client.util.internal.Preconditions.checkNotNull;
29-
30-
import java.util.Arrays;
29+
import static java.util.Arrays.fill;
3130

3231
public class SecretBoxOpener {
3332

@@ -97,13 +96,12 @@ public byte[] open(byte[] box, byte[] nonce) throws AuthenticityException {
9796
}
9897

9998
public void clearKey() {
100-
Arrays.fill(key, (byte) 0);
99+
fill(key, (byte) 0);
101100
if (key[0] != 0) {
101+
// so that hopefully the optimiser won't remove the clearing code (best sensible effort)
102102
throw new SecurityException("key not cleared correctly");
103103
}
104104
key = null;
105-
// TODO: ensure implemented securely (so that the clearing code
106-
// is not removed by compiler's optimisations)
107105
}
108106

109107
// subKey = byte[32], counter = byte[16], nonce = byte[24], key = byte[32]

0 commit comments

Comments
 (0)