def test_collection_shared(self, etesync): from etesync import service, crypto a = api.Calendar.create(etesync, get_random_uid(self), {'displayName': 'fööböö'}) a.save() ev = api.Event.create(a, ('BEGIN:VCALENDAR\r\n' 'BEGIN:VEVENT\r\n' 'UID:test @ foo ät bar град сатану\r\n' 'SUMMARY:FÖÖBÖÖ\r\n' 'END:VEVENT\r\n' 'END:VCALENDAR\r\n')) ev.save() journal_manager = service.JournalManager(etesync.remote, etesync.auth_token) etesync.sync() key_pair = crypto.AsymmetricCryptoManager.generate_key_pair() asymmetric_crypto_manager = crypto.AsymmetricCryptoManager(key_pair) # FIXME: Hack, shouldn't calculate it here cipher_key = hmac256(a.journal.uid.encode(), etesync.cipher_key) encrypted_key = asymmetric_crypto_manager.encrypt( key_pair.public_key, cipher_key) member = service.Member(USER2_EMAIL, encrypted_key) # Second user auth = api.Authenticator(TEST_REMOTE) token = auth.get_auth_token(USER2_EMAIL, USER_PASSWORD) etesync2 = api.EteSync(USER2_EMAIL, token, remote=TEST_REMOTE, db_path=TEST_DB) headers = {'Authorization': 'Token ' + etesync2.auth_token} response = requests.post(TEST_REMOTE + 'reset/', headers=headers, allow_redirects=False) assert response.status_code == 200 journal_manager.member_add(a.journal._cache_obj, member) info_manager = service.UserInfoManager(etesync2.remote, etesync2.auth_token) crypto_manager = crypto.CryptoManager(crypto.CURRENT_VERSION, etesync2.cipher_key, b"userInfo") user_info = service.RawUserInfo(crypto_manager, USER2_EMAIL, key_pair.public_key) user_info.update(key_pair.private_key) user_info.verify() info_manager.add(user_info) etesync2.sync() journal_list = list(etesync2.list()) assert len(journal_list) == 1 assert journal_list[0].uid == a.journal.uid
def test_crypto_v1(self): # Just make sure we don't break derivation crypto_manager = crypto.CryptoManager(1, DERIVED_KEY, b'TestSaltShouldBeJournalId') clear_text = b'This Is Some Test Cleartext.' cipher = crypto_manager.encrypt(clear_text) assert clear_text == crypto_manager.decrypt(cipher) expected = b'/?\x87P\\\xe1\xd4wc\xc6\xe1\x9dB\xb0p\x04mH\xcct\xf4\xba\x0e\xa6;\xc7\xf0x\xf4\x9b^\xd7' assert expected == crypto_manager.hmac(b'Some test data')
def test_crypto_v2(self): # Just make sure we don't break derivation crypto_manager = crypto.CryptoManager(2, DERIVED_KEY, b'TestSaltShouldBeJournalId') clear_text = b'This Is Some Test Cleartext.' cipher = crypto_manager.encrypt(clear_text) assert clear_text == crypto_manager.decrypt(cipher) expected = ( b']\x0f\xc0\xd2\x07\xa7\xb4\xe6\x84\xf7\xc4}\xc37\xf7\xccB\x00\x1e>\x0e\x1fQ\x85\xf0\x9e\x02\xe8' + b'\x98\x89\xba\x9a') assert expected == crypto_manager.hmac(b'Some test data')
def test_asymmetric_crypto(self): key_pair = crypto.AsymmetricCryptoManager.generate_key_pair() asymmetric_crypto_manager = crypto.AsymmetricCryptoManager(key_pair) encrypted_key = asymmetric_crypto_manager.encrypt( key_pair.public_key, DERIVED_KEY) decrypted_key = asymmetric_crypto_manager.decrypt(encrypted_key) assert DERIVED_KEY == decrypted_key crypto_manager = crypto.CryptoManager(2, DERIVED_KEY, b'TestSaltShouldBeJournalId') clear_text = b'This Is Some Test Cleartext.' cipher = ( b'\x109\xc3_\x1dM\xcd\xcf\x0e>_\xcb\x10\xff7\x07\xe3\xc6/\x17Y\x94} \x04\x1f\x11g\xa3\x1e\x11\xe5' + b'\xfe#\xbb]JZm\x1dk\xb2\x97\xde\xfcdo\xd3') assert clear_text == crypto_manager.decrypt(cipher)
def test_crypto_v_too_new(self): with pytest.raises(exceptions.VersionTooNew): crypto.CryptoManager(293, DERIVED_KEY, b'TestSalt')