jdk/src/share/classes/sun/security/internal/spec/TlsKeyMaterialSpec.java
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 2 90ce3da70b43
child 5506 202f599c92aa
permissions -rw-r--r--
Initial load
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 2005-2007 Sun Microsystems, Inc.  All Rights Reserved.
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.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
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
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
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.internal.spec;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.security.spec.KeySpec;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import javax.crypto.SecretKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import javax.crypto.spec.IvParameterSpec;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * KeySpec class for SSL/TLS key material.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * <p>Instances of this class are returned by the <code>generateKey()</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * method of KeyGenerators of the type "TlsKeyMaterial".
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * Instances of this class are immutable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * @since   1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * @author  Andreas Sterbenz
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * @deprecated Sun JDK internal use only --- WILL BE REMOVED in Dolphin (JDK 7)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
@Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
public class TlsKeyMaterialSpec implements KeySpec, SecretKey {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    static final long serialVersionUID = 812912859129525028L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    private final SecretKey clientMacKey, serverMacKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    private final SecretKey clientCipherKey, serverCipherKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    private final IvParameterSpec clientIv, serverIv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
     * Constructs a new TlsKeymaterialSpec from the client and server MAC
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
     * keys.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
     * This call is equivalent to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     * <code>new TlsKeymaterialSpec(clientMacKey, serverMacKey,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     * null, null, null, null)</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     * @param clientMacKey the client MAC key
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     * @param serverMacKey the server MAC key
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     * @throws NullPointerException if clientMacKey or serverMacKey is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    public TlsKeyMaterialSpec(SecretKey clientMacKey, SecretKey serverMacKey) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        this(clientMacKey, serverMacKey, null, null, null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     * Constructs a new TlsKeymaterialSpec from the client and server MAC
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * keys and client and server cipher keys.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * This call is equivalent to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * <code>new TlsKeymaterialSpec(clientMacKey, serverMacKey,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * clientCipherKey, serverCipherKey, null, null)</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * @param clientMacKey the client MAC key
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * @param serverMacKey the server MAC key
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * @param clientCipherKey the client cipher key (or null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * @param serverCipherKey the server cipher key (or null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * @throws NullPointerException if clientMacKey or serverMacKey is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    public TlsKeyMaterialSpec(SecretKey clientMacKey, SecretKey serverMacKey,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
            SecretKey clientCipherKey, SecretKey serverCipherKey) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        this(clientMacKey, serverMacKey, clientCipherKey, null, serverCipherKey, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * Constructs a new TlsKeymaterialSpec from the client and server MAC
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * keys, client and server cipher keys, and client and server
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * initialization vectors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * @param clientMacKey the client MAC key
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * @param serverMacKey the server MAC key
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * @param clientCipherKey the client cipher key (or null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * @param clientIv the client initialization vector (or null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * @param serverCipherKey the server cipher key (or null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * @param serverIv the server initialization vector (or null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * @throws NullPointerException if clientMacKey or serverMacKey is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    public TlsKeyMaterialSpec(SecretKey clientMacKey, SecretKey serverMacKey,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            SecretKey clientCipherKey, IvParameterSpec clientIv,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            SecretKey serverCipherKey, IvParameterSpec serverIv) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        if ((clientMacKey == null) || (serverMacKey == null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            throw new NullPointerException("MAC keys must not be null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        this.clientMacKey = clientMacKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        this.serverMacKey = serverMacKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        this.clientCipherKey = clientCipherKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        this.serverCipherKey = serverCipherKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        this.clientIv = clientIv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        this.serverIv = serverIv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * Returns <code>TlsKeyMaterial</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * @return <code>TlsKeyMaterial</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    public String getAlgorithm() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        return "TlsKeyMaterial";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * Returns <code>null</code> because keys of this type have no encoding.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * @return <code>null</code> because keys of this type have no encoding.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    public String getFormat() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * Returns <code>null</code> because keys of this type have no encoding.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * @return <code>null</code> because keys of this type have no encoding.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    public byte[] getEncoded() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * Returns the client MAC key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * @return the client MAC key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    public SecretKey getClientMacKey() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        return clientMacKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * Return the server MAC key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * @return the server MAC key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    public SecretKey getServerMacKey() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        return serverMacKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * Return the client cipher key (or null).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * @return the client cipher key (or null).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    public SecretKey getClientCipherKey() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        return clientCipherKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * Return the client initialization vector (or null).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * @return the client initialization vector (or null).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    public IvParameterSpec getClientIv() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        return clientIv;
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
     * Return the server cipher key (or null).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * @return the server cipher key (or null).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    public SecretKey getServerCipherKey() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        return serverCipherKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * Return the server initialization vector (or null).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * @return the server initialization vector (or null).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    public IvParameterSpec getServerIv() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        return serverIv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
}