Skip to content

Add an anti-replay nonce facility - #325

Merged
bifurcation merged 8 commits into
masterfrom
anti-replay
Jun 10, 2015
Merged

bifurcation merged 8 commits into
masterfrom
anti-replay

Conversation

@bifurcation

Copy link
Copy Markdown
Contributor

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.

Comment thread wfe/web-front-end.go

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and ...?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow up on this: @bifurcation, you forgot to fix the comment here?

@jsha

jsha commented Jun 8, 2015

Copy link
Copy Markdown
Contributor

Thanks for implementing this! I'm in meetings all day today, but am planning to review tonight. Please wait on my review before merging.

@jcjones

jcjones commented Jun 8, 2015

Copy link
Copy Markdown
Contributor

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.

@jcjones

jcjones commented Jun 8, 2015

Copy link
Copy Markdown
Contributor

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.

@jsha

jsha commented Jun 8, 2015

Copy link
Copy Markdown
Contributor

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.

@jcjones

jcjones commented Jun 9, 2015

Copy link
Copy Markdown
Contributor

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.

@bifurcation

Copy link
Copy Markdown
Contributor Author

@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:

  • Nonce is an encrypted counter
  • Server stores:
    • Current counter value (latest valid counter)
    • Earliest valid counter (updated to constrain the size of the used counter list)
    • List of used counters between earliest and latest
  • Nonce is valid if it decrypts to a counter value that is (1) in the valid range, and (2) not on the used list.

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.

@jcjones

jcjones commented Jun 9, 2015

Copy link
Copy Markdown
Contributor

@bifurcation your new proposal sounds like a great thing, to me. I think it would be best if it get pulled into the utils package for invdividual testing, and that it accept an encryption key on initialization so it's easier to test and easier to adjust in the future. For now, I think having it generate a random key at start is OK.

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.

@bifurcation

Copy link
Copy Markdown
Contributor Author

We can also have WFE instances share state. I've created a NonceService struct under core that we can translate to something backed by common storage if we want to. New commit coming soon.

@bifurcation

Copy link
Copy Markdown
Contributor Author

Previous commit moves the nonces over to a better framework. Still need to update the WFE tests so that they pass.

@jsha

jsha commented Jun 9, 2015

Copy link
Copy Markdown
Contributor

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:

nonce = util.b64enc(bytesToBuffer(forge.random.getBytesSync(NONCE_SIZE)));

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.

@jsha

jsha commented Jun 9, 2015

Copy link
Copy Markdown
Contributor

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.

@bifurcation

Copy link
Copy Markdown
Contributor Author

@jsha, sorry forgot to git add the new files. This new push should have that implementation, as well as making the tests pass. I am working on making a PR for go-jose, but I'm not going to gate on them.

@jcjones

jcjones commented Jun 10, 2015

Copy link
Copy Markdown
Contributor

Looks good to merge. I'm sure there's more to do, but it's fine for now.

bifurcation added a commit that referenced this pull request Jun 10, 2015
Add an anti-replay nonce facility
@bifurcation
bifurcation merged commit 676ebf7 into master Jun 10, 2015
@jsha

jsha commented Jun 10, 2015

Copy link
Copy Markdown
Contributor

@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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants