BasicConstraints.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 org.bouncycastle.asn1.x509.Extensions;

  22. /**
  23.  * BasicConstraints
  24.  *
  25.  * @author Poli Andrea (apoli@link.it)
  26.  * @author $Author$
  27.  * @version $Rev$, $Date$
  28.  */
  29. public class BasicConstraints {

  30.     private boolean ca;
  31.     private long pathLen;
  32.        
  33.     public long getPathLen() {
  34.         return this.pathLen;
  35.     }
  36.     /**public boolean isCa() {
  37.         return this.ca;
  38.     }*/
  39.     public boolean isCA() {
  40.         return this.ca;
  41.     }

  42.     public static BasicConstraints getBasicConstraints(byte[]encoded) {
  43.        
  44.         org.bouncycastle.asn1.x509.Certificate c =org.bouncycastle.asn1.x509.Certificate.getInstance(encoded);
  45.         Extensions exts = c.getTBSCertificate().getExtensions();
  46.         if (exts != null){
  47.             org.bouncycastle.asn1.x509.BasicConstraints basicConstraints = org.bouncycastle.asn1.x509.BasicConstraints.fromExtensions(exts);
  48.             if(basicConstraints!=null) {
  49.                 /**System.out.println("======================");
  50.                 System.out.println("BasicConstraints '"+basicConstraints.toString()+"'");
  51.                 System.out.println("Len '"+basicConstraints.getPathLenConstraint()+"'");
  52.                 System.out.println("Qual '"+basicConstraints.isCA()+"'");
  53.                 System.out.println("======================");*/
  54.                
  55.                 BasicConstraints bc = new BasicConstraints();
  56.                 bc.ca = basicConstraints.isCA();
  57.                 if(basicConstraints.getPathLenConstraint()!=null) {
  58.                     bc.pathLen = basicConstraints.getPathLenConstraint().longValue();
  59.                 }
  60.                 return bc;
  61.             }
  62.         }
  63.         return null;
  64.        
  65.     }
  66. }