use of org.xipki.security.exception.P11TokenException in project xipki by xipki.
the class EmulatorP11Identity method rsaPkcsSign.
private byte[] rsaPkcsSign(byte[] contentToSign, HashAlgo hashAlgo) throws P11TokenException {
int modulusBitLen = getSignatureKeyBitLength();
byte[] paddedHash;
try {
if (hashAlgo == null) {
paddedHash = SignerUtil.EMSA_PKCS1_v1_5_encoding(contentToSign, modulusBitLen);
} else {
byte[] hash = hashAlgo.hash(contentToSign);
paddedHash = SignerUtil.EMSA_PKCS1_v1_5_encoding(hash, modulusBitLen, hashAlgo);
}
} catch (XiSecurityException ex) {
throw new P11TokenException("XiSecurityException: " + ex.getMessage(), ex);
}
return rsaX509Sign(paddedHash);
}
use of org.xipki.security.exception.P11TokenException in project xipki by xipki.
the class ProxyP11Slot method getPublicKey.
private PublicKey getPublicKey(P11ObjectIdentifier objectId) throws P11UnknownEntityException, P11TokenException {
P11EntityIdentifier entityId = new P11EntityIdentifier(slotId, objectId);
byte[] resp = module.send(P11ProxyConstants.ACTION_GET_PUBLICKEY, new Asn1P11EntityIdentifier(entityId));
if (resp == null) {
return null;
}
SubjectPublicKeyInfo pkInfo = SubjectPublicKeyInfo.getInstance(resp);
try {
return KeyUtil.generatePublicKey(pkInfo);
} catch (NoSuchAlgorithmException | InvalidKeySpecException ex) {
throw new P11TokenException("could not generate Public Key from SubjectPublicKeyInfo:" + ex.getMessage(), ex);
}
}
use of org.xipki.security.exception.P11TokenException in project xipki by xipki.
the class ProxyP11Slot method getObjectIdsFromServer.
private List<P11ObjectIdentifier> getObjectIdsFromServer(short action) throws P11TokenException {
Asn1P11SlotIdentifier asn1SlotId = new Asn1P11SlotIdentifier(slotId);
byte[] resp = module.send(action, asn1SlotId);
List<Asn1P11ObjectIdentifier> asn1ObjectIds;
try {
asn1ObjectIds = Asn1P11ObjectIdentifiers.getInstance(resp).getObjectIds();
} catch (BadAsn1ObjectException ex) {
throw new P11TokenException("bad ASN1 object: " + ex.getMessage(), ex);
}
List<P11ObjectIdentifier> objectIds = new ArrayList<>(asn1ObjectIds.size());
for (Asn1P11ObjectIdentifier asn1Id : asn1ObjectIds) {
objectIds.add(asn1Id.getObjectId());
}
return objectIds;
}
use of org.xipki.security.exception.P11TokenException in project xipki by xipki.
the class EmulatorP11Slot method savePkcs11Entry.
private static void savePkcs11Entry(File dir, byte[] id, String label, byte[] value) throws P11TokenException {
ParamUtil.requireNonNull("dir", dir);
ParamUtil.requireNonNull("id", id);
ParamUtil.requireNonBlank("label", label);
ParamUtil.requireNonNull("value", value);
String hexId = hex(id);
String str = StringUtil.concat(PROP_ID, "=", hexId, "\n", PROP_LABEL, "=", label, "\n", PROP_SHA1SUM, "=", HashAlgo.SHA1.hexHash(value), "\n");
try {
IoUtil.save(new File(dir, hexId + INFO_FILE_SUFFIX), str.getBytes());
IoUtil.save(new File(dir, hexId + VALUE_FILE_SUFFIX), value);
} catch (IOException ex) {
throw new P11TokenException("could not save certificate");
}
}
use of org.xipki.security.exception.P11TokenException in project xipki by xipki.
the class EmulatorP11Slot method savePkcs11PrivateKey.
private void savePkcs11PrivateKey(byte[] id, String label, PrivateKey privateKey) throws P11TokenException {
PKCS8EncryptedPrivateKeyInfo encryptedPrivKeyInfo = privateKeyCryptor.encrypt(privateKey);
byte[] encoded;
try {
encoded = encryptedPrivKeyInfo.getEncoded();
} catch (IOException ex) {
LogUtil.error(LOG, ex);
throw new P11TokenException("could not encode PrivateKey");
}
savePkcs11Entry(privKeyDir, id, label, encoded);
}
Aggregations