Browse Source

CP: SCP (Shared CP) modified to more standard PCP (Public CP)
Docs: Header values repeated on the docs for easier consulting

Marcos Dumay de Medeiros 7 years ago
parent
commit
2ba414bb3e

+ 5 - 7
src/Data/SMTP/Crypto/Algos/CP.hs

@@ -16,8 +16,6 @@ import qualified Data.SMTP.Seal as Seal
 import qualified Crypto.Hash as Hash
 import qualified Crypto.Hash as Hash
 import qualified Crypto.Hash.Algorithms as Hashs
 import qualified Crypto.Hash.Algorithms as Hashs
 import qualified Crypto.PubKey.Ed25519 as Ed25519
 import qualified Crypto.PubKey.Ed25519 as Ed25519
-import qualified Data.ByteArray as BA
-import qualified Data.ByteString as BS
 import Crypto.Error
 import Crypto.Error
 import Data.SMTP.Crypto.Types.CP
 import Data.SMTP.Crypto.Types.CP
 
 
@@ -32,17 +30,17 @@ update (Sha3_512Ed25519s s) dt = Sha3_512Ed25519s $ Hash.hashUpdate s dt
 update' :: State -> LBS.ByteString -> State
 update' :: State -> LBS.ByteString -> State
 update' (Sha3_512Ed25519s s) dt = Sha3_512Ed25519s $ Hash.hashUpdates s $ LBS.toChunks dt
 update' (Sha3_512Ed25519s s) dt = Sha3_512Ed25519s $ Hash.hashUpdates s $ LBS.toChunks dt
 
 
-checkSeal :: State -> Seal.Seal -> SCP -> Bool
-checkSeal _ _ SAll = True
-checkSeal (Sha3_512Ed25519s s) (Seal.Seal _ seal _) (SCPSha3_512Ed25519 _ pk) = let
+checkSeal :: State -> Seal.Seal -> PCP -> Bool
+checkSeal _ _ PAll = True
+checkSeal (Sha3_512Ed25519s s) (Seal.Seal _ seal _) (PCPSha3_512Ed25519 _ pk) = let
   dg = Hash.hashFinalize s
   dg = Hash.hashFinalize s
   sig' = Ed25519.signature seal
   sig' = Ed25519.signature seal
   in case sig' of
   in case sig' of
     CryptoFailed _ -> False
     CryptoFailed _ -> False
     CryptoPassed sig -> Ed25519.verify pk dg sig
     CryptoPassed sig -> Ed25519.verify pk dg sig
 
 
--- toSeal :: State -> SCP -> Maybe Seal.Seal
--- toSeal (Sha3_512Ed25519s s) (SCPSha3_512Ed25519 cpid pk (Just sk)) = let
+-- toSeal :: State -> PCP -> Maybe Seal.Seal
+-- toSeal (Sha3_512Ed25519s s) (PCPSha3_512Ed25519 cpid pk (Just sk)) = let
 --   dg = Hash.hashFinalize s
 --   dg = Hash.hashFinalize s
 --   sig = ba2bs $ Ed25519.sign sk pk dg
 --   sig = ba2bs $ Ed25519.sign sk pk dg
 --   in Just $ Seal.Seal cpid sig Nothing
 --   in Just $ Seal.Seal cpid sig Nothing

+ 12 - 6
src/Data/SMTP/Crypto/Types/CP.hs

@@ -10,6 +10,7 @@ import Crypto.Error (maybeCryptoError)
 import Data.Maybe
 import Data.Maybe
 import qualified Text.Read as Read
 import qualified Text.Read as Read
 
 
+-- | Capability algorithms
 data Algo = Sha3_512Ed25519 deriving (Eq, Ord, Bounded, Enum)
 data Algo = Sha3_512Ed25519 deriving (Eq, Ord, Bounded, Enum)
 instance Show Algo where
 instance Show Algo where
   show Sha3_512Ed25519 = "SHA3_512-ED25519"
   show Sha3_512Ed25519 = "SHA3_512-ED25519"
@@ -22,26 +23,31 @@ instance Read.Read Algo where
         lastIn = drop (length txt) input
         lastIn = drop (length txt) input
         in if firstIn == txt then Just (test, lastIn) else Nothing
         in if firstIn == txt then Just (test, lastIn) else Nothing
   
   
+-- | Public capabilities data
+data PCP = PCPSha3_512Ed25519 ByteString Ed25519.PublicKey
+         | PAll
 
 
-data SCP = SCPSha3_512Ed25519 ByteString Ed25519.PublicKey
-         | SAll
-
+-- | The fCMTP CP revocation header: "CP-Revoked"
 revocationHeader :: String
 revocationHeader :: String
 revocationHeader = "CP-Revoked"
 revocationHeader = "CP-Revoked"
 
 
+-- | The fCMTP header for public access: "CP-Grant-All"
 publicHeader :: String
 publicHeader :: String
 publicHeader = "CP-Grant-All"
 publicHeader = "CP-Grant-All"
 
 
+-- | The fCMTP CP algorithm header: "CP-Algorithm"
 algoHeader :: String
 algoHeader :: String
 algoHeader = "CP-Algorithm"
 algoHeader = "CP-Algorithm"
 
 
+-- | The fCMTP CP shared key header: "CP-Shared-Key"
 sharedKeyHeader :: String
 sharedKeyHeader :: String
 sharedKeyHeader = "CP-Shared-Key"
 sharedKeyHeader = "CP-Shared-Key"
 
 
+-- | The fMCTP CP id header: "CP-Id"
 idHeader :: String
 idHeader :: String
 idHeader = "CP-Id"
 idHeader = "CP-Id"
 
 
-sFromHeaders :: Resc.PlainHeaders -> Maybe SCP
+sFromHeaders :: Resc.PlainHeaders -> Maybe PCP
 sFromHeaders hh = let
 sFromHeaders hh = let
   shh = Resc.sealed hh
   shh = Resc.sealed hh
   pbc = fromMaybe False $ Resc.getBooleanHeader shh publicHeader
   pbc = fromMaybe False $ Resc.getBooleanHeader shh publicHeader
@@ -49,12 +55,12 @@ sFromHeaders hh = let
   in
   in
   if revoked then Nothing
   if revoked then Nothing
   else
   else
-    if pbc then Just SAll
+    if pbc then Just PAll
     else do
     else do
       algo <- Resc.getReadHeader shh algoHeader
       algo <- Resc.getReadHeader shh algoHeader
       sh' <- Resc.getBase64Header shh sharedKeyHeader
       sh' <- Resc.getBase64Header shh sharedKeyHeader
       sh <- maybeCryptoError . Ed25519.publicKey $ sh'
       sh <- maybeCryptoError . Ed25519.publicKey $ sh'
       cid <- Resc.getBase64Header shh idHeader
       cid <- Resc.getBase64Header shh idHeader
       case algo of
       case algo of
-        Sha3_512Ed25519 -> pure $ SCPSha3_512Ed25519 cid sh
+        Sha3_512Ed25519 -> pure $ PCPSha3_512Ed25519 cid sh
 
 

+ 3 - 3
src/Data/SMTP/Types/Resource.hs

@@ -79,15 +79,15 @@ getMultiple hh k = filter (hasKey k) hh
 getMultipleValue :: [Header] -> String -> [String]
 getMultipleValue :: [Header] -> String -> [String]
 getMultipleValue hh k = map value $ getMultiple hh k
 getMultipleValue hh k = map value $ getMultiple hh k
 
 
--- | fCMTP revision header
+-- | fCMTP revision header: "fCMTP-Revision"
 revisionHeader :: String
 revisionHeader :: String
 revisionHeader = "fCMTP-Revision"
 revisionHeader = "fCMTP-Revision"
 
 
--- | fCMTP base revision header
+-- | fCMTP base revision header: "fCMTP-Revision-Base"
 baseHeader :: String
 baseHeader :: String
 baseHeader = "fCMTP-Revision-Base"
 baseHeader = "fCMTP-Revision-Base"
 
 
--- | fCMTP resource URI header
+-- | fCMTP resource URI header: "fCMTP-Address"
 addressHeader :: String
 addressHeader :: String
 addressHeader = "fCMTP-Address"
 addressHeader = "fCMTP-Address"