use of ee.ria.xroad.signer.protocol.dto.TokenInfo 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.TokenInfo 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.TokenInfo in project X-Road by nordic-institute.
the class SignerCLI method listCerts.
/**
* Lists all certs on all keys on all tokens.
*
* @throws Exception if an error occurs
*/
@Command(description = "Lists all certs on all keys on all tokens")
public void listCerts() throws Exception {
List<TokenInfo> tokens = SignerClient.execute(new ListTokens());
tokens.forEach(t -> {
printTokenInfo(t, verbose);
if (verbose) {
System.out.println("Keys: ");
}
t.getKeyInfo().forEach(k -> {
printKeyInfo(k, verbose, "\t");
if (verbose) {
System.out.println("\tCerts: ");
}
printCertInfo(k, verbose, "\t\t");
});
System.out.println();
});
}
use of ee.ria.xroad.signer.protocol.dto.TokenInfo in project X-Road by nordic-institute.
the class SignerCLI method listTokens.
/**
* Lists all tokens.
*
* @throws Exception if an error occurs
*/
@Command(description = "Lists all tokens")
public void listTokens() throws Exception {
List<TokenInfo> tokens = SignerClient.execute(new ListTokens());
tokens.forEach(t -> printTokenInfo(t, verbose));
}
use of ee.ria.xroad.signer.protocol.dto.TokenInfo 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