Path: blob/master/src/java.base/share/classes/sun/security/internal/spec/TlsKeyMaterialSpec.java
41161 views
/*1* Copyright (c) 2005, 2019, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.security.internal.spec;2627import java.security.spec.KeySpec;2829import javax.crypto.SecretKey;30import javax.crypto.spec.IvParameterSpec;3132/**33* KeySpec class for SSL/TLS key material.34*35* <p>Instances of this class are returned by the <code>generateKey()</code>36* method of KeyGenerators of the type "TlsKeyMaterial".37* Instances of this class are immutable.38*39* @since 1.640* @author Andreas Sterbenz41* @deprecated Sun JDK internal use only --- WILL BE REMOVED in a future42* release.43*/44@Deprecated45public class TlsKeyMaterialSpec implements KeySpec, SecretKey {4647@java.io.Serial48static final long serialVersionUID = 812912859129525028L;4950private final SecretKey clientMacKey, serverMacKey;51private final SecretKey clientCipherKey, serverCipherKey;5253@SuppressWarnings("serial") // Not statically typed as Serializable54private final IvParameterSpec clientIv;55@SuppressWarnings("serial") // Not statically typed as Serializable56private final IvParameterSpec serverIv;5758/**59* Constructs a new TlsKeymaterialSpec from the client and server MAC60* keys.61* This call is equivalent to62* <code>new TlsKeymaterialSpec(clientMacKey, serverMacKey,63* null, null, null, null)</code>.64*65* @param clientMacKey the client MAC key (or null)66* @param serverMacKey the server MAC key (or null)67*/68public TlsKeyMaterialSpec(SecretKey clientMacKey, SecretKey serverMacKey) {69this(clientMacKey, serverMacKey, null, null, null, null);70}7172/**73* Constructs a new TlsKeymaterialSpec from the client and server MAC74* keys and client and server cipher keys.75* This call is equivalent to76* <code>new TlsKeymaterialSpec(clientMacKey, serverMacKey,77* clientCipherKey, serverCipherKey, null, null)</code>.78*79* @param clientMacKey the client MAC key (or null)80* @param serverMacKey the server MAC key (or null)81* @param clientCipherKey the client cipher key (or null)82* @param serverCipherKey the server cipher key (or null)83*/84public TlsKeyMaterialSpec(SecretKey clientMacKey, SecretKey serverMacKey,85SecretKey clientCipherKey, SecretKey serverCipherKey) {86this(clientMacKey, serverMacKey, clientCipherKey, null,87serverCipherKey, null);88}8990/**91* Constructs a new TlsKeymaterialSpec from the client and server MAC92* keys, client and server cipher keys, and client and server93* initialization vectors.94*95* @param clientMacKey the client MAC key (or null)96* @param serverMacKey the server MAC key (or null)97* @param clientCipherKey the client cipher key (or null)98* @param clientIv the client initialization vector (or null)99* @param serverCipherKey the server cipher key (or null)100* @param serverIv the server initialization vector (or null)101*/102public TlsKeyMaterialSpec(SecretKey clientMacKey, SecretKey serverMacKey,103SecretKey clientCipherKey, IvParameterSpec clientIv,104SecretKey serverCipherKey, IvParameterSpec serverIv) {105106this.clientMacKey = clientMacKey;107this.serverMacKey = serverMacKey;108this.clientCipherKey = clientCipherKey;109this.serverCipherKey = serverCipherKey;110this.clientIv = clientIv;111this.serverIv = serverIv;112}113114/**115* Returns <code>TlsKeyMaterial</code>.116*117* @return <code>TlsKeyMaterial</code>.118*/119public String getAlgorithm() {120return "TlsKeyMaterial";121}122123/**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*/128public String getFormat() {129return null;130}131132/**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*/137public byte[] getEncoded() {138return null;139}140141/**142* Returns the client MAC key.143*144* @return the client MAC key (or null).145*/146public SecretKey getClientMacKey() {147return clientMacKey;148}149150/**151* Return the server MAC key.152*153* @return the server MAC key (or null).154*/155public SecretKey getServerMacKey() {156return serverMacKey;157}158159/**160* Return the client cipher key (or null).161*162* @return the client cipher key (or null).163*/164public SecretKey getClientCipherKey() {165return clientCipherKey;166}167168/**169* Return the client initialization vector (or null).170*171* @return the client initialization vector (or null).172*/173public IvParameterSpec getClientIv() {174return clientIv;175}176177/**178* Return the server cipher key (or null).179*180* @return the server cipher key (or null).181*/182public SecretKey getServerCipherKey() {183return serverCipherKey;184}185186/**187* Return the server initialization vector (or null).188*189* @return the server initialization vector (or null).190*/191public IvParameterSpec getServerIv() {192return serverIv;193}194195}196197198