2 * ============LICENSE_START====================================================
4 * ===========================================================================
5 * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
6 * ===========================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END====================================================
21 package org.onap.aaf.auth.cm.cert;
23 import java.util.ArrayList;
24 import java.util.List;
26 import org.bouncycastle.asn1.ASN1ObjectIdentifier;
27 import org.bouncycastle.asn1.x500.style.BCStyle;
28 import org.onap.aaf.cadi.configure.CertException;
29 import org.onap.aaf.cadi.util.Split;
34 public ASN1ObjectIdentifier aoi;
35 public RDN(final String tagValue) throws CertException {
36 String[] tv = Split.splitTrim('=',tagValue);
38 case "cn":case "CN": aoi = BCStyle.CN;
40 case "c":case "C": aoi = BCStyle.C;
42 case "st":case "ST": aoi = BCStyle.ST;
44 case "l":case "L": aoi = BCStyle.L;
46 case "o":case "O": aoi = BCStyle.O;
48 case "ou":case "OU": aoi = BCStyle.OU;
50 case "dc":case "DC": aoi = BCStyle.DC;
52 case "gn":case "GN": aoi = BCStyle.GIVENNAME;
54 case "sn":case "SN": aoi = BCStyle.SN;
56 case "email":case "EMAIL":
58 case "EMAILADDRESS": aoi = BCStyle.EmailAddress;
59 break; // should be SAN extension
60 case "initials": aoi = BCStyle.INITIALS;
62 case "pseudonym": aoi = BCStyle.PSEUDONYM;
64 case "generationQualifier": aoi = BCStyle.GENERATION;
66 case "serialNumber": aoi = BCStyle.SERIALNUMBER;
69 throw new CertException("Unknown ASN1ObjectIdentifier for " + tv[0] + " in " + tagValue);
76 * Parse various forms of DNs into appropriate RDNs, which have the ASN1ObjectIdentifier
80 * @throws CertException
82 public static List<RDN> parse(final char delim, final String dnString ) throws CertException {
83 List<RDN> lrnd = new ArrayList<>();
84 StringBuilder sb = new StringBuilder();
85 boolean inQuotes = false;
86 for (int i=0;i<dnString.length();++i) {
87 char c = dnString.charAt(i);
92 sb.append(dnString.charAt(i));
97 } else if (delim==c) {
99 lrnd.add(new RDN(sb.toString()));
103 sb.append(dnString.charAt(i));
107 if (sb.indexOf("=")>0) {
108 lrnd.add(new RDN(sb.toString()));
114 public String toString() {
115 return tag + '=' + value;