use of ee.ria.xroad.signer.protocol.dto.CertRequestInfo in project X-Road by nordic-institute.
the class RegenerateCertRequestRequestHandler method handle.
@Override
protected Object handle(RegenerateCertRequest message) throws Exception {
TokenAndKey tokenAndKey = findTokenAndKeyForCsrId(message.getCertRequestId());
if (!TokenManager.isKeyAvailable(tokenAndKey.getKeyId())) {
throw keyNotAvailable(tokenAndKey.getKeyId());
}
if (tokenAndKey.getKey().getUsage() == KeyUsageInfo.AUTHENTICATION && !SoftwareTokenType.ID.equals(tokenAndKey.getTokenId())) {
throw new CodedException(X_INTERNAL_ERROR, "Authentication keys are only supported for software tokens");
}
String csrId = message.getCertRequestId();
CertRequestInfo certRequestInfo = TokenManager.getCertRequestInfo(csrId);
if (certRequestInfo == null) {
throw CodedException.tr(X_CSR_NOT_FOUND, "csr_not_found", "Certificate request '%s' not found", csrId);
}
String subjectName = certRequestInfo.getSubjectName();
PKCS10CertificationRequest generatedRequest = buildSignedCertRequest(tokenAndKey, subjectName);
return new RegenerateCertRequestResponse(message.getCertRequestId(), convert(generatedRequest, message.getFormat()), message.getFormat(), certRequestInfo.getMemberId(), tokenAndKey.getKey().getUsage());
}
use of ee.ria.xroad.signer.protocol.dto.CertRequestInfo in project X-Road by nordic-institute.
the class TokenCertificateServiceTest method setup.
@Before
public void setup() throws Exception {
when(clientService.getLocalClientMemberIds()).thenReturn(new HashSet<>(Collections.singletonList(client)));
DnFieldDescription editableField = new DnFieldDescriptionImpl("O", "x", "default").setReadOnly(false);
when(certificateAuthorityService.getCertificateProfile(any(), any(), any(), anyBoolean())).thenReturn(new DnFieldTestCertificateProfileInfo(editableField, true));
// need lots of mocking
// construct some test keys, with csrs and certs
// make used finders return data from these items:
// keyService.getKey, signerProxyFacade.getKeyIdForCertHash,
// signerProxyFacade.getCertForHash
// mock delete-operations (deleteCertificate, deleteCsr)
CertRequestInfo goodCsr = new CertRequestInfo(GOOD_CSR_ID, null, null);
CertRequestInfo authCsr = new CertRequestInfo(GOOD_AUTH_CSR_ID, null, null);
CertRequestInfo signCsr = new CertRequestInfo(GOOD_SIGN_CSR_ID, null, null);
CertRequestInfo signerExceptionCsr = new CertRequestInfo(SIGNER_EXCEPTION_CSR_ID, null, null);
KeyInfo authKey = new TokenTestUtils.KeyInfoBuilder().id(AUTH_KEY_ID).keyUsageInfo(KeyUsageInfo.AUTHENTICATION).csr(authCsr).cert(authCert).build();
KeyInfo goodKey = new TokenTestUtils.KeyInfoBuilder().id(GOOD_KEY_ID).csr(goodCsr).csr(signerExceptionCsr).build();
KeyInfo signKey = new TokenTestUtils.KeyInfoBuilder().id(SIGN_KEY_ID).keyUsageInfo(KeyUsageInfo.SIGNING).csr(signCsr).cert(signCert).build();
TokenInfo tokenInfo = new TokenTestUtils.TokenInfoBuilder().friendlyName("fubar").build();
tokenInfo.getKeyInfo().add(authKey);
tokenInfo.getKeyInfo().add(signKey);
tokenInfo.getKeyInfo().add(goodKey);
mockGetTokenAndKeyIdForCertificateHash(authKey, goodKey, signKey, tokenInfo);
mockGetTokenAndKeyIdForCertificateRequestId(authKey, goodKey, signKey, tokenInfo);
mockGetKey(authKey, goodKey, signKey);
mockGetKeyIdForCertHash();
mockGetCertForHash();
mockDeleteCert();
mockDeleteCertRequest();
mockGetTokenForKeyId(tokenInfo);
// activate / deactivate
doAnswer(invocation -> {
Object[] args = invocation.getArguments();
String hash = (String) args[0];
if (MISSING_CERTIFICATE_HASH.equals(hash)) {
throw new CodedException(TokenCertificateService.CERT_NOT_FOUND_FAULT_CODE);
}
return null;
}).when(signerProxyFacade).deactivateCert(any());
doAnswer(invocation -> {
Object[] args = invocation.getArguments();
String hash = (String) args[0];
if (MISSING_CERTIFICATE_HASH.equals(hash)) {
throw new CodedException(TokenCertificateService.CERT_NOT_FOUND_FAULT_CODE);
}
return null;
}).when(signerProxyFacade).activateCert(eq("certID"));
// by default all actions are possible
doReturn(EnumSet.allOf(PossibleActionEnum.class)).when(possibleActionsRuleEngine).getPossibleTokenActions(any());
doReturn(EnumSet.allOf(PossibleActionEnum.class)).when(possibleActionsRuleEngine).getPossibleKeyActions(any(), any());
doReturn(EnumSet.allOf(PossibleActionEnum.class)).when(possibleActionsRuleEngine).getPossibleCertificateActions(any(), any(), any());
doReturn(EnumSet.allOf(PossibleActionEnum.class)).when(possibleActionsRuleEngine).getPossibleCsrActions(any());
}
Aggregations