1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2025-09-09 00:59:39 +02:00

smack-omemo*: Do not swallow IOException deep within the library

Those exception are caused by I/O operations in the OmemoStore, which
is now declaring that it throws those (since it is not uncommon for
I/O operations to cause IOExceptions). After all, this is nicely
demonstrated as this change is caused by switching with this commit to
the Android API 19 compatible methods in FileBasedOmemoStore, which
throw.

The library can not decide what to do in case of those exceptions,
hence it is sensible to expose them to the user.
This commit is contained in:
Florian Schmaus 2019-08-05 08:28:42 +02:00
parent 699905a1de
commit 1bce378e6d
16 changed files with 299 additions and 331 deletions

View file

@ -20,6 +20,7 @@
*/
package org.jivesoftware.smackx.omemo.signal;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
@ -73,7 +74,7 @@ public class SignalOmemoRatchet
@Override
public byte[] doubleRatchetDecrypt(OmemoDevice sender, byte[] encryptedKey)
throws CorruptedOmemoKeyException, NoRawSessionException, CryptoFailedException,
UntrustedOmemoIdentityException {
UntrustedOmemoIdentityException, IOException {
SessionCipher cipher = getCipher(sender);
byte[] decryptedKey;

View file

@ -20,6 +20,7 @@
*/
package org.jivesoftware.smackx.omemo.signal;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.TreeMap;
@ -79,7 +80,7 @@ public class SignalOmemoStoreConnector
public IdentityKeyPair getIdentityKeyPair() {
try {
return omemoStore.loadOmemoIdentityKeyPair(getOurDevice());
} catch (CorruptedOmemoKeyException e) {
} catch (CorruptedOmemoKeyException | IOException e) {
LOGGER.log(Level.SEVERE, "IdentityKeyPair seems to be invalid.", e);
return null;
}
@ -103,7 +104,11 @@ public class SignalOmemoStoreConnector
throw new AssertionError(e);
}
omemoStore.storeOmemoIdentityKey(getOurDevice(), device, identityKey);
try {
omemoStore.storeOmemoIdentityKey(getOurDevice(), device, identityKey);
} catch (IOException e) {
throw new IllegalStateException(e);
}
return true;
}
@ -118,7 +123,12 @@ public class SignalOmemoStoreConnector
@Override
public PreKeyRecord loadPreKey(int i) throws InvalidKeyIdException {
PreKeyRecord preKey = omemoStore.loadOmemoPreKey(getOurDevice(), i);
PreKeyRecord preKey;
try {
preKey = omemoStore.loadOmemoPreKey(getOurDevice(), i);
} catch (IOException e) {
throw new IllegalStateException(e);
}
if (preKey == null) {
throw new InvalidKeyIdException("No PreKey with Id " + i + " found.");
@ -129,7 +139,11 @@ public class SignalOmemoStoreConnector
@Override
public void storePreKey(int i, PreKeyRecord preKeyRecord) {
omemoStore.storeOmemoPreKey(getOurDevice(), i, preKeyRecord);
try {
omemoStore.storeOmemoPreKey(getOurDevice(), i, preKeyRecord);
} catch (IOException e) {
throw new IllegalStateException(e);
}
}
@Override
@ -155,7 +169,12 @@ public class SignalOmemoStoreConnector
throw new AssertionError(e);
}
SessionRecord record = omemoStore.loadRawSession(getOurDevice(), device);
SessionRecord record;
try {
record = omemoStore.loadRawSession(getOurDevice(), device);
} catch (IOException e) {
throw new IllegalStateException(e);
}
if (record != null) {
return record;
@ -173,7 +192,11 @@ public class SignalOmemoStoreConnector
throw new AssertionError(e);
}
return new ArrayList<>(omemoStore.loadAllRawSessionsOf(getOurDevice(), jid).keySet());
try {
return new ArrayList<>(omemoStore.loadAllRawSessionsOf(getOurDevice(), jid).keySet());
} catch (IOException e) {
throw new IllegalStateException(e);
}
}
@Override
@ -185,7 +208,11 @@ public class SignalOmemoStoreConnector
throw new AssertionError(e);
}
omemoStore.storeRawSession(getOurDevice(), device, sessionRecord);
try {
omemoStore.storeRawSession(getOurDevice(), device, sessionRecord);
} catch (IOException e) {
throw new IllegalStateException(e);
}
}
@Override
@ -226,7 +253,12 @@ public class SignalOmemoStoreConnector
@Override
public SignedPreKeyRecord loadSignedPreKey(int i) throws InvalidKeyIdException {
SignedPreKeyRecord signedPreKeyRecord = omemoStore.loadOmemoSignedPreKey(getOurDevice(), i);
SignedPreKeyRecord signedPreKeyRecord;
try {
signedPreKeyRecord = omemoStore.loadOmemoSignedPreKey(getOurDevice(), i);
} catch (IOException e) {
throw new IllegalStateException(e);
}
if (signedPreKeyRecord == null) {
throw new InvalidKeyIdException("No signed preKey with id " + i + " found.");
}
@ -236,14 +268,22 @@ public class SignalOmemoStoreConnector
@Override
public List<SignedPreKeyRecord> loadSignedPreKeys() {
TreeMap<Integer, SignedPreKeyRecord> signedPreKeyRecordHashMap =
omemoStore.loadOmemoSignedPreKeys(getOurDevice());
TreeMap<Integer, SignedPreKeyRecord> signedPreKeyRecordHashMap;
try {
signedPreKeyRecordHashMap = omemoStore.loadOmemoSignedPreKeys(getOurDevice());
} catch (IOException e) {
throw new IllegalStateException(e);
}
return new ArrayList<>(signedPreKeyRecordHashMap.values());
}
@Override
public void storeSignedPreKey(int i, SignedPreKeyRecord signedPreKeyRecord) {
omemoStore.storeOmemoSignedPreKey(getOurDevice(), i, signedPreKeyRecord);
try {
omemoStore.storeOmemoSignedPreKey(getOurDevice(), i, signedPreKeyRecord);
} catch (IOException e) {
throw new IllegalStateException(e);
}
}
@Override