1 /* 2 * Copyright (C) 2016 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 com.android.apksig.internal.util; 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.Provider; 25 import java.security.PublicKey; 26 import java.security.SignatureException; 27 import java.security.cert.CertificateEncodingException; 28 import java.security.cert.CertificateException; 29 import java.security.cert.CertificateExpiredException; 30 import java.security.cert.CertificateNotYetValidException; 31 import java.security.cert.CertificateParsingException; 32 import java.security.cert.X509Certificate; 33 import java.util.Collection; 34 import java.util.Date; 35 import java.util.List; 36 import java.util.Set; 37 38 import javax.security.auth.x500.X500Principal; 39 40 /** 41 * {@link X509Certificate} which delegates all method invocations to the provided delegate 42 * {@code X509Certificate}. 43 */ 44 public class DelegatingX509Certificate extends X509Certificate { 45 private static final long serialVersionUID = 1L; 46 47 private final X509Certificate mDelegate; 48 DelegatingX509Certificate(X509Certificate delegate)49 public DelegatingX509Certificate(X509Certificate delegate) { 50 this.mDelegate = delegate; 51 } 52 53 @Override getCriticalExtensionOIDs()54 public Set<String> getCriticalExtensionOIDs() { 55 return mDelegate.getCriticalExtensionOIDs(); 56 } 57 58 @Override getExtensionValue(String oid)59 public byte[] getExtensionValue(String oid) { 60 return mDelegate.getExtensionValue(oid); 61 } 62 63 @Override getNonCriticalExtensionOIDs()64 public Set<String> getNonCriticalExtensionOIDs() { 65 return mDelegate.getNonCriticalExtensionOIDs(); 66 } 67 68 @Override hasUnsupportedCriticalExtension()69 public boolean hasUnsupportedCriticalExtension() { 70 return mDelegate.hasUnsupportedCriticalExtension(); 71 } 72 73 @Override checkValidity()74 public void checkValidity() 75 throws CertificateExpiredException, CertificateNotYetValidException { 76 mDelegate.checkValidity(); 77 } 78 79 @Override checkValidity(Date date)80 public void checkValidity(Date date) 81 throws CertificateExpiredException, CertificateNotYetValidException { 82 mDelegate.checkValidity(date); 83 } 84 85 @Override getVersion()86 public int getVersion() { 87 return mDelegate.getVersion(); 88 } 89 90 @Override getSerialNumber()91 public BigInteger getSerialNumber() { 92 return mDelegate.getSerialNumber(); 93 } 94 95 @Override getIssuerDN()96 public Principal getIssuerDN() { 97 return mDelegate.getIssuerDN(); 98 } 99 100 @Override getSubjectDN()101 public Principal getSubjectDN() { 102 return mDelegate.getSubjectDN(); 103 } 104 105 @Override getNotBefore()106 public Date getNotBefore() { 107 return mDelegate.getNotBefore(); 108 } 109 110 @Override getNotAfter()111 public Date getNotAfter() { 112 return mDelegate.getNotAfter(); 113 } 114 115 @Override getTBSCertificate()116 public byte[] getTBSCertificate() throws CertificateEncodingException { 117 return mDelegate.getTBSCertificate(); 118 } 119 120 @Override getSignature()121 public byte[] getSignature() { 122 return mDelegate.getSignature(); 123 } 124 125 @Override getSigAlgName()126 public String getSigAlgName() { 127 return mDelegate.getSigAlgName(); 128 } 129 130 @Override getSigAlgOID()131 public String getSigAlgOID() { 132 return mDelegate.getSigAlgOID(); 133 } 134 135 @Override getSigAlgParams()136 public byte[] getSigAlgParams() { 137 return mDelegate.getSigAlgParams(); 138 } 139 140 @Override getIssuerUniqueID()141 public boolean[] getIssuerUniqueID() { 142 return mDelegate.getIssuerUniqueID(); 143 } 144 145 @Override getSubjectUniqueID()146 public boolean[] getSubjectUniqueID() { 147 return mDelegate.getSubjectUniqueID(); 148 } 149 150 @Override getKeyUsage()151 public boolean[] getKeyUsage() { 152 return mDelegate.getKeyUsage(); 153 } 154 155 @Override getBasicConstraints()156 public int getBasicConstraints() { 157 return mDelegate.getBasicConstraints(); 158 } 159 160 @Override getEncoded()161 public byte[] getEncoded() throws CertificateEncodingException { 162 return mDelegate.getEncoded(); 163 } 164 165 @Override verify(PublicKey key)166 public void verify(PublicKey key) throws CertificateException, NoSuchAlgorithmException, 167 InvalidKeyException, NoSuchProviderException, SignatureException { 168 mDelegate.verify(key); 169 } 170 171 @Override verify(PublicKey key, String sigProvider)172 public void verify(PublicKey key, String sigProvider) 173 throws CertificateException, NoSuchAlgorithmException, InvalidKeyException, 174 NoSuchProviderException, SignatureException { 175 mDelegate.verify(key, sigProvider); 176 } 177 178 @Override toString()179 public String toString() { 180 return mDelegate.toString(); 181 } 182 183 @Override getPublicKey()184 public PublicKey getPublicKey() { 185 return mDelegate.getPublicKey(); 186 } 187 188 @Override getIssuerX500Principal()189 public X500Principal getIssuerX500Principal() { 190 return mDelegate.getIssuerX500Principal(); 191 } 192 193 @Override getSubjectX500Principal()194 public X500Principal getSubjectX500Principal() { 195 return mDelegate.getSubjectX500Principal(); 196 } 197 198 @Override getExtendedKeyUsage()199 public List<String> getExtendedKeyUsage() throws CertificateParsingException { 200 return mDelegate.getExtendedKeyUsage(); 201 } 202 203 @Override getSubjectAlternativeNames()204 public Collection<List<?>> getSubjectAlternativeNames() throws CertificateParsingException { 205 return mDelegate.getSubjectAlternativeNames(); 206 } 207 208 @Override getIssuerAlternativeNames()209 public Collection<List<?>> getIssuerAlternativeNames() throws CertificateParsingException { 210 return mDelegate.getIssuerAlternativeNames(); 211 } 212 213 @Override 214 @SuppressWarnings("AndroidJdkLibsChecker") verify(PublicKey key, Provider sigProvider)215 public void verify(PublicKey key, Provider sigProvider) throws CertificateException, 216 NoSuchAlgorithmException, InvalidKeyException, SignatureException { 217 mDelegate.verify(key, sigProvider); 218 } 219 } 220