Disable bus encryption

This commit is contained in:
Sergey Ivanov 2023-07-04 21:55:03 +04:00
parent c403b77556
commit 9c408bcb03
1 changed files with 76 additions and 66 deletions

View File

@ -94,9 +94,19 @@ runProxyMessaging env = liftIO do
liftIO $ mapM_ waitCatch [u,t] liftIO $ mapM_ waitCatch [u,t]
instance Messaging ProxyMessaging L4Proto LBS.ByteString where instance Messaging ProxyMessaging L4Proto LBS.ByteString where
sendTo = sendToPlainProxyMessaging sendTo = sendToPlainProxyMessaging
receive = receiveFromProxyMessaging
receive bus _ = liftIO do
-- trace "PROXY: RECEIVE"
-- receive (view proxyUDP bus) w
let answ = view proxyAnswers bus
atomically $ do
r <- readTQueue answ
rs <- flushTQueue answ
pure (r:rs)
sendToPlainProxyMessaging :: (MonadIO m) sendToPlainProxyMessaging :: (MonadIO m)
=> ProxyMessaging => ProxyMessaging
@ -111,73 +121,73 @@ sendToPlainProxyMessaging bus t@(To whom) proto msg = do
TCP -> maybe1 (view proxyTCP bus) none $ \tcp -> do TCP -> maybe1 (view proxyTCP bus) none $ \tcp -> do
sendTo tcp t proto msg sendTo tcp t proto msg
-- sendToProxyMessaging :: (MonadIO m) sendToProxyMessaging :: (MonadIO m)
-- => ProxyMessaging => ProxyMessaging
-- -> To L4Proto -> To L4Proto
-- -> From L4Proto -> From L4Proto
-- -> LBS.ByteString -> LBS.ByteString
-- -> m () -> m ()
-- sendToProxyMessaging bus t@(To whom) proto msg = do sendToProxyMessaging bus t@(To whom) proto msg = do
-- -- sendTo (view proxyUDP bus) t proto msg -- sendTo (view proxyUDP bus) t proto msg
-- -- trace $ "PROXY: SEND" <+> pretty whom -- trace $ "PROXY: SEND" <+> pretty whom
-- encKey <- Map.lookup whom <$> (liftIO . readTVarIO) (view proxyEncryptionKeys bus) encKey <- Map.lookup whom <$> (liftIO . readTVarIO) (view proxyEncryptionKeys bus)
-- cf <- case encKey of cf <- case encKey of
-- Nothing -> do Nothing -> do
-- trace $ "ENCRYPTION SEND: sending plain message to" <+> pretty whom trace $ "ENCRYPTION SEND: sending plain message to" <+> pretty whom
-- pure id pure id
-- Just k -> do Just k -> do
-- trace $ "ENCRYPTION SEND: sending encrypted message to" <+> pretty whom <+> "with key" <+> viaShow k trace $ "ENCRYPTION SEND: sending encrypted message to" <+> pretty whom <+> "with key" <+> viaShow k
-- boxAfterNMLazy k <$> liftIO Encrypt.newNonce boxAfterNMLazy k <$> liftIO Encrypt.newNonce
-- sendTo (PlainProxyMessaging bus) t proto (cf msg) sendToPlainProxyMessaging bus t proto (cf msg)
-- receiveFromProxyMessaging :: MonadIO m receiveFromProxyMessaging :: MonadIO m
-- => ProxyMessaging -> To L4Proto -> m [(From L4Proto, LBS.ByteString)] => ProxyMessaging -> To L4Proto -> m [(From L4Proto, LBS.ByteString)]
-- receiveFromProxyMessaging bus _ = liftIO do receiveFromProxyMessaging bus _ = liftIO do
-- -- trace "PROXY: RECEIVE" -- trace "PROXY: RECEIVE"
-- -- receive (view proxyUDP bus) w -- receive (view proxyUDP bus) w
-- let answ = view proxyAnswers bus let answ = view proxyAnswers bus
-- rs <- atomically $ liftM2 (:) (readTQueue answ) (flushTQueue answ) rs <- atomically $ liftM2 (:) (readTQueue answ) (flushTQueue answ)
-- fmap catMaybes $ forM rs \(w@(From whom), msg) -> do fmap catMaybes $ forM rs \(w@(From whom), msg) -> do
-- encKeys <- (liftIO . readTVarIO) (view proxyEncryptionKeys bus) encKeys <- (liftIO . readTVarIO) (view proxyEncryptionKeys bus)
-- fmap (w, ) <$> dfm whom (Map.lookup whom encKeys) msg fmap (w, ) <$> dfm whom (Map.lookup whom encKeys) msg
-- where where
-- dfm :: Peer L4Proto -> Maybe Encrypt.CombinedKey -> LBS.ByteString -> IO (Maybe LBS.ByteString) dfm :: Peer L4Proto -> Maybe Encrypt.CombinedKey -> LBS.ByteString -> IO (Maybe LBS.ByteString)
-- dfm = \whom mk msg -> case mk of dfm = \whom mk msg -> case mk of
-- Nothing -> do Nothing -> do
-- trace $ "ENCRYPTION RECEIVE: we do not have a key to decode" <+> pretty whom trace $ "ENCRYPTION RECEIVE: we do not have a key to decode" <+> pretty whom
-- pure (Just msg) pure (Just msg)
-- Just k -> runMaybeT $ Just k -> runMaybeT $
-- -- А будем-ка мы просто передавать сообщение дальше как есть, если не смогли расшифровать -- А будем-ка мы просто передавать сообщение дальше как есть, если не смогли расшифровать
-- (<|> (do (<|> (do
-- -- И сотрём ключ из памяти -- И сотрём ключ из памяти
-- -- liftIO $ atomically $ modifyTVar' (view proxyEncryptionKeys bus) $ Lens.at whom .~ Nothing -- liftIO $ atomically $ modifyTVar' (view proxyEncryptionKeys bus) $ Lens.at whom .~ Nothing
-- trace $ "ENCRYPTION RECEIVE: got plain message. clearing key of" <+> pretty whom trace $ "ENCRYPTION RECEIVE: got plain message. clearing key of" <+> pretty whom
-- pure msg pure msg
-- )) $ )) $
-- do do
-- trace $ "ENCRYPTION RECEIVE: we have a key to decode from" <+> pretty whom <+> ":" <+> viaShow k trace $ "ENCRYPTION RECEIVE: we have a key to decode from" <+> pretty whom <+> ":" <+> viaShow k
-- case ((extractNonce . cs) msg) of case ((extractNonce . cs) msg) of
-- Nothing -> do Nothing -> do
-- trace $ "ENCRYPTION RECEIVE: can not extract nonce from" <+> pretty whom <+> "message" <+> viaShow msg trace $ "ENCRYPTION RECEIVE: can not extract nonce from" <+> pretty whom <+> "message" <+> viaShow msg
-- fail "" fail ""
-- Just (nonce, msg') -> Just (nonce, msg') ->
-- ((MaybeT . pure) (boxOpenAfterNMLazy k nonce msg') ((MaybeT . pure) (boxOpenAfterNMLazy k nonce msg')
-- <* (trace $ "ENCRYPTION RECEIVE: message successfully decoded from" <+> pretty whom) <* (trace $ "ENCRYPTION RECEIVE: message successfully decoded from" <+> pretty whom)
-- ) )
-- <|> <|>
-- (do (do
-- (trace $ "ENCRYPTION RECEIVE: can not decode message from" <+> pretty whom) (trace $ "ENCRYPTION RECEIVE: can not decode message from" <+> pretty whom)
-- fail "" fail ""
-- -- -- Попытаться десериализовать сообщение как PeerPing или PeerPingCrypted -- -- Попытаться десериализовать сообщение как PeerPing или PeerPingCrypted
-- -- case deserialiseOrFail msg of -- case deserialiseOrFail msg of
-- -- Right (_ :: PeerHandshake L4Proto) -> do -- Right (_ :: PeerHandshake L4Proto) -> do
-- -- trace $ "ENCRYPTION RECEIVE: plain message decoded as PeerHandshake" <+> pretty whom -- trace $ "ENCRYPTION RECEIVE: plain message decoded as PeerHandshake" <+> pretty whom
-- -- fail "" -- fail ""
-- -- Left _ -> do -- Left _ -> do
-- -- trace $ "ENCRYPTION RECEIVE: failed" <+> pretty whom -- trace $ "ENCRYPTION RECEIVE: failed" <+> pretty whom
-- -- mzero -- mzero
-- ) )