CRLCertstore.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.security.keystore;

  21. import java.io.Serializable;
  22. import java.security.cert.CertStore;
  23. import java.security.cert.CertificateFactory;
  24. import java.security.cert.X509CRL;
  25. import java.util.ArrayList;
  26. import java.util.List;
  27. import java.util.Map;

  28. import org.openspcoop2.security.SecurityException;

  29. /**
  30.  * CRLCertstore
  31.  *
  32.  * @author Andrea Poli (apoli@link.it)
  33.  * @author $Author$
  34.  * @version $Rev$, $Date$
  35.  */
  36. public class CRLCertstore implements Serializable {

  37.     /**
  38.      *
  39.      */
  40.     private static final long serialVersionUID = 1L;

  41.     private org.openspcoop2.utils.certificate.CRLCertstore crl = null;
  42.    
  43.     public CRLCertstore(String crlPaths) throws SecurityException {
  44.         this(crlPaths, null);
  45.     }
  46.     public CRLCertstore(String crlPaths, Map<String, byte[]> localResources) throws SecurityException {
  47.         List<String> crlPathsList = null;
  48.         if(localResources!=null && localResources.containsKey(crlPaths)){ // caso ldap in cui la virgola fa parte del path
  49.             crlPathsList = new ArrayList<>();
  50.             crlPathsList.add(crlPaths);
  51.         }
  52.         else {
  53.             crlPathsList = org.openspcoop2.utils.certificate.CRLCertstore.readCrlPaths(crlPaths);
  54.         }
  55.         try {
  56.             this.initEngine(crlPathsList, localResources);
  57.         }catch(Exception t) {
  58.             throw new SecurityException(t.getMessage(),t);
  59.         }
  60.     }
  61.    
  62.     public CRLCertstore(List<String> crlPaths) throws SecurityException{
  63.         this(crlPaths, null);
  64.     }
  65.     public CRLCertstore(List<String> crlPaths, Map<String, byte[]> localResources) throws SecurityException{
  66.         try {
  67.             this.initEngine(crlPaths, localResources);
  68.         }catch(Exception t) {
  69.             throw new SecurityException(t.getMessage(),t);
  70.         }
  71.     }

  72.     private void initEngine(List<String> crlPaths, Map<String, byte[]> localResources) throws SecurityException{
  73.         try{
  74.             this.crl = new org.openspcoop2.utils.certificate.CRLCertstore(crlPaths, localResources);
  75.         }catch(Exception e){
  76.             throw new SecurityException(e.getMessage(),e);
  77.         }
  78.        
  79.     }
  80.    
  81.     public CertificateFactory getCertFactory() throws SecurityException {
  82.         try {
  83.             return this.crl.getCertFactory();
  84.         }catch(Exception e){
  85.             throw new SecurityException(e.getMessage(),e);
  86.         }
  87.     }

  88.     public List<X509CRL> getCaCrls() throws SecurityException {
  89.         try {
  90.             return this.crl.getCaCrls();
  91.         }catch(Exception e){
  92.             throw new SecurityException(e.getMessage(),e);
  93.         }
  94.     }

  95.     public CertStore getCertStore() throws SecurityException {
  96.         try {
  97.             return this.crl.getCertStore();
  98.         }catch(Exception e){
  99.             throw new SecurityException(e.getMessage(),e);
  100.         }
  101.     }
  102.    
  103.     public org.openspcoop2.utils.certificate.CRLCertstore getWrappedCRLCertStore() {
  104.         return this.crl;
  105.     }
  106.    
  107. }