Repository navigation
Conversation
There was a problem hiding this comment.
This change is a step backwards, contrary to the original intention of the per SSL DRBGs. Since the per SSL DRBGs are short-lived and private already, it does not make sense to fall back to using RAND_priv_bytes(). In particular since one looses the advantage of lock-free access. And the latter is an important aspect if one has a lot of concurrent SSL connections.
Also, I'm not sure whether the premaster secret qualifies as a long term secret.
There was a problem hiding this comment.
The client normally sends us the premaster secret encrypted to the server's RSA key. If decrypting that fails we'll end up using this random premaster secret and continue as if decryption was successful. So it's clearly not long term, in normal cases it's not even used at all.
There was a problem hiding this comment.
I prefer the original name ssl_randbytes (or even better ssl_rand_bytes, which would be more consistent with the naming scheme) and don't see any sense in adding the _public suffix. See my comment on "public" and "private" random output in #4641 (comment).
There was a problem hiding this comment.
ssl_randbytes() has been obsoleted by 16cfc2c. This needs to be rebased.
There was a problem hiding this comment.
IMHO, RAND_priv_bytes() should be only used for long term secrets like RSA and ECDSA private keys. These two keys look more like session keys to me. But I'm not so familiar with libssl details, since I'm mainly using libcrypto.
There was a problem hiding this comment.
That keys is used to send an encrypted ssl ticket to the client which the client can send back in the next connection. Note that this key is in an SSL_CTX, not an SSL. As far as I know we only generate this key once per SSL_CTX, so this key might be used for a lot of connections for a long time.
There was a problem hiding this comment.
Yes, I noticed that it's an SSL_CTX, so ssl_randbytes() can't be used. But I was not sure about the typical lifetime of an SSL_CTX. Does a webserver typically have only one or multiple SSL_CTX contexts? Does an SSL_CTX live througout the entire lifetime of the process? Is it passed on to forked children? etc., etc... As I said, I know too little about TLS implementation details.
Still, even if the process lives for some months, that's still much less than the lifetime of a certificate. So I thougth RAND_bytes() would be fine. But that's probably a matter of taste.
There was a problem hiding this comment.
It all depends on the application, but I think it is safe to assume that SSL_CTX is long lived and passed to children.
However, this case is interesting. An attacker would be able to grab an arbitrary amount of information from the DRBG which pushes toward using the public DRBG yet the values are long lived (process lifetime) which leans towards the private. It almost makes for a third kind.
We could instantiate a new DRBG for this and throw it away afterwards. Is this overkill?
|
The reason to start this pull request is so that people can comment on it to see in which direction it could be going. |
|
I've pushed a new commit with what I think the private/public split is. There are actually cases I'm not really sure about. |
|
I think there are many ways to slice this. Keep in mind that I don't think protecting against root, or other process that can our memory is worth trying to address. So the question becomes, can an adversary see something about one CSPRNG that gives it information about others? To me, that means having a CSPRNG per each SSL object, or if that is too much (memory or whatever) then for each SSL_CTX object. And then, maybe you have two at whatever level is appropriate -- one for private key material, and one for public. But also, maybe that is too much. I think it makes sense to have two CSPRNG's at the global level, maybe. What "public" key information is okay to leak? Maybe it's all private? Maybe for CMS, the bulk encryption key is kind of public, since it's protected via asymmetric crypto. I think more than two levels of CSPRNG are more than we need, but don't feel strongly about that. I think the second-level ones should seed off a global one, where the personalization string includes the memory address of the second-level object. Another way to slice this is to have one (maybe two) per thread. I have no information about which is better. I hope whoever works on this, or the related PR's, can justify their decisions with some facgts. |
|
So does anybody want to comment on how to go forward with this? I'm thinking about having 2 DRBGs in the SSL object, one that has as parent the public and the other the private DRBG. Did we have a discussion about this in some other PR/issue? |
|
There was discussion in another PR; @mspncp probably remembers where. FWIW I think two global generators is enough. Maybe one in the SSL object to avoid any "leakage." Right now it feels like we're headed toward a separate generator for every single time we need random bytes :) |
|
I don't remember the location, but I remember having said that the SSL drbg is in a sense already a private instance, so two SSL instances are IMHO a little overkill. I mean, we are talking about things like session keys, not long term secrets, right? |
|
I think a session is actually also long term. I expect that my TLS session still can't be decrypted in X years. Anyway, I think there are 2 ways that people seem to look at this:
If you look at something like ECDHE, you create a temporary key and sign the public key. It's at least my understanding that that temporary key is important to keep secret. In #5481 @richsalz insisted that we change from RAND_bytes() to RAND_priv_bytes() for it. But I guess some people could argue that the X functions should be done with the public RNG, and the ED with the private. For me it's usually at least clear what is considered private/secret vs public than what is long term or short term. Anyway, I would like to move as much as possible DRBG calls use the SSL specific DRBG, which is what #5510 does. That is currently at the point that I can set a break point at RAND_bytes() and never hit it (except in SSL_CTX_new()). The only place where I currently hit RAND_priv_bytes() is in the generation of a temporary key. But if people think this patch makes sense we would start taking the lock on the private DRBG more, and so it might make sense to have a private DRBG we don't need to lock. That could for instance be per SSL, or per thread. |
|
How hard would it be to automatically create two thread local DRBGs? |
Just to be sure that I understand your question right: Are you asking for the effort to replace the In theory, this would be a good idea, because it would make The drawback is that thread local storage is platform and compiler specific and might not be available everywhere. It would have to be an optional feature which could be selectively enabled on suitable platforms. So it's hard to say how big the effort is. Does OpenSSL currently use thread local storage at all? At first sight, the above picture looks a bit over-engineered, so I'm undeceded whether it's worth the effort. If at all, this would be a task for the next release. Let's discuss this after the code freeze in more detail. |
|
We have thread support, including thread local storage, for pthread and windows. If it's not enabled, we don't even take a lock. |
|
So is it that what I sketched in my last post what you were thinking of? |
|
It's at least one way of doing it. |
|
I'm okay moving the two global drbgs to be per thread. I think I mentioned per thread drbg's at one point but I was think of them in addition to the two global ones rather than replacing them. I don't see a necessity for two per ssl drbg's but wouldn't object to having them. The greater the separation the better I feel -- so long as the overhead isn't huge -- which it isn't. @richsalz I wouldn't want to see a per random request drbg either. |
There was a problem hiding this comment.
The comment Not all primes are private right in front of a call to BN_priv_rand() is a little confusing. And by the way: What does XXX: mean?
There was a problem hiding this comment.
Maybe I should replace it with TODO
There was a problem hiding this comment.
I'm not sure whether I always understand the rationale behind your choice of public vs. private rng.
There was a problem hiding this comment.
Anything that gets send to a peer is public, the rest is private.
There was a problem hiding this comment.
Why do you use the public drbg in bn_probable_prime_dh()and the private drbg in probable_prime()?
There was a problem hiding this comment.
That doesn't make sense at all ...
There was a problem hiding this comment.
(And clearly why the other one is marked as XXX/TODO)
There was a problem hiding this comment.
Oh, but this is about primes for use in DH, where the prime is actually send to the peer.
There was a problem hiding this comment.
ssl_randbytes() has been obsoleted by 16cfc2c. This needs to be rebased.
|
I will continue the review after the pull request is rebased. |
c517fb7 to
3a049d4
Compare
|
Is this still WIP or do you consider it ready-for-review? |
|
It's WIP because I didn't go over all the calls yet. |
mspncp
left a comment
There was a problem hiding this comment.
Looks good to me. But maybe somebody who is more familiar with the ssl code should also have a quick look over it (@richsalz? @mattcaswell?).
Reviewed-by: Dr. Matthias St. Pierre <[email protected]> Reviewed-by: Rich Salz <[email protected]> Fixes: #4641 GH: #4665
No description provided.