If the caller instantiates the context using the default
GSSManager instance, then the Kerberos v5 GSS-API mechanism
is guaranteed to be available for context establishment. This mechanism
is identified by the Oid "1.2.840.113554.1.2.2" and is defined in RFC
1964.
Before the context establishment phase is initiated, the context
initiator may request specific characteristics desired of the
established context. Not all underlying mechanisms support all
characteristics that a caller might desire. After the context is
established, the caller can check the actual characteristics and services
offered by that context by means of various query methods. When using
the Kerberos v5 GSS-API mechanism offered by the default
GSSManager instance, all optional services will be
available locally. They are mutual authentication, credential
delegation, confidentiality and integrity protection, and per-message
replay detection and sequencing. Note that in the GSS-API, message integrity
is a prerequisite for message confidentiality.
The context establishment occurs in a loop where the
initiator calls initSecContext
and the acceptor calls acceptSecContext until the context is established. While in this loop
the initSecContext and acceptSecContext
methods produce tokens that the application sends over to the peer. The
peer passes any such token as input to its acceptSecContext
or initSecContext as the case may be.
During the context establishment phase, the isProtReady method may be called to determine if the
context can be used for the per-message operations of wrap and getMIC. This allows applications to use
per-message operations on contexts which aren't yet fully
established.
After the context has been established or the isProtReady
method returns true, the query routines can be invoked to
determine the actual characteristics and services of the established
context. The application can also start using the per-message methods
of wrap and
getMIC to obtain
cryptographic operations on application supplied data.
When the context is no longer needed, the application should call
dispose to release any system resources the context
may be using.
A security context typically maintains sequencing and replay detection
information about the tokens it processes. Therefore, the sequence in
which any tokens are presented to this context for processing can be
important. Also note that none of the methods in this interface are
synchronized. Therefore, it is not advisable to share a
GSSContext among several threads unless some application
level synchronization is in place.
The stream-based methods of GSSContext have been deprecated in
Java SE 11. These methods have also been removed from
RFC 8353: Generic Security Service API Version 2: Java Bindings Update
for the following reasons (see section 11): "The overloaded methods of
GSSContext that use input and output streams as the means to convey
authentication and per-message GSS-API tokens as described in Section 5.15
of RFC 5653 are removed in this update as the wire protocol
should be defined by an application and not a library. It's also impossible
to implement these methods correctly when the token has no self-framing
(where the end cannot be determined), or the library has no knowledge of
the token format (for example, as a bridge talking to another GSS library)".
These methods include initSecContext(InputStream, OutputStream),
acceptSecContext(InputStream, OutputStream),
wrap(InputStream, OutputStream, MessageProp),
unwrap(InputStream, OutputStream, MessageProp),
getMIC(InputStream, OutputStream, MessageProp),
and verifyMIC(InputStream, InputStream, MessageProp).
The example code presented below demonstrates the usage of the
GSSContext interface for the initiating peer. Different
operations on the GSSContext object are presented,
including: object instantiation, setting of desired flags, context
establishment, query of actual context flags, per-message operations on
application data, and finally context deletion.
// Create a context using default credentials
// and the implementation specific default mechanism
GSSManager manager = ...
GSSName targetName = ...
GSSContext context = manager.createContext(targetName, null, null,
GSSContext.INDEFINITE_LIFETIME);
// set desired context options prior to context establishment
context.requestConf(true);
context.requestMutualAuth(true);
context.requestReplayDet(true);
context.requestSequenceDet(true);
// establish a context between peers
byte[] inToken = new byte[0];
byte[] outToken;
// Loop while there still is a token to be processed
while (!context.isEstablished()) {
outToken = context.initSecContext(inToken, 0, inToken.length);
// send the output token if generated
if (outToken != null) {
sendToken(outToken);
}
if (!context.isEstablished()) {
inToken = readToken();
}
}
// display context information
System.out.println("Remaining lifetime in seconds = "
+ context.getLifetime());
System.out.println("Context mechanism = " + context.getMech());
System.out.println("Initiator = " + context.getSrcName());
System.out.println("Acceptor = " + context.getTargName());
if (context.getConfState()) {
System.out.println("Confidentiality (i.e., privacy) is available");
}
if (context.getIntegState()) {
System.out.println("Integrity is available");
}
// perform wrap on an application supplied message, appMsg,
// using QOP = 0, and requesting privacy service
byte[] appMsg = ...
MessageProp mProp = new MessageProp(0, true);
outToken = context.wrap(appMsg, 0, appMsg.length, mProp);
sendToken(outToken);
// perform unwrap on an incoming application message, and check
// its privacy state and supplementary information
inToken = readToken();
mProp = new MessageProp(0, true);
appMsg = context.unwrap(inToken, 0, inToken.length, mProp);
System.out.println("Was it encrypted? " + mProp.getPrivacy());
System.out.println("Duplicate Token? " + mProp.isDuplicateToken());
System.out.println("Old Token? " + mProp.isOldToken());
System.out.println("Unsequenced Token? " + mProp.isUnseqToken());
System.out.println("Gap Token? " + mProp.isGapToken());
// the application determines if the privacy state and supplementary
// information are acceptable
// release the local-end of the context
context.dispose();
| Modifier and Type | Field and Description |
|---|---|
| public static final int | DEFAULT_LIFETIME
A lifetime constant representing the default context lifetime. |
| public static final int | INDEFINITE_LIFETIME
A lifetime constant representing indefinite context lifetime. |
| Modifier and Type | Method and Description |
|---|---|
| public byte[] | Returns: a byte[] containing the token to be sent to the peer.null indicates that no token is generated.token generated by the peer. inToken, int the offset within the inToken where the token begins. offset, int the length of the token. len)Called by the context acceptor upon receiving a token from the peer. |
| public void | acceptSecContext(InputStream
an InputStream that contains the token generated by
the peer. inStream, OutputStream an OutputStream where the output token will be
written. During the final stage of context establishment, there may be
no bytes written. outStream)
Deprecated
since 11. The stream-based methods have been removed from RFC 8353.
Use
acceptSecContext(byte[], int, int) instead.
Called by the context acceptor to process a token from the peer using streams. |
| public void | dispose()
Releases any system resources and cryptographic information stored in the context object and invalidates the context. |
| public byte[] | Returns: a byte[] containing the exported contextExports this context so that another process may import it. |
| public boolean | Returns: true if the context initiator is still anonymous, false otherwise.Determines if the context initiator is anonymously authenticated to the context acceptor. |
| public boolean | Returns: true if confidentiality services are available, false otherwise.Determines if data confidentiality is available over the context. |
| public boolean | Returns: true if delegation is enabled, false otherwise.Determines if credential delegation is enabled on this context. |
| public GSSCredential | Returns: a GSSCredential containing the initiator's delegated credentials, ornull is no credentials
were delegated.Obtains the credentials delegated by the context initiator to the context acceptor. |
| public boolean | Returns: true if integrity services are available, false otherwise.Determines if data integrity is available over the context. |
| public int | Returns: the remaining lifetime in secondsDetermines what the remaining lifetime for this context is. |
| public Oid | Returns: the Oid of the mechanism being usedDetermines what mechanism is being used for this context. |
| public byte[] | Returns: a byte[] containing the token to be sent to the peer.the message to generate the MIC over. inMsg, int offset within the inMsg where the message begins. offset, int the length of the message len, MessageProp an instance of msgProp)MessageProp that is used
by the application to set the desired QOP. Set the desired QOP to
0 in msgProp to request the default
QOP. Alternatively pass in null for msgProp
to request the default QOP.Returns a token containing a cryptographic Message Integrity Code (MIC) for the supplied message, for transfer to the peer application. |
| public void | getMIC(InputStream
an InputStream containing the message to generate the
MIC over. All the data that is available in
inStream is used. inStream, OutputStream an OutputStream to write the output token to. outStream, MessageProp an instance of msgProp)MessageProp that is used
by the application to set the desired QOP. Set the desired QOP to
0 in msgProp to request the default
QOP. Alternatively pass in null for msgProp
to request the default QOP.
Deprecated
since 11. The stream-based methods have been removed from RFC 8353.
Use
getMIC(byte[], int, int, MessageProp) instead.
Uses streams to produce a token containing a cryptographic MIC for the supplied message, for transfer to the peer application. |
| public boolean | Returns: true if mutual authentication is enabled, false otherwise.Determines if mutual authentication is enabled on this context. |
| public boolean | Returns: true if replay detection is enabled, false otherwise.Determines if replay detection is enabled for the per-message security services from this context. |
| public boolean | Returns: true if sequence checking is enabled, false otherwise.Determines if sequence checking is enabled for the per-message security services from this context. |
| public GSSName | Returns: a GSSName that is an MN containing the name of the context initiator.Returns the name of the context initiator. |
| public GSSName | Returns: a GSSName that is an MN containing the name of the context acceptor.Returns the name of the context acceptor. |
| public int | Returns: the maximum size of the input token for the given output token sizethe level of protection wrap will be asked to provide. qop, boolean true if wrap will be asked to provide
privacy, false otherwise.the desired maximum size of the token emitted by
wrap. maxTokenSize)Used to determine limits on the size of the message
that can be passed to |
| public byte[] | Returns: a byte[] containing the token to be sent to the peer.null indicates that no token is generated.token generated by the peer. This parameter is ignored
on the first call since no token has been received from the peer. inputBuf, int the offset within the inputBuf where the token begins. offset, int the length of the token. len)Called by the context initiator to start the context creation
phase and process any tokens generated
by the peer's |
| public int | Returns: the number of bytes written to the OutputStream as part of the token to be sent to the peer. A value of 0 indicates that no token needs to be sent.an InputStream that contains the token generated by
the peer. This parameter is ignored on the first call since no token
has been or will be received from the peer at that point. inStream, OutputStream an OutputStream where the output token will be
written. During the final stage of context establishment, there may be
no bytes written. outStream)
Deprecated
since 11. The stream-based methods have been removed from RFC 8353.
Use
initSecContext(byte[], int, int) instead.
Called by the context initiator to start the context creation
phase and process any tokens generated
by the peer's |
| public boolean | Returns: true if this is a fully established context on
the caller's side and no more tokens are needed from the peer.Used during context establishment to determine the state of the context. |
| public boolean | Returns: true if this is the context initiator, false if it is the context acceptor.Determines if this is the context initiator. |
| public boolean | Returns: true if methods likewrap, unwrap,
getMIC, and verifyMIC can be used with
this context at the current stage of context establishment, false
otherwise.Determines if the context is ready for per message operations to be used over it. |
| public boolean | Returns: true if this context can be exported, false otherwise.Determines if the context is transferable to other processes
through the use of the |
| public void | requestAnonymity(boolean
a boolean value indicating if the initiator should
be authenticated to the acceptor as an anonymous principal. state)Requests that the initiator's identity not be disclosed to the acceptor. |
| public void | requestConf(boolean
a boolean value indicating whether confidentiality
should be enabled or not. state)Requests that data confidentiality be enabled
for the |
| public void | requestCredDeleg(boolean
a boolean value indicating whether the credentials
should be delegated or not. state)Requests that the initiator's credentials be delegated to the acceptor during context establishment. |
| public void | requestInteg(boolean
a boolean value indicating whether integrity
should be enabled or not. state)Requests that data integrity be enabled
for the |
| public void | requestLifetime(int
the desired context lifetime in seconds. Use
lifetime)INDEFINITE_LIFETIME to request an indefinite lifetime
and DEFAULT_LIFETIME to request a default lifetime.Requests a lifetime in seconds for the context. |
| public void | requestMutualAuth(boolean
a boolean value indicating whether mutual
authentication should be used or not. state)Requests that mutual authentication be done during context establishment. |
| public void | requestReplayDet(boolean
a boolean value indicating whether replay detection
should be enabled over the established context or not. state)Requests that replay detection be enabled for the per-message security services after context establishment. |
| public void | requestSequenceDet(boolean
a boolean value indicating whether sequence checking
should be enabled over the established context or not. state)Requests that sequence checking be enabled for the per-message security services after context establishment. |
| public void | setChannelBinding(ChannelBinding
the channel bindings to use. cb)Sets the channel bindings to be used during context establishment. |
| public byte[] | Returns: a byte[] containing the message unwrapped from the input token.a byte array containing the wrap token received from
peer. inBuf, int the offset where the token begins. offset, int the length of the token len, MessageProp upon return from the method, this object will contain
the applied QOP, the privacy state of the message, and supplementary
information stating if the token was a duplicate, old, out of
sequence or arriving after a gap. msgProp)Used to process tokens generated by the |
| public void | unwrap(InputStream
an InputStream that contains the wrap token generated
by the peer. inStream, OutputStream an OutputStream to write the application message
to. outStream, MessageProp upon return from the method, this object will contain
the applied QOP, the privacy state of the message, and supplementary
information stating if the token was a duplicate, old, out of
sequence or arriving after a gap. msgProp)
Deprecated
since 11. The stream-based methods have been removed from RFC 8353.
Use
unwrap(byte[], int, int, MessageProp) instead.
Uses streams to process tokens generated by the |
| public void | verifyMIC(byte[]
the token generated by peer's getMIC method. inToken, int the offset within the inToken where the token
begins. tokOffset, int the length of the token. tokLen, byte[] the application message to verify the cryptographic MIC
over. inMsg, int the offset in inMsg where the message begins. msgOffset, int the length of the message. msgLen, MessageProp upon return from the method, this object will contain
the applied QOP and supplementary information stating if the token
was a duplicate, old, out of sequence or arriving after a gap. msgProp)Verifies the cryptographic MIC, contained in the token parameter, over the supplied message. |
| public void | verifyMIC(InputStream
an InputStream containing the token generated by the
peer's getMIC method. tokStream, InputStream an InputStream containing the application message to
verify the cryptographic MIC over. All the data
that is available in msgStream is used. msgStream, MessageProp upon return from the method, this object will contain
the applied QOP and supplementary information stating if the token
was a duplicate, old, out of sequence or arriving after a gap. msgProp)
Deprecated
since 11. The stream-based methods have been removed from RFC 8353.
Uses streams to verify the cryptographic MIC, contained in the token parameter, over the supplied message. |
| public byte[] | Returns: a byte[] containing the token to be sent to the peer.application data to be protected. inBuf, int the offset within the inBuf where the data begins. offset, int the length of the data len, MessageProp instance of MessageProp that is used by the
application to set the desired QOP and privacy state. Set the
desired QOP to 0 to request the default QOP. Upon return from this
method, this object will contain the actual privacy state that
was applied to the message by the underlying mechanism. msgProp)Applies per-message security services over the established security context. |
| public void | wrap(InputStream
an InputStream containing the application data to be
protected. All the data that is available in
inStream is used. inStream, OutputStream an OutputStream to write the protected message
to. outStream, MessageProp instance of MessageProp that is used by the
application to set the desired QOP and privacy state. Set the
desired QOP to 0 to request the default QOP. Upon return from this
method, this object will contain the actual privacy state that
was applied to the message by the underlying mechanism. msgProp)
Deprecated
since 11. The stream-based methods have been removed from RFC 8353.
Use
wrap(byte[], int, int, MessageProp) instead.
Applies per-message security services over the established security context using streams. |