1 /*
2  * Copyright (C) 2015 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package android.security.keystore;
18 
19 import java.math.BigInteger;
20 import java.security.InvalidKeyException;
21 import java.security.NoSuchAlgorithmException;
22 import java.security.NoSuchProviderException;
23 import java.security.Principal;
24 import java.security.PublicKey;
25 import java.security.SignatureException;
26 import java.security.cert.CertificateEncodingException;
27 import java.security.cert.CertificateException;
28 import java.security.cert.CertificateExpiredException;
29 import java.security.cert.CertificateNotYetValidException;
30 import java.security.cert.CertificateParsingException;
31 import java.security.cert.X509Certificate;
32 import java.util.Collection;
33 import java.util.Date;
34 import java.util.List;
35 import java.util.Set;
36 
37 import javax.security.auth.x500.X500Principal;
38 
39 class DelegatingX509Certificate extends X509Certificate {
40     private final X509Certificate mDelegate;
41 
DelegatingX509Certificate(X509Certificate delegate)42     DelegatingX509Certificate(X509Certificate delegate) {
43         mDelegate = delegate;
44     }
45 
46     @Override
getCriticalExtensionOIDs()47     public Set<String> getCriticalExtensionOIDs() {
48         return mDelegate.getCriticalExtensionOIDs();
49     }
50 
51     @Override
getExtensionValue(String oid)52     public byte[] getExtensionValue(String oid) {
53         return mDelegate.getExtensionValue(oid);
54     }
55 
56     @Override
getNonCriticalExtensionOIDs()57     public Set<String> getNonCriticalExtensionOIDs() {
58         return mDelegate.getNonCriticalExtensionOIDs();
59     }
60 
61     @Override
hasUnsupportedCriticalExtension()62     public boolean hasUnsupportedCriticalExtension() {
63         return mDelegate.hasUnsupportedCriticalExtension();
64     }
65 
66     @Override
checkValidity()67     public void checkValidity() throws CertificateExpiredException,
68             CertificateNotYetValidException {
69         mDelegate.checkValidity();
70     }
71 
72     @Override
checkValidity(Date date)73     public void checkValidity(Date date) throws CertificateExpiredException,
74             CertificateNotYetValidException {
75         mDelegate.checkValidity(date);
76     }
77 
78     @Override
getBasicConstraints()79     public int getBasicConstraints() {
80         return mDelegate.getBasicConstraints();
81     }
82 
83     @Override
getIssuerDN()84     public Principal getIssuerDN() {
85         return mDelegate.getIssuerDN();
86     }
87 
88     @Override
getIssuerUniqueID()89     public boolean[] getIssuerUniqueID() {
90         return mDelegate.getIssuerUniqueID();
91     }
92 
93     @Override
getKeyUsage()94     public boolean[] getKeyUsage() {
95         return mDelegate.getKeyUsage();
96     }
97 
98     @Override
getNotAfter()99     public Date getNotAfter() {
100         return mDelegate.getNotAfter();
101     }
102 
103     @Override
getNotBefore()104     public Date getNotBefore() {
105         return mDelegate.getNotBefore();
106     }
107 
108     @Override
getSerialNumber()109     public BigInteger getSerialNumber() {
110         return mDelegate.getSerialNumber();
111     }
112 
113     @Override
getSigAlgName()114     public String getSigAlgName() {
115         return mDelegate.getSigAlgName();
116     }
117 
118     @Override
getSigAlgOID()119     public String getSigAlgOID() {
120         return mDelegate.getSigAlgOID();
121     }
122 
123     @Override
getSigAlgParams()124     public byte[] getSigAlgParams() {
125         return mDelegate.getSigAlgParams();
126     }
127 
128     @Override
getSignature()129     public byte[] getSignature() {
130         return mDelegate.getSignature();
131     }
132 
133     @Override
getSubjectDN()134     public Principal getSubjectDN() {
135         return mDelegate.getSubjectDN();
136     }
137 
138     @Override
getSubjectUniqueID()139     public boolean[] getSubjectUniqueID() {
140         return mDelegate.getSubjectUniqueID();
141     }
142 
143     @Override
getTBSCertificate()144     public byte[] getTBSCertificate() throws CertificateEncodingException {
145         return mDelegate.getTBSCertificate();
146     }
147 
148     @Override
getVersion()149     public int getVersion() {
150         return mDelegate.getVersion();
151     }
152 
153     @Override
getEncoded()154     public byte[] getEncoded() throws CertificateEncodingException {
155         return mDelegate.getEncoded();
156     }
157 
158     @Override
getPublicKey()159     public PublicKey getPublicKey() {
160         return mDelegate.getPublicKey();
161     }
162 
163     @Override
toString()164     public String toString() {
165         return mDelegate.toString();
166     }
167 
168     @Override
verify(PublicKey key)169     public void verify(PublicKey key)
170             throws CertificateException,
171             NoSuchAlgorithmException,
172             InvalidKeyException,
173             NoSuchProviderException,
174             SignatureException {
175         mDelegate.verify(key);
176     }
177 
178     @Override
verify(PublicKey key, String sigProvider)179     public void verify(PublicKey key, String sigProvider)
180             throws CertificateException,
181             NoSuchAlgorithmException,
182             InvalidKeyException,
183             NoSuchProviderException,
184             SignatureException {
185         mDelegate.verify(key, sigProvider);
186     }
187 
188     @Override
getExtendedKeyUsage()189     public List<String> getExtendedKeyUsage() throws CertificateParsingException {
190         return mDelegate.getExtendedKeyUsage();
191     }
192 
193     @Override
getIssuerAlternativeNames()194     public Collection<List<?>> getIssuerAlternativeNames() throws CertificateParsingException {
195         return mDelegate.getIssuerAlternativeNames();
196     }
197 
198     @Override
getIssuerX500Principal()199     public X500Principal getIssuerX500Principal() {
200         return mDelegate.getIssuerX500Principal();
201     }
202 
203     @Override
getSubjectAlternativeNames()204     public Collection<List<?>> getSubjectAlternativeNames() throws CertificateParsingException {
205         return mDelegate.getSubjectAlternativeNames();
206     }
207 
208     @Override
getSubjectX500Principal()209     public X500Principal getSubjectX500Principal() {
210         return mDelegate.getSubjectX500Principal();
211     }
212 }
213