Add special handling for expected ECC import format for Nitrokey 3
This commit is contained in:
@@ -33,13 +33,13 @@ import java.security.interfaces.RSAPrivateCrtKey;
|
|||||||
|
|
||||||
public class SecurityTokenUtils {
|
public class SecurityTokenUtils {
|
||||||
public static byte[] attributesFromSecretKey(KeyType slot, CanonicalizedSecretKey secretKey,
|
public static byte[] attributesFromSecretKey(KeyType slot, CanonicalizedSecretKey secretKey,
|
||||||
KeyFormat formatForKeyType)
|
KeyFormat currentKeyFormat, boolean withEccPublicKey)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
if (secretKey.isRSA()) {
|
if (secretKey.isRSA()) {
|
||||||
return attributesForRsaKey(secretKey.getBitStrength(), (RsaKeyFormat) formatForKeyType);
|
return attributesForRsaKey(secretKey.getBitStrength(), (RsaKeyFormat) currentKeyFormat);
|
||||||
} else if (secretKey.isEC()) {
|
} else if (secretKey.isEC()) {
|
||||||
byte[] oid = new ASN1ObjectIdentifier(secretKey.getCurveOid()).getEncoded();
|
byte[] oid = new ASN1ObjectIdentifier(secretKey.getCurveOid()).getEncoded();
|
||||||
byte[] attrs = new byte[1 + (oid.length - 2) + 1];
|
byte[] attrs = new byte[1 + (oid.length - 2) + (withEccPublicKey ? 1 : 0)];
|
||||||
|
|
||||||
if (slot.equals(KeyType.ENCRYPT))
|
if (slot.equals(KeyType.ENCRYPT))
|
||||||
attrs[0] = PublicKeyAlgorithmTags.ECDH;
|
attrs[0] = PublicKeyAlgorithmTags.ECDH;
|
||||||
@@ -49,7 +49,9 @@ public class SecurityTokenUtils {
|
|||||||
|
|
||||||
System.arraycopy(oid, 2, attrs, 1, (oid.length - 2));
|
System.arraycopy(oid, 2, attrs, 1, (oid.length - 2));
|
||||||
|
|
||||||
|
if (withEccPublicKey) {
|
||||||
attrs[attrs.length - 1] = (byte) 0xff;
|
attrs[attrs.length - 1] = (byte) 0xff;
|
||||||
|
}
|
||||||
|
|
||||||
return attrs;
|
return attrs;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ import org.sufficientlysecure.keychain.securitytoken.OpenPgpCapabilities;
|
|||||||
import org.sufficientlysecure.keychain.securitytoken.RsaKeyFormat;
|
import org.sufficientlysecure.keychain.securitytoken.RsaKeyFormat;
|
||||||
import org.sufficientlysecure.keychain.securitytoken.ResponseApdu;
|
import org.sufficientlysecure.keychain.securitytoken.ResponseApdu;
|
||||||
import org.sufficientlysecure.keychain.securitytoken.SecurityTokenConnection;
|
import org.sufficientlysecure.keychain.securitytoken.SecurityTokenConnection;
|
||||||
|
import org.sufficientlysecure.keychain.securitytoken.SecurityTokenInfo.TokenType;
|
||||||
import org.sufficientlysecure.keychain.securitytoken.SecurityTokenUtils;
|
import org.sufficientlysecure.keychain.securitytoken.SecurityTokenUtils;
|
||||||
import org.sufficientlysecure.keychain.util.Passphrase;
|
import org.sufficientlysecure.keychain.util.Passphrase;
|
||||||
|
|
||||||
@@ -150,7 +151,9 @@ public class SecurityTokenChangeKeyTokenOp {
|
|||||||
OpenPgpCapabilities openPgpCapabilities = connection.getOpenPgpCapabilities();
|
OpenPgpCapabilities openPgpCapabilities = connection.getOpenPgpCapabilities();
|
||||||
KeyFormat formatForKeyType = openPgpCapabilities.getFormatForKeyType(slot);
|
KeyFormat formatForKeyType = openPgpCapabilities.getFormatForKeyType(slot);
|
||||||
|
|
||||||
return SecurityTokenUtils.attributesFromSecretKey(slot, secretKey, formatForKeyType);
|
// the Nitrokey 3 doesn't support including the public key
|
||||||
|
boolean withEccPublicKey = connection.getTokenType() != TokenType.NITROKEY_3;
|
||||||
|
return SecurityTokenUtils.attributesFromSecretKey(slot, secretKey, formatForKeyType, withEccPublicKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setKeyAttributes(Passphrase adminPin, KeyType keyType, byte[] data) throws IOException {
|
private void setKeyAttributes(Passphrase adminPin, KeyType keyType, byte[] data) throws IOException {
|
||||||
|
|||||||
Reference in New Issue
Block a user