-
Notifications
You must be signed in to change notification settings - Fork 144
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
Initial WasmThemis wrapper #461
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 task
The new wrapper was christened "WasmThemis". Let's get rolling! It will live under src/wrappers/themis/wasm. Introduce a new submakefile "wasmthemis.mk" which will contain all specific targets and configuration for building WasmThemis. The main target is "wasm_themis", that's our user-facing target which should be used by developers. It will build the wrapper in BUILD_PATH. We still don't have a proper wrapper so instead we're going to build libthemis.js library for now. This is our 'native code' as far as JavaScript is concerned. It simply links Themis static library and its dependencies with `emcc`. Note, however, a couple of caveats: - Use EMSCRIPTEN_KEEPALIVE marker for public API Emscripten does dead-code elimination when linking final WebAssembly application. Anything not called from main() will be removed. And if there is no main() -- typical for a library, eh? -- then everything will be removed. We don't want that, so we use EMSCRIPTEN_KEEPALIVE to keep LLVM from optimizing out the functions we're going to use. - Use EXTRA_EXPORTED_RUNTIME_METHODS to keep preamble.js API Emscripten provides a bunch of useful utilities for interacting with its sandbox from JavaScript. However, they are also optimized out by default. We need to explicitly list the APIs we're going to use. Finally, all WebAssembly builds must be performed in properly configured Emscripten environment. That is, by calling "emmake make wasm_themis". Add a simple check before running the build to ensure that the developer did not forget to use emmake.
We're going to publish WasmThemis via npm, create a package for that. Let's be nice and provide README and LICENSE files, fill in some informational fields in in package.json, etc. Note also these carefully crafted .gitignore and .npmignore files. They are meant to ensure that developers could do their thing in the working copy without accidentally committing unnecessary files to git or publishing them on npm. The package is currently marked as _private_ to prevent accidental publish. However, it is going to be named "wasm-themis" and that's the name used in README. As for the wrapper code itself, let's start with secure key generation. This gives us a good start as we need to provide all the scaffolding around Node.js modules and Themis error handling. The interface stays similar to JsThemis, but there are no compatibility requirements. Thus we are able to provide strongly typed PrivateKey and PublicKey wrappers over Uint8Array, and expose then as read-only properties of KeyPair.
Add some test using Mocha as test runner (just like we do for JsThemis). We don't have much API to check, just verify some basic invariants. Add "test_wasm" target to Makefile and integrate that into CI builds. Note that this target has to be run with 'emmake' helper.
d5350fa
to
beb358f
Compare
Ready for review, please take a look. |
Lagovas
approved these changes
Apr 16, 2019
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
infrastructure
Automated building and packaging
W-WasmThemis 🌐
Wrapper: WasmThemis, JavaScript API, npm packages
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I'm getting better at writing JavaScript. Here's an initial version of WasmThemis wrapper. This is basic scaffolding that has
which is good enough for start. It covers only key generation API, but adding other functions should be mostly mechanical job now. (Well, maybe except for Secure Session and its callbacks which are going to get tricky.)
The new wrapper was christened WasmThemis. Let's get rolling! It will live under
src/wrappers/themis/wasm
.Introduce a new submakefile
wasmthemis.mk
which will contain all specific targets and configuration for building WasmThemis. The main target iswasm_themis
, that's our user-facing target which should be used by developers. It will build the wrapper in BUILD_PATH.We still don't have a proper wrapper so instead we're going to build libthemis.js library for now. This is our 'native code' as far as JavaScript is concerned. It simply links Themis static library and its dependencies with
emcc
. Note, however, a couple of caveats:Use EMSCRIPTEN_KEEPALIVE marker for public API
Emscripten does dead-code elimination when linking final WebAssembly application. Anything not called from main() will be removed. And if there is no main() — typical for a library, eh? — then everything will be removed. We don't want that, so we use EMSCRIPTEN_KEEPALIVE to keep LLVM from optimizing out the functions we're going to use.
Use EXTRA_EXPORTED_RUNTIME_METHODS to keep preamble.js API
Emscripten provides a bunch of useful utilities for interacting with its sandbox from JavaScript. However, they are also optimized out by default. We need to explicitly list the APIs we're going to use.
Finally, all WebAssembly builds must be performed in properly configured Emscripten environment. That is, by calling
emmake make wasm_themis
. Add a simple check before running the build to ensure that the developer did not forget to use emmake.We're going to publish WasmThemis via npm, create a package for that. Let's be nice and provide README and LICENSE files, fill in some informational fields in in package.json, etc. Note also these carefully crafted .gitignore and .npmignore files. They are meant to ensure that developers could do their thing in the working copy without accidentally committing unnecessary files to git or publishing them on npm.
The package is currently marked as private to prevent accidental publish. However, it is going to be named wasm-themis and that's the name used in README.
As for the wrapper code itself, let's start with secure key generation. This gives us a good start as we need to provide all the scaffolding around Node.js modules and Themis error handling. The interface stays similar to JsThemis, but there are no compatibility requirements. Thus we are able to provide strongly typed PrivateKey and PublicKey wrappers over Uint8Array, and expose then as read-only properties of KeyPair.
Add some test using Mocha as test runner (just like we do for JsThemis). We don't have much API to check, just verify some basic invariants.
Add
test_wasm
target to Makefile and integrate that into CI builds. Note that this target has to be run with emmake helper.