jdk/test/javax/crypto/JceSecurity/MyX509CertImpl.java
author prr
Thu, 18 Dec 2014 10:45:45 -0800
changeset 29908 83e2c403fefd
parent 5506 202f599c92aa
permissions -rw-r--r--
8067050: Better font consistency checking Reviewed-by: bae, srl, mschoene
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 2006, 2007, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * @bug 6377058
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * @summary SunJCE depends on sun.security.provider.SignatureImpl
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * behaviour, BC can't load into 1st slot.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * @author Brad R. Wetmore
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.math.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.security.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.security.cert.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import javax.security.auth.x500.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
public class MyX509CertImpl extends X509Certificate
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
        implements X509Extension {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    X509Certificate c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    protected MyX509CertImpl(X509Certificate cert) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
        c = cert;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    public void checkValidity() throws CertificateExpiredException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
            CertificateNotYetValidException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
        c.checkValidity();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    public void checkValidity(Date date) throws CertificateExpiredException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
            CertificateNotYetValidException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        c.checkValidity(date);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    public int getVersion() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        return c.getVersion();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    public BigInteger getSerialNumber() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        return c.getSerialNumber();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    public Principal getIssuerDN() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        return c.getIssuerDN();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    public X500Principal getIssuerX500Principal() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        return c.getIssuerX500Principal();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    public Principal getSubjectDN() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        return c.getSubjectDN();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    public X500Principal getSubjectX500Principal() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        return c.getSubjectX500Principal();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    public Date getNotBefore() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        return c.getNotBefore();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    public Date getNotAfter() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        return c.getNotAfter();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    public byte[] getTBSCertificate()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        throws CertificateEncodingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        return c.getTBSCertificate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    public byte[] getSignature() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        return c.getSignature();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    public String getSigAlgName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        return c.getSigAlgName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    public String getSigAlgOID() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        return c.getSigAlgOID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    public byte[] getSigAlgParams() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        return c.getSigAlgParams();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    public boolean[] getIssuerUniqueID() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        return c.getIssuerUniqueID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    public boolean[] getSubjectUniqueID() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        return c.getSubjectUniqueID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    public boolean[] getKeyUsage() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        return c.getKeyUsage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    public List<String> getExtendedKeyUsage()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            throws CertificateParsingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        return c.getExtendedKeyUsage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    public int getBasicConstraints() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        return c.getBasicConstraints();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    public Collection<List<?>> getSubjectAlternativeNames()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        throws CertificateParsingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        return c.getSubjectAlternativeNames();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    public Collection<List<?>> getIssuerAlternativeNames()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        throws CertificateParsingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        return c.getIssuerAlternativeNames();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * The following are from X509Extension
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    public boolean hasUnsupportedCriticalExtension() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        return c.hasUnsupportedCriticalExtension();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    public Set<String> getCriticalExtensionOIDs() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        return c.getCriticalExtensionOIDs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    public Set<String> getNonCriticalExtensionOIDs() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        return c.getNonCriticalExtensionOIDs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    public byte[] getExtensionValue(String oid) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        return c.getExtensionValue(oid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * The rest are from Certificate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    public boolean equals(Object other) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        return c.equals(other);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        return c.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    public byte[] getEncoded()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            throws CertificateEncodingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        return c.getEncoded();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    public void verify(PublicKey key)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            throws CertificateException, NoSuchAlgorithmException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            InvalidKeyException, NoSuchProviderException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            SignatureException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        System.out.println("Trying a verify");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            c.verify(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        } catch (SignatureException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            System.out.println("Rethrowing \"acceptable\" exception");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            throw new InvalidKeyException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                "Rethrowing as a SignatureException", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    public void verify(PublicKey key, String sigProvider)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            throws CertificateException, NoSuchAlgorithmException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            InvalidKeyException, NoSuchProviderException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            SignatureException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        System.out.println("Trying a verify");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            c.verify(key, sigProvider);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        } catch (SignatureException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
            System.out.println("Rethrowing \"acceptable\" exception");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            throw new InvalidKeyException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                "Rethrowing as a SignatureException", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        return c.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    public PublicKey getPublicKey() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        return c.getPublicKey();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
}