30 import javax.crypto.SecretKey;
31
32 /**
33 * Parameters for SSL/TLS master secret generation.
34 * This class encapsulates the information necessary to calculate a SSL/TLS
35 * master secret from the premaster secret and other parameters.
36 * It is used to initialize KeyGenerators of the type "TlsMasterSecret".
37 *
38 * <p>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 a future
43 * release.
44 */
45 @Deprecated
46 public class TlsMasterSecretParameterSpec implements AlgorithmParameterSpec {
47
48 private final SecretKey premasterSecret;
49 private final int majorVersion, minorVersion;
50 private final byte[] clientRandom, serverRandom;
51 private final String prfHashAlg;
52 private final int prfHashLength;
53 private final int prfBlockSize;
54
55 /**
56 * Constructs a new TlsMasterSecretParameterSpec.
57 *
58 * <p>The <code>getAlgorithm()</code> method of <code>premasterSecret</code>
59 * should return <code>"TlsRsaPremasterSecret"</code> if the key exchange
60 * algorithm was RSA and <code>"TlsPremasterSecret"</code> otherwise.
61 *
62 * @param premasterSecret the premaster secret
63 * @param majorVersion the major number of the protocol version
64 * @param minorVersion the minor number of the protocol version
65 * @param clientRandom the client's random value
66 * @param serverRandom the server's random value
67 * @param prfHashAlg the name of the TLS PRF hash algorithm to use.
68 * Used only for TLS 1.2+. TLS1.1 and earlier use a fixed PRF.
69 * @param prfHashLength the output length of the TLS PRF hash algorithm.
70 * Used only for TLS 1.2+.
71 * @param prfBlockSize the input block size of the TLS PRF hash algorithm.
72 * Used only for TLS 1.2+.
73 *
74 * @throws NullPointerException if premasterSecret, clientRandom,
75 * or serverRandom are null
76 * @throws IllegalArgumentException if minorVersion or majorVersion are
77 * negative or larger than 255
78 */
79 public TlsMasterSecretParameterSpec(SecretKey premasterSecret,
80 int majorVersion, int minorVersion,
81 byte[] clientRandom, byte[] serverRandom,
82 String prfHashAlg, int prfHashLength, int prfBlockSize) {
83 if (premasterSecret == null) {
84 throw new NullPointerException("premasterSecret must not be null");
85 }
86 this.premasterSecret = premasterSecret;
87 this.majorVersion = checkVersion(majorVersion);
88 this.minorVersion = checkVersion(minorVersion);
89 this.clientRandom = clientRandom.clone();
90 this.serverRandom = serverRandom.clone();
91 this.prfHashAlg = prfHashAlg;
92 this.prfHashLength = prfHashLength;
93 this.prfBlockSize = prfBlockSize;
94 }
95
96 static int checkVersion(int version) {
97 if ((version < 0) || (version > 255)) {
98 throw new IllegalArgumentException(
99 "Version must be between 0 and 255");
100 }
101 return version;
102 }
103
104 /**
105 * Returns the premaster secret.
106 *
107 * @return the premaster secret.
108 */
109 public SecretKey getPremasterSecret() {
110 return premasterSecret;
127 public int getMinorVersion() {
128 return minorVersion;
129 }
130
131 /**
132 * Returns a copy of the client's random value.
133 *
134 * @return a copy of the client's random value.
135 */
136 public byte[] getClientRandom() {
137 return clientRandom.clone();
138 }
139
140 /**
141 * Returns a copy of the server's random value.
142 *
143 * @return a copy of the server's random value.
144 */
145 public byte[] getServerRandom() {
146 return serverRandom.clone();
147 }
148
149 /**
150 * Obtains the PRF hash algorithm to use in the PRF calculation.
151 *
152 * @return the hash algorithm.
153 */
154 public String getPRFHashAlg() {
155 return prfHashAlg;
156 }
157
158 /**
159 * Obtains the length of the PRF hash algorithm.
160 *
161 * @return the hash algorithm length.
162 */
163 public int getPRFHashLength() {
164 return prfHashLength;
165 }
166
|
30 import javax.crypto.SecretKey;
31
32 /**
33 * Parameters for SSL/TLS master secret generation.
34 * This class encapsulates the information necessary to calculate a SSL/TLS
35 * master secret from the premaster secret and other parameters.
36 * It is used to initialize KeyGenerators of the type "TlsMasterSecret".
37 *
38 * <p>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 a future
43 * release.
44 */
45 @Deprecated
46 public class TlsMasterSecretParameterSpec implements AlgorithmParameterSpec {
47
48 private final SecretKey premasterSecret;
49 private final int majorVersion, minorVersion;
50 private final byte[] clientRandom, serverRandom, extendedMasterSecretSessionHash;
51 private final String prfHashAlg;
52 private final int prfHashLength;
53 private final int prfBlockSize;
54
55 /**
56 * Constructs a new TlsMasterSecretParameterSpec.
57 *
58 * <p>The <code>getAlgorithm()</code> method of <code>premasterSecret</code>
59 * should return <code>"TlsRsaPremasterSecret"</code> if the key exchange
60 * algorithm was RSA and <code>"TlsPremasterSecret"</code> otherwise.
61 *
62 * @param premasterSecret the premaster secret
63 * @param majorVersion the major number of the protocol version
64 * @param minorVersion the minor number of the protocol version
65 * @param clientRandom the client's random value
66 * @param serverRandom the server's random value
67 * @param extendedMasterSecretSessionHash the session hash for Extended Master Secret
68 * @param prfHashAlg the name of the TLS PRF hash algorithm to use.
69 * Used only for TLS 1.2+. TLS1.1 and earlier use a fixed PRF.
70 * @param prfHashLength the output length of the TLS PRF hash algorithm.
71 * Used only for TLS 1.2+.
72 * @param prfBlockSize the input block size of the TLS PRF hash algorithm.
73 * Used only for TLS 1.2+.
74 *
75 * @throws NullPointerException if premasterSecret, clientRandom,
76 * or serverRandom are null
77 * @throws IllegalArgumentException if minorVersion or majorVersion are
78 * negative or larger than 255
79 */
80 public TlsMasterSecretParameterSpec(SecretKey premasterSecret,
81 int majorVersion, int minorVersion,
82 byte[] clientRandom, byte[] serverRandom,
83 byte[] extendedMasterSecretSessionHash,
84 String prfHashAlg, int prfHashLength, int prfBlockSize) {
85 if (premasterSecret == null) {
86 throw new NullPointerException("premasterSecret must not be null");
87 }
88 this.premasterSecret = premasterSecret;
89 this.majorVersion = checkVersion(majorVersion);
90 this.minorVersion = checkVersion(minorVersion);
91 this.clientRandom = clientRandom.clone();
92 this.serverRandom = serverRandom.clone();
93 this.extendedMasterSecretSessionHash =
94 (extendedMasterSecretSessionHash != null ?
95 extendedMasterSecretSessionHash.clone() : null);
96 this.prfHashAlg = prfHashAlg;
97 this.prfHashLength = prfHashLength;
98 this.prfBlockSize = prfBlockSize;
99 }
100
101 static int checkVersion(int version) {
102 if ((version < 0) || (version > 255)) {
103 throw new IllegalArgumentException(
104 "Version must be between 0 and 255");
105 }
106 return version;
107 }
108
109 /**
110 * Returns the premaster secret.
111 *
112 * @return the premaster secret.
113 */
114 public SecretKey getPremasterSecret() {
115 return premasterSecret;
132 public int getMinorVersion() {
133 return minorVersion;
134 }
135
136 /**
137 * Returns a copy of the client's random value.
138 *
139 * @return a copy of the client's random value.
140 */
141 public byte[] getClientRandom() {
142 return clientRandom.clone();
143 }
144
145 /**
146 * Returns a copy of the server's random value.
147 *
148 * @return a copy of the server's random value.
149 */
150 public byte[] getServerRandom() {
151 return serverRandom.clone();
152 }
153
154 /**
155 * Returns a copy of the Extended Master Secret session hash.
156 *
157 * @return a copy of the Extended Master Secret session hash.
158 */
159 public byte[] getExtendedMasterSecretSessionHash() {
160 return (extendedMasterSecretSessionHash != null ?
161 extendedMasterSecretSessionHash.clone() :
162 null);
163 }
164
165 /**
166 * Obtains the PRF hash algorithm to use in the PRF calculation.
167 *
168 * @return the hash algorithm.
169 */
170 public String getPRFHashAlg() {
171 return prfHashAlg;
172 }
173
174 /**
175 * Obtains the length of the PRF hash algorithm.
176 *
177 * @return the hash algorithm length.
178 */
179 public int getPRFHashLength() {
180 return prfHashLength;
181 }
182
|