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.cm.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; break;
39 case "c":case "C": aoi = BCStyle.C;break;
40 case "st":case "ST": aoi = BCStyle.ST;break;
41 case "l":case "L": aoi = BCStyle.L;break;
42 case "o":case "O": aoi = BCStyle.O;break;
43 case "ou":case "OU": aoi = BCStyle.OU;break;
44 case "dc":case "DC": aoi = BCStyle.DC;break;
45 case "gn":case "GN": aoi = BCStyle.GIVENNAME; break;
46 case "sn":case "SN": aoi = BCStyle.SN; break; // surname
47 case "email":case "EMAIL":
49 case "EMAILADDRESS": aoi = BCStyle.EmailAddress;break; // should be SAN extension
50 case "initials": aoi = BCStyle.INITIALS; break;
51 case "pseudonym": aoi = BCStyle.PSEUDONYM; break;
52 case "generationQualifier": aoi = BCStyle.GENERATION; break;
53 case "serialNumber": aoi = BCStyle.SERIALNUMBER; break;
55 throw new CertException("Unknown ASN1ObjectIdentifier for " + tv[0]);
62 * Parse various forms of DNs into appropriate RDNs, which have the ASN1ObjectIdentifier
66 * @throws CertException
68 public static List<RDN> parse(final char delim, final String dnString ) throws CertException {
69 List<RDN> lrnd = new ArrayList<RDN>();
70 StringBuilder sb = new StringBuilder();
71 boolean inQuotes = false;
72 for(int i=0;i<dnString.length();++i) {
73 char c = dnString.charAt(i);
78 sb.append(dnString.charAt(i));
84 lrnd.add(new RDN(sb.toString()));
87 sb.append(dnString.charAt(i));
91 if(sb.indexOf("=")>0) {
92 lrnd.add(new RDN(sb.toString()));
98 public String toString() {
99 return tag + '=' + value;