Upgrade openssl 1.0.2 to 1.1.1 guideline

2022-03-08 Thread Yan, Bob via openssl-users
Hi All,

Is there any guideline for upgrading openssl version from 1.0.2 to 1.1.1?

Thanks
Bob
 


RE: ECDSA certificate question

2020-09-22 Thread Yan, Bob via openssl-users
Thanks Michael,

I tried to invoke SM3 algorithm in command "openssl req -new -key eckey.pem 
-x509 -sm3 -nodes -days 365 -out cert.csr", unfortunately got the following 
error:

140320586413888:error:100C508A:elliptic curve 
routines:pkey_ec_ctrl:invalid digest type:crypto/ec/ec_pmeth.c:331:


-Original Message-
From: Michael Richardson  
Sent: Tuesday, September 22, 2020 4:36 PM
To: Yan, Bob 
Cc: openssl-users@openssl.org
Subject: Re: ECDSA certificate question


Yan, Bob via openssl-users  wrote:
> Is there a way to generate a ECDSA certificate with SM2 typed public
> key and ecdsa-with-SM3 as the signature algorithm in openssl 1.1.1x
> version?

I don't know the detail with the SM3, part, but have you seen:

  https://datatracker.ietf.org/doc/html/draft-moskowitz-ecdsa-pki-09
  https://github.com/rgmhtt/draft-moskowitz-ecdsa-pki

but, 1.1.1 release notes say it supports SM3. I expect you need to tweak 
something when "openssl req" is run.

--
Michael Richardson. o O ( IPv6 IøT consulting )
   Sandelman Software Works Inc, Ottawa and Worldwide






ECDSA certificate question

2020-09-22 Thread Yan, Bob via openssl-users
Hello everybody,

Is there a way to generate a ECDSA certificate with SM2 typed public key and 
ecdsa-with-SM3 as the signature algorithm in openssl 1.1.1x version?

Thank you very much!
Bob


[openssl-users] Lock for SSL_accept method

2018-02-07 Thread Yan, Bob via openssl-users
Hi All,

I used a mutex lock to prevent the SSL_accept() method being called by multiple 
thread concurrently since it may get coredump if there is no lock on 
SSL_accept() method. I am just wondering is the lock is still needed for 
openssl 1.0.2e version?

mutex.lock();
int rt = SSL_accept(SslSessionObject);
mutex.unlock();

Thank you very much!
Bob


-- 
openssl-users mailing list
To unsubscribe: https://mta.openssl.org/mailman/listinfo/openssl-users


Re: [openssl-users] Certificate Comparison

2017-09-19 Thread Yan, Bob via openssl-users
Thanks Scott, it can be done. I am also looking for some functions which can 
compare the fingerprint of certificates   

-Original Message-
From: Scott Neugroschl [mailto:scot...@xypro.com] 
Sent: Tuesday, September 19, 2017 11:30 AM
To: Yan, Bob ; openssl-users@openssl.org
Subject: RE: Certificate Comparison

How about saving the received cert as a PEM file and comparing the two?

-Original Message-
From: openssl-users [mailto:openssl-users-boun...@openssl.org] On Behalf Of 
Yan, Bob via openssl-users
Sent: Tuesday, September 19, 2017 10:53 AM
To: openssl-users@openssl.org
Subject: [openssl-users] Certificate Comparison

Hi All,

I need to compare a received certificate object with a PEM-formatted 
certificate stored at local file system. Is there any openssl library functions 
or an easy way to compare these two certificates?

Thank you very much!
Bob

-- 
openssl-users mailing list
To unsubscribe: https://mta.openssl.org/mailman/listinfo/openssl-users

-- 
openssl-users mailing list
To unsubscribe: https://mta.openssl.org/mailman/listinfo/openssl-users


[openssl-users] Certificate Comparison

2017-09-19 Thread Yan, Bob via openssl-users
Hi All,

I need to compare a received certificate object with a PEM-formatted 
certificate stored at local file system. Is there any openssl library functions 
or an easy way to compare these two certificates?

Thank you very much!
Bob

-- 
openssl-users mailing list
To unsubscribe: https://mta.openssl.org/mailman/listinfo/openssl-users


Re: [openssl-users] SSL_accept error code

2016-03-08 Thread Yan, Bob
Matt, thank you very much! It works after I use ERR_get_error() to get the 
error code.


-Original Message-
From: openssl-users [mailto:openssl-users-boun...@openssl.org] On Behalf Of 
Matt Caswell
Sent: Tuesday, March 08, 2016 1:29 AM
To: openssl-users@openssl.org
Subject: Re: [openssl-users] SSL_accept error code



On 08/03/16 01:04, Yan, Bob wrote:
> Hi All,
> 
> I have a SSL server application which use SSL_accept to accept the 
> connections from client, see the code below:
> 
> int retcode = SSL_accept(mSsl);
> unsigned long error =  SSL_get_error(mSsl, retcode); 
> ERR_error_string_n(error, errmsg, sizeof(errmsg));
> 
> When something went wrong, for example Client connect server with
> ssl3 protocol (disabled), I get the error like this 
> "error:0001:lib(0):func(0):reason(1)". Could somebody tell me that 
> is there any way to have more detailed debug messages from openssl?

You're not doing it right.

SSL_get_error() will give a return code to tell you the type of error that was 
received, e.g. SSL_ERROR_WANT_READ, SSL_ERROR_SYSCALL, SSL_ERROR_SSL, etc.

If error == SSL_ERROR_SSL then you can inspect the OpenSSL error queue for more 
details. You *do not* pass SSL_ERROR_SSL to ERR_error_string_n!
Use a function such as ERR_print_errors(), ERR_print_errors_fp(),
ERR_get_error() etc See the man pages for those functions.

Matt
--
openssl-users mailing list
To unsubscribe: https://mta.openssl.org/mailman/listinfo/openssl-users

-- 
openssl-users mailing list
To unsubscribe: https://mta.openssl.org/mailman/listinfo/openssl-users


[openssl-users] SSL_accept error code

2016-03-07 Thread Yan, Bob
Hi All,

I have a SSL server application which use SSL_accept to accept the connections 
from client, see the code below:

  int retcode = SSL_accept(mSsl);
  unsigned long error = SSL_get_error(mSsl, retcode);
  ERR_error_string_n(error, errmsg, sizeof(errmsg));
  
When something went wrong, for example Client connect server with ssl3 protocol 
(disabled), I get the error like this 
"error:0001:lib(0):func(0):reason(1)". Could somebody tell me that is there 
any way to have more detailed debug messages from openssl?

Thanks
Bob

 
-- 
openssl-users mailing list
To unsubscribe: https://mta.openssl.org/mailman/listinfo/openssl-users


[openssl-users] How to retrieve the revoked certificate list when X509_LOOKUP_hash_dir() method used

2016-02-25 Thread Yan, Bob
H All,

I used the following methods to load CRL hashed-directory into a SSL_CTX object 
to verify the client certificate against the CRL. The code works fine and it's 
able to verify the client certificate against the loaded CRLs.  

   X509_STORE *x509Store = SSL_CTX_get_cert_store(sslCtx);
   X509_LOOKUP *lookup = X509_STORE_add_lookup(x509Store, 
X509_LOOKUP_hash_dir());
   X509_LOOKUP_add_dir(lookup, crlDirectory, X509_FILETYPE_PEM);

My question is that, is there any method to retrieve the CRL list or print all 
revoked certificate list?

Thanks
Bob

-- 
openssl-users mailing list
To unsubscribe: https://mta.openssl.org/mailman/listinfo/openssl-users


Re: [openssl-users] WARNING message "can't open config file??? when running openssl command

2016-02-04 Thread Yan, Bob
Thanks, Steve!

-Original Message-
From: openssl-users [mailto:openssl-users-boun...@openssl.org] On Behalf Of Dr. 
Stephen Henson
Sent: Thursday, February 04, 2016 3:40 PM
To: openssl-users@openssl.org
Subject: Re: [openssl-users] WARNING message "can't open config file??? when 
running openssl command

On Thu, Feb 04, 2016, Yan, Bob wrote:

> Hi Rich,
> 
> It works, thank you for your suggestions! I am just wondering is there any 
> other options, for example eliminate the WARNING message while building the 
> openssl libraries and executables?
> 

Another option is to set an appropriate install location (the default is a 
Unixy path which doesn't make much sense on Windows) and install openssl.cnf in 
there.

Steve.
--
Dr Stephen N. Henson. OpenSSL project core developer.
Commercial tech support now available see: http://www.openssl.org 
___
openssl-users mailing list
To unsubscribe: https://mta.openssl.org/mailman/listinfo/openssl-users

___
openssl-users mailing list
To unsubscribe: https://mta.openssl.org/mailman/listinfo/openssl-users


Re: [openssl-users] WARNING message "can't open config file” when running openssl command

2016-02-04 Thread Yan, Bob
Thanks again, Rich!

-Original Message-
From: openssl-users [mailto:openssl-users-boun...@openssl.org] On Behalf Of 
Salz, Rich
Sent: Thursday, February 04, 2016 10:57 AM
To: openssl-users@openssl.org
Subject: Re: [openssl-users] WARNING message "can't open config file” when 
running openssl command

> It works, thank you for your suggestions! I am just wondering is there 
> any other options, for example eliminate the WARNING message while 
> building the openssl libraries and executables?

You could modify the source (e_os2.h, somewhere in that #ifdef maze sorry) to 
set the default ot be /dev/null ___
openssl-users mailing list
To unsubscribe: https://mta.openssl.org/mailman/listinfo/openssl-users

___
openssl-users mailing list
To unsubscribe: https://mta.openssl.org/mailman/listinfo/openssl-users


Re: [openssl-users] WARNING message "can't open config file” when running openssl command

2016-02-04 Thread Yan, Bob
Hi Rich,

It works, thank you for your suggestions! I am just wondering is there any 
other options, for example eliminate the WARNING message while building the 
openssl libraries and executables?

Thank you very much!
Bob


-Original Message-
From: openssl-users [mailto:openssl-users-boun...@openssl.org] On Behalf Of 
Salz, Rich
Sent: Thursday, February 04, 2016 10:41 AM
To: openssl-users@openssl.org
Subject: Re: [openssl-users] WARNING message "can't open config file” when 
running openssl command

> $ openssl x509 -in cert.pem -noout -text $ WARNING: can't open config 
> file: /usr/local/ssl/openssl.cnf

> How can I eliminate this WARNING message even though the 
> “/usr/local/ssl/openssl.cnf” file does not exist?

Among other options, "OPENSSL_CONF=/dev/null ; export OPENSSL_CONF" 
___
openssl-users mailing list
To unsubscribe: https://mta.openssl.org/mailman/listinfo/openssl-users
___
openssl-users mailing list
To unsubscribe: https://mta.openssl.org/mailman/listinfo/openssl-users


[openssl-users] WARNING message "can't open config file” when running openssl command

2016-02-04 Thread Yan, Bob
Hi All,

I downloaded openssl 1.0.2e source files and built it in a Linux server. It 
seems everything working fine except there is a WARNING message, “can't open 
config file” always shown on screen when I run openssl command, see below for 
detail:

$ openssl x509 -in cert.pem -noout -text
$ WARNING: can't open config file: /usr/local/ssl/openssl.cnf

How can I eliminate this WARNING message even though the 
“/usr/local/ssl/openssl.cnf” file does not exist?

Thanks
Bob


___
openssl-users mailing list
To unsubscribe: https://mta.openssl.org/mailman/listinfo/openssl-users


Re: [openssl-users] Certificate verification failure

2016-02-03 Thread Yan, Bob
Hi Jan,

The problem is due to the mis-matched version between openssl library (used by 
application) and openssl executable. Basically the CA/Intermediate CA 
certificate hash is calculated different between two versions.

Thank you for your help!
Bob

-Original Message-
From: openssl-users [mailto:openssl-users-boun...@openssl.org] On Behalf Of Jan 
Just Keijser
Sent: Wednesday, February 03, 2016 8:17 AM
To: openssl-users@openssl.org
Subject: Re: [openssl-users] Certificate verification failure

Yan, Bob wrote:
> Thanks Jan,
>
> When I am using the CApath, I do have the symbolic hash link (with ".0" at 
> the end hash) linked to my ca-root.pem certificate file and 
> ca-intermediate.pem certificate. Any other issues which could cause this 
> issue? 
>   
what happens if you run
  openssl verify -CApathclient.crt

? is that certificate correctly verified?

HTH,

JJK

> -Original Message-
> From: openssl-users [mailto:openssl-users-boun...@openssl.org] On 
> Behalf Of Jan Just Keijser
> Sent: Monday, February 01, 2016 1:04 AM
> To: openssl-users@openssl.org
> Subject: Re: [openssl-users] Certificate verification failure
>
> Yan, Bob wrote:
>   
>> Dear Sir/Madam,
>>
>> I have an application which acting as SSL server. When the 
>> application loads the root and intermediate CA files from a CA path, 
>> the handshake between my application and openssl client was failed at 
>> the point when my application was authenticating the client's 
>> certificate. But when I bound the root CA and intermediate CA into a 
>> single pem file and reload it from my application, the handshake is 
>> successful. Could anybody help me resolve this issue? Below is the 
>> sample of my application code for loading the CA certificates:
>>
>> if (SSL_CTX_load_verify_locations(ctx, caFile, caPath) != 1) {
>>
>> exit;
>>
>> }
>>
>> if (SSL_CTX_set_default_verify_paths(ctx) != 1) {
>>
>> exit;
>>
>> }
>>
>> if (SSL_CTX_use_certificate_chain_file(ctx, certFile) != 1) {
>>
>> exit;
>>
>> }
>>
>> if (SSL_CTX_use_PrivateKey_file(ctx, keyFile, SSL_FILETYPE_PEM) != 1) 
>> {
>>
>> exit;
>>
>> }
>>
>> SSL_CTX_set_verify_depth(ctx, chainDepths);
>>
>> SSL_CTX_set_verify(ctx, SSL_VERIFY_PEER | 
>> SSL_VERIFY_FAIL_IF_NO_PEER_CERT, callback);
>>
>> SSL_CTX_set_options(ctx, SSL_OP_ALL | SSL_OP_NO_SSLv2);
>>
>> 
>
> when you're using CA path , what are the contents of this CA path directory? 
> In it you should have placed the root and intermediate CA files using special 
> names. Instead of using "ca.pem" you need to have a file ".0" , where 
>  is the output of "openssl x509 -hash -noout -in ca.pem" (and similarly 
> for the intermediate CA file).
>
> JJK
>
> ___
> openssl-users mailing list
> To unsubscribe: https://mta.openssl.org/mailman/listinfo/openssl-users
>
> ___
> openssl-users mailing list
> To unsubscribe: https://mta.openssl.org/mailman/listinfo/openssl-users
>   

___
openssl-users mailing list
To unsubscribe: https://mta.openssl.org/mailman/listinfo/openssl-users

___
openssl-users mailing list
To unsubscribe: https://mta.openssl.org/mailman/listinfo/openssl-users


Re: [openssl-users] Certificate verification failure

2016-02-01 Thread Yan, Bob
Thanks Jan,

When I am using the CApath, I do have the symbolic hash link (with ".0" at the 
end hash) linked to my ca-root.pem certificate file and ca-intermediate.pem 
certificate. Any other issues which could cause this issue? 

-Original Message-
From: openssl-users [mailto:openssl-users-boun...@openssl.org] On Behalf Of Jan 
Just Keijser
Sent: Monday, February 01, 2016 1:04 AM
To: openssl-users@openssl.org
Subject: Re: [openssl-users] Certificate verification failure

Yan, Bob wrote:
>
> Dear Sir/Madam,
>
> I have an application which acting as SSL server. When the application 
> loads the root and intermediate CA files from a CA path, the handshake 
> between my application and openssl client was failed at the point when 
> my application was authenticating the client's certificate. But when I 
> bound the root CA and intermediate CA into a single pem file and 
> reload it from my application, the handshake is successful. Could 
> anybody help me resolve this issue? Below is the sample of my 
> application code for loading the CA certificates:
>
> if (SSL_CTX_load_verify_locations(ctx, caFile, caPath) != 1) {
>
> exit;
>
> }
>
> if (SSL_CTX_set_default_verify_paths(ctx) != 1) {
>
> exit;
>
> }
>
> if (SSL_CTX_use_certificate_chain_file(ctx, certFile) != 1) {
>
> exit;
>
> }
>
> if (SSL_CTX_use_PrivateKey_file(ctx, keyFile, SSL_FILETYPE_PEM) != 1) 
> {
>
> exit;
>
> }
>
> SSL_CTX_set_verify_depth(ctx, chainDepths);
>
> SSL_CTX_set_verify(ctx, SSL_VERIFY_PEER | 
> SSL_VERIFY_FAIL_IF_NO_PEER_CERT, callback);
>
> SSL_CTX_set_options(ctx, SSL_OP_ALL | SSL_OP_NO_SSLv2);
>

when you're using CA path , what are the contents of this CA path directory? In 
it you should have placed the root and intermediate CA files using special 
names. Instead of using "ca.pem" you need to have a file ".0" , where 
 is the output of "openssl x509 -hash -noout -in ca.pem" (and similarly 
for the intermediate CA file).

JJK

___
openssl-users mailing list
To unsubscribe: https://mta.openssl.org/mailman/listinfo/openssl-users

___
openssl-users mailing list
To unsubscribe: https://mta.openssl.org/mailman/listinfo/openssl-users


[openssl-users] Certificate verification failure

2016-01-29 Thread Yan, Bob
Dear Sir/Madam,

I have an application which acting as SSL server. When the application loads 
the root and intermediate CA files from a CA path, the handshake between my 
application and openssl client was failed at the point when my application was 
authenticating the client's certificate. But when I bound the root CA and 
intermediate CA into a single pem file and reload it from my application, the 
handshake is successful. Could anybody help me resolve this issue? Below is the 
sample of my application code for loading the CA certificates:

if (SSL_CTX_load_verify_locations(ctx, caFile, caPath) != 1) {
exit;
}
if (SSL_CTX_set_default_verify_paths(ctx) != 1) {
exit;
}
if (SSL_CTX_use_certificate_chain_file(ctx, certFile) != 1) {
exit;
}
if (SSL_CTX_use_PrivateKey_file(ctx, keyFile, SSL_FILETYPE_PEM) != 1) {
exit;
}
SSL_CTX_set_verify_depth(ctx, chainDepths);
SSL_CTX_set_verify(ctx, SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT, 
callback);
SSL_CTX_set_options(ctx, SSL_OP_ALL | SSL_OP_NO_SSLv2);

Thank you very much!
Bob

___
openssl-users mailing list
To unsubscribe: https://mta.openssl.org/mailman/listinfo/openssl-users


RE: Static and Dynamic Locking Functions

2013-03-14 Thread Yan, Bob
Gordon,

Just quick question for you, have you seen any dynamic mutex lock been created 
while your openssl application is running? I implemented both static and 
dynamic locking mechanism in my application. I can see that there are a total 
of 41 static mutex locks been created during initialization but I haven't seen 
any dynamic mutex lock been created and invoked by openssl functions.

Thanks
Bob

From: owner-openssl-us...@openssl.org [mailto:owner-openssl-us...@openssl.org] 
On Behalf Of Le Huang
Sent: Wednesday, March 13, 2013 8:21 PM
To: openssl-users@openssl.org
Subject: Re: Static and Dynamic Locking Functions

Gordon,

Not sure how your question relates OpenSSL, but in general, thread id is not a 
unique identifier for locks.

On Thu, Mar 14, 2013 at 3:40 AM, Betsy Gordon 
mailto:bgor...@companioncorp.com>> wrote:
Hello,

I have implemented static and dynamic locking functions but have a 
lingering question. It is not clear to me whether the same thread would ever 
create more than one lock before previous locks created by that thread had been 
destroyed. In other words, is the thread id intended to be the unique 
identifier for locks?

Thank you,
B. Gordon
__
OpenSSL Project http://www.openssl.org
User Support Mailing List
openssl-users@openssl.org
Automated List Manager   
majord...@openssl.org



--
Regards,
Huang Le (Eric, Alibaba DevOps)
Email: 4tarhl AT gmail.com, le.hl AT 
alibaba-inc.com


Test code coredump when running with IBM purify under openssl 1.0.1c release

2012-11-08 Thread Yan, Bob
Hi All,

When I am running my test code with IBM purify, my code was coredump. The same 
code worked fine in openssl 1.0.0a release but coredump under 1.0.1c release. 
Following is the debug message reported by IBM purify:

  Purify instrumented testapp (pid 16764)  
COR: Fatal core dump:
  * This is occurring while in thread 16764:
sha1_block_data_order_ssse3 [libcrypto.so.1.0.0]
SHA1_Update[libcrypto.so.1.0.0]
ssleay_rand_add [libcrypto.so.1.0.0]
RAND_poll  [libcrypto.so.1.0.0]
ssleay_rand_bytes [libcrypto.so.1.0.0]
SSL_CTX_new[libssl.so.1.0.0]
TestApp::init() [TestApp.cpp:32]
  * Received signal 11 (SIGSEGV - Segmentation fault)
  * Handler function: SIG_DFL
  * Faulting address = 0x0
  * Signal mask: (SIGSEGV)
  * Pending signals:

But that after I rebuilt openssl 1.0.1c library with "no-asm" option, the 
coredump was gone. Could somebody explain to me why this happens?

Thanks
Bob

__
OpenSSL Project http://www.openssl.org
User Support Mailing Listopenssl-users@openssl.org
Automated List Manager   majord...@openssl.org


RE: SSL_do_handshake() failed on openssl version 1.0.1c

2012-10-24 Thread Yan, Bob
Dear Sir/Madam,

I have used SSL_negotiate() and SSL_do_handshake() function to move the SSL 
connection into renegotiate state in my server side code. It works fine in 
openssl 1.0.0.a release. But after I upgraded the openssl library from version 
1.0.0a to 1.0.1c, this code does not work. Basically the second call on 
SSL_do_handshake() function was failed with the error: 
error:0001:lib(0):func(0):reason(1). Following is my sample code:

SSL *ssl_con = SSL_new(ssl_context);
SSL_negotiate(ssl_con);
SSL_do_handshake(ssl_con);
ssl_con->state = SSL_ST_ACCEPT;
SSL_do_handshake(ssl_con); Failed: 
error:0001:lib(0):func(0):reason(1).

Could somebody please show me how to resolve this issue?

Thank you very much in advance!
Bob

__
OpenSSL Project http://www.openssl.org
User Support Mailing Listopenssl-users@openssl.org
Automated List Manager   majord...@openssl.org


RE: Question regarding to memory leak

2011-06-27 Thread Yan, Bob
Thanks all of you for providing the inputs, and with your help, I think I found 
out the problem.

In my test program I am calling the function "X509_STORE_get_by_subject(ctx, 
X509_LU_CRL, issuer, &obj)" to get the CRL list. But after this function call, 
I didn't use the "X509_OBJECT_free_contents()" to free the contents of the 
returned object "obj". It seems this is the cause of the memory leak. By adding 
"X509_OBJECT_free_contents(&obj)" function, the Purify does not report any 
memory leaks.

Thanks
Bob



-Original Message-
From: owner-openssl-us...@openssl.org [mailto:owner-openssl-us...@openssl.org] 
On Behalf Of Chris Dodd
Sent: Friday, June 24, 2011 5:30 PM
To: openssl-users@openssl.org
Subject: Re: Question regarding to memory leak

  On Fri, Jun 24, 2011, Yan, Bob wrote:

>  Hi,
>
>  I have used IBM purify to check my test program which invokes openssl  
> library. There are some memory leaks reported by Purify, please see  
> below. Could somebody point to me from which function those leaks were  
> generated, and how to avoid those leaks? Thanks, Bob
>
>
>  MLK: 1104 bytes leaked in 46 blocks
>  This memory was allocated from:
>  malloc [rtlib.o]
>  CRYPTO_malloc [libcrypto.so.1.0.0]
>  ASN1_STRING_type_new [libcrypto.so.1.0.0]  ASN1_primitive_new 
> [libcrypto.so.1.0.0]  asn1_item_ex_combine_new [libcrypto.so.1.0.0]  
> asn1_item_ex_combine_new [libcrypto.so.1.0.0]  ASN1_item_ex_d2i 
> [libcrypto.so.1.0.0]  asn1_template_noexp_d2i [libcrypto.so.1.0.0]  
> Block of 24 bytes (46 times); last block at 0x2c0f7218

I've used valgrind with OpenSSL based programs to find memory leaks, and with 
it, you can use a "--num-callers=N" option to get deeper stack traces in the 
leak reports.  You need a depth of 15-20 to get far enough to see where your 
code is calling into the OpenSSL code in most cases.

There's probably a similar option for IBM purify.

 -chris

__
OpenSSL Project http://www.openssl.org
User Support Mailing Listopenssl-users@openssl.org
Automated List Manager   majord...@openssl.org
__
OpenSSL Project http://www.openssl.org
User Support Mailing Listopenssl-users@openssl.org
Automated List Manager   majord...@openssl.org


RE: Question regarding to memory leak

2011-06-24 Thread Yan, Bob
Thank you and Eric for the inputs. I will look at them and see what I should do 
with this.

Have a nice weekend.
Bob
 

-Original Message-
From: owner-openssl-us...@openssl.org [mailto:owner-openssl-us...@openssl.org] 
On Behalf Of t...@terralogic.net
Sent: Friday, June 24, 2011 4:52 PM
To: openssl-users@openssl.org
Subject: Re: Question regarding to memory leak

I have suggested this before.  Write your own memtools.


http://www.terralogic.net/developer/developer.html


I tossed up a couple poor boy examples.

Note the calls:

struct pfa_ControlBlock chain1 = { ipfa_ControlBlock }
  , chain2 = { ipfa_ControlBlock };

pfa_Init( &chain1, 8172 );
pfa_Init( &chain2, 8172 );

p = pfa_alloc( &chain1, 10, &ierr );   




In OpenSSL for instance each connection is identified by an fd (for the socket) 
and there are a fixed number of these.

One can set up an array of pointers and allocate a page of memory for each 
connection at the time the connection is opened.  

One wants a 1:1 correspondence between the fd flags from select() and the 
pfa_Control_Block pointer array.

Then when _ANY_ memory is needed simply use pfa_alloc() with the approriate 
control block of which the address can easily be looked up from the pointer 
array.

At any time if the connection is lost... forget it.  Close the socket and the 
next time the fd is used the old pages will be fetched from virtual memory as 
required.  No leaks!  Also all memory for a connection will be in a small group 
of pages which will be flushed to the swap file and they will stay there 
because there will never be any competing connections using that pool of pages! 
 (malloc will shuffle memory for many connections into a given set of pages).


If we want to actally free the memory because we are closing the fd then its 
simple... follow the linked list and free the pages.


-

Next it really doesn't matter if malloc and pfa_alloc() are both used.  Any 
structres which use pfa_blah will live in a world of their own which is totally 
compatible with anything malloc() might do.  We just wouldn't want a struct 
allocated with pfa_blah() pointed to by something allocated with malloc() 
because if we call pfa_init() then all those pointers in the malloc()ed structs 
are invalid.  However by definition if we call pfa_init() then that fd is dead 
so anything that points to anything allocated for that dead fd is likely 
invalid anyways.


The thing is this.  One can free and reallocate in a pfa_blah page pool.  I 
didn't need to do this so I never bothered.  But it can be done.  Anything 
which is not actually freed can be re-initialized at any time by calling 
pfa_init().  At that point all pages are wiped and ready for re-use.  One 
doesn't have to go through all sorts of linked structures and determine peice 
by piece what was and what was not allocated and whether something has been 
freed.  There is one master and simple linked list structure and that is found 
from the fd which identifies the socket.


-

As I said I offered this a few years ago.  I was told there is already some 
sort of memory management being used.  But I keep seeing comments on leaks so 
I'm not sure what is done because I think if one uses the fd one can sort of 
allocate a pool of pages for each connection and as long as all malloc() is 
done within that pool then we shouldn't have leaks.

Also if all malloc()s for an fd are in their own pool of pages then the machine 
can swap that connection out if required and if the connection times out and 
dies jsut re-initialize it when the fd is re-opened (on another connection).


On Fri, Jun 24, 2011 at 01:20:42PM -0700, Eric S. Eberhard wrote:
> As a general comment not all memory leaks reported by these tools are 
> a bad thing.  I often write code that has these type of leaks on 
> purpose for performance reasons.  For example a function that is 
> called often and malloc's memory ... rather than malloc and free each 
> time (causing context switching and generally slow) I just make the 
> pointer static and a size variable static.  I use the pointer until it 
> is too small, then I realloc to a larger size.  In modern systems 
> often the "leak" is worth the performance gain.  I run on IBM AIX.  
> Having said that, I have not dug in to your specifics which may just 
> be bugs, an error with the tool, or deliberate.  Eric
> 
> 
> At 11:58 AM 6/24/2011, Yan, Bob wrote:
> >Hi,
> >
> >I have used IBM purify to check my test program which invokes openssl 
> >library. There are some memory leaks reported by Purify, please see 
> >below. Could somebody point to me from which function those leaks 
> >were generated, and how to avoid those leaks? Thanks, Bob
> >
> >
> >  MLK: 1104 bytes leaked in 46 blocks
> >  This memor

Question regarding to memory leak

2011-06-24 Thread Yan, Bob
Hi,

I have used IBM purify to check my test program which invokes openssl library. 
There are some memory leaks reported by Purify, please see below. Could 
somebody point to me from which function those leaks were generated, and how to 
avoid those leaks? Thanks, Bob


 MLK: 1104 bytes leaked in 46 blocks
 This memory was allocated from:
   malloc [rtlib.o]
   CRYPTO_malloc  [libcrypto.so.1.0.0]
   ASN1_STRING_type_new [libcrypto.so.1.0.0]
   ASN1_primitive_new [libcrypto.so.1.0.0]
   asn1_item_ex_combine_new [libcrypto.so.1.0.0]
   asn1_item_ex_combine_new [libcrypto.so.1.0.0]
   ASN1_item_ex_d2i [libcrypto.so.1.0.0]
   asn1_template_noexp_d2i [libcrypto.so.1.0.0]
 Block of 24 bytes (46 times); last block at 0x2c0f7218
 MLK: 836 bytes leaked in 2 blocks
 This memory was allocated from:
   malloc [rtlib.o]
   CRYPTO_malloc  [libcrypto.so.1.0.0]
   asn1_enc_save  [libcrypto.so.1.0.0]
   ASN1_item_ex_d2i [libcrypto.so.1.0.0]
   asn1_template_noexp_d2i [libcrypto.so.1.0.0]
   asn1_template_ex_d2i [libcrypto.so.1.0.0]
   ASN1_item_ex_d2i [libcrypto.so.1.0.0]
   ASN1_item_d2i  [libcrypto.so.1.0.0]
 Block of 432 bytes at 0x2c093668
 Block of 404 bytes at 0x2c009d58
 MLK: 800 bytes leaked in 20 blocks
 This memory was allocated from:
   malloc [rtlib.o]
   CRYPTO_malloc  [libcrypto.so.1.0.0]
   ASN1_OBJECT_new [libcrypto.so.1.0.0]
   c2i_ASN1_OBJECT [libcrypto.so.1.0.0]
   asn1_ex_c2i[libcrypto.so.1.0.0]
   asn1_d2i_ex_primitive [libcrypto.so.1.0.0]
   ASN1_item_ex_d2i [libcrypto.so.1.0.0]
   asn1_template_noexp_d2i [libcrypto.so.1.0.0]
 Block of 40 bytes (20 times); last block at 0x2c097a78
 MLK: 600 bytes leaked in 15 blocks
 This memory was allocated from:
   malloc [rtlib.o]
   CRYPTO_malloc  [libcrypto.so.1.0.0]
   asn1_item_ex_combine_new [libcrypto.so.1.0.0]
   ASN1_item_ex_d2i [libcrypto.so.1.0.0]
   asn1_template_noexp_d2i [libcrypto.so.1.0.0]
   asn1_template_ex_d2i [libcrypto.so.1.0.0]
   ASN1_item_ex_d2i [libcrypto.so.1.0.0]
   asn1_template_noexp_d2i [libcrypto.so.1.0.0]
 Block of 40 bytes (15 times); last block at 0x2c0f6e98
 MLK: 376 bytes leaked in 33 blocks
 This memory was allocated from:
   malloc [rtlib.o]
   CRYPTO_malloc  [libcrypto.so.1.0.0]
   ASN1_STRING_set [libcrypto.so.1.0.0]
   asn1_ex_c2i[libcrypto.so.1.0.0]
   asn1_d2i_ex_primitive [libcrypto.so.1.0.0]
   ASN1_item_ex_d2i [libcrypto.so.1.0.0]
   asn1_template_noexp_d2i [libcrypto.so.1.0.0]
   asn1_template_ex_d2i [libcrypto.so.1.0.0]
 Block of 14 bytes (21 times); last block at 0x2c0f7168
 Block of 12 bytes (2 times); last block at 0x2c096828
 Block of 11 bytes (2 times); last block at 0x2c096338
 Block of 5 bytes (6 times); last block at 0x2c0976f8
 Block of 3 bytes (2 times); last block at 0x2c095e58
 .
 .
 .




Question about SSL_CTX_load_verify_locations()

2011-06-13 Thread Yan, Bob
Hi,

I am using "SSL_CTX_load_verify_locations(ssl_ctx, NULL, CApath)" function to 
load the CA certificates from the "CApath" directory. Since the certificates in 
CApath are only looked up when required, my questions is that, is any openssl 
function can be used to load all trusted CA certificates from CApath before 
performing the verification of a peer certificate?

Thanks
Bob
__
OpenSSL Project http://www.openssl.org
User Support Mailing Listopenssl-users@openssl.org
Automated List Manager   majord...@openssl.org


RE: ssl_connect core dump in multi-threading application

2011-05-31 Thread Yan, Bob
Thanks Steve,

Currently my test program does not setup the locking callbacks as well as the 
thread ID callback. In general, should I must setup them in multi-threading 
openssl application? If so, should the following two functions be used to setup 
the locking callbacks and the thread ID callback?   

   CRYPTO_set_id_callback((unsigned long (*)())pthreads_thread_id);
   CRYPTO_set_locking_callback((void (*)())pthreads_locking_callback);

Thanks
Bob

__
OpenSSL Project http://www.openssl.org
User Support Mailing Listopenssl-users@openssl.org
Automated List Manager   majord...@openssl.org


ssl_connect core dump in multi-threading application

2011-05-31 Thread Yan, Bob
Hi,

I have an application which has more than 100 SSL client threads and each of 
those threads tried to connect to a SSL server simultaneously. Occasionally the 
application process got coredump on the call to ssl_connect(), please see the 
stack trace below for detail.

*** glibc detected *** testnetwork: double free or corruption (!prev): 
0x2aaaf001adf0 ***
=== Backtrace: =
/lib64/libc.so.6[0x30896722ef]
/lib64/libc.so.6[0x3089674542]
/lib64/libc.so.6(realloc+0x102)[0x30896751a2]
~/openssl/lib/libcrypto.so.1.0.0(CRYPTO_realloc+0x60)[0x2b06737c1d80]
~/openssl/lib/libcrypto.so.1.0.0(lh_insert+0x176)[0x2b067382a926]
~/openssl/lib/libcrypto.so.1.0.0[0x2b067382c9c6]
~/openssl/lib/libcrypto.so.1.0.0(ERR_get_state+0x1f9)[0x2b067382cf09]
~/openssl/lib/libcrypto.so.1.0.0(ERR_clear_error+0xd)[0x2b067382d62d]
~/openssl/lib/libssl.so.1.0.0(ssl3_connect+0x31)[0x2b0673529f21]

Could someone give me some suggestions about this issue? By the way, in my 
application, all these 100 SSL client threads share the same SSL_CTX object and 
the application runs under RedHat Linux.

Thanks
Bob



RE: Trying to get URI of CRL from certificate extension

2011-05-27 Thread Yan, Bob
Hi Akash,

I have encountered the same issue as you mentioned in your email but I still 
haven't figured out the cause of the failure. However, after I replaced "d2i(0, 
&data, ext->value->length)" function with X509V3_EXT_d2i(ext), the problem was 
gone.

Regards
Bob




From: owner-openssl-us...@openssl.org [mailto:owner-openssl-us...@openssl.org] 
On Behalf Of Akash Deo
Sent: Thursday, May 26, 2011 11:57 PM
To: openssl-users@openssl.org
Subject: Trying to get URI of CRL from certificate extension

Hi,

I am trying to get URI of the CRL from certificate extension using below 
function:

static char *get_distribution_point(X509 *cert) {
  int   extcount, i, j;
  const char*extstr;
  CONF_VALUE*nval;
  unsigned char *data;
  X509_EXTENSION*ext;
  X509V3_EXT_METHOD *meth;
  STACK_OF(CONF_VALUE)  *val;

  if ((extcount = X509_get_ext_count(cert)) > 0) {
for (i = 0; i < extcount; i++) {
  ext = X509_get_ext(cert, i);
  extstr = OBJ_nid2sn(OBJ_obj2nid(X509_EXTENSION_get_object(ext)));
  if (strcasecmp(extstr, "crlDistributionPoints")) continue;

  if (!(meth = X509V3_EXT_get(ext))) break;
  data = ext->value->data;
  val = meth->i2v(meth, meth->d2i(0, &data, ext->value->length), 0);
  for (j = 0;  j < sk_CONF_VALUE_num(val);  j++) {
nval = sk_CONF_VALUE_value(val, j);
if (!strcasecmp(nval->name, "URI"))
  return strdup(nval->value);
  }
}
  }
  return 0;
}



Above function fails at
val = meth->i2v(meth, meth->d2i(0, &data, ext->value->length), 0);

Any suggestions ?

Please help

Thanks & Regards,
Akash Deo


SSL_read() fails right after the failure of SSL_do_handsahake() on client side

2011-04-14 Thread Yan, Bob
Hi,

I have a simple SSL Client and SSL Server program. SSL Client connects to SSL 
Server via an established ssl session and transmit data each other.

Every time when SSL Server invokes the SSL_write() function and successful 
wrote some data into the ssl session, if, at the same time, the SSL Client side 
start to renegotiate on this session, which invokes SSL_renegotiate() function 
and followed by SSL_do_handsahake(), the SSL_do_handsahake() will fail. Further 
more, right after the failure on SSL Client side, the SSL_read() call on SSL 
Server side will also fail, which returns an error code SSL_ERROR_SSL.

Is this is right behavior of ssl session? Or did I make something wrong?

Thanks
Bob





RE: SSL_ERROR_WANT_READ and SSL_ERROR_WANT-WRITE question

2011-03-07 Thread Yan, Bob
Thank you very much, David,

In general, if the application use "select/poll" system function to check the 
readable of underline BIO and invoke the SSL_read/SSL_write only if there are 
data available on the socket, can the deadlock still happened?

Specially, in your last statement "At step 3 above, the reader thread is now 
blocking waiting for the renegotiation data to arrive on the socket. But that 
renegotiation data has already been received and read by the SSL engine. So the 
thread will block indefinitely waiting for something that has already 
happened.", the question is that if the underline socket is non-blocking and 
the application is using select/poll to check the readable of SSL connection 
and then invoke the SSL_write/SSL_read call, can this deadlock still happen?

Thanks
Bob


-Original Message-
From: David Schwartz [mailto:dav...@webmaster.com] 
Sent: Monday, March 07, 2011 3:43 PM
To: openssl-users@openssl.org
Cc: Yan, Bob
Subject: Re: SSL_ERROR_WANT_READ and SSL_ERROR_WANT-WRITE question

On 3/7/2011 2:45 PM, Yan, Bob wrote:

> My question is that if my Reader thread gets a SSL_ERROR_WANT_WRITE 
> error from SSL_read function call, can my Writer thread do the 
> SSL_write operation right after the Reader's SSL_read operation?

Yes.

 > Or, if my Writer
> thread gets a SSL_ERROR_WANT_READ error from SSL_write call, can my 
> Reader thread do the SSL_read just following the Writer's SSL_write 
> operation?

Yes.

 > Basically is that ok to mix the SSL_read and SSL_write
> function by two different threads regardless the returning error code?

Yes, there is one very important caveat though -- an SSL connection has one and 
only one state. So the following sequence of operations will get you in big 
trouble:

1) Reader thread calls SSL_write, gets WANT_READ.

2) Writer thread calls SSL_read, gets WANT_READ.

3) Reader thread (not knowing what happened in step 2) calls 'select' or 
similar function in response to the WANT_READ it got in step 1 and does not 
call SSL_write again until the socket is readable.

After step 2, the state of the SSL connection is 'data must be read from the 
socket in order to read from the SSL connection'. It is an error to assume that 
the WANT_READ returned in step 1 is still valid since step 2 may have 
invalidated it.

This can cause your code to deadlock in real world situations. For example, 
supposed the SSL connection is in the process of renegotiating:

At step 1 above suppose it has sent the last thing it needed to send to 
complete the renegotiation and now it just must read the last bit of 
renegotiation data before it can continue to make further forward progress. So 
it returns WANT_READ.

At step 2 above, the engine knows it needs to read from the socket to make 
further progress, so it does. Suppose the renegotiation data has all arrived 
and it reads all of it, but there's no application data to read, so it returns 
WANT_READ.

At step 3 above, the reader thread is now blocking waiting for the 
renegotiation data to arrive on the socket. But that renegotiation data has 
already been received and read by the SSL engine. So the thread will block 
indefinitely waiting for something that has already happened.

DS

__
OpenSSL Project http://www.openssl.org
User Support Mailing Listopenssl-users@openssl.org
Automated List Manager   majord...@openssl.org


How to disable SSL/TLS Renegotiation

2011-03-07 Thread Yan, Bob
I have two questions regarding to SSL/TLS Renegotiation:

1) Can SSL/TLS Renegotiation happen automatically during the normal SSL_read 
and SSL_write operation on a SSL connection? Basically if the application 
doesn't invoke the SSL_renegotiate function, can SSL/TLS Renegotiation still 
happen automatically on a SSL connection?

2) Can the SSL/TLS Renegotiation be disabled? Such as if the peer requests the 
SSL/TLS renegotiation, the SSL_read or SSL_write will return an error but not 
SSL_ERROR_WANT_READ/WRITE?

Thanks
Bob





SSL_ERROR_WANT_READ and SSL_ERROR_WANT-WRITE question

2011-03-07 Thread Yan, Bob
Thread are two threads in my application and one thread is called Reader and 
another one is Writer. The Reader thread calls the SSL_read function to receive 
the incoming data from the SSL socket connection; and the Writer thread invokes 
the SSL_write function to send out the data to the same SSL connection. In 
order to prevent Reader and Writer thread access the same SSL connection at the 
same time, I have placed a mutex to avoid this situation.

My question is that if my Reader thread gets a SSL_ERROR_WANT_WRITE error from 
SSL_read function call, can my Writer thread do the SSL_write operation right 
after the Reader's SSL_read operation? Or, if my Writer thread gets a 
SSL_ERROR_WANT_READ error from SSL_write call, can my Reader thread do the 
SSL_read just following the Writer's SSL_write operation? Basically is that ok 
to mix the SSL_read and SSL_write function by two different threads regardless 
the returning error code?

Thank you for your time!
Bob