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