|
| 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 | + |
1 | 11 | package org.thoughtcrime.securesms.crypto; |
2 | 12 |
|
3 | 13 | import android.os.Build; |
4 | 14 | import android.os.Process; |
| 15 | +import android.util.Log; |
5 | 16 |
|
6 | 17 | import java.io.ByteArrayOutputStream; |
7 | 18 | import java.io.DataInputStream; |
|
25 | 36 | * Since I still don't know exactly what the source of this bug was, I'm using |
26 | 37 | * this class verbatim under the assumption that the Android team knows what |
27 | 38 | * they're doing. Although, at this point, that is perhaps a foolish assumption. |
28 | | - * |
29 | 39 | */ |
30 | 40 |
|
31 | 41 | /** |
@@ -213,10 +223,13 @@ protected void engineSetSeed(byte[] bytes) { |
213 | 223 | } |
214 | 224 | out.write(bytes); |
215 | 225 | out.flush(); |
216 | | - mSeeded = true; |
217 | 226 | } 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; |
220 | 233 | } |
221 | 234 | } |
222 | 235 |
|
@@ -267,15 +280,10 @@ private DataInputStream getUrandomInputStream() { |
267 | 280 | } |
268 | 281 | } |
269 | 282 |
|
270 | | - private OutputStream getUrandomOutputStream() { |
| 283 | + private OutputStream getUrandomOutputStream() throws IOException { |
271 | 284 | synchronized (sLock) { |
272 | 285 | 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); |
279 | 287 | } |
280 | 288 | return sUrandomOut; |
281 | 289 | } |
|
0 commit comments