Rename methods related only to security tokens
This commit is contained in:
@@ -203,7 +203,7 @@ public class CanonicalizedPublicKey extends UncachedPublicKey {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// For use only in card export; returns the public key.
|
// For use only in card export; returns the public key.
|
||||||
public ECPublicKey getECPublicKey()
|
public ECPublicKey getSecurityTokenECPublicKey()
|
||||||
throws PgpGeneralException {
|
throws PgpGeneralException {
|
||||||
JcaPGPKeyConverter keyConverter = new JcaPGPKeyConverter();
|
JcaPGPKeyConverter keyConverter = new JcaPGPKeyConverter();
|
||||||
PublicKey retVal;
|
PublicKey retVal;
|
||||||
@@ -216,7 +216,7 @@ public class CanonicalizedPublicKey extends UncachedPublicKey {
|
|||||||
return (ECPublicKey) retVal;
|
return (ECPublicKey) retVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ASN1ObjectIdentifier getHashAlgorithm()
|
public ASN1ObjectIdentifier getSecurityTokenHashAlgorithm()
|
||||||
throws PGPException {
|
throws PGPException {
|
||||||
if (!isEC()) {
|
if (!isEC()) {
|
||||||
throw new PGPException("Key encryption OID is valid only for EC key!");
|
throw new PGPException("Key encryption OID is valid only for EC key!");
|
||||||
@@ -236,7 +236,7 @@ public class CanonicalizedPublicKey extends UncachedPublicKey {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getSymmetricKeySize()
|
public int getSecurityTokenSymmetricKeySize()
|
||||||
throws PGPException {
|
throws PGPException {
|
||||||
if (!isEC()) {
|
if (!isEC()) {
|
||||||
throw new PGPException("Key encryption OID is valid only for EC key!");
|
throw new PGPException("Key encryption OID is valid only for EC key!");
|
||||||
|
|||||||
@@ -300,7 +300,7 @@ public class CanonicalizedSecretKey extends CanonicalizedPublicKey {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// For use only in card export; returns the secret key in Chinese Remainder Theorem format.
|
// For use only in card export; returns the secret key in Chinese Remainder Theorem format.
|
||||||
public RSAPrivateCrtKey getCrtSecretKey() throws PgpGeneralException {
|
public RSAPrivateCrtKey getSecurityTokenRSASecretKey() throws PgpGeneralException {
|
||||||
if (mPrivateKeyState == PRIVATE_KEY_STATE_LOCKED) {
|
if (mPrivateKeyState == PRIVATE_KEY_STATE_LOCKED) {
|
||||||
throw new PgpGeneralException("Cannot get secret key attributes while key is locked.");
|
throw new PgpGeneralException("Cannot get secret key attributes while key is locked.");
|
||||||
}
|
}
|
||||||
@@ -321,7 +321,7 @@ public class CanonicalizedSecretKey extends CanonicalizedPublicKey {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// For use only in card export; returns the secret key.
|
// For use only in card export; returns the secret key.
|
||||||
public ECPrivateKey getECSecretKey()
|
public ECPrivateKey getSecurityTokenECSecretKey()
|
||||||
throws PgpGeneralException {
|
throws PgpGeneralException {
|
||||||
if (mPrivateKeyState == PRIVATE_KEY_STATE_LOCKED) {
|
if (mPrivateKeyState == PRIVATE_KEY_STATE_LOCKED) {
|
||||||
throw new PgpGeneralException("Cannot get secret key attributes while key is locked.");
|
throw new PgpGeneralException("Cannot get secret key attributes while key is locked.");
|
||||||
|
|||||||
@@ -338,7 +338,7 @@ public class SecurityTokenHelper {
|
|||||||
System.arraycopy(encryptedSessionKey, 2 + pLen + 1, keyEnc, 0, keyEnc.length);
|
System.arraycopy(encryptedSessionKey, 2 + pLen + 1, keyEnc, 0, keyEnc.length);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final MessageDigest kdf = MessageDigest.getInstance(MessageDigestUtils.getDigestName(publicKey.getHashAlgorithm()));
|
final MessageDigest kdf = MessageDigest.getInstance(MessageDigestUtils.getDigestName(publicKey.getSecurityTokenHashAlgorithm()));
|
||||||
|
|
||||||
kdf.update(new byte[]{ (byte)0, (byte)0, (byte)0, (byte)1 });
|
kdf.update(new byte[]{ (byte)0, (byte)0, (byte)0, (byte)1 });
|
||||||
kdf.update(data);
|
kdf.update(data);
|
||||||
@@ -347,7 +347,7 @@ public class SecurityTokenHelper {
|
|||||||
final byte[] kek = kdf.digest();
|
final byte[] kek = kdf.digest();
|
||||||
final Cipher c = Cipher.getInstance("AESWrap");
|
final Cipher c = Cipher.getInstance("AESWrap");
|
||||||
|
|
||||||
c.init(Cipher.UNWRAP_MODE, new SecretKeySpec(kek, 0, publicKey.getSymmetricKeySize() / 8, "AES"));
|
c.init(Cipher.UNWRAP_MODE, new SecretKeySpec(kek, 0, publicKey.getSecurityTokenSymmetricKeySize() / 8, "AES"));
|
||||||
|
|
||||||
final Key paddedSessionKey = c.unwrap(keyEnc, "Session", Cipher.SECRET_KEY);
|
final Key paddedSessionKey = c.unwrap(keyEnc, "Session", Cipher.SECRET_KEY);
|
||||||
|
|
||||||
@@ -489,7 +489,7 @@ public class SecurityTokenHelper {
|
|||||||
if (!secretKey.isRSA()) {
|
if (!secretKey.isRSA()) {
|
||||||
throw new IOException("Security Token not configured for RSA key.");
|
throw new IOException("Security Token not configured for RSA key.");
|
||||||
}
|
}
|
||||||
crtSecretKey = secretKey.getCrtSecretKey();
|
crtSecretKey = secretKey.getSecurityTokenRSASecretKey();
|
||||||
|
|
||||||
// Should happen only rarely; all GnuPG keys since 2006 use public exponent 65537.
|
// Should happen only rarely; all GnuPG keys since 2006 use public exponent 65537.
|
||||||
if (!crtSecretKey.getPublicExponent().equals(new BigInteger("65537"))) {
|
if (!crtSecretKey.getPublicExponent().equals(new BigInteger("65537"))) {
|
||||||
@@ -506,8 +506,8 @@ public class SecurityTokenHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
secretKey.unlock(passphrase);
|
secretKey.unlock(passphrase);
|
||||||
ecSecretKey = secretKey.getECSecretKey();
|
ecSecretKey = secretKey.getSecurityTokenECSecretKey();
|
||||||
ecPublicKey = secretKey.getECPublicKey();
|
ecPublicKey = secretKey.getSecurityTokenECPublicKey();
|
||||||
|
|
||||||
keyBytes = SecurityTokenUtils.createECPrivKeyTemplate(ecSecretKey, ecPublicKey, slot,
|
keyBytes = SecurityTokenUtils.createECPrivKeyTemplate(ecSecretKey, ecPublicKey, slot,
|
||||||
(ECKeyFormat) (mOpenPgpCapabilities.getFormatForKeyType(slot)));
|
(ECKeyFormat) (mOpenPgpCapabilities.getFormatForKeyType(slot)));
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ public class SecurityTokenUtils {
|
|||||||
public static byte[] attributesFromSecretKey(final KeyType slot, final CanonicalizedSecretKey secretKey) throws IOException, PgpGeneralException {
|
public 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.getCrtSecretKey().getPublicExponent().bitLength();
|
final int mExponentLength = secretKey.getSecurityTokenRSASecretKey().getPublicExponent().bitLength();
|
||||||
final byte[] attrs = new byte[6];
|
final byte[] attrs = new byte[6];
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user