diff --git a/app/src/main/java/com/etesync/syncadapter/journalmanager/UserInfoManager.java b/app/src/main/java/com/etesync/syncadapter/journalmanager/UserInfoManager.java index 49487290..f1495165 100644 --- a/app/src/main/java/com/etesync/syncadapter/journalmanager/UserInfoManager.java +++ b/app/src/main/java/com/etesync/syncadapter/journalmanager/UserInfoManager.java @@ -30,7 +30,7 @@ public class UserInfoManager extends BaseManager { this.client = httpClient; } - public UserInfo get(Crypto.CryptoManager cryptoManager, String owner) throws Exceptions.HttpException, Exceptions.IntegrityException, Exceptions.GenericCryptoException { + public UserInfo get(String owner) throws Exceptions.HttpException { HttpUrl remote = this.remote.newBuilder().addPathSegment(owner).addPathSegment("").build(); Request request = new Request.Builder() .get() @@ -50,7 +50,6 @@ public class UserInfoManager extends BaseManager { ResponseBody body = response.body(); UserInfo ret = GsonHelper.gson.fromJson(body.charStream(), UserInfo.class); - ret.verify(cryptoManager); ret.setOwner(owner); return ret; @@ -109,7 +108,7 @@ public class UserInfoManager extends BaseManager { this.content = Arrays.concatenate(calculateHmac(crypto, content), content); } - void verify(Crypto.CryptoManager crypto) throws Exceptions.IntegrityException { + public void verify(Crypto.CryptoManager crypto) throws Exceptions.IntegrityException { if (this.content == null) { // Nothing to verify. return; diff --git a/app/src/main/java/com/etesync/syncadapter/ui/AddMemberFragment.java b/app/src/main/java/com/etesync/syncadapter/ui/AddMemberFragment.java index 96547d02..9e07848d 100644 --- a/app/src/main/java/com/etesync/syncadapter/ui/AddMemberFragment.java +++ b/app/src/main/java/com/etesync/syncadapter/ui/AddMemberFragment.java @@ -79,9 +79,7 @@ public class AddMemberFragment extends DialogFragment { try { UserInfoManager userInfoManager = new UserInfoManager(httpClient, remote); - Crypto.CryptoManager crypto = new Crypto.CryptoManager(info.version, settings.password(), info.uid); - - memberPubKey = userInfoManager.get(crypto, memberEmail).getPubkey(); + memberPubKey = userInfoManager.get(memberEmail).getPubkey(); return new AddResult(null); } catch (Exception e) { return new AddResult(e); diff --git a/app/src/main/java/com/etesync/syncadapter/ui/setup/SetupUserInfoFragment.java b/app/src/main/java/com/etesync/syncadapter/ui/setup/SetupUserInfoFragment.java index eda1db14..997f810c 100644 --- a/app/src/main/java/com/etesync/syncadapter/ui/setup/SetupUserInfoFragment.java +++ b/app/src/main/java/com/etesync/syncadapter/ui/setup/SetupUserInfoFragment.java @@ -18,6 +18,7 @@ import com.etesync.syncadapter.App; import com.etesync.syncadapter.HttpClient; import com.etesync.syncadapter.InvalidAccountException; import com.etesync.syncadapter.R; +import com.etesync.syncadapter.journalmanager.Constants; import com.etesync.syncadapter.journalmanager.Crypto; import com.etesync.syncadapter.journalmanager.UserInfoManager; @@ -88,18 +89,21 @@ public class SetupUserInfoFragment extends DialogFragment { @Override protected SetupUserInfo.SetupUserInfoResult doInBackground(Account... accounts) { try { + Crypto.CryptoManager cryptoManager; OkHttpClient httpClient = HttpClient.create(getContext(), account); - Crypto.CryptoManager cryptoManager = new Crypto.CryptoManager(com.etesync.syncadapter.journalmanager.Constants.CURRENT_VERSION, settings.password(), "userInfo"); UserInfoManager userInfoManager = new UserInfoManager(httpClient, HttpUrl.get(settings.getUri())); - UserInfoManager.UserInfo userInfo = userInfoManager.get(cryptoManager, account.name); + UserInfoManager.UserInfo userInfo = userInfoManager.get(account.name); if (userInfo == null) { App.log.info("Creating userInfo for " + account.name); + cryptoManager = new Crypto.CryptoManager(Constants.CURRENT_VERSION, settings.password(), "userInfo"); userInfo = UserInfoManager.UserInfo.generate(cryptoManager, account.name); userInfoManager.create(userInfo); } else { App.log.info("Fetched userInfo for " + account.name); + cryptoManager = new Crypto.CryptoManager(userInfo.getVersion(), settings.password(), "userInfo"); + userInfo.verify(cryptoManager); } Crypto.AsymmetricKeyPair keyPair = new Crypto.AsymmetricKeyPair(userInfo.getContent(cryptoManager), userInfo.getPubkey()); diff --git a/app/src/test/java/com/etesync/syncadapter/journalmanager/ServiceTest.java b/app/src/test/java/com/etesync/syncadapter/journalmanager/ServiceTest.java index a905856d..9d9dc2ae 100644 --- a/app/src/test/java/com/etesync/syncadapter/journalmanager/ServiceTest.java +++ b/app/src/test/java/com/etesync/syncadapter/journalmanager/ServiceTest.java @@ -210,7 +210,7 @@ public class ServiceTest { UserInfoManager manager = new UserInfoManager(httpClient, remote); // Get when there's nothing - userInfo = manager.get(cryptoManager, Helpers.USER); + userInfo = manager.get(Helpers.USER); assertNull(userInfo); // Create @@ -218,20 +218,20 @@ public class ServiceTest { manager.create(userInfo); // Get - userInfo2 = manager.get(cryptoManager, Helpers.USER); + userInfo2 = manager.get(Helpers.USER); assertNotNull(userInfo2); assertArrayEquals(userInfo.getContent(cryptoManager), userInfo2.getContent(cryptoManager)); // Update userInfo.setContent(cryptoManager, "test".getBytes(Charsets.UTF_8)); manager.update(userInfo); - userInfo2 = manager.get(cryptoManager, Helpers.USER); + userInfo2 = manager.get(Helpers.USER); assertNotNull(userInfo2); assertArrayEquals(userInfo.getContent(cryptoManager), userInfo2.getContent(cryptoManager)); // Delete manager.delete(userInfo); - userInfo = manager.get(cryptoManager, Helpers.USER); + userInfo = manager.get(Helpers.USER); assertNull(userInfo); }