src/java.base/share/classes/sun/security/internal/spec/TlsKeyMaterialSpec.java
author chegar
Thu, 17 Oct 2019 20:54:25 +0100
branchdatagramsocketimpl-branch
changeset 58679 9c3209ff7550
parent 58678 9cf78a70fa4f
parent 58519 6e017b301287
permissions -rw-r--r--
datagramsocketimpl-branch: merge with default
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
57950
4612a3cfb927 8229999: Apply java.io.Serial annotations to security types in java.base
darcy
parents: 47216
diff changeset
     2
 * Copyright (c) 2005, 2019, 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.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
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
    42
 * @deprecated Sun JDK internal use only --- WILL BE REMOVED in a future
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
    43
 * release.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
@Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
public class TlsKeyMaterialSpec implements KeySpec, SecretKey {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
57950
4612a3cfb927 8229999: Apply java.io.Serial annotations to security types in java.base
darcy
parents: 47216
diff changeset
    48
    @java.io.Serial
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    static final long serialVersionUID = 812912859129525028L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    private final SecretKey clientMacKey, serverMacKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    private final SecretKey clientCipherKey, serverCipherKey;
58519
6e017b301287 8231262: Suppress warnings on non-serializable instance fields in security libs serializable classes
darcy
parents: 57950
diff changeset
    53
6e017b301287 8231262: Suppress warnings on non-serializable instance fields in security libs serializable classes
darcy
parents: 57950
diff changeset
    54
    @SuppressWarnings("serial") // Not statically typed as Serializable
6e017b301287 8231262: Suppress warnings on non-serializable instance fields in security libs serializable classes
darcy
parents: 57950
diff changeset
    55
    private final IvParameterSpec clientIv;
6e017b301287 8231262: Suppress warnings on non-serializable instance fields in security libs serializable classes
darcy
parents: 57950
diff changeset
    56
    @SuppressWarnings("serial") // Not statically typed as Serializable
6e017b301287 8231262: Suppress warnings on non-serializable instance fields in security libs serializable classes
darcy
parents: 57950
diff changeset
    57
    private final IvParameterSpec serverIv;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     * Constructs a new TlsKeymaterialSpec from the client and server MAC
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     * keys.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     * This call is equivalent to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     * <code>new TlsKeymaterialSpec(clientMacKey, serverMacKey,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     * null, null, null, null)</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     *
16913
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents: 16067
diff changeset
    66
     * @param clientMacKey the client MAC key (or null)
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents: 16067
diff changeset
    67
     * @param serverMacKey the server MAC key (or null)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    public TlsKeyMaterialSpec(SecretKey clientMacKey, SecretKey serverMacKey) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        this(clientMacKey, serverMacKey, null, null, null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * Constructs a new TlsKeymaterialSpec from the client and server MAC
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * keys and client and server cipher keys.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * This call is equivalent to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * <code>new TlsKeymaterialSpec(clientMacKey, serverMacKey,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * clientCipherKey, serverCipherKey, null, null)</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     *
16913
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents: 16067
diff changeset
    80
     * @param clientMacKey the client MAC key (or null)
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents: 16067
diff changeset
    81
     * @param serverMacKey the server MAC key (or null)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * @param clientCipherKey the client cipher key (or null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * @param serverCipherKey the server cipher key (or null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    public TlsKeyMaterialSpec(SecretKey clientMacKey, SecretKey serverMacKey,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
            SecretKey clientCipherKey, SecretKey serverCipherKey) {
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
    87
        this(clientMacKey, serverMacKey, clientCipherKey, null,
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
    88
            serverCipherKey, null);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * Constructs a new TlsKeymaterialSpec from the client and server MAC
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * keys, client and server cipher keys, and client and server
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * initialization vectors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     *
16913
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents: 16067
diff changeset
    96
     * @param clientMacKey the client MAC key (or null)
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents: 16067
diff changeset
    97
     * @param serverMacKey the server MAC key (or null)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * @param clientCipherKey the client cipher key (or null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * @param clientIv the client initialization vector (or null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * @param serverCipherKey the server cipher key (or null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * @param serverIv the server initialization vector (or null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    public TlsKeyMaterialSpec(SecretKey clientMacKey, SecretKey serverMacKey,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            SecretKey clientCipherKey, IvParameterSpec clientIv,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            SecretKey serverCipherKey, IvParameterSpec serverIv) {
16913
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents: 16067
diff changeset
   106
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        this.clientMacKey = clientMacKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        this.serverMacKey = serverMacKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        this.clientCipherKey = clientCipherKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        this.serverCipherKey = serverCipherKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        this.clientIv = clientIv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        this.serverIv = serverIv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * Returns <code>TlsKeyMaterial</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * @return <code>TlsKeyMaterial</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    public String getAlgorithm() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        return "TlsKeyMaterial";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * Returns <code>null</code> because keys of this type have no encoding.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * @return <code>null</code> because keys of this type have no encoding.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    public String getFormat() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * Returns <code>null</code> because keys of this type have no encoding.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * @return <code>null</code> because keys of this type have no encoding.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    public byte[] getEncoded() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * Returns the client MAC key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     *
16913
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents: 16067
diff changeset
   145
     * @return the client MAC key (or null).
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    public SecretKey getClientMacKey() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        return clientMacKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * Return the server MAC key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     *
16913
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents: 16067
diff changeset
   154
     * @return the server MAC key (or null).
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    public SecretKey getServerMacKey() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        return serverMacKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * Return the client cipher key (or null).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * @return the client cipher key (or null).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    public SecretKey getClientCipherKey() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        return clientCipherKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * Return the client initialization vector (or null).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * @return the client initialization vector (or null).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    public IvParameterSpec getClientIv() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        return clientIv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * Return the server cipher key (or null).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * @return the server cipher key (or null).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    public SecretKey getServerCipherKey() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        return serverCipherKey;
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
     * Return the server initialization vector (or null).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * @return the server initialization vector (or null).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    public IvParameterSpec getServerIv() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        return serverIv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
}