This code was originally in magic-wormhole, embedded in the server startup code. I carved it out to a separate file (with tests) in mailbox-server, but it should be used here too.