{-# OPTIONS_HADDOCK hide #-}{-# LANGUAGE RecordWildCards, BangPatterns, ViewPatterns, DeriveDataTypeable #-}moduleNetwork.Hermes.ProtocolwhereimportControl.ApplicativeimportControl.MonadimportControl.ExceptionimportData.TypeableimportData.DataimportqualifiedData.ByteStringasBimportqualifiedData.ByteString.Char8asB8importNetwork.Hermes.MiscimportData.SerializeimportData.Serialize.PutimportData.Serialize.GetimportCodec.Digest.SHAimportCodec.Crypto.RSAimportNetwork.Socket(HostName)importData.Serialize-- * Errors-- | Most Hermes functions can throw one of these exceptions, which-- | are mainly triggered when (re)negotiating connections.dataHermesException=HermesIDUnknownHermesID-- ^ Hermes has no idea who you're talking about. How did you even get the HermesID?-- HermesID information is never discarded, so this exception should be rather uncommon.|AddressUnknownHermesID-- ^ We don't know where this HermesID is; we never did, or old information proved to be false.|DNSFailureAddress-- ^ Failed to resolve the address|WrongProtocol-- ^ The remote server is not speaking Hermes-speak.|ProtocolVersionMismatchWord32Word32-- ^ A different protocol version is in use at the remote host. Check library version.|AuthErrorString-- ^ Something went wrong while authenticating. Have a reason.|DeserializationErrorString-- ^ Something went wrong while deserializing your data.|ListenerAlreadyExists-- ^ Attempted to create a listener on a port we're already listening to|MessageError-- ^ Message corrupted (connection broken)|Timeout-- ^ Some operation took longer than the user-configured timeout|RecvCancelled-- ^ Receive was explicitly cancelled by the userderiving(Typeable,Show,Eq)instanceExceptionHermesException-- | Exceptions that are handled by simply closing the connectiondataCloseException=EOFderiving(Typeable,Show,Eq)instanceExceptionCloseExceptiondecode'::Serializea=>B.ByteString->adecode'=either(throw.DeserializationError)id.decoderunGet'::Geta->B.ByteString->arunGet'g=either(throw.DeserializationError)id.runGetg-- * And some typesdataAddress=IPHostNameInt-- ^ Host name and port, IPv4, IPv6, or both|IPv4HostNameInt-- ^ IPv4 only|IPv6HostNameInt-- ^ IPv6 only|UnixFilePath-- ^ Unix domain socket, not available on Windowsderiving(Show,Read,Eq,Ord,Typeable,Data)instanceSerializeAddresswhereput(IPab)=putWord80>>puta>>putbput(IPv4ab)=putWord81>>puta>>putbput(IPv6ab)=putWord82>>puta>>putbput(Unixa)=putWord83>>putaget=dotag<-getWord8casetagof0->IP<$>get<*>get1->IPv4<$>get<*>get2->IPv6<$>get<*>get3->Unix<$>get_->error"Corrupted binary data for Address"-- * Cryptographic parameters-- | AES session key size, in bitsaesKeySize::IntaesKeySize=128-- | Cipher to use for encrypting the session keyevpCipher::StringevpCipher="aes-128-cbc"-- | Hash used all over the placeevpHash::StringevpHash="sha256"-- | RSA key size, in bits; 512 <= size <= 1024rsaKeySize::IntrsaKeySize=1024-- | DSA key size, for the signature authoritiesdsaKeySize::IntdsaKeySize=1024-- * Line protocol-- | Unchangeable bytes telling peers that this.. is... HERMES!magicString::B.ByteStringmagicString=B8.pack"This.. is... HERMES!\n"protocolVersion::Word32-- Do not change typeprotocolVersion=0dataKeyQuery=KeyOK|RequestKeyderiving(Show)-- | A hash computed from a public keytypeHermesID=IntegerdataKeyReply=KeyReply{keyReplyKey::PublicKey,keyReplySig::MaybeB.ByteString}deriving(Show)-- | If Indirect, require a signature from an authority.---- If Direct, require an OK from the library client.---- If None, no trust is required.dataTrustLevel=None|Indirect|Directderiving(Eq,Ord,Show)dataSessionSetup=SessionSetup{setupKey,setupIV,setupChallenge::B.ByteString,clientAddress::MaybeAddress}deriving(Show)dataAnyMessage=AKeyQueryKeyQuery|AKeyReplyKeyReply|AChallengeB.ByteString|ASessionSetupB.ByteString|AHermesIDHermesIDderiving(Show)-- | If a message (m :: t) is discarded, then a RejectedMessage is-- sent in reply, with (showType t,encode (original tag)) as the tag. The message body-- is discarded.dataRejectedMessage=RejectedMessagederiving(Typeable)instanceSerializeRejectedMessagewhereput_=return()get=returnRejectedMessageinstanceSerializePublicKeywhereputPublicKey{..}=putpublic_size>>putpublic_n>>putpublic_eget=dopublic_size<-getpublic_n<-getpublic_e<-getreturnPublicKey{..}instanceSerializePrivateKeywhereputPrivateKey{..}=putprivate_size>>putprivate_n>>putprivate_dget=doprivate_size<-getprivate_n<-getprivate_d<-getreturnPrivateKey{..}-- GENERATED STARTinstanceSerializeKeyQuerywhereputx=casexofKeyOK->putWord80RequestKey->putWord81get=doi<-getWord8caseiof0->returnKeyOK1->returnRequestKey_->error"Corrupted binary data for KeyQuery"instanceSerializeKeyReplywhereput(KeyReplyx1x2)=doputx1putx2get=dox1<-getx2<-getreturn(KeyReplyx1x2)instanceSerializeTrustLevelwhereputx=casexofNone->putWord80Indirect->putWord81Direct->putWord82get=doi<-getWord8caseiof0->returnNone1->returnIndirect2->returnDirect_->error"Corrupted binary data for TrustLevel"instanceSerializeSessionSetupwhereput(SessionSetupx1x2x3x4)=doputx1putx2putx3putx4get=dox1<-getx2<-getx3<-getx4<-getreturn(SessionSetupx1x2x3x4)instanceSerializeAnyMessagewhereputx=casexofAKeyQueryx1->doputWord81putx1AKeyReplyx1->doputWord82putx1AChallengex1->doputWord83putx1ASessionSetupx1->doputWord84putx1AHermesIDx1->doputWord85putx1get=doi<-getWord8caseiof1->dox1<-getreturn(AKeyQueryx1)2->dox1<-getreturn(AKeyReplyx1)3->dox1<-getreturn(AChallengex1)4->dox1<-getreturn(ASessionSetupx1)5->dox1<-getreturn(AHermesIDx1)_->error"Corrupted binary data for AnyMessage"-- GENERATED STOP