CRLDistributionPoint.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;

  21. import java.security.cert.CertificateParsingException;
  22. import java.util.ArrayList;
  23. import java.util.List;

  24. import org.bouncycastle.asn1.x509.DistributionPointName;
  25. import org.bouncycastle.asn1.x509.GeneralName;
  26. import org.bouncycastle.asn1.x509.ReasonFlags;

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

  35.     protected List<GeneralName> crlIssuers = new ArrayList<>();
  36.     protected ReasonFlags reasonFlags;
  37.     protected DistributionPointName distributionPointName;
  38.     protected List<GeneralName> distributionPointNames = new ArrayList<>();
  39.    
  40.    
  41.    
  42.     public DistributionPointName getObjectDistributionPointName() {
  43.         return this.distributionPointName;
  44.     }
  45.     public int getDistributionPointType() {
  46.         return this.distributionPointName!=null ? this.distributionPointName.getType() : -1 ;
  47.     }
  48.    
  49.     public List<GeneralName> getObjectDistributionPointNames() {
  50.         return this.distributionPointNames;
  51.     }
  52.     public GeneralName getObjectDistributionPointName(int index) {
  53.         return this.distributionPointNames!=null && (this.distributionPointNames.size()>index) ? this.distributionPointNames.get(index) : null;
  54.     }
  55.     public List<String> getDistributionPointNames() {
  56.         List<String> s = new ArrayList<>();
  57.         if(this.distributionPointNames!=null && !this.distributionPointNames.isEmpty()) {
  58.             for (GeneralName o : this.distributionPointNames) {
  59.                 if(o.getName()!=null) {
  60.                     s.add(o.getName().toString());
  61.                 }
  62.             }
  63.         }
  64.         return s;
  65.     }
  66.     public String getDistributionPointName(int index) {
  67.         if(this.distributionPointNames!=null && (this.distributionPointNames.size()>index)) {
  68.             return (this.distributionPointNames.get(index)!=null && this.distributionPointNames.get(index).getName()!=null) ? this.distributionPointNames.get(index).getName().toString() : null;
  69.         }
  70.         return null;
  71.     }
  72.     public boolean containsDistributionPointName(String name) throws CertificateParsingException {
  73.         return containsDistributionPointNameEngine(null, name);
  74.     }
  75.     public boolean containsDistributionPointName(int tagNum, String name) throws CertificateParsingException {
  76.         return containsDistributionPointNameEngine(tagNum, name);
  77.     }
  78.     private boolean containsDistributionPointNameEngine(Integer tagNum, String name) throws CertificateParsingException {
  79.         if(name==null) {
  80.             throw new CertificateParsingException("Param name undefined");
  81.         }
  82.         if(this.distributionPointNames!=null && !this.distributionPointNames.isEmpty()) {
  83.             for (GeneralName o : this.distributionPointNames) {
  84.                 if(isEquals(o, tagNum, name)) {
  85.                     return true;
  86.                 }
  87.             }
  88.         }
  89.         return false;
  90.     }
  91.    

  92.     public ReasonFlags getReasonFlags() {
  93.         return this.reasonFlags;
  94.     }
  95.    
  96.     public List<GeneralName> getObjectCRLIssuers() {
  97.         return this.crlIssuers;
  98.     }
  99.     public GeneralName getObjectCRLIssuer(int index) {
  100.         return this.crlIssuers!=null && (this.crlIssuers.size()>index) ? this.crlIssuers.get(index) : null;
  101.     }
  102.     public List<String> getCRLIssuers() {
  103.         List<String> s = new ArrayList<>();
  104.         if(this.crlIssuers!=null && !this.crlIssuers.isEmpty()) {
  105.             for (GeneralName o : this.crlIssuers) {
  106.                 if(o.getName()!=null) {
  107.                     s.add(o.getName().toString());
  108.                 }
  109.             }
  110.         }
  111.         return s;
  112.     }
  113.     public String getCRLIssuer(int index) {
  114.         if(this.crlIssuers!=null && (this.crlIssuers.size()>index)) {
  115.             return (this.crlIssuers.get(index)!=null && this.crlIssuers.get(index).getName()!=null) ? this.crlIssuers.get(index).getName().toString() : null;
  116.         }
  117.         return null;
  118.     }
  119.     public boolean containsCRLIssuer(String name) throws CertificateParsingException {
  120.         return containsCRLIssuerEngine(null, name);
  121.     }
  122.     public boolean containsCRLIssuer(int tagNum, String name) throws CertificateParsingException {
  123.         return containsCRLIssuerEngine(tagNum, name);
  124.     }
  125.     private boolean containsCRLIssuerEngine(Integer tagNum, String name) throws CertificateParsingException {
  126.         if(name==null) {
  127.             throw new CertificateParsingException("Param name undefined");
  128.         }
  129.         if(this.crlIssuers!=null && !this.crlIssuers.isEmpty()) {
  130.             for (GeneralName o : this.crlIssuers) {
  131.                 if(isEquals(o, tagNum, name)) {
  132.                     return true;
  133.                 }
  134.             }
  135.         }
  136.         return false;
  137.     }
  138.    
  139.     private boolean isEquals(GeneralName o, Integer tagNum, String name) {
  140.         if(o.getName()!=null && name.equals(o.getName().toString())) {
  141.             if(tagNum==null) {
  142.                 return true;
  143.             }
  144.             else {
  145.                 if(tagNum.intValue() == o.getTagNo()) {
  146.                     return true;
  147.                 }
  148.             }
  149.         }
  150.         return false;
  151.     }
  152. }