Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade DID RSA Key format #573

Merged
merged 19 commits into from
Feb 4, 2022
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions fission-cli/library/Fission/CLI/Connected.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import qualified Network.IPFS.Process.Error as IPFS.Process
import qualified Network.IPFS.Timeout.Types as IPFS
import qualified Network.IPFS.Types as IPFS

import Web.DID.Types
import Web.DID.Types as DID

import qualified Web.UCAN.Resolver.Error as UCAN.Resolver

Expand Down Expand Up @@ -155,10 +155,7 @@ mkConnected inCfg ipfsTimeout = do
let
ignoredFiles = Environment.ignored config

cliDID = DID
{ publicKey = Key.Ed25519PublicKey $ Ed25519.toPublic secretKey
, method = Key
}
cliDID = DID.Key $ Key.Ed25519PublicKey $ Ed25519.toPublic secretKey

cfg = Config { httpManager = getField @"httpManager" inCfg, ..}

Expand Down
4 changes: 2 additions & 2 deletions fission-cli/library/Fission/CLI/Handler/Setup.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import RIO.FilePath
import Network.DNS as DNS
import Servant.Client

import Web.DID.Types
import Web.DID.Types as DID
import qualified Web.UCAN.Types as UCAN


Expand Down Expand Up @@ -96,7 +96,7 @@ setup maybeOS maybeUsername maybeEmail maybeKeyFile = do
Right username -> do
baseURL <- getRemoteBaseUrl
signingPK <- Key.Store.fetchPublic (Proxy @SigningKey)
_ <- WNFS.create (DID Key $ Key.Ed25519PublicKey signingPK) "/"
_ <- WNFS.create (DID.Key $ Key.Ed25519PublicKey signingPK) "/"
Env.init username baseURL Nothing
Display.putOk $ "Done! Welcome to Fission, " <> textDisplay username <> " ✨"

Expand Down
8 changes: 4 additions & 4 deletions fission-cli/library/Fission/CLI/Handler/User/Login.hs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import qualified Fission.Web.Serialization as Web.Serializatio

-- 🛂 JWT/UCAN

import Web.DID.Types
import Web.DID.Types as DID
import qualified Web.UCAN.Claims.Error as UCAN.Claims
import qualified Web.UCAN.Proof as UCAN.Proof
import qualified Web.UCAN.Resolver.Class as UCAN
Expand Down Expand Up @@ -159,15 +159,15 @@ consume signingSK baseURL optUsername = do
signingPK <- Key.Store.toPublic (Proxy @SigningKey) signingSK

let
myDID = DID Key (Ed25519PublicKey signingPK)
myDID = DID.Key (Ed25519PublicKey signingPK)
topic = PubSub.Topic $ textDisplay targetDID

PubSub.connect baseURL topic \conn -> reattempt 10 do
logDebug @Text "🤝 Device linking handshake: Step 1"
aesConn <- secure conn () \(rsaConn :: Secure.Connection m (RSA.PublicKey, RSA.PrivateKey)) -> reattempt 10 do
let
Secure.Connection {key = (pk, _sk)} = rsaConn
sessionDID = DID Key (RSAPublicKey pk)
sessionDID = DID.Key (RSAPublicKey pk)

logDebug @Text "🤝 Device linking handshake: Step 2"
broadcastApiData conn sessionDID
Expand Down Expand Up @@ -274,7 +274,7 @@ produce signingSK baseURL = do

secure conn () \(rsaConn@Secure.Connection {key = (_, sk)} :: Secure.Connection m (RSA.PublicKey, RSA.PrivateKey)) -> reattempt 10 do
logDebug @Text "🤝 Device linking handshake: Step 2"
requestorTempDID@(DID _ tmpPK) <- listenRaw conn
requestorTempDID@(DID.Key tmpPK) <- listenRaw conn

case tmpPK of
Ed25519PublicKey _ ->
Expand Down
4 changes: 2 additions & 2 deletions fission-cli/library/Fission/CLI/Handler/User/Register.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import Fission.User.Username.Types
import Fission.Web.Auth.Token.Types
import Fission.Web.Client as Client

import Web.DID.Types
import Web.DID.Types as DID
import qualified Web.UCAN.Types as UCAN

import Fission.User.Email.Types
Expand Down Expand Up @@ -124,7 +124,7 @@ createAccount maybeUsername maybeEmail = do

exchangePK <- KeyStore.fetchPublic (Proxy @ExchangeKey)
signingPK <- KeyStore.fetchPublic (Proxy @SigningKey)
_ <- WNFS.create (DID Key $ Key.Ed25519PublicKey signingPK) "/"
_ <- WNFS.create (DID.Key $ Key.Ed25519PublicKey signingPK) "/"

let
form = Registration
Expand Down
2 changes: 2 additions & 0 deletions fission-core/library/Fission/Internal/Orphanage/RSA2048.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@ import qualified System.IO.Unsafe as Unsafe

import Fission.Prelude


-- Wait. This is weird. How did this end up in this module?
instance Arbitrary Ed25519.SecretKey where
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup that is weird! It's probably me being confused, but the compiler warning is turned off because {-# OPTIONS_GHC -fno-warn-orphans #-}. All the more reason for us to just bite the bullet and newtype everything. The more that I think about it, the more I'm in favour of just doing that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe to clarify: let's make this change in this PR. This line should not be in this module!

arbitrary = return . Unsafe.unsafePerformIO $ Ed25519.generateSecretKey
10 changes: 2 additions & 8 deletions fission-core/library/Fission/Web/Auth/Token/UCAN.hs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ getRootDID ::
-> m DID
getRootDID fallbackPK = \case
RootCredential ->
return $ DID Key fallbackPK
return $ DID.Key fallbackPK

Nested _ ucan -> do
UCAN {claims = Claims {sender}} <- ensureM $ getRoot ucan
Expand Down Expand Up @@ -135,14 +135,8 @@ mkUCAN ::
mkUCAN receiver senderSK nbf exp facts resource potency proof = UCAN {..}
where
sig = signEd25519 header claims senderSK

sender = DID
{ publicKey = Key.Ed25519PublicKey $ Ed25519.toPublic senderSK
, method = DID.Key
}

sender = DID.Key $ Key.Ed25519PublicKey $ Ed25519.toPublic senderSK
claims = Claims {..}

header = Header
{ typ = UCAN.Typ.JWT
, alg = Key.Ed25519
Expand Down
2 changes: 0 additions & 2 deletions fission-core/test/Fission/Test.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import qualified Fission.Test.Internal.Bool as Bool
import qualified Fission.Test.Internal.UTF8 as UTF8
import qualified Fission.Test.Random as Random
import qualified Fission.Test.URL as URL
import qualified Fission.Test.User.DID as DID
import qualified Fission.Test.Web.Auth.Signature.Ed25519 as Ed
import qualified Fission.Test.Web.Auth.Token.Bearer as Bearer
import qualified Fission.Test.Web.Auth.Token.UCAN as UCAN
Expand All @@ -20,7 +19,6 @@ spec :: Spec
spec =
describe "Fission" do
Bool.spec
DID.spec
DNS.spec
Environment.spec
Random.spec
Expand Down
84 changes: 0 additions & 84 deletions fission-core/test/Fission/Test/User/DID.hs

This file was deleted.

7 changes: 2 additions & 5 deletions fission-core/test/Fission/Test/Web/Auth/Signature/Ed25519.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import qualified Crypto.Key.Asymmetric as Key
import Crypto.Key.Asymmetric.Algorithm.Types
import qualified Crypto.PubKey.Ed25519 as Ed25519

import Web.DID.Types
import Web.DID.Types as DID
import qualified Web.UCAN.Internal.Base64.URL as B64.URL
import qualified Web.UCAN.RawContent as UCAN
import Web.UCAN.Types
Expand All @@ -26,10 +26,7 @@ spec =
sig' = signEd25519 header' claims' sk
rawContent = UCAN.RawContent $ B64.URL.encodeJWT header' claims'

did = DID
{ publicKey = Key.Ed25519PublicKey pk
, method = Key
}
did = DID.Key $ Key.Ed25519PublicKey pk

ucan' = ucan
{ header = header'
Expand Down
2 changes: 0 additions & 2 deletions fission-web-client/library/Fission/Web/Client.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
{-# LANGUAGE AllowAmbiguousTypes #-}

module Fission.Web.Client
( sendRequestM
, sendAuthedRequest
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Fission.Web.Server.Auth.Token.UCAN (handler) where

import Web.DID.Types
import Web.DID.Types as DID
import Web.UCAN.Resolver as UCAN
import qualified Web.UCAN.Types as UCAN
import qualified Web.UCAN.Validation as UCAN
Expand Down Expand Up @@ -42,7 +42,7 @@ handler (Bearer.Token jwt rawContent) = do
toAuthorization jwt

toAuthorization ::
( UCAN.Resolver m
( UCAN.Resolver m
, MonadThrow m
, MonadLogger m
, MonadDB t m
Expand All @@ -56,7 +56,7 @@ toAuthorization jwt@UCAN.UCAN {claims = UCAN.Claims {..}} = do
Left err ->
throwM err

Right UCAN.UCAN {claims = UCAN.Claims {sender = DID {publicKey = pk}}} ->
Right UCAN.UCAN {claims = UCAN.Claims {sender = DID.Key pk}} ->
runDB (User.getByPublicKey pk) >>= \case
Nothing ->
Web.Error.throw $ NotFound @User
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Servant.Server.Generic

import Fission.Prelude

import Web.DID.Types
import Web.DID.Types as DID

import qualified Fission.Web.API.User.Create.Types as User.Create

Expand Down Expand Up @@ -45,7 +45,7 @@ withDID ::
, Challenge.Creator m
)
=> ServerT User.Create.WithDID m
withDID User.Registration {username, email} DID {..} = do
withDID User.Registration {username, email} (DID.Key publicKey) = do
now <- currentTime
userId <- Web.Err.ensureM $ User.create username publicKey email now
challenge <- Web.Err.ensureM $ Challenge.create userId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import Fission.Prelude
import Fission.Internal.Fixture.Key.Ed25519 as Fixture.Ed25519

import Fission.URL.Types
import Web.DID.Types
import Web.DID.Types as DID

import Fission.Web.API.Host.Types
import Fission.Web.API.Remote
Expand Down Expand Up @@ -108,10 +108,7 @@ run logFunc dbPool processCtx httpManager tlsManager action = do
herokuID = Hku.ID "HEROKU_ID"
herokuPassword = Hku.Password "HEROKU_PASSWORD"

fissionDID = DID
{ publicKey = Fixture.Ed25519.pk
, method = Key
}
fissionDID = DID.Key $ Fixture.Ed25519.pk

environment = LocalDev

Expand Down Expand Up @@ -185,10 +182,7 @@ mkConfig dbPool processCtx httpManager tlsManager logFunc linkRelayStoreVar mach
herokuID = Hku.ID "HEROKU_ID"
herokuPassword = Hku.Password "HEROKU_PASSWORD"

fissionDID = DID
{ publicKey = Fixture.Ed25519.pk
, method = Key
}
fissionDID = DID.Key $ Fixture.Ed25519.pk

ipfsPath = "/usr/local/bin/ipfs"
ipfsURLs = Partial.fromJust $ nonEmpty [IPFS.URL $ BaseUrl Http "localhost" 5001 ""]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import Fission.Prelude

import Fission.Internal.App
import Fission.Time
import Web.DID.Types
import Web.DID.Types as DID

import Fission.Web.API.Host.Types as Server
import qualified Fission.Web.API.Types as Fission
Expand Down Expand Up @@ -195,7 +195,7 @@ start middleware runner = do
now <- currentTime
cfg@Fission.Server.Config {..} <- ask

let DID _ serverPK = fissionDID
let DID.Key serverPK = fissionDID

logDebug $ displayShow cfg

Expand Down
15 changes: 3 additions & 12 deletions fission-web-server/library/Fission/Web/Server/Mock/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import qualified Network.IPFS.Types as IPFS
import Servant
import Servant.Server.Experimental.Auth

import Web.DID.Types
import Web.DID.Types as DID

import Fission.Prelude

Expand Down Expand Up @@ -39,11 +39,7 @@ defaultConfig :: Config
defaultConfig = Config
{ now = agesAgo
, linkedPeers = pure $ IPFS.Peer "ipv4/fakepeeraddress"
, didVerifier = mkAuthHandler \_ ->
return $ DID
{ publicKey = pk
, method = Key
}
, didVerifier = mkAuthHandler \_ -> pure $ DID.Key pk
, userVerifier = mkAuthHandler \_ -> pure $ Fixture.entity Fixture.user
, authVerifier = mkAuthHandler \_ -> authZ
, herokuVerifier = BasicAuthCheck \_ -> pure . Authorized $ Heroku.Auth "FAKE HEROKU"
Expand All @@ -68,13 +64,8 @@ defaultConfig = Config

authZ :: Monad m => m Authorization
authZ = return Authorization
{ sender = Right did
{ sender = Right $ DID.Key $ Fixture.Ed25519.pk
, about = Fixture.entity Fixture.user
, potency = Just AppendOnly
, resource = Subset $ FissionFileSystem "/test/"
}
where
did = DID
{ publicKey = Fixture.Ed25519.pk
, method = Key
}
Loading