0N/A/*
2998N/A * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage sun.security.internal.spec;
0N/A
0N/Aimport java.security.spec.AlgorithmParameterSpec;
0N/A
0N/Aimport javax.crypto.SecretKey;
0N/A
0N/A/**
0N/A * Parameters for SSL/TLS key material generation.
0N/A * This class is used to initialize KeyGenerator of the type
0N/A * "TlsKeyMaterial". The keys returned by such KeyGenerators will be
0N/A * instances of {@link TlsKeyMaterialSpec}.
0N/A *
0N/A * <p>Instances of this class are immutable.
0N/A *
0N/A * @since 1.6
0N/A * @author Andreas Sterbenz
3002N/A * @deprecated Sun JDK internal use only --- WILL BE REMOVED in a future
3002N/A * release.
0N/A */
0N/A@Deprecated
0N/Apublic class TlsKeyMaterialParameterSpec implements AlgorithmParameterSpec {
0N/A
0N/A private final SecretKey masterSecret;
0N/A private final int majorVersion, minorVersion;
0N/A private final byte[] clientRandom, serverRandom;
0N/A private final String cipherAlgorithm;
0N/A private final int cipherKeyLength, ivLength, macKeyLength;
0N/A private final int expandedCipherKeyLength; // == 0 for domestic ciphersuites
3002N/A private final String prfHashAlg;
3002N/A private final int prfHashLength;
3002N/A private final int prfBlockSize;
0N/A
0N/A /**
0N/A * Constructs a new TlsKeyMaterialParameterSpec.
0N/A *
0N/A * @param masterSecret the master secret
0N/A * @param majorVersion the major number of the protocol version
0N/A * @param minorVersion the minor number of the protocol version
0N/A * @param clientRandom the client's random value
0N/A * @param serverRandom the server's random value
0N/A * @param cipherAlgorithm the algorithm name of the cipher keys to
0N/A * be generated
0N/A * @param cipherKeyLength if 0, no cipher keys will be generated;
0N/A * otherwise, the length in bytes of cipher keys to be
0N/A * generated for domestic cipher suites; for cipher suites defined as
0N/A * exportable, the number of key material bytes to be generated;
0N/A * @param expandedCipherKeyLength 0 for domestic cipher suites; for
0N/A * exportable cipher suites the length in bytes of the key to be
0N/A * generated.
0N/A * @param ivLength the length in bytes of the initialization vector
0N/A * to be generated, or 0 if no initialization vector is required
0N/A * @param macKeyLength the length in bytes of the MAC key to be generated
3002N/A * @param prfHashAlg the name of the TLS PRF hash algorithm to use.
3002N/A * Used only for TLS 1.2+. TLS1.1 and earlier use a fixed PRF.
3002N/A * @param prfHashLength the output length of the TLS PRF hash algorithm.
3002N/A * Used only for TLS 1.2+.
3002N/A * @param prfBlockSize the input block size of the TLS PRF hash algorithm.
3002N/A * Used only for TLS 1.2+.
0N/A *
0N/A * @throws NullPointerException if masterSecret, clientRandom,
0N/A * serverRandom, or cipherAlgorithm are null
0N/A * @throws IllegalArgumentException if the algorithm of masterSecret is
0N/A * not TlsMasterSecret, or if majorVersion or minorVersion are
0N/A * negative or larger than 255; or if cipherKeyLength, expandedKeyLength,
0N/A * ivLength, or macKeyLength are negative
0N/A */
0N/A public TlsKeyMaterialParameterSpec(SecretKey masterSecret,
0N/A int majorVersion, int minorVersion, byte[] clientRandom,
0N/A byte[] serverRandom, String cipherAlgorithm, int cipherKeyLength,
3002N/A int expandedCipherKeyLength, int ivLength, int macKeyLength,
3002N/A String prfHashAlg, int prfHashLength, int prfBlockSize) {
0N/A if (masterSecret.getAlgorithm().equals("TlsMasterSecret") == false) {
0N/A throw new IllegalArgumentException("Not a TLS master secret");
0N/A }
0N/A if (cipherAlgorithm == null) {
0N/A throw new NullPointerException();
0N/A }
0N/A this.masterSecret = masterSecret;
2998N/A this.majorVersion =
2998N/A TlsMasterSecretParameterSpec.checkVersion(majorVersion);
2998N/A this.minorVersion =
2998N/A TlsMasterSecretParameterSpec.checkVersion(minorVersion);
0N/A this.clientRandom = clientRandom.clone();
0N/A this.serverRandom = serverRandom.clone();
0N/A this.cipherAlgorithm = cipherAlgorithm;
0N/A this.cipherKeyLength = checkSign(cipherKeyLength);
0N/A this.expandedCipherKeyLength = checkSign(expandedCipherKeyLength);
0N/A this.ivLength = checkSign(ivLength);
0N/A this.macKeyLength = checkSign(macKeyLength);
3002N/A this.prfHashAlg = prfHashAlg;
3002N/A this.prfHashLength = prfHashLength;
3002N/A this.prfBlockSize = prfBlockSize;
0N/A }
0N/A
0N/A private static int checkSign(int k) {
0N/A if (k < 0) {
0N/A throw new IllegalArgumentException("Value must not be negative");
0N/A }
0N/A return k;
0N/A }
0N/A
0N/A /**
0N/A * Returns the master secret.
0N/A *
0N/A * @return the master secret.
0N/A */
0N/A public SecretKey getMasterSecret() {
0N/A return masterSecret;
0N/A }
0N/A
0N/A /**
0N/A * Returns the major version number.
0N/A *
0N/A * @return the major version number.
0N/A */
0N/A public int getMajorVersion() {
0N/A return majorVersion;
0N/A }
0N/A
0N/A /**
0N/A * Returns the minor version number.
0N/A *
0N/A * @return the minor version number.
0N/A */
0N/A public int getMinorVersion() {
0N/A return minorVersion;
0N/A }
0N/A
0N/A /**
0N/A * Returns a copy of the client's random value.
0N/A *
0N/A * @return a copy of the client's random value.
0N/A */
0N/A public byte[] getClientRandom() {
0N/A return clientRandom.clone();
0N/A }
0N/A
0N/A /**
0N/A * Returns a copy of the server's random value.
0N/A *
0N/A * @return a copy of the server's random value.
0N/A */
0N/A public byte[] getServerRandom() {
0N/A return serverRandom.clone();
0N/A }
0N/A
0N/A /**
0N/A * Returns the cipher algorithm.
0N/A *
0N/A * @return the cipher algorithm.
0N/A */
0N/A public String getCipherAlgorithm() {
0N/A return cipherAlgorithm;
0N/A }
0N/A
0N/A /**
0N/A * Returns the length in bytes of the encryption key to be generated.
0N/A *
0N/A * @return the length in bytes of the encryption key to be generated.
0N/A */
0N/A public int getCipherKeyLength() {
0N/A return cipherKeyLength;
0N/A }
0N/A
0N/A /**
2998N/A * Returns the length in bytes of the expanded encryption key to be
2998N/A * generated. Returns zero if the expanded encryption key is not
2998N/A * supposed to be generated.
0N/A *
2998N/A * @return the length in bytes of the expanded encryption key to be
2998N/A * generated.
0N/A */
0N/A public int getExpandedCipherKeyLength() {
2998N/A // TLS v1.1 disables the exportable weak cipher suites.
2998N/A if (majorVersion >= 0x03 && minorVersion >= 0x02) {
2998N/A return 0;
2998N/A }
0N/A return expandedCipherKeyLength;
0N/A }
0N/A
0N/A /**
2998N/A * Returns the length in bytes of the initialization vector to be
2998N/A * generated. Returns zero if the initialization vector is not
2998N/A * supposed to be generated.
0N/A *
2998N/A * @return the length in bytes of the initialization vector to be
2998N/A * generated.
0N/A */
0N/A public int getIvLength() {
2998N/A // TLS v1.1 or later uses an explicit IV to protect against
2998N/A // the CBC attacks.
2998N/A if (majorVersion >= 0x03 && minorVersion >= 0x02) {
2998N/A return 0;
2998N/A }
2998N/A
0N/A return ivLength;
0N/A }
0N/A
0N/A /**
0N/A * Returns the length in bytes of the MAC key to be generated.
0N/A *
0N/A * @return the length in bytes of the MAC key to be generated.
0N/A */
0N/A public int getMacKeyLength() {
0N/A return macKeyLength;
0N/A }
0N/A
3002N/A /**
3002N/A * Obtains the PRF hash algorithm to use in the PRF calculation.
3002N/A *
3002N/A * @return the hash algorithm.
3002N/A */
3002N/A public String getPRFHashAlg() {
3002N/A return prfHashAlg;
3002N/A }
3002N/A
3002N/A /**
3002N/A * Obtains the length of the PRF hash algorithm.
3002N/A *
3002N/A * @return the hash algorithm length.
3002N/A */
3002N/A public int getPRFHashLength() {
3002N/A return prfHashLength;
3002N/A }
3002N/A
3002N/A /**
3002N/A * Obtains the block size of the PRF hash algorithm.
3002N/A *
3002N/A * @return the hash algorithm block size
3002N/A */
3002N/A public int getPRFBlockSize() {
3002N/A return prfBlockSize;
3002N/A }
0N/A}