use of ee.ria.xroad.signer.protocol.dto.CertificateInfo in project X-Road by nordic-institute.
the class TokenCertificateConverterTest method convert.
@Test
public void convert() throws Exception {
CertificateInfo certificateInfo = new CertificateTestUtils.CertificateInfoBuilder().build();
TokenCertificate certificate = tokenCertificateConverter.convert(certificateInfo);
assertEquals(true, certificate.getActive());
assertEquals("N/A", certificate.getCertificateDetails().getSubjectCommonName());
assertEquals(2038, certificate.getCertificateDetails().getNotAfter().getYear());
assertEquals(CertificateOcspStatus.OCSP_RESPONSE_GOOD, certificate.getOcspStatus());
assertEquals("a:b:c", certificate.getOwnerId());
assertEquals(true, certificate.getSavedToConfiguration());
assertEquals(org.niis.xroad.securityserver.restapi.openapi.model.CertificateStatus.REGISTERED, certificate.getStatus());
}
use of ee.ria.xroad.signer.protocol.dto.CertificateInfo in project X-Road by nordic-institute.
the class TokenCertificateConverterTest method handleOcspResponses.
@Test
public void handleOcspResponses() throws Exception {
// test bot expired and non-expired certs
int currentYear = LocalDate.now().getYear();
if (currentYear < 2014 || currentYear > 2037) {
fail("test data (used certificates) only works correctly between years 2014 and 2037");
}
// Not After : Sep 14 11:57:16 2013 GMT
X509Certificate cert = TestCertUtil.getCertChainCert("user_1.p12");
CertificateInfo certificateInfo = new CertificateTestUtils.CertificateInfoBuilder().certificate(cert).build();
TokenCertificate certificate = tokenCertificateConverter.convert(certificateInfo);
assertEquals(CertificateOcspStatus.EXPIRED, certificate.getOcspStatus());
// Not After : Jan 1 00:00:00 2038 GMT
cert = CertificateTestUtils.getMockCertificate();
certificateInfo = new CertificateTestUtils.CertificateInfoBuilder().certificate(cert).build();
certificate = tokenCertificateConverter.convert(certificateInfo);
assertEquals(CertificateOcspStatus.OCSP_RESPONSE_GOOD, certificate.getOcspStatus());
RevokedStatus revokedStatus = new RevokedStatus(new Date(), CRLReason.certificateHold);
certificateInfo = new CertificateTestUtils.CertificateInfoBuilder().certificate(cert).ocspStatus(revokedStatus).build();
certificate = tokenCertificateConverter.convert(certificateInfo);
assertEquals(CertificateOcspStatus.OCSP_RESPONSE_SUSPENDED, certificate.getOcspStatus());
revokedStatus = new RevokedStatus(new Date(), CRLReason.unspecified);
certificateInfo = new CertificateTestUtils.CertificateInfoBuilder().certificate(cert).ocspStatus(revokedStatus).build();
certificate = tokenCertificateConverter.convert(certificateInfo);
assertEquals(CertificateOcspStatus.OCSP_RESPONSE_REVOKED, certificate.getOcspStatus());
}
use of ee.ria.xroad.signer.protocol.dto.CertificateInfo in project X-Road by nordic-institute.
the class SignerCLI method showCertificate.
/**
* Show certificate.
*
* @param certId certificate id
* @throws Exception if an error occurs
*/
@Command(description = "Show certificate")
public void showCertificate(@Param(name = "certId", description = "Certificate ID") String certId) throws Exception {
List<TokenInfo> tokens = SignerClient.execute(new ListTokens());
for (TokenInfo token : tokens) {
for (KeyInfo key : token.getKeyInfo()) {
for (CertificateInfo cert : key.getCerts()) {
if (certId.equals(cert.getId())) {
X509Certificate x509 = readCertificate(cert.getCertificateBytes());
System.out.println(x509);
return;
}
}
}
}
System.out.println("Certificate " + certId + " not found");
}
use of ee.ria.xroad.signer.protocol.dto.CertificateInfo in project X-Road by nordic-institute.
the class GetAuthKeyRequestHandler method handle.
@Override
protected Object handle(GetAuthKey message) throws Exception {
log.trace("Selecting authentication key for security server {}", message.getSecurityServer());
validateToken();
for (TokenInfo tokenInfo : TokenManager.listTokens()) {
if (!SoftwareModuleType.TYPE.equals(tokenInfo.getType())) {
log.trace("Ignoring {} module", tokenInfo.getType());
continue;
}
for (KeyInfo keyInfo : tokenInfo.getKeyInfo()) {
if (keyInfo.isForSigning()) {
log.trace("Ignoring {} key {}", keyInfo.getUsage(), keyInfo.getId());
continue;
}
if (!keyInfo.isAvailable()) {
log.trace("Ignoring unavailable key {}", keyInfo.getId());
continue;
}
for (CertificateInfo certInfo : keyInfo.getCerts()) {
if (authCertValid(certInfo, message.getSecurityServer())) {
log.trace("Found suitable authentication key {}", keyInfo.getId());
return authKeyResponse(keyInfo, certInfo);
}
}
}
}
throw CodedException.tr(X_KEY_NOT_FOUND, "auth_key_not_found_for_server", "Could not find active authentication key for " + "security server '%s'", message.getSecurityServer());
}
use of ee.ria.xroad.signer.protocol.dto.CertificateInfo in project X-Road by nordic-institute.
the class ImportCertRequestHandler method importCertificateToKey.
private void importCertificateToKey(KeyInfo keyInfo, X509Certificate cert, String initialStatus, ClientId memberId) throws Exception {
String certHash = calculateCertHexHash(cert.getEncoded());
CertificateInfo existingCert = TokenManager.getCertificateInfoForCertHash(certHash);
if (existingCert != null && existingCert.isSavedToConfiguration()) {
throw CodedException.tr(X_CERT_EXISTS, "cert_exists_under_key", "Certificate already exists under key '%s'", keyInfo.getFriendlyName() == null ? keyInfo.getId() : keyInfo.getFriendlyName());
}
boolean signing = CertUtils.isSigningCert(cert);
boolean authentication = CertUtils.isAuthCert(cert);
if (signing && authentication) {
throw CodedException.tr(X_WRONG_CERT_USAGE, "wrong_cert_usage.both", "Both signing and authentication, " + "only one of them allowed.");
}
KeyUsageInfo keyUsage = getKeyUsage(keyInfo, signing);
validateCertKeyUsage(signing, authentication, keyUsage);
verifyCertChain(cert);
if (existingCert != null) {
TokenManager.removeCert(existingCert.getId());
}
CertificateInfo certType = new CertificateInfo(memberId, !authentication, true, initialStatus, SignerUtil.randomId(), cert.getEncoded(), null);
TokenManager.addCert(keyInfo.getId(), certType);
TokenManager.setKeyUsage(keyInfo.getId(), keyUsage);
updateOcspResponse(cert);
log.info("Imported certificate to key '{}', certificate hash:\n{}", keyInfo.getId(), certHash);
deleteCertRequest(keyInfo.getId(), memberId);
}
Aggregations