1
0
mirror of https://github.com/etesync/android synced 2025-06-24 08:58:50 +00:00

Crypto: add an exception to when crypto version is too new.

This commit is contained in:
Tom Hacohen 2017-04-06 16:15:42 +01:00
parent 5abf635fa0
commit 70b549033c
9 changed files with 22 additions and 10 deletions

View File

@ -41,12 +41,12 @@ public class Crypto {
private final byte[] cipherKey; private final byte[] cipherKey;
private final byte[] hmacKey; private final byte[] hmacKey;
public CryptoManager(int version, @NonNull String keyBase64, @NonNull String salt) throws Exceptions.IntegrityException { public CryptoManager(int version, @NonNull String keyBase64, @NonNull String salt) throws Exceptions.IntegrityException, Exceptions.VersionTooNewException {
byte[] derivedKey; byte[] derivedKey;
if (version > Byte.MAX_VALUE) { if (version > Byte.MAX_VALUE) {
throw new Exceptions.IntegrityException("Version is out of range."); throw new Exceptions.IntegrityException("Version is out of range.");
} else if (version > Constants.CURRENT_VERSION) { } else if (version > Constants.CURRENT_VERSION) {
throw new RuntimeException("Journal version is newer than expected."); throw new Exceptions.VersionTooNewException("Version to new: " + String.valueOf(version));
} else if (version == 1) { } else if (version == 1) {
derivedKey = Base64.decode(keyBase64, Base64.NO_WRAP); derivedKey = Base64.decode(keyBase64, Base64.NO_WRAP);
} else { } else {

View File

@ -45,8 +45,20 @@ public class Exceptions {
} }
} }
public static class HttpException extends Exception implements Serializable {
public static class GenericCryptoException extends Exception {
public GenericCryptoException(String message) {
super(message);
}
}
public static class VersionTooNewException extends GenericCryptoException {
public VersionTooNewException(String message) {
super(message);
}
}
public static class HttpException extends Exception implements Serializable {
final int status; final int status;
final String message; final String message;

View File

@ -38,7 +38,7 @@ public class JournalManager extends BaseManager {
this.client = httpClient; this.client = httpClient;
} }
public List<Journal> getJournals(String keyBase64) throws Exceptions.HttpException, Exceptions.IntegrityException { public List<Journal> getJournals(String keyBase64) throws Exceptions.HttpException, Exceptions.IntegrityException, Exceptions.GenericCryptoException {
Request request = new Request.Builder() Request request = new Request.Builder()
.get() .get()
.url(remote) .url(remote)

View File

@ -45,7 +45,7 @@ public class CalendarSyncManager extends SyncManager {
final private HttpUrl remote; final private HttpUrl remote;
public CalendarSyncManager(Context context, Account account, AccountSettings settings, Bundle extras, String authority, SyncResult result, LocalCalendar calendar, HttpUrl remote) throws InvalidAccountException, Exceptions.IntegrityException { public CalendarSyncManager(Context context, Account account, AccountSettings settings, Bundle extras, String authority, SyncResult result, LocalCalendar calendar, HttpUrl remote) throws InvalidAccountException, Exceptions.IntegrityException, Exceptions.GenericCryptoException {
super(context, account, settings, extras, authority, result, calendar.getName(), CollectionInfo.Type.CALENDAR); super(context, account, settings, extras, authority, result, calendar.getName(), CollectionInfo.Type.CALENDAR);
localCollection = calendar; localCollection = calendar;
this.remote = remote; this.remote = remote;

View File

@ -60,7 +60,7 @@ public class ContactsSyncManager extends SyncManager {
final private ContentProviderClient provider; final private ContentProviderClient provider;
final private HttpUrl remote; final private HttpUrl remote;
public ContactsSyncManager(Context context, Account account, AccountSettings settings, Bundle extras, String authority, ContentProviderClient provider, SyncResult result, HttpUrl principal, CollectionInfo info) throws InvalidAccountException, Exceptions.IntegrityException { public ContactsSyncManager(Context context, Account account, AccountSettings settings, Bundle extras, String authority, ContentProviderClient provider, SyncResult result, HttpUrl principal, CollectionInfo info) throws InvalidAccountException, Exceptions.IntegrityException, Exceptions.GenericCryptoException {
super(context, account, settings, extras, authority, result, info.url, CollectionInfo.Type.ADDRESS_BOOK); super(context, account, settings, extras, authority, result, info.url, CollectionInfo.Type.ADDRESS_BOOK);
this.provider = provider; this.provider = provider;
this.remote = principal; this.remote = principal;

View File

@ -142,7 +142,7 @@ public abstract class SyncAdapterService extends Service {
dbHelper = new ServiceDB.OpenHelper(context); dbHelper = new ServiceDB.OpenHelper(context);
} }
void run() throws Exceptions.HttpException, Exceptions.IntegrityException, InvalidAccountException { void run() throws Exceptions.HttpException, Exceptions.IntegrityException, InvalidAccountException, Exceptions.GenericCryptoException {
try { try {
@Cleanup SQLiteDatabase db = dbHelper.getWritableDatabase(); @Cleanup SQLiteDatabase db = dbHelper.getWritableDatabase();

View File

@ -95,7 +95,7 @@ abstract public class SyncManager {
private List<LocalResource> localDeleted; private List<LocalResource> localDeleted;
private LocalResource[] localDirty; private LocalResource[] localDirty;
public SyncManager(Context context, Account account, AccountSettings settings, Bundle extras, String authority, SyncResult syncResult, String journalUid, CollectionInfo.Type serviceType) throws InvalidAccountException, Exceptions.IntegrityException { public SyncManager(Context context, Account account, AccountSettings settings, Bundle extras, String authority, SyncResult syncResult, String journalUid, CollectionInfo.Type serviceType) throws InvalidAccountException, Exceptions.IntegrityException, Exceptions.GenericCryptoException {
this.context = context; this.context = context;
this.account = account; this.account = account;
this.settings = settings; this.settings = settings;

View File

@ -179,7 +179,7 @@ public class CreateCollectionFragment extends DialogFragment implements LoaderMa
return e; return e;
} catch (InvalidAccountException e) { } catch (InvalidAccountException e) {
return e; return e;
} catch (Exceptions.IntegrityException e) { } catch (Exceptions.IntegrityException|Exceptions.GenericCryptoException e) {
return e; return e;
} finally { } finally {
dbHelper.close(); dbHelper.close();

View File

@ -128,7 +128,7 @@ public class DeleteCollectionFragment extends DialogFragment implements LoaderMa
data.update(journalEntity); data.update(journalEntity);
return null; return null;
} catch (Exceptions.HttpException|Exceptions.IntegrityException e) { } catch (Exceptions.HttpException|Exceptions.IntegrityException|Exceptions.GenericCryptoException e) {
return e; return e;
} catch (InvalidAccountException e) { } catch (InvalidAccountException e) {
return e; return e;