Search in sources :

Example 1 with Token

use of ee.ria.xroad.signer.model.Token in project X-Road by nordic-institute.

the class MergeOntoFileTokenStrategyTest method mergeShouldMergeTokensInLists.

/**
 * @see MergeOntoFileTokensStrategy#merge(List, List)
 */
@Test
public void mergeShouldMergeTokensInLists() {
    final String tokenId = "1124";
    Token fileToken = new Token(SoftwareModuleType.TYPE, tokenId, CryptoUtils.CKM_RSA_PKCS_NAME);
    fileToken.setActive(false);
    Token memoryToken = new Token(SoftwareModuleType.TYPE, tokenId, CryptoUtils.CKM_RSA_PKCS_NAME);
    memoryToken.setActive(true);
    MergeResult result = testedStrategy.merge(Collections.singletonList(fileToken), Collections.singletonList(memoryToken));
    assertTrue("Token was not merged, isActive was not changed", result.getResultTokens().get(0).isActive());
}
Also used : MergeResult(ee.ria.xroad.signer.tokenmanager.merge.TokenMergeStrategy.MergeResult) Token(ee.ria.xroad.signer.model.Token) Test(org.junit.Test)

Example 2 with Token

use of ee.ria.xroad.signer.model.Token in project X-Road by nordic-institute.

the class MergeOntoFileTokenStrategyTest method mergeTokenShouldMergeKeysInTokens.

/**
 * @see MergeOntoFileTokensStrategy#mergeToken(Token, Token)
 */
@Test
public void mergeTokenShouldMergeKeysInTokens() {
    final String tokenId = "1123";
    Token fileToken = new Token(SoftwareModuleType.TYPE, tokenId, CryptoUtils.CKM_RSA_PKCS_NAME);
    Token memoryToken = new Token(SoftwareModuleType.TYPE, tokenId, CryptoUtils.CKM_RSA_PKCS_NAME);
    final String keyId = "1551";
    Key memoryKey = createKey(keyId, 2);
    memoryKey.setAvailable(true);
    memoryToken.addKey(memoryKey);
    Key fileKey = createKey(keyId, 3);
    fileKey.setAvailable(false);
    fileToken.addKey(fileKey);
    testedStrategy.mergeToken(fileToken, memoryToken);
    assertTrue("key availability in token was not merged", fileKey.isAvailable());
}
Also used : Token(ee.ria.xroad.signer.model.Token) Key(ee.ria.xroad.signer.model.Key) TestKeyHelper.createKey(ee.ria.xroad.signer.tokenmanager.merge.MergeOntoFileTokenStrategyTest.TestKeyHelper.createKey) Test(org.junit.Test)

Example 3 with Token

use of ee.ria.xroad.signer.model.Token in project X-Road by nordic-institute.

the class TokenManager method setTokenAvailable.

/**
 * Sets the token available.
 *
 * @param tokenType the token type
 * @param available availability flag
 */
public static synchronized void setTokenAvailable(TokenType tokenType, boolean available) {
    String tokenId = tokenType.getId();
    log.trace("setTokenAvailable({}, {})", tokenId, available);
    Token token = findToken(tokenId);
    token.setAvailable(available);
    token.setModuleId(tokenType.getModuleType());
}
Also used : Token(ee.ria.xroad.signer.model.Token)

Example 4 with Token

use of ee.ria.xroad.signer.model.Token in project X-Road by nordic-institute.

the class TokenManager method merge.

/**
 * Merge the in-memory configuration and the on-disk configuration if the configuration on
 * disk has changed.
 * @param listener
 */
public static void merge(TokenMergeAddedCertificatesListener listener) {
    if (TokenConf.getInstance().hasChanged()) {
        log.debug("The key configuration on disk has changed, merging changes.");
        List<Token> fileTokens;
        try {
            fileTokens = TokenConf.getInstance().retrieveTokensFromConf();
        } catch (TokenConf.TokenConfException e) {
            log.error("Failed to load the new key configuration from disk.", e);
            return;
        }
        MergeResult result;
        synchronized (TokenManager.class) {
            result = mergeStrategy.merge(fileTokens, currentTokens);
            currentTokens = result.getResultTokens();
        }
        if (listener != null) {
            listener.mergeDone(result.getAddedCertificates());
        }
        log.info("Merged new key configuration.");
    } else {
        log.debug("The key configuration on disk has not changed, skipping merge.");
    }
}
Also used : MergeResult(ee.ria.xroad.signer.tokenmanager.merge.TokenMergeStrategy.MergeResult) Token(ee.ria.xroad.signer.model.Token)

Example 5 with Token

use of ee.ria.xroad.signer.model.Token in project X-Road by nordic-institute.

the class MergeOntoFileTokenStrategyTest method mergeShouldAddMissingTokens.

/**
 * @see MergeOntoFileTokensStrategy#merge(List, List)
 */
@Test
public void mergeShouldAddMissingTokens() {
    Token fileToken1 = new Token(SoftwareModuleType.TYPE, "1", CryptoUtils.CKM_RSA_PKCS_NAME);
    Token fileToken2 = new Token(SoftwareModuleType.TYPE, "2", CryptoUtils.CKM_RSA_PKCS_NAME);
    Token memoryToken1 = new Token(SoftwareModuleType.TYPE, "1", CryptoUtils.CKM_RSA_PKCS_NAME);
    Token memoryToken2 = new Token(SoftwareModuleType.TYPE, "2", CryptoUtils.CKM_RSA_PKCS_NAME);
    Token memoryToken3 = new Token(SoftwareModuleType.TYPE, "3", CryptoUtils.CKM_RSA_PKCS_NAME);
    List<Token> fileList = Arrays.asList(fileToken1, fileToken2);
    List<Token> memoryList = Arrays.asList(memoryToken1, memoryToken2, memoryToken3);
    final int memListSize = memoryList.size();
    MergeResult result = testedStrategy.merge(fileList, memoryList);
    List<Token> mergedList = result.getResultTokens();
    assertThat("Missing tokens were not added", mergedList.size(), is(memListSize));
    assertThat("Missing tokens were not added", mergedList, hasItems(fileToken1, fileToken2, memoryToken3));
}
Also used : MergeResult(ee.ria.xroad.signer.tokenmanager.merge.TokenMergeStrategy.MergeResult) Token(ee.ria.xroad.signer.model.Token) Test(org.junit.Test)

Aggregations

Token (ee.ria.xroad.signer.model.Token)12 Test (org.junit.Test)6 Key (ee.ria.xroad.signer.model.Key)4 MergeResult (ee.ria.xroad.signer.tokenmanager.merge.TokenMergeStrategy.MergeResult)3 TestKeyHelper.createKey (ee.ria.xroad.signer.tokenmanager.merge.MergeOntoFileTokenStrategyTest.TestKeyHelper.createKey)2 TokenAndKey (ee.ria.xroad.signer.util.TokenAndKey)2 KeyType (ee.ria.xroad.common.conf.keyconf.KeyType)1 Cert (ee.ria.xroad.signer.model.Cert)1 KeyInfo (ee.ria.xroad.signer.protocol.dto.KeyInfo)1 KeyUsageInfo (ee.ria.xroad.signer.protocol.dto.KeyUsageInfo)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1