mirror of
https://github.com/urbit/shrub.git
synced 2024-12-25 04:52:06 +03:00
kh: parse pubkeys at json parsing site, not later
This ensures we crash early if the received data is in an unexpected format or otherwise not sane.
This commit is contained in:
parent
7925171b77
commit
aec9883c3b
@ -42,12 +42,10 @@ import qualified Network.HTTP.Types as HT
|
|||||||
|
|
||||||
-- Conversion Utilities --------------------------------------------------------
|
-- Conversion Utilities --------------------------------------------------------
|
||||||
|
|
||||||
passFromText :: Text -> Text -> Int -> Pass
|
passFromBytes :: ByteString -> ByteString -> Int -> Pass
|
||||||
passFromText enc aut sut
|
passFromBytes enc aut sut
|
||||||
| sut /= 1 = Pass (Ed.PublicKey mempty) (Ed.PublicKey mempty)
|
| sut /= 1 = Pass (Ed.PublicKey mempty) (Ed.PublicKey mempty)
|
||||||
| otherwise = Pass (Ed.PublicKey $ grab aut) (Ed.PublicKey $ grab enc)
|
| otherwise = Pass (Ed.PublicKey aut) (Ed.PublicKey enc)
|
||||||
where
|
|
||||||
grab = reverse . toBytes . hexString . removePrefix . encodeUtf8
|
|
||||||
|
|
||||||
clanFromShip :: Ship -> Ob.Class
|
clanFromShip :: Ship -> Ob.Class
|
||||||
clanFromShip = Ob.clan . Ob.patp . fromIntegral
|
clanFromShip = Ob.clan . Ob.patp . fromIntegral
|
||||||
@ -186,17 +184,21 @@ instance FromJSON PointNetwork where
|
|||||||
data PointKeys = PointKeys
|
data PointKeys = PointKeys
|
||||||
{ pkLife :: Life
|
{ pkLife :: Life
|
||||||
, pkSuite :: Int
|
, pkSuite :: Int
|
||||||
, pkAuth :: Text --NOTE 0xhex string
|
, pkAuth :: ByteString
|
||||||
, pkCrypt :: Text --NOTE 0xhex string
|
, pkCrypt :: ByteString
|
||||||
} deriving (Show, Eq, Generic)
|
} deriving (Show, Eq, Generic)
|
||||||
|
|
||||||
instance FromJSON PointKeys where
|
instance FromJSON PointKeys where
|
||||||
parseJSON (Object o) = do
|
parseJSON (Object o) = do
|
||||||
pkLife <- o .: "life"
|
pkLife <- o .: "life"
|
||||||
pkSuite <- o .: "suite"
|
pkSuite <- o .: "suite"
|
||||||
pkAuth <- o .: "auth"
|
rawAuth <- o .: "auth"
|
||||||
pkCrypt <- o .: "crypt"
|
rawCrypt <- o .: "crypt"
|
||||||
|
let pkAuth = parseKey rawAuth
|
||||||
|
let pkCrypt = parseKey rawCrypt
|
||||||
pure PointKeys{..}
|
pure PointKeys{..}
|
||||||
|
where
|
||||||
|
parseKey = reverse . toBytes . hexString . removePrefix . encodeUtf8
|
||||||
parseJSON _ = do error "failed to parse PointKeys json"
|
parseJSON _ = do error "failed to parse PointKeys json"
|
||||||
|
|
||||||
data PointSponsor = PointSponsor
|
data PointSponsor = PointSponsor
|
||||||
@ -236,7 +238,7 @@ parseAzimuthPoint (PointRequest point) response = EthPoint{..}
|
|||||||
Left _ -> Nothing
|
Left _ -> Nothing
|
||||||
Right s -> Just
|
Right s -> Just
|
||||||
( fromIntegral $ pkLife key
|
( fromIntegral $ pkLife key
|
||||||
, passFromText (pkCrypt key) (pkAuth key) (pkSuite key)
|
, passFromBytes (pkCrypt key) (pkAuth key) (pkSuite key)
|
||||||
, fromIntegral $ pnRift net
|
, fromIntegral $ pnRift net
|
||||||
, (psHas $ pnSponsor net, Ship $ fromIntegral $ Ob.fromPatp s)
|
, (psHas $ pnSponsor net, Ship $ fromIntegral $ Ob.fromPatp s)
|
||||||
, Nothing --NOTE goes unused currently, so we simply put Nothing
|
, Nothing --NOTE goes unused currently, so we simply put Nothing
|
||||||
@ -260,7 +262,7 @@ parseGalaxyTableEntry (PointRequest point) response = (ship, (rift, life, pass))
|
|||||||
ship = Ship $ fromIntegral point
|
ship = Ship $ fromIntegral point
|
||||||
rift = fromIntegral $ pnRift net
|
rift = fromIntegral $ pnRift net
|
||||||
life = fromIntegral $ pkLife keys
|
life = fromIntegral $ pkLife keys
|
||||||
pass = passFromText (pkCrypt keys) (pkAuth keys) (pkSuite keys)
|
pass = passFromBytes (pkCrypt keys) (pkAuth keys) (pkSuite keys)
|
||||||
|
|
||||||
removePrefix :: ByteString -> ByteString
|
removePrefix :: ByteString -> ByteString
|
||||||
removePrefix withOhEx
|
removePrefix withOhEx
|
||||||
|
Loading…
Reference in New Issue
Block a user