-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Crypto module * Disable acceptance tests * Remove TypedDict for py3.7 compatibility * Fix compatibility with py3.7... again * Remove randbytes for 3.7 compatibility. sigh * Post review fixes * Integrate crypto_module with pubnub * Update test matrix - drop support for py3.7 as it has reached end of life * Fix type, add missing params, add example * Add tests * Fix bug with always riv encrypting files * reenable acceptance tests for crypto module * Fix miss of encrypting files * Update license * PubNub SDK v7.3.0 release. --------- Co-authored-by: PubNub Release Bot <120067856+pubnub-release-bot@users.noreply.github.com>
- Loading branch information
1 parent
701ece7
commit 86df330
Showing
24 changed files
with
1,328 additions
and
585 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,29 @@ | ||
PubNub Real-time Cloud-Hosted Push API and Push Notification Client Frameworks | ||
Copyright (c) 2013 PubNub Inc. | ||
http://www.pubnub.com/ | ||
http://www.pubnub.com/terms | ||
PubNub Software Development Kit License Agreement | ||
Copyright © 2023 PubNub Inc. All rights reserved. | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
Subject to the terms and conditions of the license, you are hereby granted | ||
a non-exclusive, worldwide, royalty-free license to (a) copy and modify | ||
the software in source code or binary form for use with the software services | ||
and interfaces provided by PubNub, and (b) redistribute unmodified copies | ||
of the software to third parties. The software may not be incorporated in | ||
or used to provide any product or service competitive with the products | ||
and services of PubNub. | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
The above copyright notice and this license shall be included | ||
in or with all copies or substantial portions of the software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. | ||
This license does not grant you permission to use the trade names, trademarks, | ||
service marks, or product names of PubNub, except as required for reasonable | ||
and customary use in describing the origin of the software and reproducing | ||
the content of this license. | ||
|
||
PubNub Real-time Cloud-Hosted Push API and Push Notification Client Frameworks | ||
Copyright (c) 2013 PubNub Inc. | ||
http://www.pubnub.com/ | ||
http://www.pubnub.com/terms | ||
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF | ||
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO | ||
EVENT SHALL PUBNUB OR THE AUTHORS OR COPYRIGHT HOLDERS OF THE SOFTWARE BE | ||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF | ||
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
|
||
https://www.pubnub.com/ | ||
https://www.pubnub.com/terms |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
from pubnub.pnconfiguration import PNConfiguration | ||
from pubnub.pubnub import PubNub | ||
from pubnub.crypto import AesCbcCryptoModule | ||
from Cryptodome.Cipher import AES | ||
|
||
my_cipher_key = 'myCipherKey' | ||
my_message = 'myMessage' | ||
|
||
# by default no configuration changes is needed | ||
config = PNConfiguration() | ||
config.uuid = 'myUUID' | ||
config.cipher_key = my_cipher_key | ||
pubnub = PubNub(config) | ||
|
||
# message will be encrypted the same way it was encrypted previously | ||
cbc_message = pubnub.crypto.encrypt(my_message) # new way of using cryptographic module from pubnub | ||
decrypted = config.crypto.decrypt(my_cipher_key, cbc_message) | ||
assert decrypted == my_message | ||
|
||
# also no configuration changes is needed if you previously updated the cipher_mode to GCM | ||
config = PNConfiguration() | ||
config.uuid = 'myUUID' | ||
config.cipher_key = my_cipher_key | ||
config.cipher_mode = AES.MODE_GCM | ||
config.fallback_cipher_mode = AES.MODE_CBC | ||
pubnub = PubNub(config) | ||
|
||
# message will be encrypted the same way it was encrypted previously | ||
gcm_message = pubnub.crypto.encrypt(my_message) # new way of using cryptographic module from pubnub | ||
decrypted = config.crypto.decrypt(my_cipher_key, gcm_message) | ||
assert decrypted == my_message | ||
|
||
# opt in to use crypto module with headers and improved entropy | ||
config = PNConfiguration() | ||
config.uuid = 'myUUID' | ||
config.cipher_key = my_cipher_key | ||
config.cipher_mode = AES.MODE_GCM | ||
config.fallback_cipher_mode = AES.MODE_CBC | ||
module = AesCbcCryptoModule(config) | ||
config.crypto_module = module | ||
pubnub = PubNub(config) | ||
message = pubnub.crypto.encrypt(my_message) | ||
# this encryption method is not compatible with previous crypto methods | ||
try: | ||
decoded = config.crypto.decrypt(my_cipher_key, message) | ||
except Exception: | ||
pass | ||
# but can be decrypted with new crypto module | ||
decrypted = pubnub.crypto.decrypt(message) | ||
assert decrypted == my_message |
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
Oops, something went wrong.