use of ee.ria.xroad.signer.protocol.dto.TokenInfo in project X-Road by nordic-institute.
the class ImportCertRequestHandler method importCertificate.
private String importCertificate(X509Certificate cert, String initialStatus, ClientId memberId) throws Exception {
String publicKey = encodeBase64(cert.getPublicKey().getEncoded());
// Find the key based on the public key of the cert
for (TokenInfo tokenInfo : TokenManager.listTokens()) {
for (KeyInfo keyInfo : tokenInfo.getKeyInfo()) {
if (matchesPublicKeyOrExistingCert(publicKey, cert, keyInfo)) {
String keyId = keyInfo.getId();
log.debug("Importing certificate under key '{}'", keyId);
importCertificateToKey(keyInfo, cert, initialStatus, memberId);
return keyId;
}
}
}
throw CodedException.tr(X_KEY_NOT_FOUND, "key_not_found_for_certificate", "Could not find key that has public key that matches the " + "public key of certificate");
}
use of ee.ria.xroad.signer.protocol.dto.TokenInfo in project X-Road by nordic-institute.
the class CertificateInfoSensorTest method createTestTokenInfo.
private TokenInfo createTestTokenInfo(KeyInfo... keyInfoParams) {
List<KeyInfo> keyInfos = new ArrayList<>();
for (KeyInfo info : keyInfoParams) {
keyInfos.add(info);
}
Map<String, String> tokenInfos = new HashMap<>();
return new TokenInfo("type", "friendlyName", "id", false, false, false, "serialNumber", "label", -1, TokenStatusInfo.OK, Collections.unmodifiableList(keyInfos), Collections.unmodifiableMap(tokenInfos));
}
use of ee.ria.xroad.signer.protocol.dto.TokenInfo in project X-Road by nordic-institute.
the class GlobalConfCheckerTest method setup.
@Before
public void setup() throws Exception {
doAnswer(answer -> null).when(globalConfFacade).verifyValidity();
doAnswer(answer -> null).when(globalConfFacade).reload();
List<MemberInfo> globalMemberInfos = new ArrayList<>(Arrays.asList(TestUtils.getMemberInfo(TestUtils.INSTANCE_FI, TestUtils.MEMBER_CLASS_GOV, TestUtils.MEMBER_CODE_M1, null), TestUtils.getMemberInfo(TestUtils.INSTANCE_FI, TestUtils.MEMBER_CLASS_GOV, TestUtils.MEMBER_CODE_M2, null)));
when(globalConfFacade.getMembers(any())).thenReturn(globalMemberInfos);
when(globalConfFacade.getMemberName(any())).thenAnswer(invocation -> {
ClientId clientId = (ClientId) invocation.getArguments()[0];
Optional<MemberInfo> m = globalMemberInfos.stream().filter(g -> g.getId().equals(clientId)).findFirst();
if (m.isPresent()) {
return m.get().getName();
} else {
return null;
}
});
when(globalConfFacade.getInstanceIdentifier()).thenReturn(TestUtils.INSTANCE_FI);
when(managementRequestSenderService.sendClientRegisterRequest(any())).thenReturn(1);
KeyInfo ownerSignKey = new TokenTestUtils.KeyInfoBuilder().id(KEY_OWNER_ID).keyUsageInfo(KeyUsageInfo.SIGNING).csr(new CertificateTestUtils.CertRequestInfoBuilder().clientId(OWNER_MEMBER).id(CERT_OWNER_HASH).build()).build();
KeyInfo newOwnerSignKey = new TokenTestUtils.KeyInfoBuilder().id(KEY_NEW_OWNER_ID).keyUsageInfo(KeyUsageInfo.SIGNING).csr(new CertificateTestUtils.CertRequestInfoBuilder().clientId(NEW_OWNER_MEMBER).id(CERT_NEW_OWNER_HASH).build()).build();
CertificateInfo certificateInfo = new CertificateTestUtils.CertificateInfoBuilder().id(CERT_AUTH_HASH).build();
KeyInfo authKey = new TokenTestUtils.KeyInfoBuilder().id(KEY_AUTH_ID).keyUsageInfo(KeyUsageInfo.AUTHENTICATION).cert(certificateInfo).build();
TokenInfo tokenInfo = new TokenTestUtils.TokenInfoBuilder().friendlyName("fubar").key(ownerSignKey).key(newOwnerSignKey).key(authKey).build();
Map<String, TokenInfo> tokens = new HashMap<>();
tokens.put(tokenInfo.getId(), tokenInfo);
when(signerProxyFacade.getTokens()).thenReturn(new ArrayList<>(tokens.values()));
when(signerProxyFacade.execute(new GetAuthKey(any()))).thenReturn(new AuthKeyInfo(KEY_AUTH_ID, null, null, certificateInfo));
when(globalConfService.getMemberClassesForThisInstance()).thenReturn(new HashSet<>(MEMBER_CLASSES));
}
use of ee.ria.xroad.signer.protocol.dto.TokenInfo in project X-Road by nordic-institute.
the class KeyAndCertificateRequestServiceIntegrationTest method setup.
@Before
public void setup() throws Exception {
TokenInfo token0 = new TokenTestUtils.TokenInfoBuilder().id(SOFTWARE_TOKEN_ID).type(TokenInfo.SOFTWARE_MODULE_TYPE).friendlyName("mock-token0").build();
TokenInfo token1 = new TokenTestUtils.TokenInfoBuilder().id(OTHER_TOKEN_ID).type("mock-type").friendlyName("mock-token1").build();
Map<String, TokenInfo> tokens = new HashMap<>();
tokens.put(token0.getId(), token0);
tokens.put(token1.getId(), token1);
// mock related signer proxy methods
when(signerProxyFacade.getTokens()).thenReturn(new ArrayList<>(tokens.values()));
when(signerProxyFacade.getToken(any())).thenAnswer(invocation -> tokens.get(invocation.getArguments()[0]));
when(signerProxyFacade.generateKey(any(), any())).thenAnswer(invocation -> {
String tokenId = (String) invocation.getArguments()[0];
String label = (String) invocation.getArguments()[1];
// new keys start with usage = null
KeyInfo keyInfo = new TokenTestUtils.KeyInfoBuilder().id(label).keyUsageInfo(null).friendlyName(label).build();
TokenInfo token = tokens.get(tokenId);
token.getKeyInfo().add(keyInfo);
return keyInfo;
});
when(signerProxyFacade.getTokenForKeyId(any())).thenAnswer(invocation -> {
String keyId = (String) invocation.getArguments()[0];
return getTokenWithKey(tokens, keyId);
});
when(signerProxyFacade.generateCertRequest(any(), any(), any(), any(), any())).thenAnswer(invocation -> {
// keyInfo is immutable, so we need some work to replace KeyInfo with
// one that has correct usage
String keyId = (String) invocation.getArguments()[0];
KeyUsageInfo keyUsage = (KeyUsageInfo) invocation.getArguments()[2];
KeyInfo keyInfo = getKey(tokens, keyId);
TokenInfo tokenInfo = getTokenWithKey(tokens, keyId);
KeyInfo copy = new TokenTestUtils.KeyInfoBuilder().keyInfo(keyInfo).keyUsageInfo(keyUsage).build();
tokenInfo.getKeyInfo().remove(keyInfo);
tokenInfo.getKeyInfo().add(copy);
return new SignerProxy.GeneratedCertRequestInfo(null, null, null, null, null);
});
when(globalConfFacade.getApprovedCAs(any())).thenReturn(Arrays.asList(new ApprovedCAInfo(MOCK_CA, false, "ee.ria.xroad.common.certificateprofile.impl.FiVRKCertificateProfileInfoProvider")));
ClientId ownerId = ClientId.create("FI", "GOV", "M1");
SecurityServerId ownerSsId = SecurityServerId.create(ownerId, "TEST-INMEM-SS");
when(currentSecurityServerId.getServerId()).thenReturn(ownerSsId);
}
use of ee.ria.xroad.signer.protocol.dto.TokenInfo in project X-Road by nordic-institute.
the class NotificationServiceTest method getAlertsSoftTokenNotFound.
@Test
public void getAlertsSoftTokenNotFound() {
notificationService.resetBackupRestoreRunningSince();
assertEquals(null, notificationService.getBackupRestoreRunningSince());
doAnswer(answer -> null).when(globalConfFacade).verifyValidity();
TokenInfo tokenInfo = new TokenTestUtils.TokenInfoBuilder().id(SIGN_TOKEN_ID).active(true).build();
List<TokenInfo> allTokens = Collections.singletonList(tokenInfo);
when(tokenService.getAllTokens()).thenReturn(allTokens);
AlertStatus alertStatus = notificationService.getAlerts();
assertEquals(true, alertStatus.getGlobalConfValid());
assertEquals(true, alertStatus.getGlobalConfValidCheckSuccess());
assertEquals(false, alertStatus.getSoftTokenPinEntered());
assertEquals(false, alertStatus.getSoftTokenPinEnteredCheckSuccess());
}
Aggregations