jdk/src/jdk.crypto.token/share/classes/sun/security/pkcs11/Token.java
author mchung
Wed, 14 Dec 2016 10:51:13 -0800
changeset 42693 6645de32a866
parent 25859 jdk/src/jdk.crypto.pkcs11/share/classes/sun/security/pkcs11/Token.java@3317bb8137f4
permissions -rw-r--r--
8171201: Drop java.compact$N aggregator modules 8171202: Rename jdk.crypto.pkcs11 and jdk.pack200 to end with Java letters Reviewed-by: alanb, erikj
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
21848
3902d25a64b1 7200306: SunPKCS11 provider delays the check of DSA key size for SHA1withDSA to sign() instead of init()
valeriep
parents: 10363
diff changeset
     2
 * Copyright (c) 2003, 2013, 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
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.security.pkcs11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.util.*;
21848
3902d25a64b1 7200306: SunPKCS11 provider delays the check of DSA key size for SHA1withDSA to sign() instead of init()
valeriep
parents: 10363
diff changeset
    29
import java.util.concurrent.ConcurrentHashMap;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.lang.ref.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.security.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import javax.security.auth.login.LoginException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import sun.security.jca.JCAUtil;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import sun.security.pkcs11.wrapper.*;
23733
b9b80421cfa7 8028192: Use of PKCS11-NSS provider in FIPS mode broken
xuelei
parents: 21848
diff changeset
    39
import static sun.security.pkcs11.TemplateManager.*;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import static sun.security.pkcs11.wrapper.PKCS11Constants.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * PKCS#11 token.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * @author  Andreas Sterbenz
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * @since   1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
class Token implements Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    // need to be serializable to allow SecureRandom to be serialized
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    private static final long serialVersionUID = 2541527649100571747L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    // how often to check if the token is still present (in ms)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    // this is different from checking if a token has been inserted,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    // that is done in SunPKCS11. Currently 50 ms.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    private final static long CHECK_INTERVAL = 50;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    final SunPKCS11 provider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    final PKCS11 p11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    final Config config;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    final CK_TOKEN_INFO tokenInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    // session manager to pool sessions
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    final SessionManager sessionManager;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    // template manager to customize the attributes used when creating objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    private final TemplateManager templateManager;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    // flag indicating whether we need to explicitly cancel operations
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    // we started on the token. If false, we assume operations are
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    // automatically cancelled once we start another one
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    final boolean explicitCancel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    // translation cache for secret keys
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    final KeyCache secretCache;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    // translation cache for asymmetric keys (public and private)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    final KeyCache privateCache;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    // cached instances of the various key factories, initialized on demand
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    private volatile P11KeyFactory rsaFactory, dsaFactory, dhFactory, ecFactory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    // table which maps mechanisms to the corresponding cached
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    // MechanismInfo objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    private final Map<Long, CK_MECHANISM_INFO> mechInfoMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    // single SecureRandomSpi instance we use per token
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    // initialized on demand (if supported)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    private volatile P11SecureRandom secureRandom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    // single KeyStoreSpi instance we use per provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    // initialized on demand
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    private volatile P11KeyStore keyStore;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    // whether this token is a removable token
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    private final boolean removable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    // for removable tokens: whether this token is valid or has been removed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    private volatile boolean valid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    // for removable tokens: time last checked for token presence
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    private long lastPresentCheck;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    // unique token id, used for serialization only
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    private byte[] tokenId;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    // flag indicating whether the token is write protected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    private boolean writeProtected;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    // flag indicating whether we are logged in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    private volatile boolean loggedIn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    // time we last checked login status
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    private long lastLoginCheck;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    // mutex for token-present-check
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    private final static Object CHECK_LOCK = new Object();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    // object for indicating unsupported mechanism in 'mechInfoMap'
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    private final static CK_MECHANISM_INFO INVALID_MECH =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        new CK_MECHANISM_INFO(0, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
23733
b9b80421cfa7 8028192: Use of PKCS11-NSS provider in FIPS mode broken
xuelei
parents: 21848
diff changeset
   126
    // flag indicating whether the token supports raw secret key material import
b9b80421cfa7 8028192: Use of PKCS11-NSS provider in FIPS mode broken
xuelei
parents: 21848
diff changeset
   127
    private Boolean supportsRawSecretKeyImport;
b9b80421cfa7 8028192: Use of PKCS11-NSS provider in FIPS mode broken
xuelei
parents: 21848
diff changeset
   128
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    Token(SunPKCS11 provider) throws PKCS11Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        this.provider = provider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        this.removable = provider.removable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        this.valid = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        p11 = provider.p11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        config = provider.config;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        tokenInfo = p11.C_GetTokenInfo(provider.slotID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        writeProtected = (tokenInfo.flags & CKF_WRITE_PROTECTED) != 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        // create session manager and open a test session
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        SessionManager sessionManager;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            sessionManager = new SessionManager(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            Session s = sessionManager.getOpSession();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            sessionManager.releaseSession(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        } catch (PKCS11Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            if (writeProtected) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                throw e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            // token might not permit RW sessions even though
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            // CKF_WRITE_PROTECTED is not set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            writeProtected = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            sessionManager = new SessionManager(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            Session s = sessionManager.getOpSession();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            sessionManager.releaseSession(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        this.sessionManager = sessionManager;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        secretCache = new KeyCache();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        privateCache = new KeyCache();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        templateManager = config.getTemplateManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        explicitCancel = config.getExplicitCancel();
21848
3902d25a64b1 7200306: SunPKCS11 provider delays the check of DSA key size for SHA1withDSA to sign() instead of init()
valeriep
parents: 10363
diff changeset
   159
        mechInfoMap =
3902d25a64b1 7200306: SunPKCS11 provider delays the check of DSA key size for SHA1withDSA to sign() instead of init()
valeriep
parents: 10363
diff changeset
   160
            new ConcurrentHashMap<Long, CK_MECHANISM_INFO>(10);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    boolean isWriteProtected() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        return writeProtected;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
23733
b9b80421cfa7 8028192: Use of PKCS11-NSS provider in FIPS mode broken
xuelei
parents: 21848
diff changeset
   167
    // return whether the token supports raw secret key material import
b9b80421cfa7 8028192: Use of PKCS11-NSS provider in FIPS mode broken
xuelei
parents: 21848
diff changeset
   168
    boolean supportsRawSecretKeyImport() {
b9b80421cfa7 8028192: Use of PKCS11-NSS provider in FIPS mode broken
xuelei
parents: 21848
diff changeset
   169
        if (supportsRawSecretKeyImport == null) {
b9b80421cfa7 8028192: Use of PKCS11-NSS provider in FIPS mode broken
xuelei
parents: 21848
diff changeset
   170
            SecureRandom random = JCAUtil.getSecureRandom();
b9b80421cfa7 8028192: Use of PKCS11-NSS provider in FIPS mode broken
xuelei
parents: 21848
diff changeset
   171
            byte[] encoded = new byte[48];
b9b80421cfa7 8028192: Use of PKCS11-NSS provider in FIPS mode broken
xuelei
parents: 21848
diff changeset
   172
            random.nextBytes(encoded);
b9b80421cfa7 8028192: Use of PKCS11-NSS provider in FIPS mode broken
xuelei
parents: 21848
diff changeset
   173
b9b80421cfa7 8028192: Use of PKCS11-NSS provider in FIPS mode broken
xuelei
parents: 21848
diff changeset
   174
            CK_ATTRIBUTE[] attributes = new CK_ATTRIBUTE[3];
b9b80421cfa7 8028192: Use of PKCS11-NSS provider in FIPS mode broken
xuelei
parents: 21848
diff changeset
   175
            attributes[0] = new CK_ATTRIBUTE(CKA_CLASS, CKO_SECRET_KEY);
b9b80421cfa7 8028192: Use of PKCS11-NSS provider in FIPS mode broken
xuelei
parents: 21848
diff changeset
   176
            attributes[1] = new CK_ATTRIBUTE(CKA_KEY_TYPE, CKK_GENERIC_SECRET);
b9b80421cfa7 8028192: Use of PKCS11-NSS provider in FIPS mode broken
xuelei
parents: 21848
diff changeset
   177
            attributes[2] = new CK_ATTRIBUTE(CKA_VALUE, encoded);
b9b80421cfa7 8028192: Use of PKCS11-NSS provider in FIPS mode broken
xuelei
parents: 21848
diff changeset
   178
b9b80421cfa7 8028192: Use of PKCS11-NSS provider in FIPS mode broken
xuelei
parents: 21848
diff changeset
   179
            Session session = null;
b9b80421cfa7 8028192: Use of PKCS11-NSS provider in FIPS mode broken
xuelei
parents: 21848
diff changeset
   180
            try {
b9b80421cfa7 8028192: Use of PKCS11-NSS provider in FIPS mode broken
xuelei
parents: 21848
diff changeset
   181
                attributes = getAttributes(O_IMPORT,
b9b80421cfa7 8028192: Use of PKCS11-NSS provider in FIPS mode broken
xuelei
parents: 21848
diff changeset
   182
                        CKO_SECRET_KEY, CKK_GENERIC_SECRET, attributes);
b9b80421cfa7 8028192: Use of PKCS11-NSS provider in FIPS mode broken
xuelei
parents: 21848
diff changeset
   183
                session = getObjSession();
b9b80421cfa7 8028192: Use of PKCS11-NSS provider in FIPS mode broken
xuelei
parents: 21848
diff changeset
   184
                long keyID = p11.C_CreateObject(session.id(), attributes);
b9b80421cfa7 8028192: Use of PKCS11-NSS provider in FIPS mode broken
xuelei
parents: 21848
diff changeset
   185
b9b80421cfa7 8028192: Use of PKCS11-NSS provider in FIPS mode broken
xuelei
parents: 21848
diff changeset
   186
                supportsRawSecretKeyImport = Boolean.TRUE;
b9b80421cfa7 8028192: Use of PKCS11-NSS provider in FIPS mode broken
xuelei
parents: 21848
diff changeset
   187
            } catch (PKCS11Exception e) {
b9b80421cfa7 8028192: Use of PKCS11-NSS provider in FIPS mode broken
xuelei
parents: 21848
diff changeset
   188
                supportsRawSecretKeyImport = Boolean.FALSE;
b9b80421cfa7 8028192: Use of PKCS11-NSS provider in FIPS mode broken
xuelei
parents: 21848
diff changeset
   189
            } finally {
b9b80421cfa7 8028192: Use of PKCS11-NSS provider in FIPS mode broken
xuelei
parents: 21848
diff changeset
   190
                releaseSession(session);
b9b80421cfa7 8028192: Use of PKCS11-NSS provider in FIPS mode broken
xuelei
parents: 21848
diff changeset
   191
            }
b9b80421cfa7 8028192: Use of PKCS11-NSS provider in FIPS mode broken
xuelei
parents: 21848
diff changeset
   192
        }
b9b80421cfa7 8028192: Use of PKCS11-NSS provider in FIPS mode broken
xuelei
parents: 21848
diff changeset
   193
b9b80421cfa7 8028192: Use of PKCS11-NSS provider in FIPS mode broken
xuelei
parents: 21848
diff changeset
   194
        return supportsRawSecretKeyImport;
b9b80421cfa7 8028192: Use of PKCS11-NSS provider in FIPS mode broken
xuelei
parents: 21848
diff changeset
   195
    }
b9b80421cfa7 8028192: Use of PKCS11-NSS provider in FIPS mode broken
xuelei
parents: 21848
diff changeset
   196
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    // return whether we are logged in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    // uses cached result if current. session is optional and may be null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    boolean isLoggedIn(Session session) throws PKCS11Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        // volatile load first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        boolean loggedIn = this.loggedIn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        long time = System.currentTimeMillis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        if (time - lastLoginCheck > CHECK_INTERVAL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            loggedIn = isLoggedInNow(session);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            lastLoginCheck = time;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        return loggedIn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    // return whether we are logged in now
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    // does not use cache
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    boolean isLoggedInNow(Session session) throws PKCS11Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        boolean allocSession = (session == null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            if (allocSession) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                session = getOpSession();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            CK_SESSION_INFO info = p11.C_GetSessionInfo(session.id());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            boolean loggedIn = (info.state == CKS_RO_USER_FUNCTIONS) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                                (info.state == CKS_RW_USER_FUNCTIONS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            this.loggedIn = loggedIn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            return loggedIn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            if (allocSession) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                releaseSession(session);
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    // ensure that we are logged in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    // call provider.login() if not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    void ensureLoggedIn(Session session) throws PKCS11Exception, LoginException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        if (isLoggedIn(session) == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            provider.login(null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    // return whether this token object is valid (i.e. token not removed)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    // returns value from last check, does not perform new check
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    boolean isValid() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        if (removable == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        return valid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    void ensureValid() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        if (isValid() == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            throw new ProviderException("Token has been removed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    // return whether a token is present (i.e. token not removed)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    // returns cached value if current, otherwise performs new check
10363
6670d68e5011 7024697: SessionRef.dispose() should determine if the token referred to by the token object is still valid
coffeys
parents: 5506
diff changeset
   255
    boolean isPresent(long sessionID) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        if (removable == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        if (valid == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        long time = System.currentTimeMillis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        if ((time - lastPresentCheck) >= CHECK_INTERVAL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
            synchronized (CHECK_LOCK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                if ((time - lastPresentCheck) >= CHECK_INTERVAL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                    boolean ok = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
                        // check if token still present
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                        CK_SLOT_INFO slotInfo =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                                provider.p11.C_GetSlotInfo(provider.slotID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                        if ((slotInfo.flags & CKF_TOKEN_PRESENT) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                            // if the token has been removed and re-inserted,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                            // the token should return an error
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                            CK_SESSION_INFO sessInfo =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                                    provider.p11.C_GetSessionInfo
10363
6670d68e5011 7024697: SessionRef.dispose() should determine if the token referred to by the token object is still valid
coffeys
parents: 5506
diff changeset
   276
                                    (sessionID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
                            ok = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                    } catch (PKCS11Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                        // empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                    valid = ok;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                    lastPresentCheck = System.currentTimeMillis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
                    if (ok == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
                        destroy();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        return valid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    void destroy() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        valid = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        provider.uninitToken(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    Session getObjSession() throws PKCS11Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        return sessionManager.getObjSession();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    Session getOpSession() throws PKCS11Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        return sessionManager.getOpSession();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    Session releaseSession(Session session) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        return sessionManager.releaseSession(session);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    Session killSession(Session session) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        return sessionManager.killSession(session);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    CK_ATTRIBUTE[] getAttributes(String op, long type, long alg,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
            CK_ATTRIBUTE[] attrs) throws PKCS11Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        CK_ATTRIBUTE[] newAttrs =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
                    templateManager.getAttributes(op, type, alg, attrs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        for (CK_ATTRIBUTE attr : newAttrs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
            if (attr.type == CKA_TOKEN) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
                if (attr.getBoolean()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
                        ensureLoggedIn(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
                    } catch (LoginException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
                        throw new ProviderException("Login failed", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
                // break once we have found a CKA_TOKEN attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        return newAttrs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
    P11KeyFactory getKeyFactory(String algorithm) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        P11KeyFactory f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        if (algorithm.equals("RSA")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
            f = rsaFactory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
            if (f == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
                f = new P11RSAKeyFactory(this, algorithm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
                rsaFactory = f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        } else if (algorithm.equals("DSA")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
            f = dsaFactory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
            if (f == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
                f = new P11DSAKeyFactory(this, algorithm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
                dsaFactory = f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        } else if (algorithm.equals("DH")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
            f = dhFactory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
            if (f == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
                f = new P11DHKeyFactory(this, algorithm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
                dhFactory = f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        } else if (algorithm.equals("EC")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
            f = ecFactory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
            if (f == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
                f = new P11ECKeyFactory(this, algorithm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
                ecFactory = f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
            throw new ProviderException("Unknown algorithm " + algorithm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        return f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    P11SecureRandom getRandom() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        if (secureRandom == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
            secureRandom = new P11SecureRandom(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        return secureRandom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    P11KeyStore getKeyStore() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        if (keyStore == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
            keyStore = new P11KeyStore(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        return keyStore;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
    CK_MECHANISM_INFO getMechanismInfo(long mechanism) throws PKCS11Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        CK_MECHANISM_INFO result = mechInfoMap.get(mechanism);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        if (result == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
                result = p11.C_GetMechanismInfo(provider.slotID,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
                                                mechanism);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
                mechInfoMap.put(mechanism, result);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
            } catch (PKCS11Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
                if (e.getErrorCode() != PKCS11Constants.CKR_MECHANISM_INVALID) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
                    throw e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
                    mechInfoMap.put(mechanism, INVALID_MECH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        } else if (result == INVALID_MECH) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
            result = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
    private synchronized byte[] getTokenId() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        if (tokenId == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
            SecureRandom random = JCAUtil.getSecureRandom();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
            tokenId = new byte[20];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
            random.nextBytes(tokenId);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
            serializedTokens.add(new WeakReference<Token>(this));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        return tokenId;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
    // list of all tokens that have been serialized within this VM
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
    // NOTE that elements are never removed from this list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
    // the assumption is that the number of tokens that are serialized
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
    // is relatively small
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
    private static final List<Reference<Token>> serializedTokens =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        new ArrayList<Reference<Token>>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    private Object writeReplace() throws ObjectStreamException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        if (isValid() == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
            throw new NotSerializableException("Token has been removed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        return new TokenRep(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
    // serialized representation of a token
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
    // tokens can only be de-serialized within the same VM invocation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
    // and if the token has not been removed in the meantime
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
    private static class TokenRep implements Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        private static final long serialVersionUID = 3503721168218219807L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        private final byte[] tokenId;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        TokenRep(Token token) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
            tokenId = token.getTokenId();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
        private Object readResolve() throws ObjectStreamException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
            for (Reference<Token> tokenRef : serializedTokens) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
                Token token = tokenRef.get();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
                if ((token != null) && token.isValid()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
                    if (Arrays.equals(token.getTokenId(), tokenId)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
                        return token;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
            throw new NotSerializableException("Could not find token");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
}