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

feat(user-auth): initial implementation #1

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

jdvlio
Copy link
Contributor

@jdvlio jdvlio commented Jan 13, 2023

Initial implementation of the user authentication enclave

@jdvlio jdvlio requested review from sonasi and tshepang January 13, 2023 11:11
@jdvlio jdvlio force-pushed the feat-initial-user-auth-enclave branch 6 times, most recently from be2452a to 906fb31 Compare January 17, 2023 11:15
@jdvlio jdvlio force-pushed the feat-initial-user-auth-enclave branch 8 times, most recently from 473784e to 45b9074 Compare January 24, 2023 10:34
user-auth/README.md Outdated Show resolved Hide resolved
| |-- Enclave.lds
| |-- Makefile
| |-- Xargo.toml
| +-- rust-toolchain
Copy link
Contributor

Choose a reason for hiding this comment

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

same here, to avoid duplicating this info

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a draft only. The final version will look different.

@tshepang
Copy link
Contributor

General note: copyright blurbs are not needed at the top of the source files, because LICENSE (at the repo root) should cover it. See Rust project (rust-lang/rust) as an example.

@jdvlio jdvlio force-pushed the feat-initial-user-auth-enclave branch from 45b9074 to e084035 Compare January 26, 2023 08:01
@tshepang
Copy link
Contributor

I see that we actually have a mix of licenses, something to be clear about (what is the criteria?).

As a sidenote, it looks like one can create AGPL software that depends (via static or dynamic linking) on Apache 2 software.

@jdvlio jdvlio force-pushed the feat-initial-user-auth-enclave branch from e084035 to 391c07d Compare January 26, 2023 10:06
@jdvlio
Copy link
Contributor Author

jdvlio commented Jan 26, 2023

General note: copyright blurbs are not needed at the top of the source files, because LICENSE (at the repo root) should cover it. See Rust project (rust-lang/rust) as an example.

In this case yes but this is not true in general. Free software licenses, even permissive ones. virtually always require that one preserve any copyright notices. See for example section 4 of the Apache-2.0 license.

@jdvlio jdvlio force-pushed the feat-initial-user-auth-enclave branch from 391c07d to fb2d3b6 Compare January 26, 2023 10:19
@jdvlio jdvlio requested a review from tshepang January 26, 2023 10:35
@jdvlio jdvlio force-pushed the feat-initial-user-auth-enclave branch from fb2d3b6 to 15d4de7 Compare January 26, 2023 10:37
@tshepang
Copy link
Contributor

ah, good to know

@jdvlio jdvlio force-pushed the feat-initial-user-auth-enclave branch 3 times, most recently from fd94cf6 to 26bd60a Compare January 26, 2023 13:16
@jdvlio jdvlio force-pushed the feat-initial-user-auth-enclave branch 5 times, most recently from f23ded4 to 259933f Compare January 31, 2023 09:47
@jdvlio jdvlio changed the base branch from main to doc-clarify-repo-purpose January 31, 2023 09:48
@jdvlio jdvlio requested review from IscoRuta98 and tshepang January 31, 2023 09:58
@jdvlio jdvlio force-pushed the feat-initial-user-auth-enclave branch from 259933f to 4c7fd4d Compare February 2, 2023 09:42
@jdvlio jdvlio force-pushed the feat-initial-user-auth-enclave branch from 4c7fd4d to 5261174 Compare February 8, 2023 07:41
Base automatically changed from doc-clarify-repo-purpose to main February 11, 2023 00:18
@tshepang tshepang marked this pull request as ready for review February 14, 2023 00:24
@sonasi sonasi requested a review from tshepang February 14, 2023 13:17
user-auth/enclave/src/lib.rs Outdated Show resolved Hide resolved
user-auth/enclave/Cargo.toml Outdated Show resolved Hide resolved
user-auth/enclave/src/lib.rs Outdated Show resolved Hide resolved
@@ -0,0 +1,161 @@
#![no_std]
Copy link
Contributor

Choose a reason for hiding this comment

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

perhaps redundant, since std will result in build errors anyways

Copy link
Contributor

Choose a reason for hiding this comment

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

unexcellent thought... ignore me

user-auth/app/src/ecall.rs Outdated Show resolved Hide resolved
user-auth/app/src/lib.rs Outdated Show resolved Hide resolved
Comment on lines 38 to 21
fn new_hash_context<'a>(pepper: &'a [u8]) -> Result<Argon2<'a>, argon2::Error> {
Argon2::<'a>::new_with_secret(
Copy link
Contributor

Choose a reason for hiding this comment

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

lifetime could be elided

let hash_ctx = new_hash_context(pepper.as_ref());

match hash_ctx {
Err(_) => sgx_status_t::SGX_ERROR_UNEXPECTED,
Copy link
Contributor

Choose a reason for hiding this comment

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

would be kool to display the error value (perhaps with eprintln! OCALL), of if it really is not useful, use an if let Ok(ctx) to reduce right-ward drift (and perhaps improve readability)

Comment on lines 27 to 30
// Convert the Argon2 memory cost from MiB to KiB
const fn m_cost_calc(mebibytes: u32) -> {
mebibytes * 1024
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just do this in a constant called M_COST_KIB and remove M_COST_MIB. Much simpler.

/// dynammically calculated!
// XXX: Certain assumptions are made here that relate to the hash context. See
// the doc comment above.
pub const HASH_STRING_LENGTH: usize = 97;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Link the PHC specification

@jdvlio jdvlio force-pushed the feat-initial-user-auth-enclave branch from 5261174 to fea6380 Compare March 6, 2023 15:46
@@ -3,4 +3,5 @@
[workspace]
members = [
"sealing",
"user-auth"
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
"user-auth"
"user-auth",

make diffs more pleasant to read :)

@@ -0,0 +1,8 @@
[package]
name = "user-auth-common"
version = "0.1.0"
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I like leaving this at 0.0.0 until we actually make releases, where it actually matters

Comment on lines +5 to +8

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: noise :)

Suggested change
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

@@ -0,0 +1 @@
{"rustc_fingerprint":14295617405981936619,"outputs":{"15697416045686424142":{"success":true,"status":"","code":0,"stdout":"___\nlib___.rlib\nlib___.so\nlib___.so\nlib___.a\nlib___.so\n","stderr":""},"10376369925670944939":{"success":true,"status":"","code":0,"stdout":"___\nlib___.rlib\nlib___.so\nlib___.so\nlib___.a\nlib___.so\n/home/jean-pierre/.rustup/toolchains/nightly-2022-10-22-x86_64-unknown-linux-gnu\ndebug_assertions\npanic=\"unwind\"\nproc_macro\ntarget_abi=\"\"\ntarget_arch=\"x86_64\"\ntarget_endian=\"little\"\ntarget_env=\"gnu\"\ntarget_family=\"unix\"\ntarget_feature=\"fxsr\"\ntarget_feature=\"llvm14-builtins-abi\"\ntarget_feature=\"sse\"\ntarget_feature=\"sse2\"\ntarget_has_atomic=\"16\"\ntarget_has_atomic=\"32\"\ntarget_has_atomic=\"64\"\ntarget_has_atomic=\"8\"\ntarget_has_atomic=\"ptr\"\ntarget_has_atomic_equal_alignment=\"16\"\ntarget_has_atomic_equal_alignment=\"32\"\ntarget_has_atomic_equal_alignment=\"64\"\ntarget_has_atomic_equal_alignment=\"8\"\ntarget_has_atomic_equal_alignment=\"ptr\"\ntarget_has_atomic_load_store=\"16\"\ntarget_has_atomic_load_store=\"32\"\ntarget_has_atomic_load_store=\"64\"\ntarget_has_atomic_load_store=\"8\"\ntarget_has_atomic_load_store=\"ptr\"\ntarget_os=\"linux\"\ntarget_pointer_width=\"64\"\ntarget_thread_local\ntarget_vendor=\"unknown\"\nunix\n","stderr":""},"4614504638168534921":{"success":true,"status":"","code":0,"stdout":"rustc 1.66.0-nightly (5c8bff74b 2022-10-21)\nbinary: rustc\ncommit-hash: 5c8bff74bc1c52bef0c79f3689bb227f51f3e82d\ncommit-date: 2022-10-21\nhost: x86_64-unknown-linux-gnu\nrelease: 1.66.0-nightly\nLLVM version: 15.0.2\n","stderr":""}},"successes":{}}
Copy link
Contributor

Choose a reason for hiding this comment

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

hm, somehow .gitignore was ignored :)

password-hash = { version = "0.4", features = ["std"] }
argon2 = { version = "0.4", features = ["rand"] }

[patch.'https://github.com/apache/teaclave-sgx-sdk.git']
Copy link
Contributor

Choose a reason for hiding this comment

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

unused patch

Comment on lines +88 to +91
match verify_status {
VerifyPasswordStatus::InvalidPassword => Ok(VerifyPasswordStatus::InvalidPassword),
VerifyPasswordStatus::PasswordVerified => Ok(VerifyPasswordStatus::PasswordVerified),
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
match verify_status {
VerifyPasswordStatus::InvalidPassword => Ok(VerifyPasswordStatus::InvalidPassword),
VerifyPasswordStatus::PasswordVerified => Ok(VerifyPasswordStatus::PasswordVerified),
}
Ok(verify_status)

user_auth_sgx,
InvalidHashString,
PyException,
"supplied hash is not a valid PHC string"
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
"supplied hash is not a valid PHC string"
"supplied hash is not a valid PHC string",

<ProdID>0</ProdID>
<ISVSVN>0</ISVSVN>
<StackMaxSize>0x40000</StackMaxSize>
<HeapMaxSize>0x1600000</HeapMaxSize>
Copy link
Contributor

Choose a reason for hiding this comment

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

would be kool to explan here why this was increased

@@ -0,0 +1,161 @@
#![no_std]
Copy link
Contributor

Choose a reason for hiding this comment

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

unexcellent thought... ignore me

unsafe { *verify_status = VerifyPasswordStatus::InvalidPassword };
sgx_status_t::SGX_SUCCESS
}
Err(_) => sgx_status_t::SGX_ERROR_UNEXPECTED,
Copy link
Contributor

Choose a reason for hiding this comment

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

I would at least do eprintln! ocall, or debugging this may get unpleasant, requiring a re-compile. We can also do a TODO note, so we don't forget to look at it again when it gets to production.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants