use of java.security.cert.CertificateEncodingException in project xipki by xipki.
the class AbstractOcspRequestor method ask.
@Override
public OCSPResp ask(X509Certificate issuerCert, X509Certificate cert, URL responderUrl, RequestOptions requestOptions, RequestResponseDebug debug) throws OcspResponseException, OcspRequestorException {
ParamUtil.requireNonNull("issuerCert", issuerCert);
ParamUtil.requireNonNull("cert", cert);
try {
if (!X509Util.issues(issuerCert, cert)) {
throw new IllegalArgumentException("cert and issuerCert do not match");
}
} catch (CertificateEncodingException ex) {
throw new OcspRequestorException(ex.getMessage(), ex);
}
return ask(issuerCert, new BigInteger[] { cert.getSerialNumber() }, responderUrl, requestOptions, debug);
}
use of java.security.cert.CertificateEncodingException in project xipki by xipki.
the class AbstractOcspRequestor method ask.
@Override
public OCSPResp ask(X509Certificate issuerCert, X509Certificate[] certs, URL responderUrl, RequestOptions requestOptions, RequestResponseDebug debug) throws OcspResponseException, OcspRequestorException {
ParamUtil.requireNonNull("issuerCert", issuerCert);
ParamUtil.requireNonNull("certs", certs);
ParamUtil.requireMin("certs.length", certs.length, 1);
BigInteger[] serialNumbers = new BigInteger[certs.length];
for (int i = 0; i < certs.length; i++) {
X509Certificate cert = certs[i];
try {
if (!X509Util.issues(issuerCert, cert)) {
throw new IllegalArgumentException("cert at index " + i + " and issuerCert do not match");
}
} catch (CertificateEncodingException ex) {
throw new OcspRequestorException(ex.getMessage(), ex);
}
serialNumbers[i] = cert.getSerialNumber();
}
return ask(issuerCert, serialNumbers, responderUrl, requestOptions, debug);
}
use of java.security.cert.CertificateEncodingException in project xipki by xipki.
the class CaManagerQueryExecutor method addRequestor.
// method addCmpControl
void addRequestor(RequestorEntry dbEntry) throws CaMgmtException {
ParamUtil.requireNonNull("dbEntry", dbEntry);
try {
int id = (int) datasource.getMax(null, "REQUESTOR", "ID");
dbEntry.getIdent().setId(id + 1);
} catch (DataAccessException ex) {
throw new CaMgmtException(ex);
}
final String sql = "INSERT INTO REQUESTOR (ID,NAME,CERT) VALUES (?,?,?)";
PreparedStatement ps = null;
try {
ps = prepareStatement(sql);
int idx = 1;
ps.setInt(idx++, dbEntry.getIdent().getId());
ps.setString(idx++, dbEntry.getIdent().getName());
ps.setString(idx++, Base64.encodeToString(dbEntry.getCert().getEncoded()));
if (ps.executeUpdate() == 0) {
throw new CaMgmtException("could not add requestor " + dbEntry.getIdent());
}
if (LOG.isInfoEnabled()) {
LOG.info("added requestor '{}': {}", dbEntry.getIdent(), dbEntry.toString(false));
}
} catch (SQLException ex) {
throw new CaMgmtException(datasource, sql, ex);
} catch (CertificateEncodingException ex) {
throw new CaMgmtException(ex);
} finally {
datasource.releaseResources(ps, null);
}
}
use of java.security.cert.CertificateEncodingException in project xipki by xipki.
the class ScepUtil method getCoreExtValue.
private static byte[] getCoreExtValue(X509Certificate cert, ASN1ObjectIdentifier type) throws CertificateEncodingException {
requireNonNull("cert", cert);
requireNonNull("type", type);
byte[] fullExtValue = cert.getExtensionValue(type.getId());
if (fullExtValue == null) {
return null;
}
try {
return ASN1OctetString.getInstance(fullExtValue).getOctets();
} catch (IllegalArgumentException ex) {
throw new CertificateEncodingException("invalid extension " + type.getId() + ": " + ex.getMessage());
}
}
use of java.security.cert.CertificateEncodingException in project xipki by xipki.
the class NextCaMessage method encode.
public ContentInfo encode(PrivateKey signingKey, X509Certificate signerCert, X509Certificate[] cmsCertSet) throws MessageEncodingException {
ScepUtil.requireNonNull("signingKey", signingKey);
ScepUtil.requireNonNull("signerCert", signerCert);
try {
byte[] degenratedSignedDataBytes;
try {
CMSSignedDataGenerator degenerateSignedData = new CMSSignedDataGenerator();
degenerateSignedData.addCertificate(new X509CertificateHolder(caCert.getEncoded()));
if (raCerts != null && !raCerts.isEmpty()) {
for (X509Certificate m : raCerts) {
degenerateSignedData.addCertificate(new X509CertificateHolder(m.getEncoded()));
}
}
degenratedSignedDataBytes = degenerateSignedData.generate(new CMSAbsentContent()).getEncoded();
} catch (CertificateEncodingException ex) {
throw new MessageEncodingException(ex.getMessage(), ex);
}
CMSSignedDataGenerator generator = new CMSSignedDataGenerator();
// I don't known which hash algorithm is supported by the client, use SHA-1
String signatureAlgo = getSignatureAlgorithm(signingKey, ScepHashAlgo.SHA1);
ContentSigner signer = new JcaContentSignerBuilder(signatureAlgo).build(signingKey);
// signerInfo
JcaSignerInfoGeneratorBuilder signerInfoBuilder = new JcaSignerInfoGeneratorBuilder(new BcDigestCalculatorProvider());
signerInfoBuilder.setSignedAttributeGenerator(new DefaultSignedAttributeTableGenerator());
SignerInfoGenerator signerInfo = signerInfoBuilder.build(signer, signerCert);
generator.addSignerInfoGenerator(signerInfo);
CMSTypedData cmsContent = new CMSProcessableByteArray(CMSObjectIdentifiers.signedData, degenratedSignedDataBytes);
// certificateSet
ScepUtil.addCmsCertSet(generator, cmsCertSet);
return generator.generate(cmsContent, true).toASN1Structure();
} catch (CMSException | CertificateEncodingException | IOException | OperatorCreationException ex) {
throw new MessageEncodingException(ex);
}
}
Aggregations