Annotation of embedaddon/axTLS/bindings/java/SSL.java, revision 1.1
1.1 ! misho 1: /*
! 2: * Copyright (c) 2007, Cameron Rich
! 3: *
! 4: * All rights reserved.
! 5: *
! 6: * Redistribution and use in source and binary forms, with or without
! 7: * modification, are permitted provided that the following conditions are met:
! 8: *
! 9: * * Redistributions of source code must retain the above copyright notice,
! 10: * this list of conditions and the following disclaimer.
! 11: * * Redistributions in binary form must reproduce the above copyright notice,
! 12: * this list of conditions and the following disclaimer in the documentation
! 13: * and/or other materials provided with the distribution.
! 14: * * Neither the name of the axTLS project nor the names of its contributors
! 15: * may be used to endorse or promote products derived from this software
! 16: * without specific prior written permission.
! 17: *
! 18: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
! 19: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
! 20: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
! 21: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
! 22: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
! 23: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
! 24: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
! 25: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
! 26: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
! 27: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
! 28: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
! 29: */
! 30:
! 31: /*
! 32: * A wrapper around the unmanaged interface to give a semi-decent Java API
! 33: */
! 34:
! 35: package axTLSj;
! 36:
! 37: import java.io.*;
! 38: import java.util.*;
! 39:
! 40: /**
! 41: * @defgroup java_api Java API.
! 42: *
! 43: * Ensure that the appropriate dispose() methods are called when finished with
! 44: * various objects - otherwise memory leaks will result.
! 45: */
! 46:
! 47: /**
! 48: * @class SSL
! 49: * @ingroup java_api
! 50: * @brief A representation of an SSL connection.
! 51: *
! 52: */
! 53: public class SSL
! 54: {
! 55: public int m_ssl; /**< A pointer to the real SSL type */
! 56:
! 57: /**
! 58: * @brief Store the reference to an SSL context.
! 59: * @param ip [in] A reference to an SSL object.
! 60: */
! 61: public SSL(int ip)
! 62: {
! 63: m_ssl = ip;
! 64: }
! 65:
! 66: /**
! 67: * @brief Free any used resources on this connection.
! 68: *
! 69: * A "Close Notify" message is sent on this connection (if possible). It
! 70: * is up to the application to close the socket.
! 71: */
! 72: public void dispose()
! 73: {
! 74: axtlsj.ssl_free(m_ssl);
! 75: }
! 76:
! 77: /**
! 78: * @brief Return the result of a handshake.
! 79: * @return SSL_OK if the handshake is complete and ok.
! 80: * @see ssl.h for the error code list.
! 81: */
! 82: public int handshakeStatus()
! 83: {
! 84: return axtlsj.ssl_handshake_status(m_ssl);
! 85: }
! 86:
! 87: /**
! 88: * @brief Return the SSL cipher id.
! 89: * @return The cipher id which is one of:
! 90: * - SSL_AES128_SHA (0x2f)
! 91: * - SSL_AES256_SHA (0x35)
! 92: * - SSL_RC4_128_SHA (0x05)
! 93: * - SSL_RC4_128_MD5 (0x04)
! 94: */
! 95: public byte getCipherId()
! 96: {
! 97: return axtlsj.ssl_get_cipher_id(m_ssl);
! 98: }
! 99:
! 100: /**
! 101: * @brief Get the session id for a handshake.
! 102: *
! 103: * This will be a 32 byte sequence and is available after the first
! 104: * handshaking messages are sent.
! 105: * @return The session id as a 32 byte sequence.
! 106: * @note A SSLv23 handshake may have only 16 valid bytes.
! 107: */
! 108: public byte[] getSessionId()
! 109: {
! 110: return axtlsj.ssl_get_session_id(m_ssl);
! 111: }
! 112:
! 113: /**
! 114: * @brief Retrieve an X.509 distinguished name component.
! 115: *
! 116: * When a handshake is complete and a certificate has been exchanged,
! 117: * then the details of the remote certificate can be retrieved.
! 118: *
! 119: * This will usually be used by a client to check that the server's common
! 120: * name matches the URL.
! 121: *
! 122: * A full handshake needs to occur for this call to work.
! 123: *
! 124: * @param component [in] one of:
! 125: * - SSL_X509_CERT_COMMON_NAME
! 126: * - SSL_X509_CERT_ORGANIZATION
! 127: * - SSL_X509_CERT_ORGANIZATIONAL_NAME
! 128: * - SSL_X509_CA_CERT_COMMON_NAME
! 129: * - SSL_X509_CA_CERT_ORGANIZATION
! 130: * - SSL_X509_CA_CERT_ORGANIZATIONAL_NAME
! 131: * @return The appropriate string (or null if not defined)
! 132: */
! 133: public String getCertificateDN(int component)
! 134: {
! 135: return axtlsj.ssl_get_cert_dn(m_ssl, component);
! 136: }
! 137: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>