Fix incorrect querying of autocrypt peer master key id
This commit is contained in:
@@ -30,7 +30,6 @@ import org.sufficientlysecure.keychain.AutocryptKeyStatus;
|
||||
import org.sufficientlysecure.keychain.AutocryptPeersQueries;
|
||||
import org.sufficientlysecure.keychain.Autocrypt_peers;
|
||||
import org.sufficientlysecure.keychain.KeychainDatabase;
|
||||
import org.sufficientlysecure.keychain.SelectMasterKeyIdByIdentifier;
|
||||
import org.sufficientlysecure.keychain.model.GossipOrigin;
|
||||
|
||||
|
||||
@@ -50,16 +49,6 @@ public class AutocryptPeerDao extends AbstractDao {
|
||||
super(database, databaseNotifyManager);
|
||||
}
|
||||
|
||||
public Long getMasterKeyIdForAutocryptPeer(String autocryptId) {
|
||||
SelectMasterKeyIdByIdentifier masterKeyId =
|
||||
autocryptPeersQueries.selectMasterKeyIdByIdentifier(autocryptId)
|
||||
.executeAsOneOrNull();
|
||||
if (masterKeyId != null) {
|
||||
return masterKeyId.getMaster_key_id();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Autocrypt_peers getAutocryptPeer(String packageName, String autocryptId) {
|
||||
return autocryptPeersQueries.selectByIdentifiers(packageName,
|
||||
@@ -114,10 +103,10 @@ public class AutocryptPeerDao extends AbstractDao {
|
||||
}
|
||||
|
||||
public void deleteByIdentifier(String packageName, String autocryptId) {
|
||||
Long masterKeyId = getMasterKeyIdForAutocryptPeer(autocryptId);
|
||||
Autocrypt_peers peer = getAutocryptPeer(packageName, autocryptId);
|
||||
autocryptPeersQueries.deleteByIdentifier(packageName, autocryptId);
|
||||
if (masterKeyId != null) {
|
||||
getDatabaseNotifyManager().notifyAutocryptDelete(autocryptId, masterKeyId);
|
||||
if (peer != null && peer.getMaster_key_id() != null) {
|
||||
getDatabaseNotifyManager().notifyAutocryptDelete(autocryptId, peer.getMaster_key_id());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -51,6 +51,7 @@ import org.openintents.openpgp.OpenPgpMetadata;
|
||||
import org.openintents.openpgp.OpenPgpSignatureResult;
|
||||
import org.openintents.openpgp.OpenPgpSignatureResult.AutocryptPeerResult;
|
||||
import org.openintents.openpgp.util.OpenPgpApi;
|
||||
import org.sufficientlysecure.keychain.Autocrypt_peers;
|
||||
import org.sufficientlysecure.keychain.Constants;
|
||||
import org.sufficientlysecure.keychain.daos.ApiAppDao;
|
||||
import org.sufficientlysecure.keychain.daos.AutocryptPeerDao;
|
||||
@@ -585,10 +586,12 @@ public class OpenPgpService extends Service {
|
||||
|
||||
AutocryptPeerDao autocryptPeerentityDao =
|
||||
AutocryptPeerDao.getInstance(getBaseContext());
|
||||
Long autocryptPeerMasterKeyId = autocryptPeerentityDao.getMasterKeyIdForAutocryptPeer(autocryptPeerId);
|
||||
String packageName = mApiPermissionHelper.getCurrentCallingPackage();
|
||||
Autocrypt_peers
|
||||
autocryptPeer = autocryptPeerentityDao.getAutocryptPeer(packageName, autocryptPeerId);
|
||||
|
||||
long masterKeyId = signatureResult.getKeyId();
|
||||
if (autocryptPeerMasterKeyId == null) {
|
||||
if (autocryptPeer == null) {
|
||||
Date now = new Date();
|
||||
Date effectiveTime = signatureResult.getSignatureTimestamp();
|
||||
if (effectiveTime.after(now)) {
|
||||
@@ -598,7 +601,7 @@ public class OpenPgpService extends Service {
|
||||
AutocryptInteractor.getInstance(this, mApiPermissionHelper.getCurrentCallingPackage());
|
||||
autocryptInteractor.updateKeyGossipFromSignature(autocryptPeerId, effectiveTime, masterKeyId);
|
||||
return signatureResult.withAutocryptPeerResult(AutocryptPeerResult.NEW);
|
||||
} else if (masterKeyId == autocryptPeerMasterKeyId) {
|
||||
} else if (autocryptPeer.getMaster_key_id() != null && masterKeyId == autocryptPeer.getMaster_key_id()) {
|
||||
return signatureResult.withAutocryptPeerResult(AutocryptPeerResult.OK);
|
||||
} else {
|
||||
return signatureResult.withAutocryptPeerResult(AutocryptPeerResult.MISMATCH);
|
||||
|
||||
@@ -25,11 +25,6 @@ SELECT *
|
||||
FROM autocrypt_peers
|
||||
WHERE master_key_id = ?;
|
||||
|
||||
selectMasterKeyIdByIdentifier:
|
||||
SELECT master_key_id
|
||||
FROM autocrypt_peers
|
||||
WHERE identifier = ?;
|
||||
|
||||
deleteByIdentifier:
|
||||
DELETE FROM autocrypt_peers
|
||||
WHERE package_name = ? AND identifier = ?;
|
||||
|
||||
Reference in New Issue
Block a user