@Test void testNonHttpsServer() throws Exception { tempDirectory = JAVA_IO_TMPDIR + "-" + (int)(Math.random() * 1000000); Files.createDirectory(Paths.get(tempDirectory)); log.trace("Generated random temp dir: {}", tempDirectory); Path resourceDirectory = Paths.get("src", "test", "resources"); File source = new File(resourceDirectory + "/POSeIDAS-nonhttps.xml"); File dest = new File(tempDirectory + "/POSeIDAS.xml"); Files.copy(source.toPath(), dest.toPath(), StandardCopyOption.REPLACE_EXISTING); System.setProperty("spring.config.additional-location", Paths.get(tempDirectory).toString()); TerminalPermissionAO terminalPermission = mock(TerminalPermissionAO.class); CvcTlsCheck check = new CvcTlsCheck(terminalPermission); CvcTlsCheckResult result = check.check(); assertFalse(CERTIFICATE_VALID, result.isServerTlsValid()); }
public CvcTlsCheckResult check() { CoreConfigurationDto config = PoseidasConfigurator.getInstance().getCurrentConfig(); CvcTlsCheckResult resultHolder = new CvcTlsCheckResult(); Optional<X509Certificate> certificate = getOwnTlsCertificate(config.getServerUrl()); if (certificate.isPresent()) { resultHolder.setServerTlsValid(testTlsValidity(certificate.get())); } else { log.warn("TLS certificate not found for url {} ", config.getServerUrl()); } for ( ServiceProviderDto sp : config.getServiceProvider().values() ) { CvcCheckResults cvcResults = new CvcCheckResults(); TerminalPermission tp = facade.getTerminalPermission(sp.getEpaConnectorConfiguration().getCVCRefID()); if (tp == null) { resultHolder.getProviderCvcChecks().put(sp.getEntityID(), cvcResults); continue; } try { TerminalData data = tp.getFullCvc(); cvcResults.setCvcPresent(true); cvcResults.setCvcValidity(testCvcExpired(data)); cvcResults.setCvcUrlMatch(testCvcUrlMatch(data, config.getServerUrl())); cvcResults.setCvcTlsMatch(testCvcTlsMatch(data, certificate)); } catch (IllegalArgumentException e) { } resultHolder.getProviderCvcChecks().put(sp.getEntityID(), cvcResults); } return resultHolder; }
CvcTlsCheck { public CvcTlsCheckResult check() { CoreConfigurationDto config = PoseidasConfigurator.getInstance().getCurrentConfig(); CvcTlsCheckResult resultHolder = new CvcTlsCheckResult(); Optional<X509Certificate> certificate = getOwnTlsCertificate(config.getServerUrl()); if (certificate.isPresent()) { resultHolder.setServerTlsValid(testTlsValidity(certificate.get())); } else { log.warn("TLS certificate not found for url {} ", config.getServerUrl()); } for ( ServiceProviderDto sp : config.getServiceProvider().values() ) { CvcCheckResults cvcResults = new CvcCheckResults(); TerminalPermission tp = facade.getTerminalPermission(sp.getEpaConnectorConfiguration().getCVCRefID()); if (tp == null) { resultHolder.getProviderCvcChecks().put(sp.getEntityID(), cvcResults); continue; } try { TerminalData data = tp.getFullCvc(); cvcResults.setCvcPresent(true); cvcResults.setCvcValidity(testCvcExpired(data)); cvcResults.setCvcUrlMatch(testCvcUrlMatch(data, config.getServerUrl())); cvcResults.setCvcTlsMatch(testCvcTlsMatch(data, certificate)); } catch (IllegalArgumentException e) { } resultHolder.getProviderCvcChecks().put(sp.getEntityID(), cvcResults); } return resultHolder; } }
CvcTlsCheck { public CvcTlsCheckResult check() { CoreConfigurationDto config = PoseidasConfigurator.getInstance().getCurrentConfig(); CvcTlsCheckResult resultHolder = new CvcTlsCheckResult(); Optional<X509Certificate> certificate = getOwnTlsCertificate(config.getServerUrl()); if (certificate.isPresent()) { resultHolder.setServerTlsValid(testTlsValidity(certificate.get())); } else { log.warn("TLS certificate not found for url {} ", config.getServerUrl()); } for ( ServiceProviderDto sp : config.getServiceProvider().values() ) { CvcCheckResults cvcResults = new CvcCheckResults(); TerminalPermission tp = facade.getTerminalPermission(sp.getEpaConnectorConfiguration().getCVCRefID()); if (tp == null) { resultHolder.getProviderCvcChecks().put(sp.getEntityID(), cvcResults); continue; } try { TerminalData data = tp.getFullCvc(); cvcResults.setCvcPresent(true); cvcResults.setCvcValidity(testCvcExpired(data)); cvcResults.setCvcUrlMatch(testCvcUrlMatch(data, config.getServerUrl())); cvcResults.setCvcTlsMatch(testCvcTlsMatch(data, certificate)); } catch (IllegalArgumentException e) { } resultHolder.getProviderCvcChecks().put(sp.getEntityID(), cvcResults); } return resultHolder; }  }
CvcTlsCheck { public CvcTlsCheckResult check() { CoreConfigurationDto config = PoseidasConfigurator.getInstance().getCurrentConfig(); CvcTlsCheckResult resultHolder = new CvcTlsCheckResult(); Optional<X509Certificate> certificate = getOwnTlsCertificate(config.getServerUrl()); if (certificate.isPresent()) { resultHolder.setServerTlsValid(testTlsValidity(certificate.get())); } else { log.warn("TLS certificate not found for url {} ", config.getServerUrl()); } for ( ServiceProviderDto sp : config.getServiceProvider().values() ) { CvcCheckResults cvcResults = new CvcCheckResults(); TerminalPermission tp = facade.getTerminalPermission(sp.getEpaConnectorConfiguration().getCVCRefID()); if (tp == null) { resultHolder.getProviderCvcChecks().put(sp.getEntityID(), cvcResults); continue; } try { TerminalData data = tp.getFullCvc(); cvcResults.setCvcPresent(true); cvcResults.setCvcValidity(testCvcExpired(data)); cvcResults.setCvcUrlMatch(testCvcUrlMatch(data, config.getServerUrl())); cvcResults.setCvcTlsMatch(testCvcTlsMatch(data, certificate)); } catch (IllegalArgumentException e) { } resultHolder.getProviderCvcChecks().put(sp.getEntityID(), cvcResults); } return resultHolder; }  CvcTlsCheckResult check(); }
CvcTlsCheck { public CvcTlsCheckResult check() { CoreConfigurationDto config = PoseidasConfigurator.getInstance().getCurrentConfig(); CvcTlsCheckResult resultHolder = new CvcTlsCheckResult(); Optional<X509Certificate> certificate = getOwnTlsCertificate(config.getServerUrl()); if (certificate.isPresent()) { resultHolder.setServerTlsValid(testTlsValidity(certificate.get())); } else { log.warn("TLS certificate not found for url {} ", config.getServerUrl()); } for ( ServiceProviderDto sp : config.getServiceProvider().values() ) { CvcCheckResults cvcResults = new CvcCheckResults(); TerminalPermission tp = facade.getTerminalPermission(sp.getEpaConnectorConfiguration().getCVCRefID()); if (tp == null) { resultHolder.getProviderCvcChecks().put(sp.getEntityID(), cvcResults); continue; } try { TerminalData data = tp.getFullCvc(); cvcResults.setCvcPresent(true); cvcResults.setCvcValidity(testCvcExpired(data)); cvcResults.setCvcUrlMatch(testCvcUrlMatch(data, config.getServerUrl())); cvcResults.setCvcTlsMatch(testCvcTlsMatch(data, certificate)); } catch (IllegalArgumentException e) { } resultHolder.getProviderCvcChecks().put(sp.getEntityID(), cvcResults); } return resultHolder; }  CvcTlsCheckResult check();  }