Search in sources :

Example 31 with TokenInfo

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());
}
Also used : KeyInfo(ee.ria.xroad.signer.protocol.dto.KeyInfo) TokenTestUtils(org.niis.xroad.securityserver.restapi.util.TokenTestUtils) TokenInfo(ee.ria.xroad.signer.protocol.dto.TokenInfo) Test(org.junit.Test)

Example 32 with TokenInfo

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");
}
Also used : KeyInfo(ee.ria.xroad.signer.protocol.dto.KeyInfo) AuthKeyInfo(ee.ria.xroad.signer.protocol.dto.AuthKeyInfo) Utils.printKeyInfo(ee.ria.xroad.signer.console.Utils.printKeyInfo) ListTokens(ee.ria.xroad.signer.protocol.message.ListTokens) CertificateInfo(ee.ria.xroad.signer.protocol.dto.CertificateInfo) TokenInfo(ee.ria.xroad.signer.protocol.dto.TokenInfo) Utils.printTokenInfo(ee.ria.xroad.signer.console.Utils.printTokenInfo) X509Certificate(java.security.cert.X509Certificate) Command(asg.cliche.Command)

Example 33 with TokenInfo

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();
    });
}
Also used : ListTokens(ee.ria.xroad.signer.protocol.message.ListTokens) TokenInfo(ee.ria.xroad.signer.protocol.dto.TokenInfo) Utils.printTokenInfo(ee.ria.xroad.signer.console.Utils.printTokenInfo) Command(asg.cliche.Command)

Example 34 with TokenInfo

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));
}
Also used : ListTokens(ee.ria.xroad.signer.protocol.message.ListTokens) TokenInfo(ee.ria.xroad.signer.protocol.dto.TokenInfo) Utils.printTokenInfo(ee.ria.xroad.signer.console.Utils.printTokenInfo) Command(asg.cliche.Command)

Example 35 with TokenInfo

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());
}
Also used : AuthKeyInfo(ee.ria.xroad.signer.protocol.dto.AuthKeyInfo) KeyInfo(ee.ria.xroad.signer.protocol.dto.KeyInfo) CertificateInfo(ee.ria.xroad.signer.protocol.dto.CertificateInfo) TokenInfo(ee.ria.xroad.signer.protocol.dto.TokenInfo)

Aggregations

TokenInfo (ee.ria.xroad.signer.protocol.dto.TokenInfo)52 KeyInfo (ee.ria.xroad.signer.protocol.dto.KeyInfo)33 Test (org.junit.Test)19 TokenTestUtils (org.niis.xroad.securityserver.restapi.util.TokenTestUtils)16 CodedException (ee.ria.xroad.common.CodedException)14 CertificateInfo (ee.ria.xroad.signer.protocol.dto.CertificateInfo)13 SignerNotReachableException (org.niis.xroad.restapi.service.SignerNotReachableException)11 TokenInfoAndKeyId (ee.ria.xroad.signer.protocol.dto.TokenInfoAndKeyId)9 ServiceException (org.niis.xroad.restapi.service.ServiceException)8 Before (org.junit.Before)7 CertRequestInfo (ee.ria.xroad.signer.protocol.dto.CertRequestInfo)6 CertificateTestUtils (org.niis.xroad.securityserver.restapi.util.CertificateTestUtils)6 ClientId (ee.ria.xroad.common.identifier.ClientId)5 HashMap (java.util.HashMap)5 DeviationAwareRuntimeException (org.niis.xroad.restapi.exceptions.DeviationAwareRuntimeException)5 Command (asg.cliche.Command)4 Utils.printTokenInfo (ee.ria.xroad.signer.console.Utils.printTokenInfo)4 KeyUsageInfo (ee.ria.xroad.signer.protocol.dto.KeyUsageInfo)4 ListTokens (ee.ria.xroad.signer.protocol.message.ListTokens)4 ArrayList (java.util.ArrayList)4