use of org.xipki.security.exception.P11TokenException in project xipki by xipki.
the class ProxyP11Slot method removeObjects.
@Override
public int removeObjects(byte[] id, String label) throws P11TokenException {
if ((id == null || id.length == 0) && StringUtil.isBlank(label)) {
throw new IllegalArgumentException("at least one of id and label must not be null");
}
Asn1RemoveObjectsParams params = new Asn1RemoveObjectsParams(slotId, id, label);
byte[] resp = module.send(P11ProxyConstants.ACTION_REMOVE_OBJECTS, params);
try {
return ASN1Integer.getInstance(resp).getValue().intValue();
} catch (IllegalArgumentException ex) {
throw new P11TokenException(ex.getMessage(), ex);
}
}
use of org.xipki.security.exception.P11TokenException in project xipki by xipki.
the class EmulatorP11Slot method loadProperties.
private Properties loadProperties(File file) throws P11TokenException {
try {
try (InputStream stream = new FileInputStream(file)) {
Properties props = new Properties();
props.load(stream);
return props;
}
} catch (IOException ex) {
throw new P11TokenException("could not load properties from the file " + file.getPath(), ex);
}
}
use of org.xipki.security.exception.P11TokenException in project xipki by xipki.
the class EmulatorP11Slot method savePkcs11SecretKey.
private void savePkcs11SecretKey(byte[] id, String label, SecretKey secretKey) throws P11TokenException {
byte[] encrytedValue;
try {
KeyStore ks = KeyStore.getInstance("JCEKS");
ks.load(null, password);
ks.setKeyEntry("main", secretKey, password, null);
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
ks.store(outStream, password);
outStream.flush();
encrytedValue = outStream.toByteArray();
} catch (NoSuchAlgorithmException | KeyStoreException | CertificateException | IOException ex) {
throw new P11TokenException(ex.getClass().getName() + ": " + ex.getMessage(), ex);
}
savePkcs11Entry(secKeyDir, id, label, encrytedValue);
}
use of org.xipki.security.exception.P11TokenException in project xipki by xipki.
the class EmulatorP11Slot method generateECKeypair0.
@Override
protected P11Identity generateECKeypair0(ASN1ObjectIdentifier curveId, String label, P11NewKeyControl control) throws P11TokenException {
assertMechanismSupported(PKCS11Constants.CKM_EC_KEY_PAIR_GEN);
KeyPair keypair;
try {
keypair = KeyUtil.generateECKeypairForCurveNameOrOid(curveId.getId(), random);
} catch (NoSuchAlgorithmException | NoSuchProviderException | InvalidAlgorithmParameterException ex) {
throw new P11TokenException(ex.getMessage(), ex);
}
return saveP11Entity(keypair, label);
}
use of org.xipki.security.exception.P11TokenException in project xipki by xipki.
the class LocalP11CryptServicePool method init.
public void init() throws P11TokenException, XiSecurityException {
LOG.info("initializing ...");
if (initialized.get()) {
LOG.info("already initialized, skipping ...");
return;
}
if (p11CryptServiceFactory == null) {
throw new IllegalStateException("securityFactory is not configured");
}
Set<String> moduleNames = p11CryptServiceFactory.getModuleNames();
for (String moduleName : moduleNames) {
P11CryptService p11Service = p11CryptServiceFactory.getP11CryptService(moduleName);
if (p11Service != null) {
short moduleId = deriveModuleId(moduleName);
String hexModuleId = "0x" + Integer.toHexString(moduleId);
if (p11CryptServices.containsKey(moduleId)) {
throw new P11TokenException("module Id " + moduleId + " for name " + moduleName + " already used, use another module name");
}
p11CryptServices.put(moduleId, p11Service);
LOG.info("map module name '{}' to ID {}({}), access path: " + "'proxy:url=https://<host>:<port>/p11proxy,module={}'", moduleName, moduleId, hexModuleId, hexModuleId);
}
}
initialized.set(true);
LOG.info("initialized");
}
Aggregations