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

Adjust Crypto, CipherParams and ChannelOptions to spec. #231

Merged
merged 3 commits into from
Feb 29, 2016
Merged

Conversation

tcard
Copy link
Contributor

@tcard tcard commented Feb 19, 2016

#211 (comment)

I've kept the IV param in Crypto.getDefaultParams for the reasons mentioned in the discussion.

@tcard tcard mentioned this pull request Feb 19, 2016
@tcard
Copy link
Contributor Author

tcard commented Feb 19, 2016

After a conversation with @paddybyers and @mattheworiordan, it seems like the iOS library is doing this pretty wrong. The IV is supposed to be randomly generated in every message (it's currently being set when instantiating the channel only), and it's communicated as the first block in every encrypted message data. Java already does this, could take a look there.

This PR can be merged for now, but the IV param will be gone in a followup.

@mattheworiordan
Copy link
Member

Sure, looks like it can be merged. Equally, not difficult to add another commit onto this PR to address iv in the correct way i.e. randomly generated for each encoding

@tcard
Copy link
Contributor Author

tcard commented Feb 23, 2016

@mattheworiordan Done. Turns out it was actually doing that already, so I've only added a test in the end. I also checked with another library to confirm that the implementations are compatible.

@tcard tcard force-pushed the fix-crypto-api branch 2 times, most recently from a4382cd to a3c4208 Compare February 23, 2016 11:52
@ricardopereira
Copy link
Contributor

LGTM

This was referenced Feb 24, 2016
@@ -1297,6 +1299,66 @@ class RealtimeClientChannel: QuickSpec {

}

context("crypto") {
it("if configured for encryption, channels encrypt and decrypt messages' data") {
Copy link
Member

Choose a reason for hiding this comment

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

I like this test, however I am concerned that at no point are we actually checking that the message is encrypted i.e. if you removed the cipher options completely this test would still pass. A simple way to make sure this test is actually checking for encrypted messages is to add another subscriber that has encryption disabled and check that the messages are received with an encrypted payload i.e. data should be different and encoding should indicate it's an encrypted payload

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right now that wouldn't work, because that behavior is not working properly (see #211). Can I just intercept the raw ProtocolMessage and check that the data is encoded and the encoding is set there?

Copy link
Member

Choose a reason for hiding this comment

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

Ok sure intercept is fine

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done at 88ea27c.

@tcard
Copy link
Contributor Author

tcard commented Feb 24, 2016

API is about to change, discussion at ably/docs#89 (comment). Once that's settled I make the changes here.

@tcard
Copy link
Contributor Author

tcard commented Feb 29, 2016

@mattheworiordan @ricardopereira PTAL

@mattheworiordan
Copy link
Member

@tcard this looks good, but can you confirm that the iv is randomly generated and used for every message that is encoded?

@tcard
Copy link
Contributor Author

tcard commented Feb 29, 2016

@tcard this looks good, but can you confirm that the iv is randomly generated and used for every message that is encoded?

@mattheworiordan Fixed at 2d6e9b7. I realized along the way that the IV was being chained between messages when encrypting, I thought I checked this already but apparently I only did so for decryption, which was right. So I had to fix that.

Now CipherParams only has an IV for testing. If set, encrypt will use that, and if not, it will generate a random one.

@ricardopereira
Copy link
Contributor

LGTM

1 similar comment
@mattheworiordan
Copy link
Member

LGTM

When decrypting, IV is being extracted from the beginning of the
message's data blob. When encrypting, the IV should be random, and
there's no point in taking it as an argument except for testing.

I've added and end-to-end test that sends and receives encrypted
messages. I've also run it with ably/ably-js as sender and receiver
and it works.
tcard added a commit that referenced this pull request Feb 29, 2016
Adjust Crypto, CipherParams and ChannelOptions to spec.
@tcard tcard merged commit b8a3954 into master Feb 29, 2016
@ricardopereira ricardopereira deleted the fix-crypto-api branch March 2, 2016 10:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants