|
|
@ -53,9 +53,8 @@ const syncInfoSelector = createSelector(
|
|
|
|
(props: PropsTypeInner) => props.userInfo.value!,
|
|
|
|
(props: PropsTypeInner) => props.userInfo.value!,
|
|
|
|
(etesync, journals, entries, userInfo) => {
|
|
|
|
(etesync, journals, entries, userInfo) => {
|
|
|
|
const derived = etesync.encryptionKey;
|
|
|
|
const derived = etesync.encryptionKey;
|
|
|
|
let asymmetricCryptoManager: EteSync.AsymmetricCryptoManager;
|
|
|
|
const userInfoCryptoManager = userInfo.getCryptoManager(etesync.encryptionKey);
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
const userInfoCryptoManager = new EteSync.CryptoManager(etesync.encryptionKey, 'userInfo');
|
|
|
|
|
|
|
|
userInfo.verify(userInfoCryptoManager);
|
|
|
|
userInfo.verify(userInfoCryptoManager);
|
|
|
|
} catch (error) {
|
|
|
|
} catch (error) {
|
|
|
|
if (error instanceof EteSync.IntegrityError) {
|
|
|
|
if (error instanceof EteSync.IntegrityError) {
|
|
|
@ -74,17 +73,8 @@ const syncInfoSelector = createSelector(
|
|
|
|
return ret;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
let cryptoManager: EteSync.CryptoManager;
|
|
|
|
const keyPair = userInfo.getKeyPair(userInfoCryptoManager);
|
|
|
|
if (journal.key) {
|
|
|
|
const cryptoManager = journal.getCryptoManager(derived, keyPair);
|
|
|
|
if (!asymmetricCryptoManager) {
|
|
|
|
|
|
|
|
const keyPair = userInfo.getKeyPair(new EteSync.CryptoManager(derived, 'userInfo', userInfo.version));
|
|
|
|
|
|
|
|
asymmetricCryptoManager = new EteSync.AsymmetricCryptoManager(keyPair);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
const derivedJournalKey = asymmetricCryptoManager.decryptBytes(journal.key);
|
|
|
|
|
|
|
|
cryptoManager = EteSync.CryptoManager.fromDerivedKey(derivedJournalKey, journal.version);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
cryptoManager = new EteSync.CryptoManager(derived, journal.uid, journal.version);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const collectionInfo = journal.getInfo(cryptoManager);
|
|
|
|
const collectionInfo = journal.getInfo(cryptoManager);
|
|
|
|
|
|
|
|
|
|
|
@ -124,7 +114,7 @@ class SyncGate extends React.PureComponent<PropsTypeInner> {
|
|
|
|
collection.type = collectionType;
|
|
|
|
collection.type = collectionType;
|
|
|
|
collection.displayName = 'Default';
|
|
|
|
collection.displayName = 'Default';
|
|
|
|
|
|
|
|
|
|
|
|
const journal = new EteSync.Journal();
|
|
|
|
const journal = new EteSync.Journal({ uid: collection.uid });
|
|
|
|
const cryptoManager = new EteSync.CryptoManager(this.props.etesync.encryptionKey, collection.uid);
|
|
|
|
const cryptoManager = new EteSync.CryptoManager(this.props.etesync.encryptionKey, collection.uid);
|
|
|
|
journal.setInfo(cryptoManager, collection);
|
|
|
|
journal.setInfo(cryptoManager, collection);
|
|
|
|
store.dispatch<any>(addJournal(this.props.etesync, journal)).then(
|
|
|
|
store.dispatch<any>(addJournal(this.props.etesync, journal)).then(
|
|
|
@ -144,7 +134,7 @@ class SyncGate extends React.PureComponent<PropsTypeInner> {
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
const userInfo = new EteSync.UserInfo(me, CURRENT_VERSION);
|
|
|
|
const userInfo = new EteSync.UserInfo(me, CURRENT_VERSION);
|
|
|
|
const keyPair = EteSync.AsymmetricCryptoManager.generateKeyPair();
|
|
|
|
const keyPair = EteSync.AsymmetricCryptoManager.generateKeyPair();
|
|
|
|
const cryptoManager = new EteSync.CryptoManager(this.props.etesync.encryptionKey, 'userInfo');
|
|
|
|
const cryptoManager = userInfo.getCryptoManager(this.props.etesync.encryptionKey);
|
|
|
|
|
|
|
|
|
|
|
|
userInfo.setKeyPair(cryptoManager, keyPair);
|
|
|
|
userInfo.setKeyPair(cryptoManager, keyPair);
|
|
|
|
|
|
|
|
|
|
|
|