use of org.xipki.security.exception.NoIdleSignerException in project xipki by xipki.
the class CsrGenAction method generateRequest.
private PKCS10CertificationRequest generateRequest(ConcurrentContentSigner signer, SubjectPublicKeyInfo subjectPublicKeyInfo, X500Name subjectDn, Map<ASN1ObjectIdentifier, ASN1Encodable> attributes) throws XiSecurityException {
ParamUtil.requireNonNull("signer", signer);
ParamUtil.requireNonNull("subjectPublicKeyInfo", subjectPublicKeyInfo);
ParamUtil.requireNonNull("subjectDn", subjectDn);
PKCS10CertificationRequestBuilder csrBuilder = new PKCS10CertificationRequestBuilder(subjectDn, subjectPublicKeyInfo);
if (CollectionUtil.isNonEmpty(attributes)) {
for (ASN1ObjectIdentifier attrType : attributes.keySet()) {
csrBuilder.addAttribute(attrType, attributes.get(attrType));
}
}
ConcurrentBagEntrySigner signer0;
try {
signer0 = signer.borrowSigner();
} catch (NoIdleSignerException ex) {
throw new XiSecurityException(ex.getMessage(), ex);
}
try {
return csrBuilder.build(signer0.value());
} finally {
signer.requiteSigner(signer0);
}
}
use of org.xipki.security.exception.NoIdleSignerException in project xipki by xipki.
the class SecurityFactoryImpl method validateSigner.
private static void validateSigner(ConcurrentContentSigner signer, String signerType, SignerConf signerConf) throws ObjectCreationException {
if (signer.getPublicKey() == null) {
return;
}
String signatureAlgoName = signer.getAlgorithmName();
try {
byte[] dummyContent = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
Signature verifier = Signature.getInstance(signatureAlgoName, "BC");
byte[] signatureValue = signer.sign(dummyContent);
verifier.initVerify(signer.getPublicKey());
verifier.update(dummyContent);
boolean valid = verifier.verify(signatureValue);
if (!valid) {
StringBuilder sb = new StringBuilder();
sb.append("private key and public key does not match, ");
sb.append("key type='").append(signerType).append("'; ");
String pwd = signerConf.getConfValue("password");
if (pwd != null) {
signerConf.putConfEntry("password", "****");
}
signerConf.putConfEntry("algo", signatureAlgoName);
sb.append("conf='").append(signerConf.getConf());
X509Certificate cert = signer.getCertificate();
if (cert != null) {
String subject = X509Util.getRfc4519Name(cert.getSubjectX500Principal());
sb.append("', certificate subject='").append(subject).append("'");
}
throw new ObjectCreationException(sb.toString());
}
} catch (NoSuchAlgorithmException | InvalidKeyException | SignatureException | NoSuchProviderException | NoIdleSignerException ex) {
throw new ObjectCreationException(ex.getMessage(), ex);
}
}
Aggregations