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

Support invite accept reject #893

Merged
merged 49 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from 40 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
bf7a369
refactor out invite types module
James-Mart Oct 2, 2024
e547d67
invite plugin refactor: removes callback_url and deals strictly with …
James-Mart Oct 2, 2024
bd14fc1
add plugins for all auth services: authsig, authany, authinvite, auth…
James-Mart Oct 14, 2024
7bfbc1a
fix doc typo
James-Mart Oct 14, 2024
53637d9
update demoapp1 deploy script to use psibase config
James-Mart Oct 14, 2024
747587f
finish initial invite plugin
James-Mart Oct 15, 2024
4828d9c
finish initial auth-invite plugin
James-Mart Oct 15, 2024
4264a2e
fix the description of the get-account plugin function
James-Mart Oct 15, 2024
30dc5fe
update transact plugin to collect & attach claims/proofs to the trans…
James-Mart Oct 15, 2024
8322c0c
create producer account on boot, and set tx signing key
James-Mart Oct 15, 2024
8c9010b
support dynamically loading user plugins in supervisor
James-Mart Oct 16, 2024
44a0cfc
separate import and export interfaces for smart-auth
James-Mart Oct 16, 2024
ae055ea
add missing getPlugin call in supervisor
James-Mart Oct 16, 2024
a54025f
export a plugin-ref resource from the host
James-Mart Oct 16, 2024
89e4e3b
remove unnecessary check from auth-sig
James-Mart Oct 17, 2024
5c0aa15
enable dynamic plugin linking within the host
James-Mart Oct 17, 2024
6aaac70
add privileged host API. Currently allows privileged plugins to ask f…
James-Mart Oct 17, 2024
ac0cd63
support logout in accounts plugin
James-Mart Oct 17, 2024
888d685
simplify host client interface
James-Mart Oct 17, 2024
f6b82cf
remove some debug printing
James-Mart Oct 17, 2024
a9de877
Merge remote-tracking branch 'origin/main' into support-invite-accept…
James-Mart Oct 18, 2024
6a6bb43
fix demoapp1
James-Mart Oct 18, 2024
b6e4ed1
ensure reloading user plugins on user change
James-Mart Oct 18, 2024
5e9a1af
fix auth-sig signing (was applying sha256 hash twice)
James-Mart Oct 18, 2024
2605c74
fix - transact plugin failing to add needed claims
James-Mart Oct 21, 2024
2730332
auth-sig plugin support adding claims/proofs
James-Mart Oct 21, 2024
722520a
smart authorization doc update
James-Mart Oct 21, 2024
fd6c54a
Merge remote-tracking branch 'origin/main' into support-invite-accept…
James-Mart Oct 21, 2024
69751cf
add isLoggedIn support to accounts plugin
James-Mart Oct 21, 2024
78ed6b3
distinguish the user's selected auth service plugin from a third-part…
James-Mart Oct 22, 2024
7949474
Merge remote-tracking branch 'origin/main' into support-invite-accept…
James-Mart Oct 22, 2024
783f509
authsig managedkeys interface cleanup
James-Mart Oct 22, 2024
c74b00e
remove comment
James-Mart Oct 22, 2024
eb59fa3
transact plugin db interface cleanup
James-Mart Oct 22, 2024
b35d085
fix authsig plugin compile warning
James-Mart Oct 22, 2024
8aea257
authinvite plugin - extract db helper module
James-Mart Oct 22, 2024
20cfe6b
use filenames in browser for dynamically loaded plugins
James-Mart Oct 22, 2024
371db30
allow supervisor to logout
James-Mart Oct 23, 2024
cce550f
supervisor refactoring
James-Mart Oct 23, 2024
d9abc47
minor doc improvement
James-Mart Oct 23, 2024
4e1b428
Merge remote-tracking branch 'origin/main' into support-invite-accept…
James-Mart Oct 23, 2024
5801741
pr feedback - grammar in docs
James-Mart Oct 28, 2024
575d95d
pr feedback - don't use lazy_static
James-Mart Oct 28, 2024
f1137bf
pr feedback - unify doc comment wording
James-Mart Oct 28, 2024
de907fd
pr feedback - move instead of copy/clone
James-Mart Oct 28, 2024
d3bd581
Merge remote-tracking branch 'origin/main' into support-invite-accept…
James-Mart Oct 28, 2024
20a6df9
pr feedback - eliminate clone
James-Mart Oct 28, 2024
ecaefe6
rename 'message' parameter in smart-auth get_proofs api to 'transacti…
James-Mart Oct 29, 2024
19b06e8
Merge remote-tracking branch 'origin/main' into support-invite-accept…
James-Mart Oct 29, 2024
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
14 changes: 13 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,10 @@ add_dependencies(CommonApiCommonLib_js ComponentParser)
add_rs_component(services/system/Transact/plugin:TransactPlugin transact.wasm wasm32-wasi )
add_rs_component(services/system/Accounts/plugin:AccountsPlugin accounts.wasm wasm32-wasi )
add_rs_component(services/system/AuthSig/plugin:AuthPlugin auth_sig.wasm wasm32-wasi )
add_rs_component(services/user/Invite/plugin:InvitesPlugin invite.wasm wasm32-wasi ${AuthPlugin_DEP})
add_rs_component(services/system/AuthDelegate/plugin:AuthDelegatePlugin auth_delegate.wasm wasm32-wasi )
add_rs_component(services/system/AuthAny/plugin:AuthAnyPlugin auth_any.wasm wasm32-wasi )
add_rs_component(services/user/Invite/plugin:InvitesPlugin invite.wasm wasm32-wasi )
add_rs_component(services/user/Invite/plugin_AuthInvite:AuthInvitePlugin auth_invite.wasm wasm32-wasi )
add_rs_component(services/user/Tokens/plugin:TokensPlugin tokens.wasm wasm32-wasi )
add_rs_component(services/user/Supervisor/plugin:TestsPlugin test.wasm wasm32-wasi )
add_rs_component(services/user/ClientData/plugin:ClientDataPlugin clientdata.wasm wasm32-wasi )
Expand Down Expand Up @@ -483,7 +486,11 @@ psibase_package(
DESCRIPTION "Auth service that delegates authorization to another account"
SERVICE auth-delegate
WASM ${CMAKE_CURRENT_BINARY_DIR}/AuthDelegate.wasm
SERVER auth-delegate
DATA ${COMPONENT_BIN_DIR}/${AuthDelegatePlugin_OUTPUT_FILE} /plugin.wasm
DEPENDS wasm
DEPENDS ${AuthDelegatePlugin_DEP}
PACKAGE_DEPENDS "HttpServer(^${PSIBASE_VERSION})" "Sites(^${PSIBASE_VERSION})"
)

psibase_package(
Expand All @@ -493,7 +500,10 @@ psibase_package(
DESCRIPTION "Insecure auth service that allows any access"
SERVICE auth-any
WASM ${CMAKE_CURRENT_BINARY_DIR}/AuthAny.wasm
DATA ${COMPONENT_BIN_DIR}/${AuthAnyPlugin_OUTPUT_FILE} /plugin.wasm
DEPENDS wasm
DEPENDS ${AuthAnyPlugin_DEP}
PACKAGE_DEPENDS "Sites(^${PSIBASE_VERSION})"
)

psibase_package(
Expand Down Expand Up @@ -644,8 +654,10 @@ psibase_package(
DATA ${COMPONENT_BIN_DIR}/${InvitesPlugin_OUTPUT_FILE} /plugin.wasm
SERVICE auth-invite
WASM ${CMAKE_CURRENT_BINARY_DIR}/AuthInvite.wasm
DATA ${COMPONENT_BIN_DIR}/${AuthInvitePlugin_OUTPUT_FILE} /plugin.wasm
DEPENDS wasm
DEPENDS ${InvitesPlugin_DEP}
DEPENDS ${AuthInvitePlugin_DEP}
)

psibase_package(
Expand Down
13 changes: 7 additions & 6 deletions dev/DemoApp1/plugin/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions dev/DemoApp1/plugin/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#[allow(warnings)]
mod bindings;

use bindings::host::common::types as CommonTypes;
use bindings::transact::plugin::intf as Transact;
use bindings::exports::demoapp1::example::intf::Guest as Intf;
use bindings::host::common::types as CommonTypes;
use bindings::invite;
use bindings::transact::plugin::intf as Transact;
use bindings::Guest as MainInterface;

use psibase::fracpack::Pack;
Expand All @@ -20,7 +20,7 @@ impl MainInterface for Component {

impl Intf for Component {
fn helloworld2() -> Result<String, CommonTypes::Error> {
Ok(invite::plugin::inviter::generate_invite("/subpath")?)
Ok(invite::plugin::inviter::generate_invite()?)
}

fn multiply(a: u32, b: u32) -> Result<String, CommonTypes::Error> {
Expand Down
13 changes: 7 additions & 6 deletions dev/DemoApp1/service/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions dev/demoapp1-build-and-deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ cd $root_dir

# Account Creation
echo "Creating demoapp1 account..."
psibase create -i $account_name
psibase -a dev create -i $account_name

pushd ./service
# Build service and deploy
cargo psibase deploy -p -i $account_name
cargo psibase deploy -a dev -p -i $account_name
popd

# Build plugin and copy to public dir
Expand All @@ -26,6 +26,6 @@ cd ./ui
rm -rf node_modules
rm -rf dist
yarn --mutex network && yarn build
psibase upload -r ./dist / -S $account_name
psibase -a dev upload -r ./dist / -S $account_name


118 changes: 62 additions & 56 deletions doc/psidk/src/specifications/blockchain/smart-authorization.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,38 @@
# Smart authorization

Account authorization can be done in many different ways: simple signature verification, time locks, zero-knowledge password proofs, multi-user authentication, and more. As technology progresses, new cryptographic techniques are discovered to improve the capabilities and efficiency of proving technology. Rather than attempt to add and maintain native support for all major authorization techniques, psibase instead describes a mechanism by which accounts are given full programmatic control over account authorization.
For an account to call an action defined in a service requires that the posted payload satisfies the authorization of the account.

Account authorization can use various techniques: simple signature verification, multi-signature verification, time locks, zero-knowledge proofs, and more. As technology progresses, new cryptographic techniques are discovered to improve the capabilities and efficiency of proving technology. Rather than attempt to add and maintain native support for all major authorization techniques, psibase instead describes a mechanism by which all accounts are given full programmatic control over how they should be authorized.

## Goals

* Enable accounts to have complete programmatic control over how their account can be authorized
* Allow developers to develop, deploy, and use custom cryptographic verification programs without requiring coordinated upgrades to the native node software
- Enable accounts to have complete programmatic control over how their account can be authorized
- Allow developers to develop, deploy, and use custom cryptographic verification programs without requiring coordinated upgrades to the native node software

## Design overview
## Design

### Definitions
### How it works

* **Claim** - Something that the submitter of a transaction claims to know (e.g. a public key)
* **Proof** - Conclusive evidence that the transaction submitter does actually know what she claims (e.g. a cryptographic signature)
* **Transaction** - A payload that specifies the intent of the sender to execute some code on the network
* **Auth service** - A service (configurable by each account) that specifies what claims are needed to authorize transactions from that account
* **Verify service** - A service that knows how to verify proof of a claim
#### Overview

### How it works
Individual accounts may specify how they want their account to be authorized. As the user interacts with psibase apps and publishes transactions to modify their state on the network, code is dynamically loaded on the client-side to ensure that the published transaction contains the necessary information to authorize the account. For example, if an account specifies that it uses a simple cryptographic signature for authorization, the psibase infrastructure on the client-side will automatically pull the corresponding signature-authorization plugin from the server and allow it to modify the transaction by adding signatures before it is published to the network.
swatanabe marked this conversation as resolved.
Show resolved Hide resolved

This is fully dynamic. Third-party developers can write their own authorization plugins, and accounts are free to use any authorization plugin.

#### Definitions

- **Claim** - Something that the submitter of a transaction claims to know (e.g. a public key)
- **Proof** - Conclusive evidence that the transaction submitter does actually know what she claims (e.g. a cryptographic signature)
- **Transaction** - A payload that specifies the intent of the sender to execute some code on the network
- **Auth service** - A service (configurable by each account) that specifies what claims are needed to authorize transactions from that account
- **Verify service** - A service that knows how to verify proof of a claim

#### Detailed steps

1. Every psibase account must specify an auth service
2. The auth service must enforce that transactions submitted by an account make one or more specific claims
3. A transaction gets submitted with: the claim(s) required by the auth service, a corresponding proof(s), the name of a verify service(s)
4. The auth service will verify the existence of the transaction claims, and that the correct verify service was specified.
4. The auth service will verify the existence of the needed claims in the transaction and that the correct verify service was specified.
5. The claim(s) and proof(s) are sent to the associated verify service(s), which can authorize (or fail) the transaction.

## Architecture
Expand Down Expand Up @@ -52,70 +62,66 @@ classDiagram
}
```

> Note: A `SignedTransaction` should be eventually renamed to something more generic, like `AuthedTransaction`, since "Signed" implies the specific claim/proof technique of using digital signatures.
> Note: A `SignedTransaction` should be renamed to something more generic, like `AuthedTransaction`, since "Signed" implies the specific claim/proof technique of using digital signatures.

The submitted `SignedTransaction` is sent to the AuthService defined by an account (e.g. [AuthSig](../../default-apps/auth-sig.md)) and the corresponding verification service. These services will fail the transaction if either the claims in the transaction are incorrect, or if the proof does not prove the claim.
The submitted `SignedTransaction` is sent to the auth service defined by an account (e.g. [AuthSig](../../default-apps/auth-sig.md)) and the corresponding verification service. These services will fail the transaction if either the claims in the transaction are incorrect, or if the proof does not prove the claim.

## Supervisor
## Client-side transaction construction

When building Psibase apps, the construction of each transaction submitted to the network is done automatically, including any claim and proof aggregation. The following sequence diagram shows how the supervisor aggregates claims and proofs. This entire interaction happens on the client-side.
When building psibase apps, the construction of each transaction submitted to the network is done automatically, including the aggregation of claims and generation of proofs. The following sequence diagram shows an example of a simple transaction being constructed. This entire interaction happens on the client-side.

```mermaid
sequenceDiagram

participant app
participant auth plugin
participant transact
participant supervisor
participant plugin
participant auth plugin

app->>supervisor: 1. action@plugin
app->>supervisor: call a plugin function
activate supervisor
supervisor->>auth plugin: 2. GetClaim()
activate auth plugin
auth plugin-->>supervisor: <claim>
deactivate auth plugin
note over supervisor: Add <claim> to transaction

supervisor->>plugin: 3. Call action
supervisor->>transact: start tx
activate transact
note right of transact: transaction {}
transact-->>supervisor: return
deactivate transact
supervisor->>plugin: function1()
activate plugin
plugin->>supervisor: 4. AddClaim(claim)
activate supervisor
note over supervisor: Add <claim> to transaction
supervisor-->>plugin:
deactivate supervisor
plugin-->>supervisor:
plugin->>transact: add-action-to-transaction
activate transact
note right of transact: transaction { { action1 } }
transact-->>plugin: return
deactivate transact
plugin-->>supervisor: return
deactivate plugin

supervisor->>supervisor: 5. Generate `hashedTransaction`<br>from the transaction<br>and its claims

supervisor->>auth plugin: 6. getProof(hashedTransaction, claim)
supervisor->>transact: finish tx
activate transact
note right of transact: Look up the user's auth service
transact->>auth plugin: get-claim
activate auth plugin
auth plugin->>supervisor: <proof>
auth plugin-->>transact: return <claim>
deactivate auth plugin
note over supervisor: Add <proof> to transaction

loop For each added claim
supervisor->>plugin: 7. getProof(hashedTransaction, claim)
activate plugin
plugin->>supervisor: <proof>
deactivate plugin
note over supervisor: Add <proof> to transaction
end

Note over supervisor: 8. Submit transaction
note right of transact: transaction { { action1, claim1 } }
transact->>auth plugin: get proof(transaction)
activate auth plugin
auth plugin-->>transact: return <proof>
deactivate auth plugin
note right of transact: transaction { { action1, claim1 }, proof1 }
transact-->>supervisor: return
deactivate transact
Note over supervisor: Submit transaction
deactivate supervisor
supervisor-->>app: return
```

The following is an explanation of each step in the diagram to aid understanding:
## Auth notifiers

At any time, a plugin can notify the `transact` plugin (which is responsible for transaction construction) that it has one or more claims to be added to the transaction. If this is done, at the time the transaction is being constructed, the `transact` plugin will ask this notifier for claims and proofs in addition to the user's auth service plugin.

## Transaction privacy

1. Alice calls an action on a plugin.
2. Supervisor gives the user's configured auth plugin the opportunity to add a claim to the transaction.
3. Supervisor calls the plugin action
4. If (and only if) a plugin calls a service action, then it is allowed to add a claim to the transaction.
5. Supervisor has accumulated all actions and claims for this transaction, so it calculates the hash of the transaction object which can be used for the generation of proofs (such as digital signatures).
6. The user's configured auth plugin is asked to generate a proof for the claim it added.
7. Each plugin that added a claim is asked for a proof of the claim.
8. Supervisor has collected all claims and proofs, therefore the final transaction object is packed and submitted to the network.
The only plugin that can see the full contents of a transaction is the user's auth service plugin. For every other plugin, it only knows what actions it was itself responsible for including in the transaction. This rule includes auth notifiers. While `transact` provides the user's auth service plugin with all actions in a transaction, it will only provide an auth-notifier with a list of actions that were added by the notifier plugin itself.

## Conclusion

Expand Down
5 changes: 3 additions & 2 deletions rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading