OCSPConfig.java

  1. /*
  2.  * GovWay - A customizable API Gateway
  3.  * https://govway.org
  4.  *
  5.  * Copyright (c) 2005-2025 Link.it srl (https://link.it).
  6.  *
  7.  * This program is free software: you can redistribute it and/or modify
  8.  * it under the terms of the GNU General Public License version 3, as published by
  9.  * the Free Software Foundation.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  18.  *
  19.  */
  20. package org.openspcoop2.utils.certificate.ocsp;

  21. import java.util.ArrayList;
  22. import java.util.List;
  23. import java.util.Properties;

  24. import org.apache.commons.lang.StringUtils;
  25. import org.openspcoop2.utils.UtilsException;
  26. import org.openspcoop2.utils.certificate.ExtendedKeyUsage;
  27. import org.openspcoop2.utils.certificate.KeystoreType;
  28. import org.openspcoop2.utils.random.SecureRandomAlgorithm;
  29. import org.openspcoop2.utils.transport.http.HttpUtilities;
  30. import org.slf4j.Logger;

  31. /**
  32.  * OCSPConfig
  33.  *
  34.  * @author Poli Andrea (apoli@link.it)
  35.  * @author $Author$
  36.  * @version $Rev$, $Date$
  37.  */
  38. public class OCSPConfig {
  39.    
  40.     private String id;

  41.     private String type;
  42.    
  43.     private String label;
  44.    
  45.     private boolean certificateChainVerify = true;
  46.    
  47.     private boolean checkValidity = true;
  48.     private boolean checkCAValidity = true;
  49.    
  50.     private List<CertificateSource> caSource = new ArrayList<>();
  51.     private String alternativeTrustStoreCAPath;
  52.     private String alternativeTrustStoreCAPassword;
  53.     private String alternativeTrustStoreCAType;
  54.     private boolean rejectsCertificateWithoutCA = true;
  55.    
  56.     private String trustStoreSignerPath;
  57.     private String trustStoreSignerPassword;
  58.     private String trustStoreSignerType;
  59.     private String aliasCertificateSigner;
  60.    
  61.     private boolean nonce;
  62.    
  63.     private List<CertificateSource> responderUrlSource = new ArrayList<>();
  64.     private List<String> alternativeResponderUrl;
  65.     private List<String> alternativeResponderUrlCA;
  66.     private boolean rejectsCertificateWithoutResponderUrl = true;
  67.     private boolean rejectsCAWithoutResponderUrl = false;
  68.     private List<OCSPResponseCode> responderBreakStatus = null;
  69.     private List<Integer> responderReturnCodeOk = null;
  70.    
  71.     // fondamentale per prevenire attacchi man in the middle (siamo in http) firmando con un altro certificato rilasciato dalla CA, non adibito a firmare risposte OCSP
  72.     private List<ExtendedKeyUsage> extendedKeyUsageRequired = null;
  73.    
  74.     private int readTimeout = HttpUtilities.HTTP_READ_CONNECTION_TIMEOUT;
  75.     private int connectTimeout = HttpUtilities.HTTP_CONNECTION_TIMEOUT;
  76.        
  77.     private boolean externalResourcesHostnameVerifier = true;
  78.     private boolean externalResourcesTrustAllCerts = false;
  79.     private String externalResourcesTrustStorePath;
  80.     private String externalResourcesTrustStorePassword;
  81.     private String externalResourcesTrustStoreType;
  82.    
  83.     private String externalResourcesKeyStorePath;
  84.     private String externalResourcesKeyStorePassword;
  85.     private String externalResourcesKeyStoreType;
  86.     private String externalResourcesKeyAlias;
  87.     private String externalResourcesKeyPassword;
  88.    
  89.     private String externalResourcesUsername;
  90.     private String externalResourcesPassword;
  91.    
  92.     private String forwardProxyUrl;
  93.     private String forwardProxyHeader;
  94.     private String forwardProxyQueryParameter;
  95.     private boolean forwardProxyBase64;
  96.    
  97.     private SecureRandomAlgorithm secureRandomAlgorithm;
  98.    
  99.     private int responseCheckDateToleranceMilliseconds;

  100.     private boolean crlSigningCertCheck=false;
  101.     private boolean crlCaCheck=false;
  102.     private boolean crl = false;
  103.    
  104.     private List<CertificateSource> crlSource = new ArrayList<>();
  105.     private List<String> crlAlternative = null;
  106.     private boolean rejectsCertificateWithoutCRL = false;
  107.     private boolean rejectsCAWithoutCRL = false;
  108.    
  109.     private List<CertificateSource> crlTrustStoreSource = new ArrayList<>();
  110.     private String alternativeTrustStoreCRLPath;
  111.     private String alternativeTrustStoreCRLPassword;
  112.     private String alternativeTrustStoreCRLType;
  113.                

  114.     public String getId() {
  115.         return this.id;
  116.     }

  117.     public String getType() {
  118.         return this.type;
  119.     }
  120.     public String getLabel() {
  121.         return this.label;
  122.     }
  123.    
  124.     public boolean isCertificateChainVerify() {
  125.         return this.certificateChainVerify;
  126.     }
  127.    
  128.     public boolean isCheckValidity() {
  129.         return this.checkValidity;
  130.     }

  131.     public boolean isCheckCAValidity() {
  132.         return this.checkCAValidity;
  133.     }
  134.    
  135.     public List<CertificateSource> getCaSource() {
  136.         return this.caSource;
  137.     }
  138.     public String getAlternativeTrustStoreCAPath() {
  139.         return this.alternativeTrustStoreCAPath;
  140.     }
  141.     public String getAlternativeTrustStoreCAPassword() {
  142.         return this.alternativeTrustStoreCAPassword;
  143.     }
  144.     public String getAlternativeTrustStoreCAType() {
  145.         return this.alternativeTrustStoreCAType;
  146.     }
  147.     public boolean isRejectsCertificateWithoutCA() {
  148.         return this.rejectsCertificateWithoutCA;
  149.     }
  150.    
  151.     public String getTrustStoreSignerPath() {
  152.         return this.trustStoreSignerPath;
  153.     }
  154.     public String getTrustStoreSignerPassword() {
  155.         return this.trustStoreSignerPassword;
  156.     }
  157.     public String getTrustStoreSignerType() {
  158.         return this.trustStoreSignerType;
  159.     }
  160.     public String getAliasCertificateSigner() {
  161.         return this.aliasCertificateSigner;
  162.     }  
  163.    
  164.     public boolean isNonce() {
  165.         return this.nonce;
  166.     }
  167.    
  168.     public List<CertificateSource> getResponderUrlSource() {
  169.         return this.responderUrlSource;
  170.     }
  171.     public List<String> getAlternativeResponderUrl() {
  172.         return this.alternativeResponderUrl;
  173.     }
  174.     public List<String> getAlternativeResponderUrlCA() {
  175.         return this.alternativeResponderUrlCA;
  176.     }
  177.     public boolean isRejectsCertificateWithoutResponderUrl() {
  178.         return this.rejectsCertificateWithoutResponderUrl;
  179.     }
  180.     public boolean isRejectsCAWithoutResponderUrl() {
  181.         return this.rejectsCAWithoutResponderUrl;
  182.     }
  183.     public List<OCSPResponseCode> getResponderBreakStatus() {
  184.         return this.responderBreakStatus;
  185.     }
  186.     public List<Integer> getResponderReturnCodeOk() {
  187.         return this.responderReturnCodeOk;
  188.     }
  189.    
  190.     public List<ExtendedKeyUsage> getExtendedKeyUsageRequired() {
  191.         return this.extendedKeyUsageRequired;
  192.     }
  193.        
  194.     public int getReadTimeout() {
  195.         return this.readTimeout;
  196.     }
  197.     public int getConnectTimeout() {
  198.         return this.connectTimeout;
  199.     }

  200.     public boolean isExternalResourcesHostnameVerifier() {
  201.         return this.externalResourcesHostnameVerifier;
  202.     }
  203.     public boolean isExternalResourcesTrustAllCerts() {
  204.         return this.externalResourcesTrustAllCerts;
  205.     }
  206.     public String getExternalResourcesTrustStorePath() {
  207.         return this.externalResourcesTrustStorePath;
  208.     }
  209.     public String getExternalResourcesTrustStorePassword() {
  210.         return this.externalResourcesTrustStorePassword;
  211.     }
  212.     public String getExternalResourcesTrustStoreType() {
  213.         return this.externalResourcesTrustStoreType;
  214.     }
  215.    
  216.     public String getExternalResourcesKeyStorePath() {
  217.         return this.externalResourcesKeyStorePath;
  218.     }
  219.     public String getExternalResourcesKeyStorePassword() {
  220.         return this.externalResourcesKeyStorePassword;
  221.     }
  222.     public String getExternalResourcesKeyStoreType() {
  223.         return this.externalResourcesKeyStoreType;
  224.     }
  225.     public String getExternalResourcesKeyAlias() {
  226.         return this.externalResourcesKeyAlias;
  227.     }
  228.     public String getExternalResourcesKeyPassword() {
  229.         return this.externalResourcesKeyPassword;
  230.     }
  231.    
  232.     public String getExternalResourcesUsername() {
  233.         return this.externalResourcesUsername;
  234.     }
  235.     public String getExternalResourcesPassword() {
  236.         return this.externalResourcesPassword;
  237.     }

  238.     public String getForwardProxyUrl() {
  239.         return this.forwardProxyUrl;
  240.     }
  241.     public String getForwardProxyHeader() {
  242.         return this.forwardProxyHeader;
  243.     }
  244.     public String getForwardProxyQueryParameter() {
  245.         return this.forwardProxyQueryParameter;
  246.     }
  247.     public boolean isForwardProxyBase64() {
  248.         return this.forwardProxyBase64;
  249.     }
  250.    
  251.     public SecureRandomAlgorithm getSecureRandomAlgorithm() {
  252.         return this.secureRandomAlgorithm;
  253.     }
  254.    
  255.     public int getResponseCheckDateToleranceMilliseconds() {
  256.         return this.responseCheckDateToleranceMilliseconds;
  257.     }
  258.    
  259.     public boolean isCrlSigningCertCheck() {
  260.         return this.crlSigningCertCheck;
  261.     }
  262.    
  263.     public boolean isCrlCaCheck() {
  264.         return this.crlCaCheck;
  265.     }
  266.    
  267.     public boolean isCrl() {
  268.         return this.crl;
  269.     }

  270.     public List<CertificateSource> getCrlSource() {
  271.         return this.crlSource;
  272.     }

  273.     public List<String> getCrlAlternative() {
  274.         return this.crlAlternative;
  275.     }
  276.    
  277.     public boolean isRejectsCertificateWithoutCRL() {
  278.         return this.rejectsCertificateWithoutCRL;
  279.     }
  280.     public boolean isRejectsCAWithoutCRL() {
  281.         return this.rejectsCAWithoutCRL;
  282.     }
  283.    
  284.     public List<CertificateSource> getCrlTrustStoreSource() {
  285.         return this.crlTrustStoreSource;
  286.     }

  287.     public String getAlternativeTrustStoreCRLPath() {
  288.         return this.alternativeTrustStoreCRLPath;
  289.     }

  290.     public String getAlternativeTrustStoreCRLPassword() {
  291.         return this.alternativeTrustStoreCRLPassword;
  292.     }

  293.     public String getAlternativeTrustStoreCRLType() {
  294.         return this.alternativeTrustStoreCRLType;
  295.     }

  296.    
  297.     protected OCSPConfig(String id, Properties p, Logger log) throws UtilsException {
  298.         this.id = id;
  299.        
  300.         if(log!=null) {
  301.             // nop
  302.         }
  303.        
  304.         if(p==null || p.isEmpty()) {
  305.             throw new UtilsException("Properties '"+OCSPCostanti.PROPERTY_PREFIX+id+".*' undefined");
  306.         }
  307.        
  308.         this.type = getProperty(id, p, OCSPCostanti.PROPERTY_SUFFIX_TYPE, true);    
  309.         this.label = getProperty(id, p, OCSPCostanti.PROPERTY_SUFFIX_LABEL, true);  
  310.        
  311.         this.certificateChainVerify = getBooleanProperty(id, p, OCSPCostanti.PROPERTY_SUFFIX_CERTIFICATE_CHAIN_VERIFY, false, true);    
  312.        
  313.         this.checkValidity = getBooleanProperty(id, p, OCSPCostanti.PROPERTY_SUFFIX_CHECK_VALIDITY, false, true);  
  314.         this.checkCAValidity = getBooleanProperty(id, p, OCSPCostanti.PROPERTY_SUFFIX_CHECK_CA_VALIDITY, false, true);  
  315.        
  316.         this.caSource = getCertificateSourceProperty(id, p, OCSPCostanti.PROPERTY_SUFFIX_CA_SOURCE, true, null);
  317.        
  318.         this.alternativeTrustStoreCAPath = getProperty(id, p, OCSPCostanti.PROPERTY_SUFFIX_CA_ALTERNATIVE_TRUST_STORE, false);  
  319.         if(this.alternativeTrustStoreCAPath!=null && StringUtils.isNotEmpty(this.alternativeTrustStoreCAPath)) {
  320.             this.alternativeTrustStoreCAPassword = getProperty(id, p, OCSPCostanti.PROPERTY_SUFFIX_CA_ALTERNATIVE_TRUST_STORE_PASSWORD, true);  
  321.             this.alternativeTrustStoreCAType = getProperty(id, p, OCSPCostanti.PROPERTY_SUFFIX_CA_ALTERNATIVE_TRUST_STORE_TYPE, false);
  322.             if(this.alternativeTrustStoreCAType==null || StringUtils.isEmpty(this.alternativeTrustStoreCAType)) {
  323.                 this.alternativeTrustStoreCAType = KeystoreType.JKS.getNome();
  324.             }
  325.         }
  326.        
  327.         this.rejectsCertificateWithoutCA = getBooleanProperty(id, p, OCSPCostanti.PROPERTY_SUFFIX_CA_NOT_FOUD_REJECTS_CERTIFICATE, false, true);    
  328.        
  329.         this.trustStoreSignerPath = getProperty(id, p, OCSPCostanti.PROPERTY_SUFFIX_SIGNER_TRUST_STORE, false);
  330.         if(this.trustStoreSignerPath!=null && StringUtils.isNotEmpty(this.trustStoreSignerPath)) {
  331.             this.trustStoreSignerPassword = getProperty(id, p, OCSPCostanti.PROPERTY_SUFFIX_SIGNER_TRUST_STORE_PASSWORD, true);
  332.             this.trustStoreSignerType = getProperty(id, p, OCSPCostanti.PROPERTY_SUFFIX_SIGNER_TRUST_STORE_TYPE, false);
  333.             if(this.trustStoreSignerType==null || StringUtils.isEmpty(this.trustStoreSignerType)) {
  334.                 this.trustStoreSignerType = KeystoreType.JKS.getNome();
  335.             }
  336.         }
  337.        
  338.         String prefix = "Property '"+OCSPCostanti.PROPERTY_PREFIX+id+".";
  339.        
  340.         this.aliasCertificateSigner = getProperty(id, p, OCSPCostanti.PROPERTY_SUFFIX_SIGNER_ALIAS, false);
  341.         if(
  342.                 (this.aliasCertificateSigner!=null && StringUtils.isNotEmpty(this.aliasCertificateSigner))
  343.                 &&
  344.                 (this.trustStoreSignerPath==null || StringUtils.isEmpty(this.trustStoreSignerPath))
  345.             ){
  346.             throw new UtilsException(prefix+OCSPCostanti.PROPERTY_SUFFIX_SIGNER_ALIAS+"' require property '"+
  347.                     OCSPCostanti.PROPERTY_PREFIX+id+"."+OCSPCostanti.PROPERTY_SUFFIX_SIGNER_TRUST_STORE+"'");
  348.         }
  349.        
  350.         this.nonce = getBooleanProperty(id, p, OCSPCostanti.PROPERTY_SUFFIX_NONCE_ENABLED, false, true);
  351.        
  352.         this.crl=getBooleanProperty(id, p, OCSPCostanti.PROPERTY_SUFFIX_CRL_ENABLED, false, false);
  353.        
  354.         if(this.crl) {
  355.             this.responderUrlSource = getCertificateSourceProperty(id, p, OCSPCostanti.PROPERTY_SUFFIX_URL_SOURCE, false, null);
  356.         }
  357.         else {
  358.             this.responderUrlSource = getCertificateSourceProperty(id, p, OCSPCostanti.PROPERTY_SUFFIX_URL_SOURCE, true, null);
  359.         }
  360.         if(this.responderUrlSource!=null && this.responderUrlSource.contains(CertificateSource.CONFIG)) {
  361.             throw new UtilsException(prefix+OCSPCostanti.PROPERTY_SUFFIX_URL_SOURCE+"' declare unsupported '"+CertificateSource.CONFIG+"' mode");
  362.         }
  363.        
  364.         this.alternativeResponderUrl = getListProperty(id, p, OCSPCostanti.PROPERTY_SUFFIX_URL_ALTERNATIVE, false, null);
  365.         this.alternativeResponderUrlCA = getListProperty(id, p, OCSPCostanti.PROPERTY_SUFFIX_URL_ALTERNATIVE_CA, false, null);
  366.         this.rejectsCertificateWithoutResponderUrl = getBooleanProperty(id, p, OCSPCostanti.PROPERTY_SUFFIX_URL_NOT_FOUND_REJECTS_CERTIFICATE, false, true);    
  367.         this.rejectsCAWithoutResponderUrl = getBooleanProperty(id, p, OCSPCostanti.PROPERTY_SUFFIX_URL_NOT_FOUND_REJECTS_CA, false, false);
  368.         this.responderBreakStatus = getOCSPResponseCodeProperty(id, p, OCSPCostanti.PROPERTY_SUFFIX_URL_BREAK_STATUS, false, null);
  369.         this.responderReturnCodeOk = getListIntProperty(id, p, OCSPCostanti.PROPERTY_SUFFIX_URL_RETURN_CODE_OK, false, null);
  370.        
  371.         // fondamentale per prevenire attacchi man in the middle (siamo in http) firmando con un altro certificato rilasciato dalla CA, non adibito a firmare risposte OCSP
  372.         List<ExtendedKeyUsage> extendedKeyUsageRequiredDefault = new ArrayList<>();
  373.         extendedKeyUsageRequiredDefault.add(ExtendedKeyUsage.OCSP_SIGNING);
  374.         this.extendedKeyUsageRequired = getExtendedKeyUsageProperty(id, p, OCSPCostanti.PROPERTY_SUFFIX_EXTENDED_KEY_USAGE, extendedKeyUsageRequiredDefault);
  375.        
  376.         this.readTimeout = getIntProperty(id, p, OCSPCostanti.PROPERTY_SUFFIX_READ_TIMEOUT, false, 15000); /** HttpUtilities.HTTP_READ_CONNECTION_TIMEOUT); */
  377.         this.connectTimeout = getIntProperty(id, p, OCSPCostanti.PROPERTY_SUFFIX_CONNECT_TIMEOUT, false, HttpUtilities.HTTP_CONNECTION_TIMEOUT);
  378.        
  379.         this.externalResourcesHostnameVerifier = getBooleanProperty(id, p, OCSPCostanti.PROPERTY_SUFFIX_HTTPS_HOSTNAME_VERIFIER, false, true);  
  380.         this.externalResourcesTrustAllCerts = getBooleanProperty(id, p, OCSPCostanti.PROPERTY_SUFFIX_HTTPS_TRUST_ALL_CERTS, false, false);  
  381.         this.externalResourcesTrustStorePath = getProperty(id, p, OCSPCostanti.PROPERTY_SUFFIX_HTTPS_TRUST_STORE, false);  
  382.         if(this.externalResourcesTrustStorePath!=null && StringUtils.isNotEmpty(this.externalResourcesTrustStorePath)) {
  383.             this.externalResourcesTrustStorePassword = getProperty(id, p, OCSPCostanti.PROPERTY_SUFFIX_HTTPS_TRUST_STORE_PASSWORD, true);  
  384.             this.externalResourcesTrustStoreType = getProperty(id, p, OCSPCostanti.PROPERTY_SUFFIX_HTTPS_TRUST_STORE_TYPE, false);
  385.             if(this.externalResourcesTrustStoreType==null || StringUtils.isEmpty(this.externalResourcesTrustStoreType)) {
  386.                 this.externalResourcesTrustStoreType = KeystoreType.JKS.getNome();
  387.             }
  388.         }
  389.        
  390.         this.externalResourcesKeyStorePath = getProperty(id, p, OCSPCostanti.PROPERTY_SUFFIX_HTTPS_KEY_STORE, false);  
  391.         if(this.externalResourcesKeyStorePath!=null && StringUtils.isNotEmpty(this.externalResourcesKeyStorePath)) {
  392.             this.externalResourcesKeyStorePassword = getProperty(id, p, OCSPCostanti.PROPERTY_SUFFIX_HTTPS_KEY_STORE_PASSWORD, true);  
  393.             this.externalResourcesKeyStoreType = getProperty(id, p, OCSPCostanti.PROPERTY_SUFFIX_HTTPS_KEY_STORE_TYPE, false);
  394.             if(this.externalResourcesKeyStoreType==null || StringUtils.isEmpty(this.externalResourcesKeyStoreType)) {
  395.                 this.externalResourcesKeyStoreType = KeystoreType.JKS.getNome();
  396.             }
  397.            
  398.             this.externalResourcesKeyPassword = getProperty(id, p, OCSPCostanti.PROPERTY_SUFFIX_HTTPS_KEY_PASSWORD, true);  
  399.             this.externalResourcesKeyAlias = getProperty(id, p, OCSPCostanti.PROPERTY_SUFFIX_HTTPS_KEY_ALIAS, false);  
  400.         }
  401.        
  402.         this.externalResourcesUsername = getProperty(id, p, OCSPCostanti.PROPERTY_SUFFIX_USERNAME, false);  
  403.         if(this.externalResourcesUsername!=null && StringUtils.isNotEmpty(this.externalResourcesUsername)) {
  404.             this.externalResourcesPassword = getProperty(id, p, OCSPCostanti.PROPERTY_SUFFIX_PASSWORD, false);  
  405.         }
  406.        
  407.         this.forwardProxyUrl = getProperty(id, p, OCSPCostanti.PROPERTY_SUFFIX_FORWARD_PROXY_URL, false);  
  408.         if(this.forwardProxyUrl!=null && StringUtils.isNotEmpty(this.forwardProxyUrl)) {
  409.             this.forwardProxyHeader = getProperty(id, p, OCSPCostanti.PROPERTY_SUFFIX_FORWARD_PROXY_HEADER, false);
  410.             this.forwardProxyQueryParameter = getProperty(id, p, OCSPCostanti.PROPERTY_SUFFIX_FORWARD_PROXY_QUERY_PARAMETER, false);
  411.             if(this.forwardProxyHeader==null && this.forwardProxyQueryParameter==null) {
  412.                 throw new UtilsException("ForwardProxy property '"+OCSPCostanti.PROPERTY_PREFIX+id+"."+OCSPCostanti.PROPERTY_SUFFIX_FORWARD_PROXY_URL+"' require '"+
  413.                         OCSPCostanti.PROPERTY_PREFIX+id+"."+OCSPCostanti.PROPERTY_SUFFIX_FORWARD_PROXY_HEADER+"' o '"+
  414.                         OCSPCostanti.PROPERTY_PREFIX+id+"."+OCSPCostanti.PROPERTY_SUFFIX_FORWARD_PROXY_QUERY_PARAMETER+"'");
  415.             }
  416.             this.forwardProxyBase64 = getBooleanProperty(id, p, OCSPCostanti.PROPERTY_SUFFIX_FORWARD_PROXY_BASE64, false, true);
  417.         }

  418.         String tmp = getProperty(id, p, OCSPCostanti.PROPERTY_SUFFIX_SECURE_RANDOM_ALGORITHM, false);
  419.         if(tmp!=null && StringUtils.isNotEmpty(tmp)) {
  420.             try {
  421.                 this.secureRandomAlgorithm = SecureRandomAlgorithm.valueOf(tmp);
  422.             }catch(Exception t) {
  423.                 throw new UtilsException("SecureRandomAlgorithm property '"+OCSPCostanti.PROPERTY_PREFIX+id+"."+OCSPCostanti.PROPERTY_SUFFIX_SECURE_RANDOM_ALGORITHM+"' invalid (found value:["+tmp+"]): "+t.getMessage(),t);
  424.             }
  425.         }
  426.         if( this.secureRandomAlgorithm == null) {
  427.             this.secureRandomAlgorithm = SecureRandomAlgorithm.SHA1PRNG;
  428.         }
  429.        
  430.         int defaultTolerance = 1000 * 60 * 10; // 10 minuti
  431.         this.responseCheckDateToleranceMilliseconds = getIntProperty(id, p, OCSPCostanti.PROPERTY_SUFFIX_RESPONSE_DATE_TOLERANCE_MS, false, defaultTolerance);

  432.         this.crlSigningCertCheck=getBooleanProperty(id, p, OCSPCostanti.PROPERTY_SUFFIX_CRL_SIGNING_CERT_CHECK, false, false);
  433.        
  434.         this.crlCaCheck=getBooleanProperty(id, p, OCSPCostanti.PROPERTY_SUFFIX_CRL_CA_CHECK, false, true);
  435.        
  436.         //this.crl=getBooleanProperty(id, p, OCSPCostanti.PROPERTY_SUFFIX_CRL_ENABLED, false, false); spostato sopra
  437.        
  438.         if(this.crl || this.crlSigningCertCheck || this.crlCaCheck) {
  439.            
  440.             List<CertificateSource> defaultValue = new ArrayList<>();
  441.             defaultValue.add(CertificateSource.AUTHORITY_INFORMATION_ACCESS);
  442.            
  443.             this.crlSource = getCertificateSourceProperty(id, p, OCSPCostanti.PROPERTY_SUFFIX_CRL_SOURCE, false, defaultValue);
  444.             if(this.crlSource == null || this.crlSource.isEmpty()) {
  445.                 throw new UtilsException(prefix+OCSPCostanti.PROPERTY_SUFFIX_CRL_SOURCE+"' is empty");
  446.             }
  447.             if(this.crlSigningCertCheck && !this.crlSource.contains(CertificateSource.AUTHORITY_INFORMATION_ACCESS)) {
  448.                 throw new UtilsException(prefix+OCSPCostanti.PROPERTY_SUFFIX_CRL_SIGNING_CERT_CHECK+"' require mode '"+
  449.                         CertificateSource.AUTHORITY_INFORMATION_ACCESS+"' defined in property '"+OCSPCostanti.PROPERTY_PREFIX+id+"."+OCSPCostanti.PROPERTY_SUFFIX_CRL_SOURCE+"'");
  450.             }
  451.             if(this.crlCaCheck && !this.crlSource.contains(CertificateSource.AUTHORITY_INFORMATION_ACCESS)) {
  452.                 throw new UtilsException(prefix+OCSPCostanti.PROPERTY_SUFFIX_CRL_CA_CHECK+"' require mode '"+
  453.                         CertificateSource.AUTHORITY_INFORMATION_ACCESS+"' defined in property '"+OCSPCostanti.PROPERTY_PREFIX+id+"."+OCSPCostanti.PROPERTY_SUFFIX_CRL_SOURCE+"'");
  454.             }
  455.            
  456.             this.crlAlternative = getListProperty(id, p, OCSPCostanti.PROPERTY_SUFFIX_CRL_ALTERNATIVE, false, null);
  457.            
  458.             this.rejectsCertificateWithoutCRL = getBooleanProperty(id, p, OCSPCostanti.PROPERTY_SUFFIX_CRL_NOT_FOUND_REJECTS_CERTIFICATE, false, false);    
  459.             this.rejectsCAWithoutCRL = getBooleanProperty(id, p, OCSPCostanti.PROPERTY_SUFFIX_CRL_NOT_FOUND_REJECTS_CA, false, false);  
  460.                        
  461.             this.crlTrustStoreSource = getCertificateSourceProperty(id, p, OCSPCostanti.PROPERTY_SUFFIX_CRL_TRUSTSTORE_SOURCE, false, defaultValue);
  462.             if(this.crlTrustStoreSource == null || this.crlTrustStoreSource.isEmpty()) {
  463.                 throw new UtilsException(prefix+OCSPCostanti.PROPERTY_SUFFIX_CRL_TRUSTSTORE_SOURCE+"' is empty");
  464.             }
  465.            
  466.             this.alternativeTrustStoreCRLPath = getProperty(id, p, OCSPCostanti.PROPERTY_SUFFIX_CRL_ALTERNATIVE_TRUST_STORE, false);    
  467.             if(this.alternativeTrustStoreCRLPath!=null && StringUtils.isNotEmpty(this.alternativeTrustStoreCRLPath)) {
  468.                 this.alternativeTrustStoreCRLPassword = getProperty(id, p, OCSPCostanti.PROPERTY_SUFFIX_CRL_ALTERNATIVE_TRUST_STORE_PASSWORD, true);    
  469.                 this.alternativeTrustStoreCRLType = getProperty(id, p, OCSPCostanti.PROPERTY_SUFFIX_CRL_ALTERNATIVE_TRUST_STORE_TYPE, false);
  470.                 if(this.alternativeTrustStoreCRLType==null || StringUtils.isEmpty(this.alternativeTrustStoreCRLType)) {
  471.                     this.alternativeTrustStoreCRLType = KeystoreType.JKS.getNome();
  472.                 }
  473.             }
  474.         }

  475.     }
  476.    
  477.     private static String getProperty(String id, Properties p, String name, boolean required) throws UtilsException {
  478.         String tmp = p.getProperty(name);
  479.         if(tmp!=null) {
  480.             return tmp.trim();
  481.         }
  482.         else {
  483.             if(required) {
  484.                 throw new UtilsException("Property '"+OCSPCostanti.PROPERTY_PREFIX+id+"."+name+"' notFound");
  485.             }
  486.             return null;
  487.         }
  488.     }
  489.     private static boolean getBooleanProperty(String id, Properties p, String name, boolean required, boolean defaultValue) throws UtilsException {
  490.         String tmp = getProperty(id, p, name, required);
  491.         if(tmp!=null && StringUtils.isNotEmpty(tmp)) {
  492.             try {
  493.                 return Boolean.valueOf(tmp);
  494.             }catch(Exception t) {
  495.                 throw new UtilsException("Boolean property '"+OCSPCostanti.PROPERTY_PREFIX+id+"."+name+"' invalid (found value:["+tmp+"]): "+t.getMessage(),t);
  496.             }
  497.         }
  498.         return defaultValue;
  499.     }
  500.     private static int getIntProperty(String id, Properties p, String name, boolean required, int defaultValue) throws UtilsException {
  501.         String tmp = getProperty(id, p, name, required);
  502.         if(tmp!=null && StringUtils.isNotEmpty(tmp)) {
  503.             try {
  504.                 return Integer.valueOf(tmp);
  505.             }catch(Exception t) {
  506.                 throw new UtilsException("Boolean property '"+OCSPCostanti.PROPERTY_PREFIX+id+"."+name+"' invalid (found value:["+tmp+"]): "+t.getMessage(),t);
  507.             }
  508.         }
  509.         return defaultValue;
  510.     }
  511.     private static List<String> getListProperty(String id, Properties p, String name, boolean required, List<String> defaultValue) throws UtilsException {
  512.         String tmp = getProperty(id, p, name, required);
  513.         if(tmp!=null && StringUtils.isNotEmpty(tmp)) {
  514.             try {
  515.                 List<String> l = new ArrayList<>();
  516.                 String [] tmpArray = tmp.split(",");
  517.                 if(tmpArray==null || tmpArray.length<=0) {
  518.                     throw new UtilsException("Undefined value");
  519.                 }
  520.                 for (String s : tmpArray) {
  521.                     if(s!=null && StringUtils.isNotEmpty(s.trim())) {
  522.                         l.add(s.trim());
  523.                     }
  524.                 }
  525.                 return l;
  526.             }catch(Exception t) {
  527.                 throw new UtilsException("CertificateSource property '"+OCSPCostanti.PROPERTY_PREFIX+id+"."+name+"' invalid (found value:["+tmp+"]): "+t.getMessage(),t);
  528.             }
  529.         }
  530.         return defaultValue;
  531.     }
  532.     private static List<Integer> getListIntProperty(String id, Properties p, String name, boolean required, List<Integer> defaultValue) throws UtilsException {
  533.         List<String> l = getListProperty(id, p, name, required, null);
  534.         if(l==null || l.isEmpty()) {
  535.             return defaultValue;
  536.         }
  537.         List<Integer> lCS = new ArrayList<>();
  538.         for (String certificateSource : l) {
  539.             try {
  540.                 int c = Integer.parseInt(certificateSource);
  541.                 lCS.add(c);
  542.             }catch(Exception t) {
  543.                 throw new UtilsException("CertificateSource property '"+OCSPCostanti.PROPERTY_PREFIX+id+"."+name+"' invalid (found value:["+certificateSource+"]): "+t.getMessage(),t);
  544.             }
  545.         }
  546.         return lCS;
  547.     }
  548.     private static List<CertificateSource> getCertificateSourceProperty(String id, Properties p, String name, boolean required, List<CertificateSource> defaultValue) throws UtilsException {
  549.         List<String> l = getListProperty(id, p, name, required, null);
  550.         if(l==null || l.isEmpty()) {
  551.             return defaultValue;
  552.         }
  553.         List<CertificateSource> lCS = new ArrayList<>();
  554.         for (String certificateSource : l) {
  555.             try {
  556.                 CertificateSource c = CertificateSource.valueOf(certificateSource.toUpperCase());
  557.                 lCS.add(c);
  558.             }catch(Exception t) {
  559.                 throw new UtilsException("CertificateSource property '"+OCSPCostanti.PROPERTY_PREFIX+id+"."+name+"' invalid (found value:["+certificateSource+"]): "+t.getMessage(),t);
  560.             }
  561.         }
  562.         if(lCS.isEmpty()) {
  563.             return defaultValue;
  564.         }
  565.         return lCS;
  566.     }
  567.     private static List<OCSPResponseCode> getOCSPResponseCodeProperty(String id, Properties p, String name, boolean required, List<OCSPResponseCode> defaultValue) throws UtilsException {
  568.         List<String> l = getListProperty(id, p, name, required, null);
  569.         if(l==null || l.isEmpty()) {
  570.             return defaultValue;
  571.         }
  572.         List<OCSPResponseCode> lCS = new ArrayList<>();
  573.         for (String certificateSource : l) {
  574.             try {
  575.                 OCSPResponseCode c = OCSPResponseCode.valueOf(certificateSource.toUpperCase());
  576.                 lCS.add(c);
  577.             }catch(Exception t) {
  578.                 throw new UtilsException("OCSPResponseCode property '"+OCSPCostanti.PROPERTY_PREFIX+id+"."+name+"' invalid (found value:["+certificateSource+"]): "+t.getMessage(),t);
  579.             }
  580.         }
  581.         if(lCS.isEmpty()) {
  582.             return defaultValue;
  583.         }
  584.         return lCS;
  585.     }
  586.     private static List<ExtendedKeyUsage> getExtendedKeyUsageProperty(String id, Properties p, String name, List<ExtendedKeyUsage> defaultValue) throws UtilsException {
  587.        
  588.         String tmp = getProperty(id, p, name, false);
  589.         if(tmp!=null && "".equals(tmp)) {
  590.             // non si vuole attuare alcun controllo
  591.             return new ArrayList<>();
  592.         }
  593.        
  594.         List<String> l = getListProperty(id, p, name, false, null);
  595.         if(l==null || l.isEmpty()) {
  596.             return defaultValue;
  597.         }
  598.         List<ExtendedKeyUsage> lCS = new ArrayList<>();
  599.         for (String e : l) {
  600.             try {
  601.                 ExtendedKeyUsage c = ExtendedKeyUsage.valueOf(e.toUpperCase());
  602.                 lCS.add(c);
  603.             }catch(Exception t) {
  604.                 throw new UtilsException("ExtendedKeyUsage property '"+OCSPCostanti.PROPERTY_PREFIX+id+"."+name+"' invalid (found value:["+e+"]): "+t.getMessage(),t);
  605.             }
  606.         }
  607.         if(lCS.isEmpty()) {
  608.             return defaultValue;
  609.         }
  610.         return lCS;
  611.     }
  612.    
  613.    
  614. }