use of ee.ria.xroad.signer.protocol.dto.KeyInfo in project X-Road by nordic-institute.
the class KeyConverterTest method isSavedToConfiguration.
@Test
public void isSavedToConfiguration() throws Exception {
// test different combinations of keys and certs and the logic for isSavedToConfiguration
KeyInfo info = new TokenTestUtils.KeyInfoBuilder().build();
info.getCerts().clear();
info.getCertRequests().clear();
info.getCertRequests().add(createTestCsr());
assertEquals(true, keyConverter.convert(info).getSavedToConfiguration());
info.getCerts().clear();
info.getCertRequests().clear();
assertEquals(false, keyConverter.convert(info).getSavedToConfiguration());
info.getCerts().clear();
info.getCertRequests().clear();
info.getCerts().add(new CertificateTestUtils.CertificateInfoBuilder().savedToConfiguration(false).build());
info.getCerts().add(new CertificateTestUtils.CertificateInfoBuilder().savedToConfiguration(false).build());
assertEquals(false, keyConverter.convert(info).getSavedToConfiguration());
info.getCerts().clear();
info.getCertRequests().clear();
info.getCerts().add(new CertificateTestUtils.CertificateInfoBuilder().savedToConfiguration(false).build());
info.getCerts().add(new CertificateTestUtils.CertificateInfoBuilder().savedToConfiguration(true).build());
assertEquals(true, keyConverter.convert(info).getSavedToConfiguration());
info.getCerts().clear();
info.getCertRequests().clear();
info.getCerts().add(new CertificateTestUtils.CertificateInfoBuilder().savedToConfiguration(true).build());
info.getCerts().add(new CertificateTestUtils.CertificateInfoBuilder().savedToConfiguration(false).build());
assertEquals(true, keyConverter.convert(info).getSavedToConfiguration());
}
use of ee.ria.xroad.signer.protocol.dto.KeyInfo in project X-Road by nordic-institute.
the class OrphanRemovalService method deleteOrphans.
/**
* Deletes orphan keys, certs and csrs for given clientId
* @param clientId
* @throws OrphansNotFoundException if orphans dont exist for this client. Possible reasons
* include also that this client is still alive (not deleted).
* @throws ActionNotPossibleException if delete-cert or delete-csr was not possible action
* @throws GlobalConfOutdatedException
* if global conf is outdated. This prevents key deletion.
*/
public void deleteOrphans(ClientId clientId) throws OrphansNotFoundException, ActionNotPossibleException, GlobalConfOutdatedException {
auditDataHelper.put(clientId);
if (isAlive(clientId) || hasAliveSiblings(clientId)) {
throw new OrphansNotFoundException();
}
Orphans orphans = findOrphans(clientId);
if (orphans.isEmpty()) {
throw new OrphansNotFoundException();
}
try {
// delete the orphans
for (KeyInfo keyInfo : orphans.getKeys()) {
keyService.deleteKeyAndIgnoreWarnings(keyInfo.getId());
}
tokenCertificateService.deleteCertificates(orphans.getCerts());
for (CertRequestInfo certRequestInfo : orphans.getCsrs()) {
tokenCertificateService.deleteCsr(certRequestInfo.getId());
}
} catch (KeyNotFoundException | CsrNotFoundException | CertificateNotFoundException e) {
// we just internally looked up these items, so them not being found is an internal error
throw new RuntimeException(e);
}
}
use of ee.ria.xroad.signer.protocol.dto.KeyInfo in project X-Road by nordic-institute.
the class ConfProxyUtilAddSigningKey method execute.
@Override
final void execute(final CommandLine commandLine) throws Exception {
ensureProxyExists(commandLine);
final ConfProxyProperties conf = loadConf(commandLine);
if (commandLine.hasOption("key-id")) {
String keyId = commandLine.getOptionValue("k");
addSigningKey(conf, keyId);
} else if (commandLine.hasOption("token-id")) {
String tokenId = commandLine.getOptionValue("t");
KeyInfo keyInfo = SignerClient.execute(new GenerateKey(tokenId, "key-" + System.currentTimeMillis()));
System.out.println("Generated key with ID " + keyInfo.getId());
addSigningKey(conf, keyInfo.getId());
} else {
printHelp();
}
}
use of ee.ria.xroad.signer.protocol.dto.KeyInfo in project X-Road by nordic-institute.
the class CertificateAuthoritiesApiControllerTest method setUp.
@Before
public void setUp() throws Exception {
KeyInfo signKeyInfo = new TokenTestUtils.KeyInfoBuilder().id(GOOD_SIGN_KEY_ID).keyUsageInfo(KeyUsageInfo.SIGNING).build();
KeyInfo authKeyInfo = new TokenTestUtils.KeyInfoBuilder().id(GOOD_AUTH_KEY_ID).keyUsageInfo(KeyUsageInfo.AUTHENTICATION).build();
doAnswer(invocation -> {
Object[] args = invocation.getArguments();
String keyId = (String) args[0];
if (keyId.equals(GOOD_AUTH_KEY_ID)) {
return authKeyInfo;
} else if (keyId.equals(GOOD_SIGN_KEY_ID)) {
return signKeyInfo;
} else {
throw new KeyNotFoundException("foo");
}
}).when(keyService).getKey(any());
List<ApprovedCaDto> approvedCAInfos = new ArrayList<>();
approvedCAInfos.add(ApprovedCaDto.builder().name(GENERAL_PURPOSE_CA_NAME).authenticationOnly(false).build());
when(certificateAuthorityService.getCertificateAuthorities(any())).thenReturn(approvedCAInfos);
when(certificateAuthorityService.getCertificateProfile(any(), any(), any(), anyBoolean())).thenReturn(new CertificateProfileInfo() {
@Override
public DnFieldDescription[] getSubjectFields() {
return new DnFieldDescription[0];
}
@Override
public X500Principal createSubjectDn(DnFieldValue[] values) {
return null;
}
@Override
public void validateSubjectField(DnFieldValue field) throws Exception {
}
});
}
use of ee.ria.xroad.signer.protocol.dto.KeyInfo in project X-Road by nordic-institute.
the class TokenCertificatesApiControllerIntegrationTest method setup.
@Before
public void setup() throws Exception {
doAnswer(answer -> "key-id").when(signerProxyFacade).importCert(any(), any(), any());
doAnswer(answer -> null).when(globalConfFacade).verifyValidity();
doAnswer(answer -> TestUtils.INSTANCE_FI).when(globalConfFacade).getInstanceIdentifier();
doAnswer(answer -> TestUtils.getM1Ss1ClientId()).when(globalConfFacade).getSubjectName(any(), any());
CertificateInfo signCertificateInfo = new CertificateInfoBuilder().certificate(getMockCertificate()).certificateStatus("SAVED").build();
CertificateInfo authCertificateInfo = new CertificateInfoBuilder().certificate(getMockAuthCertificate()).certificateStatus("SAVED").build();
CertificateInfo unknownCertificateInfo = new CertificateInfoBuilder().certificate(getMockCertificateWithoutExtensions()).certificateStatus("SAVED").build();
doAnswer(invocation -> {
Object[] args = invocation.getArguments();
String certId = (String) args[0];
if (AUTH_CERT_HASH.equals(certId)) {
return authCertificateInfo;
} else if (UNKNOWN_CERT_HASH.equals(certId)) {
return unknownCertificateInfo;
} else {
return signCertificateInfo;
}
}).when(signerProxyFacade).getCertForHash(any());
doAnswer(answer -> "key-id").when(signerProxyFacade).getKeyIdForCertHash(any());
TokenInfo tokenInfo = new TokenTestUtils.TokenInfoBuilder().build();
KeyInfo keyInfo = new TokenTestUtils.KeyInfoBuilder().id("key-id").build();
tokenInfo.getKeyInfo().add(keyInfo);
doAnswer(answer -> Collections.singletonList(tokenInfo)).when(signerProxyFacade).getTokens();
TokenInfoAndKeyId tokenInfoAndKeyId = new TokenInfoAndKeyId(tokenInfo, keyInfo.getId());
doAnswer(answer -> tokenInfoAndKeyId).when(signerProxyFacade).getTokenAndKeyIdForCertRequestId(any());
doAnswer(answer -> tokenInfoAndKeyId).when(signerProxyFacade).getTokenAndKeyIdForCertHash(any());
// by default all actions are possible
doReturn(EnumSet.allOf(PossibleActionEnum.class)).when(possibleActionsRuleEngine).getPossibleCertificateActions(any(), any(), any());
}
Aggregations