@Test(expected = DSSException.class) // TODO check root cause SSLHandshakeException public void testWrongTrustStore() throws GeneralSecurityException, IOException { CommonsDataLoader dataLoader = new CommonsDataLoader(); dataLoader.setSslTruststorePath(WRONG_KS_PATH); dataLoader.setSslTruststoreType(KS_TYPE); dataLoader.setSslTruststorePassword("azert"); dataLoader.setSslKeystorePath(WRONG_KS_PATH); dataLoader.setSslKeystoreType(KS_TYPE); dataLoader.setSslKeystorePassword("azert"); byte[] binaries = dataLoader.get(URL); assertNotNull(binaries); assertTrue(binaries.length > 0); }
@Test public void testTrustStore() throws GeneralSecurityException, IOException { CommonsDataLoader dataLoader = new CommonsDataLoader(); dataLoader.setSslTruststorePath(CORRECT_KS_PATH); dataLoader.setSslTruststoreType(KS_TYPE); dataLoader.setSslTruststorePassword("azert"); byte[] binaries = dataLoader.get(URL); assertNotNull(binaries); assertTrue(binaries.length > 0); }
/** * @param dataLoader data loader * @param configuration configuration */ public static void decorateWithSslSettings(CommonsDataLoader dataLoader, Configuration configuration) { if (configuration.isSslConfigurationEnabled()) { logger.debug("Configuring SSL"); dataLoader.setSslKeystorePath(configuration.getSslKeystorePath()); dataLoader.setSslTruststorePath(configuration.getSslTruststorePath()); if (configuration.getSslKeystoreType() != null) { dataLoader.setSslKeystoreType(configuration.getSslKeystoreType()); } if (configuration.getSslKeystorePassword() != null) { dataLoader.setSslKeystorePassword(configuration.getSslKeystorePassword()); } if (configuration.getSslTruststoreType() != null) { dataLoader.setSslTruststoreType(configuration.getSslTruststoreType()); } if (configuration.getSslTruststorePassword() != null) { dataLoader.setSslTruststorePassword(configuration.getSslTruststorePassword()); } } } }
/** * The default constructor. A {@code CommonsDataLoader is created}. */ public OnlineCRLSource() { dataLoader = new CommonsDataLoader(); LOG.trace("+OnlineCRLSource with the default data loader."); }
@Test public void testDefault() { CommonsDataLoader dataLoader = new CommonsDataLoader(); byte[] binaries = dataLoader.get(URL); assertNotNull(binaries); assertTrue(binaries.length > 0); }
/** * This method is useful only with the cache handling implementation of the * {@code DataLoader}. * * @param url * to access * @param refresh * if true indicates that the cached data should be refreshed * @return {@code byte} array of obtained data */ @Override public byte[] get(final String url, final boolean refresh) { return get(url); }
protected SignedDocumentValidator createValidatorFromDocument(final ValidationDocument validationDocument) { final DSSDocument dssDocument = createDssDocument(validationDocument); SignedDocumentValidator validator = SignedDocumentValidator.fromDocument(dssDocument); CommonCertificateVerifier certificateVerifier = new CommonCertificateVerifier(trustedListsCertificateSource, new AlwaysFailingCRLSource(), new AlwaysFailingOCSPSource(), new CommonsDataLoader()); LOGGER.info("Certificate pool size: {}", getCertificatePoolSize(certificateVerifier)); validator.setCertificateVerifier(certificateVerifier); validator.setValidationLevel(VALIDATION_LEVEL); return validator; }
@Override public DataAndUrl get(final List<String> urlStrings) { final int numberOfUrls = urlStrings.size(); int ii = 0; for (final String urlString : urlStrings) { try { ii++; final byte[] bytes = get(urlString); if (bytes == null) { continue; } return new DataAndUrl(bytes, urlString); } catch (Exception e) { if (ii == numberOfUrls) { if (e instanceof DSSException) { throw (DSSException) e; } throw new DSSException(e); } LOG.warn("Impossible to obtain data using '{}' : {}", urlString, e.getMessage()); } } return null; }
private DataLoader createDataLoader() { if (Protocol.isHttpUrl(this.configuration.getTslLocation())) { CachingDataLoader dataLoader = new CachingDataLoader(this.configuration); dataLoader.setTimeoutConnection(this.configuration.getConnectionTimeout()); dataLoader.setTimeoutSocket(this.configuration.getSocketTimeout()); dataLoader.setCacheExpirationTime(this.configuration.getTslCacheExpirationTime()); dataLoader.setFileCacheDirectory(this.fileCacheDirectory); logger.debug("Using file cache directory for storing TSL: {}", this.fileCacheDirectory); return dataLoader; } else { return new CommonsDataLoader(); } }
@Test public void ldapTest1() { String url = "ldap://x500.gov.si/ou=sigen-ca,o=state-institutions,c=si?certificateRevocationList?base"; assertTrue(Utils.isArrayNotEmpty(dataLoader.get(url))); }
@Test public void testWithCommonDataLoader() { OnlineTSPSource tspSource = new OnlineTSPSource(TSA_URL); tspSource.setDataLoader(new CommonsDataLoader()); byte[] digest = DSSUtils.digest(DigestAlgorithm.SHA1, "Hello world".getBytes()); TimeStampToken timeStampResponse = tspSource.getTimeStampResponse(DigestAlgorithm.SHA1, digest); assertNotNull(timeStampResponse); }
@Test public void ldapTest3() { String url = "ldap://acldap.nlb.si/o=ACNLB,c=SI?certificateRevocationList"; assertTrue(Utils.isArrayNotEmpty(dataLoader.get(url))); }
@Before public void setUp() throws Exception { cacheDirectory = testFolder.newFolder("dss-file-cache"); dataLoader = new FileCacheDataLoader(); dataLoader.setDataLoader(new CommonsDataLoader()); dataLoader.setFileCacheDirectory(cacheDirectory); }
@Test public void ldapTest2() { String url = "ldap://postarca.posta.si/ou=POSTArCA,o=POSTA,c=SI?certificateRevocationList"; assertTrue(Utils.isArrayNotEmpty(dataLoader.get(url))); }
private void initTslValidationJob() { tslValidationJob = tslValidationJobFactory.createValidationJob(); tslValidationJob.setDataLoader(new CommonsDataLoader()); TSLRepository tslRepository = new TSLRepository(); tslRepository.setTrustedListsCertificateSource(trustedListSource); tslValidationJob.setRepository(tslRepository); tslValidationJob.setLotlUrl(configurationProperties.getUrl()); tslValidationJob.setLotlCode(configurationProperties.getCode()); tslValidationJob.setOjContentKeyStore(keyStoreCertificateSource); tslValidationJob.setOjUrl(configurationProperties.getOjUrl()); tslValidationJob.setLotlRootSchemeInfoUri(configurationProperties.getLotlRootSchemeInfoUri()); tslValidationJob.setFilterTerritories(configurationProperties.getTrustedTerritories()); tslValidationJob.setCheckLOTLSignature(true); tslValidationJob.setCheckTSLSignatures(true); }
@Test public void testGet() { byte[] bytesArray = dataLoader.get(URL_TO_LOAD); NativeHTTPDataLoader dataLoader2 = new NativeHTTPDataLoader(); byte[] bytesArrays2 = dataLoader2.get(URL_TO_LOAD); assertTrue(Arrays.equals(bytesArray, bytesArrays2)); CertificateToken certificate = DSSUtils.loadCertificate(bytesArray); assertNotNull(certificate); }