class CvcTlsCheck {

  public CvcTlsCheckResult check()
  {
    CoreConfigurationDto config = PoseidasConfigurator.getInstance().getCurrentConfig();

    CvcTlsCheckResult resultHolder = new CvcTlsCheckResult();
    Optional<X509Certificate> certificate = getOwnTlsCertificate(config.getServerUrl());

    // Test TLS Certificates
    if (certificate.isPresent())
    {
      resultHolder.setServerTlsValid(testTlsValidity(certificate.get()));
    }
    else
    {
      log.warn("TLS certificate not found for url {} ", config.getServerUrl());
    }

    // Check CVCs
    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)
      {
        // happens if no cvc in terminalpermission
      }
      resultHolder.getProviderCvcChecks().put(sp.getEntityID(), cvcResults);
    }
    return resultHolder;
  }

}