IpSecManager
public
final
class
IpSecManager
extends Object
| java.lang.Object | |
| ↳ | android.net.IpSecManager |
This class contains methods for managing IPsec sessions, which will perform kernel-space encryption and decryption of socket or Network traffic.
An IpSecManager may be obtained by calling Context#getSystemService(String) with Context#IPSEC_SERVICE
Summary
Nested classes | |
|---|---|
class |
IpSecManager.ResourceUnavailableException
Indicates that the requested system resource for IPsec, such as a socket or other system resource is unavailable. |
class |
IpSecManager.SecurityParameterIndex
|
class |
IpSecManager.SpiUnavailableException
Indicates that the combination of remote InetAddress and SPI was non-unique for a given request. |
class |
IpSecManager.UdpEncapsulationSocket
Class providing access to a system-provided UDP Encapsulation Socket, which may be used for IKE signalling as well as for inbound and outbound UDP encapsulated IPsec traffic. |
Constants | |
|---|---|
int |
INVALID_SECURITY_PARAMETER_INDEX
The Security Parameter Index, SPI, 0 indicates an unknown or invalid index. |
Public methods | |
|---|---|
void
|
applyTransportModeTransform(FileDescriptor socket, IpSecTransform transform)
Apply an active Transport Mode IPsec Transform to a stream socket to perform IPsec encapsulation of the traffic flowing between the socket and the remote InetAddress of that transform. |
IpSecManager.UdpEncapsulationSocket
|
openUdpEncapsulationSocket(int port)
Open a socket that is bound to a free UDP port on the system. |
IpSecManager.UdpEncapsulationSocket
|
openUdpEncapsulationSocket()
Open a socket that is bound to a port selected by the system. |
void
|
removeTransportModeTransform(FileDescriptor socket, IpSecTransform transform)
Remove a transform from a given stream socket. |
IpSecManager.SecurityParameterIndex
|
reserveSecurityParameterIndex(int direction, InetAddress remoteAddress, int requestedSpi)
Reserve an SPI for traffic bound towards the specified remote address. |
IpSecManager.SecurityParameterIndex
|
reserveSecurityParameterIndex(int direction, InetAddress remoteAddress)
Reserve an SPI for traffic bound towards the specified remote address. |
Inherited methods | |
|---|---|
java.lang.Object
| |
Constants
INVALID_SECURITY_PARAMETER_INDEX
int INVALID_SECURITY_PARAMETER_INDEX
The Security Parameter Index, SPI, 0 indicates an unknown or invalid index.
No IPsec packet may contain an SPI of 0.
Constant Value: 0 (0x00000000)
Public methods
applyTransportModeTransform
void applyTransportModeTransform (FileDescriptor socket, IpSecTransform transform)
Apply an active Transport Mode IPsec Transform to a stream socket to perform IPsec
encapsulation of the traffic flowing between the socket and the remote InetAddress of that
transform. For security reasons, attempts to send traffic to any IP address other than the
address associated with that transform will throw an IOException. In addition, if the
IpSecTransform is later deactivated, the socket will throw an IOException on any calls to
send() or receive() until the transform is removed from the socket by calling removeTransportModeTransform(FileDescriptor, IpSecTransform);
| Parameters | |
|---|---|
socket |
FileDescriptor:
a socket file descriptor |
transform |
IpSecTransform:
an IpSecTransform, which must be an active Transport Mode transform.
|
| Throws | |
|---|---|
IOException |
|
openUdpEncapsulationSocket
IpSecManager.UdpEncapsulationSocket openUdpEncapsulationSocket (int port)
Open a socket that is bound to a free UDP port on the system.
By binding in this manner and holding the FileDescriptor, the socket cannot be un-bound by the caller. This provides safe access to a socket on a port that can later be used as a UDP Encapsulation port.
This socket reservation works in conjunction with IpSecTransforms, which may re-use the socket port. Explicitly opening this port is only necessary if communication is desired on that port.
| Parameters | |
|---|---|
port |
int:
a local UDP port to be reserved for UDP Encapsulation. is provided, then this
method will bind to the specified port or fail. To retrieve the port number, call getsockname(FileDescriptor). |
| Returns | |
|---|---|
IpSecManager.UdpEncapsulationSocket |
a IpSecManager.UdpEncapsulationSocket that is bound to the requested port for the lifetime
of the object.
|
| Throws | |
|---|---|
IOException |
|
IpSecManager.ResourceUnavailableException |
|
openUdpEncapsulationSocket
IpSecManager.UdpEncapsulationSocket openUdpEncapsulationSocket ()
Open a socket that is bound to a port selected by the system.
By binding in this manner and holding the FileDescriptor, the socket cannot be un-bound by the caller. This provides safe access to a socket on a port that can later be used as a UDP Encapsulation port.
This socket reservation works in conjunction with IpSecTransforms, which may re-use the socket port. Explicitly opening this port is only necessary if communication is desired on that port.
| Returns | |
|---|---|
IpSecManager.UdpEncapsulationSocket |
a IpSecManager.UdpEncapsulationSocket that is bound to an arbitrarily selected port
|
| Throws | |
|---|---|
IOException |
|
IpSecManager.ResourceUnavailableException |
|
removeTransportModeTransform
void removeTransportModeTransform (FileDescriptor socket, IpSecTransform transform)
Remove a transform from a given stream socket. Once removed, traffic on the socket will not be encypted. This allows sockets that have been used for IPsec to be reclaimed for communication in the clear in the event socket reuse is desired. This operation will succeed regardless of the underlying state of a transform. If a transform is removed, communication on all sockets to which that transform was applied will fail until this method is called.
| Parameters | |
|---|---|
socket |
FileDescriptor:
a socket file descriptor that previously had a transform applied to it. |
transform |
IpSecTransform:
the IPsec Transform that was previously applied to the given socket
|
| Throws | |
|---|---|
IOException |
|
reserveSecurityParameterIndex
IpSecManager.SecurityParameterIndex reserveSecurityParameterIndex (int direction, InetAddress remoteAddress, int requestedSpi)
Reserve an SPI for traffic bound towards the specified remote address.
If successful, this SPI is guaranteed available until released by a call to close().
| Parameters | |
|---|---|
direction |
int:
DIRECTION_IN or DIRECTION_OUT |
remoteAddress |
InetAddress:
address of the remote. SPIs must be unique for each remoteAddress. |
requestedSpi |
int:
the requested SPI, or '0' to allocate a random SPI. |
| Returns | |
|---|---|
IpSecManager.SecurityParameterIndex |
the reserved SecurityParameterIndex |
| Throws | |
|---|---|
IpSecManager.ResourceUnavailableException |
indicating that too many SPIs are currently allocated for this user |
IpSecManager.SpiUnavailableException |
|
reserveSecurityParameterIndex
IpSecManager.SecurityParameterIndex reserveSecurityParameterIndex (int direction, InetAddress remoteAddress)
Reserve an SPI for traffic bound towards the specified remote address.
If successful, this SPI is guaranteed available until released by a call to close().
| Parameters | |
|---|---|
direction |
int:
DIRECTION_IN or DIRECTION_OUT |
remoteAddress |
InetAddress:
address of the remote. SPIs must be unique for each remoteAddress. |
| Returns | |
|---|---|
IpSecManager.SecurityParameterIndex |
the reserved SecurityParameterIndex |
| Throws | |
|---|---|
IpSecManager.ResourceUnavailableException |
indicating that too many SPIs are currently allocated for this user |
IpSecManager.SpiUnavailableException |
indicating that a particular SPI cannot be reserved |
Interfaces
Classes
- CaptivePortal
- ConnectivityManager
- ConnectivityManager.NetworkCallback
- Credentials
- DhcpInfo
- IpPrefix
- IpSecAlgorithm
- IpSecManager
- IpSecManager.SecurityParameterIndex
- IpSecManager.UdpEncapsulationSocket
- IpSecTransform
- IpSecTransform.Builder
- LinkAddress
- LinkProperties
- LocalServerSocket
- LocalSocket
- LocalSocketAddress
- MailTo
- Network
- NetworkCapabilities
- NetworkInfo
- NetworkRequest
- NetworkRequest.Builder
- NetworkSpecifier
- Proxy
- ProxyInfo
- RouteInfo
- SSLCertificateSocketFactory
- SSLSessionCache
- TrafficStats
- Uri
- Uri.Builder
- UrlQuerySanitizer
- UrlQuerySanitizer.IllegalCharacterValueSanitizer
- UrlQuerySanitizer.ParameterValuePair
- VpnService
- VpnService.Builder
Enums
Exceptions