From a67b63175a084d5d1fb6cd67bbd64ae2d7bdb4df Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Thu, 23 Jul 2009 10:03:20 +0000 Subject: [PATCH] 2009-07-23 12:02 UTC+0200 Viktor Szakats (harbour.01 syenar.hu) * contrib/hbmisc/dates2.c * Renamed DAYSINMONTH() to HBMISC_DAYSINMONTH(), to avoid collision with hbct function with the same name, but different functionality. - Deleted functions below from hbmisc library: EOM(), BOM(), WOM(), DOY(), WOY(), EOY(), BOY() They have superior alternatives with the same name in hbct lib, please use those. * contrib/hbssl/evpciph.c * contrib/hbssl/ssl.c * contrib/hbssl/bio.c * contrib/hbssl/tests/pem.prg + contrib/hbssl/tests/pubkey.pem * contrib/hbssl/tests/crypt.prg * contrib/hbssl/err.c + Added EVP_SEALINIT() (under development) + Added EVP_SEALUPDATE(), EVP_SEALFINAL(). + Added SSL_SET_MSG_CALLBACK() (it's a debug function really, and the solution is slightly hackish, as I have to access OpenSSL structure and Harbour item freeing needs to be done manually. Anyhow it can be excluded from builds. + Added ERR_LOAD_CRYPTO_STRINGS(). + Added ERR_PRINT_ERRORS(). (very useful) + Added ERR_FREE_STRINGS(). * include/hbapi.h * source/vm/arrays.c * source/vm/extend.c * source/debug/dbgentry.c * source/rtl/hbgtcore.c ! Renamed API function hb_arraySetCPtr() to hb_arraySetCLPtr(). Old function name still available for compatibility. --- harbour/ChangeLog | 43 +++++++- harbour/contrib/hbmisc/dates2.c | 103 +----------------- harbour/contrib/hbssl/bio.c | 7 ++ harbour/contrib/hbssl/err.c | 22 ++++ harbour/contrib/hbssl/evpciph.c | 140 +++++++++++++++++++++++-- harbour/contrib/hbssl/ssl.c | 58 +++++++++- harbour/contrib/hbssl/tests/crypt.prg | 40 +++++++ harbour/contrib/hbssl/tests/pem.prg | 12 +++ harbour/contrib/hbssl/tests/pubkey.pem | 6 ++ harbour/include/hbapi.h | 4 +- harbour/source/debug/dbgentry.c | 4 +- harbour/source/rtl/hbgtcore.c | 2 +- harbour/source/vm/arrays.c | 4 +- harbour/source/vm/extend.c | 2 +- 14 files changed, 322 insertions(+), 125 deletions(-) create mode 100644 harbour/contrib/hbssl/tests/pubkey.pem diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 594ad2d8a4..0f45625d61 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -17,6 +17,41 @@ past entries belonging to author(s): Viktor Szakats. */ +2009-07-23 12:02 UTC+0200 Viktor Szakats (harbour.01 syenar.hu) + * contrib/hbmisc/dates2.c + * Renamed DAYSINMONTH() to HBMISC_DAYSINMONTH(), + to avoid collision with hbct function with the same + name, but different functionality. + - Deleted functions below from hbmisc library: + EOM(), BOM(), WOM(), DOY(), WOY(), EOY(), BOY() + They have superior alternatives with the same name + in hbct lib, please use those. + + * contrib/hbssl/evpciph.c + * contrib/hbssl/ssl.c + * contrib/hbssl/bio.c + * contrib/hbssl/tests/pem.prg + + contrib/hbssl/tests/pubkey.pem + * contrib/hbssl/tests/crypt.prg + * contrib/hbssl/err.c + + Added EVP_SEALINIT() (under development) + + Added EVP_SEALUPDATE(), EVP_SEALFINAL(). + + Added SSL_SET_MSG_CALLBACK() (it's a debug function really, + and the solution is slightly hackish, as I have to access + OpenSSL structure and Harbour item freeing needs to be done + manually. Anyhow it can be excluded from builds. + + Added ERR_LOAD_CRYPTO_STRINGS(). + + Added ERR_PRINT_ERRORS(). (very useful) + + Added ERR_FREE_STRINGS(). + + * include/hbapi.h + * source/vm/arrays.c + * source/vm/extend.c + * source/debug/dbgentry.c + * source/rtl/hbgtcore.c + ! Renamed API function hb_arraySetCPtr() to hb_arraySetCLPtr(). + Old function name still available for compatibility. + 2009-07-23 01:06 UTC+0200 Viktor Szakats (harbour.01 syenar.hu) + contrib/hbssl/tests/pem.prg + contrib/hbssl/tests/privkey.pem @@ -45,7 +80,7 @@ 2009-07-22 22:10 UTC+0200 Viktor Szakats (harbour.01 syenar.hu) * config/global.cf ! Fixed GTSLN exclusion if HB_COMMERCE is set. - This is rrequired to communicate this fact with + This is required to communicate this fact with postinst.sh (hb-func.sh -> hbmk script and hbmk.cfg) Thanks to Tamas Tevesz for report and tests. @@ -68,13 +103,13 @@ * contrib/hbssl/bio.c * contrib/hbssl/evpmd.c * Changed to make it build on darwin. - It's be better to control feature automatically by + It'd be better to control features automatically by OPENSSL_VERSION_NUMBER, but documentation is very scarce. * utils/hbmk2/hbmk2.prg ! Temp fix to not pass runflags to darwin GUI programs - (started via 'open'), until we find out how to make it. - Prevsiously 'open' considered extra options as its own, + (started via 'open'), until we find out how to do it. + Previously 'open' considered extra options as its own, and failed. 2009-07-22 17:51 UTC+0200 Viktor Szakats (harbour.01 syenar.hu) diff --git a/harbour/contrib/hbmisc/dates2.c b/harbour/contrib/hbmisc/dates2.c index 0123dd5072..49c43b9249 100644 --- a/harbour/contrib/hbmisc/dates2.c +++ b/harbour/contrib/hbmisc/dates2.c @@ -178,7 +178,7 @@ HB_FUNC( ISLEAPYEAR ) hb_retl( FALSE ); } -HB_FUNC( DAYSINMONTH ) +HB_FUNC( HBMISC_DAYSINMONTH ) { PHB_ITEM pDate = hb_param( 1, HB_IT_DATETIME ); @@ -193,66 +193,6 @@ HB_FUNC( DAYSINMONTH ) hb_retni( 0 ); } -HB_FUNC( EOM ) -{ - PHB_ITEM pDate = hb_param( 1, HB_IT_DATETIME ); - - if( pDate ) - { - int iYear, iMonth, iDay; - - hb_dateDecode( hb_itemGetDL( pDate ), &iYear, &iMonth, &iDay ); - hb_retd( iYear, iMonth, hb_daysinmonth( iYear, iMonth ) ); - } - else - hb_retdl( 0 ); -} - -HB_FUNC( BOM ) -{ - PHB_ITEM pDate = hb_param( 1, HB_IT_DATETIME ); - - if( pDate ) - { - int iYear, iMonth, iDay; - - hb_dateDecode( hb_itemGetDL( pDate ), &iYear, &iMonth, &iDay ); - hb_retd( iYear, iMonth, 1 ); - } - else - hb_retdl( 0 ); -} - -HB_FUNC( WOM ) -{ - PHB_ITEM pDate = hb_param( 1, HB_IT_DATETIME ); - - if( pDate ) - { - int iYear, iMonth, iDay; - - hb_dateDecode( hb_itemGetDL( pDate ), &iYear, &iMonth, &iDay ); - hb_retni( hb_wom( iYear, iMonth, iDay ) ); - } - else - hb_retni( 0 ); -} - -HB_FUNC( DOY ) -{ - PHB_ITEM pDate = hb_param( 1, HB_IT_DATETIME ); - - if( pDate ) - { - int iYear, iMonth, iDay; - - hb_dateDecode( hb_itemGetDL( pDate ), &iYear, &iMonth, &iDay ); - hb_retni( hb_doy( iYear, iMonth, iDay ) ); - } - else - hb_retni( 0 ); -} - /* Return the nWeek of the year (1 - 52, 0 - 52 if ISO) */ HB_FUNC( WOY ) @@ -269,44 +209,3 @@ HB_FUNC( WOY ) else hb_retni( 0 ); } - -HB_FUNC( EOY ) -{ - PHB_ITEM pDate = hb_param( 1, HB_IT_DATETIME ); - - if( pDate ) - { - int iYear, iMonth, iDay; - - hb_dateDecode( hb_itemGetDL( pDate ), &iYear, &iMonth, &iDay ); - hb_retd( iYear, 12, 31 ); - } - else - hb_retdl( 0 ); -} - -HB_FUNC( BOY ) -{ - PHB_ITEM pDate = hb_param( 1, HB_IT_DATETIME ); - - if( pDate ) - { - int iYear, iMonth, iDay; - - hb_dateDecode( hb_itemGetDL( pDate ), &iYear, &iMonth, &iDay ); - hb_retd( iYear, 1, 1 ); - } - else - hb_retdl( 0 ); -} - -/* -HB_FUNC( DATETIME ) -{ - time_t current_time; - - time( ¤t_time ); - - hb_retc( ctime( ¤t_time ) ); -} -*/ diff --git a/harbour/contrib/hbssl/bio.c b/harbour/contrib/hbssl/bio.c index 30dfe299c0..4b89efcdd2 100644 --- a/harbour/contrib/hbssl/bio.c +++ b/harbour/contrib/hbssl/bio.c @@ -725,6 +725,13 @@ int BIO_nread(BIO *bio, char **buf, int num); int BIO_nwrite0(BIO *bio, char **buf); int BIO_nwrite(BIO *bio, char **buf, int num); +BIO_METHOD * BIO_s_mem(void); + +BIO_set_mem_eof_return(BIO *b,int v) +long BIO_get_mem_data(BIO *b, char **pp) +BIO_set_mem_buf(BIO *b,BUF_MEM *bm,int c) +BIO_get_mem_ptr(BIO *b,BUF_MEM **pp) + BIO *BIO_new_mem_buf(void *buf, int len); #endif diff --git a/harbour/contrib/hbssl/err.c b/harbour/contrib/hbssl/err.c index b4c95a51a3..9af4ee8a7b 100644 --- a/harbour/contrib/hbssl/err.c +++ b/harbour/contrib/hbssl/err.c @@ -53,8 +53,25 @@ #include "hbapi.h" #include "hbapierr.h" +#include "hbssl.h" + #include +HB_FUNC( ERR_LOAD_CRYPTO_STRINGS ) +{ + ERR_load_crypto_strings(); +} + +HB_FUNC( ERR_PRINT_ERRORS ) +{ + BIO * bio = hb_BIO_par( 1 ); + + if( bio ) + ERR_print_errors( bio ); + else + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); +} + HB_FUNC( ERR_GET_ERROR ) { hb_retnint( ERR_get_error() ); @@ -173,3 +190,8 @@ HB_FUNC( ERR_PEEK_LAST_ERROR_LINE_DATA ) hb_storc( data, 3 ); hb_storni( flags, 4 ); } + +HB_FUNC( ERR_FREE_STRINGS ) +{ + ERR_free_strings(); +} diff --git a/harbour/contrib/hbssl/evpciph.c b/harbour/contrib/hbssl/evpciph.c index 7bf97d2ed7..cc1ea2061b 100644 --- a/harbour/contrib/hbssl/evpciph.c +++ b/harbour/contrib/hbssl/evpciph.c @@ -886,20 +886,144 @@ HB_FUNC( EVP_CIPHERFINAL_EX ) hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); } +HB_FUNC( EVP_SEALINIT ) +{ + const EVP_CIPHER * cipher = hb_EVP_CIPHER_par( 2 ); + + if( hb_EVP_CIPHER_CTX_is( 1 ) && cipher ) + { + EVP_CIPHER_CTX * ctx = hb_EVP_CIPHER_CTX_par( 1 ); + + if( ctx ) + { + int npubk = 0; + PHB_ITEM pArray = NULL; + EVP_PKEY * pkey1 = NULL; + + if( HB_ISARRAY( 5 ) ) + npubk = ( int ) hb_arrayLen( pArray = hb_param( 5, HB_IT_ARRAY ) ); + else if( HB_ISPOINTER( 5 ) ) + { + if( ( pkey1 = ( EVP_PKEY * ) hb_parptr( 5 ) ) ) + npubk = 1; + } + + if( npubk > 0 ) + { + unsigned char ** ek = ( unsigned char ** ) hb_xgrab( sizeof( unsigned char * ) * npubk ); + int * ekl = ( int * ) hb_xgrab( sizeof( int ) * npubk ); + int ivl = EVP_CIPHER_iv_length( cipher ); + unsigned char * iv = ivl > 0 ? ( unsigned char * ) hb_xgrab( ivl ) : NULL; + EVP_PKEY ** pubk = ( EVP_PKEY ** ) hb_xgrab( sizeof( EVP_PKEY * ) * npubk ); + PHB_ITEM pPKEY; + int tmp; + + for( tmp = 0; tmp < npubk; tmp++ ) + { + pubk[ tmp ] = pkey1 ? pkey1 : ( EVP_PKEY * ) hb_arrayGetPtr( pArray, tmp + 1 ); + ek[ tmp ] = ( unsigned char * ) hb_xgrab( EVP_PKEY_size( pubk[ tmp ] ) ); + ekl[ tmp ] = 0; + } + + hb_retni( EVP_SealInit( ctx, + cipher, + ek, + ekl, + iv, + pubk, + npubk ) ); + + pPKEY = hb_itemArrayNew( npubk ); + + for( tmp = 0; tmp < npubk; tmp++ ) + hb_arraySetCLPtr( pPKEY, tmp + 1, ( char * ) ek[ tmp ], ekl[ tmp ] ); + + hb_itemParamStoreForward( 3, pPKEY ); + hb_itemRelease( pPKEY ); + + if( iv ) + { + if( ! hb_storclen_buffer( ( char * ) iv, ivl, 4 ) ) + hb_xfree( iv ); + } + else + hb_stor( 4 ); + + hb_xfree( ek ); + hb_xfree( ekl ); + } + } + } + else + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); +} + +HB_FUNC( EVP_SEALUPDATE ) +{ + if( hb_EVP_CIPHER_CTX_is( 1 ) ) + { + EVP_CIPHER_CTX * ctx = hb_EVP_CIPHER_CTX_par( 1 ); + + if( ctx ) + { + int size = hb_parclen( 3 ) + EVP_CIPHER_CTX_block_size( ctx ) - 1; + unsigned char * buffer = ( unsigned char * ) hb_xgrab( size ); + + hb_retni( EVP_SealUpdate( ctx, + buffer, + &size, + ( const unsigned char * ) hb_parcx( 3 ), + ( size_t ) hb_parclen( 3 ) ) ); + + if( size > 0 ) + { + if( ! hb_storclen_buffer( ( char * ) buffer, size, 2 ) ) + hb_xfree( buffer ); + } + else + hb_storc( NULL, 2 ); + } + } + else + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); +} + +HB_FUNC( EVP_SEALFINAL ) +{ + if( hb_EVP_CIPHER_CTX_is( 1 ) ) + { + EVP_CIPHER_CTX * ctx = hb_EVP_CIPHER_CTX_par( 1 ); + + if( ctx ) + { + int size = EVP_CIPHER_CTX_block_size( ctx ); + unsigned char * buffer = ( unsigned char * ) hb_xgrab( size ); + + hb_retni( EVP_SealFinal( ctx, buffer, &size ) ); + + if( size > 0 ) + { + if( ! hb_storclen_buffer( ( char * ) buffer, size, 2 ) ) + hb_xfree( buffer ); + } + else + hb_storc( NULL, 2 ); + } + } + else + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); +} + #if 0 +int EVP_OpenInit(EVP_CIPHER_CTX *ctx,EVP_CIPHER *type,unsigned char *ek, int ekl,unsigned char *iv,EVP_PKEY *priv); +int EVP_OpenUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl, unsigned char *in, int inl); +int EVP_OpenFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl); + #define EVP_CIPHER_CTX_get_app_data(e) ((e)->app_data) #define EVP_CIPHER_CTX_set_app_data(e,d) ((e)->app_data=(char *)(d)) int EVP_CIPHER_param_to_asn1(EVP_CIPHER_CTX *c, ASN1_TYPE *type); int EVP_CIPHER_asn1_to_param(EVP_CIPHER_CTX *c, ASN1_TYPE *type); -int EVP_OpenInit(EVP_CIPHER_CTX *ctx,EVP_CIPHER *type,unsigned char *ek, int ekl,unsigned char *iv,EVP_PKEY *priv); -int EVP_OpenUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl, unsigned char *in, int inl); -int EVP_OpenFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl); - -int EVP_SealInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type, unsigned char **ek, int *ekl, unsigned char *iv, EVP_PKEY **pubk, int npubk); -int EVP_SealUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl, unsigned char *in, int inl); -int EVP_SealFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl); - #endif diff --git a/harbour/contrib/hbssl/ssl.c b/harbour/contrib/hbssl/ssl.c index f73ebb41be..d10734ebc2 100644 --- a/harbour/contrib/hbssl/ssl.c +++ b/harbour/contrib/hbssl/ssl.c @@ -53,6 +53,7 @@ #include "hbapi.h" #include "hbapierr.h" #include "hbapiitm.h" +#include "hbvm.h" #include "hbssl.h" @@ -1456,8 +1457,61 @@ HB_FUNC( SSL_USE_PRIVATEKEY ) hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); } +/* ---------------------------------------------------------------------------- */ +/* Callback */ + +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 ) + { + PHB_ITEM p1 = hb_itemPutL( NULL, write_p ); + PHB_ITEM p2 = hb_itemPutNI( NULL, version ); + PHB_ITEM p3 = hb_itemPutNI( NULL, content_type ); + PHB_ITEM p4 = hb_itemPutCL( NULL, buf, ( ULONG ) len ); + + hb_vmEvalBlockV( ( PHB_ITEM ) userdata, 4, p1, p2, p3, p4 ); + + hb_itemRelease( p4 ); + hb_itemRelease( p3 ); + hb_itemRelease( p2 ); + hb_itemRelease( p1 ); + } +} + +HB_FUNC( SSL_SET_MSG_CALLBACK ) +{ + if( hb_SSL_is( 1 ) ) + { + SSL * ssl = hb_SSL_par( 1 ); + + if( ssl ) + { + if( HB_ISBLOCK( 2 ) ) + { + PHB_ITEM pPassBlock = hb_itemNew( hb_param( 2, HB_IT_BLOCK ) ); + SSL_set_msg_callback_arg( ssl, pPassBlock ); + 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 ); + } + } + } + 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); @@ -1477,9 +1531,5 @@ 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_msg_callback(SSL *ctx, void (*cb)(int write_p, int version, int content_type, const void *buf, size_t len, SSL *ssl, void *arg)); -void SSL_set_msg_callback_arg(SSL *ctx, void *arg); void SSL_set_verify(SSL *ssl, int mode, int (*callback);(void)) -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)); */ diff --git a/harbour/contrib/hbssl/tests/crypt.prg b/harbour/contrib/hbssl/tests/crypt.prg index 5b837286b1..7f053e5390 100644 --- a/harbour/contrib/hbssl/tests/crypt.prg +++ b/harbour/contrib/hbssl/tests/crypt.prg @@ -20,6 +20,24 @@ PROCEDURE Main() LOCAL cKey := "key" + LOCAL a, iv, pub, bioe, tmp + + LOCAL all := {; + @PEM_READ_BIO_PRIVATEKEY() ,; + @PEM_READ_BIO_PUBKEY() ,; // + @PEM_READ_BIO_RSAPRIVATEKEY() ,; + @PEM_READ_BIO_RSAPUBLICKEY() ,; + @PEM_READ_BIO_RSA_PUBKEY() ,; // + @PEM_READ_BIO_DSAPRIVATEKEY() ,; + @PEM_READ_BIO_DSA_PUBKEY() ,; + @PEM_READ_BIO_DSAPARAMS() ,; + @PEM_READ_BIO_DHPARAMS() ,; + @PEM_READ_BIO_X509() ,; + @PEM_READ_BIO_X509_AUX() ,; + @PEM_READ_BIO_X509_REQ() ,; + @PEM_READ_BIO_X509_CRL() ,; + @PEM_READ_BIO_PKCS7() } + OpenSSL_add_all_ciphers() ctx := hb_EVP_CIPHER_CTX_create() @@ -51,6 +69,28 @@ PROCEDURE Main() decrypted += result ? "DECRYTPTED", ">" + decrypted + "<" + ? ERR_load_PEM_strings() + ? OpenSSL_add_all_algorithms() + + EVP_CIPHER_CTX_init( ctx ) + EVP_CIPHER_CTX_cleanup( ctx ) + + ? "()()()()()()()" +// bioe := BIO_new_fd( 1, HB_BIO_NOCLOSE ) +// FOR EACH tmp IN all +// ? tmp:__enumIndex(), tmp:exec( "pubkey.pem", "test" ) +// ? ; ERR_print_errors( bioe ) +// NEXT + + ? pub := PEM_READ_BIO_PUBKEY( "pubkey.pem", "test" ) + + ? "EVP_SealInit", EVP_SealInit( ctx, "AES-192-OFB", @a, @iv, { pub } ) + ? ValType( a ), Len( a ) + ? ValType( a[ 1 ] ), ">" + hb_StrToHex( a[ 1 ] ) + "<" + ? ValType( iv ), ">" + hb_StrToHex( iv ) + "<" + +// BIO_free( bioe ) + EVP_cleanup() RETURN diff --git a/harbour/contrib/hbssl/tests/pem.prg b/harbour/contrib/hbssl/tests/pem.prg index 5cf0955068..70e7f740b9 100644 --- a/harbour/contrib/hbssl/tests/pem.prg +++ b/harbour/contrib/hbssl/tests/pem.prg @@ -14,14 +14,21 @@ PROCEDURE Main() LOCAL cString LOCAL bio + LOCAL bioe ? ERR_load_PEM_strings() ? OpenSSL_add_all_algorithms() + bioe := BIO_new_fd( 1, HB_BIO_NOCLOSE ) + ? PEM_READ_BIO_RSAPRIVATEKEY( "privkey.pem", {| lWrite | QOut( "Callback", lWrite, hb_osNewLine() ), "test" } ) + ? ; ERR_print_errors( bioe ) ? PEM_READ_BIO_RSAPRIVATEKEY( "privkey.pem", "test" ) + ? ; ERR_print_errors( bioe ) ? PEM_READ_BIO_RSAPUBLICKEY( "privkey.pem", {| lWrite | QOut( "Callback", lWrite, hb_osNewLine() ), "test" } ) + ? ; ERR_print_errors( bioe ) ? PEM_READ_BIO_RSAPUBLICKEY( "privkey.pem", "test" ) + ? ; ERR_print_errors( bioe ) #pragma __cstream|cString:=%s -----BEGIN RSA PRIVATE KEY----- @@ -45,10 +52,15 @@ B0NDIZKbaPJHHPb9Ne7nQECzv0/kzmAley9UMTZ1M7fq6KYemR0LsA== ENDTEXT ? PEM_READ_BIO_RSAPRIVATEKEY( bio := BIO_new_mem_buf( cString ), {| lWrite | QOut( "Callback", lWrite, hb_osNewLine() ), "test" } ) + ? ; ERR_print_errors( bioe ) BIO_free( bio ) ? PEM_READ_BIO_RSAPRIVATEKEY( bio := BIO_new_mem_buf( cString ), "test" ) + ? ; ERR_print_errors( bioe ) BIO_free( bio ) ? PEM_READ_BIO_RSAPRIVATEKEY( bio := BIO_new_mem_buf( cString ), "" ) + ? ; ERR_print_errors( bioe ) BIO_free( bio ) + BIO_free( bioe ) + RETURN diff --git a/harbour/contrib/hbssl/tests/pubkey.pem b/harbour/contrib/hbssl/tests/pubkey.pem new file mode 100644 index 0000000000..f66531b91d --- /dev/null +++ b/harbour/contrib/hbssl/tests/pubkey.pem @@ -0,0 +1,6 @@ +-----BEGIN PUBLIC KEY----- +MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC0HdHkPyNDbBOXLPEIv6NFR3Kl +k+n+o8LdItmO/nm5kEttW+TzihF8PT+rfLq9YlNWEStKorSjVN9aSg448iFGkWXX +jG9vjKD56tWVSqbhASaqS3mThXXU8CEbHQNj+irrgOjn2429t9tA13WTuR/vfJIH +RtWcnqIuVtrjY2CKAwIDAQAB +-----END PUBLIC KEY----- diff --git a/harbour/include/hbapi.h b/harbour/include/hbapi.h index aafecac3a2..129590cae4 100644 --- a/harbour/include/hbapi.h +++ b/harbour/include/hbapi.h @@ -689,6 +689,8 @@ extern HB_EXPORT void hb_retnlllen( LONGLONG lNumber, int iWidth ); /* returns #define hb_retcStatic( szText ) hb_retc_const( (szText) ) #define hb_storclenAdopt hb_storclen_buffer #define hb_itemPutCRawStatic hb_itemPutCLConst +/* compatibility with older Harbour */ +#define hb_arraySetCPtr hb_arraySetCLPtr #ifdef HB_API_MACROS @@ -810,7 +812,7 @@ extern HB_EXPORT BOOL hb_arraySetNInt( PHB_ITEM pArray, ULONG ulIndex, H extern HB_EXPORT BOOL hb_arraySetND( PHB_ITEM pArray, ULONG ulIndex, double dNumber ); extern HB_EXPORT BOOL hb_arraySetC( PHB_ITEM pArray, ULONG ulIndex, const char * szText ); extern HB_EXPORT BOOL hb_arraySetCL( PHB_ITEM pArray, ULONG ulIndex, const char * szText, ULONG ulLen ); -extern HB_EXPORT BOOL hb_arraySetCPtr( PHB_ITEM pArray, ULONG ulIndex, char * szText, ULONG ulLen ); +extern HB_EXPORT BOOL hb_arraySetCLPtr( PHB_ITEM pArray, ULONG ulIndex, char * szText, ULONG ulLen ); extern HB_EXPORT BOOL hb_arraySetPtr( PHB_ITEM pArray, ULONG ulIndex, void * pValue ); extern HB_EXPORT BOOL hb_arraySetPtrGC( PHB_ITEM pArray, ULONG ulIndex, void * pValue ); extern HB_EXPORT BOOL hb_arraySetSymbol( PHB_ITEM pArray, ULONG ulIndex, PHB_SYMB pSymbol ); diff --git a/harbour/source/debug/dbgentry.c b/harbour/source/debug/dbgentry.c index d5bef3ecd4..c7f8c31189 100644 --- a/harbour/source/debug/dbgentry.c +++ b/harbour/source/debug/dbgentry.c @@ -731,7 +731,7 @@ static void hb_dbgAddStopLines( HB_DEBUGINFO *info, PHB_ITEM pItem ) pBuffer[ nOrigMin / 8 + k - nMin / 8 ] |= pOrigBuffer[ k ]; } hb_arraySetNL( pLines, 2, nMin ); - if( !hb_arraySetCPtr( pLines, 3, pBuffer, nLen - 1 ) ) + if( !hb_arraySetCLPtr( pLines, 3, pBuffer, nLen - 1 ) ) hb_xfree( pBuffer ); bFound = TRUE; break; @@ -755,7 +755,7 @@ static void hb_dbgAddStopLines( HB_DEBUGINFO *info, PHB_ITEM pItem ) if( szName != szModule ) { - hb_arraySetCPtr( pEntry, 1, hb_strdup( szName ), strlen( szName ) ); + hb_arraySetCLPtr( pEntry, 1, hb_strdup( szName ), strlen( szName ) ); } } } diff --git a/harbour/source/rtl/hbgtcore.c b/harbour/source/rtl/hbgtcore.c index 4b269e7789..bdae92a9ea 100644 --- a/harbour/source/rtl/hbgtcore.c +++ b/harbour/source/rtl/hbgtcore.c @@ -1530,7 +1530,7 @@ static BOOL hb_gt_def_Info( PHB_GT pGT, int iType, PHB_GT_INFO pInfo ) { void * pBuffer = hb_xgrab( ulSize + 1 ); HB_GTSELF_SAVE( pGT, 0, 0, iRow, iCol, pBuffer ); - hb_arraySetCPtr( pInfo->pResult, 7, ( char * ) pBuffer, ulSize ); + hb_arraySetCLPtr( pInfo->pResult, 7, ( char * ) pBuffer, ulSize ); } break; } diff --git a/harbour/source/vm/arrays.c b/harbour/source/vm/arrays.c index b903d8eb4e..40a63281ad 100644 --- a/harbour/source/vm/arrays.c +++ b/harbour/source/vm/arrays.c @@ -831,9 +831,9 @@ BOOL hb_arraySetCL( PHB_ITEM pArray, ULONG ulIndex, const char * szText, ULONG u return FALSE; } -BOOL hb_arraySetCPtr( PHB_ITEM pArray, ULONG ulIndex, char * szText, ULONG ulLen ) +BOOL hb_arraySetCLPtr( PHB_ITEM pArray, ULONG ulIndex, char * szText, ULONG ulLen ) { - HB_TRACE(HB_TR_DEBUG, ("hb_arraySetCPtr(%p, %lu, %p, %lu)", pArray, ulIndex, szText, ulLen)); + HB_TRACE(HB_TR_DEBUG, ("hb_arraySetCLPtr(%p, %lu, %p, %lu)", pArray, ulIndex, szText, ulLen)); if( HB_IS_ARRAY( pArray ) && ulIndex > 0 && ulIndex <= pArray->item.asArray.value->ulLen ) { diff --git a/harbour/source/vm/extend.c b/harbour/source/vm/extend.c index 8669d5f60a..6d81589bc9 100644 --- a/harbour/source/vm/extend.c +++ b/harbour/source/vm/extend.c @@ -1985,7 +1985,7 @@ int hb_storvclen_buffer( char * szText, ULONG ulLen, int iParam, ... ) int iRetVal; va_list va; va_start( va, iParam ); - iRetVal = hb_arraySetCPtr( pItem, va_arg( va, ULONG ), szText, ulLen ) ? 1 : 0; + iRetVal = hb_arraySetCLPtr( pItem, va_arg( va, ULONG ), szText, ulLen ) ? 1 : 0; va_end( va ); return iRetVal; }