- All Known Subinterfaces:
ExtendedGSSContext
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.
Finally, different mechanism providers might place different security restrictions on using GSS-API contexts. These will be documented by the mechanism provider. The application will need to ensure that it has the appropriate permissions if such checks are made in the mechanism layer.
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();
- Since:
- 1.4
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intA lifetime constant representing the default context lifetime.static final intA lifetime constant representing indefinite context lifetime. -
Method Summary
Modifier and TypeMethodDescriptionbyte[]acceptSecContext(byte[] inToken, int offset, int len) Called by the context acceptor upon receiving a token from the peer.voidacceptSecContext(InputStream inStream, OutputStream outStream) Deprecated.The stream-based methods have been removed from RFC 8353.voiddispose()Releases any system resources and cryptographic information stored in the context object and invalidates the context.byte[]export()Exports this context so that another process may import it.booleanDetermines if the context initiator is anonymously authenticated to the context acceptor.booleanDetermines if data confidentiality is available over the context.booleanDetermines if credential delegation is enabled on this context.Obtains the credentials delegated by the context initiator to the context acceptor.booleanDetermines if data integrity is available over the context.intDetermines what the remaining lifetime for this context is.getMech()Determines what mechanism is being used for this context.byte[]getMIC(byte[] inMsg, int offset, int len, MessageProp msgProp) Returns a token containing a cryptographic Message Integrity Code (MIC) for the supplied message, for transfer to the peer application.voidgetMIC(InputStream inStream, OutputStream outStream, MessageProp msgProp) Deprecated.The stream-based methods have been removed from RFC 8353.booleanDetermines if mutual authentication is enabled on this context.booleanDetermines if replay detection is enabled for the per-message security services from this context.booleanDetermines if sequence checking is enabled for the per-message security services from this context.Returns the name of the context initiator.Returns the name of the context acceptor.intgetWrapSizeLimit(int qop, boolean confReq, int maxTokenSize) Used to determine limits on the size of the message that can be passed towrap.byte[]initSecContext(byte[] inputBuf, int offset, int len) Called by the context initiator to start the context creation phase and process any tokens generated by the peer'sacceptSecContextmethod.intinitSecContext(InputStream inStream, OutputStream outStream) Deprecated.The stream-based methods have been removed from RFC 8353.booleanUsed during context establishment to determine the state of the context.booleanDetermines if this is the context initiator.booleanDetermines if the context is ready for per message operations to be used over it.booleanDetermines if the context is transferable to other processes through the use of theexportmethod.voidrequestAnonymity(boolean state) Requests that the initiator's identity not be disclosed to the acceptor.voidrequestConf(boolean state) Requests that data confidentiality be enabled for thewrapmethod.voidrequestCredDeleg(boolean state) Requests that the initiator's credentials be delegated to the acceptor during context establishment.voidrequestInteg(boolean state) Requests that data integrity be enabled for thewrapandgetMICmethods.voidrequestLifetime(int lifetime) Requests a lifetime in seconds for the context.voidrequestMutualAuth(boolean state) Requests that mutual authentication be done during context establishment.voidrequestReplayDet(boolean state) Requests that replay detection be enabled for the per-message security services after context establishment.voidrequestSequenceDet(boolean state) Requests that sequence checking be enabled for the per-message security services after context establishment.voidSets the channel bindings to be used during context establishment.byte[]unwrap(byte[] inBuf, int offset, int len, MessageProp msgProp) Used to process tokens generated by thewrapmethod on the other side of the context.voidunwrap(InputStream inStream, OutputStream outStream, MessageProp msgProp) Deprecated.The stream-based methods have been removed from RFC 8353.voidverifyMIC(byte[] inToken, int tokOffset, int tokLen, byte[] inMsg, int msgOffset, int msgLen, MessageProp msgProp) Verifies the cryptographic MIC, contained in the token parameter, over the supplied message.voidverifyMIC(InputStream tokStream, InputStream msgStream, MessageProp msgProp) Deprecated.The stream-based methods have been removed from RFC 8353.byte[]wrap(byte[] inBuf, int offset, int len, MessageProp msgProp) Applies per-message security services over the established security context.voidwrap(InputStream inStream, OutputStream outStream, MessageProp msgProp) Deprecated.The stream-based methods have been removed from RFC 8353.
-
Field Details
-
DEFAULT_LIFETIME
static final int DEFAULT_LIFETIMEA lifetime constant representing the default context lifetime. This value is set to 0.- See Also:
-
INDEFINITE_LIFETIME
static final int INDEFINITE_LIFETIMEA lifetime constant representing indefinite context lifetime. This value must is set to the maximum integer value in Java -Integer.MAX_VALUE.- See Also:
-
-
Method Details
-
initSecContext
Called by the context initiator to start the context creation phase and process any tokens generated by the peer'sacceptSecContextmethod. This method may return an output token which the application will need to send to the peer for processing by itsacceptSecContextmethod. The application can callisEstablishedto determine if the context establishment phase is complete on this side of the context. A return value offalsefromisEstablishedindicates that more tokens are expected to be supplied toinitSecContext. Upon completion of the context establishment, the available context options may be queried through the get methods.Note that it is possible that the
initSecContextmethod return a token for the peer, andisEstablishedreturntruealso. This indicates that the token needs to be sent to the peer, but the local end of the context is now fully established.Some mechanism providers might require that the caller be granted permission to initiate a security context. A failed permission check might cause a
SecurityExceptionto be thrown from this method.- Parameters:
inputBuf- token generated by the peer. This parameter is ignored on the first call since no token has been received from the peer.offset- the offset within the inputBuf where the token begins.len- the length of the token.- Returns:
- a byte[] containing the token to be sent to the
peer.
nullindicates that no token is generated. - Throws:
GSSException- containing the following major error codes:GSSException.DEFECTIVE_TOKEN,GSSException.BAD_MIC,GSSException.NO_CRED,GSSException.CREDENTIALS_EXPIRED,GSSException.BAD_BINDINGS,GSSException.OLD_TOKEN,GSSException.DUPLICATE_TOKEN,GSSException.BAD_NAMETYPE,GSSException.BAD_MECH,GSSException.FAILURE
-
initSecContext
@Deprecated(since="11") int initSecContext(InputStream inStream, OutputStream outStream) throws GSSException Deprecated.The stream-based methods have been removed from RFC 8353. UseinitSecContext(byte[], int, int)instead.Called by the context initiator to start the context creation phase and process any tokens generated by the peer'sacceptSecContextmethod using streams. This method may write an output token to theOutpuStream, which the application will need to send to the peer for processing by itsacceptSecContextcall. Typically, the application would ensure this by calling theflushmethod on anOutputStreamthat encapsulates the connection between the two peers. The application can determine if a token is written to the OutputStream from the return value of this method. A return value of0indicates that no token was written. The application can callisEstablishedto determine if the context establishment phase is complete on this side of the context. A return value offalsefromisEstablishedindicates that more tokens are expected to be supplied toinitSecContext. Upon completion of the context establishment, the available context options may be queried through the get methods.Note that it is possible that the
initSecContextmethod return a token for the peer, andisEstablishedreturntruealso. This indicates that the token needs to be sent to the peer, but the local end of the context is now fully established.The GSS-API authentication tokens contain a definitive start and end. This method will attempt to read one of these tokens per invocation, and may block on the stream if only part of the token is available. In all other respects this method is equivalent to the byte array based
initSecContext.Some mechanism providers might require that the caller be granted permission to initiate a security context. A failed permission check might cause a
SecurityExceptionto be thrown from this method.The following example code demonstrates how this method might be used:
InputStream is ... OutputStream os ... GSSContext context ... // Loop while there is still a token to be processed while (!context.isEstablished()) { context.initSecContext(is, os); // send output token if generated os.flush(); }- Parameters:
inStream- 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.outStream- an OutputStream where the output token will be written. During the final stage of context establishment, there may be no bytes written.- 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.
- Throws:
GSSException- containing the following major error codes:GSSException.DEFECTIVE_TOKEN,GSSException.BAD_MIC,GSSException.NO_CRED,GSSException.CREDENTIALS_EXPIRED,GSSException.BAD_BINDINGS,GSSException.OLD_TOKEN,GSSException.DUPLICATE_TOKEN,GSSException.BAD_NAMETYPE,GSSException.BAD_MECH,GSSException.FAILURE
-
acceptSecContext
Called by the context acceptor upon receiving a token from the peer. This method may return an output token which the application will need to send to the peer for further processing by itsinitSecContextcall.The application can call
isEstablishedto determine if the context establishment phase is complete for this peer. A return value offalsefromisEstablishedindicates that more tokens are expected to be supplied to this method. Upon completion of the context establishment, the available context options may be queried through the get methods.Note that it is possible that
acceptSecContextreturn a token for the peer, andisEstablishedreturntruealso. This indicates that the token needs to be sent to the peer, but the local end of the context is now fully established.Some mechanism providers might require that the caller be granted permission to accept a security context. A failed permission check might cause a
SecurityExceptionto be thrown from this method.The following example code demonstrates how this method might be used:
byte[] inToken; byte[] outToken; GSSContext context ... // Loop while there is still a token to be processed while (!context.isEstablished()) { inToken = readToken(); outToken = context.acceptSecContext(inToken, 0, inToken.length); // send output token if generated if (outToken != null) sendToken(outToken); }- Parameters:
inToken- token generated by the peer.offset- the offset within the inToken where the token begins.len- the length of the token.- Returns:
- a byte[] containing the token to be sent to the
peer.
nullindicates that no token is generated. - Throws:
GSSException- containing the following major error codes:GSSException.DEFECTIVE_TOKEN,GSSException.BAD_MIC,GSSException.NO_CRED,GSSException.CREDENTIALS_EXPIRED,GSSException.BAD_BINDINGS,GSSException.OLD_TOKEN,GSSException.DUPLICATE_TOKEN,GSSException.BAD_MECH,GSSException.FAILURE
-
acceptSecContext
@Deprecated(since="11") void acceptSecContext(InputStream inStream, OutputStream outStream) throws GSSException Deprecated.The stream-based methods have been removed from RFC 8353. UseacceptSecContext(byte[], int, int)instead.Called by the context acceptor to process a token from the peer using streams. It may write an output token to theOutputStream, which the application will need to send to the peer for processing by itsinitSecContextmethod. Typically, the application would ensure this by calling theflushmethod on anOutputStreamthat encapsulates the connection between the two peers. The application can callisEstablishedto determine if the context establishment phase is complete on this side of the context. A return value offalsefromisEstablishedindicates that more tokens are expected to be supplied toacceptSecContext. Upon completion of the context establishment, the available context options may be queried through the get methods.Note that it is possible that
acceptSecContextreturn a token for the peer, andisEstablishedreturntruealso. This indicates that the token needs to be sent to the peer, but the local end of the context is now fully established.The GSS-API authentication tokens contain a definitive start and end. This method will attempt to read one of these tokens per invocation, and may block on the stream if only part of the token is available. In all other respects this method is equivalent to the byte array based
acceptSecContext.Some mechanism providers might require that the caller be granted permission to accept a security context. A failed permission check might cause a
SecurityExceptionto be thrown from this method.The following example code demonstrates how this method might be used:
InputStream is ... OutputStream os ... GSSContext context ... // Loop while there is still a token to be processed while (!context.isEstablished()) { context.acceptSecContext(is, os); // send output token if generated os.flush(); }- Parameters:
inStream- an InputStream that contains the token generated by the peer.outStream- an OutputStream where the output token will be written. During the final stage of context establishment, there may be no bytes written.- Throws:
GSSException- containing the following major error codes:GSSException.DEFECTIVE_TOKEN,GSSException.BAD_MIC,GSSException.NO_CRED,GSSException.CREDENTIALS_EXPIRED,GSSException.BAD_BINDINGS,GSSException.OLD_TOKEN,GSSException.DUPLICATE_TOKEN,GSSException.BAD_MECH,GSSException.FAILURE
-
isEstablished
boolean isEstablished()Used during context establishment to determine the state of the context.- Returns:
trueif this is a fully established context on the caller's side and no more tokens are needed from the peer.
-
dispose
Releases any system resources and cryptographic information stored in the context object and invalidates the context.- Throws:
GSSException- containing the following major error codes:GSSException.FAILURE
-
getWrapSizeLimit
Used to determine limits on the size of the message that can be passed towrap. Returns the maximum message size that, if presented to thewrapmethod with the sameconfReqandqopparameters, will result in an output token containing no more thanmaxTokenSizebytes.This call is intended for use by applications that communicate over protocols that impose a maximum message size. It enables the application to fragment messages prior to applying protection.
GSS-API implementations are recommended but not required to detect invalid QOP values when
getWrapSizeLimitis called. This routine guarantees only a maximum message size, not the availability of specific QOP values for message protection.- Parameters:
qop- the level of protection wrap will be asked to provide.confReq-trueif wrap will be asked to provide privacy,falseotherwise.maxTokenSize- the desired maximum size of the token emitted by wrap.- Returns:
- the maximum size of the input token for the given output token size
- Throws:
GSSException- containing the following major error codes:GSSException.CONTEXT_EXPIRED,GSSException.BAD_QOP,GSSException.FAILURE
-
wrap
Applies per-message security services over the established security context. The method will return a token with the application supplied data and a cryptographic MIC over it. The data may be encrypted if confidentiality (privacy) was requested.The MessageProp object is instantiated by the application and used to specify a QOP value which selects cryptographic algorithms, and a privacy service to optionally encrypt the message. The underlying mechanism that is used in the call may not be able to provide the privacy service. It sets the actual privacy service that it does provide in this MessageProp object which the caller should then query upon return. If the mechanism is not able to provide the requested QOP, it throws a GSSException with the BAD_QOP code.
Since some application-level protocols may wish to use tokens emitted by wrap to provide "secure framing", implementations should support the wrapping of zero-length messages.
The application will be responsible for sending the token to the peer.
- Parameters:
inBuf- application data to be protected.offset- the offset within the inBuf where the data begins.len- the length of the datamsgProp- 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.- Returns:
- a byte[] containing the token to be sent to the peer.
- Throws:
GSSException- containing the following major error codes:GSSException.CONTEXT_EXPIRED,GSSException.BAD_QOP,GSSException.FAILURE
-
wrap
@Deprecated(since="11") void wrap(InputStream inStream, OutputStream outStream, MessageProp msgProp) throws GSSException Deprecated.The stream-based methods have been removed from RFC 8353. Usewrap(byte[], int, int, MessageProp)instead.Applies per-message security services over the established security context using streams. The method will return a token with the application supplied data and a cryptographic MIC over it. The data may be encrypted if confidentiality (privacy) was requested. This method is equivalent to the byte array basedwrapmethod.The application will be responsible for sending the token to the peer. Typically, the application would ensure this by calling the
flushmethod on anOutputStreamthat encapsulates the connection between the two peers.The MessageProp object is instantiated by the application and used to specify a QOP value which selects cryptographic algorithms, and a privacy service to optionally encrypt the message. The underlying mechanism that is used in the call may not be able to provide the privacy service. It sets the actual privacy service that it does provide in this MessageProp object which the caller should then query upon return. If the mechanism is not able to provide the requested QOP, it throws a GSSException with the BAD_QOP code.
Since some application-level protocols may wish to use tokens emitted by wrap to provide "secure framing", implementations should support the wrapping of zero-length messages.
- Parameters:
inStream- an InputStream containing the application data to be protected. All the data that is available in inStream is used.outStream- an OutputStream to write the protected message to.msgProp- 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.- Throws:
GSSException- containing the following major error codes:GSSException.CONTEXT_EXPIRED,GSSException.BAD_QOP,GSSException.FAILURE
-
unwrap
Used to process tokens generated by thewrapmethod on the other side of the context. The method will return the message supplied by the peer application to its wrap call, while at the same time verifying the embedded MIC for that message.The MessageProp object is instantiated by the application and is used by the underlying mechanism to return information to the caller such as the QOP, whether confidentiality was applied to the message, and other supplementary message state information.
Since some application-level protocols may wish to use tokens emitted by wrap to provide "secure framing", implementations should support the wrapping and unwrapping of zero-length messages.
- Parameters:
inBuf- a byte array containing the wrap token received from peer.offset- the offset where the token begins.len- the length of the tokenmsgProp- 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.- Returns:
- a byte[] containing the message unwrapped from the input token.
- Throws:
GSSException- containing the following major error codes:GSSException.DEFECTIVE_TOKEN,GSSException.BAD_MIC,GSSException.CONTEXT_EXPIRED,GSSException.FAILURE
-
unwrap
@Deprecated(since="11") void unwrap(InputStream inStream, OutputStream outStream, MessageProp msgProp) throws GSSException Deprecated.The stream-based methods have been removed from RFC 8353. Useunwrap(byte[], int, int, MessageProp)instead.Uses streams to process tokens generated by thewrapmethod on the other side of the context. The method will return the message supplied by the peer application to its wrap call, while at the same time verifying the embedded MIC for that message.The MessageProp object is instantiated by the application and is used by the underlying mechanism to return information to the caller such as the QOP, whether confidentiality was applied to the message, and other supplementary message state information.
Since some application-level protocols may wish to use tokens emitted by wrap to provide "secure framing", implementations should support the wrapping and unwrapping of zero-length messages.
The format of the input token that this method reads is defined in the specification for the underlying mechanism that will be used. This method will attempt to read one of these tokens per invocation. If the mechanism token contains a definitive start and end this method may block on the
InputStreamif only part of the token is available. If the start and end of the token are not definitive then the method will attempt to treat all available bytes as part of the token.Other than the possible blocking behavior described above, this method is equivalent to the byte array based
unwrapmethod.- Parameters:
inStream- an InputStream that contains the wrap token generated by the peer.outStream- an OutputStream to write the application message to.msgProp- 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.- Throws:
GSSException- containing the following major error codes:GSSException.DEFECTIVE_TOKEN,GSSException.BAD_MIC,GSSException.CONTEXT_EXPIRED,GSSException.FAILURE
-
getMIC
Returns a token containing a cryptographic Message Integrity Code (MIC) for the supplied message, for transfer to the peer application. Unlike wrap, which encapsulates the user message in the returned token, only the message MIC is returned in the output token.Note that privacy can only be applied through the wrap call.
Since some application-level protocols may wish to use tokens emitted by getMIC to provide "secure framing", implementations should support derivation of MICs from zero-length messages.
- Parameters:
inMsg- the message to generate the MIC over.offset- offset within the inMsg where the message begins.len- the length of the messagemsgProp- an instance ofMessagePropthat is used by the application to set the desired QOP. Set the desired QOP to0inmsgPropto request the default QOP. Alternatively pass innullformsgPropto request the default QOP.- Returns:
- a byte[] containing the token to be sent to the peer.
- Throws:
GSSException- containing the following major error codes:GSSException.CONTEXT_EXPIRED,GSSException.BAD_QOP,GSSException.FAILURE
-
getMIC
@Deprecated(since="11") void getMIC(InputStream inStream, OutputStream outStream, MessageProp msgProp) throws GSSException Deprecated.The stream-based methods have been removed from RFC 8353. UsegetMIC(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. Unlike wrap, which encapsulates the user message in the returned token, only the message MIC is produced in the output token. This method is equivalent to the byte array basedgetMICmethod. Note that privacy can only be applied through the wrap call.Since some application-level protocols may wish to use tokens emitted by getMIC to provide "secure framing", implementations should support derivation of MICs from zero-length messages.
- Parameters:
inStream- an InputStream containing the message to generate the MIC over. All the data that is available in inStream is used.outStream- an OutputStream to write the output token to.msgProp- an instance ofMessagePropthat is used by the application to set the desired QOP. Set the desired QOP to0inmsgPropto request the default QOP. Alternatively pass innullformsgPropto request the default QOP.- Throws:
GSSException- containing the following major error codes:GSSException.CONTEXT_EXPIRED,GSSException.BAD_QOP,GSSException.FAILURE
-
verifyMIC
void verifyMIC(byte[] inToken, int tokOffset, int tokLen, byte[] inMsg, int msgOffset, int msgLen, MessageProp msgProp) throws GSSException Verifies the cryptographic MIC, contained in the token parameter, over the supplied message.The MessageProp object is instantiated by the application and is used by the underlying mechanism to return information to the caller such as the QOP indicating the strength of protection that was applied to the message and other supplementary message state information.
Since some application-level protocols may wish to use tokens emitted by getMIC to provide "secure framing", implementations should support the calculation and verification of MICs over zero-length messages.
- Parameters:
inToken- the token generated by peer's getMIC method.tokOffset- the offset within the inToken where the token begins.tokLen- the length of the token.inMsg- the application message to verify the cryptographic MIC over.msgOffset- the offset in inMsg where the message begins.msgLen- the length of the message.msgProp- 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.- Throws:
GSSException- containing the following major error codes:GSSException.DEFECTIVE_TOKENGSSException.BAD_MICGSSException.CONTEXT_EXPIREDGSSException.FAILURE
-
verifyMIC
@Deprecated(since="11") void verifyMIC(InputStream tokStream, InputStream msgStream, MessageProp msgProp) throws GSSException Deprecated.The stream-based methods have been removed from RFC 8353. UseverifyMIC(byte[], int, int, byte[], int, int, MessageProp)instead.Uses streams to verify the cryptographic MIC, contained in the token parameter, over the supplied message. This method is equivalent to the byte array basedverifyMICmethod. The MessageProp object is instantiated by the application and is used by the underlying mechanism to return information to the caller such as the QOP indicating the strength of protection that was applied to the message and other supplementary message state information.Since some application-level protocols may wish to use tokens emitted by getMIC to provide "secure framing", implementations should support the calculation and verification of MICs over zero-length messages.
The format of the input token that this method reads is defined in the specification for the underlying mechanism that will be used. This method will attempt to read one of these tokens per invocation. If the mechanism token contains a definitive start and end this method may block on the
InputStreamif only part of the token is available. If the start and end of the token are not definitive then the method will attempt to treat all available bytes as part of the token.Other than the possible blocking behavior described above, this method is equivalent to the byte array based
verifyMICmethod.- Parameters:
tokStream- an InputStream containing the token generated by the peer's getMIC method.msgStream- an InputStream containing the application message to verify the cryptographic MIC over. All the data that is available in msgStream is used.msgProp- 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.- Throws:
GSSException- containing the following major error codes:GSSException.DEFECTIVE_TOKENGSSException.BAD_MICGSSException.CONTEXT_EXPIREDGSSException.FAILURE
-
export
Exports this context so that another process may import it. Provided to support the sharing of work between multiple processes. This routine will typically be used by the context-acceptor, in an application where a single process receives incoming connection requests and accepts security contexts over them, then passes the established context to one or more other processes for message exchange.This method deactivates the security context and creates an interprocess token which, when passed to
GSSManager.createContextin another process, will re-activate the context in the second process. Only a single instantiation of a given context may be active at any one time; a subsequent attempt by a context exporter to access the exported security context will fail.The implementation may constrain the set of processes by which the interprocess token may be imported, either as a function of local security policy, or as a result of implementation decisions. For example, some implementations may constrain contexts to be passed only between processes that run under the same account, or which are part of the same process group.
The interprocess token may contain security-sensitive information (for example cryptographic keys). While mechanisms are encouraged to either avoid placing such sensitive information within interprocess tokens, or to encrypt the token before returning it to the application, in a typical GSS-API implementation this may not be possible. Thus, the application must take care to protect the interprocess token, and ensure that any process to which the token is transferred is trustworthy.
Implementations are not required to support the inter-process transfer of security contexts. Calling the
isTransferablemethod will indicate if the context object is transferable.Calling this method on a context that is not exportable will result in this exception being thrown with the error code
GSSException.UNAVAILABLE.- Returns:
- a byte[] containing the exported context
- Throws:
GSSException- containing the following major error codes:GSSException.UNAVAILABLE,GSSException.CONTEXT_EXPIRED,GSSException.NO_CONTEXT,GSSException.FAILURE- See Also:
-
requestMutualAuth
Requests that mutual authentication be done during context establishment. This request can only be made on the context initiator's side, and it has to be done prior to the first call toinitSecContext.Not all mechanisms support mutual authentication and some mechanisms might require mutual authentication even if the application doesn't. Therefore, the application should check to see if the request was honored with the
getMutualAuthStatemethod.- Parameters:
state- a boolean value indicating whether mutual authentication should be used or not.- Throws:
GSSException- containing the following major error codes:GSSException.FAILURE- See Also:
-
requestReplayDet
Requests that replay detection be enabled for the per-message security services after context establishment. This request can only be made on the context initiator's side, and it has to be done prior to the first call toinitSecContext. During context establishment replay detection is not an option and is a function of the underlying mechanism's capabilities.Not all mechanisms support replay detection and some mechanisms might require replay detection even if the application doesn't. Therefore, the application should check to see if the request was honored with the
getReplayDetStatemethod. If replay detection is enabled then theMessageProp.isDuplicateTokenandMessageProp.isOldTokenmethods will return valid results for theMessagePropobject that is passed in to theunwrapmethod or theverifyMICmethod.- Parameters:
state- a boolean value indicating whether replay detection should be enabled over the established context or not.- Throws:
GSSException- containing the following major error codes:GSSException.FAILURE- See Also:
-
requestSequenceDet
Requests that sequence checking be enabled for the per-message security services after context establishment. This request can only be made on the context initiator's side, and it has to be done prior to the first call toinitSecContext. During context establishment sequence checking is not an option and is a function of the underlying mechanism's capabilities.Not all mechanisms support sequence checking and some mechanisms might require sequence checking even if the application doesn't. Therefore, the application should check to see if the request was honored with the
getSequenceDetStatemethod. If sequence checking is enabled then theMessageProp.isDuplicateToken,MessageProp.isOldToken,MessageProp.isUnseqToken, andMessageProp.isGapTokenmethods will return valid results for theMessagePropobject that is passed in to theunwrapmethod or theverifyMICmethod.- Parameters:
state- a boolean value indicating whether sequence checking should be enabled over the established context or not.- Throws:
GSSException- containing the following major error codes:GSSException.FAILURE- See Also:
-
requestCredDeleg
Requests that the initiator's credentials be delegated to the acceptor during context establishment. This request can only be made on the context initiator's side, and it has to be done prior to the first call toinitSecContext. Not all mechanisms support credential delegation. Therefore, an application that desires delegation should check to see if the request was honored with thegetCredDelegStatemethod. If the application indicates that delegation must not be used, then the mechanism will honor the request and delegation will not occur. This is an exception to the general rule that a mechanism may enable a service even if it is not requested.- Parameters:
state- a boolean value indicating whether the credentials should be delegated or not.- Throws:
GSSException- containing the following major error codes:GSSException.FAILURE- See Also:
-
requestAnonymity
Requests that the initiator's identity not be disclosed to the acceptor. This request can only be made on the context initiator's side, and it has to be done prior to the first call toinitSecContext. Not all mechanisms support anonymity for the initiator. Therefore, the application should check to see if the request was honored with thegetAnonymityStatemethod.- Parameters:
state- a boolean value indicating if the initiator should be authenticated to the acceptor as an anonymous principal.- Throws:
GSSException- containing the following major error codes:GSSException.FAILURE- See Also:
-
requestConf
Requests that data confidentiality be enabled for thewrapmethod. This request can only be made on the context initiator's side, and it has to be done prior to the first call toinitSecContext. Not all mechanisms support confidentiality and other mechanisms might enable it even if the application doesn't request it. The application may check to see if the request was honored with thegetConfStatemethod. If confidentiality is enabled, only then will the mechanism honor a request for privacy in theMessagePropobject that is passed in to thewrapmethod.Enabling confidentiality will also automatically enable integrity.
- Parameters:
state- a boolean value indicating whether confidentiality should be enabled or not.- Throws:
GSSException- containing the following major error codes:GSSException.FAILURE- See Also:
-
requestInteg
Requests that data integrity be enabled for thewrapandgetMICmethods. This request can only be made on the context initiator's side, and it has to be done prior to the first call toinitSecContext. Not all mechanisms support integrity and other mechanisms might enable it even if the application doesn't request it. The application may check to see if the request was honored with thegetIntegStatemethod.Disabling integrity will also automatically disable confidentiality.
- Parameters:
state- a boolean value indicating whether integrity should be enabled or not.- Throws:
GSSException- containing the following major error codes:GSSException.FAILURE- See Also:
-
requestLifetime
Requests a lifetime in seconds for the context. This method can only be called on the context initiator's side, and it has to be done prior to the first call toinitSecContext.The actual lifetime of the context will depend on the capabilities of the underlying mechanism and the application should call the
getLifetimemethod to determine this.- Parameters:
lifetime- the desired context lifetime in seconds. UseINDEFINITE_LIFETIMEto request an indefinite lifetime andDEFAULT_LIFETIMEto request a default lifetime.- Throws:
GSSException- containing the following major error codes:GSSException.FAILURE- See Also:
-
setChannelBinding
Sets the channel bindings to be used during context establishment. This method can be called on both the context initiator's and the context acceptor's side, but it must be called before context establishment begins. This means that an initiator must call it before the first call toinitSecContextand the acceptor must call it before the first call toacceptSecContext.- Parameters:
cb- the channel bindings to use.- Throws:
GSSException- containing the following major error codes:GSSException.FAILURE
-
getCredDelegState
boolean getCredDelegState()Determines if credential delegation is enabled on this context. It can be called by both the context initiator and the context acceptor. For a definitive answer this method must be called only after context establishment is complete. Note that if an initiator requests that delegation not be allowed therequestCredDelegmethod will honor that request and this method will returnfalseon the initiator's side from that point onwards.- Returns:
- true if delegation is enabled, false otherwise.
- See Also:
-
getMutualAuthState
boolean getMutualAuthState()Determines if mutual authentication is enabled on this context. It can be called by both the context initiator and the context acceptor. For a definitive answer this method must be called only after context establishment is complete. An initiator that requests mutual authentication can call this method after context completion and dispose the context if its request was not honored.- Returns:
- true if mutual authentication is enabled, false otherwise.
- See Also:
-
getReplayDetState
boolean getReplayDetState()Determines if replay detection is enabled for the per-message security services from this context. It can be called by both the context initiator and the context acceptor. For a definitive answer this method must be called only after context establishment is complete. An initiator that requests replay detection can call this method after context completion and dispose the context if its request was not honored.- Returns:
- true if replay detection is enabled, false otherwise.
- See Also:
-
getSequenceDetState
boolean getSequenceDetState()Determines if sequence checking is enabled for the per-message security services from this context. It can be called by both the context initiator and the context acceptor. For a definitive answer this method must be called only after context establishment is complete. An initiator that requests sequence checking can call this method after context completion and dispose the context if its request was not honored.- Returns:
- true if sequence checking is enabled, false otherwise.
- See Also:
-
getAnonymityState
boolean getAnonymityState()Determines if the context initiator is anonymously authenticated to the context acceptor. It can be called by both the context initiator and the context acceptor, and at any time. On the initiator side, a call to this method determines if the identity of the initiator has been disclosed in any of the context establishment tokens that might have been generated thus far byinitSecContext. An initiator that absolutely must be authenticated anonymously should call this method after each call toinitSecContextto determine if the generated token should be sent to the peer or the context aborted. On the acceptor side, a call to this method determines if any of the tokens processed byacceptSecContextthus far have divulged the identity of the initiator.- Returns:
- true if the context initiator is still anonymous, false otherwise.
- See Also:
-
isTransferable
Determines if the context is transferable to other processes through the use of theexportmethod. This call is only valid on fully established contexts.- Returns:
- true if this context can be exported, false otherwise.
- Throws:
GSSException- containing the following major error codes:GSSException.FAILURE
-
isProtReady
boolean isProtReady()Determines if the context is ready for per message operations to be used over it. Some mechanisms may allow the usage of the per-message operations before the context is fully established.- Returns:
- true if methods like
wrap,unwrap,getMIC, andverifyMICcan be used with this context at the current stage of context establishment, false otherwise.
-
getConfState
boolean getConfState()Determines if data confidentiality is available over the context. This method can be called by both the context initiator and the context acceptor, but only after one ofisProtReadyorisEstablishedreturntrue. If this method returnstrue, so willgetIntegState- Returns:
- true if confidentiality services are available, false otherwise.
- See Also:
-
getIntegState
boolean getIntegState()Determines if data integrity is available over the context. This method can be called by both the context initiator and the context acceptor, but only after one ofisProtReadyorisEstablishedreturntrue. This method will always returntrueifgetConfStatereturns true.- Returns:
- true if integrity services are available, false otherwise.
- See Also:
-
getLifetime
int getLifetime()Determines what the remaining lifetime for this context is. It can be called by both the context initiator and the context acceptor, but for a definitive answer it should be called only afterisEstablishedreturns true.- Returns:
- the remaining lifetime in seconds
- See Also:
-
getSrcName
Returns the name of the context initiator. This call is valid only after one ofisProtReadyorisEstablishedreturntrue.- Returns:
- a GSSName that is an MN containing the name of the context initiator.
- Throws:
GSSException- containing the following major error codes:GSSException.FAILURE- See Also:
-
getTargName
Returns the name of the context acceptor. This call is valid only after one ofisProtReadyorisEstablishedreturntrue.- Returns:
- a GSSName that is an MN containing the name of the context acceptor.
- Throws:
GSSException- containing the following major error codes:GSSException.FAILURE
-
getMech
Determines what mechanism is being used for this context. This method may be called before the context is fully established, but the mechanism returned may change on successive calls in the negotiated mechanism case.- Returns:
- the Oid of the mechanism being used
- Throws:
GSSException- containing the following major error codes:GSSException.FAILURE
-
getDelegCred
Obtains the credentials delegated by the context initiator to the context acceptor. It should be called only on the context acceptor's side, and once the context is fully established. The caller can use the methodgetCredDelegStateto determine if there are any delegated credentials.- Returns:
- a GSSCredential containing the initiator's delegated
credentials, or
nullis no credentials were delegated. - Throws:
GSSException- containing the following major error codes:GSSException.FAILURE
-
isInitiator
Determines if this is the context initiator. This can be called on both the context initiator's and context acceptor's side.- Returns:
- true if this is the context initiator, false if it is the context acceptor.
- Throws:
GSSException- containing the following major error codes:GSSException.FAILURE
-