SSLSession.java 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. /* SSLSession.java -- an SSL session.
  2. Copyright (C) 2004 Free Software Foundation, Inc.
  3. This file is part of GNU Classpath.
  4. GNU Classpath is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2, or (at your option)
  7. any later version.
  8. GNU Classpath is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GNU Classpath; see the file COPYING. If not, write to the
  14. Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  15. 02110-1301 USA.
  16. Linking this library statically or dynamically with other modules is
  17. making a combined work based on this library. Thus, the terms and
  18. conditions of the GNU General Public License cover the whole
  19. combination.
  20. As a special exception, the copyright holders of this library give you
  21. permission to link this library with independent modules to produce an
  22. executable, regardless of the license terms of these independent
  23. modules, and to copy and distribute the resulting executable under
  24. terms of your choice, provided that you also meet, for each linked
  25. independent module, the terms and conditions of the license of that
  26. module. An independent module is a module which is not derived from
  27. or based on this library. If you modify this library, you may extend
  28. this exception to your version of the library, but you are not
  29. obligated to do so. If you do not wish to do so, delete this
  30. exception statement from your version. */
  31. package javax.net.ssl;
  32. import java.security.Principal;
  33. import java.security.cert.Certificate;
  34. import javax.security.cert.X509Certificate;
  35. /**
  36. * An SSL session is a mechanism through which connections can be established
  37. * by re-using previously negotiated handshakes.
  38. */
  39. public interface SSLSession
  40. {
  41. /**
  42. * Returns the size of the largest application data buffer that can
  43. * occur in this session.
  44. *
  45. * <p>Buffers passed to handle the incoming data for the
  46. * <code>unwrap</code> method of SSLEngine must be at least this
  47. * large.
  48. *
  49. * @return The size of application buffers.
  50. * @since 1.5
  51. */
  52. int getApplicationBufferSize ();
  53. /**
  54. * Returns this session's cihper suite.
  55. *
  56. * @return The cipher suite.
  57. */
  58. String getCipherSuite();
  59. /**
  60. * Returns the time in milliseconds since midnight GMT, 1 January 1970, that
  61. * this session was created.
  62. *
  63. * @return The creation time.
  64. */
  65. long getCreationTime();
  66. /**
  67. * Returns this session's unique identifier, a arbitrary byte array of up
  68. * to 32 bytes.
  69. *
  70. * @return The session identifier.
  71. */
  72. byte[] getId();
  73. /**
  74. * Returns the last time this session was accessed.
  75. *
  76. * @return The lest time this session was accessed.
  77. */
  78. long getLastAccessedTime();
  79. /**
  80. * Returns the chain of certificates that the local side used in the
  81. * handshake, or null if none were used.
  82. *
  83. * @return The local certificate chain.
  84. */
  85. Certificate[] getLocalCertificates();
  86. /**
  87. * Returns the {@link Principal} representing the local identity
  88. * used in this session, or <code>null</code> if there is no local
  89. * identity.
  90. *
  91. * @return The local principal.
  92. */
  93. Principal getLocalPrincipal ();
  94. /**
  95. * Returns the size of the largest SSL message that will be
  96. * generated by this session.
  97. *
  98. * <p>Callers of <code>wrap</code> and <code>unwrap</code> should
  99. * use this value to determine the size of buffers for data coming
  100. * into, or going out over, the network.
  101. *
  102. * @returns The maximum network packet size.
  103. * @since 1.5
  104. */
  105. int getPacketBufferSize ();
  106. /**
  107. * Returns the chain of certificates that the remote side used in
  108. * the handshake, or null if none were used.
  109. *
  110. * @return The peer's certificate chain.
  111. * @throws SSLPeerUnverifiedException If the identity of the peer has
  112. * not been verified.
  113. */
  114. Certificate[] getPeerCertificates() throws SSLPeerUnverifiedException;
  115. /**
  116. * Returns the chain of certificates that the remote side used in
  117. * the handshake, or null if none were used.
  118. *
  119. * @return The peer's certificate chain.
  120. * @throws SSLPeerUnverifiedException If the identity of the peer has
  121. * not been verified.
  122. */
  123. X509Certificate[] getPeerCertificateChain()
  124. throws SSLPeerUnverifiedException;
  125. /**
  126. * Returns the remote host's name.
  127. *
  128. * @return The name of the remote host.
  129. */
  130. String getPeerHost();
  131. /**
  132. * Returns the port number the remote peer is using for this
  133. * session.
  134. *
  135. * @return The peer's port number.
  136. * @since 1.5
  137. */
  138. int getPeerPort ();
  139. /**
  140. * Returns the {@link Principal} representing the identity of the
  141. * remote peer, or <code>null</code> if the remote peer has no known
  142. * identity.
  143. *
  144. * @return The remote peer's principal.
  145. * @throws SSLPeerUnverifiedException If the remote peer's identity
  146. * could not be verified.
  147. * @since 1.5
  148. */
  149. Principal getPeerPrincipal () throws SSLPeerUnverifiedException;
  150. /**
  151. * Returns the protocol this session uses.
  152. *
  153. * @return The protocol.
  154. */
  155. String getProtocol();
  156. /**
  157. * Returns this session's session context object.
  158. *
  159. * @return The session context.
  160. * @throws SecurityException If the caller does not have the
  161. * {@link SSLPermission} "getSessionContext".
  162. */
  163. SSLSessionContext getSessionContext();
  164. /**
  165. * Returns the names of all values bound to this session.
  166. *
  167. * @return The list of bound names.
  168. */
  169. String[] getValueNames();
  170. /**
  171. * Returns the object bound to the given name.
  172. *
  173. * @param name The name of the value to get.
  174. * @return The object bound by that name, or null.
  175. */
  176. Object getValue(String name);
  177. /**
  178. * Invalidates this session, ensuring that it will not be continued by
  179. * another socket.
  180. */
  181. void invalidate();
  182. /**
  183. * Tells if this session is currently valid, and may be resumed.
  184. *
  185. * @return True if this session is valid.
  186. * @since 1.5
  187. * @see #invalidate()
  188. */
  189. boolean isValid ();
  190. /**
  191. * Binds a value to this session, with the given name.
  192. *
  193. * @param name The name to bind the object with.
  194. * @param value The value to bind.
  195. */
  196. void putValue(String name, Object value);
  197. /**
  198. * Un-binds a value.
  199. *
  200. * @param name The name of the value to un-bind.
  201. */
  202. void removeValue(String name);
  203. }