init secure greeter

This commit is contained in:
boneyard93501 2021-04-09 22:50:07 -05:00
parent f4350547d7
commit bff6358cc7
11 changed files with 326 additions and 0 deletions

7
par-greeter/secure-greeter/.gitignore vendored Normal file
View File

@ -0,0 +1,7 @@
.DS_Store
.repl_history
/target
**/**.bak
**/**.bk
/artifacts
keypair.json

178
par-greeter/secure-greeter/Cargo.lock generated Normal file
View File

@ -0,0 +1,178 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "fluence"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "342831732a977f13220ecd6f25c7e6b6127af8d3794d42e3c880b05e457a0484"
dependencies = [
"fluence-sdk-macro",
"fluence-sdk-main",
]
[[package]]
name = "fluence-sdk-macro"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "00c840552e5e58b62d4a272e3e4aabd548e1a4519df629a51d42157c7ecbe653"
dependencies = [
"fluence-sdk-wit",
]
[[package]]
name = "fluence-sdk-main"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1f1d126f05a798c8f812fbe47a42145478ce8029e00411b04d1c5194ab368313"
dependencies = [
"fluence-sdk-macro",
"log",
"serde",
]
[[package]]
name = "fluence-sdk-wit"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0ac71e8d48a8e2bdaccf59572dc7a8e8a1ad0de512fc452107756e37ac0bf752"
dependencies = [
"proc-macro2",
"quote",
"serde",
"serde_json",
"syn",
"uuid",
]
[[package]]
name = "getrandom"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c9495705279e7140bf035dde1f6e750c162df8b625267cd52cc44e0b156732c8"
dependencies = [
"cfg-if",
"libc",
"wasi",
]
[[package]]
name = "itoa"
version = "0.4.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dd25036021b0de88a0aff6b850051563c6516d0bf53f8638938edbb9de732736"
[[package]]
name = "libc"
version = "0.2.93"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9385f66bf6105b241aa65a61cb923ef20efc665cb9f9bb50ac2f0c4b7f378d41"
[[package]]
name = "log"
version = "0.4.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710"
dependencies = [
"cfg-if",
]
[[package]]
name = "proc-macro2"
version = "1.0.26"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a152013215dca273577e18d2bf00fa862b89b24169fb78c4c95aeb07992c9cec"
dependencies = [
"unicode-xid",
]
[[package]]
name = "quote"
version = "1.0.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c3d0b9745dc2debf507c8422de05d7226cc1f0644216dfdfead988f9b1ab32a7"
dependencies = [
"proc-macro2",
]
[[package]]
name = "ryu"
version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e"
[[package]]
name = "secure-greeter"
version = "0.1.0"
dependencies = [
"fluence",
"log",
]
[[package]]
name = "serde"
version = "1.0.118"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06c64263859d87aa2eb554587e2d23183398d617427327cf2b3d0ed8c69e4800"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.118"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c84d3526699cd55261af4b941e4e725444df67aa4f9e6a3564f18030d12672df"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "serde_json"
version = "1.0.64"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "799e97dc9fdae36a5c8b8f2cae9ce2ee9fdce2058c57a93e6099d919fd982f79"
dependencies = [
"itoa",
"ryu",
"serde",
]
[[package]]
name = "syn"
version = "1.0.69"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "48fe99c6bd8b1cc636890bcc071842de909d902c81ac7dab53ba33c421ab8ffb"
dependencies = [
"proc-macro2",
"quote",
"unicode-xid",
]
[[package]]
name = "unicode-xid"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564"
[[package]]
name = "uuid"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7"
dependencies = [
"getrandom",
]
[[package]]
name = "wasi"
version = "0.10.2+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6"

View File

@ -0,0 +1,13 @@
[package]
name = "secure-greeter"
version = "0.1.0"
authors = ["The Fluence Team"]
edition = "2018"
[[bin]]
name = "secure_greeter"
path = "src/main.rs"
[dependencies]
fluence = { version="0.5.0", feature=["log"]}
log = "0.4.14"

View File

@ -0,0 +1,6 @@
modules_dir = "artifacts/"
[[module]]
name = "secure_greeter"
mem_pages_count = 1
logger_enabled = false

View File

@ -0,0 +1,17 @@
(xor
(seq
(seq
(call relay ("op" "identity") [])
(call node (greeter "greeting") [name] result)
)
(seq
(call relay ("op" "identity") [])
(call %init_peer_id% (returnService "run") [result])
)
)
(seq
(call relay ("op" "identity") [])
(call %init_peer_id% (returnService "run") ["XOR FAILED" %last_error%])
)
)

View File

@ -0,0 +1,9 @@
#!/usr/bin/env bash -o errexit -o nounset -o pipefail
# This script builds all subprojects and puts all created Wasm modules in one dir
mkdir -p artifacts
cargo update
fce build --release
rm -f artifacts/*.wasm
cp target/wasm32-wasi/release/secure_greeter.wasm artifacts/

View File

@ -0,0 +1,3 @@
{
"name": "secure_greeter"
}

View File

@ -0,0 +1,4 @@
#!/usr/bin/env bash
echo "secure greeter new service:"
fldist new_service --node 12D3KooWQYAEG4LJCUYZtnGAxjsDnkfnKSxfrML2RrTLY63dd33U --node-addr /ip4/127.0.0.1/tcp/9999/ws/p2p/12D3KooWQYAEG4LJCUYZtnGAxjsDnkfnKSxfrML2RrTLY63dd33U --name "secure-greeter" --modules artifacts/secure_greeter.wasm:configs/secure_greeter_cfg.json

View File

@ -0,0 +1,12 @@
./deploy.sh
secure greeter new service:
client seed: 6waFrz5AtYFetZvaKHwv94KtLjyQzXwcdDMacaS69GCQ
client peerId: 12D3KooWQt8imsDnzigvv6RYFDCEU5JDApRjfrGnBLxahRM24XMD
relay peerId: 12D3KooWQYAEG4LJCUYZtnGAxjsDnkfnKSxfrML2RrTLY63dd33U
service id: a3a5c871-7be2-4b8f-ae6e-e14410df7184
service created successfully
fldist --node 12D3KooWQYAEG4LJCUYZtnGAxjsDnkfnKSxfrML2RrTLY63dd33U --node-addr /ip4/127.0.0.1/tcp/9999/ws/p2p/12D3KooWQYAEG4LJCUYZtnGAxjsDnkfnKSxfrML2RrTLY63dd33U run_air -p air-scripts/air_greet.clj -d '{"node":"12D3KooWQYAEG4LJCUYZtnGAxjsDnkfnKSxfrML2RrTLY63dd33U", "greeter":"a3a5c871-7be2-4b8f-ae6e-e14410df7184", "name":"boo yah"}'
fldist --node 12D3KooWQYAEG4LJCUYZtnGAxjsDnkfnKSxfrML2RrTLY63dd33U --node-addr /ip4/127.0.0.1/tcp/9999/ws/p2p/12D3KooWQYAEG4LJCUYZtnGAxjsDnkfnKSxfrML2RrTLY63dd33U run_air -p air-scripts/air_greet.clj -d '{"node":"12D3KooWQYAEG4LJCUYZtnGAxjsDnkfnKSxfrML2RrTLY63dd33U", "greeter":"a3a5c871-7be2-4b8f-ae6e-e14410df7184", "name":"boo yah"}' --s 6waFrz5AtYFetZvaKHwv94KtLjyQzXwcdDMacaS69GCQ

View File

@ -0,0 +1,31 @@
/*
* Copyright 2021 Fluence Labs Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
use ::fluence;
use fluence::{fce, CallParameters};
pub fn is_owner() -> bool {
let meta = fluence::get_call_parameters();
let caller = meta.init_peer_id;
let owner = meta.service_creator_peer_id;
caller == owner
}
#[fce]
pub fn am_i_owner() -> bool {
is_owner()
}

View File

@ -0,0 +1,46 @@
/*
* Copyright 2020 Fluence Labs Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
use fluence::fce;
use fluence::module_manifest;
mod auth;
use crate::auth::is_owner;
module_manifest!();
pub fn main() {}
#[fce]
#[derive(Debug)]
pub struct Gresult {
pub greeting: String,
pub err_str: String,
}
#[fce]
pub fn greeting(name: String) -> Gresult {
if !is_owner() {
return Gresult {
greeting: "".into(),
err_str: "You are not the owner".into(),
};
}
Gresult {
greeting: format!("Hi, {}", name),
err_str: "".into(),
}
}