简体   繁体   English

来自java的UUID.randomUUID()的重复UUID集

[英]Repeated set of UUIDs from java's UUID.randomUUID()

We have observed that set of almost 200,000 UUIDs has replayed two months apart, and I'm wondering if anyone has seen anything similar. 我们观察到近200,000个UUID已经重播了两个月,我想知道是否有人见过类似的东西。

The UUIDs are generated using UUID.randomUUID(). UUID是使用UUID.randomUUID()生成的。 In digging into this (looking at java source), randomUUID() uses SecureRandom() under the hood, which in turn is using NativePRNG. 在深入研究这个问题(查看java源代码)时,randomUUID()在引擎盖下使用SecureRandom(),后者又使用NativePRNG。 It is my understanding that NativePRNG uses /dev/urandom to acquire its seed. 据我所知,NativePRNG使用/ dev / urandom获取其种子。 The implication of course is baffling - that somehow /dev/urandom returned the same seed to NativePRNG two months apart. 当然这意味着莫名其妙 - 不知何故/ dev / urandom在相隔两个月的时间里将相同的种子归还给NativePRNG。 From what I can tell, once instantiated the PRNG does not re-seed. 据我所知,一旦实例化,PRNG就不会再播种。 This is a long running job which s listening for messages and using a UUID as an ID for it. 这是一个长时间运行的作业,它正在侦听消息并使用UUID作为它的ID。 The pseudocode is simply: 伪代码很简单:

< receive message> String uuid = UUID.randomUUID().toString(); String fname = h.composeArtifact(uuid);

The OS is Centos 6, on an AWS EC2 instance running JDK1.6. 操作系统是Centos 6,位于运行JDK1.6的AWS EC2实例上。 Is this something that anyone has seen/experienced in the past? 这是过去曾见过/经历过的事吗? Seems like the kind of thing that should 'never happen'... 似乎应该“永远不会发生”的事情......

From JDK 1.6 source, indeed, UUID.randomUUID() feeds on a java.util.SecureRandom instance. 实际上,从JDK 1.6源代码, UUID.randomUUID()java.util.SecureRandom实例为基础。 If you got a repeated sequence of UUID, then either you got very lucky (or very unlucky, depending on point of view), or someone played with VM snapshots, or there is something fishy in your Java configuration. 如果你有一个重复的UUID序列,那么要么你很幸运(或者非常不幸,取决于观点),或者有人使用VM快照,或者你的Java配置中有些可疑。

When taking a VM snapshot, you record the complete live state of the machine, processes and RAM included. 在拍摄VM快照时,您将记录机器的完整实时状态,包括的进程和RAM。 If there was a live process with an already instantiated SecureRandom instance, restoring the snapshot will bring back that state, so the sequence of random values output by that SecureRandom will be the same each time a restore occurs, until the SecureRandom reseeds itself from /dev/urandom ( /dev/urandom continuously gathers "random" physical events, but these won't impact the SecureRandom state until the next reseeding). 如果存在已经实例化的SecureRandom实例的实时进程,则恢复快照将恢复该状态,因此每次恢复时SecureRandom输出的随机值序列将相同,直到SecureRandom/dev/urandom自身为止/dev/urandom/dev/urandom持续收集“随机”物理事件,但这些事件在下次重播之前不会影响SecureRandom状态)。

The Java configuration may impact SecureRandom , in that SecureRandom is NOT a PRNG, but a shell around an instance of SecureRandomSpi provided by a duly registered cryptographic provider. Java配置可能会影响SecureRandom ,因为SecureRandom不是PRNG,而是由正式注册的加密提供程序提供的SecureRandomSpi实例周围的shell。 Sun's JDK comes with a default implementation that normally feeds on the system's resources ( /dev/urandom on Linux). Sun的JDK附带了一个默认实现, 通常以系统资源为基础(Linux上的/dev/urandom )。 However, this can be configured; 但是,这可以配置; lookup the java.security.egd system property, and also the securerandom.source property in the java.security file. 查找java.security.egd系统属性,以及java.security文件中的securerandom.source属性。 The default provider may also be replaced altogether with an alternate implementation that does things differently (and possibly very poorly). 默认提供程序也可以与替代实现一起替换,该替换实现以不同方式执行(并且可能非常差)。 See this answer for some details. 有关详细信息,请参阅此答案 Verifying what random source is indeed used can be a bit complex, but you could try launching your process with strace , which will show system calls, hence whether /dev/random or /dev/urandom is opened at some point. 验证确实使用了什么随机源可能有点复杂,但您可以尝试使用strace启动您的进程,这将显示系统调用,因此在某些时候是否打开/dev/random/dev/urandom

If your Java configuration is fine, and there was no game with VM snapshots, and you are sure that you indeed got the same sequence of UUID as previously, then you really really should have bought a Powerball ticket instead (but I do not honestly believe in this scenario). 如果您的Java配置没问题, 并且没有带有VM快照的游戏, 并且您确定您确实获得了与之前相同的UUID序列,那么您真的应该购买一张强力球票(但我并不诚实地相信)在这种情况下)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM