1. /*
  2. * @(#)GSSContext.java 1.8 03/01/23
  3. *
  4. * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package org.ietf.jgss;
  8. import sun.security.jgss.spi.*;
  9. import java.io.InputStream;
  10. import java.io.OutputStream;
  11. /**
  12. * This interface encapsulates the GSS-API security context and provides
  13. * the security services that are available over the context. Security
  14. * contexts are established between peers using locally acquired
  15. * credentials. Multiple contexts may exist simultaneously between a pair
  16. * of peers, using the same or different set of credentials. GSS-API
  17. * functions in a manner independent of the underlying transport protocol
  18. * and depends on its calling application to transport the tokens that are
  19. * generated by the security context between the peers.<p>
  20. *
  21. * If the caller instantiates the context using the default
  22. * <code>GSSManager</code> instance, then the Kerberos v5 GSS-API mechanism
  23. * is guaranteed to be available for context establishment. This mechanism
  24. * is identified by the Oid "1.2.840.113554.1.2.2" and is defined in RFC
  25. * 1964.<p>
  26. *
  27. * Before the context establishment phase is initiated, the context
  28. * initiator may request specific characteristics desired of the
  29. * established context. Not all underlying mechanisms support all
  30. * characteristics that a caller might desire. After the context is
  31. * established, the caller can check the actual characteristics and services
  32. * offered by that context by means of various query methods. When using
  33. * the Kerberos v5 GSS-API mechanism offered by the default
  34. * <code>GSSManager</code> instance, all optional services will be
  35. * available locally. They are mutual authentication, credential
  36. * delegation, confidentiality and integrity protection, and per-message
  37. * replay detection and sequencing. Note that in the GSS-API, message integrity
  38. * is a prerequisite for message confidentiality.<p>
  39. *
  40. * The context establishment occurs in a loop where the
  41. * initiator calls {@link #initSecContext(byte[], int, int) initSecContext}
  42. * and the acceptor calls {@link #acceptSecContext(byte[], int, int)
  43. * acceptSecContext} until the context is established. While in this loop
  44. * the <code>initSecContext</code> and <code>acceptSecContext</code>
  45. * methods produce tokens that the application sends over to the peer. The
  46. * peer passes any such token as input to its <code>acceptSecContext</code>
  47. * or <code>initSecContext</code> as the case may be.<p>
  48. *
  49. * During the context establishment phase, the {@link
  50. * #isProtReady() isProtReady} method may be called to determine if the
  51. * context can be used for the per-message operations of {@link
  52. * #wrap(byte[], int, int, MessageProp) wrap} and {@link #getMIC(byte[],
  53. * int, int, MessageProp) getMIC}. This allows applications to use
  54. * per-message operations on contexts which aren't yet fully
  55. * established.<p>
  56. *
  57. * After the context has been established or the <code>isProtReady</code>
  58. * method returns <code>true</code>, the query routines can be invoked to
  59. * determine the actual characteristics and services of the established
  60. * context. The application can also start using the per-message methods
  61. * of {@link #wrap(byte[], int, int, MessageProp) wrap} and
  62. * {@link #getMIC(byte[], int, int, MessageProp) getMIC} to obtain
  63. * cryptographic operations on application supplied data.<p>
  64. *
  65. * When the context is no longer needed, the application should call
  66. * {@link #dispose() dispose} to release any system resources the context
  67. * may be using.<p>
  68. *
  69. * A security context typically maintains sequencing and replay detection
  70. * information about the tokens it processes. Therefore, the sequence in
  71. * which any tokens are presented to this context for processing can be
  72. * important. Also note that none of the methods in this interface are
  73. * synchronized. Therefore, it is not advisable to share a
  74. * <code>GSSContext</code> among several threads unless some application
  75. * level synchronization is in place.<p>
  76. *
  77. * Finally, different mechanism providers might place different security
  78. * restrictions on using GSS-API contexts. These will be documented by the
  79. * mechanism provider. The application will need to ensure that it has the
  80. * appropriate permissions if such checks are made in the mechanism layer.<p>
  81. *
  82. * The example code presented below demonstrates the usage of the
  83. * <code>GSSContext</code> interface for the initiating peer. Different
  84. * operations on the <code>GSSContext</code> object are presented,
  85. * including: object instantiation, setting of desired flags, context
  86. * establishment, query of actual context flags, per-message operations on
  87. * application data, and finally context deletion.<p>
  88. *
  89. * <pre>
  90. * // Create a context using default credentials
  91. * // and the implementation specific default mechanism
  92. * GSSManager manager ...
  93. * GSSName targetName ...
  94. * GSSContext context = manager.createContext(targetName, null, null,
  95. * GSSContext.INDEFINITE_LIFETIME);
  96. *
  97. * // set desired context options prior to context establishment
  98. * context.requestConf(true);
  99. * context.requestMutualAuth(true);
  100. * context.requestReplayDet(true);
  101. * context.requestSequenceDet(true);
  102. *
  103. * // establish a context between peers
  104. *
  105. * byte []inToken = new byte[0];
  106. *
  107. * // Loop while there still is a token to be processed
  108. *
  109. * while (!context.isEstablished()) {
  110. *
  111. * byte[] outToken
  112. * = context.initSecContext(inToken, 0, inToken.length);
  113. *
  114. * // send the output token if generated
  115. * if (outToken != null)
  116. * sendToken(outToken);
  117. *
  118. * if (!context.isEstablished()) {
  119. * inToken = readToken();
  120. * }
  121. *
  122. * // display context information
  123. * System.out.println("Remaining lifetime in seconds = "
  124. * + context.getLifetime());
  125. * System.out.println("Context mechanism = " + context.getMech());
  126. * System.out.println("Initiator = " + context.getSrcName());
  127. * System.out.println("Acceptor = " + context.getTargName());
  128. *
  129. * if (context.getConfState())
  130. * System.out.println("Confidentiality (i.e., privacy) is available");
  131. *
  132. * if (context.getIntegState())
  133. * System.out.println("Integrity is available");
  134. *
  135. * // perform wrap on an application supplied message, appMsg,
  136. * // using QOP = 0, and requesting privacy service
  137. * byte [] appMsg ...
  138. *
  139. * MessageProp mProp = new MessageProp(0, true);
  140. *
  141. * byte []tok = context.wrap(appMsg, 0, appMsg.length, mProp);
  142. *
  143. * sendToken(tok);
  144. *
  145. * // release the local-end of the context
  146. * context.dispose();
  147. *
  148. * </pre>
  149. *
  150. * @author Mayank Upadhyay
  151. * @version 1.8, 01/23/03
  152. * @since 1.4
  153. */
  154. public interface GSSContext {
  155. /**
  156. * A lifetime constant representing the default context lifetime. This
  157. * value is set to 0.
  158. */
  159. public static final int DEFAULT_LIFETIME = 0;
  160. /**
  161. * A lifetime constant representing indefinite context lifetime.
  162. * This value must is set to the maximum integer value in Java -
  163. * {@link java.lang.Integer#MAX_VALUE Integer.MAX_VALUE}.
  164. */
  165. public static final int INDEFINITE_LIFETIME = Integer.MAX_VALUE;
  166. /**
  167. * Called by the context initiator to start the context creation
  168. * phase and process any tokens generated
  169. * by the peer's <code>acceptSecContext</code> method.
  170. * This method may return an output token which the application will need
  171. * to send to the peer for processing by its <code>acceptSecContext</code>
  172. * method. The application can call {@link #isEstablished()
  173. * isEstablished} to determine if the context establishment phase is
  174. * complete on this side of the context. A return value of
  175. * <code>false</code> from <code>isEstablished</code> indicates that
  176. * more tokens are expected to be supplied to
  177. * <code>initSecContext</code>. Upon completion of the context
  178. * establishment, the available context options may be queried through
  179. * the get methods.<p>
  180. *
  181. * Note that it is possible that the <code>initSecContext</code> method
  182. * return a token for the peer, and <code>isEstablished</code> return
  183. * <code>true</code> also. This indicates that the token needs to be sent
  184. * to the peer, but the local end of the context is now fully
  185. * established.<p>
  186. *
  187. * Some mechanism providers might require that the caller be granted
  188. * permission to initiate a security context. A failed permission check
  189. * might cause a {@link java.lang.SecurityException SecurityException}
  190. * to be thrown from this method.<p>
  191. *
  192. * @return a byte[] containing the token to be sent to the
  193. * peer. <code>null</code> indicates that no token is generated.
  194. * @param inputBuf token generated by the peer. This parameter is ignored
  195. * on the first call since no token has been received from the peer.
  196. * @param offset the offset within the inputBuf where the token begins.
  197. * @param len the length of the token.
  198. *
  199. * @throws GSSException containing the following
  200. * major error codes:
  201. * {@link GSSException#DEFECTIVE_TOKEN GSSException.DEFECTIVE_TOKEN},
  202. * {@link GSSException#BAD_MIC GSSException.BAD_MIC},
  203. * {@link GSSException#NO_CRED GSSException.NO_CRED},
  204. * {@link GSSException#CREDENTIALS_EXPIRED
  205. * GSSException.CREDENTIALS_EXPIRED},
  206. * {@link GSSException#BAD_BINDINGS GSSException.BAD_BINDINGS},
  207. * {@link GSSException#OLD_TOKEN GSSException.OLD_TOKEN},
  208. * {@link GSSException#DUPLICATE_TOKEN GSSException.DUPLICATE_TOKEN},
  209. * {@link GSSException#BAD_NAMETYPE GSSException.BAD_NAMETYPE},
  210. * {@link GSSException#BAD_MECH GSSException.BAD_MECH},
  211. * {@link GSSException#FAILURE GSSException.FAILURE}
  212. */
  213. public byte[] initSecContext(byte inputBuf[], int offset, int len)
  214. throws GSSException;
  215. /**
  216. * Called by the context initiator to start the context creation
  217. * phase and process any tokens generated
  218. * by the peer's <code>acceptSecContext</code> method using
  219. * streams. This method may write an output token to the
  220. * <code>OutpuStream</code>, which the application will
  221. * need to send to the peer for processing by its
  222. * <code>acceptSecContext</code> call. Typically, the application would
  223. * ensure this by calling the {@link java.io.OutputStream#flush() flush}
  224. * method on an <code>OutputStream</code> that encapsulates the
  225. * connection between the two peers. The application can
  226. * determine if a token is written to the OutputStream from the return
  227. * value of this method. A return value of <code>0</code> indicates that
  228. * no token was written. The application can call
  229. * {@link #isEstablished() isEstablished} to determine if the context
  230. * establishment phase is complete on this side of the context. A
  231. * return value of <code>false</code> from <code>isEstablished</code>
  232. * indicates that more tokens are expected to be supplied to
  233. * <code>initSecContext</code>.
  234. * Upon completion of the context establishment, the available context
  235. * options may be queried through the get methods.<p>
  236. *
  237. * Note that it is possible that the <code>initSecContext</code> method
  238. * return a token for the peer, and <code>isEstablished</code> return
  239. * <code>true</code> also. This indicates that the token needs to be sent
  240. * to the peer, but the local end of the context is now fully
  241. * established.<p>
  242. *
  243. * The GSS-API authentication tokens contain a definitive start and
  244. * end. This method will attempt to read one of these tokens per
  245. * invocation, and may block on the stream if only part of the token is
  246. * available. In all other respects this method is equivalent to the
  247. * byte array based {@link #initSecContext(byte[], int, int)
  248. * initSecContext}.<p>
  249. *
  250. * Some mechanism providers might require that the caller be granted
  251. * permission to initiate a security context. A failed permission check
  252. * might cause a {@link java.lang.SecurityException SecurityException}
  253. * to be thrown from this method.<p>
  254. *
  255. * The following example code demonstrates how this method might be
  256. * used:<p>
  257. * <pre>
  258. * InputStream is ...
  259. * OutputStream os ...
  260. * GSSContext context ...
  261. *
  262. * // Loop while there is still a token to be processed
  263. *
  264. * while (!context.isEstablished()) {
  265. *
  266. * context.initSecContext(is, os);
  267. *
  268. * // send output token if generated
  269. * os.flush();
  270. * }
  271. * </pre>
  272. *
  273. *
  274. * @return the number of bytes written to the OutputStream as part of the
  275. * token to be sent to the peer. A value of 0 indicates that no token
  276. * needs to be sent.
  277. * @param inStream an InputStream that contains the token generated by
  278. * the peer. This parameter is ignored on the first call since no token
  279. * has been or will be received from the peer at that point.
  280. * @param outStream an OutputStream where the output token will be
  281. * written. During the final stage of context establishment, there may be
  282. * no bytes written.
  283. *
  284. * @throws GSSException containing the following
  285. * major error codes:
  286. * {@link GSSException#DEFECTIVE_TOKEN GSSException.DEFECTIVE_TOKEN},
  287. * {@link GSSException#BAD_MIC GSSException.BAD_MIC},
  288. * {@link GSSException#NO_CRED GSSException.NO_CRED},
  289. * {@link GSSException#CREDENTIALS_EXPIRED GSSException.CREDENTIALS_EXPIRED},
  290. * {@link GSSException#BAD_BINDINGS GSSException.BAD_BINDINGS},
  291. * {@link GSSException#OLD_TOKEN GSSException.OLD_TOKEN},
  292. * {@link GSSException#DUPLICATE_TOKEN GSSException.DUPLICATE_TOKEN},
  293. * {@link GSSException#BAD_NAMETYPE GSSException.BAD_NAMETYPE},
  294. * {@link GSSException#BAD_MECH GSSException.BAD_MECH},
  295. * {@link GSSException#FAILURE GSSException.FAILURE}
  296. */
  297. public int initSecContext(InputStream inStream,
  298. OutputStream outStream) throws GSSException;
  299. /**
  300. * Called by the context acceptor upon receiving a token from the
  301. * peer. This method may return an output token which the application
  302. * will need to send to the peer for further processing by its
  303. * <code>initSecContext</code> call.<p>
  304. *
  305. * The application can call {@link #isEstablished() isEstablished} to
  306. * determine if the context establishment phase is complete for this
  307. * peer. A return value of <code>false</code> from
  308. * <code>isEstablished</code> indicates that more tokens are expected to
  309. * be supplied to this method. Upon completion of the context
  310. * establishment, the available context options may be queried through
  311. * the get methods.<p>
  312. *
  313. * Note that it is possible that <code>acceptSecContext</code> return a
  314. * token for the peer, and <code>isEstablished</code> return
  315. * <code>true</code> also. This indicates that the token needs to be
  316. * sent to the peer, but the local end of the context is now fully
  317. * established.<p>
  318. *
  319. * Some mechanism providers might require that the caller be granted
  320. * permission to accept a security context. A failed permission check
  321. * might cause a {@link java.lang.SecurityException SecurityException}
  322. * to be thrown from this method.<p>
  323. *
  324. * The following example code demonstrates how this method might be
  325. * used:<p>
  326. * <pre>
  327. * byte[] inToken;
  328. * byte[] outToken;
  329. * GSSContext context ...
  330. *
  331. * // Loop while there is still a token to be processed
  332. *
  333. * while (!context.isEstablished()) {
  334. * inToken = readToken();
  335. * outToken = context.acceptSecContext(inToken, 0,
  336. * inToken.length);
  337. * // send output token if generated
  338. * if (outToken != null)
  339. * sendToken(outToken);
  340. * }
  341. * </pre>
  342. *
  343. *
  344. * @return a byte[] containing the token to be sent to the
  345. * peer. <code>null</code> indicates that no token is generated.
  346. * @param inToken token generated by the peer.
  347. * @param offset the offset within the inToken where the token begins.
  348. * @param len the length of the token.
  349. *
  350. * @throws GSSException containing the following
  351. * major error codes:
  352. * {@link GSSException#DEFECTIVE_TOKEN GSSException.DEFECTIVE_TOKEN},
  353. * {@link GSSException#BAD_MIC GSSException.BAD_MIC},
  354. * {@link GSSException#NO_CRED GSSException.NO_CRED},
  355. * {@link GSSException#CREDENTIALS_EXPIRED
  356. * GSSException.CREDENTIALS_EXPIRED},
  357. * {@link GSSException#BAD_BINDINGS GSSException.BAD_BINDINGS},
  358. * {@link GSSException#OLD_TOKEN GSSException.OLD_TOKEN},
  359. * {@link GSSException#DUPLICATE_TOKEN GSSException.DUPLICATE_TOKEN},
  360. * {@link GSSException#BAD_MECH GSSException.BAD_MECH},
  361. * {@link GSSException#FAILURE GSSException.FAILURE}
  362. */
  363. public byte[] acceptSecContext(byte inToken[], int offset, int len)
  364. throws GSSException;
  365. /**
  366. * Called by the context acceptor to process a token from the peer using
  367. * streams. It may write an output token to the
  368. * <code>OutputStream</code>, which the application
  369. * will need to send to the peer for processing by its
  370. * <code>initSecContext</code> method. Typically, the application would
  371. * ensure this by calling the {@link java.io.OutputStream#flush() flush}
  372. * method on an <code>OutputStream</code> that encapsulates the
  373. * connection between the two peers. The application can call
  374. * {@link #isEstablished() isEstablished} to determine if the context
  375. * establishment phase is complete on this side of the context. A
  376. * return value of <code>false</code> from <code>isEstablished</code>
  377. * indicates that more tokens are expected to be supplied to
  378. * <code>acceptSecContext</code>.
  379. * Upon completion of the context establishment, the available context
  380. * options may be queried through the get methods.<p>
  381. *
  382. * Note that it is possible that <code>acceptSecContext</code> return a
  383. * token for the peer, and <code>isEstablished</code> return
  384. * <code>true</code> also. This indicates that the token needs to be
  385. * sent to the peer, but the local end of the context is now fully
  386. * established.<p>
  387. *
  388. * The GSS-API authentication tokens contain a definitive start and
  389. * end. This method will attempt to read one of these tokens per
  390. * invocation, and may block on the stream if only part of the token is
  391. * available. In all other respects this method is equivalent to the byte
  392. * array based {@link #acceptSecContext(byte[], int, int)
  393. * acceptSecContext}.<p>
  394. *
  395. * Some mechanism providers might require that the caller be granted
  396. * permission to accept a security context. A failed permission check
  397. * might cause a {@link java.lang.SecurityException SecurityException}
  398. * to be thrown from this method.<p>
  399. *
  400. * The following example code demonstrates how this method might be
  401. * used:<p>
  402. * <pre>
  403. * InputStream is ...
  404. * OutputStream os ...
  405. * GSSContext context ...
  406. *
  407. * // Loop while there is still a token to be processed
  408. *
  409. * while (!context.isEstablished()) {
  410. *
  411. * context.acceptSecContext(is, os);
  412. *
  413. * // send output token if generated
  414. * os.flush();
  415. * }
  416. * </pre>
  417. *
  418. *
  419. * @param inStream an InputStream that contains the token generated by
  420. * the peer.
  421. * @param outStream an OutputStream where the output token will be
  422. * written. During the final stage of context establishment, there may be
  423. * no bytes written.
  424. *
  425. * @throws GSSException containing the following
  426. * major error codes:
  427. * {@link GSSException#DEFECTIVE_TOKEN GSSException.DEFECTIVE_TOKEN},
  428. * {@link GSSException#BAD_MIC GSSException.BAD_MIC},
  429. * {@link GSSException#NO_CRED GSSException.NO_CRED},
  430. * {@link GSSException#CREDENTIALS_EXPIRED
  431. * GSSException.CREDENTIALS_EXPIRED},
  432. * {@link GSSException#BAD_BINDINGS GSSException.BAD_BINDINGS},
  433. * {@link GSSException#OLD_TOKEN GSSException.OLD_TOKEN},
  434. * {@link GSSException#DUPLICATE_TOKEN GSSException.DUPLICATE_TOKEN},
  435. * {@link GSSException#BAD_MECH GSSException.BAD_MECH},
  436. * {@link GSSException#FAILURE GSSException.FAILURE}
  437. */
  438. /* Missing return value in RFC. int should have been returned.
  439. * -----------------------------------------------------------
  440. *
  441. * The application can determine if a token is written to the
  442. * OutputStream from the return value of this method. A return value of
  443. * <code>0</code> indicates that no token was written.
  444. *
  445. * @return <strong>the number of bytes written to the
  446. * OutputStream as part of the token to be sent to the peer. A value of
  447. * 0 indicates that no token needs to be
  448. * sent.</strong>
  449. */
  450. public void acceptSecContext(InputStream inStream,
  451. OutputStream outStream) throws GSSException;
  452. /**
  453. * Used during context establishment to determine the state of the
  454. * context.
  455. *
  456. * @return <code>true</code> if this is a fully established context on
  457. * the caller's side and no more tokens are needed from the peer.
  458. */
  459. public boolean isEstablished();
  460. /**
  461. * Releases any system resources and cryptographic information stored in
  462. * the context object and invalidates the context.
  463. *
  464. *
  465. * @throws GSSException containing the following
  466. * major error codes:
  467. * {@link GSSException#FAILURE GSSException.FAILURE}
  468. */
  469. public void dispose() throws GSSException;
  470. /**
  471. * Used to determine limits on the size of the message
  472. * that can be passed to <code>wrap</code>. Returns the maximum
  473. * message size that, if presented to the <code>wrap</code> method with
  474. * the same <code>confReq</code> and <code>qop</code> parameters, will
  475. * result in an output token containing no more
  476. * than <code>maxTokenSize</code> bytes.<p>
  477. *
  478. * This call is intended for use by applications that communicate over
  479. * protocols that impose a maximum message size. It enables the
  480. * application to fragment messages prior to applying protection.<p>
  481. *
  482. * GSS-API implementations are recommended but not required to detect
  483. * invalid QOP values when <code>getWrapSizeLimit</code> is called.
  484. * This routine guarantees only a maximum message size, not the
  485. * availability of specific QOP values for message protection.<p>
  486. *
  487. * @param qop the level of protection wrap will be asked to provide.
  488. * @param confReq <code>true</code> if wrap will be asked to provide
  489. * privacy, <code>false</code> otherwise.
  490. * @param maxTokenSize the desired maximum size of the token emitted by
  491. * wrap.
  492. * @return the maximum size of the input token for the given output
  493. * token size
  494. *
  495. * @throws GSSException containing the following
  496. * major error codes:
  497. * {@link GSSException#CONTEXT_EXPIRED GSSException.CONTEXT_EXPIRED},
  498. * {@link GSSException#BAD_QOP GSSException.BAD_QOP},
  499. * {@link GSSException#FAILURE GSSException.FAILURE}
  500. */
  501. public int getWrapSizeLimit(int qop, boolean confReq,
  502. int maxTokenSize) throws GSSException;
  503. /**
  504. * Applies per-message security services over the established security
  505. * context. The method will return a token with the
  506. * application supplied data and a cryptographic MIC over it.
  507. * The data may be encrypted if confidentiality (privacy) was
  508. * requested.<p>
  509. *
  510. * The MessageProp object is instantiated by the application and used
  511. * to specify a QOP value which selects cryptographic algorithms, and a
  512. * privacy service to optionally encrypt the message. The underlying
  513. * mechanism that is used in the call may not be able to provide the
  514. * privacy service. It sets the actual privacy service that it does
  515. * provide in this MessageProp object which the caller should then
  516. * query upon return. If the mechanism is not able to provide the
  517. * requested QOP, it throws a GSSException with the BAD_QOP code.<p>
  518. *
  519. * Since some application-level protocols may wish to use tokens
  520. * emitted by wrap to provide "secure framing", implementations should
  521. * support the wrapping of zero-length messages.<p>
  522. *
  523. * The application will be responsible for sending the token to the
  524. * peer.
  525. *
  526. * @param inBuf application data to be protected.
  527. * @param offset the offset within the inBuf where the data begins.
  528. * @param len the length of the data
  529. * @param msgProp instance of MessageProp that is used by the
  530. * application to set the desired QOP and privacy state. Set the
  531. * desired QOP to 0 to request the default QOP. Upon return from this
  532. * method, this object will contain the the actual privacy state that
  533. * was applied to the message by the underlying mechanism.
  534. * @return a byte[] containing the token to be sent to the peer.
  535. *
  536. * @throws GSSException containing the following major error codes:
  537. * {@link GSSException#CONTEXT_EXPIRED GSSException.CONTEXT_EXPIRED},
  538. * {@link GSSException#BAD_QOP GSSException.BAD_QOP},
  539. * {@link GSSException#FAILURE GSSException.FAILURE}
  540. */
  541. public byte[] wrap(byte inBuf[], int offset, int len,
  542. MessageProp msgProp) throws GSSException;
  543. /**
  544. * Applies per-message security services over the established security
  545. * context using streams. The method will return a
  546. * token with the application supplied data and a cryptographic MIC over it.
  547. * The data may be encrypted if confidentiality
  548. * (privacy) was requested. This method is equivalent to the byte array
  549. * based {@link #wrap(byte[], int, int, MessageProp) wrap} method.<p>
  550. *
  551. * The application will be responsible for sending the token to the
  552. * peer. Typically, the application would
  553. * ensure this by calling the {@link java.io.OutputStream#flush() flush}
  554. * method on an <code>OutputStream</code> that encapsulates the
  555. * connection between the two peers.<p>
  556. *
  557. * The MessageProp object is instantiated by the application and used
  558. * to specify a QOP value which selects cryptographic algorithms, and a
  559. * privacy service to optionally encrypt the message. The underlying
  560. * mechanism that is used in the call may not be able to provide the
  561. * privacy service. It sets the actual privacy service that it does
  562. * provide in this MessageProp object which the caller should then
  563. * query upon return. If the mechanism is not able to provide the
  564. * requested QOP, it throws a GSSException with the BAD_QOP code.<p>
  565. *
  566. * Since some application-level protocols may wish to use tokens
  567. * emitted by wrap to provide "secure framing", implementations should
  568. * support the wrapping of zero-length messages.<p>
  569. *
  570. * @param inStream an InputStream containing the application data to be
  571. * protected. All of the data that is available in
  572. * inStream is used.
  573. * @param outStream an OutputStream to write the protected message
  574. * to.
  575. * @param msgProp instance of MessageProp that is used by the
  576. * application to set the desired QOP and privacy state. Set the
  577. * desired QOP to 0 to request the default QOP. Upon return from this
  578. * method, this object will contain the the actual privacy state that
  579. * was applied to the message by the underlying mechanism.
  580. *
  581. * @throws GSSException containing the following
  582. * major error codes:
  583. * {@link GSSException#CONTEXT_EXPIRED GSSException.CONTEXT_EXPIRED},
  584. * {@link GSSException#BAD_QOP GSSException.BAD_QOP},
  585. * {@link GSSException#FAILURE GSSException.FAILURE}
  586. */
  587. public void wrap(InputStream inStream, OutputStream outStream,
  588. MessageProp msgProp) throws GSSException;
  589. /**
  590. * Used to process tokens generated by the <code>wrap</code> method on
  591. * the other side of the context. The method will return the message
  592. * supplied by the peer application to its wrap call, while at the same
  593. * time verifying the embedded MIC for that message.<p>
  594. *
  595. * The MessageProp object is instantiated by the application and is
  596. * used by the underlying mechanism to return information to the caller
  597. * such as the QOP, whether confidentiality was applied to the message,
  598. * and other supplementary message state information.<p>
  599. *
  600. * Since some application-level protocols may wish to use tokens
  601. * emitted by wrap to provide "secure framing", implementations should
  602. * support the wrapping and unwrapping of zero-length messages.<p>
  603. *
  604. * @param inBuf a byte array containing the wrap token received from
  605. * peer.
  606. * @param offset the offset where the token begins.
  607. * @param len the length of the token
  608. * @param msgProp upon return from the method, this object will contain
  609. * the applied QOP, the privacy state of the message, and supplementary
  610. * information stating if the token was a duplicate, old, out of
  611. * sequence or arriving after a gap.
  612. * @return a byte[] containing the message unwrapped from the input
  613. * token.
  614. *
  615. * @throws GSSException containing the following
  616. * major error codes:
  617. * {@link GSSException#DEFECTIVE_TOKEN GSSException.DEFECTIVE_TOKEN},
  618. * {@link GSSException#BAD_MIC GSSException.BAD_MIC},
  619. * {@link GSSException#CONTEXT_EXPIRED GSSException.CONTEXT_EXPIRED},
  620. * {@link GSSException#FAILURE GSSException.FAILURE}
  621. */
  622. public byte [] unwrap(byte[] inBuf, int offset, int len,
  623. MessageProp msgProp) throws GSSException;
  624. /**
  625. * Uses streams to process tokens generated by the <code>wrap</code>
  626. * method on the other side of the context. The method will return the
  627. * message supplied by the peer application to its wrap call, while at
  628. * the same time verifying the embedded MIC for that message.<p>
  629. *
  630. * The MessageProp object is instantiated by the application and is
  631. * used by the underlying mechanism to return information to the caller
  632. * such as the QOP, whether confidentiality was applied to the message,
  633. * and other supplementary message state information.<p>
  634. *
  635. * Since some application-level protocols may wish to use tokens
  636. * emitted by wrap to provide "secure framing", implementations should
  637. * support the wrapping and unwrapping of zero-length messages.<p>
  638. *
  639. * The format of the input token that this method
  640. * reads is defined in the specification for the underlying mechanism that
  641. * will be used. This method will attempt to read one of these tokens per
  642. * invocation. If the mechanism token contains a definitive start and
  643. * end this method may block on the <code>InputStream</code> if only
  644. * part of the token is available. If the start and end of the token
  645. * are not definitive then the method will attempt to treat all
  646. * available bytes as part of the token.<p>
  647. *
  648. * Other than the possible blocking behaviour described above, this
  649. * method is equivalent to the byte array based {@link #unwrap(byte[],
  650. * int, int, MessageProp) unwrap} method.<p>
  651. *
  652. * @param inStream an InputStream that contains the wrap token generated
  653. * by the peer.
  654. * @param outStream an OutputStream to write the application message
  655. * to.
  656. * @param msgProp upon return from the method, this object will contain
  657. * the applied QOP, the privacy state of the message, and supplementary
  658. * information stating if the token was a duplicate, old, out of
  659. * sequence or arriving after a gap.
  660. *
  661. * @throws GSSException containing the following
  662. * major error codes:
  663. * {@link GSSException#DEFECTIVE_TOKEN GSSException.DEFECTIVE_TOKEN},
  664. * {@link GSSException#BAD_MIC GSSException.BAD_MIC},
  665. * {@link GSSException#CONTEXT_EXPIRED GSSException.CONTEXT_EXPIRED},
  666. * {@link GSSException#FAILURE GSSException.FAILURE}
  667. */
  668. public void unwrap(InputStream inStream, OutputStream outStream,
  669. MessageProp msgProp) throws GSSException;
  670. /**
  671. * Returns a token containing a cryptographic Message Integrity Code
  672. * (MIC) for the supplied message, for transfer to the peer
  673. * application. Unlike wrap, which encapsulates the user message in the
  674. * returned token, only the message MIC is returned in the output
  675. * token.<p>
  676. *
  677. * Note that privacy can only be applied through the wrap call.<p>
  678. *
  679. * Since some application-level protocols may wish to use tokens emitted
  680. * by getMIC to provide "secure framing", implementations should support
  681. * derivation of MICs from zero-length messages.
  682. *
  683. * @param inMsg the message to generate the MIC over.
  684. * @param offset offset within the inMsg where the message begins.
  685. * @param len the length of the message
  686. * @param msgProp an instance of <code>MessageProp</code> that is used
  687. * by the application to set the desired QOP. Set the desired QOP to
  688. * <code>0</code> in <code>msgProp</code> to request the default
  689. * QOP. Alternatively pass in <code>null</code> for <code>msgProp</code>
  690. * to request the default QOP.
  691. * @return a byte[] containing the token to be sent to the peer.
  692. *
  693. * @throws GSSException containing the following
  694. * major error codes:
  695. * {@link GSSException#CONTEXT_EXPIRED GSSException.CONTEXT_EXPIRED},
  696. * {@link GSSException#BAD_QOP GSSException.BAD_QOP},
  697. * {@link GSSException#FAILURE GSSException.FAILURE}
  698. */
  699. public byte[] getMIC(byte []inMsg, int offset, int len,
  700. MessageProp msgProp) throws GSSException;
  701. /**
  702. * Uses streams to produce a token containing a cryptographic MIC for
  703. * the supplied message, for transfer to the peer application.
  704. * Unlike wrap, which encapsulates the user message in the returned
  705. * token, only the message MIC is produced in the output token. This
  706. * method is equivalent to the byte array based {@link #getMIC(byte[],
  707. * int, int, MessageProp) getMIC} method.
  708. *
  709. * Note that privacy can only be applied through the wrap call.<p>
  710. *
  711. * Since some application-level protocols may wish to use tokens emitted
  712. * by getMIC to provide "secure framing", implementations should support
  713. * derivation of MICs from zero-length messages.
  714. *
  715. * @param inStream an InputStream containing the message to generate the
  716. * MIC over. All of the data that is available in
  717. * inStream is used.
  718. * @param outStream an OutputStream to write the output token to.
  719. * @param msgProp an instance of <code>MessageProp</code> that is used
  720. * by the application to set the desired QOP. Set the desired QOP to
  721. * <code>0</code> in <code>msgProp</code> to request the default
  722. * QOP. Alternatively pass in <code>null</code> for <code>msgProp</code>
  723. * to request the default QOP.
  724. *
  725. * @throws GSSException containing the following
  726. * major error codes:
  727. * {@link GSSException#CONTEXT_EXPIRED GSSException.CONTEXT_EXPIRED},
  728. * {@link GSSException#BAD_QOP GSSException.BAD_QOP},
  729. * {@link GSSException#FAILURE GSSException.FAILURE}
  730. */
  731. public void getMIC(InputStream inStream, OutputStream outStream,
  732. MessageProp msgProp) throws GSSException;
  733. /**
  734. * Verifies the cryptographic MIC, contained in the token parameter,
  735. * over the supplied message.<p>
  736. *
  737. * The MessageProp object is instantiated by the application and is used
  738. * by the underlying mechanism to return information to the caller such
  739. * as the QOP indicating the strength of protection that was applied to
  740. * the message and other supplementary message state information.<p>
  741. *
  742. * Since some application-level protocols may wish to use tokens emitted
  743. * by getMIC to provide "secure framing", implementations should support
  744. * the calculation and verification of MICs over zero-length messages.
  745. *
  746. * @param inToken the token generated by peer's getMIC method.
  747. * @param tokOffset the offset within the inToken where the token
  748. * begins.
  749. * @param tokLen the length of the token.
  750. * @param inMsg the application message to verify the cryptographic MIC
  751. * over.
  752. * @param msgOffset the offset in inMsg where the message begins.
  753. * @param msgLen the length of the message.
  754. * @param msgProp upon return from the method, this object will contain
  755. * the applied QOP and supplementary information stating if the token
  756. * was a duplicate, old, out of sequence or arriving after a gap.
  757. *
  758. * @throws GSSException containing the following
  759. * major error codes:
  760. * {@link GSSException#DEFECTIVE_TOKEN GSSException.DEFECTIVE_TOKEN}
  761. * {@link GSSException#BAD_MIC GSSException.BAD_MIC}
  762. * {@link GSSException#CONTEXT_EXPIRED GSSException.CONTEXT_EXPIRED}
  763. * {@link GSSException#FAILURE GSSException.FAILURE}
  764. */
  765. public void verifyMIC(byte[] inToken, int tokOffset, int tokLen,
  766. byte[] inMsg, int msgOffset, int msgLen,
  767. MessageProp msgProp) throws GSSException;
  768. /**
  769. * Uses streams to verify the cryptographic MIC, contained in the token
  770. * parameter, over the supplied message. This method is equivalent to
  771. * the byte array based {@link #verifyMIC(byte[], int, int, byte[], int,
  772. * int, MessageProp) verifyMIC} method.
  773. *
  774. * The MessageProp object is instantiated by the application and is used
  775. * by the underlying mechanism to return information to the caller such
  776. * as the QOP indicating the strength of protection that was applied to
  777. * the message and other supplementary message state information.<p>
  778. *
  779. * Since some application-level protocols may wish to use tokens emitted
  780. * by getMIC to provide "secure framing", implementations should support
  781. * the calculation and verification of MICs over zero-length messages.<p>
  782. *
  783. * The format of the input token that this method
  784. * reads is defined in the specification for the underlying mechanism that
  785. * will be used. This method will attempt to read one of these tokens per
  786. * invocation. If the mechanism token contains a definitive start and
  787. * end this method may block on the <code>InputStream</code> if only
  788. * part of the token is available. If the start and end of the token
  789. * are not definitive then the method will attempt to treat all
  790. * available bytes as part of the token.<p>
  791. *
  792. * Other than the possible blocking behaviour described above, this
  793. * method is equivalent to the byte array based {@link #verifyMIC(byte[],
  794. * int, int, byte[], int, int, MessageProp) verifyMIC} method.<p>
  795. *
  796. * @param tokStream an InputStream containing the token generated by the
  797. * peer's getMIC method.
  798. * @param msgStream an InputStream containing the application message to
  799. * verify the cryptographic MIC over. All of the data
  800. * that is available in msgStream is used.
  801. * @param msgProp upon return from the method, this object will contain
  802. * the applied QOP and supplementary information stating if the token
  803. * was a duplicate, old, out of sequence or arriving after a gap.
  804. *
  805. * @throws GSSException containing the following
  806. * major error codes:
  807. * {@link GSSException#DEFECTIVE_TOKEN GSSException.DEFECTIVE_TOKEN}
  808. * {@link GSSException#BAD_MIC GSSException.BAD_MIC}
  809. * {@link GSSException#CONTEXT_EXPIRED GSSException.CONTEXT_EXPIRED}
  810. * {@link GSSException#FAILURE GSSException.FAILURE}
  811. */
  812. public void verifyMIC(InputStream tokStream, InputStream msgStream,
  813. MessageProp msgProp) throws GSSException;
  814. /**
  815. * Exports this context so that another process may
  816. * import it.. Provided to support the sharing of work between
  817. * multiple processes. This routine will typically be used by the
  818. * context-acceptor, in an application where a single process receives
  819. * incoming connection requests and accepts security contexts over
  820. * them, then passes the established context to one or more other
  821. * processes for message exchange.<p>
  822. *
  823. * This method deactivates the security context and creates an
  824. * interprocess token which, when passed to {@link
  825. * GSSManager#createContext(byte[]) GSSManager.createContext} in
  826. * another process, will re-activate the context in the second process.
  827. * Only a single instantiation of a given context may be active at any
  828. * one time; a subsequent attempt by a context exporter to access the
  829. * exported security context will fail.<p>
  830. *
  831. * The implementation may constrain the set of processes by which the
  832. * interprocess token may be imported, either as a function of local
  833. * security policy, or as a result of implementation decisions. For
  834. * example, some implementations may constrain contexts to be passed
  835. * only between processes that run under the same account, or which are
  836. * part of the same process group.<p>
  837. *
  838. * The interprocess token may contain security-sensitive information
  839. * (for example cryptographic keys). While mechanisms are encouraged
  840. * to either avoid placing such sensitive information within
  841. * interprocess tokens, or to encrypt the token before returning it to
  842. * the application, in a typical GSS-API implementation this may not be
  843. * possible. Thus the application must take care to protect the
  844. * interprocess token, and ensure that any process to which the token
  845. * is transferred is trustworthy. <p>
  846. *
  847. * Implementations are not required to support the inter-process
  848. * transfer of security contexts. Calling the {@link #isTransferable()
  849. * isTransferable} method will indicate if the context object is
  850. * transferable.<p>
  851. *
  852. * Calling this method on a context that
  853. * is not exportable will result in this exception being thrown with
  854. * the error code {@link GSSException#UNAVAILABLE
  855. * GSSException.UNAVAILABLE}.
  856. *
  857. * @return a byte[] containing the exported context
  858. * @see GSSManager#createContext(byte[])
  859. *
  860. * @throws GSSException containing the following
  861. * major error codes:
  862. * {@link GSSException#UNAVAILABLE GSSException.UNAVAILABLE},
  863. * {@link GSSException#CONTEXT_EXPIRED GSSException.CONTEXT_EXPIRED},
  864. * {@link GSSException#NO_CONTEXT GSSException.NO_CONTEXT},
  865. * {@link GSSException#FAILURE GSSException.FAILURE}
  866. */
  867. public byte [] export() throws GSSException;
  868. /**
  869. * Requests that mutual authentication be done during
  870. * context establishment. This request can only be made on the context
  871. * initiator's side and it has to be done prior to the first call to
  872. * <code>initSecContext</code>.<p>
  873. *
  874. * Not all mechanisms support mutual authentication and some mechanisms
  875. * might require mutual authentication even if the application
  876. * doesn't. Therefore, the application should check to see if the
  877. * request was honored with the {@link #getMutualAuthState()
  878. * getMutualAuthState} method.<p>
  879. *
  880. * @param state a boolean value indicating whether mutual
  881. * authentication shouls be used or not.
  882. * @see #getMutualAuthState()
  883. *
  884. * @throws GSSException containing the following
  885. * major error codes:
  886. * {@link GSSException#FAILURE GSSException.FAILURE}
  887. */
  888. public void requestMutualAuth(boolean state) throws GSSException;
  889. /**
  890. * Requests that replay detection be enabled for the
  891. * per-message security services after context establishemnt. This
  892. * request can only be made on the context initiator's side and it has
  893. * to be done prior to the first call to
  894. * <code>initSecContext</code>. During context establishment replay
  895. * detection is not an option and is a function of the underlying
  896. * mechanism's capabilities.<p>
  897. *
  898. * Not all mechanisms support replay detection and some mechanisms
  899. * might require replay detection even if the application
  900. * doesn't. Therefore, the application should check to see if the
  901. * request was honored with the {@link #getReplayDetState()
  902. * getReplayDetState} method. If replay detection is enabled then the
  903. * {@link MessageProp#isDuplicateToken() MessageProp.isDuplicateToken} and {@link
  904. * MessageProp#isOldToken() MessageProp.isOldToken} methods will return
  905. * valid results for the <code>MessageProp</code> object that is passed
  906. * in to the <code>unwrap</code> method or the <code>verifyMIC</code>
  907. * method.<p>
  908. *
  909. * @param state a boolean value indicating whether replay detection
  910. * should be enabled over the established context or not.
  911. * @see #getReplayDetState()
  912. *
  913. * @throws GSSException containing the following
  914. * major error codes:
  915. * {@link GSSException#FAILURE GSSException.FAILURE}
  916. */
  917. public void requestReplayDet(boolean state) throws GSSException;
  918. /**
  919. * Requests that sequence checking be enabled for the
  920. * per-message security services after context establishemnt. This
  921. * request can only be made on the context initiator's side and it has
  922. * to be done prior to the first call to
  923. * <code>initSecContext</code>. During context establishment sequence
  924. * checking is not an option and is a function of the underlying
  925. * mechanism's capabilities.<p>
  926. *
  927. * Not all mechanisms support sequence checking and some mechanisms
  928. * might require sequence checking even if the application
  929. * doesn't. Therefore, the application should check to see if the
  930. * request was honored with the {@link #getSequenceDetState()
  931. * getSequenceDetState} method. If sequence checking is enabled then the
  932. * {@link MessageProp#isDuplicateToken() MessageProp.isDuplicateToken},
  933. * {@link MessageProp#isOldToken() MessageProp.isOldToken},
  934. * {@link MessageProp#isUnseqToken() MessageProp.isUnseqToken}, and
  935. * {@link MessageProp#isGapToken() MessageProp.isGapToken} methods will return
  936. * valid results for the <code>MessageProp</code> object that is passed
  937. * in to the <code>unwrap</code> method or the <code>verifyMIC</code>
  938. * method.<p>
  939. *
  940. * @param state a boolean value indicating whether sequence checking
  941. * should be enabled over the established context or not.
  942. * @see #getSequenceDetState()
  943. *
  944. * @throws GSSException containing the following
  945. * major error codes:
  946. * {@link GSSException#FAILURE GSSException.FAILURE}
  947. */
  948. public void requestSequenceDet(boolean state) throws GSSException;
  949. /**
  950. * Requests that the initiator's credentials be
  951. * delegated to the acceptor during context establishment. This
  952. * request can only be made on the context initiator's side and it has
  953. * to be done prior to the first call to
  954. * <code>initSecContext</code>.
  955. *
  956. * Not all mechanisms support credential delegation. Therefore, an
  957. * application that desires delegation should check to see if the
  958. * request was honored with the {@link #getCredDelegState()
  959. * getCredDelegState} method. If the application indicates that
  960. * delegation must not be used, then the mechanism will honor the
  961. * request and delegation will not occur. This is an exception
  962. * to the general rule that a mechanism may enable a service even if it
  963. * is not requested.<p>
  964. *
  965. * @param state a boolean value indicating whether the credentials
  966. * should be delegated or not.
  967. * @see #getCredDelegState()
  968. *
  969. * @throws GSSException containing the following
  970. * major error codes:
  971. * {@link GSSException#FAILURE GSSException.FAILURE}
  972. */
  973. public void requestCredDeleg(boolean state) throws GSSException;
  974. /**
  975. * Requests that the initiator's identity not be
  976. * disclosed to the acceptor. This request can only be made on the
  977. * context initiator's side and it has to be done prior to the first
  978. * call to <code>initSecContext</code>.
  979. *
  980. * Not all mechanisms support anonymity for the initiator. Therefore, the
  981. * application should check to see if the request was honored with the
  982. * {@link #getAnonymityState() getAnonymityState} method.<p>
  983. *
  984. * @param state a boolean value indicating if the initiator should
  985. * be authenticated to the acceptor as an anonymous principal.
  986. * @see #getAnonymityState
  987. *
  988. * @throws GSSException containing the following
  989. * major error codes:
  990. * {@link GSSException#FAILURE GSSException.FAILURE}
  991. */
  992. public void requestAnonymity(boolean state) throws GSSException;
  993. /**
  994. * Requests that data confidentiality be enabled
  995. * for the <code>wrap</code> method. This request can only be made on
  996. * the context initiator's side and it has to be done prior to the
  997. * first call to <code>initSecContext</code>.
  998. *
  999. * Not all mechanisms support confidentiality and other mechanisms
  1000. * might enable it even if the application doesn't request
  1001. * it. The application may check to see if the request was honored with
  1002. * the {@link #getConfState() getConfState} method. If confidentiality
  1003. * is enabled, only then will the mechanism honor a request for privacy
  1004. * in the {@link MessageProp#MessageProp(int, boolean) MessageProp}
  1005. * object that is passed in to the <code>wrap</code> method.<p>
  1006. *
  1007. * Enabling confidentiality will also automatically enable
  1008. * integrity.<p>
  1009. *
  1010. * @param state a boolean value indicating whether confidentiality
  1011. * should be enabled or not.
  1012. * @see #getConfState()
  1013. * @see #getIntegState()
  1014. * @see #requestInteg(boolean)
  1015. * @see MessageProp
  1016. *
  1017. * @throws GSSException containing the following
  1018. * major error codes:
  1019. * {@link GSSException#FAILURE GSSException.FAILURE}
  1020. */
  1021. public void requestConf(boolean state) throws GSSException;
  1022. /**
  1023. * Requests that data integrity be enabled
  1024. * for the <code>wrap</code> and <code>getMIC</code>methods. This
  1025. * request can only be made on the context initiator's side and it has
  1026. * to be done prior to the first call to <code>initSecContext</code>.
  1027. *
  1028. * Not all mechanisms support integrity and other mechanisms
  1029. * might enable it even if the application doesn't request
  1030. * it. The application may check to see if the request was honored with
  1031. * the {@link #getIntegState() getIntegState} method.<p>
  1032. *
  1033. * Disabling integrity will also automatically disable
  1034. * confidentiality.<p>
  1035. *
  1036. * @param state a boolean value indicating whether integrity
  1037. * should be enabled or not.
  1038. * @see #getIntegState()
  1039. *
  1040. * @throws GSSException containing the following
  1041. * major error codes:
  1042. * {@link GSSException#FAILURE GSSException.FAILURE}
  1043. */
  1044. public void requestInteg(boolean state) throws GSSException;
  1045. /**
  1046. * Requests a lifetime in seconds for the
  1047. * context. This method can only be called on the context initiator's
  1048. * side and it has to be done prior to the first call to
  1049. * <code>initSecContext</code>.<p>
  1050. *
  1051. * The actual lifetime of the context will depend on the capabilites of
  1052. * the underlying mechanism and the application should call the {@link
  1053. * #getLifetime() getLifetime} method to determine this.<p>
  1054. *
  1055. * @param lifetime the desired context lifetime in seconds. Use
  1056. * <code>INDEFINITE_LIFETIME</code> to request an indefinite lifetime
  1057. * and <code>DEFAULT_LIFETIME</code> to request a default lifetime.
  1058. * @see #getLifetime()
  1059. *
  1060. * @throws GSSException containing the following
  1061. * major error codes:
  1062. * {@link GSSException#FAILURE GSSException.FAILURE}
  1063. */
  1064. public void requestLifetime(int lifetime) throws GSSException;
  1065. /**
  1066. * Sets the channel bindings to be used during context
  1067. * establishment. This method can be called on both
  1068. * the context initiator's and the context acceptor's side, but it must
  1069. * be called before context establishment begins. This means that an
  1070. * initiator must call it before the first call to
  1071. * <code>initSecContext</code> and the acceptor must call it before the
  1072. * first call to <code>acceptSecContext</code>.
  1073. *
  1074. * @param cb the channel bindings to use.
  1075. *
  1076. * @throws GSSException containing the following
  1077. * major error codes:
  1078. * {@link GSSException#FAILURE GSSException.FAILURE}
  1079. */
  1080. public void setChannelBinding(ChannelBinding cb) throws GSSException;
  1081. /**
  1082. * Determines if credential delegation is enabled on
  1083. * this context. It can be called by both the context initiator and the
  1084. * context acceptor. For a definitive answer this method must be
  1085. * called only after context establishment is complete. Note that if an
  1086. * initiator requests that delegation not be allowed the {@link
  1087. * #requestCredDeleg(boolean) requestCredDeleg} method will honor that
  1088. * request and this method will return <code>false</code> on the
  1089. * initiator's side from that point onwards. <p>
  1090. *
  1091. * @return true if delegation is enabled, false otherwise.
  1092. * @see #requestCredDeleg(boolean)
  1093. */
  1094. public boolean getCredDelegState();
  1095. /**
  1096. * Determines if mutual authentication is enabled on
  1097. * this context. It can be called by both the context initiator and the
  1098. * context acceptor. For a definitive answer this method must be
  1099. * called only after context establishment is complete. An initiator
  1100. * that requests mutual authentication can call this method after
  1101. * context completion and dispose the context if its request was not
  1102. * honored.<p>
  1103. *
  1104. * @return true if mutual authentication is enabled, false otherwise.
  1105. * @see #requestMutualAuth(boolean)
  1106. */
  1107. public boolean getMutualAuthState();
  1108. /**
  1109. * Determines if replay detection is enabled for the
  1110. * per-message security services from this context. It can be called by
  1111. * both the context initiator and the context acceptor. For a
  1112. * definitive answer this method must be called only after context
  1113. * establishment is complete. An initiator that requests replay
  1114. * detection can call this method after context completion and
  1115. * dispose the context if its request was not honored.<p>
  1116. *
  1117. * @return true if replay detection is enabled, false otherwise.
  1118. * @see #requestReplayDet(boolean)
  1119. */
  1120. public boolean getReplayDetState();
  1121. /**
  1122. * Determines if sequence checking is enabled for the
  1123. * per-message security services from this context. It can be called by
  1124. * both the context initiator and the context acceptor. For a
  1125. * definitive answer this method must be called only after context
  1126. * establishment is complete. An initiator that requests sequence
  1127. * checking can call this method after context completion and
  1128. * dispose the context if its request was not honored.<p>
  1129. *
  1130. * @return true if sequence checking is enabled, false otherwise.
  1131. * @see #requestSequenceDet(boolean)
  1132. */
  1133. public boolean getSequenceDetState();
  1134. /**
  1135. * Determines if the context initiator is
  1136. * anonymously authenticated to the context acceptor. It can be called by
  1137. * both the context initiator and the context acceptor, and at any
  1138. * time. <strong>On the initiator side, a call to this method determines
  1139. * if the identity of the initiator has been disclosed in any of the
  1140. * context establishment tokens that might have been generated thus far
  1141. * by <code>initSecContext</code>. An initiator that absolutely must be
  1142. * authenticated anonymously should call this method after each call to
  1143. * <code>initSecContext</code> to determine if the generated token
  1144. * should be sent to the peer or the context aborted.</strong> On the
  1145. * acceptor side, a call to this method determines if any of the tokens
  1146. * processed by <code>acceptSecContext</code> thus far have divulged
  1147. * the identity of the initiator.<p>
  1148. *
  1149. * @return true if the context initiator is still anonymous, false
  1150. * otherwise.
  1151. * @see #requestAnonymity(boolean)
  1152. */
  1153. public boolean getAnonymityState();
  1154. /**
  1155. * Determines if the context is transferable to other processes
  1156. * through the use of the {@link #export() export} method. This call
  1157. * is only valid on fully established contexts.
  1158. *
  1159. * @return true if this context can be exported, false otherwise.
  1160. *
  1161. * @throws GSSException containing the following
  1162. * major error codes:
  1163. * {@link GSSException#FAILURE GSSException.FAILURE}
  1164. */
  1165. public boolean isTransferable() throws GSSException;
  1166. /**
  1167. * Determines if the context is ready for per message operations to be
  1168. * used over it. Some mechanisms may allow the usage of the
  1169. * per-message operations before the context is fully established.
  1170. *
  1171. * @return true if methods like <code>wrap</code>, <code>unwrap</code>,
  1172. * <code>getMIC</code>, and <code>verifyMIC</code> can be used with
  1173. * this context at the current stage of context establishment, false
  1174. * otherwise.
  1175. */
  1176. public boolean isProtReady();
  1177. /**
  1178. * Determines if data confidentiality is available
  1179. * over the context. This method can be called by both the context
  1180. * initiator and the context acceptor, but only after one of {@link
  1181. * #isProtReady() isProtReady} or {@link #isEstablished()
  1182. * isEstablished} return <code>true</code>. If this method returns
  1183. * <code>true</code>, so will {@link #getIntegState()
  1184. * getIntegState}<p>
  1185. *
  1186. * @return true if confidentiality services are available, false
  1187. * otherwise.
  1188. * @see #requestConf(boolean)
  1189. */
  1190. public boolean getConfState();
  1191. /**
  1192. * Determines if data integrity is available
  1193. * over the context. This method can be called by both the context
  1194. * initiator and the context acceptor, but only after one of {@link
  1195. * #isProtReady() isProtReady} or {@link #isEstablished()
  1196. * isEstablished} return <code>true</code>. This method will always
  1197. * return <code>true</code> if {@link #getConfState() getConfState}
  1198. * returns true.<p>
  1199. *
  1200. * @return true if integrity services are available, false otherwise.
  1201. * @see #requestInteg(boolean)
  1202. */
  1203. public boolean getIntegState();
  1204. /**
  1205. * Determines what the remaining lifetime for this
  1206. * context is. It can be called by both the context initiator and the
  1207. * context acceptor, but for a definitive answer it should be called
  1208. * only after {@link #isEstablished() isEstablished} returns
  1209. * true.<p>
  1210. *
  1211. * @return the remaining lifetime in seconds
  1212. * @see #requestLifetime(int)
  1213. */
  1214. public int getLifetime();
  1215. /**
  1216. * Returns the name of the context initiator. This call is valid only
  1217. * after one of {@link #isProtReady() isProtReady} or {@link
  1218. * #isEstablished() isEstablished} return <code>true</code>.
  1219. *
  1220. * @return a GSSName that is an MN containing the name of the context
  1221. * initiator.
  1222. * @see GSSName
  1223. *
  1224. * @throws GSSException containing the following
  1225. * major error codes:
  1226. * {@link GSSException#FAILURE GSSException.FAILURE}
  1227. */
  1228. public GSSName getSrcName() throws GSSException;
  1229. /**
  1230. * Returns the name of the context acceptor. This call is valid only
  1231. * after one of {@link #isProtReady() isProtReady} or {@link
  1232. * #isEstablished() isEstablished} return <code>true</code>.
  1233. *
  1234. * @return a GSSName that is an MN containing the name of the context
  1235. * acceptor.
  1236. *
  1237. * @throws GSSException containing the following
  1238. * major error codes:
  1239. * {@link GSSException#FAILURE GSSException.FAILURE}
  1240. */
  1241. public GSSName getTargName() throws GSSException;
  1242. /**
  1243. * Determines what mechanism is being used for this
  1244. * context. This method may be called before the context is fully
  1245. * established, but the mechanism returned may change on successive
  1246. * calls in the negotiated mechanism case.
  1247. *
  1248. * @return the Oid of the mechanism being used
  1249. *
  1250. * @throws GSSException containing the following
  1251. * major error codes:
  1252. * {@link GSSException#FAILURE GSSException.FAILURE}
  1253. */
  1254. public Oid getMech() throws GSSException;
  1255. /**
  1256. * Obtains the credentials delegated by the context
  1257. * initiator to the context acceptor. It should be called only on the
  1258. * context acceptor's side, and once the context is fully
  1259. * established. The caller can use the method {@link
  1260. * #getCredDelegState() getCredDelegState} to determine if there are
  1261. * any delegated credentials.
  1262. *
  1263. * @return a GSSCredential containing the initiator's delegated
  1264. * credentials, or <code>null</code> is no credentials
  1265. * were delegated.
  1266. *
  1267. * @throws GSSException containing the following
  1268. * major error codes:
  1269. * {@link GSSException#FAILURE GSSException.FAILURE}
  1270. */
  1271. public GSSCredential getDelegCred() throws GSSException;
  1272. /**
  1273. * Determines if this is the context initiator. This
  1274. * can be called on both the context initiator's and context acceptor's
  1275. * side.
  1276. *
  1277. * @return true if this is the context initiator, false if it is the
  1278. * context acceptor.
  1279. *
  1280. * @throws GSSException containing the following
  1281. * major error codes:
  1282. * {@link GSSException#FAILURE GSSException.FAILURE}
  1283. */
  1284. public boolean isInitiator() throws GSSException;
  1285. }