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

hs-ucan upgrade #586

Closed
wants to merge 25 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
c7f5907
Upgrade DID RSA Key format (#573)
matheus23 Feb 4, 2022
a0b4641
PowerDNS Support (#579)
walkah Feb 11, 2022
e061629
Add error handling for a few failure cases
QuinnWilton Feb 15, 2022
a9d1a4e
tlsManager for github requests (#582)
walkah Mar 14, 2022
8c77c7b
Add docker-compose based setup for local dev (#581)
walkah Mar 14, 2022
7b76f4a
Extract version-specific parsing functions
matheus23 Jan 28, 2022
dcad95e
Some version of hs-ucan
matheus23 Feb 1, 2022
05919c5
Upgrade header to V 0.7
matheus23 Feb 2, 2022
eb54bf6
Rename some stuff
matheus23 Feb 2, 2022
c8b117f
Parse claims depending on header version
matheus23 Feb 2, 2022
ee9a734
Parse version 0.7 of UCANs
matheus23 Feb 2, 2022
8421a6d
Make nbf optional, rename nbf & exp
matheus23 Feb 2, 2022
fc69a05
WIP
matheus23 Feb 3, 2022
472d778
Capabilities (without rights amplification)
matheus23 Feb 8, 2022
299c0f9
Write a test for the capabilities func
matheus23 Feb 9, 2022
dc6e5db
WIP
matheus23 Feb 10, 2022
63ca566
Rename Proof -> Witness WIP
matheus23 Feb 11, 2022
4e43a92
More Witness <-> Proof renaming, Restructure cap checking
matheus23 Feb 18, 2022
62f018c
Short-circuit on invalid witnesses
matheus23 Feb 18, 2022
ca3a7ff
Use ListT for streaming errors/capabilities
matheus23 Feb 21, 2022
4d73d2e
Check against fixture (from ts-ucan)
matheus23 Feb 21, 2022
e423efc
Test partial order capability semantics
matheus23 Feb 22, 2022
02260a4
WIP
matheus23 Mar 1, 2022
9f2f399
Parse as & my & prf
matheus23 Mar 16, 2022
19fb52c
Work on capability proofs
matheus23 Mar 30, 2022
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
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ result
yesod-devel/*
addon-manifest.json
env.yaml
server.yaml
domain-key.txt
domain-crt.txt

Expand Down Expand Up @@ -587,4 +588,5 @@ MigrationBackup/

# End of https://www.gitignore.io/api/vim,emacs,sublimetext,visualstudio


fission-web-server/data/
fission-web-server/.env
1 change: 1 addition & 0 deletions fission-cli/library/Fission/CLI.hs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ cli = do
Http -> defaultManagerSettings
Https -> tlsManagerSettings

tlsManager <- liftIO $ HTTP.newManager tlsManagerSettings
httpManager <- liftIO $ HTTP.newManager rawHTTPSettings
{ managerResponseTimeout = responseTimeoutMicro 1_800_000_000 }

Expand Down
41 changes: 27 additions & 14 deletions fission-cli/library/Fission/CLI/App.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import Fission.CLI.Connected as Connected

import Fission.CLI.App.Environment as App.Env
import qualified Fission.CLI.Display.Error as CLI.Error
import Fission.CLI.Environment as CLI.Env hiding (Env)
import Fission.CLI.Error.Types
import qualified Fission.CLI.Handler as Handler
import Fission.CLI.Handler.Error.Types (Errs)

Expand Down Expand Up @@ -44,22 +46,33 @@ interpret baseCfg cmd = do
run' :: FissionCLI errs Connected.Config () -> FissionCLI errs Base.Config ()
run' = ensureM . Connected.run baseCfg timeoutSeconds

attempt App.Env.read >>= \case
Right Env {appURL} -> do
UTF8.putTextLn $ "App already set up at " <> textDisplay appURL
logDebug . textDisplay $ AlreadyExists @URL
raise $ AlreadyExists @URL

Left errs -> do
case openUnionMatch @(NotFound FilePath) errs of
Just _ -> do
logDebug @Text "Setting up new app"
run' $ Handler.appInit appDir buildDir mayAppName

Nothing -> do
logError @Text "Problem setting up new app"
attempt CLI.Env.alreadySetup >>= \case
Left errs ->
case openUnionMatch @NotSetup errs of
Just err -> do
CLI.Error.put err "Fission is installed, but you are not logged in. Please run `fission login`"
raise errs

Nothing ->
raise errs

Right _ ->
attempt App.Env.read >>= \case
Right Env {appURL} -> do
UTF8.putTextLn $ "App already set up at " <> textDisplay appURL
logDebug . textDisplay $ AlreadyExists @URL
raise $ AlreadyExists @URL

Left errs -> do
case openUnionMatch @(NotFound FilePath) errs of
Just _ -> do
logDebug @Text "Setting up new app"
run' $ Handler.appInit appDir buildDir mayAppName

Nothing -> do
logError @Text "Problem setting up new app"
raise errs

Up App.Up.Options {open, watch, updateDNS, updateData, filePath, ipfsCfg = IPFS.Config {..}} -> do
let
run' :: FissionCLI errs Connected.Config () -> FissionCLI errs Base.Config ()
Expand Down
1 change: 1 addition & 0 deletions fission-cli/library/Fission/CLI/Base/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import Fission.CLI.Remote
-- | The configuration used for the CLI application
data Config = Config
{ httpManager :: HTTP.Manager
, tlsManager :: HTTP.Manager
, ipfsTimeout :: IPFS.Timeout
, ipfsURL :: IPFS.URL
, remote :: Remote
Expand Down
10 changes: 4 additions & 6 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 @@ -61,6 +61,7 @@ type BaseErrs =
, SomeException
, IPFS.UnableToConnect
, NotRegistered
, NotSetup
, NotFound [IPFS.Peer]
, NotFound Ed25519.SecretKey
]
Expand Down Expand Up @@ -155,10 +156,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 All @@ -167,7 +165,7 @@ mkConnected inCfg ipfsTimeout = do
proof <- getRootUserProof
attempt (sendAuthedRequest proof whoAmI) >>= \case
Left err -> do
CLI.Error.put err "Not registered. Please run: fission user login"
CLI.Error.put err "Not registered. Please run `fission user login`"
raise NotRegistered

Right username -> do
Expand Down
21 changes: 21 additions & 0 deletions fission-cli/library/Fission/CLI/Environment.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module Fission.CLI.Environment
, getOrRetrievePeers
, absPath
, fetchServerDID
, alreadySetup

-- * Reexport

Expand All @@ -15,6 +16,7 @@ module Fission.CLI.Environment
) where

import qualified Data.ByteString.Char8 as BS8
import Data.Function
import qualified Data.List.NonEmpty as NonEmpty
import qualified Data.Yaml as YAML

Expand All @@ -37,6 +39,7 @@ import Fission.User.Username.Types
import Web.DID.Types

import qualified Fission.CLI.Display.Error as CLI.Error
import Fission.CLI.Error.Types
import Fission.CLI.IPFS.Peers as Peers
import Fission.CLI.Key.Store as KeyStore
import qualified Fission.CLI.YAML as YAML
Expand Down Expand Up @@ -194,3 +197,21 @@ fetchServerDID fissionURL = do
Right serverDID -> do
logDebug $ "DID retrieved " <> textDisplay serverDID
return serverDID

alreadySetup ::
( MonadRescue m
, MonadLogger m
, MonadIO m
, MonadEnvironment m
, m `Raises` YAML.ParseException
, m `Raises` NotFound FilePath
, m `Raises` NotSetup
)
=> m ()
alreadySetup =
attemptM get \case
Left _ ->
raise NotSetup

Right _ ->
return ()
9 changes: 9 additions & 0 deletions fission-cli/library/Fission/CLI/Error/Types.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module Fission.CLI.Error.Types
( NotRegistered (..)
, NotSetup (..)
, NoKeyFile (..)
) where

Expand All @@ -13,6 +14,14 @@ instance Display NotRegistered where

----------

data NotSetup = NotSetup
deriving (Show, Eq, Exception)

instance Display NotSetup where
display NotSetup = "Not setup"

----------

data NoKeyFile = NoKeyFile
deriving (Show, Eq, Exception)

Expand Down
10 changes: 9 additions & 1 deletion fission-cli/library/Fission/CLI/Handler/App/Publish.hs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,15 @@ publish
logUser @Text "✈️ Pushing to remote"
retryOnStatus [status502] 100 (runUpdate cid) >>= \case
Left err -> do
CLI.Error.put err "Server unable to sync data"
let errMsg =
case err of
FailureResponse _ (responseStatusCode -> status) | status == status404 ->
"The app has not yet been registered. Please delete your fission.yaml and run `fission app register --name some-name`"

_ ->
"Server unable to sync data"

CLI.Error.put err errMsg
raise err

Right _ -> do
Expand Down
1 change: 1 addition & 0 deletions fission-cli/library/Fission/CLI/Handler/Error/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ type Errs
, NotFound URL
, NotFound [IPFS.Peer]
, NotRegistered
, NotSetup
--
, OS.Unsupported
, RSA.Error
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
18 changes: 17 additions & 1 deletion fission-cli/library/Fission/CLI/Handler/User.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ module Fission.CLI.Handler.User (interpret) where
import Fission.Prelude

import qualified Fission.CLI.Base.Types as Base

import qualified Fission.CLI.Display.Error as CLI.Error
import Fission.CLI.Error.Types

import Fission.CLI.Environment as Env
import Fission.CLI.Types

import qualified Fission.CLI.Handler as Handler
Expand All @@ -29,4 +34,15 @@ interpret cmd = do
return ()

WhoAmI _ ->
Handler.whoami
attemptM Env.alreadySetup \case
Left errs ->
case openUnionMatch @NotSetup errs of
Just err -> do
CLI.Error.put err "Fission is installed, but you are not logged in. Please run `fission login`"
raise errs

Nothing ->
raise errs

Right _ ->
Handler.whoami
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
4 changes: 2 additions & 2 deletions fission-cli/library/Fission/CLI/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -191,13 +191,13 @@ instance
, Display (OpenUnion errs)
, IsMember SomeException errs

, HasField' "httpManager" cfg HTTP.Manager
, HasField' "tlsManager" cfg HTTP.Manager
, HasLogFunc cfg
)
=> MonadGitHub (FissionCLI errs cfg) where
sendRequest req =
CLI.withLoader 50_000 do
manager <- asks $ getField @"httpManager"
manager <- asks $ getField @"tlsManager"

logDebug @Text "🐱🐙 Making request to GitHub"
liftIO . runClientM req . mkClientEnv manager $ BaseUrl Https "github.com" 443 ""
Expand Down
2 changes: 1 addition & 1 deletion fission-cli/package.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: fission-cli
version: '2.17.0.0'
version: "2.17.1.0"
category: CLI
author:
- Brooklyn Zelenka
Expand Down
11 changes: 0 additions & 11 deletions fission-core/library/Fission/Internal/Orphanage/RSA2048.hs

This file was deleted.

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
Loading