Files
harbour-core/contrib/hbssl/ssl.c
Przemysław Czerpak 41b8ecb6c7 2015-08-26 15:51 UTC+0200 Przemyslaw Czerpak (druzus/at/poczta.onet.pl)
* include/hbsocket.h
  * src/rtl/hbsockhb.c
    + added socket filters to standard socket API.
      At C level hb_sockex*() function with PHB_SOCKEX handler can be
      used to operate on socket filters. At PRG level standard hb_socket*()
      functions can be used.
      The following things has been changed in PRG hb_socket*() functions:
      hb_socketErorrString() can accept <pSocket> as 1-st or 2-nd parameter
      and redirect call to socket filter errorStr() method.
      hb_socketClose() executes automatically shutdown() for connected
      sockets - it is important in windows only where without explicit
      call to shutdown() before close transmitted data can be lost.
      hb_socketSend() and hb_socketRecv() can be redirected to filter
      streams if filter set such redirection. If filter does not redirect
      them then they operate on raw sockets. If hb_socketSend() is
      redirected then sent data is flushed automatically.
      The following new PRG functions has been added:
      Add/replace socket filter:
         hb_socketSetFilter( <pSocket>, [<cFilterName>], [<hParams>] )
               -> <pSocket> | NIL
            <cFilterName> is filter name, It's possible to set many filters
            in single hb_socketSetFilter() call separating filter names
            with "|" character, i.e.:
               pSock := hb_socketSetFilter( pSock, "ZSOCK|BFSOCK", hParams )
            <hParams> is hash array with initialization parameters used by
            given socket filter. The core implementation recognize the
            following settings:
               "readahead" - numeric value with size of read ahead buffer
               "flush" - numeric value with auto flush parameter (for more
                         information look at hb_socketAutoFlush() below)
               "redir" - logical value which can be use to enable/disable
                         hb_socketSend() and hb_socketRecv() redirection
                         to filter stream.
      Return filter name used by socket:
         hb_socketGetFilter( <pSocket> ) -> <cFilterName>
      Read from socket stream:
         hb_socketRead( <pSocket>, @<cData>, [<nLen> = Len( cData )],
                        [<nTimeout> = FOREVER] ) -> <nRead>
         this function is similar to hb_socketRecv() but is always
         redirected to socket stream filters.
      Write to socket stream:
         hb_socketWrite( <pSocket>, <cData>, [<nLen> = Len( cData )],
                         [<nTimeout> = FOREVER] ) -> <nWritten>
         this function is similar to hb_socketSend() but it is always
         redirected to socket stream filters. Written data is not flushed
         by default and it should be flushed explicitly by hb_socketFlush().
         Automatic flushing can be enabled by hb_socketAutoFlush() function.
      Flush data written to socket:
         hb_socketFlush( <pSocket>, [<nTimeout> = FOREVER], [<lSync>] )
                     -> <nNotFlushed>
            <lSync> parameter is logical value which can be used to force
            special synchronization method in some filters. Usually users
            do not have to use it in normal code.
      Enable/disable automatic flushing of written data.
         hb_socketAutoFlush( <pSocket>, [ <nTimeout> ] ) -> <nTimeout>
            <nTimeout> is timeout for automatic flush operation on written
            data in milliseconds. <nTimeout> = -1 means wait forever and
            <nTimeout> = 0 disables auto flush.
         automatic flushing can help in adopting existing code anyhow it
         may strongly reduce the performance in some filters, i.e.
         compression filters like ZSOCK have to add special data to the
         stream after each flush operation so it's suggested to call
         flush explicitly when we want to force delivering written data
         to the peer.

  * include/hbznet.h
  * src/rtl/hbznet.c
    + added ZNET socket filter - compressed and encrypted streams are
      compatible with hb_znet*() streams. The old hb_znet*() interface
      is obsolete for pure socket communication and if not used as
      hb_inet*() filter then should be replaced by hb_sockex*() in
      user programs.
      ZNET socket filter can be created by new PRG functions:
         hb_socketNewZNet( <pSocket>, [<cPass>], [<nCompressionLevel>], ;
                           [<nStrategy>] ) -> <pSocket> | NIL
      or by standard socket API with "ZNET" as filter name.
      ZNET filter recognize the following settings in initialization
      hash array:
         "key" or "pass" - string with encryption password
         "zlib" - numeric compression level (HB_ZLIB_COMPRESSION_*)
         "zs" - numeric ZLIB compression strategy (HB_ZLIB_STRATEGY_*)
      ZNET filter always disables any other filters and operates on raw
      socket.
      Please remember that it's optional module. If programmer does not
      use hb_socketNewZNet() explicitly and prefers using hb_socketNew()
      then he should force linking this module by REQUEST hb_socketNewZNet

    + added fSync parameter to hb_znetFlush()
      [INCOMPATIBLE]

  * src/rtl/hbinet.c
    * call flush filter function before socket is closed

  * src/rtl/Makefile
  + src/rtl/hbzsock.c
    + added ZSOCK socket filter - ZLIB and GZIP compression for socket
      streams.
      ZSOCK socket filter can be created by new PRG functions:
         hb_socketNewZSock( <pSocket>, [<hParams>] ) -> <pSocket> | NIL
      or by standard socket API with "ZSOCK" as filter name.
      Programmers using hb_socketNew() can force linking this module by
         REQUEST hb_socketNewZSock
      ZSOCK filter can be used with other filters.
      ZSOCK filter recognize the following settings in initialization
      hash array:
         "zlib" - numeric compression level (HB_ZLIB_COMPRESSION_*)
         "zs" - numeric ZLIB compression strategy (HB_ZLIB_STRATEGY_*)
         "zin" - logical value which allow to enable/disable ZLIB
                 decompression on input stream (default)
         "gzin" - logical value which allow to enable/disable GZIP
                  decompression on input stream - it's possible to
                  enable both ZLIB and GZIP decompression together
                  so both streams can be decompress
         "zout" - logical value which allow to enable/disable ZLIB
                  compression on output stream (default)
         "gzout" - logical value which allow to enable/disable GZIP
                   compression on output stream - if both "zout" and
                   "gzout" are enabled GZIP compression is used.

  * src/rtl/Makefile
  + src/rtl/hbbfsock.c
    + added BFSOCK socket filter - BlowFish input and output stream
      encryption in CTR mode.
      BFSOCK socket filter can be created by new PRG functions:
         hb_socketNewBFSock( <pSocket>, [<hParams>] ) -> <pSocket> | NIL
      or by standard socket API with "BFSOCK" as filter name.
      Programmers using hb_socketNew() can force linking this module by
         REQUEST hb_socketNewBFSock
      BFSOCK filter can be used with other filters, i.e. with ZSOCK.
      Please only remember that good encryption algorithms have to
      generate data which cannot be compressed so using "BFSOCK|ZSOCK"
      only wastes resources and correct filter order is "ZSOCK|BFSOCK".
      BFSOCK filter recognize the following settings in initialization
      hash array:
         "key" or "pass" - string with encryption password
         "iv" - string with initialization vector for CTR mode

  * contrib/hbssl/hbssl.ch
  * contrib/hbssl/hbssl.h
  * contrib/hbssl/hbssl.hbm
  * contrib/hbssl/hbssl.hbx
  * contrib/hbssl/ssl.c
  * contrib/hbssl/ssl_inet.c
  + contrib/hbssl/ssl_sock.c
    + added SSL socket filter
      SSL socket filter can be created by new PRG functions:
         hb_socketNewSSL_connect( <pSocket>, <pSSL> [, <nTimeout> ] )
               -> <pSocketSSL> | NIL
         hb_socketNewSSL_accept( <pSocket>, <pSSL> [, <nTimeout> ] )
               -> <pSocketSSL> | NIL
      or by standard socket API with "SSL" as filter name.
      Programmers using hb_socketNew() can force linking this module by
         REQUEST hb_socketNewSSL_connect
      or
         REQUEST hb_socketNewSSL_accept
      SSL filter always disables any other filters and operates on raw
      socket.
      SSL filter recognize the following settings in initialization hash
      array:
         "ctx" or "key" - pointer SSL item <pSSL>
         "timeout" - timeout (numeric)
         "client" - logical value indicating client mode (SSL_connect())
         "server" - logical value indicating server mode (SSL_accept())

  * contrib/hbssl/tests/inetssl.prg
    ! cleaned typo in local function name

  * contrib/hbnetio/netiocli.c
  * contrib/hbnetio/netiosrv.c
    * use new Harbour extended socket API (hb_sockex*()) instead of
      raw sockets and hb_znet*()

  * contrib/hbtcpio/tcpio.c
    * use new Harbour extended socket API (hb_sockex*()) instead of
      raw sockets
    + implemented hb_fileFlush()
2015-08-26 15:51:35 +02:00

1593 lines
36 KiB
C

/*
* Harbour Project source code:
* OpenSSL API (SSL) - Harbour interface.
*
* Copyright 2009 Viktor Szakats (vszakats.net/harbour)
* www - http://harbour-project.org
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this software; see the file COPYING.txt. If not, write to
* the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/).
*
* As a special exception, the Harbour Project gives permission for
* additional uses of the text contained in its release of Harbour.
*
* The exception is that, if you link the Harbour libraries with other
* files to produce an executable, this does not by itself cause the
* resulting executable to be covered by the GNU General Public License.
* Your use of that executable is in no way restricted on account of
* linking the Harbour library code into it.
*
* This exception does not however invalidate any other reasons why
* the executable file might be covered by the GNU General Public License.
*
* This exception applies only to the code released by the Harbour
* Project under the name Harbour. If you copy code from other
* Harbour Project or Free Software Foundation releases into a copy of
* Harbour, as the General Public License permits, the exception does
* not apply to the code that you add in this way. To avoid misleading
* anyone as to the status of such modified files, you must delete
* this exception notice from them.
*
* If you write modifications of your own for Harbour, it is your choice
* whether to permit this exception to apply to your modifications.
* If you do not wish that, delete this exception notice.
*
*/
/* for applink.c */
#if ! defined( HB_OPENSSL_STATIC )
#if defined( _MSC_VER )
#ifndef _CRT_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS
#endif
#endif
#endif
#include "hbapi.h"
#include "hbapierr.h"
#include "hbapiitm.h"
#include "hbvm.h"
#if defined( HB_OS_WIN )
#include <windows.h>
#include <wincrypt.h>
#endif
#include "hbssl.h"
/* NOTE: See: http://www.openssl.org/support/faq.html#PROG2
Application must call SSL_init(), so that this module gets linked.
[vszakats] */
#if defined( HB_OS_WIN ) && ! defined( HB_OPENSSL_STATIC ) && OPENSSL_VERSION_NUMBER >= 0x00908000L
/* NOTE: It doesn't build in bcc55:
Warning W8065 openssl/applink.c 40: Call to function '_setmode' with no prototype in function app_fsetmod
Error E2451 openssl/applink.c 82: Undefined symbol '_lseek' in function OPENSSL_Applink
*/
#if ! defined( __BORLANDC__ )
#include "openssl/applink.c"
#endif
#endif
HB_FUNC( SSL_INIT )
{
SSL_library_init();
SSL_load_error_strings();
}
HB_FUNC( SSLEAY_VERSION )
{
int value = hb_parni( 1 );
switch( value )
{
case HB_SSLEAY_VERSION: value = SSLEAY_VERSION; break;
case HB_SSLEAY_CFLAGS: value = SSLEAY_CFLAGS; break;
case HB_SSLEAY_BUILT_ON: value = SSLEAY_BUILT_ON; break;
case HB_SSLEAY_PLATFORM: value = SSLEAY_PLATFORM; break;
case HB_SSLEAY_DIR: value = SSLEAY_DIR; break;
}
hb_retc( SSLeay_version( value ) );
}
HB_FUNC( OPENSSL_VERSION )
{
hb_retnint( OPENSSL_VERSION_NUMBER );
}
HB_FUNC( SSLEAY )
{
hb_retnint( SSLeay() );
}
static HB_GARBAGE_FUNC( SSL_release )
{
void ** ph = ( void ** ) Cargo;
/* Check if pointer is not NULL to avoid multiple freeing */
if( ph && *ph )
{
/* Destroy the object */
SSL_free( ( SSL * ) *ph );
/* set pointer to NULL just in case */
*ph = NULL;
}
}
static const HB_GC_FUNCS s_gcSSL_funcs =
{
SSL_release,
hb_gcDummyMark
};
void * hb_SSL_is( int iParam )
{
return hb_parptrGC( &s_gcSSL_funcs, iParam );
}
SSL * hb_SSL_par( int iParam )
{
void ** ph = ( void ** ) hb_parptrGC( &s_gcSSL_funcs, iParam );
return ph ? ( SSL * ) *ph : NULL;
}
SSL * hb_SSL_itemGet( PHB_ITEM pItem )
{
void ** ph = ( void ** ) hb_itemGetPtrGC( pItem, &s_gcSSL_funcs );
return ph ? ( SSL * ) *ph : NULL;
}
HB_FUNC( SSL_NEW )
{
if( hb_SSL_CTX_is( 1 ) )
{
SSL_CTX * ctx = hb_SSL_CTX_par( 1 );
if( ctx )
{
void ** ph = ( void ** ) hb_gcAllocate( sizeof( SSL * ), &s_gcSSL_funcs );
SSL * ssl = SSL_new( ctx );
*ph = ssl;
hb_retptrGC( ph );
}
}
else
hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( SSL_DUP )
{
if( hb_SSL_is( 1 ) )
{
SSL * ssl_par = hb_SSL_par( 1 );
if( ssl_par )
{
void ** ph = ( void ** ) hb_gcAllocate( sizeof( SSL * ), &s_gcSSL_funcs );
SSL * ssl = SSL_dup( ssl_par );
*ph = ssl;
hb_retptrGC( ph );
}
}
else
hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( SSL_ACCEPT )
{
if( hb_SSL_is( 1 ) )
{
SSL * ssl = hb_SSL_par( 1 );
if( ssl )
hb_retni( SSL_accept( ssl ) );
}
else
hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( SSL_CLEAR )
{
if( hb_SSL_is( 1 ) )
{
SSL * ssl = hb_SSL_par( 1 );
if( ssl )
SSL_clear( ssl );
}
else
hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( SSL_STATE )
{
if( hb_SSL_is( 1 ) )
{
SSL * ssl = hb_SSL_par( 1 );
if( ssl )
hb_retni( SSL_state( ssl ) );
}
else
hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( SSL_PENDING )
{
if( hb_SSL_is( 1 ) )
{
SSL * ssl = hb_SSL_par( 1 );
if( ssl )
hb_retni( SSL_pending( ssl ) );
}
else
hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( SSL_SET_BIO )
{
BIO * rbio = hb_BIO_par( 2 );
BIO * wbio = hb_BIO_par( 3 );
if( hb_SSL_is( 1 ) && rbio && wbio )
{
SSL * ssl = hb_SSL_par( 1 );
if( ssl )
SSL_set_bio( ssl, rbio, wbio );
}
else
hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( SSL_GET_RBIO )
{
if( hb_SSL_is( 1 ) )
{
SSL * ssl = hb_SSL_par( 1 );
if( ssl )
hb_retptr( SSL_get_rbio( ssl ) );
}
else
hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( SSL_GET_WBIO )
{
if( hb_SSL_is( 1 ) )
{
SSL * ssl = hb_SSL_par( 1 );
if( ssl )
hb_retptr( SSL_get_wbio( ssl ) );
}
else
hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( SSL_CONNECT )
{
if( hb_SSL_is( 1 ) )
{
SSL * ssl = hb_SSL_par( 1 );
if( ssl )
hb_retni( SSL_connect( ssl ) );
}
else
hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( SSL_SHUTDOWN )
{
if( hb_SSL_is( 1 ) )
{
SSL * ssl = hb_SSL_par( 1 );
if( ssl )
hb_retni( SSL_shutdown( ssl ) );
}
else
hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( SSL_VERSION )
{
if( hb_SSL_is( 1 ) )
{
SSL * ssl = hb_SSL_par( 1 );
if( ssl )
hb_retni( SSL_version( ssl ) );
}
else
hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( SSL_GET_VERSION )
{
if( hb_SSL_is( 1 ) )
{
SSL * ssl = hb_SSL_par( 1 );
if( ssl )
hb_retc( SSL_get_version( ssl ) );
}
else
hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( SSL_GET_CIPHER )
{
if( hb_SSL_is( 1 ) )
{
SSL * ssl = hb_SSL_par( 1 );
if( ssl )
hb_retc( SSL_get_cipher( ssl ) );
}
else
hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( SSL_DO_HANDSHAKE )
{
if( hb_SSL_is( 1 ) )
{
SSL * ssl = hb_SSL_par( 1 );
if( ssl )
hb_retni( SSL_do_handshake( ssl ) );
}
else
hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( SSL_RENEGOTIATE )
{
if( hb_SSL_is( 1 ) )
{
SSL * ssl = hb_SSL_par( 1 );
if( ssl )
hb_retni( SSL_renegotiate( ssl ) );
}
else
hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( SSL_TOTAL_RENEGOTIATIONS )
{
if( hb_SSL_is( 1 ) )
{
SSL * ssl = hb_SSL_par( 1 );
if( ssl )
hb_retnl( SSL_total_renegotiations( ssl ) );
}
else
hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( SSL_SET_FD )
{
int iSD;
if( hb_SSL_is( 1 ) && ( iSD = hb_parnidef( 2, -1 ) ) != -1 )
{
SSL * ssl = hb_SSL_par( 1 );
if( ssl )
hb_retni( SSL_set_fd( ssl, iSD ) );
}
else
hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( SSL_SET_RFD )
{
int iSD;
if( hb_SSL_is( 1 ) && ( iSD = hb_parnidef( 2, -1 ) ) != -1 )
{
SSL * ssl = hb_SSL_par( 1 );
if( ssl )
hb_retni( SSL_set_rfd( ssl, iSD ) );
}
else
hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( SSL_SET_WFD )
{
int iSD;
if( hb_SSL_is( 1 ) && ( iSD = hb_parnidef( 2, -1 ) ) != -1 )
{
SSL * ssl = hb_SSL_par( 1 );
if( ssl )
hb_retni( SSL_set_wfd( ssl, iSD ) );
}
else
hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( SSL_WANT )
{
if( hb_SSL_is( 1 ) )
{
SSL * ssl = hb_SSL_par( 1 );
if( ssl )
hb_retni( SSL_want( ssl ) );
}
else
hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( SSL_WANT_NOTHING )
{
if( hb_SSL_is( 1 ) )
{
SSL * ssl = hb_SSL_par( 1 );
if( ssl )
hb_retni( SSL_want_nothing( ssl ) );
}
else
hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( SSL_WANT_X509_LOOKUP )
{
if( hb_SSL_is( 1 ) )
{
SSL * ssl = hb_SSL_par( 1 );
if( ssl )
hb_retni( SSL_want_x509_lookup( ssl ) );
}
else
hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( SSL_WANT_READ )
{
if( hb_SSL_is( 1 ) )
{
SSL * ssl = hb_SSL_par( 1 );
if( ssl )
hb_retni( SSL_want_read( ssl ) );
}
else
hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( SSL_READ )
{
if( hb_SSL_is( 1 ) )
{
SSL * ssl = hb_SSL_par( 1 );
if( ssl )
{
PHB_ITEM pItem = hb_param( 2, HB_IT_STRING );
char * pBuffer;
HB_SIZE nLen;
int nRead = 0;
if( pItem && HB_ISBYREF( 2 ) &&
hb_itemGetWriteCL( pItem, &pBuffer, &nLen ) )
{
if( HB_ISNUM( 3 ) )
{
nRead = hb_parni( 3 );
if( nRead >= 0 && nRead < ( int ) nLen )
nLen = nRead;
}
nRead = nLen >= INT_MAX ? INT_MAX : ( int ) nLen;
nRead = SSL_read( ssl, pBuffer, nRead );
}
hb_retni( nRead );
}
}
else
hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( SSL_PEEK )
{
if( hb_SSL_is( 1 ) )
{
SSL * ssl = hb_SSL_par( 1 );
if( ssl )
{
PHB_ITEM pItem = hb_param( 2, HB_IT_STRING );
char * pBuffer;
HB_SIZE nLen;
int nRead = 0;
if( pItem && HB_ISBYREF( 2 ) &&
hb_itemGetWriteCL( pItem, &pBuffer, &nLen ) )
{
if( HB_ISNUM( 3 ) )
{
nRead = hb_parni( 3 );
if( nRead >= 0 && nRead < ( int ) nLen )
nLen = nRead;
}
nRead = nLen >= INT_MAX ? INT_MAX : ( int ) nLen;
nRead = SSL_peek( ssl, pBuffer, nRead );
}
hb_retni( nRead );
}
}
else
hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( SSL_WANT_WRITE )
{
if( hb_SSL_is( 1 ) )
{
SSL * ssl = hb_SSL_par( 1 );
if( ssl )
hb_retni( SSL_want_write( ssl ) );
}
else
hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( SSL_WRITE )
{
if( hb_SSL_is( 1 ) )
{
SSL * ssl = hb_SSL_par( 1 );
if( ssl )
{
PHB_ITEM pBuffer = hb_param( 2, HB_IT_STRING );
HB_SIZE nLen = hb_itemGetCLen( pBuffer );
if( HB_ISNUM( 3 ) )
{
HB_SIZE nWrite = ( HB_SIZE ) hb_parnl( 3 );
if( nWrite < nLen )
nLen = nWrite;
}
hb_retni( SSL_write( ssl, hb_itemGetCPtr( pBuffer ), ( int ) nLen ) );
}
}
else
hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( SSL_SET_SSL_METHOD )
{
if( hb_SSL_is( 1 ) )
{
SSL * ssl = hb_SSL_par( 1 );
if( ssl )
#if OPENSSL_VERSION_NUMBER < 0x10000000L
hb_retni( SSL_set_ssl_method( ssl, ( SSL_METHOD * ) hb_ssl_method_id_to_ptr( hb_parni( 2 ) ) ) );
#else
hb_retni( SSL_set_ssl_method( ssl, hb_ssl_method_id_to_ptr( hb_parni( 2 ) ) ) );
#endif
}
else
hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( SSL_GET_SSL_METHOD )
{
if( hb_SSL_is( 1 ) )
{
SSL * ssl = hb_SSL_par( 1 );
if( ssl )
{
#if OPENSSL_VERSION_NUMBER < 0x10000000L
SSL_METHOD * p = SSL_get_ssl_method( ssl );
#else
const SSL_METHOD * p = SSL_get_ssl_method( ssl );
#endif
int n;
if( p == SSLv3_method() ) n = HB_SSL_CTX_NEW_METHOD_SSLV3;
else if( p == SSLv3_server_method() ) n = HB_SSL_CTX_NEW_METHOD_SSLV3_SERVER;
else if( p == SSLv3_client_method() ) n = HB_SSL_CTX_NEW_METHOD_SSLV3_CLIENT;
#if OPENSSL_VERSION_NUMBER < 0x10000000L
else if( p == SSLv2_method() ) n = HB_SSL_CTX_NEW_METHOD_SSLV2;
else if( p == SSLv2_server_method() ) n = HB_SSL_CTX_NEW_METHOD_SSLV2_SERVER;
else if( p == SSLv2_client_method() ) n = HB_SSL_CTX_NEW_METHOD_SSLV2_CLIENT;
#endif
else if( p == TLSv1_method() ) n = HB_SSL_CTX_NEW_METHOD_TLSV1;
else if( p == TLSv1_server_method() ) n = HB_SSL_CTX_NEW_METHOD_TLSV1_SERVER;
else if( p == TLSv1_client_method() ) n = HB_SSL_CTX_NEW_METHOD_TLSV1_CLIENT;
else if( p == SSLv23_method() ) n = HB_SSL_CTX_NEW_METHOD_SSLV23;
else if( p == SSLv23_server_method() ) n = HB_SSL_CTX_NEW_METHOD_SSLV23_SERVER;
else if( p == SSLv23_client_method() ) n = HB_SSL_CTX_NEW_METHOD_SSLV23_CLIENT;
else n = HB_SSL_CTX_NEW_METHOD_UNKNOWN;
hb_retni( n );
}
}
else
hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( SSL_GET_CURRENT_CIPHER )
{
if( hb_SSL_is( 1 ) )
{
SSL * ssl = hb_SSL_par( 1 );
if( ssl )
hb_retptr( ( void * ) SSL_get_current_cipher( ssl ) );
}
else
hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( SSL_GET_CIPHER_BITS )
{
if( hb_SSL_is( 1 ) )
{
SSL * ssl = hb_SSL_par( 1 );
if( ssl )
{
int alg_bits = 0;
hb_retni( SSL_get_cipher_bits( ssl, &alg_bits ) );
hb_storni( alg_bits, 2 );
}
}
else
hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( SSL_GET_CIPHER_LIST )
{
if( hb_SSL_is( 1 ) )
{
SSL * ssl = hb_SSL_par( 1 );
if( ssl )
hb_retc( SSL_get_cipher_list( ssl, hb_parni( 2 ) ) );
}
else
hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( SSL_SET_CIPHER_LIST )
{
if( hb_SSL_is( 1 ) )
{
SSL * ssl = hb_SSL_par( 1 );
if( ssl && hb_parclen( 2 ) <= 255 )
hb_retni( SSL_set_cipher_list( ssl, hb_parcx( 2 ) ) );
}
else
hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( SSL_GET_CIPHER_NAME )
{
if( hb_SSL_is( 1 ) )
{
SSL * ssl = hb_SSL_par( 1 );
if( ssl )
hb_retc( SSL_get_cipher_name( ssl ) );
}
else
hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( SSL_GET_CIPHER_VERSION )
{
if( hb_SSL_is( 1 ) )
{
SSL * ssl = hb_SSL_par( 1 );
if( ssl )
hb_retc( SSL_get_cipher_version( ssl ) );
}
else
hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( SSL_COPY_SESSION_ID )
{
if( hb_SSL_is( 1 ) && hb_SSL_is( 2 ) )
{
SSL * ssl1 = hb_SSL_par( 1 );
SSL * ssl2 = hb_SSL_par( 2 );
if( ssl1 && ssl2 )
SSL_copy_session_id( ssl1, ssl2 );
}
else
hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( SSL_GET_SHARED_CIPHERS )
{
if( hb_SSL_is( 1 ) )
{
SSL * ssl = hb_SSL_par( 1 );
if( ssl )
{
char buffer[ 128 + 1 ]; /* See: CVE-2006-3738 */
buffer[ 0 ] = '\0';
hb_retc( SSL_get_shared_ciphers( ssl, buffer, sizeof( buffer ) - 1 ) );
}
}
else
hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( SSL_ALERT_DESC_STRING )
{
hb_retc( SSL_alert_desc_string( hb_parni( 1 ) ) );
}
HB_FUNC( SSL_ALERT_DESC_STRING_LONG )
{
hb_retc( SSL_alert_desc_string_long( hb_parni( 1 ) ) );
}
HB_FUNC( SSL_ALERT_TYPE_STRING )
{
hb_retc( SSL_alert_type_string( hb_parni( 1 ) ) );
}
HB_FUNC( SSL_ALERT_TYPE_STRING_LONG )
{
hb_retc( SSL_alert_type_string_long( hb_parni( 1 ) ) );
}
HB_FUNC( SSL_RSTATE_STRING )
{
if( hb_SSL_is( 1 ) )
{
SSL * ssl = hb_SSL_par( 1 );
if( ssl )
hb_retc( SSL_rstate_string( ssl ) );
}
else
hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( SSL_RSTATE_STRING_LONG )
{
if( hb_SSL_is( 1 ) )
{
SSL * ssl = hb_SSL_par( 1 );
if( ssl )
hb_retc( SSL_rstate_string( ssl ) );
}
else
hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( SSL_STATE_STRING )
{
if( hb_SSL_is( 1 ) )
{
SSL * ssl = hb_SSL_par( 1 );
if( ssl )
hb_retc( SSL_rstate_string( ssl ) );
}
else
hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( SSL_STATE_STRING_LONG )
{
if( hb_SSL_is( 1 ) )
{
SSL * ssl = hb_SSL_par( 1 );
if( ssl )
hb_retc( SSL_rstate_string( ssl ) );
}
else
hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
#if 0
HB_FUNC( SSL_GET_PSK_IDENTITY_HINT )
{
if( hb_SSL_is( 1 ) )
{
SSL * ssl = hb_SSL_par( 1 );
if( ssl )
hb_retc( SSL_get_psk_identity_hint( ssl ) );
}
else
hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( SSL_GET_PSK_IDENTITY )
{
if( hb_SSL_is( 1 ) )
{
SSL * ssl = hb_SSL_par( 1 );
if( ssl )
hb_retc( SSL_get_psk_identity( ssl ) );
}
else
hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
#endif
HB_FUNC( SSL_CHECK_PRIVATE_KEY )
{
if( hb_SSL_is( 1 ) )
{
SSL * ssl = hb_SSL_par( 1 );
if( ssl )
hb_retni( SSL_check_private_key( ssl ) );
}
else
hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( SSL_GET_ERROR )
{
if( hb_SSL_is( 1 ) )
{
SSL * ssl = hb_SSL_par( 1 );
if( ssl )
hb_retni( SSL_get_error( ssl, hb_parni( 2 ) ) );
}
else
hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( SSL_GET_FD )
{
if( hb_SSL_is( 1 ) )
{
SSL * ssl = hb_SSL_par( 1 );
if( ssl )
hb_retni( SSL_get_fd( ssl ) );
}
else
hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( SSL_GET_RFD )
{
if( hb_SSL_is( 1 ) )
{
SSL * ssl = hb_SSL_par( 1 );
if( ssl )
hb_retni( SSL_get_rfd( ssl ) );
}
else
hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( SSL_GET_WFD )
{
if( hb_SSL_is( 1 ) )
{
SSL * ssl = hb_SSL_par( 1 );
if( ssl )
hb_retni( SSL_get_wfd( ssl ) );
}
else
hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( SSL_GET_QUIET_SHUTDOWN )
{
if( hb_SSL_is( 1 ) )
{
SSL * ssl = hb_SSL_par( 1 );
if( ssl )
hb_retni( SSL_get_quiet_shutdown( ssl ) );
}
else
hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( SSL_GET_SHUTDOWN )
{
if( hb_SSL_is( 1 ) )
{
SSL * ssl = hb_SSL_par( 1 );
if( ssl )
hb_retni( SSL_get_shutdown( ssl ) );
}
else
hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( SSL_GET_READ_AHEAD )
{
if( hb_SSL_is( 1 ) )
{
#if defined( __BORLANDC__ ) /* TOFIX: SSL_get_read_ahead is an unresolved external when trying to link with BCC */
hb_retni( 0 );
#else
SSL * ssl = hb_SSL_par( 1 );
if( ssl )
hb_retni( SSL_get_read_ahead( ssl ) );
#endif
}
else
hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( SSL_GET_STATE )
{
if( hb_SSL_is( 1 ) )
{
SSL * ssl = hb_SSL_par( 1 );
if( ssl )
hb_retni( SSL_get_state( ssl ) );
}
else
hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( SSL_GET_VERIFY_MODE )
{
if( hb_SSL_is( 1 ) )
{
SSL * ssl = hb_SSL_par( 1 );
if( ssl )
hb_retni( SSL_get_verify_mode( ssl ) );
}
else
hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( SSL_IN_ACCEPT_INIT )
{
if( hb_SSL_is( 1 ) )
{
SSL * ssl = hb_SSL_par( 1 );
if( ssl )
hb_retni( SSL_in_accept_init( ssl ) );
}
else
hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( SSL_IN_BEFORE )
{
if( hb_SSL_is( 1 ) )
{
SSL * ssl = hb_SSL_par( 1 );
if( ssl )
hb_retni( SSL_in_before( ssl ) );
}
else
hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( SSL_IN_CONNECT_INIT )
{
if( hb_SSL_is( 1 ) )
{
SSL * ssl = hb_SSL_par( 1 );
if( ssl )
hb_retni( SSL_in_connect_init( ssl ) );
}
else
hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( SSL_IN_INIT )
{
if( hb_SSL_is( 1 ) )
{
SSL * ssl = hb_SSL_par( 1 );
if( ssl )
hb_retni( SSL_in_init( ssl ) );
}
else
hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( SSL_IS_INIT_FINISHED )
{
if( hb_SSL_is( 1 ) )
{
SSL * ssl = hb_SSL_par( 1 );
if( ssl )
hb_retni( SSL_is_init_finished( ssl ) );
}
else
hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( SSL_NUM_RENEGOTIATIONS )
{
if( hb_SSL_is( 1 ) )
{
SSL * ssl = hb_SSL_par( 1 );
if( ssl )
hb_retnl( SSL_num_renegotiations( ssl ) );
}
else
hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( SSL_CLEAR_NUM_RENEGOTIATIONS )
{
if( hb_SSL_is( 1 ) )
{
SSL * ssl = hb_SSL_par( 1 );
if( ssl )
hb_retnl( SSL_clear_num_renegotiations( ssl ) );
}
else
hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( SSL_GET_DEFAULT_TIMEOUT )
{
if( hb_SSL_is( 1 ) )
{
SSL * ssl = hb_SSL_par( 1 );
if( ssl )
hb_retnl( SSL_get_default_timeout( ssl ) );
}
else
hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( SSL_GET_VERIFY_RESULT )
{
if( hb_SSL_is( 1 ) )
{
SSL * ssl = hb_SSL_par( 1 );
if( ssl )
hb_retnl( SSL_get_verify_result( ssl ) );
}
else
hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( SSL_SESSION_REUSED )
{
if( hb_SSL_is( 1 ) )
{
SSL * ssl = hb_SSL_par( 1 );
if( ssl )
hb_retnl( SSL_session_reused( ssl ) );
}
else
hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( SSL_SET_ACCEPT_STATE )
{
if( hb_SSL_is( 1 ) )
{
SSL * ssl = hb_SSL_par( 1 );
if( ssl )
SSL_set_accept_state( ssl );
}
else
hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( SSL_SET_CONNECT_STATE )
{
if( hb_SSL_is( 1 ) )
{
SSL * ssl = hb_SSL_par( 1 );
if( ssl )
SSL_set_connect_state( ssl );
}
else
hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( SSL_GET_OPTIONS )
{
if( hb_SSL_is( 1 ) )
{
SSL * ssl = hb_SSL_par( 1 );
if( ssl )
hb_retnl( SSL_get_options( ssl ) );
}
else
hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( SSL_SET_OPTIONS )
{
if( hb_SSL_is( 1 ) )
{
SSL * ssl = hb_SSL_par( 1 );
if( ssl )
SSL_set_options( ssl, ( unsigned long ) hb_parnl( 2 ) );
}
else
hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( SSL_SET_QUIET_SHUTDOWN )
{
if( hb_SSL_is( 1 ) )
{
SSL * ssl = hb_SSL_par( 1 );
if( ssl )
SSL_set_quiet_shutdown( ssl, hb_parni( 2 ) );
}
else
hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( SSL_SET_READ_AHEAD )
{
if( hb_SSL_is( 1 ) )
{
SSL * ssl = hb_SSL_par( 1 );
if( ssl )
SSL_set_read_ahead( ssl, hb_parni( 2 ) /* yes */ );
}
else
hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( SSL_SET_SHUTDOWN )
{
if( hb_SSL_is( 1 ) )
{
SSL * ssl = hb_SSL_par( 1 );
if( ssl )
SSL_set_shutdown( ssl, hb_parni( 2 ) /* mode */ );
}
else
hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( SSL_SET_VERIFY_RESULT )
{
if( hb_SSL_is( 1 ) )
{
SSL * ssl = hb_SSL_par( 1 );
if( ssl )
SSL_set_verify_result( ssl, hb_parnl( 2 ) /* arg */ );
}
else
hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( SSL_SET_MODE )
{
if( hb_SSL_is( 1 ) )
{
SSL * ssl = hb_SSL_par( 1 );
if( ssl )
SSL_set_mode( ssl, hb_parnl( 2 ) );
}
else
hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( SSL_GET_MODE )
{
if( hb_SSL_is( 1 ) )
{
SSL * ssl = hb_SSL_par( 1 );
if( ssl )
hb_retnl( SSL_get_mode( ssl ) );
}
else
hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( SSL_SET_MTU )
{
if( hb_SSL_is( 1 ) )
{
#if OPENSSL_VERSION_NUMBER >= 0x00908000L && ! defined( HB_OPENSSL_OLD_OSX_ )
SSL * ssl = hb_SSL_par( 1 );
if( ssl )
SSL_set_mtu( ssl, hb_parnl( 2 ) );
#endif
}
else
hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( SSL_GET_CERTIFICATE )
{
if( hb_SSL_is( 1 ) )
{
SSL * ssl = hb_SSL_par( 1 );
if( ssl )
hb_X509_ret( SSL_get_certificate( ssl ), HB_FALSE );
}
else
hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( SSL_GET_PEER_CERTIFICATE )
{
if( hb_SSL_is( 1 ) )
{
SSL * ssl = hb_SSL_par( 1 );
if( ssl )
hb_X509_ret( SSL_get_peer_certificate( ssl ), HB_TRUE );
}
else
hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( SSL_USE_CERTIFICATE )
{
if( hb_SSL_is( 1 ) && hb_X509_is( 2 ) )
{
SSL * ssl = hb_SSL_par( 1 );
X509 * x509 = hb_X509_par( 2 );
if( ssl && x509 )
hb_retni( SSL_use_certificate( ssl, x509 ) );
}
else
hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( SSL_ADD_CLIENT_CA )
{
if( hb_SSL_is( 1 ) && hb_X509_is( 2 ) )
{
SSL * ssl = hb_SSL_par( 1 );
X509 * x509 = hb_X509_par( 2 );
if( ssl && x509 )
hb_retni( SSL_add_client_CA( ssl, x509 ) );
}
else
hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( SSL_USE_CERTIFICATE_FILE )
{
if( hb_SSL_is( 1 ) )
{
SSL * ssl = hb_SSL_par( 1 );
if( ssl )
hb_retni( SSL_use_certificate_file( ssl, hb_parc( 2 ), hb_parni( 3 ) ) );
}
else
hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( SSL_USE_PRIVATEKEY_FILE )
{
if( hb_SSL_is( 1 ) )
{
SSL * ssl = hb_SSL_par( 1 );
if( ssl )
hb_retni( SSL_use_PrivateKey_file( ssl, hb_parc( 2 ), hb_parni( 3 ) ) );
}
else
hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( SSL_USE_RSAPRIVATEKEY_FILE )
{
if( hb_SSL_is( 1 ) )
{
SSL * ssl = hb_SSL_par( 1 );
if( ssl )
hb_retni( SSL_use_RSAPrivateKey_file( ssl, hb_parc( 2 ), hb_parni( 3 ) ) );
}
else
hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( SSL_GET_CIPHERS )
{
if( hb_SSL_is( 1 ) )
{
SSL * ssl = hb_SSL_par( 1 );
if( ssl )
{
STACK_OF( SSL_CIPHER ) * stack = SSL_get_ciphers( ssl );
int len = sk_SSL_CIPHER_num( stack );
if( len > 0 )
{
PHB_ITEM pArray = hb_itemArrayNew( len );
int tmp;
for( tmp = 0; tmp < len; tmp++ )
hb_arraySetPtr( pArray, tmp + 1, sk_SSL_CIPHER_value( stack, tmp ) );
hb_itemReturnRelease( pArray );
}
else
hb_reta( 0 );
}
}
else
hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( SSL_GET_CLIENT_CA_LIST )
{
if( hb_SSL_is( 1 ) )
{
SSL * ssl = hb_SSL_par( 1 );
if( ssl )
{
STACK_OF( X509_NAME ) * stack = SSL_get_client_CA_list( ssl );
int len = sk_X509_NAME_num( stack );
if( len > 0 )
{
PHB_ITEM pArray = hb_itemArrayNew( len );
int tmp;
for( tmp = 0; tmp < len; tmp++ )
hb_arraySetPtr( pArray, tmp + 1, sk_X509_NAME_value( stack, tmp ) );
hb_itemReturnRelease( pArray );
}
else
hb_reta( 0 );
}
}
else
hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( SSL_LOAD_CLIENT_CA_FILE )
{
if( HB_ISCHAR( 1 ) )
{
STACK_OF( X509_NAME ) * stack = SSL_load_client_CA_file( hb_parc( 1 ) );
int len = sk_X509_NAME_num( stack );
if( len > 0 )
{
PHB_ITEM pArray = hb_itemArrayNew( len );
int tmp;
for( tmp = 0; tmp < len; tmp++ )
hb_arraySetPtr( pArray, tmp + 1, sk_X509_NAME_value( stack, tmp ) );
hb_itemReturnRelease( pArray );
}
else
hb_reta( 0 );
}
else
hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( SSL_USE_RSAPRIVATEKEY_ASN1 )
{
if( hb_SSL_is( 1 ) )
{
SSL * ssl = hb_SSL_par( 1 );
if( ssl )
/* 'const' not used in 2nd param because ssh.h misses it, too.
Bug report sent: #1988
[vszakats] */
hb_retni( SSL_use_RSAPrivateKey_ASN1( ssl, ( unsigned char * ) hb_parc( 2 ), ( int ) hb_parclen( 2 ) ) );
}
else
hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( SSL_USE_PRIVATEKEY_ASN1 )
{
if( hb_SSL_is( 2 ) )
{
SSL * ssl = hb_SSL_par( 2 );
if( ssl )
hb_retni( SSL_use_PrivateKey_ASN1( hb_parni( 1 ), ssl, ( HB_SSL_CONST unsigned char * ) hb_parc( 3 ), ( int ) hb_parclen( 3 ) ) );
}
else
hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( SSL_USE_CERTIFICATE_ASN1 )
{
if( hb_SSL_is( 1 ) )
{
SSL * ssl = hb_SSL_par( 1 );
if( ssl )
hb_retni( SSL_use_certificate_ASN1( ssl, ( HB_SSL_CONST unsigned char * ) hb_parc( 2 ), ( int ) hb_parclen( 2 ) ) );
}
else
hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( SSL_USE_PRIVATEKEY )
{
if( hb_SSL_is( 1 ) && hb_EVP_PKEY_is( 2 ) )
{
SSL * ssl = hb_SSL_par( 1 );
if( ssl )
/* QUESTION: It's unclear whether we should pass a copy here,
and who should free such passed EVP_PKEY object.
[vszakats] */
hb_retni( SSL_use_PrivateKey( ssl, hb_EVP_PKEY_par( 2 ) ) );
}
else
hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
/* Callback */
#if OPENSSL_VERSION_NUMBER >= 0x00907000L
static void hb_ssl_msg_callback( int write_p, int version, int content_type, const void * buf, size_t len, SSL * ssl, void * userdata )
{
HB_SYMBOL_UNUSED( ssl );
if( userdata && hb_vmRequestReenter() )
{
hb_vmPushEvalSym();
hb_vmPush( ( PHB_ITEM ) userdata );
hb_vmPushLogical( write_p );
hb_vmPushInteger( version );
hb_vmPushInteger( content_type );
hb_vmPushString( ( const char * ) buf, ( HB_SIZE ) len );
hb_vmSend( 4 );
hb_vmRequestRestore();
}
}
#endif
HB_FUNC( SSL_SET_MSG_CALLBACK )
{
if( hb_SSL_is( 1 ) )
{
SSL * ssl = hb_SSL_par( 1 );
if( ssl )
{
#if OPENSSL_VERSION_NUMBER >= 0x00907000L
PHB_ITEM pCallback = hb_param( 2, HB_IT_EVALITEM );
if( pCallback )
{
PHB_ITEM pPassCallback = hb_itemNew( pCallback );
SSL_set_msg_callback_arg( ssl, pPassCallback );
SSL_set_msg_callback( ssl, hb_ssl_msg_callback );
}
else
{
/* NOTE: WARNING: Direct access to OpenSSL internals. [vszakats] */
hb_itemRelease( ( PHB_ITEM ) ssl->msg_callback_arg );
SSL_set_msg_callback_arg( ssl, NULL );
SSL_set_msg_callback( ssl, NULL );
}
#endif
}
}
else
hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
/*
void SSL_set_psk_client_callback(SSL *ssl, unsigned int (*callback)(SSL *ssl, const char *hint, char *identity, unsigned int max_identity_len, unsigned char *psk, unsigned int max_psk_len));
void SSL_set_psk_server_callback(SSL *ssl, unsigned int (*callback)(SSL *ssl, const char *identity, unsigned char *psk, int max_psk_len));
EVP_PKEY * SSL_get_privatekey(SSL *ssl);
STACK * SSL_get_peer_cert_chain(const SSL *ssl);
int SSL_use_RSAPrivateKey(SSL *ssl, RSA *rsa);
void SSL_set_app_data(SSL *ssl, char *arg);
int SSL_set_ex_data(SSL *ssl, int idx, char *arg);
char * SSL_get_app_data(SSL *ssl);
char * SSL_get_ex_data( ssl, int );
int SSL_add_dir_cert_subjects_to_stack(STACK *stack, const char *dir);
int SSL_add_file_cert_subjects_to_stack(STACK *stack, const char *file);
STACK * SSL_dup_CA_list(STACK *sk);
SSL_CTX * SSL_get_SSL_CTX(const SSL *ssl);
int SSL_get_ex_data_X509_STORE_CTX_idx(void);
int SSL_get_ex_new_index(long argl, char *argp, int (*new_func);(void), int (*dup_func)(void), void (*free_func)(void))
void (*SSL_get_info_callback(const SSL *ssl);)()
SSL_SESSION *SSL_get_session(const SSL *ssl);
int (*SSL_get_verify_callback(const SSL *ssl))(int,X509_STORE_CTX *)
void SSL_set_client_CA_list(SSL *ssl, STACK *list);
void SSL_set_info_callback(SSL *ssl, void (*cb);(void))
void SSL_set_verify(SSL *ssl, int mode, int (*callback);(void))
*/