Repository navigation
Add an anti-replay nonce facility - #325
Conversation
There was a problem hiding this comment.
Follow up on this: @bifurcation, you forgot to fix the comment here?
|
Thanks for implementing this! I'm in meetings all day today, but am planning to review tonight. Please wait on my review before merging. |
|
This is a good start. If you want to proceed with the merge after @jsha's review, that's fine, but we also need to at least open a ticket to deal with bounding the growth of the nonce table. There are a variety of strategies we can use to provide both bounded growth, and bounded seek times on the nonces. The bounded growth can just be a compile-time constant for now; if we see the need to adjust it significantly, we can do it later. I would recommend we aim to maintain no more than 256 MB of nonces, or to bound at ~ 7.5 million entries. That should be something around 25 ms per transaction to find the nonce, and gives clients exceptional breathing room under high load scenarios that their nonce shouldn't expire prematurely. Or we could be nice and binary and go for 65535 entries, which would probably be fine too. |
|
Oh, and since we're working on the map from many goroutines, we'll need to be threadsafe in the cache implementation. We should probably pull it into a utils class to be separately tested. |
|
This implements the version of nonces that I originally proposed, where the server remembers the nonces it has seen and rejects ones it sees twice. @ekr pointed out on the mailing list that this approach fails badly when there is any loss of state, and instead the server should create the nonces and expect to receive them back from the client. I agree with this criticism, and I think we should implement the approach he suggests. |
|
I'm confused, @jsha. This patch has the server creating the nonces and putting them in response headers and then expecting to receive them back from the client. I don't believe there is any difference between what ekr suggested and this implementation. |
|
@jsha I agree with JC that you have this backwards. This is EKR's proposal. It fails closed if you lose state -- client requests are rejected until they get a fresh nonce. As opposed to a scheme where you just remember which nonces a client has sent and reject duplicates (my original proposal), which fails open when you lose state. @jcjones I agree that we should limit size here, but I'm concerned about a cascading DOS where the attacker exhausts the nonce table, then all clients start requesting nonces. To defend against that, it seems like we need a system where issuing nonces is cheap, but using them is expensive. I think that something like the following will work:
Since the expensive resource here is the list of used counters, the attacker has to do a signature operation for every counter he wants to add to the list. |
|
@bifurcation your new proposal sounds like a great thing, to me. I think it would be best if it get pulled into the In deployment when we have multiple copies of the WFE running, we'll be instructing the load balancers to ensure that clients connect to the same WFE instance on each transaction, within a several hour window. Outside that window, or in the event of a fault requiring failover, the client's nonces would be invalid. That seems OK here as long as the client development handles the case properly. |
|
We can also have WFE instances share state. I've created a NonceService struct under |
|
Previous commit moves the nonces over to a better framework. Still need to update the WFE tests so that they pass. |
|
Sorry for the confusion about which style of nonce this implemented. I was in a rush and misread this line in crypt-util.js as indicating that the client was generating its own nonces: But I see now that's only used when nonceIn isn't provided. Will review now. To make sure I understand: Under the encrypted counter approach, the idea is that the server will always lose the counter state at the same time it loses the "already seen" state? And on server restart, we'll see a wave of 403's from clients needing new nonces? I think we probably shouldn't be treating signatures as a proof-of-work to slow down attackers. They are very cheap. One possible alternative: The server issues and stores nonces, and buckets them per registration. Each registration would have a maximum of N active nonces. That way an attacker can only flood the nonce table for their own registration. They could still cause excess server load, but that should be covered by general rate limiting. POSTs that are not required to be associated with a registration could be bucketed by IP address instead. |
|
It looks like the implementation of core.NewNonceService is not in this change. Can you add it? Also, can you send a pull request against go-jose for the return-header functionality and link it here? It might be easier for them to accept if we make it a non-API-breaking change, like adding VerifyWithHeader. |
|
@jsha, sorry forgot to |
|
Looks good to merge. I'm sure there's more to do, but it's fine for now. |
Add an anti-replay nonce facility
|
@bifurcation, merging this before I got a chance to read core.NewNonceService doesn't follow the spirit of the code review rules we all agreed on. You also did not address the substantive concerns and questions I raised in #325 (comment). |
This PR implements the replay-nonce facility recently added to the ACME spec, along with corresponding updates to tests. It does not implement the "acmeUrl" / "acmePath" facility.
The one unfortunate thing about the current patch is that it monkey-patches the JOSE library to expose the protected header. I will try to get that pushed upstream, but in the mean-time, we may have to be careful about updating go-jose.