use of ee.ria.xroad.signer.protocol.dto.KeyInfo in project X-Road by nordic-institute.
the class TokenCertificateSigningRequestConverterTest method convertWithPossibleActions.
@Test
public void convertWithPossibleActions() throws Exception {
CertRequestInfo certRequestInfo = new CertificateTestUtils.CertRequestInfoBuilder().build();
KeyInfo keyInfo = new TokenTestUtils.KeyInfoBuilder().csr(certRequestInfo).build();
TokenInfo tokenInfo = new TokenTestUtils.TokenInfoBuilder().key(keyInfo).build();
TokenCertificateSigningRequest csr = csrConverter.convert(certRequestInfo, keyInfo, tokenInfo);
Collection<PossibleAction> actions = csr.getPossibleActions();
assertTrue(actions.contains(PossibleAction.DELETE));
assertEquals(1, actions.size());
}
use of ee.ria.xroad.signer.protocol.dto.KeyInfo in project X-Road by nordic-institute.
the class TokenConverterTest method isSavedToConfiguration.
@Test
public void isSavedToConfiguration() throws Exception {
// test different combinations of saved and unsaved keys and the logic for isSavedToConfiguration
KeyInfo savedKey = new TokenTestUtils.KeyInfoBuilder().build();
KeyInfo unsavedKey = new TokenTestUtils.KeyInfoBuilder().build();
savedKey.getCerts().clear();
savedKey.getCertRequests().clear();
savedKey.getCertRequests().add(KeyConverterTest.createTestCsr());
unsavedKey.getCerts().clear();
unsavedKey.getCertRequests().clear();
TokenInfo tokenInfo = new TokenTestUtils.TokenInfoBuilder().build();
tokenInfo.getKeyInfo().clear();
assertEquals(false, tokenConverter.convert(tokenInfo).getSavedToConfiguration());
tokenInfo.getKeyInfo().clear();
tokenInfo.getKeyInfo().add(unsavedKey);
assertEquals(false, tokenConverter.convert(tokenInfo).getSavedToConfiguration());
tokenInfo.getKeyInfo().clear();
tokenInfo.getKeyInfo().add(savedKey);
assertEquals(true, tokenConverter.convert(tokenInfo).getSavedToConfiguration());
tokenInfo.getKeyInfo().clear();
tokenInfo.getKeyInfo().add(unsavedKey);
tokenInfo.getKeyInfo().add(savedKey);
tokenInfo.getKeyInfo().add(unsavedKey);
assertEquals(true, tokenConverter.convert(tokenInfo).getSavedToConfiguration());
}
use of ee.ria.xroad.signer.protocol.dto.KeyInfo 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.KeyInfo in project X-Road by nordic-institute.
the class SignerCLI method generateKey.
/**
* Generate key on token.
*
* @param tokenId token id
* @param label label
* @throws Exception if an error occurs
*/
@Command(description = "Generate key on token")
public void generateKey(@Param(name = "tokenId", description = "Token ID") String tokenId, @Param(name = "label", description = "Key label") String label) throws Exception {
Map<String, Object> logData = new LinkedHashMap<>();
logData.put(TOKEN_ID_PARAM, tokenId);
logData.put(KEY_LABEL_PARAM, label);
KeyInfo response;
try {
response = SignerClient.execute(new GenerateKey(tokenId, label));
logData.put(KEY_ID_PARAM, response.getId());
AuditLogger.log(GENERATE_A_KEY_ON_THE_TOKEN_EVENT, XROAD_USER, logData);
} catch (Exception e) {
AuditLogger.log(GENERATE_A_KEY_ON_THE_TOKEN_EVENT, XROAD_USER, e.getMessage(), logData);
throw e;
}
System.out.println(response.getId());
}
use of ee.ria.xroad.signer.protocol.dto.KeyInfo 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());
}
Aggregations