diff --git a/apps/simplex-directory-service/src/Directory/Events.hs b/apps/simplex-directory-service/src/Directory/Events.hs index 290742ce03..8ae7f60b3d 100644 --- a/apps/simplex-directory-service/src/Directory/Events.hs +++ b/apps/simplex-directory-service/src/Directory/Events.hs @@ -66,7 +66,7 @@ crDirectoryEvent :: Either ChatError ChatEvent -> Maybe DirectoryEvent crDirectoryEvent = \case Right evt -> crDirectoryEvent_ evt Left e -> case e of - ChatErrorAgent {agentError = BROKER _ NETWORK} -> Nothing + ChatErrorAgent {agentError = BROKER _ (NETWORK _)} -> Nothing ChatErrorAgent {agentError = BROKER _ TIMEOUT} -> Nothing _ -> Just $ DELogChatResponse $ "chat error: " <> tshow e diff --git a/bots/api/TYPES.md b/bots/api/TYPES.md index 4743ccb881..8353359484 100644 --- a/bots/api/TYPES.md +++ b/bots/api/TYPES.md @@ -121,6 +121,7 @@ This file is generated automatically. - [MsgFilter](#msgfilter) - [MsgReaction](#msgreaction) - [MsgReceiptStatus](#msgreceiptstatus) +- [NetworkError](#networkerror) - [NewUser](#newuser) - [NoteFolder](#notefolder) - [PendingContactConnection](#pendingcontactconnection) @@ -343,6 +344,7 @@ UNEXPECTED: NETWORK: - type: "NETWORK" +- networkError: [NetworkError](#networkerror) HOST: - type: "HOST" @@ -2635,6 +2637,34 @@ Unknown: - "badMsgHash" +--- + +## NetworkError + +**Discriminated union type**: + +ConnectError: +- type: "connectError" +- connectError: string + +TLSError: +- type: "tLSError" +- tlsError: string + +UnknownCAError: +- type: "unknownCAError" + +FailedError: +- type: "failedError" + +TimeoutError: +- type: "timeoutError" + +SubscribeError: +- type: "subscribeError" +- subscribeError: string + + --- ## NewUser diff --git a/bots/src/API/Docs/Types.hs b/bots/src/API/Docs/Types.hs index 758fc62d53..83675798af 100644 --- a/bots/src/API/Docs/Types.hs +++ b/bots/src/API/Docs/Types.hs @@ -42,7 +42,7 @@ import Simplex.Messaging.Agent.Protocol import Simplex.Messaging.Client import Simplex.Messaging.Crypto.File import Simplex.Messaging.Parsers (dropPrefix, fstToLower) -import Simplex.Messaging.Protocol (BlockingInfo (..), BlockingReason (..), CommandError (..), ErrorType (..), ProxyError (..)) +import Simplex.Messaging.Protocol (BlockingInfo (..), BlockingReason (..), CommandError (..), ErrorType (..), NetworkError (..), ProxyError (..)) import Simplex.Messaging.Transport import Simplex.RemoteControl.Types import System.Console.ANSI.Types (Color (..)) @@ -299,6 +299,7 @@ chatTypesDocsData = (sti @MsgFilter, STEnum, "MF", [], "", ""), (sti @MsgReaction, STUnion, "MR", [], "", ""), (sti @MsgReceiptStatus, STEnum, "MR", [], "", ""), + (sti @NetworkError, STUnion, "NE", [], "", ""), (sti @NewUser, STRecord, "", [], "", ""), (sti @NoteFolder, STRecord, "", [], "", ""), (sti @PendingContactConnection, STRecord, "", [], "", ""), @@ -492,6 +493,7 @@ deriving instance Generic MsgErrorType deriving instance Generic MsgFilter deriving instance Generic MsgReaction deriving instance Generic MsgReceiptStatus +deriving instance Generic NetworkError deriving instance Generic NewUser deriving instance Generic NoteFolder deriving instance Generic PendingContactConnection diff --git a/cabal.project b/cabal.project index 88f8b9aede..69982949dd 100644 --- a/cabal.project +++ b/cabal.project @@ -12,7 +12,7 @@ constraints: zip +disable-bzip2 +disable-zstd source-repository-package type: git location: https://github.com/simplex-chat/simplexmq.git - tag: 0319addd2b6bcd1206921c844f81fea4adc791a4 + tag: 2a61085f078417c6a0767d3e2d8162bac83c963c source-repository-package type: git diff --git a/packages/simplex-chat-client/types/typescript/src/types.ts b/packages/simplex-chat-client/types/typescript/src/types.ts index 1511c3851f..3a056293c5 100644 --- a/packages/simplex-chat-client/types/typescript/src/types.ts +++ b/packages/simplex-chat-client/types/typescript/src/types.ts @@ -216,6 +216,7 @@ export namespace BrokerErrorType { export interface NETWORK extends Interface { type: "NETWORK" + networkError: NetworkError } export interface HOST extends Interface { @@ -2915,6 +2916,55 @@ export enum MsgReceiptStatus { BadMsgHash = "badMsgHash", } +export type NetworkError = + | NetworkError.ConnectError + | NetworkError.TLSError + | NetworkError.UnknownCAError + | NetworkError.FailedError + | NetworkError.TimeoutError + | NetworkError.SubscribeError + +export namespace NetworkError { + export type Tag = + | "connectError" + | "tLSError" + | "unknownCAError" + | "failedError" + | "timeoutError" + | "subscribeError" + + interface Interface { + type: Tag + } + + export interface ConnectError extends Interface { + type: "connectError" + connectError: string + } + + export interface TLSError extends Interface { + type: "tLSError" + tlsError: string + } + + export interface UnknownCAError extends Interface { + type: "unknownCAError" + } + + export interface FailedError extends Interface { + type: "failedError" + } + + export interface TimeoutError extends Interface { + type: "timeoutError" + } + + export interface SubscribeError extends Interface { + type: "subscribeError" + subscribeError: string + } +} + export interface NewUser { profile?: Profile pastTimestamp: boolean diff --git a/scripts/nix/sha256map.nix b/scripts/nix/sha256map.nix index c424aeb9fc..945805e68f 100644 --- a/scripts/nix/sha256map.nix +++ b/scripts/nix/sha256map.nix @@ -1,5 +1,5 @@ { - "https://github.com/simplex-chat/simplexmq.git"."0319addd2b6bcd1206921c844f81fea4adc791a4" = "1rm0m6bch648xpa8l28m3ww6fi686g9ky68qc46gsqirpm29kh0q"; + "https://github.com/simplex-chat/simplexmq.git"."2a61085f078417c6a0767d3e2d8162bac83c963c" = "1zqssgz9d3bydcrnqlfy6aj7hfi65wb1mjcjpl3q744s82lrj68w"; "https://github.com/simplex-chat/hs-socks.git"."a30cc7a79a08d8108316094f8f2f82a0c5e1ac51" = "0yasvnr7g91k76mjkamvzab2kvlb1g5pspjyjn2fr6v83swjhj38"; "https://github.com/simplex-chat/direct-sqlcipher.git"."f814ee68b16a9447fbb467ccc8f29bdd3546bfd9" = "1ql13f4kfwkbaq7nygkxgw84213i0zm7c1a8hwvramayxl38dq5d"; "https://github.com/simplex-chat/sqlcipher-simple.git"."a46bd361a19376c5211f1058908fc0ae6bf42446" = "1z0r78d8f0812kxbgsm735qf6xx8lvaz27k1a0b4a2m0sshpd5gl"; diff --git a/src/Simplex/Chat/Library/Commands.hs b/src/Simplex/Chat/Library/Commands.hs index e1b0779e1f..d452255d71 100644 --- a/src/Simplex/Chat/Library/Commands.hs +++ b/src/Simplex/Chat/Library/Commands.hs @@ -4243,7 +4243,7 @@ subscribeUserConnections vr onlyNeeded agentBatchSubscribe user = do netStatus = maybe NSConnected $ NSError . errorNetworkStatus errorNetworkStatus :: ChatError -> String errorNetworkStatus = \case - ChatErrorAgent (BROKER _ NETWORK) _ -> "network" + ChatErrorAgent (BROKER _ (NETWORK _)) _ -> "network" ChatErrorAgent (SMP _ SMP.AUTH) _ -> "contact deleted" e -> show e -- TODO possibly below could be replaced with less noisy events for API diff --git a/src/Simplex/Chat/Library/Subscriber.hs b/src/Simplex/Chat/Library/Subscriber.hs index 3109fd5fe9..9ecc09004e 100644 --- a/src/Simplex/Chat/Library/Subscriber.hs +++ b/src/Simplex/Chat/Library/Subscriber.hs @@ -1601,7 +1601,7 @@ processAgentMessageConn vr user@User {userId} corrId agentConnId agentMessage = e -> SndErrOther $ tshow e where brokerError srvErr = \case - NETWORK -> SndErrExpired + NETWORK _ -> SndErrExpired TIMEOUT -> SndErrExpired HOST -> srvErr SrvErrHost SMP.TRANSPORT TEVersion -> srvErr SrvErrVersion diff --git a/src/Simplex/Chat/View.hs b/src/Simplex/Chat/View.hs index f31daf233c..89bc58171c 100644 --- a/src/Simplex/Chat/View.hs +++ b/src/Simplex/Chat/View.hs @@ -68,7 +68,7 @@ import qualified Simplex.Messaging.Crypto.Ratchet as CR import Simplex.Messaging.Encoding import Simplex.Messaging.Encoding.String import Simplex.Messaging.Parsers (dropPrefix, taggedObjectJSON) -import Simplex.Messaging.Protocol (AProtoServerWithAuth (..), AProtocolType, BlockingInfo (..), BlockingReason (..), ProtocolServer (..), ProtocolTypeI, SProtocolType (..), UserProtocol) +import Simplex.Messaging.Protocol (AProtoServerWithAuth (..), AProtocolType, BlockingInfo (..), BlockingReason (..), NetworkError (..), ProtocolServer (..), ProtocolTypeI, SProtocolType (..), UserProtocol) import qualified Simplex.Messaging.Protocol as SMP import Simplex.Messaging.Transport.Client (TransportHost (..)) import Simplex.Messaging.Util (safeDecodeUtf8, tshow) @@ -1515,11 +1515,11 @@ viewServerTestResult (AProtoServerWithAuth p _) = \case result <> [pName <> " server requires authorization to create queues, check password" | testStep == TSCreateQueue && (case testError of SMP _ SMP.AUTH -> True; _ -> False)] <> [pName <> " server requires authorization to upload files, check password" | testStep == TSCreateFile && (case testError of XFTP _ XFTP.AUTH -> True; _ -> False)] - <> ["Possibly, certificate fingerprint in " <> pName <> " server address is incorrect" | testStep == TSConnect && brokerErr] + <> ["Certificate fingerprint in " <> pName <> " server address does not match server certificate" | testStep == TSConnect && unknownCA] where result = [pName <> " server test failed at " <> plain (drop 2 $ show testStep) <> ", error: " <> sShow testError] - brokerErr = case testError of - BROKER _ NETWORK -> True + unknownCA = case testError of + BROKER _ (NETWORK NEUnknownCAError) -> True _ -> False _ -> [pName <> " server test passed"] where @@ -2546,7 +2546,7 @@ viewChatError isCmd logLevel testView = \case reasonStr = case reason of BRSpam -> "spam" BRContent -> "content violates conditions of use" - BROKER _ NETWORK | not isCmd -> [] + BROKER _ (NETWORK _) | not isCmd -> [] BROKER _ TIMEOUT | not isCmd -> [] AGENT A_DUPLICATE -> [withConnEntity <> "error: AGENT A_DUPLICATE" | logLevel == CLLDebug || isCmd] AGENT (A_PROHIBITED e) -> [withConnEntity <> "error: AGENT A_PROHIBITED, " <> plain e | logLevel <= CLLWarning || isCmd] diff --git a/tests/ChatTests/Direct.hs b/tests/ChatTests/Direct.hs index cac90936a8..5d64514277 100644 --- a/tests/ChatTests/Direct.hs +++ b/tests/ChatTests/Direct.hs @@ -1161,8 +1161,8 @@ testTestSMPServerConnection = alice ##> "/smp test smp://LcJUMfVhwD8yxjAiSaDzzGF3-kLG4Uh0Fl_ZIjrRwjI=:server_password@localhost:7001" alice <## "SMP server test passed" alice ##> "/smp test smp://LcJU@localhost:7001" - alice <## "SMP server test failed at Connect, error: BROKER {brokerAddress = \"smp://LcJU@localhost:7001\", brokerErr = NETWORK}" - alice <## "Possibly, certificate fingerprint in SMP server address is incorrect" + alice <## "SMP server test failed at Connect, error: BROKER {brokerAddress = \"smp://LcJU@localhost:7001\", brokerErr = NETWORK {networkError = NEUnknownCAError}}" + alice <## "Certificate fingerprint in SMP server address does not match server certificate" testGetSetXFTPServers :: HasCallStack => TestParams -> IO () testGetSetXFTPServers = @@ -1203,8 +1203,8 @@ testTestXFTPServer = alice ##> "/xftp test xftp://LcJUMfVhwD8yxjAiSaDzzGF3-kLG4Uh0Fl_ZIjrRwjI=:server_password@localhost:7002" alice <## "XFTP server test passed" alice ##> "/xftp test xftp://LcJU@localhost:7002" - alice <## "XFTP server test failed at Connect, error: BROKER {brokerAddress = \"xftp://LcJU@localhost:7002\", brokerErr = NETWORK}" - alice <## "Possibly, certificate fingerprint in XFTP server address is incorrect" + alice <## "XFTP server test failed at Connect, error: BROKER {brokerAddress = \"xftp://LcJU@localhost:7002\", brokerErr = NETWORK {networkError = NEUnknownCAError}}" + alice <## "Certificate fingerprint in XFTP server address does not match server certificate" testOperators :: HasCallStack => TestParams -> IO () testOperators =