mirror of
https://github.com/etesync/android
synced 2025-04-11 04:05:48 +00:00
Crypto: add an exception to when crypto version is too new.
This commit is contained in:
parent
5abf635fa0
commit
70b549033c
@ -41,12 +41,12 @@ public class Crypto {
|
||||
private final byte[] cipherKey;
|
||||
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;
|
||||
if (version > Byte.MAX_VALUE) {
|
||||
throw new Exceptions.IntegrityException("Version is out of range.");
|
||||
} 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) {
|
||||
derivedKey = Base64.decode(keyBase64, Base64.NO_WRAP);
|
||||
} else {
|
||||
|
@ -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 String message;
|
||||
|
||||
|
@ -38,7 +38,7 @@ public class JournalManager extends BaseManager {
|
||||
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()
|
||||
.get()
|
||||
.url(remote)
|
||||
|
@ -45,7 +45,7 @@ public class CalendarSyncManager extends SyncManager {
|
||||
|
||||
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);
|
||||
localCollection = calendar;
|
||||
this.remote = remote;
|
||||
|
@ -60,7 +60,7 @@ public class ContactsSyncManager extends SyncManager {
|
||||
final private ContentProviderClient provider;
|
||||
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);
|
||||
this.provider = provider;
|
||||
this.remote = principal;
|
||||
|
@ -142,7 +142,7 @@ public abstract class SyncAdapterService extends Service {
|
||||
dbHelper = new ServiceDB.OpenHelper(context);
|
||||
}
|
||||
|
||||
void run() throws Exceptions.HttpException, Exceptions.IntegrityException, InvalidAccountException {
|
||||
void run() throws Exceptions.HttpException, Exceptions.IntegrityException, InvalidAccountException, Exceptions.GenericCryptoException {
|
||||
try {
|
||||
@Cleanup SQLiteDatabase db = dbHelper.getWritableDatabase();
|
||||
|
||||
|
@ -95,7 +95,7 @@ abstract public class SyncManager {
|
||||
private List<LocalResource> localDeleted;
|
||||
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.account = account;
|
||||
this.settings = settings;
|
||||
|
@ -179,7 +179,7 @@ public class CreateCollectionFragment extends DialogFragment implements LoaderMa
|
||||
return e;
|
||||
} catch (InvalidAccountException e) {
|
||||
return e;
|
||||
} catch (Exceptions.IntegrityException e) {
|
||||
} catch (Exceptions.IntegrityException|Exceptions.GenericCryptoException e) {
|
||||
return e;
|
||||
} finally {
|
||||
dbHelper.close();
|
||||
|
@ -128,7 +128,7 @@ public class DeleteCollectionFragment extends DialogFragment implements LoaderMa
|
||||
data.update(journalEntity);
|
||||
|
||||
return null;
|
||||
} catch (Exceptions.HttpException|Exceptions.IntegrityException e) {
|
||||
} catch (Exceptions.HttpException|Exceptions.IntegrityException|Exceptions.GenericCryptoException e) {
|
||||
return e;
|
||||
} catch (InvalidAccountException e) {
|
||||
return e;
|
||||
|
Loading…
Reference in New Issue
Block a user