9017763a514b3e4955fe2cd960de1f1a9a1f047f
[aaf/authz.git] / auth / auth-certman / src / main / java / org / onap / aaf / auth / cm / data / CertResp.java
1 /**
2  * ============LICENSE_START====================================================
3  * org.onap.aaf
4  * ===========================================================================
5  * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
6  *
7  * Modifications Copyright (C) 2018 IBM.
8  * ===========================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  * 
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  * 
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * ============LICENSE_END====================================================
21  *
22  */
23
24 package org.onap.aaf.auth.cm.data;
25
26 import java.io.IOException;
27 import java.security.KeyPair;
28 import java.security.cert.X509Certificate;
29
30 import org.onap.aaf.auth.cm.ca.CA;
31 import org.onap.aaf.auth.cm.cert.CSRMeta;
32 import org.onap.aaf.cadi.configure.CertException;
33 import org.onap.aaf.cadi.configure.Factory;
34 import org.onap.aaf.misc.env.Trans;
35
36 public class CertResp {
37     private CA ca;
38     private KeyPair keyPair;
39     private String challenge;
40     
41     private String privateKey;
42     private String certString;
43     private String[] trustChain;
44     private String[] notes;
45     
46     public CertResp(Trans trans, CA ca, X509Certificate x509, CSRMeta csrMeta, String[] trustChain, String[] notes) throws IOException, CertException {
47         keyPair = csrMeta.keypair(trans);
48         privateKey = Factory.toString(trans, keyPair.getPrivate());
49         certString = Factory.toString(trans,x509);
50         challenge=csrMeta.challenge();
51         this.ca = ca;
52         this.trustChain = trustChain;
53         this.notes = notes;
54     }
55
56     // Use for Read Responses, etc
57     public CertResp(String cert) {
58         certString = cert;
59     }
60
61     
62     public String asCertString() {
63         return certString;
64     }
65     
66     public String privateString() {
67         return privateKey;
68     }
69     
70     public String challenge() {
71         return challenge==null?"":challenge;
72     }
73     
74     public String[] notes() {
75         return notes;
76     }
77     
78     public String[] caIssuerDNs() {
79         return ca.getCaIssuerDNs();
80     }
81     
82     public String env() {
83         return ca.getEnv();
84     }
85     
86     public String[] trustChain() {
87         return trustChain;
88     }
89     
90     public String[] trustCAs() {
91         return ca.getTrustedCAs();
92     }
93 }