我见过有人使用 UUID 来生成身份验证令牌。然而,在 RFC 4122 中指出
不要假设 UUID 很难猜测;不应该使用它们
作为安全功能(仅拥有即可授予的标识符
访问),例如。
我想知道 Java 和 .NET 中使用什么算法来生成 SessionId/AuthenticationToken。在具有高于平均安全需求的应用程序中,UUID 是否确实不适合这些目的?
I have seen people using UUID for authentication token generation. However, in RFC 4122 it is stated that
Do not assume that UUIDs are hard to guess; they should not be used
as security capabilities (identifiers whose mere possession grants
access), for example.
I was wondering, what algorithms are used for example in Java and .NET for SessionId/AuthenticationToken generation. Is UUID indeed unsuitable for these purposes in an application that has more than average security needs?
发布评论
评论(2)
UUID
的生成是随机的,但是具有不良熵的随机意味着您最终会得到容易猜测的UUID
。如果您使用良好的随机数生成器,则可以生成可用于会话的UUID
。然而,问题在于UUID
没有内置的重播预防、篡改、固定等功能,您必须自己处理这些问题(阅读:UUID其本身不应被视为有效的会话 ID)。也就是说,这里有一个很好的片段,说明如何使用python
生成安全的UUID
:python 中的唯一会话 ID
UUID
generation is random, but random with bad entropy means that you will end up with easy to guessUUID
s. If you use a good random number generator, you can generateUUID
s that can be used for sessions. The catch to this, however, is thatUUID
s don't have built-in re-play prevention, tampering, fixation, etc., you have to handle that on your own (read: a UUID by itself shouldn't be considered a valid session ID by itself). That said, here's a good snippet for how you would generate a secureUUID
usingpython
:Unique session id in python
免责声明:我不是密码学家。
虽然一般来说这是正确的,但还应该注意的是,某些系统使用加密的强伪随机数生成器生成 UUID(例如 Java):
Tomcat 不使用 UUID 作为会话令牌,而是使用 SHA1PRNG 用于生成会话 ID 的安全随机生成器:
这只是默认值,您可以通过实现 org.apache 来提供自定义会话 ID 生成器.catalina.SessionIdGenerator 接口。
除了在会话 ID 中使用随机生成的字符串之外,标准实现还添加了
jvmRoute
到它生成的会话 ID:此处已经讨论了
SHA1PRNG
的优势。Java UUID 几乎与 Tomcat 的默认会话 ID 生成器一样安全,后者生成 16 字节长的会话 ID:
Tomcat:
OpenJDK 7 中的 java.util.UUID:
但您可以将 Tomcat 的会话 ID 生成器配置为使用超过 16 个字节以提高安全性。
进一步阅读:
Disclaimer: I am not a cryptographer.
While in general that is true, it should also be noted that some systems produce UUIDs using cryptographically strong pseudo random number generators (e.g. Java):
Tomcat does not use UUIDs as session tokens but uses a SHA1PRNG secure random generator for producing session IDs:
This is just the default and you can provide your custom session ID generator by implementing the
org.apache.catalina.SessionIdGenerator
interface.Other than using a randomly generated string in the session ID, the standard implementation also adds a
jvmRoute
to the session IDs that it generates:Strength of
SHA1PRNG
has already been discussed here.Java UUIDs are almost as secure as Tomcat's default session ID generator which generates 16 byte long session IDs:
Tomcat:
java.util.UUID in OpenJDK 7:
But you can configure Tomcat's session ID generator to use more than 16 bytes for added security.
Further reading: