Stay organized with collections
Save and categorize content based on your preferences.
SSLSockets
open class SSLSockets
Static utility methods for accessing additional functionality of supported instances of SSLSocket
. Sockets from the platform TLS provider will be compatible with all methods in this class.
Summary
Public methods |
open static ByteArray? |
Exports a value derived from the TLS master secret as described in RFC 5705.
|
open static Boolean |
Returns whether the given socket can be used with the methods in this class.
|
open static Unit |
Enables or disables the use of session tickets.
|
Public methods
exportKeyingMaterial
open static fun exportKeyingMaterial(
socket: SSLSocket,
label: String,
context: ByteArray?,
length: Int
): ByteArray?
Exports a value derived from the TLS master secret as described in RFC 5705. A number of protocols leverage Transport Layer Security (TLS) to perform key establishment but then use some of the keying material for their own purposes. This method allows an application to export keying material from a TLS connection. The exported material will be the same on the client and server if they pass in the same values for label
and context
. See RFC 5705 for further details.
Parameters |
socket |
SSLSocket: the socket to use for exporting keying material This value cannot be null . |
label |
String: the label to use in calculating the exported value. This must be an ASCII-only string. This value cannot be null . |
context |
ByteArray?: the application-specific context value to use in calculating the exported value. This may be null to use no application context, which is treated differently than an empty byte array. |
length |
Int: the number of bytes of keying material to return. |
Return |
ByteArray? |
a value of the specified length, or null if the handshake has not yet completed or the connection has been closed. |
Exceptions |
javax.net.ssl.SSLException |
if the value could not be exported. |
isSupportedSocket
open static fun isSupportedSocket(socket: SSLSocket): Boolean
Returns whether the given socket can be used with the methods in this class. In general, only sockets from the platform TLS provider are supported.
Parameters |
socket |
SSLSocket: This value cannot be null . |
setUseSessionTickets
open static fun setUseSessionTickets(
socket: SSLSocket,
useSessionTickets: Boolean
): Unit
Enables or disables the use of session tickets.
This function must be called before the handshake is started or it will have no effect.
Parameters |
socket |
SSLSocket: the socket This value cannot be null . |
useSessionTickets |
Boolean: whether to enable or disable the use of session tickets |
Exceptions |
java.lang.IllegalArgumentException |
if the given socket is not a platform socket |
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-02-10 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-02-10 UTC."],[],[],null,["# SSLSockets\n\nAdded in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)\n\nSSLSockets\n==========\n\n*** ** * ** ***\n\nKotlin \\|[Java](/reference/android/net/ssl/SSLSockets \"View this page in Java\") \n\n```\nopen class SSLSockets\n```\n\n|---|---------------------------------|\n| [kotlin.Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html) ||\n| ↳ | [android.net.ssl.SSLSockets](#) |\n\nStatic utility methods for accessing additional functionality of supported instances of [SSLSocket](../../../javax/net/ssl/SSLSocket.html#). Sockets from the platform TLS provider will be compatible with all methods in this class.\n\nSummary\n-------\n\n| Public methods ||\n|------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| open static [ByteArray](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-byte-array/index.html)? | [exportKeyingMaterial](#exportKeyingMaterial(javax.net.ssl.SSLSocket,%20kotlin.String,%20kotlin.ByteArray,%20kotlin.Int))`(`socket:` `[SSLSocket](../../../javax/net/ssl/SSLSocket.html#)`, `label:` `[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, `context:` `[ByteArray](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-byte-array/index.html)?`, `length:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`)` Exports a value derived from the TLS master secret as described in RFC 5705. |\n| open static [Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html) | [isSupportedSocket](#isSupportedSocket(javax.net.ssl.SSLSocket))`(`socket:` `[SSLSocket](../../../javax/net/ssl/SSLSocket.html#)`)` Returns whether the given socket can be used with the methods in this class. |\n| open static [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [setUseSessionTickets](#setUseSessionTickets(javax.net.ssl.SSLSocket,%20kotlin.Boolean))`(`socket:` `[SSLSocket](../../../javax/net/ssl/SSLSocket.html#)`, `useSessionTickets:` `[Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)`)` Enables or disables the use of session tickets. |\n\nPublic methods\n--------------\n\n### exportKeyingMaterial\n\nAdded in [API level 31](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nopen static fun exportKeyingMaterial(\n socket: SSLSocket, \n label: String, \n context: ByteArray?, \n length: Int\n): ByteArray?\n```\n\nExports a value derived from the TLS master secret as described in RFC 5705. A number of protocols leverage Transport Layer Security (TLS) to perform key establishment but then use some of the keying material for their own purposes. This method allows an application to export keying material from a TLS connection. The exported material will be the same on the client and server if they pass in the same values for `label` and `context`. See RFC 5705 for further details.\n\n| Parameters ||\n|-----------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `socket` | [SSLSocket](../../../javax/net/ssl/SSLSocket.html#): the socket to use for exporting keying material This value cannot be `null`. |\n| `label` | [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html): the label to use in calculating the exported value. This must be an ASCII-only string. This value cannot be `null`. |\n| `context` | [ByteArray](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-byte-array/index.html)?: the application-specific context value to use in calculating the exported value. This may be `null` to use no application context, which is treated differently than an empty byte array. |\n| `length` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html): the number of bytes of keying material to return. |\n\n| Return ||\n|------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------|\n| [ByteArray](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-byte-array/index.html)? | a value of the specified length, or `null` if the handshake has not yet completed or the connection has been closed. |\n\n| Exceptions ||\n|------------------------------|-------------------------------------|\n| `javax.net.ssl.SSLException` | if the value could not be exported. |\n\n### isSupportedSocket\n\nAdded in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nopen static fun isSupportedSocket(socket: SSLSocket): Boolean\n```\n\nReturns whether the given socket can be used with the methods in this class. In general, only sockets from the platform TLS provider are supported.\n\n| Parameters ||\n|----------|-----------------------------------------------------------------------------------|\n| `socket` | [SSLSocket](../../../javax/net/ssl/SSLSocket.html#): This value cannot be `null`. |\n\n### setUseSessionTickets\n\nAdded in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nopen static fun setUseSessionTickets(\n socket: SSLSocket, \n useSessionTickets: Boolean\n): Unit\n```\n\nEnables or disables the use of session tickets.\n\nThis function must be called before the handshake is started or it will have no effect.\n\n| Parameters ||\n|---------------------|---------------------------------------------------------------------------------------------------------------------------------------------|\n| `socket` | [SSLSocket](../../../javax/net/ssl/SSLSocket.html#): the socket This value cannot be `null`. |\n| `useSessionTickets` | [Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html): whether to enable or disable the use of session tickets |\n\n| Exceptions ||\n|--------------------------------------|----------------------------------------------|\n| `java.lang.IllegalArgumentException` | if the given socket is not a platform socket |"]]