Safe Haskell | None |
---|---|
Language | Haskell2010 |
Low-level details for talking to a Magic Wormhole peer.
For a user-facing interface, see MagicWormhole.Internal.Peer.
Synopsis
- data Connection = Connection {}
- newtype SessionKey = SessionKey ByteString
- data PeerError
- = CouldNotDecrypt ByteString
- | InvalidNonce ByteString
- | MessageOutOfOrder Phase PlainText
- sendEncrypted :: Connection -> SessionKey -> Phase -> PlainText -> IO ()
- receiveEncrypted :: Connection -> SessionKey -> STM (Phase, PlainText)
- newtype PlainText = PlainText {
- plainTextToByteString :: ByteString
- newtype CipherText = CipherText {
- cipherTextToByteString :: ByteString
- 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
).
SessionKey ByteString |
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. |
Instances
Eq PeerError Source # | |
Show PeerError Source # | |
Exception PeerError Source # | |
Defined in MagicWormhole.Internal.ClientProtocol toException :: PeerError -> SomeException fromException :: SomeException -> Maybe PeerError displayException :: PeerError -> String |
:: 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.
PlainText | |
|
Exported for testing
newtype CipherText Source #
Encrypted text.
CipherText | |
|
Instances
Eq CipherText Source # | |
Defined in MagicWormhole.Internal.ClientProtocol (==) :: CipherText -> CipherText -> Bool (/=) :: CipherText -> CipherText -> Bool | |
Ord CipherText Source # | |
Defined in MagicWormhole.Internal.ClientProtocol compare :: CipherText -> CipherText -> Ordering (<) :: CipherText -> CipherText -> Bool (<=) :: CipherText -> CipherText -> Bool (>) :: CipherText -> CipherText -> Bool (>=) :: CipherText -> CipherText -> Bool max :: CipherText -> CipherText -> CipherText min :: CipherText -> CipherText -> CipherText | |
Show CipherText Source # | |
Defined in MagicWormhole.Internal.ClientProtocol showsPrec :: Int -> CipherText -> ShowS show :: CipherText -> String showList :: [CipherText] -> ShowS |
encrypt :: Key -> PlainText -> IO CipherText Source #
:: 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.