Safe Haskell | None |
---|---|
Language | Haskell2010 |
Low-level details for talking to a Magic Wormhole peer.
For a user-facing interface, see MagicWormhole.Internal.Peer.
- data Connection = Connection {}
- newtype SessionKey = SessionKey ByteString
- data PeerError
- sendEncrypted :: Connection -> SessionKey -> Phase -> PlainText -> IO ()
- receiveEncrypted :: Connection -> SessionKey -> STM (Phase, PlainText)
- newtype PlainText = PlainText {}
- newtype CipherText = CipherText {}
- decrypt :: Key -> CipherText -> Either PeerError PlainText
- encrypt :: Key -> PlainText -> IO CipherText
- deriveKey :: SessionKey -> Purpose -> Key
- type Purpose = ByteString
- phasePurpose :: Side -> Phase -> Purpose
Documentation
data Connection Source #
A connection to a peer via the Rendezvous server.
Normally construct this with open
.
newtype SessionKey Source #
SPAKE2 key used for the duration of a Magic Wormhole peer-to-peer connection.
You can obtain a SessionKey
using pakeExchange
.
Individual messages will be encrypted using encrypt
(decrypt
), which
must be given a key that's generated from this one (see deriveKey
).
Something that went wrong with the client protocol.
CouldNotDecrypt ByteString | We received a message from the other side that we could not decrypt |
InvalidNonce ByteString | We could not determine the SecretBox nonce from the message we received |
MessageOutOfOrder Phase PlainText | We received a message for a phase that we have already received a message for. |
:: Connection | Connection to the peer |
-> SessionKey | The key established for this session |
-> Phase | Phase of the protocol this message represents |
-> PlainText | Content of the message |
-> IO () |
Send an encrypted message to the peer.
:: Connection | Connection to the peer |
-> SessionKey | The key established for this session |
-> STM (Phase, PlainText) | The phase and content of the message we received |
Pull a message from the peer and decrypt it. If the message fails to decrypt, an exception will be thrown, aborting the transaction and leaving the message on the queue.
Unencrypted text.
Exported for testing
newtype CipherText Source #
Encrypted text.
:: SessionKey | Key established for this session |
-> Purpose | What this key is for. Normally created using |
-> Key | A key to use once to send or receive a message |
Derive a one-off key from the SPAKE2 SessionKey
. Use this key only once.
type Purpose = ByteString Source #
The purpose of a message. deriveKey
combines this with the SessionKey
to make a unique Key
. Do not re-use a Purpose
to send more
than message.