| Copyright | (c) simplex.chat |
|---|---|
| License | AGPL-3 |
| Maintainer | chat@simplex.chat |
| Stability | experimental |
| Portability | non-portable |
| Safe Haskell | None |
| Language | Haskell2010 |
Simplex.Messaging.Transport
Description
This module defines basic TCP server and client and SMP protocol encrypted transport over TCP.
See https://github.com/simplex-chat/simplexmq/blob/master/protocol/simplex-messaging.md#appendix-a
Synopsis
- data SMPVersion
- type VersionSMP = Version SMPVersion
- type VersionRangeSMP = VersionRange SMPVersion
- type THandleSMP (c :: TransportPeer -> Type) (p :: TransportPeer) = THandle SMPVersion c p
- alpnSupportedSMPHandshakes :: [ALPN]
- supportedClientSMPRelayVRange :: VersionRangeSMP
- supportedServerSMPRelayVRange :: VersionRangeSMP
- supportedProxyClientSMPRelayVRange :: VersionRangeSMP
- proxiedSMPRelayVRange :: VersionRangeSMP
- minClientSMPRelayVersion :: VersionSMP
- minServerSMPRelayVersion :: VersionSMP
- currentClientSMPRelayVersion :: VersionSMP
- currentServerSMPRelayVersion :: VersionSMP
- authCmdsSMPVersion :: VersionSMP
- sendingProxySMPVersion :: VersionSMP
- sndAuthKeySMPVersion :: VersionSMP
- deletedEventSMPVersion :: VersionSMP
- encryptedBlockSMPVersion :: VersionSMP
- blockedEntitySMPVersion :: VersionSMP
- shortLinksSMPVersion :: VersionSMP
- serviceCertsSMPVersion :: VersionSMP
- newNtfCredsSMPVersion :: VersionSMP
- clientNoticesSMPVersion :: VersionSMP
- simplexMQVersion :: String
- smpBlockSize :: Int
- data TransportConfig = TransportConfig {
- logTLSErrors :: Bool
- transportTimeout :: Maybe Int
- class Typeable c => Transport (c :: TransportPeer -> Type) where
- transport :: forall (p :: TransportPeer). ATransport p
- transportName :: forall (p :: TransportPeer). TProxy c p -> String
- transportConfig :: forall (p :: TransportPeer). c p -> TransportConfig
- getTransportConnection :: forall (p :: TransportPeer). TransportPeerI p => TransportConfig -> Bool -> CertificateChain -> Context -> IO (c p)
- certificateSent :: forall (p :: TransportPeer). c p -> Bool
- getPeerCertChain :: forall (p :: TransportPeer). c p -> CertificateChain
- tlsUnique :: forall (p :: TransportPeer). c p -> SessionId
- getSessionALPN :: forall (p :: TransportPeer). c p -> Maybe ALPN
- closeConnection :: forall (p :: TransportPeer). c p -> IO ()
- cGet :: forall (p :: TransportPeer). c p -> Int -> IO ByteString
- cPut :: forall (p :: TransportPeer). c p -> ByteString -> IO ()
- getLn :: forall (p :: TransportPeer). c p -> IO ByteString
- putLn :: forall (p :: TransportPeer). c p -> ByteString -> IO ()
- data TProxy (c :: TransportPeer -> Type) (p :: TransportPeer) = TProxy
- data ATransport (p :: TransportPeer) = Transport c => ATransport (TProxy c p)
- type ASrvTransport = ATransport 'TServer
- data TransportPeer
- data STransportPeer (p :: TransportPeer) where
- class TransportPeerI (p :: TransportPeer) where
- getServerVerifyKey :: Transport c => c 'TClient -> Either String APublicVerifyKey
- data TLS (p :: TransportPeer) = TLS {
- tlsContext :: Context
- tlsUniq :: ByteString
- tlsBuffer :: TBuffer
- tlsALPN :: Maybe ALPN
- tlsCertSent :: Bool
- tlsPeerCert :: CertificateChain
- tlsTransportConfig :: TransportConfig
- type SessionId = ByteString
- type ServiceId = EntityId
- newtype EntityId = EntityId {
- unEntityId :: ByteString
- pattern NoEntity :: EntityId
- type ALPN = ByteString
- connectTLS :: TLSParams p => Maybe HostName -> TransportConfig -> p -> Socket -> IO Context
- closeTLS :: Context -> IO ()
- defaultSupportedParams :: Supported
- defaultSupportedParamsHTTPS :: Supported
- withTlsUnique :: forall c (p :: TransportPeer). TransportPeerI p => Context -> (ByteString -> IO (c p)) -> IO (c p)
- data THandle v (c :: TransportPeer -> Type) (p :: TransportPeer) = THandle {
- connection :: c p
- params :: THandleParams v p
- data THandleParams v (p :: TransportPeer) = THandleParams {
- sessionId :: SessionId
- blockSize :: Int
- thServerVRange :: VersionRange v
- thVersion :: Version v
- thAuth :: Maybe (THandleAuth p)
- implySessId :: Bool
- encryptBlock :: Maybe TSbChainKeys
- batch :: Bool
- serviceAuth :: Bool
- data THandleAuth (p :: TransportPeer) where
- THAuthClient :: {..} -> THandleAuth 'TClient
- THAuthServer :: {..} -> THandleAuth 'TServer
- data CertChainPubKey = CertChainPubKey {
- certChain :: CertificateChain
- signedPubKey :: SignedExact PubKey
- data ServiceCredentials = ServiceCredentials {
- serviceRole :: SMPServiceRole
- serviceCreds :: Credential
- serviceCertHash :: Fingerprint
- serviceSignKey :: APrivateSignKey
- data THClientService' k = THClientService {
- serviceId :: ServiceId
- serviceRole :: SMPServiceRole
- serviceCertHash :: Fingerprint
- serviceKey :: k
- type THClientService = THClientService' PrivateKeyEd25519
- type THPeerClientService = THClientService' PublicKeyEd25519
- data SMPServiceRole
- data TSbChainKeys = TSbChainKeys {
- sndKey :: TVar SbChainKey
- rcvKey :: TVar SbChainKey
- data TransportError
- data HandshakeError
- = PARSE
- | IDENTITY
- | BAD_AUTH
- | BAD_SERVICE
- smpServerHandshake :: Transport c => CertificateChain -> APrivateSignKey -> c 'TServer -> KeyPairX25519 -> KeyHash -> VersionRangeSMP -> (SMPServiceRole -> CertificateChain -> Fingerprint -> ExceptT TransportError IO ServiceId) -> ExceptT TransportError IO (THandleSMP c 'TServer)
- smpClientHandshake :: Transport c => c 'TClient -> Maybe KeyPairX25519 -> KeyHash -> VersionRangeSMP -> Bool -> Maybe (ServiceCredentials, KeyPairEd25519) -> ExceptT TransportError IO (THandleSMP c 'TClient)
- tPutBlock :: forall (c :: TransportPeer -> Type) v (p :: TransportPeer). Transport c => THandle v c p -> ByteString -> IO (Either TransportError ())
- tGetBlock :: forall (c :: TransportPeer -> Type) v (p :: TransportPeer). Transport c => THandle v c p -> IO (Either TransportError ByteString)
- sendHandshake :: forall (c :: TransportPeer -> Type) smp v (p :: TransportPeer). (Transport c, Encoding smp) => THandle v c p -> smp -> ExceptT TransportError IO ()
- getHandshake :: forall (c :: TransportPeer -> Type) smp v (p :: TransportPeer). (Transport c, Encoding smp) => THandle v c p -> ExceptT TransportError IO smp
- smpTHParamsSetVersion :: forall (p :: TransportPeer). VersionSMP -> THandleParams SMPVersion p -> THandleParams SMPVersion p
SMP transport parameters
data SMPVersion Source #
Instances
type VersionSMP = Version SMPVersion Source #
type VersionRangeSMP = VersionRange SMPVersion Source #
type THandleSMP (c :: TransportPeer -> Type) (p :: TransportPeer) = THandle SMPVersion c p Source #
simplexMQVersion :: String Source #
smpBlockSize :: Int Source #
data TransportConfig Source #
Constructors
| TransportConfig | |
Fields
| |
Transport connection class
class Typeable c => Transport (c :: TransportPeer -> Type) where Source #
Minimal complete definition
transportName, transportConfig, getTransportConnection, certificateSent, getPeerCertChain, tlsUnique, getSessionALPN, closeConnection, cGet, cPut, getLn
Methods
transport :: forall (p :: TransportPeer). ATransport p Source #
transportName :: forall (p :: TransportPeer). TProxy c p -> String Source #
transportConfig :: forall (p :: TransportPeer). c p -> TransportConfig Source #
getTransportConnection :: forall (p :: TransportPeer). TransportPeerI p => TransportConfig -> Bool -> CertificateChain -> Context -> IO (c p) Source #
Upgrade TLS context to connection
certificateSent :: forall (p :: TransportPeer). c p -> Bool Source #
Whether TLS certificate chain was provided to peer It is always True for the server. It is True for the client when server requested it AND non-empty chain is sent.
getPeerCertChain :: forall (p :: TransportPeer). c p -> CertificateChain Source #
TLS certificate chain, server's in the client, client's in the server (empty chain for non-service clients)
tlsUnique :: forall (p :: TransportPeer). c p -> SessionId Source #
tls-unique channel binding per RFC5929
getSessionALPN :: forall (p :: TransportPeer). c p -> Maybe ALPN Source #
ALPN value negotiated for the session
closeConnection :: forall (p :: TransportPeer). c p -> IO () Source #
Close connection
cGet :: forall (p :: TransportPeer). c p -> Int -> IO ByteString Source #
Read fixed number of bytes from connection
cPut :: forall (p :: TransportPeer). c p -> ByteString -> IO () Source #
Write bytes to connection
getLn :: forall (p :: TransportPeer). c p -> IO ByteString Source #
Receive ByteString from connection, allowing LF or CRLF termination.
putLn :: forall (p :: TransportPeer). c p -> ByteString -> IO () Source #
Send ByteString to connection terminating it with CRLF.
Instances
| Transport TLS Source # | |
Defined in Simplex.Messaging.Transport Methods transport :: forall (p :: TransportPeer). ATransport p Source # transportName :: forall (p :: TransportPeer). TProxy TLS p -> String Source # transportConfig :: forall (p :: TransportPeer). TLS p -> TransportConfig Source # getTransportConnection :: forall (p :: TransportPeer). TransportPeerI p => TransportConfig -> Bool -> CertificateChain -> Context -> IO (TLS p) Source # certificateSent :: forall (p :: TransportPeer). TLS p -> Bool Source # getPeerCertChain :: forall (p :: TransportPeer). TLS p -> CertificateChain Source # tlsUnique :: forall (p :: TransportPeer). TLS p -> SessionId Source # getSessionALPN :: forall (p :: TransportPeer). TLS p -> Maybe ALPN Source # closeConnection :: forall (p :: TransportPeer). TLS p -> IO () Source # cGet :: forall (p :: TransportPeer). TLS p -> Int -> IO ByteString Source # cPut :: forall (p :: TransportPeer). TLS p -> ByteString -> IO () Source # getLn :: forall (p :: TransportPeer). TLS p -> IO ByteString Source # putLn :: forall (p :: TransportPeer). TLS p -> ByteString -> IO () Source # | |
| Transport WS Source # | |
Defined in Simplex.Messaging.Transport.WebSockets Methods transport :: forall (p :: TransportPeer). ATransport p Source # transportName :: forall (p :: TransportPeer). TProxy WS p -> String Source # transportConfig :: forall (p :: TransportPeer). WS p -> TransportConfig Source # getTransportConnection :: forall (p :: TransportPeer). TransportPeerI p => TransportConfig -> Bool -> CertificateChain -> Context -> IO (WS p) Source # certificateSent :: forall (p :: TransportPeer). WS p -> Bool Source # getPeerCertChain :: forall (p :: TransportPeer). WS p -> CertificateChain Source # tlsUnique :: forall (p :: TransportPeer). WS p -> SessionId Source # getSessionALPN :: forall (p :: TransportPeer). WS p -> Maybe ALPN Source # closeConnection :: forall (p :: TransportPeer). WS p -> IO () Source # cGet :: forall (p :: TransportPeer). WS p -> Int -> IO ByteString Source # cPut :: forall (p :: TransportPeer). WS p -> ByteString -> IO () Source # getLn :: forall (p :: TransportPeer). WS p -> IO ByteString Source # putLn :: forall (p :: TransportPeer). WS p -> ByteString -> IO () Source # | |
data TProxy (c :: TransportPeer -> Type) (p :: TransportPeer) Source #
Constructors
| TProxy |
data ATransport (p :: TransportPeer) Source #
Constructors
| Transport c => ATransport (TProxy c p) |
type ASrvTransport = ATransport 'TServer Source #
data TransportPeer Source #
Instances
| Show TransportPeer Source # | |
Defined in Simplex.Messaging.Transport Methods showsPrec :: Int -> TransportPeer -> ShowS show :: TransportPeer -> String showList :: [TransportPeer] -> ShowS | |
| Eq TransportPeer Source # | |
Defined in Simplex.Messaging.Transport | |
data STransportPeer (p :: TransportPeer) where Source #
Constructors
| STClient :: STransportPeer 'TClient | |
| STServer :: STransportPeer 'TServer |
class TransportPeerI (p :: TransportPeer) where Source #
Methods
Instances
| TransportPeerI 'TClient Source # | |
Defined in Simplex.Messaging.Transport Methods | |
| TransportPeerI 'TServer Source # | |
Defined in Simplex.Messaging.Transport Methods | |
getServerVerifyKey :: Transport c => c 'TClient -> Either String APublicVerifyKey Source #
TLS Transport
data TLS (p :: TransportPeer) Source #
Constructors
| TLS | |
Fields
| |
Instances
| Transport TLS Source # | |
Defined in Simplex.Messaging.Transport Methods transport :: forall (p :: TransportPeer). ATransport p Source # transportName :: forall (p :: TransportPeer). TProxy TLS p -> String Source # transportConfig :: forall (p :: TransportPeer). TLS p -> TransportConfig Source # getTransportConnection :: forall (p :: TransportPeer). TransportPeerI p => TransportConfig -> Bool -> CertificateChain -> Context -> IO (TLS p) Source # certificateSent :: forall (p :: TransportPeer). TLS p -> Bool Source # getPeerCertChain :: forall (p :: TransportPeer). TLS p -> CertificateChain Source # tlsUnique :: forall (p :: TransportPeer). TLS p -> SessionId Source # getSessionALPN :: forall (p :: TransportPeer). TLS p -> Maybe ALPN Source # closeConnection :: forall (p :: TransportPeer). TLS p -> IO () Source # cGet :: forall (p :: TransportPeer). TLS p -> Int -> IO ByteString Source # cPut :: forall (p :: TransportPeer). TLS p -> ByteString -> IO () Source # getLn :: forall (p :: TransportPeer). TLS p -> IO ByteString Source # putLn :: forall (p :: TransportPeer). TLS p -> ByteString -> IO () Source # | |
Constructors
| EntityId | |
Fields
| |
Instances
| Show EntityId Source # | |
| Eq EntityId Source # | |
| Ord EntityId Source # | |
Defined in Simplex.Messaging.Transport | |
| Encoding EntityId Source # | |
| StrEncoding EntityId Source # | |
| FromField EntityId Source # | |
Defined in Simplex.Messaging.Agent.Store.AgentStore | |
| ToField EntityId Source # | |
Defined in Simplex.Messaging.Agent.Store.AgentStore | |
connectTLS :: TLSParams p => Maybe HostName -> TransportConfig -> p -> Socket -> IO Context Source #
defaultSupportedParams :: Supported Source #
defaultSupportedParamsHTTPS :: Supported Source #
A selection of extra parameters to accomodate browser chains
withTlsUnique :: forall c (p :: TransportPeer). TransportPeerI p => Context -> (ByteString -> IO (c p)) -> IO (c p) Source #
SMP transport
data THandle v (c :: TransportPeer -> Type) (p :: TransportPeer) Source #
The handle for SMP encrypted transport connection over Transport.
Constructors
| THandle | |
Fields
| |
data THandleParams v (p :: TransportPeer) Source #
Constructors
| THandleParams | |
Fields
| |
data THandleAuth (p :: TransportPeer) where Source #
Constructors
| THAuthClient | |
Fields
| |
| THAuthServer | |
Fields
| |
data CertChainPubKey Source #
Constructors
| CertChainPubKey | |
Fields
| |
Instances
| Show CertChainPubKey Source # | |
Defined in Simplex.Messaging.Transport Methods showsPrec :: Int -> CertChainPubKey -> ShowS show :: CertChainPubKey -> String showList :: [CertChainPubKey] -> ShowS | |
| Eq CertChainPubKey Source # | |
Defined in Simplex.Messaging.Transport Methods (==) :: CertChainPubKey -> CertChainPubKey -> Bool (/=) :: CertChainPubKey -> CertChainPubKey -> Bool | |
| Encoding CertChainPubKey Source # | |
Defined in Simplex.Messaging.Transport Methods smpEncode :: CertChainPubKey -> ByteString Source # smpDecode :: ByteString -> Either String CertChainPubKey Source # smpP :: Parser CertChainPubKey Source # | |
data ServiceCredentials Source #
Constructors
| ServiceCredentials | |
Fields
| |
data THClientService' k Source #
Constructors
| THClientService | |
Fields
| |
data SMPServiceRole Source #
Constructors
| SRMessaging | |
| SRNotifier | |
| SRProxy |
Instances
| Show SMPServiceRole Source # | |
Defined in Simplex.Messaging.Transport Methods showsPrec :: Int -> SMPServiceRole -> ShowS show :: SMPServiceRole -> String showList :: [SMPServiceRole] -> ShowS | |
| Eq SMPServiceRole Source # | |
Defined in Simplex.Messaging.Transport Methods (==) :: SMPServiceRole -> SMPServiceRole -> Bool (/=) :: SMPServiceRole -> SMPServiceRole -> Bool | |
| Encoding SMPServiceRole Source # | |
Defined in Simplex.Messaging.Transport Methods smpEncode :: SMPServiceRole -> ByteString Source # smpDecode :: ByteString -> Either String SMPServiceRole Source # smpP :: Parser SMPServiceRole Source # | |
data TSbChainKeys Source #
Constructors
| TSbChainKeys | |
Fields
| |
data TransportError Source #
Error of SMP encrypted transport over TCP.
Constructors
| TEBadBlock | error parsing transport block |
| TEVersion | incompatible client or server version |
| TELargeMsg | message does not fit in transport block |
| TEBadSession | incorrect session ID |
| TENoServerAuth | absent server key for v7 entity This error happens when the server did not provide a DH key to authorize commands for the queue that should be authorized with a DH key. |
| TEHandshake | transport handshake error |
Fields | |
Instances
| FromJSON TransportError Source # | |
Defined in Simplex.Messaging.Transport Methods parseJSON :: Value -> Parser TransportError parseJSONList :: Value -> Parser [TransportError] omittedField :: Maybe TransportError | |
| ToJSON TransportError Source # | |
Defined in Simplex.Messaging.Transport Methods toJSON :: TransportError -> Value toEncoding :: TransportError -> Encoding toJSONList :: [TransportError] -> Value toEncodingList :: [TransportError] -> Encoding omitField :: TransportError -> Bool | |
| Exception TransportError Source # | |
Defined in Simplex.Messaging.Transport Methods toException :: TransportError -> SomeException fromException :: SomeException -> Maybe TransportError displayException :: TransportError -> String | |
| Read TransportError Source # | |
Defined in Simplex.Messaging.Transport Methods readsPrec :: Int -> ReadS TransportError readList :: ReadS [TransportError] readPrec :: ReadPrec TransportError readListPrec :: ReadPrec [TransportError] | |
| Show TransportError Source # | |
Defined in Simplex.Messaging.Transport Methods showsPrec :: Int -> TransportError -> ShowS show :: TransportError -> String showList :: [TransportError] -> ShowS | |
| Eq TransportError Source # | |
Defined in Simplex.Messaging.Transport Methods (==) :: TransportError -> TransportError -> Bool (/=) :: TransportError -> TransportError -> Bool | |
| Encoding TransportError Source # | |
Defined in Simplex.Messaging.Transport Methods smpEncode :: TransportError -> ByteString Source # smpDecode :: ByteString -> Either String TransportError Source # smpP :: Parser TransportError Source # | |
data HandshakeError Source #
Transport handshake error.
Constructors
| PARSE | parsing error |
| IDENTITY | incorrect server identity |
| BAD_AUTH | v7 authentication failed |
| BAD_SERVICE | error reading/creating service record |
Instances
| FromJSON HandshakeError Source # | |
Defined in Simplex.Messaging.Transport Methods parseJSON :: Value -> Parser HandshakeError parseJSONList :: Value -> Parser [HandshakeError] omittedField :: Maybe HandshakeError | |
| ToJSON HandshakeError Source # | |
Defined in Simplex.Messaging.Transport Methods toJSON :: HandshakeError -> Value toEncoding :: HandshakeError -> Encoding toJSONList :: [HandshakeError] -> Value toEncodingList :: [HandshakeError] -> Encoding omitField :: HandshakeError -> Bool | |
| Exception HandshakeError Source # | |
Defined in Simplex.Messaging.Transport Methods toException :: HandshakeError -> SomeException fromException :: SomeException -> Maybe HandshakeError displayException :: HandshakeError -> String | |
| Read HandshakeError Source # | |
Defined in Simplex.Messaging.Transport Methods readsPrec :: Int -> ReadS HandshakeError readList :: ReadS [HandshakeError] readPrec :: ReadPrec HandshakeError readListPrec :: ReadPrec [HandshakeError] | |
| Show HandshakeError Source # | |
Defined in Simplex.Messaging.Transport Methods showsPrec :: Int -> HandshakeError -> ShowS show :: HandshakeError -> String showList :: [HandshakeError] -> ShowS | |
| Eq HandshakeError Source # | |
Defined in Simplex.Messaging.Transport Methods (==) :: HandshakeError -> HandshakeError -> Bool (/=) :: HandshakeError -> HandshakeError -> Bool | |
smpServerHandshake :: Transport c => CertificateChain -> APrivateSignKey -> c 'TServer -> KeyPairX25519 -> KeyHash -> VersionRangeSMP -> (SMPServiceRole -> CertificateChain -> Fingerprint -> ExceptT TransportError IO ServiceId) -> ExceptT TransportError IO (THandleSMP c 'TServer) Source #
Server SMP transport handshake.
See https://github.com/simplex-chat/simplexmq/blob/master/protocol/simplex-messaging.md#appendix-a
smpClientHandshake :: Transport c => c 'TClient -> Maybe KeyPairX25519 -> KeyHash -> VersionRangeSMP -> Bool -> Maybe (ServiceCredentials, KeyPairEd25519) -> ExceptT TransportError IO (THandleSMP c 'TClient) Source #
Client SMP transport handshake.
See https://github.com/simplex-chat/simplexmq/blob/master/protocol/simplex-messaging.md#appendix-a
tPutBlock :: forall (c :: TransportPeer -> Type) v (p :: TransportPeer). Transport c => THandle v c p -> ByteString -> IO (Either TransportError ()) Source #
Pad and send block to SMP transport.
tGetBlock :: forall (c :: TransportPeer -> Type) v (p :: TransportPeer). Transport c => THandle v c p -> IO (Either TransportError ByteString) Source #
Receive block from SMP transport.
sendHandshake :: forall (c :: TransportPeer -> Type) smp v (p :: TransportPeer). (Transport c, Encoding smp) => THandle v c p -> smp -> ExceptT TransportError IO () Source #
getHandshake :: forall (c :: TransportPeer -> Type) smp v (p :: TransportPeer). (Transport c, Encoding smp) => THandle v c p -> ExceptT TransportError IO smp Source #
smpTHParamsSetVersion :: forall (p :: TransportPeer). VersionSMP -> THandleParams SMPVersion p -> THandleParams SMPVersion p Source #