OID.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.x500.style.BCStyle;

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

  30.     CN(BCStyle.CN), // [2.5.4.3] common name
  31.     C(BCStyle.C), // [2.5.4.6] country code
  32.     OU(BCStyle.OU), // [2.5.4.11] organizational unit name
  33.     O(BCStyle.O), // [2.5.4.10] organization name
  34.     L(BCStyle.L), // [2.5.4.7] locality name
  35.     ST(BCStyle.ST), // [2.5.4.8] state, or province name
  36.    
  37.     ORGANIZATION_IDENTIFIER(BCStyle.ORGANIZATION_IDENTIFIER), // [2.5.4.97]
  38.    
  39.     T(BCStyle.T),  // [2.5.4.12]
  40.     SERIALNUMBER(BCStyle.SERIALNUMBER), // [2.5.4.5] device serial number name
  41.     NAME(BCStyle.NAME), //  [2.5.4.41]
  42.     SURNAME(BCStyle.SURNAME), // [2.5.4.4] Naming attributes of type X520name
  43.     GIVENNAME(BCStyle.GIVENNAME), // [2.5.4.42]
  44.     STREET(BCStyle.STREET), // [2.5.4.9]
  45.     POSTAL_CODE(BCStyle.POSTAL_CODE), // [2.5.4.17]
  46.     POSTAL_ADDRESS(BCStyle.POSTAL_ADDRESS), // [2.5.4.16] RFC 3039 PostalAddress
  47.     TELEPHONE_NUMBER(BCStyle.TELEPHONE_NUMBER), // [2.5.4.20]
  48.     INITIALS(BCStyle.INITIALS), // [2.5.4.43]
  49.     GENERATION(BCStyle.GENERATION), // [2.5.4.44]
  50.     UNIQUE_IDENTIFIER(BCStyle.UNIQUE_IDENTIFIER), // [2.5.4.45]
  51.     DESCRIPTION(BCStyle.DESCRIPTION), // [2.5.4.13]
  52.     BUSINESS_CATEGORY(BCStyle.BUSINESS_CATEGORY), // [2.5.4.15]
  53.     DN_QUALIFIER(BCStyle.DN_QUALIFIER), // [2.5.4.46]
  54.     PSEUDONYM(BCStyle.PSEUDONYM), // [2.5.4.65] RFC 3039 Pseudonym
  55.     ROLE(BCStyle.ROLE), // [2.5.4.72]
  56.     DMD_NAME(BCStyle.DMD_NAME), // [2.5.4.54] RFC 2256 dmdName
  57.     /**@SuppressWarnings("deprecation")
  58.     @Deprecated
  59.     SN(BCStyle.SN), // [2.5.4.5] use SERIALNUMBER or SURNAME */
  60.    
  61.     UID(BCStyle.UID), // [0.9.2342.19200300.100.1.1]
  62.     DC(BCStyle.DC), // [0.9.2342.19200300.100.1.25]
  63.    
  64.     EMAIL_ADDRESS(BCStyle.EmailAddress), // [1.2.840.113549.1.9.1]
  65.     E(BCStyle.E), // [1.2.840.113549.1.9.1] email address in Verisign certificates
  66.     UNSTRUCTURED_NAME(BCStyle.UnstructuredName), // [1.2.840.113549.1.9.2]
  67.     UNSTRUCTURED_ADDRESS(BCStyle.UnstructuredAddress), // [1.2.840.113549.1.9.8]
  68.    
  69.     NAME_AT_BIRTH(BCStyle.NAME_AT_BIRTH),  // [1.3.36.8.3.14] ISIS-MTT NameAtBirth - DirectoryString(SIZE(1..64)
  70.     DATE_OF_BIRTH(BCStyle.DATE_OF_BIRTH), // [1.3.6.1.5.5.7.9.1] RFC 3039 DateOfBirth - GeneralizedTime - YYYYMMDD000000Z
  71.     PLACE_OF_BIRTH(BCStyle.PLACE_OF_BIRTH), // [1.3.6.1.5.5.7.9.2] RFC 3039 PlaceOfBirth
  72.     GENDER(BCStyle.GENDER), // [1.3.6.1.5.5.7.9.3]
  73.     COUNTRY_OF_CITIZENSHIP(BCStyle.COUNTRY_OF_CITIZENSHIP), // [1.3.6.1.5.5.7.9.4] RFC 3039 CountryOfCitizenship - PrintableString (SIZE (2)) -- ISO 3166 codes only
  74.     COUNTRY_OF_RESIDENCE(BCStyle.COUNTRY_OF_RESIDENCE); // [1.3.6.1.5.5.7.9.5] RFC 3039 CountryOfResidence - PrintableString (SIZE (2)) -- ISO 3166 codes only
  75.        

  76.    
  77.    
  78.     private String oidValue;
  79.     private org.bouncycastle.asn1.ASN1ObjectIdentifier oidBC;
  80.    
  81.     OID(org.bouncycastle.asn1.ASN1ObjectIdentifier oid) {
  82.         this.oidValue = oid.getId();
  83.         this.oidBC = oid;
  84.     }
  85.    
  86.     public String getID() {
  87.         return this.oidValue;
  88.     }
  89.     public org.bouncycastle.asn1.ASN1ObjectIdentifier getOID() {
  90.         if(this.oidBC!=null) {
  91.             return this.oidBC;
  92.         }
  93.         else {
  94.             return new org.bouncycastle.asn1.ASN1ObjectIdentifier(this.oidValue);
  95.         }
  96.     }
  97.    
  98.     @Override
  99.     public String toString() {
  100.         return toString(false);
  101.     }
  102.     public String toString(boolean printOID) {
  103.         if(printOID) {
  104.             return this.name()+" ("+this.oidValue+")";
  105.         }
  106.         else {
  107.             return this.name();
  108.         }
  109.     }
  110.    
  111.     public static OID toOID(String id) {
  112.         OID [] v = OID.values();
  113.         for (OID oid : v) {
  114.             if(oid.oidValue.equals(id)) {
  115.                 return oid;
  116.             }
  117.         }
  118.         return null;
  119.     }
  120.     public static OID toOID(org.bouncycastle.asn1.ASN1ObjectIdentifier idBC) {
  121.         OID [] v = OID.values();
  122.         for (OID oid : v) {
  123.             if(oid.oidBC.equals(idBC)) {
  124.                 return oid;
  125.             }
  126.         }
  127.         return null;
  128.     }
  129. }