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

Add new schemes for encrypted licenses #242

Merged
merged 30 commits into from
Sep 17, 2018
Merged

Conversation

ezekg
Copy link
Member

@ezekg ezekg commented Aug 5, 2018

Closes #178.

@ezekg ezekg force-pushed the feature/encrypted-licenses branch 4 times, most recently from 27b5dcb to 5b76f41 Compare August 5, 2018 08:23
@ezekg
Copy link
Member Author

ezekg commented Aug 5, 2018

After thinking on this more, I want to allow these schemes:

  • RSA_2048_ENCRYPT
  • RSA_2048_SIGN

@ezekg
Copy link
Member Author

ezekg commented Aug 5, 2018

Thinking on this even more, the RSA_2048_SIGN scheme doesn't make a lot of sense, to be honest, because we'd need the raw license key to do the verification. Might still keep it though…

Edit: we should keep it.

@ezekg ezekg force-pushed the feature/encrypted-licenses branch 3 times, most recently from 86643bb to d3b8da7 Compare August 5, 2018 20:26
@ezekg
Copy link
Member Author

ezekg commented Aug 5, 2018

Need to write tests for:

  • Providing an expiry during license creation
  • RSA_2048_ENCRYPT scheme for policies
  • RSA_2048_SIGN scheme for policies
  • RSA_2048_ENCRYPT scheme for licenses
  • RSA_2048_SIGN scheme for licenses
  • Invalid schemes for policies
  • Encrypted key validations

@ezekg
Copy link
Member Author

ezekg commented Aug 10, 2018

Currently, disallowing a nil encryptionScheme is a breaking change. Need to allow nil and then default to the LEGACY scheme.

@ezekg ezekg force-pushed the feature/encrypted-licenses branch from 77fcf9a to 51c03a4 Compare August 10, 2018 20:20
@ezekg
Copy link
Member Author

ezekg commented Aug 19, 2018

Need to update RSA encryption padding: https://stackoverflow.com/questions/16325057/why-does-rsa-encrypted-text-give-me-different-results-for-the-same-text. Should use OAEP padding.

Nevermind—that's not how RSA works. OAEP isn't available for private key encryption.

@ezekg
Copy link
Member Author

ezekg commented Aug 20, 2018

Would be cool to use RSA_PKCS1_PSS_PADDING, but that doesn't seem to be supported in most programming languages, and I'm not sure how to implement directly using OpenSSL (link is to BoringSSL, but OpenSSL is the same AFAIK).

Maybe we should file an issue? See this issue which added support for PSS signing/verification for Ruby's OpenSSL implementation: ruby/openssl#75.

@ezekg
Copy link
Member Author

ezekg commented Aug 21, 2018

Rename schemes for easier addition in the future:

  • RSA_2048_ENCRYPT -> RSA_2048_PKCS1_ENCRYPT
  • RSA_2048_SIGN -> RSA_2048_PKCS1_SIGN

New schemes:

  • RSA_2048_PKCS1_PSS_ENCRYPT (OpenSSL doesn't support the verify_restore op for PSS)
  • RSA_2048_PKCS1_PSS_SIGN
  • RSA_2048_JWT_RS256

To be able to support RSA_2048_PKCS1_PSS_SIGN, we'll need to use latest of this openssl gem instead of the packaged openssl gem that ships with Ruby, since PSS only ships with Ruby >= 2.5.

I've been working on adding RSA_2048_PKCS1_PSS_ENCRYPT to Ruby's openssl gem, but I'm not even sure if OpenSSL supports it from my initial tests; BoringSSL does, however. It's odd that BoringSSL implements private_encypt and public_decrypt with PSS but OpenSSL does not.

I think the above was incorrect docs on BoringSSL's part. PSS does not support encryption.

@ezekg ezekg force-pushed the feature/encrypted-licenses branch from 4002083 to 59956f7 Compare August 23, 2018 17:51
@ezekg
Copy link
Member Author

ezekg commented Aug 31, 2018

Let's also add a JWT encryption scheme, RSA_2048_JWT_RS256.

@ezekg ezekg force-pushed the feature/encrypted-licenses branch 2 times, most recently from 5eae32e to 0d37d38 Compare September 3, 2018 19:13
@ezekg
Copy link
Member Author

ezekg commented Sep 5, 2018

Maybe implement Plaseto as well? To supplement JWT. Edit: eh—the Ruby lib seems poorly maintained and I don't want to add the risk.

@ezekg
Copy link
Member Author

ezekg commented Sep 6, 2018

I think I want to drop the new signature column and combine that into the key, JWT-style.

E.g.

"{KEY}.{SIGNATURE}"

@ezekg ezekg force-pushed the feature/encrypted-licenses branch 2 times, most recently from ece67dd to 64ac73a Compare September 6, 2018 21:57
@ezekg
Copy link
Member Author

ezekg commented Sep 6, 2018

And just for future reference, here's what the different encryption schemes look like:

[
  {
    "scheme": "RSA_2048_PKCS1_PSS_SIGN",
    "key": "eyJmb28iOiJiYXIiLCJiYXoiOiJxdXoiLCJyYW5kIjpbNDgsMTAxLDU2LDk5LDQ5LDQ5LDk3LDUzLDU3LDU0LDQ5LDEwMSw1MCw0OSw1Miw1MCwxMDIsMTAyLDQ5LDU0LDUyLDEwMiw1Miw1NSw1Niw1MCw5Nyw0OCw0OSw1Myw1MywxMDFdfQ==.Dqw0N_14L0v-a-cQPkTM_X6_vN-tSoEWEt2Zu5SreeS_-Zn6Fsyr2EwpnOXWkWHhmcPJWSfboCrOjh73y-Q9I3aLbpTg5M_9bQmt2PjwG0l7A7T2PUreAA-8xftK0-_quQchsv73JDhrst8O1oh2dHBs6fB1EPXzKKCyIXKWIniHjEP-nqGGYXUzPQjoMI7JQCySZKtXmgV4rVRoY1E9kxywlc0Lia9OfHH2uDnBPjIpR_4U_QFLzoUKZnG5qmTC9PtgGbdsN5e01hk53ZvDA9sEdzUerk_34O6qBy203mt_4NvVbegIcS49IzyGtfn_a4OLbEGnz-gOnS2ee0Js6g=="
  },
  {
    "scheme": "RSA_2048_PKCS1_SIGN",
    "key": "eyJmb28iOiJiYXIiLCJiYXoiOiJxdXoiLCJyYW5kIjpbNTUsNTMsNDgsMTAyLDEwMSw1MywxMDIsMTAwLDEwMSw1Niw5OCw1NCw1Myw1MCw5NywxMDAsNTcsOTksNDksMTAwLDU2LDk4LDEwMiw1MSwxMDEsNDksNDksMTAwLDEwMSw1NSw5Nyw1Nl19.iLn4QFok4vvDRYwptUdakWPpwCxxAGljka9p2x4EMqV0gZqTI-VjL9J9w2m_FKFrSauVfcbl_cAKBfo12JL8a7FPIA0HEOqZX-bOGu2Z5zETeaz-4i9EY9NDO6eoKFfTKQHxHQt13nWuhj8LdLZN-9NW9AJTWyGPo4UwE5-bprRP90jCDjpRY6wu0-69MyVCSG-3GMOIpItfhYteXGM8veneijlYeMgRViK4IIdW28m6WhFWE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
]

@ezekg
Copy link
Member Author

ezekg commented Sep 7, 2018

Consider renaming encryptionScheme to something like crypto, scheme, or cryptoScheme? Encryption scheme isn’t entirely “correct”, since signing and JWTs aren’t encryption.

@ezekg
Copy link
Member Author

ezekg commented Sep 7, 2018

Also, should we generate private keys per-product and use that for this instead of the account’s private key? Right now, an offline verified license would be valid across multiple products unless explicitly checked (i.e. the license payload includes a product prop or similar).

This is alright, since other license keys are also "valid" unless an explicit product scope is given. The product ID can be embedded within the key manually, if that's needed.

@ezekg ezekg force-pushed the feature/encrypted-licenses branch from d75500f to 46cef22 Compare September 17, 2018 14:58
@ezekg ezekg force-pushed the feature/encrypted-licenses branch from 46cef22 to b786a07 Compare September 17, 2018 14:59
@ezekg ezekg merged commit 685692b into master Sep 17, 2018
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.

1 participant