mirror of
https://github.com/moparisthebest/open-keychain
synced 2025-02-07 10:30:14 -05:00
fix method visibility for tests
This commit is contained in:
parent
8131daa638
commit
c34a159cae
@ -370,8 +370,6 @@ public class UncachedKeyringCanonicalizeTest {
|
|||||||
@Test public void testSubkeyBindingNoPKB() throws Exception {
|
@Test public void testSubkeyBindingNoPKB() throws Exception {
|
||||||
|
|
||||||
UncachedPublicKey pKey = KeyringTestingHelper.getNth(ring.getPublicKeys(), 1);
|
UncachedPublicKey pKey = KeyringTestingHelper.getNth(ring.getPublicKeys(), 1);
|
||||||
Assert.assertTrue("second subkey must be able to sign", pKey.canSign());
|
|
||||||
|
|
||||||
PGPSignature sig;
|
PGPSignature sig;
|
||||||
|
|
||||||
subHashedPacketsGen.setKeyFlags(false, KeyFlags.SIGN_DATA);
|
subHashedPacketsGen.setKeyFlags(false, KeyFlags.SIGN_DATA);
|
||||||
|
@ -32,6 +32,7 @@ import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKey;
|
|||||||
import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKey.SecretKeyType;
|
import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKey.SecretKeyType;
|
||||||
import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKeyRing;
|
import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKeyRing;
|
||||||
import org.sufficientlysecure.keychain.pgp.UncachedKeyRing;
|
import org.sufficientlysecure.keychain.pgp.UncachedKeyRing;
|
||||||
|
import org.sufficientlysecure.keychain.service.results.OperationResult.OperationLog;
|
||||||
import org.sufficientlysecure.keychain.service.results.SaveKeyringResult;
|
import org.sufficientlysecure.keychain.service.results.SaveKeyringResult;
|
||||||
import org.sufficientlysecure.keychain.util.IterableIterator;
|
import org.sufficientlysecure.keychain.util.IterableIterator;
|
||||||
import org.sufficientlysecure.keychain.util.ProgressScaler;
|
import org.sufficientlysecure.keychain.util.ProgressScaler;
|
||||||
@ -80,6 +81,8 @@ public class ProviderHelperSaveTest {
|
|||||||
|
|
||||||
UncachedKeyRing pub = readRingFromResource("/test-keys/mailvelope_07_no_key_flags.asc");
|
UncachedKeyRing pub = readRingFromResource("/test-keys/mailvelope_07_no_key_flags.asc");
|
||||||
long keyId = pub.getMasterKeyId();
|
long keyId = pub.getMasterKeyId();
|
||||||
|
Assert.assertNull("key flags should be null",
|
||||||
|
pub.canonicalize(new OperationLog(), 0).getPublicKey().getKeyUsage());
|
||||||
|
|
||||||
mProviderHelper.savePublicKeyRing(pub);
|
mProviderHelper.savePublicKeyRing(pub);
|
||||||
|
|
||||||
|
@ -18,11 +18,8 @@
|
|||||||
|
|
||||||
package org.sufficientlysecure.keychain.pgp;
|
package org.sufficientlysecure.keychain.pgp;
|
||||||
|
|
||||||
import org.spongycastle.bcpg.SignatureSubpacketTags;
|
|
||||||
import org.spongycastle.bcpg.sig.KeyFlags;
|
import org.spongycastle.bcpg.sig.KeyFlags;
|
||||||
import org.spongycastle.openpgp.PGPPublicKey;
|
import org.spongycastle.openpgp.PGPPublicKey;
|
||||||
import org.spongycastle.openpgp.PGPSignature;
|
|
||||||
import org.spongycastle.openpgp.PGPSignatureSubpacketVector;
|
|
||||||
import org.spongycastle.openpgp.operator.jcajce.JcePublicKeyKeyEncryptionMethodGenerator;
|
import org.spongycastle.openpgp.operator.jcajce.JcePublicKeyKeyEncryptionMethodGenerator;
|
||||||
import org.sufficientlysecure.keychain.util.IterableIterator;
|
import org.sufficientlysecure.keychain.util.IterableIterator;
|
||||||
|
|
||||||
@ -40,7 +37,6 @@ public class CanonicalizedPublicKey extends UncachedPublicKey {
|
|||||||
|
|
||||||
// this is the parent key ring
|
// this is the parent key ring
|
||||||
final KeyRing mRing;
|
final KeyRing mRing;
|
||||||
private Integer mCacheUsage = null;
|
|
||||||
|
|
||||||
CanonicalizedPublicKey(KeyRing ring, PGPPublicKey key) {
|
CanonicalizedPublicKey(KeyRing ring, PGPPublicKey key) {
|
||||||
super(key);
|
super(key);
|
||||||
@ -52,7 +48,7 @@ public class CanonicalizedPublicKey extends UncachedPublicKey {
|
|||||||
}
|
}
|
||||||
|
|
||||||
JcePublicKeyKeyEncryptionMethodGenerator getPubKeyEncryptionGenerator() {
|
JcePublicKeyKeyEncryptionMethodGenerator getPubKeyEncryptionGenerator() {
|
||||||
return new JcePublicKeyKeyEncryptionMethodGenerator(mPublicKey);
|
return new JcePublicKeyKeyEncryptionMethodGenerator(mPublicKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean canSign() {
|
public boolean canSign() {
|
||||||
@ -68,32 +64,6 @@ public class CanonicalizedPublicKey extends UncachedPublicKey {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get all key usage flags.
|
|
||||||
* If at least one key flag subpacket is present return these.
|
|
||||||
* If no subpacket is present it returns null.
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public Integer getKeyUsage() {
|
|
||||||
if (mCacheUsage == null) {
|
|
||||||
for (PGPSignature sig : new IterableIterator<PGPSignature>(mPublicKey.getSignatures())) {
|
|
||||||
if (mPublicKey.isMasterKey() && sig.getKeyID() != mPublicKey.getKeyID()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
PGPSignatureSubpacketVector hashed = sig.getHashedSubPackets();
|
|
||||||
if (hashed != null && hashed.getSubpacket(SignatureSubpacketTags.KEY_FLAGS) != null) {
|
|
||||||
// init if at least one key flag subpacket has been found
|
|
||||||
if (mCacheUsage == null) {
|
|
||||||
mCacheUsage = 0;
|
|
||||||
}
|
|
||||||
mCacheUsage |= hashed.getKeyFlags();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return mCacheUsage;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean canCertify() {
|
public boolean canCertify() {
|
||||||
// if key flags subpacket is available, honor it!
|
// if key flags subpacket is available, honor it!
|
||||||
if (getKeyUsage() != null) {
|
if (getKeyUsage() != null) {
|
||||||
@ -129,4 +99,9 @@ public class CanonicalizedPublicKey extends UncachedPublicKey {
|
|||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Same method as superclass, but we make it public. */
|
||||||
|
public Integer getKeyUsage() {
|
||||||
|
return super.getKeyUsage();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,6 +39,7 @@ import java.util.Iterator;
|
|||||||
|
|
||||||
public class UncachedPublicKey {
|
public class UncachedPublicKey {
|
||||||
protected final PGPPublicKey mPublicKey;
|
protected final PGPPublicKey mPublicKey;
|
||||||
|
private Integer mCacheUsage = null;
|
||||||
|
|
||||||
public UncachedPublicKey(PGPPublicKey key) {
|
public UncachedPublicKey(PGPPublicKey key) {
|
||||||
mPublicKey = key;
|
mPublicKey = key;
|
||||||
@ -231,9 +232,8 @@ public class UncachedPublicKey {
|
|||||||
return mPublicKey.getFingerprint();
|
return mPublicKey.getFingerprint();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO This method should have package visibility - no access outside the pgp package!
|
|
||||||
// (It's still used in ProviderHelper at this point)
|
// (It's still used in ProviderHelper at this point)
|
||||||
public PGPPublicKey getPublicKey() {
|
PGPPublicKey getPublicKey() {
|
||||||
return mPublicKey;
|
return mPublicKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -271,4 +271,33 @@ public class UncachedPublicKey {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Get all key usage flags.
|
||||||
|
* If at least one key flag subpacket is present return these. If no
|
||||||
|
* subpacket is present it returns null.
|
||||||
|
*
|
||||||
|
* Note that this method has package visiblity because it is used in test
|
||||||
|
* cases. Certificates of UncachedPublicKey instances can NOT be assumed to
|
||||||
|
* be verified, so the result of this method should not be used in other
|
||||||
|
* places!
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
Integer getKeyUsage() {
|
||||||
|
if (mCacheUsage == null) {
|
||||||
|
for (PGPSignature sig : new IterableIterator<PGPSignature>(mPublicKey.getSignatures())) {
|
||||||
|
if (mPublicKey.isMasterKey() && sig.getKeyID() != mPublicKey.getKeyID()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
PGPSignatureSubpacketVector hashed = sig.getHashedSubPackets();
|
||||||
|
if (hashed != null && hashed.getSubpacket(SignatureSubpacketTags.KEY_FLAGS) != null) {
|
||||||
|
// init if at least one key flag subpacket has been found
|
||||||
|
if (mCacheUsage == null) {
|
||||||
|
mCacheUsage = 0;
|
||||||
|
}
|
||||||
|
mCacheUsage |= hashed.getKeyFlags();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return mCacheUsage;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user