|
1 | 1 | /*
|
2 |
| - * Copyright (c) 2010, 2024, Oracle and/or its affiliates. All rights reserved. |
| 2 | + * Copyright (c) 2010, 2025, Oracle and/or its affiliates. All rights reserved. |
3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
4 | 4 | *
|
5 | 5 | * This code is free software; you can redistribute it and/or modify it
|
|
26 | 26 | package javax.net.ssl;
|
27 | 27 |
|
28 | 28 | import java.util.List;
|
| 29 | +import javax.crypto.SecretKey; |
29 | 30 |
|
30 | 31 | /**
|
31 | 32 | * Extends the {@code SSLSession} interface to support additional
|
@@ -163,4 +164,113 @@ public List<SNIServerName> getRequestedServerNames() {
|
163 | 164 | public List<byte[]> getStatusResponses() {
|
164 | 165 | throw new UnsupportedOperationException();
|
165 | 166 | }
|
| 167 | + |
| 168 | + /** |
| 169 | + * Generates Exported Keying Material (EKM) calculated according to the |
| 170 | + * algorithms defined in RFCs 5705/8446. |
| 171 | + * <P> |
| 172 | + * RFC 5705 (for (D)TLSv1.2 and earlier) calculates different EKM |
| 173 | + * values depending on whether {@code context} is null or non-null/empty. |
| 174 | + * RFC 8446 (TLSv1.3) treats a null context as non-null/empty. |
| 175 | + * <P> |
| 176 | + * {@code label} will be converted to bytes using |
| 177 | + * the {@link java.nio.charset.StandardCharsets#UTF_8} |
| 178 | + * character encoding. |
| 179 | + * |
| 180 | + * @spec https://www.rfc-editor.org/info/rfc5705 |
| 181 | + * RFC 5705: Keying Material Exporters for Transport Layer |
| 182 | + * Security (TLS) |
| 183 | + * @spec https://www.rfc-editor.org/info/rfc8446 |
| 184 | + * RFC 8446: The Transport Layer Security (TLS) Protocol Version 1.3 |
| 185 | + * |
| 186 | + * @implSpec The default implementation throws |
| 187 | + * {@code UnsupportedOperationException}. |
| 188 | + * |
| 189 | + * @param keyAlg the algorithm of the resultant {@code SecretKey} object. |
| 190 | + * See the SecretKey Algorithms section in the |
| 191 | + * <a href="{@docRoot}/../specs/security/standard-names.html#secretkey-algorithms"> |
| 192 | + * Java Security Standard Algorithm Names Specification</a> |
| 193 | + * for information about standard secret key algorithm |
| 194 | + * names. |
| 195 | + * @param label the label bytes used in the EKM calculation. |
| 196 | + * {@code label} will be converted to a {@code byte[]} |
| 197 | + * before the operation begins. |
| 198 | + * @param context the context bytes used in the EKM calculation, or null |
| 199 | + * @param length the number of bytes of EKM material needed |
| 200 | + * |
| 201 | + * @throws SSLKeyException if the key cannot be generated |
| 202 | + * @throws IllegalArgumentException if {@code keyAlg} is empty, |
| 203 | + * {@code length} is non-positive, or if the {@code label} or |
| 204 | + * {@code context} length can not be accommodated |
| 205 | + * @throws NullPointerException if {@code keyAlg} or {@code label} is null |
| 206 | + * @throws IllegalStateException if this session does not have the |
| 207 | + * necessary key generation material (for example, a session |
| 208 | + * under construction during handshaking) |
| 209 | + * @throws UnsupportedOperationException if the underlying provider |
| 210 | + * does not implement the operation |
| 211 | + * |
| 212 | + * @return a {@code SecretKey} that contains {@code length} bytes of the |
| 213 | + * EKM material |
| 214 | + * |
| 215 | + * @since 25 |
| 216 | + */ |
| 217 | + public SecretKey exportKeyingMaterialKey(String keyAlg, |
| 218 | + String label, byte[] context, int length) throws SSLKeyException { |
| 219 | + throw new UnsupportedOperationException( |
| 220 | + "Underlying provider does not implement the method"); |
| 221 | + } |
| 222 | + |
| 223 | + /** |
| 224 | + * Generates Exported Keying Material (EKM) calculated according to the |
| 225 | + * algorithms defined in RFCs 5705/8446. |
| 226 | + * <P> |
| 227 | + * RFC 5705 (for (D)TLSv1.2 and earlier) calculates different EKM |
| 228 | + * values depending on whether {@code context} is null or non-null/empty. |
| 229 | + * RFC 8446 (TLSv1.3) treats a null context as non-null/empty. |
| 230 | + * <P> |
| 231 | + * {@code label} will be converted to bytes using |
| 232 | + * the {@link java.nio.charset.StandardCharsets#UTF_8} |
| 233 | + * character encoding. |
| 234 | + * <P> |
| 235 | + * Depending on the chosen underlying key derivation mechanism, the |
| 236 | + * raw bytes might not be extractable/exportable. In such cases, the |
| 237 | + * {@link #exportKeyingMaterialKey(String, String, byte[], int)} method |
| 238 | + * should be used instead to access the generated key material. |
| 239 | + * |
| 240 | + * @spec https://www.rfc-editor.org/info/rfc5705 |
| 241 | + * RFC 5705: Keying Material Exporters for Transport Layer |
| 242 | + * Security (TLS) |
| 243 | + * @spec https://www.rfc-editor.org/info/rfc8446 |
| 244 | + * RFC 8446: The Transport Layer Security (TLS) Protocol Version 1.3 |
| 245 | + * |
| 246 | + * @implSpec The default implementation throws |
| 247 | + * {@code UnsupportedOperationException}. |
| 248 | + * |
| 249 | + * @param label the label bytes used in the EKM calculation. |
| 250 | + * {@code label} will be converted to a {@code byte[]} |
| 251 | + * before the operation begins. |
| 252 | + * @param context the context bytes used in the EKM calculation, or null |
| 253 | + * @param length the number of bytes of EKM material needed |
| 254 | + * |
| 255 | + * @throws SSLKeyException if the key cannot be generated |
| 256 | + * @throws IllegalArgumentException if {@code length} is non-positive, |
| 257 | + * or if the {@code label} or {@code context} length can |
| 258 | + * not be accommodated |
| 259 | + * @throws NullPointerException if {@code label} is null |
| 260 | + * @throws IllegalStateException if this session does not have the |
| 261 | + * necessary key generation material (for example, a session |
| 262 | + * under construction during handshaking) |
| 263 | + * @throws UnsupportedOperationException if the underlying provider |
| 264 | + * does not implement the operation, or if the derived |
| 265 | + * keying material is not extractable |
| 266 | + * |
| 267 | + * @return a byte array of size {@code length} that contains the EKM |
| 268 | + * material |
| 269 | + * @since 25 |
| 270 | + */ |
| 271 | + public byte[] exportKeyingMaterialData( |
| 272 | + String label, byte[] context, int length) throws SSLKeyException { |
| 273 | + throw new UnsupportedOperationException( |
| 274 | + "Underlying provider does not implement the method"); |
| 275 | + } |
166 | 276 | }
|
0 commit comments