| Copyright | (c) simplex.chat |
|---|---|
| License | AGPL-3 |
| Maintainer | chat@simplex.chat |
| Stability | experimental |
| Portability | non-portable |
| Safe Haskell | Safe-Inferred |
| 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 p = 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. ATransport p
- transportName :: TProxy c p -> String
- transportConfig :: c p -> TransportConfig
- getTransportConnection :: TransportPeerI p => TransportConfig -> Bool -> CertificateChain -> Context -> IO (c p)
- certificateSent :: c p -> Bool
- getPeerCertChain :: c p -> CertificateChain
- tlsUnique :: c p -> SessionId
- getSessionALPN :: c p -> Maybe ALPN
- closeConnection :: c p -> IO ()
- cGet :: c p -> Int -> IO ByteString
- cPut :: c p -> ByteString -> IO ()
- getLn :: c p -> IO ByteString
- putLn :: c p -> ByteString -> IO ()
- data TProxy (c :: TransportPeer -> Type) (p :: TransportPeer) = TProxy
- data ATransport p = forall c.Transport c => ATransport (TProxy c p)
- type ASrvTransport = ATransport 'TServer
- data TransportPeer
- data STransportPeer (p :: TransportPeer) where
- class TransportPeerI p 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. TransportPeerI p => Context -> (ByteString -> IO (c p)) -> IO (c p)
- data THandle v c p = THandle {
- connection :: c p
- params :: THandleParams v p
- data THandleParams v p = 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 :: forall c. Transport c => CertificateChain -> APrivateSignKey -> c 'TServer -> KeyPairX25519 -> KeyHash -> VersionRangeSMP -> (SMPServiceRole -> CertificateChain -> Fingerprint -> ExceptT TransportError IO ServiceId) -> ExceptT TransportError IO (THandleSMP c 'TServer)
- smpClientHandshake :: forall c. Transport c => c 'TClient -> Maybe KeyPairX25519 -> KeyHash -> VersionRangeSMP -> Bool -> Maybe (ServiceCredentials, KeyPairEd25519) -> ExceptT TransportError IO (THandleSMP c 'TClient)
- tPutBlock :: Transport c => THandle v c p -> ByteString -> IO (Either TransportError ())
- tGetBlock :: Transport c => THandle v c p -> IO (Either TransportError ByteString)
- sendHandshake :: (Transport c, Encoding smp) => THandle v c p -> smp -> ExceptT TransportError IO ()
- getHandshake :: (Transport c, Encoding smp) => THandle v c p -> ExceptT TransportError IO smp
- smpTHParamsSetVersion :: 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 p = 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. ATransport p Source #
transportName :: TProxy c p -> String Source #
transportConfig :: c p -> TransportConfig Source #
getTransportConnection :: TransportPeerI p => TransportConfig -> Bool -> CertificateChain -> Context -> IO (c p) Source #
Upgrade TLS context to connection
certificateSent :: 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 :: c p -> CertificateChain Source #
TLS certificate chain, server's in the client, client's in the server (empty chain for non-service clients)
tlsUnique :: c p -> SessionId Source #
tls-unique channel binding per RFC5929
getSessionALPN :: c p -> Maybe ALPN Source #
ALPN value negotiated for the session
closeConnection :: c p -> IO () Source #
Close connection
cGet :: c p -> Int -> IO ByteString Source #
Read fixed number of bytes from connection
cPut :: c p -> ByteString -> IO () Source #
Write bytes to connection
getLn :: c p -> IO ByteString Source #
Receive ByteString from connection, allowing LF or CRLF termination.
putLn :: c p -> ByteString -> IO () Source #
Send ByteString to connection terminating it with CRLF.
Instances
data TProxy (c :: TransportPeer -> Type) (p :: TransportPeer) Source #
Constructors
| TProxy |
data ATransport p Source #
Constructors
| forall c.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 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
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. TransportPeerI p => Context -> (ByteString -> IO (c p)) -> IO (c p) Source #
SMP transport
The handle for SMP encrypted transport connection over Transport.
Constructors
| THandle | |
Fields
| |
data THandleParams v p 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
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
smpServerHandshake :: forall c. 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 :: forall c. 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 :: Transport c => THandle v c p -> ByteString -> IO (Either TransportError ()) Source #
Pad and send block to SMP transport.
tGetBlock :: Transport c => THandle v c p -> IO (Either TransportError ByteString) Source #
Receive block from SMP transport.
sendHandshake :: (Transport c, Encoding smp) => THandle v c p -> smp -> ExceptT TransportError IO () Source #
getHandshake :: (Transport c, Encoding smp) => THandle v c p -> ExceptT TransportError IO smp Source #