Path: blob/master/test/jdk/javax/crypto/JceSecurity/MyX509CertImpl.java
41149 views
/*1* Copyright (c) 2006, 2007, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* test25* @bug 637705826* @summary SunJCE depends on sun.security.provider.SignatureImpl27* behaviour, BC can't load into 1st slot.28* @author Brad R. Wetmore29*/303132import java.util.*;33import java.math.*;34import java.security.*;35import java.security.cert.*;36import javax.security.auth.x500.*;3738public class MyX509CertImpl extends X509Certificate39implements X509Extension {4041X509Certificate c;4243protected MyX509CertImpl(X509Certificate cert) {44c = cert;45}4647public void checkValidity() throws CertificateExpiredException,48CertificateNotYetValidException {49c.checkValidity();50}515253public void checkValidity(Date date) throws CertificateExpiredException,54CertificateNotYetValidException {55c.checkValidity(date);56}5758public int getVersion() {59return c.getVersion();60}6162public BigInteger getSerialNumber() {63return c.getSerialNumber();64}6566public Principal getIssuerDN() {67return c.getIssuerDN();68}6970public X500Principal getIssuerX500Principal() {71return c.getIssuerX500Principal();72}7374public Principal getSubjectDN() {75return c.getSubjectDN();76}7778public X500Principal getSubjectX500Principal() {79return c.getSubjectX500Principal();80}8182public Date getNotBefore() {83return c.getNotBefore();84}8586public Date getNotAfter() {87return c.getNotAfter();88}8990public byte[] getTBSCertificate()91throws CertificateEncodingException {92return c.getTBSCertificate();93}9495public byte[] getSignature() {96return c.getSignature();97}9899public String getSigAlgName() {100return c.getSigAlgName();101}102103public String getSigAlgOID() {104return c.getSigAlgOID();105}106107public byte[] getSigAlgParams() {108return c.getSigAlgParams();109}110111public boolean[] getIssuerUniqueID() {112return c.getIssuerUniqueID();113}114115public boolean[] getSubjectUniqueID() {116return c.getSubjectUniqueID();117}118119public boolean[] getKeyUsage() {120return c.getKeyUsage();121}122123public List<String> getExtendedKeyUsage()124throws CertificateParsingException {125return c.getExtendedKeyUsage();126}127128public int getBasicConstraints() {129return c.getBasicConstraints();130}131132public Collection<List<?>> getSubjectAlternativeNames()133throws CertificateParsingException {134return c.getSubjectAlternativeNames();135}136137public Collection<List<?>> getIssuerAlternativeNames()138throws CertificateParsingException {139return c.getIssuerAlternativeNames();140}141142/*143* The following are from X509Extension144*/145public boolean hasUnsupportedCriticalExtension() {146return c.hasUnsupportedCriticalExtension();147}148149public Set<String> getCriticalExtensionOIDs() {150return c.getCriticalExtensionOIDs();151}152153public Set<String> getNonCriticalExtensionOIDs() {154return c.getNonCriticalExtensionOIDs();155}156157public byte[] getExtensionValue(String oid) {158return c.getExtensionValue(oid);159}160161/*162* The rest are from Certificate163*/164public boolean equals(Object other) {165return c.equals(other);166}167168public int hashCode() {169return c.hashCode();170}171172public byte[] getEncoded()173throws CertificateEncodingException {174return c.getEncoded();175}176177public void verify(PublicKey key)178throws CertificateException, NoSuchAlgorithmException,179InvalidKeyException, NoSuchProviderException,180SignatureException {181System.out.println("Trying a verify");182try {183c.verify(key);184} catch (SignatureException e) {185System.out.println("Rethrowing \"acceptable\" exception");186throw new InvalidKeyException(187"Rethrowing as a SignatureException", e);188}189}190191public void verify(PublicKey key, String sigProvider)192throws CertificateException, NoSuchAlgorithmException,193InvalidKeyException, NoSuchProviderException,194SignatureException {195196System.out.println("Trying a verify");197try {198c.verify(key, sigProvider);199} catch (SignatureException e) {200System.out.println("Rethrowing \"acceptable\" exception");201throw new InvalidKeyException(202"Rethrowing as a SignatureException", e);203}204}205206public String toString() {207return c.toString();208}209210public PublicKey getPublicKey() {211return c.getPublicKey();212}213}214215216