Skip to content

Commit f26b907

Browse files
committed
Update PRNG fix code sample.
Google updated their code sample to account for restrictive SELinux configurations on some devices.
1 parent 1c8f866 commit f26b907

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

src/org/thoughtcrime/securesms/crypto/PRNGFixes.java

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
1+
/*
2+
* This software is provided 'as-is', without any express or implied
3+
* warranty. In no event will Google be held liable for any damages
4+
* arising from the use of this software.
5+
*
6+
* Permission is granted to anyone to use this software for any purpose,
7+
* including commercial applications, and to alter it and redistribute it
8+
* freely, as long as the origin is not misrepresented.
9+
*/
10+
111
package org.thoughtcrime.securesms.crypto;
212

313
import android.os.Build;
414
import android.os.Process;
15+
import android.util.Log;
516

617
import java.io.ByteArrayOutputStream;
718
import java.io.DataInputStream;
@@ -25,7 +36,6 @@
2536
* Since I still don't know exactly what the source of this bug was, I'm using
2637
* this class verbatim under the assumption that the Android team knows what
2738
* they're doing. Although, at this point, that is perhaps a foolish assumption.
28-
*
2939
*/
3040

3141
/**
@@ -213,10 +223,13 @@ protected void engineSetSeed(byte[] bytes) {
213223
}
214224
out.write(bytes);
215225
out.flush();
216-
mSeeded = true;
217226
} catch (IOException e) {
218-
throw new SecurityException(
219-
"Failed to mix seed into " + URANDOM_FILE, e);
227+
// On a small fraction of devices /dev/urandom is not writable.
228+
// Log and ignore.
229+
Log.w(PRNGFixes.class.getSimpleName(),
230+
"Failed to mix seed into " + URANDOM_FILE);
231+
} finally {
232+
mSeeded = true;
220233
}
221234
}
222235

@@ -267,15 +280,10 @@ private DataInputStream getUrandomInputStream() {
267280
}
268281
}
269282

270-
private OutputStream getUrandomOutputStream() {
283+
private OutputStream getUrandomOutputStream() throws IOException {
271284
synchronized (sLock) {
272285
if (sUrandomOut == null) {
273-
try {
274-
sUrandomOut = new FileOutputStream(URANDOM_FILE);
275-
} catch (IOException e) {
276-
throw new SecurityException("Failed to open "
277-
+ URANDOM_FILE + " for writing", e);
278-
}
286+
sUrandomOut = new FileOutputStream(URANDOM_FILE);
279287
}
280288
return sUrandomOut;
281289
}

0 commit comments

Comments
 (0)