1. /*
  2. * @(#)GSSCredential.java 1.7 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. /**
  9. * This interface encapsulates the GSS-API credentials for an entity. A
  10. * credential contains all the necessary cryptographic information to
  11. * enable the creation of a context on behalf of the entity that it
  12. * represents. It may contain multiple, distinct, mechanism specific
  13. * credential elements, each containing information for a specific
  14. * security mechanism, but all referring to the same entity. A credential
  15. * may be used to perform context initiation, acceptance, or both.<p>
  16. *
  17. * Credentials are instantiated using one of the
  18. * <code>createCredential</code> methods in the {@link GSSManager
  19. * GSSManager} class. GSS-API credential creation is not
  20. * intended to provide a "login to the network" function, as such a
  21. * function would involve the creation of new credentials rather than
  22. * merely acquiring a handle to existing credentials. The
  23. * <a href=package-summary.html#useSubjectCredsOnly>section on credential
  24. * acquisition</a> in the package level description describes
  25. * how existing credentials are acquired in the Java 2 platform. GSS-API
  26. * implementations must impose a local access-control policy on callers to
  27. * prevent unauthorized callers from acquiring credentials to which they
  28. * are not entitled. <p>
  29. *
  30. * Applications will create a credential object passing the desired
  31. * parameters. The application can then use the query methods to obtain
  32. * specific information about the instantiated credential object.
  33. * When the credential is no longer needed, the application should call
  34. * the {@link #dispose() dispose} method to release any resources held by
  35. * the credential object and to destroy any cryptographically sensitive
  36. * information.<p>
  37. *
  38. * This example code demonstrates the creation of a GSSCredential
  39. * implementation for a specific entity, querying of its fields, and its
  40. * release when it is no longer needed:<p>
  41. * <pre>
  42. * GSSManager manager = GSSManager.getInstance();
  43. *
  44. * // start by creating a name object for the entity
  45. * GSSName name = manager.createName("myusername", GSSName.NT_USER_NAME);
  46. *
  47. * // now acquire credentials for the entity
  48. * GSSCredential cred = manager.createCredential(name,
  49. * GSSCredential.ACCEPT_ONLY);
  50. *
  51. * // display credential information - name, remaining lifetime,
  52. * // and the mechanisms it has been acquired over
  53. * System.out.println(cred.getName().toString());
  54. * System.out.println(cred.getRemainingLifetime());
  55. *
  56. * Oid [] mechs = cred.getMechs();
  57. * if (mechs != null) {
  58. * for (int i = 0; i < mechs.length; i++)
  59. * System.out.println(mechs[i].toString());
  60. * }
  61. *
  62. * // release system resources held by the credential
  63. * cred.dispose();
  64. * </pre>
  65. *
  66. * @see GSSManager#createCredential(int)
  67. * @see GSSManager#createCredential(GSSName, int, Oid, int)
  68. * @see GSSManager#createCredential(GSSName, int, Oid[], int)
  69. * @see #dispose()
  70. *
  71. * @author Mayank Upadhyay
  72. * @version 1.7, 01/23/03
  73. * @since 1.4
  74. */
  75. public interface GSSCredential extends Cloneable{
  76. /**
  77. * Credential usage flag requesting that it be usable
  78. * for both context initiation and acceptance.
  79. *
  80. */
  81. public static final int INITIATE_AND_ACCEPT = 0;
  82. /**
  83. * Credential usage flag requesting that it be usable
  84. * for context initiation only.
  85. *
  86. */
  87. public static final int INITIATE_ONLY = 1;
  88. /**
  89. * Credential usage flag requesting that it be usable
  90. * for context acceptance only.
  91. *
  92. */
  93. public static final int ACCEPT_ONLY = 2;
  94. /**
  95. * A lifetime constant representing the default credential lifetime. This
  96. * value it set to 0.
  97. */
  98. public static final int DEFAULT_LIFETIME = 0;
  99. /**
  100. * A lifetime constant representing indefinite credential lifetime.
  101. * This value must is set to the maximum integer value in Java -
  102. * {@link java.lang.Integer#MAX_VALUE Integer.MAX_VALUE}.
  103. */
  104. public static final int INDEFINITE_LIFETIME = Integer.MAX_VALUE;
  105. /**
  106. * Releases any sensitive information that the GSSCredential object may
  107. * be containing. Applications should call this method as soon as the
  108. * credential is no longer needed to minimize the time any sensitive
  109. * information is maintained.
  110. *
  111. * @throws GSSException containing the following
  112. * major error codes:
  113. * {@link GSSException#FAILURE GSSException.FAILURE}
  114. */
  115. public void dispose() throws GSSException;
  116. /**
  117. * Retrieves the name of the entity that the credential asserts.
  118. *
  119. * @return a GSSName representing the entity
  120. *
  121. * @throws GSSException containing the following
  122. * major error codes:
  123. * {@link GSSException#FAILURE GSSException.FAILURE}
  124. */
  125. public GSSName getName() throws GSSException;
  126. /**
  127. * Retrieves a Mechanism Name of the entity that the credential
  128. * asserts. This is equivalent to calling {@link
  129. * GSSName#canonicalize(Oid) canonicalize} on the value returned by
  130. * the other form of {@link #getName() getName}.
  131. *
  132. * @param mech the Oid of the mechanism for which the Mechanism Name
  133. * should be returned.
  134. * @return a GSSName representing the entity canonicalized for the
  135. * desired mechanism
  136. *
  137. * @throws GSSException containing the following
  138. * major error codes:
  139. * {@link GSSException#BAD_MECH GSSException.BAD_MECH},
  140. * {@link GSSException#FAILURE GSSException.FAILURE}
  141. */
  142. public GSSName getName(Oid mech) throws GSSException;
  143. /**
  144. * Returns the remaining lifetime in seconds for a credential. The
  145. * remaining lifetime is the minimum lifetime amongst all of the underlying
  146. * mechanism specific credential elements.
  147. *
  148. * @return the minimum remaining lifetime in seconds for this
  149. * credential. A return value of {@link #INDEFINITE_LIFETIME
  150. * INDEFINITE_LIFETIME} indicates that the credential does
  151. * not expire. A return value of 0 indicates that the credential is
  152. * already expired.
  153. *
  154. * @see #getRemainingInitLifetime(Oid)
  155. * @see #getRemainingAcceptLifetime(Oid)
  156. *
  157. * @throws GSSException containing the following
  158. * major error codes:
  159. * {@link GSSException#FAILURE GSSException.FAILURE}
  160. */
  161. public int getRemainingLifetime() throws GSSException;
  162. /**
  163. * Returns the lifetime in seconds for the credential to remain capable
  164. * of initiating security contexts using the specified mechanism. This
  165. * method queries the initiator credential element that belongs to the
  166. * specified mechanism.
  167. *
  168. * @return the number of seconds remaining in the life of this credential
  169. * element. A return value of {@link #INDEFINITE_LIFETIME
  170. * INDEFINITE_LIFETIME} indicates that the credential element does not
  171. * expire. A return value of 0 indicates that the credential element is
  172. * already expired.
  173. *
  174. * @param mech the Oid of the mechanism whose intiator credential element
  175. * should be queried.
  176. *
  177. * @throws GSSException containing the following
  178. * major error codes:
  179. * {@link GSSException#BAD_MECH GSSException.BAD_MECH},
  180. * {@link GSSException#FAILURE GSSException.FAILURE}
  181. */
  182. public int getRemainingInitLifetime(Oid mech) throws GSSException;
  183. /**
  184. * Returns the lifetime in seconds for the credential to remain capable
  185. * of accepting security contexts using the specified mechanism. This
  186. * method queries the acceptor credential element that belongs to the
  187. * specified mechanism.
  188. *
  189. * @return the number of seconds remaining in the life of this credential
  190. * element. A return value of {@link #INDEFINITE_LIFETIME
  191. * INDEFINITE_LIFETIME} indicates that the credential element does not
  192. * expire. A return value of 0 indicates that the credential element is
  193. * already expired.
  194. *
  195. * @param mech the Oid of the mechanism whose acceptor credential element
  196. * should be queried.
  197. *
  198. * @throws GSSException containing the following
  199. * major error codes:
  200. * {@link GSSException#BAD_MECH GSSException.BAD_MECH},
  201. * {@link GSSException#FAILURE GSSException.FAILURE}
  202. */
  203. public int getRemainingAcceptLifetime(Oid mech) throws GSSException;
  204. /**
  205. * Returns the credential usage mode. In other words, it
  206. * tells us if this credential can be used for initiating or accepting
  207. * security contexts. It does not tell us which mechanism(s) has to be
  208. * used in order to do so. It is expected that an application will allow
  209. * the GSS-API to pick a default mechanism after calling this method.
  210. *
  211. * @return The return value will be one of {@link #INITIATE_ONLY
  212. * INITIATE_ONLY}, {@link #ACCEPT_ONLY ACCEPT_ONLY}, and {@link
  213. * #INITIATE_AND_ACCEPT INITIATE_AND_ACCEPT}.
  214. *
  215. * @throws GSSException containing the following
  216. * major error codes:
  217. * {@link GSSException#FAILURE GSSException.FAILURE}
  218. */
  219. public int getUsage() throws GSSException;
  220. /**
  221. * Returns the credential usage mode for a specific mechanism. In other
  222. * words, it tells us if this credential can be used
  223. * for initiating or accepting security contexts with a given underlying
  224. * mechanism.
  225. *
  226. * @return The return value will be one of {@link #INITIATE_ONLY
  227. * INITIATE_ONLY}, {@link #ACCEPT_ONLY ACCEPT_ONLY}, and {@link
  228. * #INITIATE_AND_ACCEPT INITIATE_AND_ACCEPT}.
  229. * @param mech the Oid of the mechanism whose credentials usage mode is
  230. * to be determined.
  231. *
  232. * @throws GSSException containing the following
  233. * major error codes:
  234. * {@link GSSException#BAD_MECH GSSException.BAD_MECH},
  235. * {@link GSSException#FAILURE GSSException.FAILURE}
  236. */
  237. public int getUsage(Oid mech) throws GSSException;
  238. /**
  239. * Returns a list of mechanisms supported by this credential. It does
  240. * not tell us which ones can be used to initiate
  241. * contexts and which ones can be used to accept contexts. The
  242. * application must call the {@link #getUsage(Oid) getUsage} method with
  243. * each of the returned Oid's to determine the possible modes of
  244. * usage.
  245. *
  246. * @return an array of Oid's corresponding to the supported mechanisms.
  247. *
  248. * @throws GSSException containing the following
  249. * major error codes:
  250. * {@link GSSException#FAILURE GSSException.FAILURE}
  251. */
  252. public Oid[] getMechs() throws GSSException;
  253. /**
  254. * Adds a mechanism specific credential-element to an existing
  255. * credential. This method allows the construction of credentials, one
  256. * mechanism at a time.<p>
  257. *
  258. * This routine is envisioned to be used mainly by context acceptors
  259. * during the creation of acceptor credentials which are to be used
  260. * with a variety of clients using different security mechanisms.<p>
  261. *
  262. * This routine adds the new credential element "in-place". To add the
  263. * element in a new credential, first call <code>clone</code> to obtain a
  264. * copy of this credential, then call its <code>add</code> method.<p>
  265. *
  266. * As always, GSS-API implementations must impose a local access-control
  267. * policy on callers to prevent unauthorized callers from acquiring
  268. * credentials to which they are not entitled.
  269. *
  270. * Non-default values for initLifetime and acceptLifetime cannot always
  271. * be honored by the underlying mechanisms, thus callers should be
  272. * prepared to call {@link #getRemainingInitLifetime(Oid)
  273. * getRemainingInitLifetime} and {@link #getRemainingAcceptLifetime(Oid)
  274. * getRemainingAcceptLifetime} on the credential.
  275. *
  276. * @param name the name of the principal for whom this credential is to
  277. * be acquired. Use <code>null</code> to specify the default
  278. * principal.
  279. * @param initLifetime the number of seconds that the credential element
  280. * should remain valid for initiating of security contexts. Use {@link
  281. * GSSCredential#INDEFINITE_LIFETIME GSSCredential.INDEFINITE_LIFETIME}
  282. * to request that the credentials have the maximum permitted lifetime
  283. * for this. Use {@link GSSCredential#DEFAULT_LIFETIME
  284. * GSSCredential.DEFAULT_LIFETIME} to request default credential lifetime
  285. * for this.
  286. * @param acceptLifetime the number of seconds that the credential
  287. * element should remain valid for accepting security contexts. Use {@link
  288. * GSSCredential#INDEFINITE_LIFETIME GSSCredential.INDEFINITE_LIFETIME}
  289. * to request that the credentials have the maximum permitted lifetime
  290. * for this. Use {@link GSSCredential#DEFAULT_LIFETIME
  291. * GSSCredential.DEFAULT_LIFETIME} to request default credential lifetime
  292. * for this.
  293. * @param mech the mechanism over which the credential is to be acquired.
  294. * @param usage the usage mode that this credential
  295. * element should add to the credential. The value
  296. * of this parameter must be one of:
  297. * {@link #INITIATE_AND_ACCEPT INITIATE_AND_ACCEPT},
  298. * {@link #ACCEPT_ONLY ACCEPT_ONLY}, and
  299. * {@link #INITIATE_ONLY INITIATE_ONLY}.
  300. *
  301. * @throws GSSException containing the following
  302. * major error codes:
  303. * {@link GSSException#DUPLICATE_ELEMENT
  304. * GSSException.DUPLICATE_ELEMENT},
  305. * {@link GSSException#BAD_MECH GSSException.BAD_MECH},
  306. * {@link GSSException#BAD_NAMETYPE GSSException.BAD_NAMETYPE},
  307. * {@link GSSException#NO_CRED GSSException.NO_CRED},
  308. * {@link GSSException#CREDENTIALS_EXPIRED
  309. * GSSException.CREDENTIALS_EXPIRED},
  310. * {@link GSSException#FAILURE GSSException.FAILURE}
  311. */
  312. public void add(GSSName name, int initLifetime, int acceptLifetime,
  313. Oid mech, int usage) throws GSSException;
  314. /**
  315. * Tests if this GSSCredential asserts the same entity as the supplied
  316. * object. The two credentials must be acquired over the same
  317. * mechanisms and must refer to the same principal.
  318. *
  319. * @return <code>true</code> if the two GSSCredentials assert the same
  320. * entity; <code>false</code> otherwise.
  321. * @param another another GSSCredential for comparison to this one
  322. */
  323. public boolean equals(Object another);
  324. /**
  325. * Returns a hashcode value for this GSSCredential.
  326. *
  327. * @return a hashCode value
  328. */
  329. public int hashCode();
  330. }