Search in sources :

Example 36 with KeyInfo

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

Example 37 with KeyInfo

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());
}
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 38 with KeyInfo

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");
}
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 39 with KeyInfo

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());
}
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) GenerateKey(ee.ria.xroad.signer.protocol.message.GenerateKey) IOException(java.io.IOException) CLIException(asg.cliche.CLIException) LinkedHashMap(java.util.LinkedHashMap) Command(asg.cliche.Command)

Example 40 with KeyInfo

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());
}
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

KeyInfo (ee.ria.xroad.signer.protocol.dto.KeyInfo)58 TokenInfo (ee.ria.xroad.signer.protocol.dto.TokenInfo)32 CertificateInfo (ee.ria.xroad.signer.protocol.dto.CertificateInfo)17 Test (org.junit.Test)16 CodedException (ee.ria.xroad.common.CodedException)12 TokenTestUtils (org.niis.xroad.securityserver.restapi.util.TokenTestUtils)12 CertRequestInfo (ee.ria.xroad.signer.protocol.dto.CertRequestInfo)9 TokenInfoAndKeyId (ee.ria.xroad.signer.protocol.dto.TokenInfoAndKeyId)9 Before (org.junit.Before)9 ArrayList (java.util.ArrayList)7 ClientId (ee.ria.xroad.common.identifier.ClientId)6 DeviationAwareRuntimeException (org.niis.xroad.restapi.exceptions.DeviationAwareRuntimeException)6 SignerNotReachableException (org.niis.xroad.restapi.service.SignerNotReachableException)6 KeyUsageInfo (ee.ria.xroad.signer.protocol.dto.KeyUsageInfo)5 HashMap (java.util.HashMap)5 ResourceNotFoundException (org.niis.xroad.restapi.openapi.ResourceNotFoundException)5 AuthKeyInfo (ee.ria.xroad.signer.protocol.dto.AuthKeyInfo)4 TokenManager.getKeyInfo (ee.ria.xroad.signer.tokenmanager.TokenManager.getKeyInfo)4 CertificateTestUtils (org.niis.xroad.securityserver.restapi.util.CertificateTestUtils)4 GeneratedCertRequestInfo (ee.ria.xroad.commonui.SignerProxy.GeneratedCertRequestInfo)3