jdk/test/java/security/KeyStore/EntryMethods.java
author mcimadamore
Wed, 31 Aug 2011 16:11:28 +0100
changeset 10452 c8f32009b413
parent 5506 202f599c92aa
child 31422 67cd03bc9cce
permissions -rw-r--r--
7085024: internal error; cannot instantiate Foo Summary: Types.isConvertible does not handle erroneous types correctly Reviewed-by: jjg
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) 2003, 2004, 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 1.5, 03/06/24
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * @bug 4850376
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * @summary Provide generic storage KeyStore storage facilities
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.security.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.security.cert.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import sun.security.provider.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
public class EntryMethods
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
    extends Provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
    implements KeyStore.Entry
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    private static FileInputStream pre15fis;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    private static char[] password = {'f', 'o', 'o', 'b', 'a', 'r'};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    private static char[] badPwd = {'b', 'a', 'd', 'p', 'w', 'd'};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    public static class FooProtect implements KeyStore.ProtectionParameter { }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    public static class FooParameter implements KeyStore.LoadStoreParameter {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
        public KeyStore.ProtectionParameter getProtectionParameter() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    public static class FooEntry implements KeyStore.Entry { }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    public EntryMethods() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        super("EntryMethods", 0.0, "EntryMethods");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        pre15fis = new FileInputStream
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
            (System.getProperty("test.src") + "/EntryMethods.pre15.keystore");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        AccessController.doPrivileged(new PrivilegedAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
            public Object run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
                put("KeyStore.Pre15KeyStore", "EntryMethods$Pre15");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
                put("KeyStore.Post15KeyStore", "EntryMethods$Post15");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
                put("KeyStore.UnrecoverableKeyStore",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
                                        "EntryMethods$UnrecoverableKS");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        });
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    public static void main(String[] args) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        EntryMethods entry = new EntryMethods();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        // test pre-JDK1.5 KeyStore throws UnsupportedOperationExceptions
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        // for new methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        KeyStore pre15KS = KeyStore.getInstance("Pre15KeyStore", entry);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        testPre15(pre15KS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        // test post-JDK1.5 KeyStore does right thing with new methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        KeyStore post15KS = KeyStore.getInstance("Post15KeyStore", entry);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        testPost15(post15KS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        // test post-JDK1.5 KeyStore can throw new UnrecoverableEntryException
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        KeyStore uKS = KeyStore.getInstance("UnrecoverableKeyStore", entry);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        testUnrecoverable(uKS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    private static void testPre15(KeyStore ks) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        int tNum = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        KeyStore.Entry e = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        // TEST load null param
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        ks.load((KeyStore.LoadStoreParameter)null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        System.out.println("[Pre1.5] test " + tNum++ + " passed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        // TEST load random param
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            ks.load(new FooParameter());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            throw new SecurityException("[Pre1.5] test " + tNum + " failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        } catch (UnsupportedOperationException uoe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            System.out.println("[Pre1.5] test " + tNum++ + " passed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        // TEST store random param
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        ks.load(pre15fis, password);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        // setup for later user
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        KeyStore.Entry pkeNew = ks.getEntry("privkey",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                                new KeyStore.PasswordProtection(password));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        KeyStore.Entry tceNew = ks.getEntry("trustedcert", null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            ks.store(new FooParameter());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            throw new SecurityException("[Pre1.5] test " + tNum + " failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        } catch (UnsupportedOperationException uoe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            // good
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            System.out.println("[Pre1.5] test " + tNum++ + " passed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        // TEST store null param
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            ks.store(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            throw new SecurityException("[Pre1.5] test " + tNum + " failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        } catch (UnsupportedOperationException uoe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            // good
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            System.out.println("[Pre1.5] test " + tNum++ + " passed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        // TEST getEntry with alias/protParam - use invalid alias
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        e = ks.getEntry("notPresent",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
                        new KeyStore.PasswordProtection(password));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        if (e == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            System.out.println("[Pre1.5] test " + tNum++ + " passed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            throw new SecurityException("[Pre1.5] test " + tNum + " failed - " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                                "expected null entry returned");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        // TEST getEntry with alias/null protParam - get private key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            e = ks.getEntry("privkey", null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            throw new SecurityException("[Pre1.5] test " + tNum + " failed - " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                                "expected UnrecoverableEntryException");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        } catch (UnrecoverableEntryException uee) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            System.out.println("[Pre1.5] test " + tNum++ + " passed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        // TEST getEntry with alias/bad password - get private key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
            e = ks.getEntry("privkey",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                        new KeyStore.PasswordProtection(badPwd));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            throw new SecurityException("[Pre1.5] test " + tNum + " failed - " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                                "expected UnrecoverableEntryException");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        } catch (UnrecoverableEntryException uee) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            System.out.println("[Pre1.5] test " + tNum++ + " passed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        // TEST getEntry with alias/unknown protection - get private key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            e = ks.getEntry("privkey", new FooProtect());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            throw new SecurityException("[Pre1.5] test " + tNum + " failed - " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                                "expected UnsupportedOperationException");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        } catch (UnsupportedOperationException uoe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            System.out.println("[Pre1.5] test " + tNum++ + " passed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        // TEST getEntry with alias/protParam - get private key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        e = ks.getEntry("privkey", new KeyStore.PasswordProtection(password));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        if (e instanceof KeyStore.PrivateKeyEntry) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            System.out.println("[Pre1.5] test " + tNum++ + " passed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            throw new SecurityException("[Pre1.5] test " + tNum + " failed - " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                                "expected PrivateKeyEntry");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        // TEST getEntry with alias/null protParam - get trusted cert
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        e = ks.getEntry("trustedcert", null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        if (e instanceof KeyStore.TrustedCertificateEntry) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            System.out.println("[Pre1.5] test " + tNum++ + " passed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            throw new SecurityException("[Pre1.5] test " + tNum + " failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        // TEST getEntry with alias/non-null protParam - get trusted cert
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            e = ks.getEntry("trustedcert",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                        new KeyStore.PasswordProtection(password));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
            throw new SecurityException("[Pre1.5] test " + tNum + " failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        } catch (UnsupportedOperationException uoe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            System.out.println("[Pre1.5] test " + tNum++ + " passed");
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
        // TEST setEntry with alias/entry/protParam - use invalid alias
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            ks.setEntry("foo", new FooEntry(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                        new KeyStore.PasswordProtection(password));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            throw new SecurityException("[Pre1.5] test " + tNum + " failed - " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                                "expected KeyStoreException");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        } catch (KeyStoreException kse) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
            // good
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            System.out.println("[Pre1.5] test " + tNum++ + " passed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        // TEST setEntry with alias/entry/null protParam - set private key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            ks.setEntry("newPrivKey", pkeNew, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            throw new SecurityException("[Pre1.5] test " + tNum + " failed - " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                                "expected KeyStoreException");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        } catch (KeyStoreException kse) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            System.out.println("[Pre1.5] test " + tNum++ + " passed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        // TEST setEntry with alias/entry/random protParam - set private key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            ks.setEntry("newPrivKey", pkeNew, new FooProtect());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            throw new SecurityException("[Pre1.5] test " + tNum + " failed - " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                                "expected KeyStoreException");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        } catch (KeyStoreException kse) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            System.out.println("[Pre1.5] test " + tNum++ + " passed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        // TEST setEntry with alias/entry/protParam - set private key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        ks.setEntry("newPrivKey", pkeNew,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                        new KeyStore.PasswordProtection(password));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        e = ks.getEntry("newPrivKey",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                        new KeyStore.PasswordProtection(password));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        if (e instanceof KeyStore.PrivateKeyEntry) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            System.out.println("[Pre1.5] test " + tNum++ + " passed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            throw new SecurityException("[Pre1.5] test " + tNum + " failed - " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                                "expected PrivateKeyEntry");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        // TEST setEntry with alias/entry/non null protParam - set trusted cert
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            ks.setEntry("newTrustedcert", tceNew,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                        new KeyStore.PasswordProtection(password));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
            throw new SecurityException("[Pre1.5] test " + tNum + " failed - " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                                "expected KeyStoreException");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        } catch (KeyStoreException kse) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
            // good
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
            System.out.println("[Pre1.5] test " + tNum++ + " passed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        // TEST setEntry with alias/entry/null protParam - set trusted cert
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        ks.setEntry("newTrustedcert", tceNew, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        e = ks.getEntry("newTrustedcert", null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        if (e instanceof KeyStore.TrustedCertificateEntry) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
            System.out.println("[Pre1.5] test " + tNum++ + " passed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
            throw new SecurityException("[Pre1.5] test " + tNum + " failed - " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                                "expected TrustedCertificateEntry");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        // TEST entryInstanceOf - invalid alias
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        if (ks.entryInstanceOf("foo", EntryMethods.class) == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
            System.out.println("[Pre1.5] test " + tNum++ + " passed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            throw new SecurityException("[Pre1.5] test " + tNum + " failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        // TEST entryInstanceOf - false case
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        if (ks.entryInstanceOf("privkey", EntryMethods.class) == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            System.out.println("[Pre1.5] test " + tNum++ + " passed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            throw new SecurityException("[Pre1.5] test " + tNum + " failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        // TEST entryInstanceOf - true case, trustedcert entry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        if (ks.entryInstanceOf("trustedcert",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                                KeyStore.TrustedCertificateEntry.class)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
            System.out.println("[Pre1.5] test " + tNum++ + " passed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            throw new SecurityException("[Pre1.5] test " + tNum + " failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        // TEST entryInstanceOf - true case, private key entry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        if (ks.entryInstanceOf("privkey",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
                                KeyStore.PrivateKeyEntry.class)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
            System.out.println("[Pre1.5] test " + tNum++ + " passed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
            throw new SecurityException("[Pre1.5] test " + tNum + " failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    private static void testPost15(KeyStore ks) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        KeyStore.Entry e = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        ks.load(new EntryMethods.FooParameter());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        ks.store(new EntryMethods.FooParameter());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        e = ks.getEntry("foo", new KeyStore.PasswordProtection(password));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        if (!(e instanceof EntryMethods.FooEntry)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
            throw new SecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
                        ("testPost15 getEntry(String, ProtParm) " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
                        "expected EntryMethods.FooEntry returned");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        ks.setEntry("foo", new EntryMethods.FooEntry(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
                        new KeyStore.PasswordProtection(password));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        if (!ks.entryInstanceOf("foo", KeyStore.PrivateKeyEntry.class)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
            throw new SecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
                        ("testPost15 entryInstanceOf(String, Class) " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
                        "expected true returned");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        System.out.println("[Post1.5] tests all passed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    private static void testUnrecoverable(KeyStore ks) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        ks.load(new EntryMethods.FooParameter());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
            ks.getEntry("foo", new KeyStore.PasswordProtection(password));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
            throw new SecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
                ("UnrecoverableEntryException not thrown for " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
                "getEntry(String, ProtectionParam)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        } catch (UnrecoverableEntryException uee) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
            // good
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
            System.out.println("[UnrecoverableEntry] test passed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    public static class Pre15 extends KeyStoreSpi {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        private static KeyStoreSpi jks = getJKS();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        // javac does not allow direct access to class (javac bug?)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        // use reflection instead
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        private static KeyStoreSpi getJKS() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
                Class clazz = Class.forName("sun.security.provider.JavaKeyStore$JKS");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
                return (KeyStoreSpi)clazz.newInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
            } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
                e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
                throw new RuntimeException(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        public Key engineGetKey(String alias, char[] password)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
            throws NoSuchAlgorithmException, UnrecoverableKeyException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
            return jks.engineGetKey(alias, password);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        public java.security.cert.Certificate[] engineGetCertificateChain
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
                (String alias) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
            return jks.engineGetCertificateChain(alias);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        public java.security.cert.Certificate engineGetCertificate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
                (String alias) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
            return jks.engineGetCertificate(alias);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        public Date engineGetCreationDate(String alias) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
            return jks.engineGetCreationDate(alias);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        public void engineSetKeyEntry(String alias, Key key,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
                                   char[] password,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
                                   java.security.cert.Certificate[] chain)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
            throws KeyStoreException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
            jks.engineSetKeyEntry(alias, key, password, chain);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        public void engineSetKeyEntry(String alias, byte[] key,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
                                   java.security.cert.Certificate[] chain)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
            throws KeyStoreException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
            jks.engineSetKeyEntry(alias, key, chain);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        public void engineSetCertificateEntry(String alias,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
                                           java.security.cert.Certificate cert)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
            throws KeyStoreException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
            jks.engineSetCertificateEntry(alias, cert);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        public void engineDeleteEntry(String alias)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
            throws KeyStoreException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
            jks.engineDeleteEntry(alias);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        public Enumeration engineAliases() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
            return jks.engineAliases();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        public boolean engineContainsAlias(String alias) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
            return jks.engineContainsAlias(alias);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        public int engineSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
            return jks.engineSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        public boolean engineIsKeyEntry(String alias) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
            return jks.engineIsKeyEntry(alias);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        public boolean engineIsCertificateEntry(String alias) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
            return jks.engineIsCertificateEntry(alias);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        public String engineGetCertificateAlias
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
                (java.security.cert.Certificate cert) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
            return jks.engineGetCertificateAlias(cert);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        public void engineStore(OutputStream stream, char[] password)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
            throws IOException, NoSuchAlgorithmException, CertificateException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
            jks.engineStore(stream, password);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        public void engineLoad(InputStream stream, char[] password)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
            throws IOException, NoSuchAlgorithmException, CertificateException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
            jks.engineLoad(stream, password);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
    public static class Post15 extends Pre15 {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        public void engineStore(KeyStore.LoadStoreParameter parameter)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
            throws IOException, NoSuchAlgorithmException, CertificateException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
            if (!(parameter instanceof EntryMethods.FooParameter)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
                throw new IOException("Post15 engineStore method expected " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
                        "FooParameter");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
        public void engineLoad(KeyStore.LoadStoreParameter parameter)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
            throws IOException, NoSuchAlgorithmException, CertificateException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
            if (!(parameter instanceof EntryMethods.FooParameter)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
                throw new IOException("Post15 engineLoadFrom method expected " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
                        "FooParameter");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        public KeyStore.Entry engineGetEntry(String alias,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
                        KeyStore.ProtectionParameter protectionParam)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
                        throws UnrecoverableEntryException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
            if (!alias.equals("foo")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
                throw new SecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
                        ("Post15 engineGetEntry(String, ProtectionParam) " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
                        "expected [foo] alias");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
            KeyStore.PasswordProtection pwdParam =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
                                (KeyStore.PasswordProtection)protectionParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
            if (pwdParam.getPassword().length != 6) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
                throw new SecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
                        ("Post15 engineGetEntry(String, ProtectionParam) " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
                        "expected [foobar] password");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
            return new EntryMethods.FooEntry();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
        public void engineSetEntry(String alias, KeyStore.Entry entry,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
                        KeyStore.ProtectionParameter protectionParam) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
            if (!alias.equals("foo") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
                !(entry instanceof EntryMethods.FooEntry)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
                throw new SecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
                        ("Post15 engineSetEntry(String, entry, ProtParm) " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
                        "expected [foo] alias and EntryMethods.FooEntry");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
            KeyStore.PasswordProtection pwdParam =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
                                (KeyStore.PasswordProtection)protectionParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
            if (pwdParam.getPassword().length != 6) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
                throw new SecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
                        ("Post15 engineSetEntry(String, entry, ProtParm) " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
                        "expected [foobar] password");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
        public boolean engineEntryInstanceOf(String alias,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
                                             Class<? extends KeyStore.Entry> entryClass)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
            if (!alias.equals("foo") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
                entryClass != KeyStore.PrivateKeyEntry.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
                throw new SecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
                        ("Post15 engineEntryInstanceOf(String, Class) " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
                        "expected [foo] alias " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
                        "and [KeyStore.PrivateKeyEntry] class");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
    public static class UnrecoverableKS extends Post15 {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
        public KeyStore.Entry engineGetEntry(String alias,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
                        KeyStore.ProtectionParameter protectionParam)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
                        throws UnrecoverableEntryException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
            throw new UnrecoverableEntryException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
}