-
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.
Add support for switching cipher methods (#156)
* Add support for switching cipher methods through PNConfiguration * Validation of cipher methods * Default - CBC, fallback - None * Add fallback to file crypto * PubNub SDK 7.2.0 release. --------- Co-authored-by: PubNub Release Bot <[email protected]>
- Loading branch information
1 parent
f33f7af
commit 1029e22
Showing
11 changed files
with
783 additions
and
27 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
from Cryptodome.Cipher import AES | ||
from os import getenv | ||
from pubnub.pnconfiguration import PNConfiguration | ||
from pubnub.pubnub import PubNub | ||
from time import sleep | ||
|
||
channel = 'cipher_algorithm_experiment' | ||
|
||
|
||
def PNFactory(cipher_mode=AES.MODE_GCM, fallback_cipher_mode=AES.MODE_CBC) -> PubNub: | ||
config = config = PNConfiguration() | ||
config.publish_key = getenv('PN_KEY_PUBLISH') | ||
config.subscribe_key = getenv('PN_KEY_SUBSCRIBE') | ||
config.secret_key = getenv('PN_KEY_SECRET') | ||
config.cipher_key = getenv('PN_KEY_CIPHER') | ||
config.user_id = 'experiment' | ||
config.cipher_mode = cipher_mode | ||
config.fallback_cipher_mode = fallback_cipher_mode | ||
|
||
return PubNub(config) | ||
|
||
|
||
# let's build history with legacy AES.CBC | ||
pn = PNFactory(cipher_mode=AES.MODE_CBC, fallback_cipher_mode=None) | ||
pn.publish().channel(channel).message('message encrypted with CBC').sync() | ||
pn.publish().channel(channel).message('message encrypted with CBC').sync() | ||
|
||
# now with upgraded config | ||
pn = PNFactory(cipher_mode=AES.MODE_GCM, fallback_cipher_mode=AES.MODE_CBC) | ||
pn.publish().channel(channel).message('message encrypted with GCM').sync() | ||
pn.publish().channel(channel).message('message encrypted with GCM').sync() | ||
|
||
# give some time to store messages | ||
sleep(3) | ||
|
||
# after upgrade decoding with GCM and fallback CBC | ||
pn = PNFactory(cipher_mode=AES.MODE_GCM, fallback_cipher_mode=AES.MODE_CBC) | ||
messages = pn.history().channel(channel).sync() | ||
print([message.entry for message in messages.result.messages]) | ||
|
||
# before upgrade decoding with CBC and without fallback | ||
pn = PNFactory(cipher_mode=AES.MODE_CBC, fallback_cipher_mode=None) | ||
try: | ||
messages = pn.history().channel(channel).sync() | ||
print([message.entry for message in messages.result.messages]) | ||
except UnicodeDecodeError: | ||
print('Unable to decode - Exception has been thrown') |
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 |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
|
||
setup( | ||
name='pubnub', | ||
version='7.1.0', | ||
version='7.2.0', | ||
description='PubNub Real-time push service in the cloud', | ||
author='PubNub', | ||
author_email='[email protected]', | ||
|
Oops, something went wrong.