Lines 67-74
Link Here
|
67 |
|
67 |
|
68 |
// ----------------------------------------------------- Instance Variables |
68 |
// ----------------------------------------------------- Instance Variables |
69 |
|
69 |
|
|
|
70 |
private static final String devRandomSourceDefault; |
71 |
static { |
72 |
// - Use the default value only if it is a Unix-like system |
73 |
// - Check that it exists |
74 |
File f = new File("/dev/urandom"); |
75 |
if (f.isAbsolute() && f.exists()) { |
76 |
devRandomSourceDefault = f.getPath(); |
77 |
} else { |
78 |
devRandomSourceDefault = null; |
79 |
} |
80 |
} |
81 |
|
70 |
protected DataInputStream randomIS=null; |
82 |
protected DataInputStream randomIS=null; |
71 |
protected String devRandomSource="/dev/urandom"; |
83 |
protected String devRandomSource = devRandomSourceDefault; |
72 |
|
84 |
|
73 |
/** |
85 |
/** |
74 |
* The default message digest algorithm to use if we cannot use |
86 |
* The default message digest algorithm to use if we cannot use |
Lines 220-251
Link Here
|
220 |
|
232 |
|
221 |
|
233 |
|
222 |
private class PrivilegedSetRandomFile implements PrivilegedAction{ |
234 |
private class PrivilegedSetRandomFile implements PrivilegedAction{ |
|
|
235 |
|
236 |
private final String s; |
237 |
|
223 |
public PrivilegedSetRandomFile(String s) { |
238 |
public PrivilegedSetRandomFile(String s) { |
224 |
devRandomSource = s; |
239 |
this.s = s; |
225 |
} |
240 |
} |
226 |
|
241 |
|
227 |
public Object run(){ |
242 |
public Object run(){ |
228 |
try { |
243 |
doSetRandomFile(s); |
229 |
File f=new File( devRandomSource ); |
244 |
return null; |
230 |
if( ! f.exists() ) return null; |
|
|
231 |
randomIS= new DataInputStream( new FileInputStream(f)); |
232 |
randomIS.readLong(); |
233 |
if( log.isDebugEnabled() ) |
234 |
log.debug( "Opening " + devRandomSource ); |
235 |
return randomIS; |
236 |
} catch (IOException ex){ |
237 |
log.warn("Error reading " + devRandomSource, ex); |
238 |
if (randomIS != null) { |
239 |
try { |
240 |
randomIS.close(); |
241 |
} catch (Exception e) { |
242 |
log.warn("Failed to close randomIS."); |
243 |
} |
244 |
} |
245 |
devRandomSource = null; |
246 |
randomIS=null; |
247 |
return null; |
248 |
} |
249 |
} |
245 |
} |
250 |
} |
246 |
} |
251 |
|
247 |
|
Lines 524-552
Link Here
|
524 |
// as a hack, you can use a static file - and generate the same |
520 |
// as a hack, you can use a static file - and generate the same |
525 |
// session ids ( good for strange debugging ) |
521 |
// session ids ( good for strange debugging ) |
526 |
if (System.getSecurityManager() != null){ |
522 |
if (System.getSecurityManager() != null){ |
527 |
randomIS = (DataInputStream) AccessController |
523 |
AccessController.doPrivileged(new PrivilegedSetRandomFile(s)); |
528 |
.doPrivileged(new PrivilegedSetRandomFile(s)); |
|
|
529 |
} else { |
524 |
} else { |
530 |
try{ |
525 |
doSetRandomFile(s); |
531 |
devRandomSource=s; |
526 |
} |
532 |
File f=new File( devRandomSource ); |
527 |
} |
533 |
if( ! f.exists() ) return; |
528 |
|
534 |
randomIS= new DataInputStream( new FileInputStream(f)); |
529 |
private void doSetRandomFile(String s) { |
535 |
randomIS.readLong(); |
530 |
DataInputStream is = null; |
536 |
if( log.isDebugEnabled() ) |
531 |
try { |
537 |
log.debug( "Opening " + devRandomSource ); |
532 |
if (s == null || s.length() == 0) { |
538 |
} catch( IOException ex ) { |
533 |
return; |
539 |
log.warn("Error reading " + devRandomSource, ex); |
534 |
} |
540 |
if (randomIS != null) { |
535 |
File f = new File(s); |
541 |
try { |
536 |
if( ! f.exists() ) return; |
542 |
randomIS.close(); |
537 |
if( log.isDebugEnabled() ) { |
543 |
} catch (Exception e) { |
538 |
log.debug( "Opening " + s ); |
544 |
log.warn("Failed to close randomIS."); |
539 |
} |
545 |
} |
540 |
is = new DataInputStream( new FileInputStream(f)); |
|
|
541 |
is.readLong(); |
542 |
} catch( IOException ex ) { |
543 |
log.warn("Error reading " + s, ex); |
544 |
if (is != null) { |
545 |
try { |
546 |
is.close(); |
547 |
} catch (Exception ex2) { |
548 |
log.warn("Failed to close " + s, ex2); |
546 |
} |
549 |
} |
|
|
550 |
is = null; |
551 |
} |
552 |
} finally { |
553 |
DataInputStream oldIS = randomIS; |
554 |
if (is != null) { |
555 |
devRandomSource = s; |
556 |
} else { |
547 |
devRandomSource = null; |
557 |
devRandomSource = null; |
548 |
randomIS=null; |
|
|
549 |
} |
558 |
} |
|
|
559 |
randomIS = is; |
560 |
if (oldIS != null) { |
561 |
try { |
562 |
oldIS.close(); |
563 |
} catch (Exception ex) { |
564 |
log.warn("Failed to close RandomIS", ex); |
565 |
} |
566 |
} |
550 |
} |
567 |
} |
551 |
} |
568 |
} |
552 |
|
569 |
|