reduce visibility where unnecessary

This commit is contained in:
Vincent Breitmoser
2017-10-13 17:04:44 +02:00
parent a4af2f7f5c
commit c89aab8802
6 changed files with 33 additions and 30 deletions

View File

@@ -21,7 +21,8 @@ import org.sufficientlysecure.keychain.securitytoken.usb.UsbTransportException;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
public class CardCapabilities { @SuppressWarnings("WeakerAccess")
class CardCapabilities {
private static final int MASK_CHAINING = 1 << 7; private static final int MASK_CHAINING = 1 << 7;
private static final int MASK_EXTENDED = 1 << 6; private static final int MASK_EXTENDED = 1 << 6;

View File

@@ -25,18 +25,18 @@ import org.sufficientlysecure.keychain.ui.CreateSecurityTokenAlgorithmFragment;
public abstract class KeyFormat { public abstract class KeyFormat {
public enum KeyFormatType { enum KeyFormatType {
RSAKeyFormatType, RSAKeyFormatType,
ECKeyFormatType ECKeyFormatType
}; }
private final KeyFormatType mKeyFormatType; private final KeyFormatType mKeyFormatType;
public KeyFormat(final KeyFormatType keyFormatType) { KeyFormat(final KeyFormatType keyFormatType) {
mKeyFormatType = keyFormatType; mKeyFormatType = keyFormatType;
} }
public final KeyFormatType keyFormatType() { final KeyFormatType keyFormatType() {
return mKeyFormatType; return mKeyFormatType;
} }

View File

@@ -21,7 +21,8 @@ import java.io.IOException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
public class OpenPgpCapabilities { @SuppressWarnings("unused") // just expose all included data
class OpenPgpCapabilities {
private final static int MASK_SM = 1 << 7; private final static int MASK_SM = 1 << 7;
private final static int MASK_KEY_IMPORT = 1 << 5; private final static int MASK_KEY_IMPORT = 1 << 5;
private final static int MASK_ATTRIBUTES_CHANGABLE = 1 << 2; private final static int MASK_ATTRIBUTES_CHANGABLE = 1 << 2;
@@ -40,12 +41,12 @@ public class OpenPgpCapabilities {
private Map<KeyType, KeyFormat> mKeyFormats; private Map<KeyType, KeyFormat> mKeyFormats;
public OpenPgpCapabilities(byte[] data) throws IOException { OpenPgpCapabilities(byte[] data) throws IOException {
mKeyFormats = new HashMap<>(); mKeyFormats = new HashMap<>();
updateWithData(data); updateWithData(data);
} }
public void updateWithData(byte[] data) throws IOException { void updateWithData(byte[] data) throws IOException {
Iso7816TLV[] tlvs = Iso7816TLV.readList(data, true); Iso7816TLV[] tlvs = Iso7816TLV.readList(data, true);
if (tlvs.length == 1 && tlvs[0].mT == 0x6E) { if (tlvs.length == 1 && tlvs[0].mT == 0x6E) {
tlvs = ((Iso7816TLV.Iso7816CompositeTLV) tlvs[0]).mSubs; tlvs = ((Iso7816TLV.Iso7816CompositeTLV) tlvs[0]).mSubs;
@@ -114,47 +115,47 @@ public class OpenPgpCapabilities {
mMaxRspLen = (v[8] << 8) + v[9]; mMaxRspLen = (v[8] << 8) + v[9];
} }
public boolean isPw1ValidForMultipleSignatures() { boolean isPw1ValidForMultipleSignatures() {
return mPw1ValidForMultipleSignatures; return mPw1ValidForMultipleSignatures;
} }
public byte[] getAid() { byte[] getAid() {
return mAid; return mAid;
} }
public byte[] getHistoricalBytes() { byte[] getHistoricalBytes() {
return mHistoricalBytes; return mHistoricalBytes;
} }
public boolean isHasSM() { boolean isHasSM() {
return mHasSM; return mHasSM;
} }
public boolean isAttributesChangable() { boolean isAttributesChangable() {
return mAttriburesChangable; return mAttriburesChangable;
} }
public boolean isHasKeyImport() { boolean isHasKeyImport() {
return mHasKeyImport; return mHasKeyImport;
} }
public boolean isHasAESSM() { boolean isHasAESSM() {
return isHasSM() && ((mSMType == 1) || (mSMType == 2)); return isHasSM() && ((mSMType == 1) || (mSMType == 2));
} }
public boolean isHasSCP11bSM() { boolean isHasSCP11bSM() {
return isHasSM() && (mSMType == 3); return isHasSM() && (mSMType == 3);
} }
public int getMaxCmdLen() { int getMaxCmdLen() {
return mMaxCmdLen; return mMaxCmdLen;
} }
public int getMaxRspLen() { int getMaxRspLen() {
return mMaxRspLen; return mMaxRspLen;
} }
public KeyFormat getFormatForKeyType(KeyType keyType) { KeyFormat getFormatForKeyType(KeyType keyType) {
return mKeyFormats.get(keyType); return mKeyFormats.get(keyType);
} }
} }

View File

@@ -24,6 +24,7 @@ import com.google.auto.value.AutoValue;
/** A response APDU as defined in ISO/IEC 7816-4. */ /** A response APDU as defined in ISO/IEC 7816-4. */
@AutoValue @AutoValue
@SuppressWarnings("WeakerAccess")
public abstract class ResponseApdu { public abstract class ResponseApdu {
private static final int APDU_SW_SUCCESS = 0x9000; private static final int APDU_SW_SUCCESS = 0x9000;

View File

@@ -150,7 +150,7 @@ class SCP11bSecureMessaging implements SecureMessaging {
&& (mMacChaining != null); && (mMacChaining != null);
} }
private static final ECParameterSpec getAlgorithmParameterSpec(final ECKeyFormat kf) private static ECParameterSpec getAlgorithmParameterSpec(final ECKeyFormat kf)
throws NoSuchProviderException, NoSuchAlgorithmException, InvalidParameterSpecException { throws NoSuchProviderException, NoSuchAlgorithmException, InvalidParameterSpecException {
final AlgorithmParameters algoParams = AlgorithmParameters.getInstance(SCP11B_KEY_AGREEMENT_KEY_ALGO, PROVIDER); final AlgorithmParameters algoParams = AlgorithmParameters.getInstance(SCP11B_KEY_AGREEMENT_KEY_ALGO, PROVIDER);
@@ -273,7 +273,7 @@ class SCP11bSecureMessaging implements SecureMessaging {
} }
public static void establish(final SecurityTokenConnection t, final Context ctx, OpenPgpCommandApduFactory commandFactory) static void establish(final SecurityTokenConnection t, final Context ctx, OpenPgpCommandApduFactory commandFactory)
throws SecureMessagingException, IOException { throws SecureMessagingException, IOException {
CommandAPDU cmd; CommandAPDU cmd;

View File

@@ -33,8 +33,8 @@ import java.security.interfaces.ECPrivateKey;
import java.security.interfaces.ECPublicKey; import java.security.interfaces.ECPublicKey;
import java.security.interfaces.RSAPrivateCrtKey; import java.security.interfaces.RSAPrivateCrtKey;
public class SecurityTokenUtils { class SecurityTokenUtils {
public static byte[] attributesFromSecretKey(final KeyType slot, final CanonicalizedSecretKey secretKey) throws IOException, PgpGeneralException { static byte[] attributesFromSecretKey(final KeyType slot, final CanonicalizedSecretKey secretKey) throws IOException, PgpGeneralException {
if (secretKey.isRSA()) { if (secretKey.isRSA()) {
final int mModulusLength = secretKey.getBitStrength(); final int mModulusLength = secretKey.getBitStrength();
final int mExponentLength = secretKey.getSecurityTokenRSASecretKey().getPublicExponent().bitLength(); final int mExponentLength = secretKey.getSecurityTokenRSASecretKey().getPublicExponent().bitLength();
@@ -46,7 +46,7 @@ public class SecurityTokenUtils {
attrs[i++] = (byte) (mModulusLength & 0xff); attrs[i++] = (byte) (mModulusLength & 0xff);
attrs[i++] = (byte) ((mExponentLength >> 8) & 0xff); attrs[i++] = (byte) ((mExponentLength >> 8) & 0xff);
attrs[i++] = (byte) (mExponentLength & 0xff); attrs[i++] = (byte) (mExponentLength & 0xff);
attrs[i++] = RSAKeyFormat.RSAAlgorithmFormat.CRT_WITH_MODULUS.getValue(); attrs[i] = RSAKeyFormat.RSAAlgorithmFormat.CRT_WITH_MODULUS.getValue();
return attrs; return attrs;
} else if (secretKey.isEC()) { } else if (secretKey.isEC()) {
@@ -70,8 +70,8 @@ public class SecurityTokenUtils {
} }
public static byte[] createRSAPrivKeyTemplate(RSAPrivateCrtKey secretKey, KeyType slot, static byte[] createRSAPrivKeyTemplate(RSAPrivateCrtKey secretKey, KeyType slot,
RSAKeyFormat format) throws IOException { RSAKeyFormat format) throws IOException {
ByteArrayOutputStream stream = new ByteArrayOutputStream(), ByteArrayOutputStream stream = new ByteArrayOutputStream(),
template = new ByteArrayOutputStream(), template = new ByteArrayOutputStream(),
data = new ByteArrayOutputStream(), data = new ByteArrayOutputStream(),
@@ -138,8 +138,8 @@ public class SecurityTokenUtils {
return res.toByteArray(); return res.toByteArray();
} }
public static byte[] createECPrivKeyTemplate(ECPrivateKey secretKey, ECPublicKey publicKey, KeyType slot, static byte[] createECPrivKeyTemplate(ECPrivateKey secretKey, ECPublicKey publicKey, KeyType slot,
ECKeyFormat format) throws IOException { ECKeyFormat format) throws IOException {
ByteArrayOutputStream stream = new ByteArrayOutputStream(), ByteArrayOutputStream stream = new ByteArrayOutputStream(),
template = new ByteArrayOutputStream(), template = new ByteArrayOutputStream(),
data = new ByteArrayOutputStream(), data = new ByteArrayOutputStream(),
@@ -184,7 +184,7 @@ public class SecurityTokenUtils {
return res.toByteArray(); return res.toByteArray();
} }
public static byte[] encodeLength(int len) { static byte[] encodeLength(int len) {
if (len < 0) { if (len < 0) {
throw new IllegalArgumentException("length is negative"); throw new IllegalArgumentException("length is negative");
} else if (len >= 16777216) { } else if (len >= 16777216) {
@@ -214,7 +214,7 @@ public class SecurityTokenUtils {
return res; return res;
} }
public static void writeBits(ByteArrayOutputStream stream, BigInteger value, int width) { static void writeBits(ByteArrayOutputStream stream, BigInteger value, int width) {
if (value.signum() == -1) { if (value.signum() == -1) {
throw new IllegalArgumentException("value is negative"); throw new IllegalArgumentException("value is negative");
} else if (width <= 0) { } else if (width <= 0) {