OCSPValidatorImpl.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.security.cert.X509Certificate;

  22. import org.openspcoop2.utils.LoggerBuffer;
  23. import org.openspcoop2.utils.UtilsException;
  24. import org.openspcoop2.utils.certificate.KeyStore;
  25. import org.openspcoop2.utils.transport.http.IOCSPValidator;
  26. import org.openspcoop2.utils.transport.http.OCSPTrustManager;

  27. /**
  28.  * OCSPValidatorImpl
  29.  *
  30.  * @author Poli Andrea (apoli@link.it)
  31.  * @author $Author$
  32.  * @version $Rev$, $Date$
  33.  */
  34. public class OCSPValidatorImpl implements IOCSPValidator {

  35.     private LoggerBuffer log;
  36.     private KeyStore trustStore;
  37.     private String crlInput;
  38.     private String configType;
  39.     private OCSPConfig ocspConfig;
  40.     private IOCSPResourceReader ocspResourceReader;
  41.     private OCSPTrustManager ocspTrustManager;
  42.    
  43.     public OCSPValidatorImpl(LoggerBuffer log,
  44.             String crlInput,
  45.             String configType, IOCSPResourceReader ocspResourceReader) throws UtilsException {
  46.         this(log,
  47.             null, crlInput,
  48.             configType, ocspResourceReader);
  49.     }
  50.     public OCSPValidatorImpl(LoggerBuffer log,
  51.             KeyStore trustStore, String crlInput,
  52.             String configType, IOCSPResourceReader ocspResourceReader) throws UtilsException {
  53.         this.log = log;
  54.         this.trustStore = trustStore;
  55.         this.crlInput = crlInput;
  56.         this.configType = configType;
  57.        
  58.         OCSPManager ocspManager = OCSPManager.getInstance();
  59.         this.ocspConfig = ocspManager.getOCSPConfig(this.configType);
  60.        
  61.         this.ocspResourceReader = ocspResourceReader;
  62.     }
  63.    
  64.     @Override
  65.     public void valid(X509Certificate cert) throws UtilsException {
  66.        
  67.         OCSPRequestParams params = OCSPRequestParams.build(this.log, cert, this.trustStore, this.ocspConfig, this.ocspResourceReader);
  68.         CertificateStatus certificatePrincipalStatus = OCSPValidator.check(this.log, params, this.crlInput);
  69.         certificatePrincipalStatus.checkValid();
  70.        
  71.     }
  72.    
  73.     @Override
  74.     public KeyStore getTrustStore() {
  75.         return this.trustStore;
  76.     }
  77.     @Override
  78.     public void setTrustStore(KeyStore truststore) {
  79.         this.trustStore = truststore;
  80.     }
  81.    
  82.     @Override
  83.     public OCSPTrustManager getOCSPTrustManager() {
  84.         return this.ocspTrustManager;
  85.     }
  86.     @Override
  87.     public void setOCSPTrustManager(OCSPTrustManager trustManager) {
  88.         this.ocspTrustManager = trustManager;
  89.     }

  90.     public OCSPConfig getOcspConfig() {
  91.         return this.ocspConfig;
  92.     }
  93. }