2
|
1 |
/*
|
|
2 |
* Copyright 2005-2007 Sun Microsystems, Inc. All Rights Reserved.
|
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation. Sun designates this
|
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
|
9 |
* by Sun in the LICENSE file that accompanied this code.
|
|
10 |
*
|
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
15 |
* accompanied this code).
|
|
16 |
*
|
|
17 |
* You should have received a copy of the GNU General Public License version
|
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
20 |
*
|
|
21 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
22 |
* CA 95054 USA or visit www.sun.com if you need additional information or
|
|
23 |
* have any questions.
|
|
24 |
*/
|
|
25 |
|
|
26 |
package sun.security.internal.spec;
|
|
27 |
|
|
28 |
import java.security.spec.KeySpec;
|
|
29 |
|
|
30 |
import javax.crypto.SecretKey;
|
|
31 |
import javax.crypto.spec.IvParameterSpec;
|
|
32 |
|
|
33 |
/**
|
|
34 |
* KeySpec class for SSL/TLS key material.
|
|
35 |
*
|
|
36 |
* <p>Instances of this class are returned by the <code>generateKey()</code>
|
|
37 |
* method of KeyGenerators of the type "TlsKeyMaterial".
|
|
38 |
* Instances of this class are immutable.
|
|
39 |
*
|
|
40 |
* @since 1.6
|
|
41 |
* @author Andreas Sterbenz
|
|
42 |
* @deprecated Sun JDK internal use only --- WILL BE REMOVED in Dolphin (JDK 7)
|
|
43 |
*/
|
|
44 |
@Deprecated
|
|
45 |
public class TlsKeyMaterialSpec implements KeySpec, SecretKey {
|
|
46 |
|
|
47 |
static final long serialVersionUID = 812912859129525028L;
|
|
48 |
|
|
49 |
private final SecretKey clientMacKey, serverMacKey;
|
|
50 |
private final SecretKey clientCipherKey, serverCipherKey;
|
|
51 |
private final IvParameterSpec clientIv, serverIv;
|
|
52 |
|
|
53 |
/**
|
|
54 |
* Constructs a new TlsKeymaterialSpec from the client and server MAC
|
|
55 |
* keys.
|
|
56 |
* This call is equivalent to
|
|
57 |
* <code>new TlsKeymaterialSpec(clientMacKey, serverMacKey,
|
|
58 |
* null, null, null, null)</code>.
|
|
59 |
*
|
|
60 |
* @param clientMacKey the client MAC key
|
|
61 |
* @param serverMacKey the server MAC key
|
|
62 |
* @throws NullPointerException if clientMacKey or serverMacKey is null
|
|
63 |
*/
|
|
64 |
public TlsKeyMaterialSpec(SecretKey clientMacKey, SecretKey serverMacKey) {
|
|
65 |
this(clientMacKey, serverMacKey, null, null, null, null);
|
|
66 |
}
|
|
67 |
|
|
68 |
/**
|
|
69 |
* Constructs a new TlsKeymaterialSpec from the client and server MAC
|
|
70 |
* keys and client and server cipher keys.
|
|
71 |
* This call is equivalent to
|
|
72 |
* <code>new TlsKeymaterialSpec(clientMacKey, serverMacKey,
|
|
73 |
* clientCipherKey, serverCipherKey, null, null)</code>.
|
|
74 |
*
|
|
75 |
* @param clientMacKey the client MAC key
|
|
76 |
* @param serverMacKey the server MAC key
|
|
77 |
* @param clientCipherKey the client cipher key (or null)
|
|
78 |
* @param serverCipherKey the server cipher key (or null)
|
|
79 |
* @throws NullPointerException if clientMacKey or serverMacKey is null
|
|
80 |
*/
|
|
81 |
public TlsKeyMaterialSpec(SecretKey clientMacKey, SecretKey serverMacKey,
|
|
82 |
SecretKey clientCipherKey, SecretKey serverCipherKey) {
|
|
83 |
this(clientMacKey, serverMacKey, clientCipherKey, null, serverCipherKey, null);
|
|
84 |
}
|
|
85 |
|
|
86 |
/**
|
|
87 |
* Constructs a new TlsKeymaterialSpec from the client and server MAC
|
|
88 |
* keys, client and server cipher keys, and client and server
|
|
89 |
* initialization vectors.
|
|
90 |
*
|
|
91 |
* @param clientMacKey the client MAC key
|
|
92 |
* @param serverMacKey the server MAC key
|
|
93 |
* @param clientCipherKey the client cipher key (or null)
|
|
94 |
* @param clientIv the client initialization vector (or null)
|
|
95 |
* @param serverCipherKey the server cipher key (or null)
|
|
96 |
* @param serverIv the server initialization vector (or null)
|
|
97 |
*
|
|
98 |
* @throws NullPointerException if clientMacKey or serverMacKey is null
|
|
99 |
*/
|
|
100 |
public TlsKeyMaterialSpec(SecretKey clientMacKey, SecretKey serverMacKey,
|
|
101 |
SecretKey clientCipherKey, IvParameterSpec clientIv,
|
|
102 |
SecretKey serverCipherKey, IvParameterSpec serverIv) {
|
|
103 |
if ((clientMacKey == null) || (serverMacKey == null)) {
|
|
104 |
throw new NullPointerException("MAC keys must not be null");
|
|
105 |
}
|
|
106 |
this.clientMacKey = clientMacKey;
|
|
107 |
this.serverMacKey = serverMacKey;
|
|
108 |
this.clientCipherKey = clientCipherKey;
|
|
109 |
this.serverCipherKey = serverCipherKey;
|
|
110 |
this.clientIv = clientIv;
|
|
111 |
this.serverIv = serverIv;
|
|
112 |
}
|
|
113 |
|
|
114 |
/**
|
|
115 |
* Returns <code>TlsKeyMaterial</code>.
|
|
116 |
*
|
|
117 |
* @return <code>TlsKeyMaterial</code>.
|
|
118 |
*/
|
|
119 |
public String getAlgorithm() {
|
|
120 |
return "TlsKeyMaterial";
|
|
121 |
}
|
|
122 |
|
|
123 |
/**
|
|
124 |
* Returns <code>null</code> because keys of this type have no encoding.
|
|
125 |
*
|
|
126 |
* @return <code>null</code> because keys of this type have no encoding.
|
|
127 |
*/
|
|
128 |
public String getFormat() {
|
|
129 |
return null;
|
|
130 |
}
|
|
131 |
|
|
132 |
/**
|
|
133 |
* Returns <code>null</code> because keys of this type have no encoding.
|
|
134 |
*
|
|
135 |
* @return <code>null</code> because keys of this type have no encoding.
|
|
136 |
*/
|
|
137 |
public byte[] getEncoded() {
|
|
138 |
return null;
|
|
139 |
}
|
|
140 |
|
|
141 |
/**
|
|
142 |
* Returns the client MAC key.
|
|
143 |
*
|
|
144 |
* @return the client MAC key.
|
|
145 |
*/
|
|
146 |
public SecretKey getClientMacKey() {
|
|
147 |
return clientMacKey;
|
|
148 |
}
|
|
149 |
|
|
150 |
/**
|
|
151 |
* Return the server MAC key.
|
|
152 |
*
|
|
153 |
* @return the server MAC key.
|
|
154 |
*/
|
|
155 |
public SecretKey getServerMacKey() {
|
|
156 |
return serverMacKey;
|
|
157 |
}
|
|
158 |
|
|
159 |
/**
|
|
160 |
* Return the client cipher key (or null).
|
|
161 |
*
|
|
162 |
* @return the client cipher key (or null).
|
|
163 |
*/
|
|
164 |
public SecretKey getClientCipherKey() {
|
|
165 |
return clientCipherKey;
|
|
166 |
}
|
|
167 |
|
|
168 |
/**
|
|
169 |
* Return the client initialization vector (or null).
|
|
170 |
*
|
|
171 |
* @return the client initialization vector (or null).
|
|
172 |
*/
|
|
173 |
public IvParameterSpec getClientIv() {
|
|
174 |
return clientIv;
|
|
175 |
}
|
|
176 |
|
|
177 |
/**
|
|
178 |
* Return the server cipher key (or null).
|
|
179 |
*
|
|
180 |
* @return the server cipher key (or null).
|
|
181 |
*/
|
|
182 |
public SecretKey getServerCipherKey() {
|
|
183 |
return serverCipherKey;
|
|
184 |
}
|
|
185 |
|
|
186 |
/**
|
|
187 |
* Return the server initialization vector (or null).
|
|
188 |
*
|
|
189 |
* @return the server initialization vector (or null).
|
|
190 |
*/
|
|
191 |
public IvParameterSpec getServerIv() {
|
|
192 |
return serverIv;
|
|
193 |
}
|
|
194 |
|
|
195 |
}
|