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

Compile to WASM #46

Closed
str4d opened this issue Dec 31, 2019 · 11 comments
Closed

Compile to WASM #46

str4d opened this issue Dec 31, 2019 · 11 comments

Comments

@str4d
Copy link
Owner

str4d commented Dec 31, 2019

Let's make the age crate usable in WASM!

@str4d str4d closed this as completed in dcae604 Jan 2, 2020
@str4d
Copy link
Owner Author

str4d commented Jan 2, 2020

The crate can now be compiled to WASM:

cargo build --lib --target wasm32-unknown-unknown --no-default-features

@benmkw
Copy link

benmkw commented Mar 17, 2020

I was experimenting with creating a web ui for age.

I'm having an issue with std::time::SystemTime::now on target wasi-unkown-unknown.
This appears to be a known limitation rust-lang/rust#48564 (comment)

Because an upstream fix seems unlikely in the near future a workaround may be useful.

The easiest fix is to hardcode workload values for scrypt used for passphrase things but maybe this is not appropriate. (doing this makes passphrase based de/encryption work so nothing else is blocking)

at std::time::SystemTime::now::h1e14849775e247ed (wasm-function[4185]:0x13af88)
    at age::format::scrypt::target_scrypt_work_factor::hb3a1eefd94ad935d (wasm-function[364]:0xc9939)
    at age::format::scrypt::RecipientLine::wrap_file_key::hf9740611422cef03 (wasm-function[103]:0x9a9c4)
    at age::protocol::EncryptorType::wrap_file_key::h8632c3a0773139d9 (wasm-function[237]:0xb7bff)
    at age::protocol::Encryptor::wrap_output::h99da53e943eaf299 (wasm-function[66]:0x8c2ff)

@str4d
Copy link
Owner Author

str4d commented Mar 17, 2020

@benmkw I've opened #90 which should hopefully fix your problem. Please test that branch and let me know there if it works for you. It would be great if you could test both wasm32-unknown-unknown and wasm32-wasi targets! 🙂

@benmkw
Copy link

benmkw commented Mar 17, 2020

thanks for the quick response! I like the fix, it works on wasm32-unknown-unknown. I currently don't have a wasi enabled environment ready unfortunately.

The only remaining problem I have is that on my dualcore i7 laptop (not the best, not the worst) it takes ages (no pun intended) (like about three minutes).

(Given that I'd expect about a 2x perf decrease from web assembly this seems a bit off to me.
As far as I know I am building in release mode but given that I don't yet fully understand the webpack config I'm currently running I could be off.)

When I "hacked" up the solution I used a value of 12 which still "felt" quick, (but not instantaneous).

If your judgement is that 18 should be kept thats fine with me as I can patch it up for experiments if needed.

@str4d
Copy link
Owner Author

str4d commented Mar 18, 2020

Yeah, do check that you aren't in debug mode. This tripped me up earlier; rage was auto-selecting 12 as around one second of work in debug, but 18 in release mode, and because these differ by more than 4 I couldn't decrypt in debug mode anything I encrypted in release mode.

I'll see if I can use the cfg flags to handle the guesses internally. If it turns out that we need different guesses for different targets, I'll rework the PR.

@benmkw
Copy link

benmkw commented Mar 18, 2020

This tripped me up earlier; rage was auto-selecting 12 as around one second of work in debug, but 18 in release mode

This very much sounds like it could be my issue so thats good to know. Based on that
I'd say just assume its fine the way you did it and I'll come back if I'm sure changes are needed.

@str4d
Copy link
Owner Author

str4d commented Mar 18, 2020

Sounds good. Please open a new issue for any future requests or feedback 🙂

@pirate
Copy link

pirate commented Sep 11, 2020

@benmkw I'm curious, did you ever get a web UI up and running to use Age? What's the JS usage like once it's compiled to WASM?

(It'd help me a ton to see any code snippets of the JS API even if you never got a full thing running!)

@str4d
Copy link
Owner Author

str4d commented Sep 11, 2020

I started building a WASM wrapper for rage here: https://github.com/str4d/wage

I'd definitely appreciate contributions there from people who know JavaScript better than I (or even better, converting what's there to TypeScript).

@benmkw
Copy link

benmkw commented Sep 11, 2020

So I have a small project up as well but it’s just using strings as in and output so that’s not ideal, I think @str4d project handles this much better using streams so probably better to look at that.
I‘m also trying to convert my project to TS but the typing support for svelte ui things is not totally there yet and I’m not currently investing much time into it either.

Speed was about 2x slower than native I believe so i think age on the web is totally feasible.

@benmkw
Copy link

benmkw commented Sep 13, 2020

@pirate one thing that might be nice is to have npm run dev e.g. invoke cargo, in my setup you can change any rust or js/ts file and everything reloads as necessary (https://github.com/benmkw/svelte_rust_test) but these things always take some trial and error but I guess this would be appreciated :D

@str4d a friend made these mockups for an app UI/ mobile version which we could translate (sorry its german, was just a quick mockup) to englisch and share if that would help, we did not yet manage to make much progress on the coding part (time and stuff :D) so its basically just collecting dust at the moment. The UI we imagined is basically:

  1. you create (or upload) a key
    1.1. you can share your pub key as text or QR code
  2. select if you want to encrypt or decrypt
    app1
    key
    app2

This is not perfect but we thought about making this as approachable as possible basically for non IT people. There are some considerations e.g. if the user does not input a password, a strong one time key could be generated and if a password is used that would not be ideal but the user can reuse that several times using password based enc/dec. Also the enc/ dec screens are not displayed here.
I don't think saving your or others keys in the web-app is necessary as this probably opens a whole selection of new issues.

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

No branches or pull requests

3 participants