use of ee.ria.xroad.common.conf.globalconf.AuthKey in project X-Road by nordic-institute.
the class HealthChecksTest method createMockProviderWithOcspStatus.
private static KeyConfProvider createMockProviderWithOcspStatus(int status) throws Exception {
X509Certificate mockCertificate = mock(X509Certificate.class);
when(mockCertificate.getSubjectX500Principal()).thenReturn(new X500Principal("CN=Duke, OU=JavaSoft, O=Sun Microsystems, C=US"));
CertChain mockCertChain = mock(CertChain.class);
when(mockCertChain.getEndEntityCert()).thenReturn(mockCertificate);
AuthKey authKey = new AuthKey(mockCertChain, null);
KeyConfProvider mockKeyConfProvider = mock(KeyConfProvider.class);
when(mockKeyConfProvider.getAuthKey()).thenReturn(authKey);
OCSPResp mockResponse = mock(OCSPResp.class);
when(mockResponse.getStatus()).thenReturn(status);
when(mockKeyConfProvider.getOcspResponse((X509Certificate) notNull())).thenReturn(mockResponse);
return mockKeyConfProvider;
}
use of ee.ria.xroad.common.conf.globalconf.AuthKey in project X-Road by nordic-institute.
the class HealthChecksTest method checkAuthKeyOcspStatusShouldFailWhenEndEntityCertNotAvailable.
@Test
public void checkAuthKeyOcspStatusShouldFailWhenEndEntityCertNotAvailable() {
// prepare
CertChain mockCertChain = mock(CertChain.class);
when(mockCertChain.getEndEntityCert()).thenReturn(null);
AuthKey authKey = new AuthKey(mockCertChain, null);
KeyConfProvider mockKeyConfProvider = mock(KeyConfProvider.class);
when(mockKeyConfProvider.getAuthKey()).thenReturn(authKey);
KeyConf.reload(mockKeyConfProvider);
// execute
HealthCheckProvider testedProvider = HealthChecks.checkAuthKeyOcspStatus();
HealthCheckResult checkedResult = testedProvider.get();
// verify
assertTrue("health check result should be a failure", !checkedResult.isOk());
assertThat(checkedResult.getErrorMessage(), containsString("No end entity certificate available"));
}
use of ee.ria.xroad.common.conf.globalconf.AuthKey in project X-Road by nordic-institute.
the class HealthChecksTest method checkAuthKeyOcspStatusShouldFailWhenCertChainNotAvailable.
@Test
public void checkAuthKeyOcspStatusShouldFailWhenCertChainNotAvailable() {
// prepare
AuthKey authKey = new AuthKey(null, null);
KeyConfProvider mockKeyConfProvider = mock(KeyConfProvider.class);
when(mockKeyConfProvider.getAuthKey()).thenReturn(authKey);
KeyConf.reload(mockKeyConfProvider);
// execute
HealthCheckProvider testedProvider = HealthChecks.checkAuthKeyOcspStatus();
HealthCheckResult checkedResult = testedProvider.get();
// verify
assertTrue("health check result should be a failure", !checkedResult.isOk());
assertThat(checkedResult.getErrorMessage(), containsString("No certificate chain available"));
}
use of ee.ria.xroad.common.conf.globalconf.AuthKey in project X-Road by nordic-institute.
the class ClientRestMessageHandler method verifyCanProcess.
private void verifyCanProcess() {
GlobalConf.verifyValidity();
if (!SystemProperties.isSslEnabled()) {
return;
}
AuthKey authKey = KeyConf.getAuthKey();
if (authKey.getCertChain() == null) {
throw new CodedException(X_SSL_AUTH_FAILED, "Security server has no valid authentication certificate");
}
}
use of ee.ria.xroad.common.conf.globalconf.AuthKey in project X-Road by nordic-institute.
the class ClientMessageHandler method verifyCanProcess.
private void verifyCanProcess(HttpServletRequest request) {
if (!isPostRequest(request)) {
throw new ClientException(X_INVALID_HTTP_METHOD, "Must use POST request method instead of %s", request.getMethod());
}
GlobalConf.verifyValidity();
if (!SystemProperties.isSslEnabled()) {
return;
}
AuthKey authKey = KeyConf.getAuthKey();
if (authKey.getCertChain() == null) {
throw new CodedException(X_SSL_AUTH_FAILED, "Security server has no valid authentication certificate");
}
}
Aggregations