jdk/test/javax/crypto/EncryptedPrivateKeyInfo/GetKeySpecException.java
author kvn
Thu, 05 Dec 2013 15:13:12 -0800
changeset 22858 f4a6f0eba875
parent 10061 3b9bd67298ea
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
10061
3b9bd67298ea 7055362: jdk_security2 test target cleanup
weijun
parents: 5506
diff changeset
     2
 * Copyright (c) 2003, 2011, 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
10061
3b9bd67298ea 7055362: jdk_security2 test target cleanup
weijun
parents: 5506
diff changeset
    26
 * @bug 4508341 7055362
3b9bd67298ea 7055362: jdk_security2 test target cleanup
weijun
parents: 5506
diff changeset
    27
 * @library ../../../java/security/testlibrary
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * @summary Test the error conditions of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * EncryptedPrivateKeyInfo.getKeySpec(...) methods.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * @author Valerie Peng
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.security.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.util.Arrays;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.util.Vector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.security.spec.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import javax.crypto.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import javax.crypto.spec.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
public class GetKeySpecException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
    private static final String cipherAlg = "PBEWithMD5AndDES";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    private static final char[] passwd = { 'p','a','s','s','w','d' };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    private static SecretKey cipherKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    private static Cipher cipher = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    private static byte[] encryptedData = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    private static Provider sunjce = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    private static final SecretKey INVALID_KEY =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
        new SecretKeySpec(new byte[8], "DES");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    private static AlgorithmParameters BAD_PARAMS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    private static AlgorithmParameters GOOD_PARAMS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
            sunjce = Security.getProvider("SunJCE");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
            PBEParameterSpec badParamSpec =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
                new PBEParameterSpec(new byte[10], 10);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
            BAD_PARAMS = AlgorithmParameters.getInstance(cipherAlg, sunjce);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
            BAD_PARAMS.init(badParamSpec);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
            PBEParameterSpec goodParamSpec =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
                new PBEParameterSpec(new byte[8], 1024);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
            GOOD_PARAMS = AlgorithmParameters.getInstance(cipherAlg, sunjce);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
            GOOD_PARAMS.init(goodParamSpec);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
            PBEKeySpec keySpec = new PBEKeySpec(passwd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
            SecretKeyFactory skf =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
                SecretKeyFactory.getInstance(cipherAlg, "SunJCE");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
            cipherKey = skf.generateSecret(keySpec);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        } catch (Exception ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
            // should never happen
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
            BAD_PARAMS = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
            GOOD_PARAMS = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    private static void throwException(String msg) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        throw new Exception(msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    private static Provider[] removeProviders(String cipherAlg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        Vector providers = new Vector();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        boolean done = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        while (!done) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
                Cipher c = Cipher.getInstance(cipherAlg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
                Provider p = c.getProvider();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
                providers.add(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
                Security.removeProvider(p.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
            } catch (NoSuchAlgorithmException nsae) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
                done = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            } catch (NoSuchPaddingException nspe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
                // should never happen
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        return (Provider[]) (providers.toArray(new Provider[0]));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    private static void addProviders(Provider[] provs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        for (int i=0; i<provs.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            Security.addProvider(provs[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
10061
3b9bd67298ea 7055362: jdk_security2 test target cleanup
weijun
parents: 5506
diff changeset
   101
    public static void main(String[] args) throws Exception {
3b9bd67298ea 7055362: jdk_security2 test target cleanup
weijun
parents: 5506
diff changeset
   102
        ProvidersSnapshot snapshot = ProvidersSnapshot.create();
3b9bd67298ea 7055362: jdk_security2 test target cleanup
weijun
parents: 5506
diff changeset
   103
        try {
3b9bd67298ea 7055362: jdk_security2 test target cleanup
weijun
parents: 5506
diff changeset
   104
            main0(args);
3b9bd67298ea 7055362: jdk_security2 test target cleanup
weijun
parents: 5506
diff changeset
   105
        } finally {
3b9bd67298ea 7055362: jdk_security2 test target cleanup
weijun
parents: 5506
diff changeset
   106
            snapshot.restore();
3b9bd67298ea 7055362: jdk_security2 test target cleanup
weijun
parents: 5506
diff changeset
   107
        }
3b9bd67298ea 7055362: jdk_security2 test target cleanup
weijun
parents: 5506
diff changeset
   108
    }
3b9bd67298ea 7055362: jdk_security2 test target cleanup
weijun
parents: 5506
diff changeset
   109
3b9bd67298ea 7055362: jdk_security2 test target cleanup
weijun
parents: 5506
diff changeset
   110
    public static void main0(String[] args) throws Exception {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        if ((GOOD_PARAMS == null) || (BAD_PARAMS == null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            throw new Exception("Static parameter generation failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        // use random data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        byte[] encryptedData = new byte[30];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        encryptedData[20] = (byte) 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        PKCS8EncodedKeySpec pkcs8Spec = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        // generate encrypted data and EncryptedPrivateKeyInfo objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        EncryptedPrivateKeyInfo epki =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            new EncryptedPrivateKeyInfo(GOOD_PARAMS, encryptedData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        EncryptedPrivateKeyInfo epkiBad =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            new EncryptedPrivateKeyInfo(BAD_PARAMS, encryptedData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        // TEST#1: getKeySpec(Cipher)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        System.out.println("Testing getKeySpec(Cipher)...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            pkcs8Spec = epki.getKeySpec((Cipher) null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            throwException("Should throw NPE for null Cipher!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        } catch (NullPointerException npe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            System.out.println("Expected NPE thrown");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        // TEST#2: getKeySpec(Key)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        System.out.println("Testing getKeySpec(Key)...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            pkcs8Spec = epki.getKeySpec((Key) null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            throwException("Should throw NPE for null Key!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        } catch (NullPointerException npe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            System.out.println("Expected NPE thrown");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            pkcs8Spec = epki.getKeySpec(INVALID_KEY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
            throwException("Should throw IKE for invalid Key!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        } catch (InvalidKeyException ikse) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            System.out.println("Expected IKE thrown");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            pkcs8Spec = epkiBad.getKeySpec(cipherKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            throwException("Should throw IKE for corrupted epki!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        } catch (InvalidKeyException ike) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            System.out.println("Expected IKE thrown");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        Provider[] removedProvs = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
            removedProvs = removeProviders(cipherAlg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            pkcs8Spec = epki.getKeySpec(cipherKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
            throwException("Should throw NSAE if no matching impl!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        } catch (NoSuchAlgorithmException nsae) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            System.out.println("Expected NSAE thrown");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            addProviders(removedProvs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        // TEST#3: getKeySpec(Key, String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        System.out.println("Testing getKeySpec(Key, String)...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            pkcs8Spec = epki.getKeySpec(null, "SunJCE");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            throwException("Should throw NPE for null Key!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        } catch (NullPointerException npe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            System.out.println("Expected NPE thrown");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            pkcs8Spec = epki.getKeySpec(cipherKey, (String)null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            throwException("Should throw NPE for null String!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        } catch (NullPointerException npe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            System.out.println("Expected NPE thrown");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            pkcs8Spec = epki.getKeySpec(INVALID_KEY, "SunJCE");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            throwException("Should throw IKE for invalid Key!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        } catch (InvalidKeyException ikse) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            System.out.println("Expected IKE thrown");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            pkcs8Spec = epkiBad.getKeySpec(cipherKey, "SunJCE");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            throwException("Should throw IKE for corrupted epki!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        } catch (InvalidKeyException ike) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            System.out.println("Expected IKE thrown");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            pkcs8Spec = epki.getKeySpec(cipherKey, "SUN");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            throwException("Should throw NSAE for provider without " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                           "matching implementation!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        } catch (NoSuchAlgorithmException nsae) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            System.out.println("Expected NSAE thrown");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            Security.removeProvider("SunJCE");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            pkcs8Spec = epki.getKeySpec(cipherKey, "SunJCE");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            throwException("Should throw NSPE for unconfigured provider!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        } catch (NoSuchProviderException nspe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            System.out.println("Expected NSPE thrown");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            Security.addProvider(sunjce);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        // TEST#4: getKeySpec(Key, Provider)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        System.out.println("Testing getKeySpec(Key, Provider)...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            pkcs8Spec = epki.getKeySpec(null, sunjce);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            throwException("Should throw NPE for null Key!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        } catch (NullPointerException npe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            System.out.println("Expected NPE thrown");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
            pkcs8Spec = epki.getKeySpec(cipherKey, (Provider)null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            throwException("Should throw NPE for null Provider!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        } catch (NullPointerException npe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            System.out.println("Expected NPE thrown");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            pkcs8Spec = epki.getKeySpec(INVALID_KEY, sunjce);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            throwException("Should throw IKE for invalid Key!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        } catch (InvalidKeyException ikse) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            System.out.println("Expected IKE thrown");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            pkcs8Spec = epkiBad.getKeySpec(cipherKey, sunjce);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            throwException("Should throw IKE for corrupted epki!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        } catch (InvalidKeyException ike) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            System.out.println("Expected IKE thrown");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        System.out.println("All Tests Passed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
}