-
Notifications
You must be signed in to change notification settings - Fork 81
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
Use newtypes to wrap basic types for more type safety #32
Comments
I like it! |
Use a new "Key" type to wrap the master key (derived from the SPAKE2 exchange), for better typechecking. refs #32
I'm working through this process for all the String types that we use: I've gotten Side (both ours and theirs), Key, and Nameplates done so far. I just started work on Code, and discovered a subtle and serious bug: the (a brief crypto digression so I have this written down somewhere) On Alice's side, SPAKE2 (in symmetric mode, so M=N) accepts a secret password However, if we swap
The I'll fix this when I land the newtypes code that revealed it. Interestingly, the SPAKE2 API itself doesn't protect us here (it's defined as So I'm thinking that SPAKE2.rs could benefit from a safer (i.e. different) set of types in its arguments. I wanted the |
See https://github.com/warner/magic-wormhole.rs/issues/32 for details. This would have enabled a cheap online man-in-the-middle attack. The buggy version would interoperate silently with itself (although it wouldn't have spoken to the Python version, so we probably would have caught it pretty quickly).
Adds newtypes for MySide, TheirSide, Nameplate, and Code. Still a few more to add. refs #32
Ok, I think I've implemented all the easy ones. The next set to tackle will be different flavors of messages:
There are a couple of places that should hold JSON |
This a breaking API change. The next release should bump the minor version number. As discussed in #3 and https://github.com/warner/magic-wormhole.rs/issues/32 , if an application were to accidentally swap the "password" and "identity" arguments (mainly for start_symmetric which only takes two args), the app would appear to work, but would contain a devastating security vulnerability (online brute-force password attack, with precomputation enabled). You might think of newtypes as giving the API named parameters. Instead of: `s = start_symmetric(b"pw", b"appid")` you get: `s = start_symmetric(&Password::new(b"pw"), &Identity::new(b"appid"))` but it protects you (with a compile-time error) against mistakes like: `s = start_symmetric(&Identity::new(b"appid"), &Password::new(b"pw"))` I'd like to find a way to remove requirement to pass a reference (and enable `start_symmetric(Password::new(..)..)`).
We can use newtypes to wrap Strings etc to make a zero-cost type for say,
Side
,Phase
,Body
and so on.. This would make the code a lot more typesafe.The text was updated successfully, but these errors were encountered: