what does X509_STORE_get1_crls() return and how?

2011-03-17 Thread Jeff Saremi
If I call X509_STORE_get1_crls(ctx, nm) with nm being the issuer name,
the method is supposed to return a list of CRL's with that issuer name.
How does it do that when it comes to CRLs issued by a CRL issuer
authorized by the original issuer?
Does it use Authority Key Identifier?

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


Re: Need Help with Programmatic Downloading+Checking of CRLs

2011-03-17 Thread Jeff Saremi
So as per previous posts, I implemented lookup_crl().
Now one of the major problems is what do I return from this method, if
the certificate has no CRL distribution points!
Returning an empty stack causes get_crl_delta() to fail.
Is there a flag that I can setup to let this cert be excluded from CRL
checking?
Is that something I should be doing in lookup_crl? Or should the
framework be smart enough not to even ask me for a CRL in this case?

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


fatal handshake failure

2011-03-17 Thread Zara Faisal
I've written a code for ssl server that supports multiple clients but if any
1 of the clients can't authenticate the server ,the client sends the
following alert message and causes the server to exit, including closing all
existing connections the server may have with other clients.

*error on client side:*
3573:error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate
verify failed:s3_clnt.c:894:

*error on server side:*
3065772944:error:14094418:SSL routines:SSL3_READ_BYTES:tlsv1 alert unknown
ca:s3_pkt.c:1057:SSL alert number 48



How can i prevent a handshake failure alert from closing all the other
server connections

thanx


Double-Extensions in X509 Cert

2011-03-17 Thread Gusty

Hi i have a problem.

I create Certificates using openssl: 
I try to use OCSP-Verifiaction and so i created Extensions:

x509 -req -CAkey ' . $pathToPrivKey . ' -set_serial ' . $serial . ' -in ' 

. $csrFile . ' -days ' . $days . ' -out ' . $pathToCert 
. ' -extfile ' .
$this-cfgPath . ' -extensions content_cert -signkey ' . $pathToPrivKey . '
-CA '. PATH_AUTHOR_CERT_DIR . $authorCertName;

My Problem is: 
I get an Certificate, but openSSL creates the Extensions twice, which
violates X.509 http://old.nabble.com/file/p31171410/openssl.cfg openssl.cfg 
RFC:

X509v3 extensions:
X509v3 Basic Constraints:
CA:FALSE
X509v3 Subject Key Identifier:
89:C1:6F:32:21...CA:0E:AD:EF:2B:53:DF:3D
X509v3 Authority Key Identifier:
keyid:89:C1:6FAD:EF:2B:53:DF:3D
Authority Information Access:
OCSP - URI:http://localhost:
X509v3 Basic Constraints:
CA:FALSE
X509v3 Subject Key Identifier:
89:C1:6F:32:21...AD:EF:2B:53:DF:3D
X509v3 Authority Key Identifier:
keyid:89:C1:6FEF:2B:53:DF:3D
Authority Information Access:
OCSP - URI:http://localhost:

I Attached my Config File for debugging
-- 
View this message in context: 
http://old.nabble.com/Double-Extensions-in-X509-Cert-tp31171410p31171410.html
Sent from the OpenSSL - User mailing list archive at Nabble.com.
__
OpenSSL Project http://www.openssl.org
User Support Mailing Listopenssl-users@openssl.org
Automated List Manager   majord...@openssl.org


data size issue with SSL_read( ) / SSL_write

2011-03-17 Thread ikuzar
Hello,

In my programm, client send HELLO message to server.

1)
---
SSL_write is encapsulated in MY_send( ) function like this :

MY_send(MY_cn sd, const char* data, size_t len) {
   ret = SSL_write(socki-ssl, data, len);
}

and MY_send is encapsuled in MYsend like this :

int MYApi::MYsend(SIP_cn sd, const std::string data)
{
  return MY_send(sd, data.data(), data.size());

}

in python code, I call :

api.MYsend(sock, HELLO)

2)
---
SSL_read is encapsulated in MY_recv( ) function like this :

MY_recv(MY_cn sd, char* buf,  size_t* len, unsigned int flags, unsigned int
timeout) {
 SSL_read(socki-ssl, buf, *len);
}

and MY_recv is encapsuled in MYrecv like this :

int MYApi::MYrecv(MY_cn sd, const std::string data)
{

  strresult *r = new strresult;
  const size_t L=8*1024;
  size_t  len = L;
  char buf[L];

  r-first = MY_recv(sd, buf, len, flags, timeout);
  if (!r-first)
r-second.assign(buf, len);
  return r;
}

in python code, I call
err,data = api.MYrecv(cn, 0, 0)


The problem :

when I print data, I have got :
HELLO��y0�y
0�y��y
i`�0�y
������L���L��-M
etc...
instead of
HELLO.

in MYrecv, when I make L = 5, it works

what should I do to read just the right size so that when I print I get
HELLO, GOODBYE, etc ... and not HELLO��y0�y,  GOODBYE��y0�y etc ...
thanks for your help


Re: data size issue with SSL_read( ) / SSL_write

2011-03-17 Thread David Schwartz

On 3/17/2011 5:00 AM, ikuzar wrote:


The problem :

when I print data, I have got :
HELLO��y0�y
0�y��y
i`�0�y
������L���L��-M
etc...
instead of
HELLO.

in MYrecv, when I make L = 5, it works

what should I do to read just the right size so that when I print I get
HELLO, GOODBYE, etc ... and not HELLO��y0�y,  GOODBYE��y0�y etc ...
thanks for your help


You made two common rookie mistakes:

1) Your MY_recv function is totally broken. It ignores the return value 
of SSL_read, so you have no idea how many bytes you received. So even 
though you received five bytes, you are printing god only knows how many 
bytes.


2) You forgot to implement a protocol. Who or what said that those five 
bytes you received should be printed? You need to specify and implement 
an application protocol on top of SSL. Otherwise, you will continue to 
make mistakes like '1' above. With a protocol, you'd know how to 
determine when you had a complete application-level message. Without 
one, it is impossible to do it right because there is no such thing as 
'right'.


DS

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


Handling Indirect CRL Issuer

2011-03-17 Thread Jeff Saremi
Does anyone have an example of how an indirect CRL issuer is handled?
This is my understanding of needs to be done.
If at least someone could verify that, I'd be really appreciative:

1. download the CRL
2. If not indirect, handle as usual (let's pretend for now that we know
how to handle these in OpenSSL)
3. If Indirect flag is set, check Authority Information Access.
(possibly using something like:
AUTHORITY_INFO_ACCESS *info = (AUTHORITY_INFO_ACCESS*)
X509_CRL_get_ext_d2i(crl, NID_info_access, NULL, NULL);)
4. Download the issuer's certificate using the URL above.
5. Add the cert to the store? (using X509_STORE_add_cert()?)

Any other steps?

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


Re: what does X509_STORE_get1_crls() return and how?

2011-03-17 Thread Dr. Stephen Henson
On Wed, Mar 16, 2011, Jeff Saremi wrote:

 If I call X509_STORE_get1_crls(ctx, nm) with nm being the issuer name,
 the method is supposed to return a list of CRL's with that issuer name.
 How does it do that when it comes to CRLs issued by a CRL issuer
 authorized by the original issuer?
 Does it use Authority Key Identifier?
 

Well that issuer name is a guide for the simplest case. For indirect CRLs it
can get more complex. 

In general you return any CRLs you think might be relevant for the current
certificate and return them. It doesn't matter if some are incorrect (wrong
issuer) or not current, they will be scored and the most appropriate one used.

You might for example download CRLs from CRLDP in the current certificate
(possibly cached) and return all of them.

Steve.
--
Dr Stephen N. Henson. OpenSSL project core developer.
Commercial tech support now available see: http://www.openssl.org
__
OpenSSL Project http://www.openssl.org
User Support Mailing Listopenssl-users@openssl.org
Automated List Manager   majord...@openssl.org


Re: Need Help with Programmatic Downloading+Checking of CRLs

2011-03-17 Thread Dr. Stephen Henson
On Wed, Mar 16, 2011, Jeff Saremi wrote:

 So as per previous posts, I implemented lookup_crl().
 Now one of the major problems is what do I return from this method, if
 the certificate has no CRL distribution points!
 Returning an empty stack causes get_crl_delta() to fail.
 Is there a flag that I can setup to let this cert be excluded from CRL
 checking?
 Is that something I should be doing in lookup_crl? Or should the
 framework be smart enough not to even ask me for a CRL in this case?
 

There are other out of band mechanisms where a CRL might be available but
not mentioned in a CRLDP. OpenSSL has no way of telling what those might be
and if the absence is really an error or not.

The best you can do is trap the issuer error in the verify callback and ignore
it if appropriate.

Steve.
--
Dr Stephen N. Henson. OpenSSL project core developer.
Commercial tech support now available see: http://www.openssl.org
__
OpenSSL Project http://www.openssl.org
User Support Mailing Listopenssl-users@openssl.org
Automated List Manager   majord...@openssl.org


Re: data size issue with SSL_read( ) / SSL_write

2011-03-17 Thread luiz
Hi

does your server send \r\n with hello?

i read byte by byte until i found an \r\n

Regards
Luiz

 Hello,

 In my programm, client send HELLO message to server.

 1)
 ---
 SSL_write is encapsulated in MY_send( ) function like this :

 MY_send(MY_cn sd, const char* data, size_t len) {
ret = SSL_write(socki-ssl, data, len);
 }

 and MY_send is encapsuled in MYsend like this :

 int MYApi::MYsend(SIP_cn sd, const std::string data)
 {
   return MY_send(sd, data.data(), data.size());

 }

 in python code, I call :

 api.MYsend(sock, HELLO)

 2)
 ---
 SSL_read is encapsulated in MY_recv( ) function like this :

 MY_recv(MY_cn sd, char* buf,  size_t* len, unsigned int flags, unsigned
 int
 timeout) {
  SSL_read(socki-ssl, buf, *len);
 }

 and MY_recv is encapsuled in MYrecv like this :

 int MYApi::MYrecv(MY_cn sd, const std::string data)
 {

   strresult *r = new strresult;
   const size_t L=8*1024;
   size_t  len = L;
   char buf[L];

   r-first = MY_recv(sd, buf, len, flags, timeout);
   if (!r-first)
 r-second.assign(buf, len);
   return r;
 }

 in python code, I call
 err,data = api.MYrecv(cn, 0, 0)


 The problem :

 when I print data, I have got :
 HELLO��y0�y
 0�y��y
 i`�0�y
 ������L���L��-M
 etc...
 instead of
 HELLO.

 in MYrecv, when I make L = 5, it works

 what should I do to read just the right size so that when I print I get
 HELLO, GOODBYE, etc ... and not HELLO��y0�y,
 GOODBYE��y0�y etc ...
 thanks for your help



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


Re: Handling Indirect CRL Issuer

2011-03-17 Thread Dr. Stephen Henson
On Thu, Mar 17, 2011, Jeff Saremi wrote:

 Does anyone have an example of how an indirect CRL issuer is handled?
 This is my understanding of needs to be done.
 If at least someone could verify that, I'd be really appreciative:
 
 1. download the CRL
 2. If not indirect, handle as usual (let's pretend for now that we know
 how to handle these in OpenSSL)
 3. If Indirect flag is set, check Authority Information Access.
 (possibly using something like:
 AUTHORITY_INFO_ACCESS *info = (AUTHORITY_INFO_ACCESS*)
 X509_CRL_get_ext_d2i(crl, NID_info_access, NULL, NULL);)
 4. Download the issuer's certificate using the URL above.
 5. Add the cert to the store? (using X509_STORE_add_cert()?)
 

First thing: do you need to worry about indirect CRLs: they are pretty rare
outside compliance tests. Indirect CRLs are not supported unless an explicit
flag is set btw: this is due to unresolved security issues in the standards.

Steve.
--
Dr Stephen N. Henson. OpenSSL project core developer.
Commercial tech support now available see: http://www.openssl.org
__
OpenSSL Project http://www.openssl.org
User Support Mailing Listopenssl-users@openssl.org
Automated List Manager   majord...@openssl.org


Re: data size issue with SSL_read( ) / SSL_write

2011-03-17 Thread ikuzar
Why do we expect \r\n ? why not \0 ?

2011/3/17 l...@xharbour.com.br

 Hi

 does your server send \r\n with hello?

 i read byte by byte until i found an \r\n

 Regards
 Luiz

  Hello,
 
  In my programm, client send HELLO message to server.
 
  1)
 
 ---
  SSL_write is encapsulated in MY_send( ) function like this :
 
  MY_send(MY_cn sd, const char* data, size_t len) {
 ret = SSL_write(socki-ssl, data, len);
  }
 
  and MY_send is encapsuled in MYsend like this :
 
  int MYApi::MYsend(SIP_cn sd, const std::string data)
  {
return MY_send(sd, data.data(), data.size());
 
  }
 
  in python code, I call :
 
  api.MYsend(sock, HELLO)
 
  2)
 
 ---
  SSL_read is encapsulated in MY_recv( ) function like this :
 
  MY_recv(MY_cn sd, char* buf,  size_t* len, unsigned int flags, unsigned
  int
  timeout) {
   SSL_read(socki-ssl, buf, *len);
  }
 
  and MY_recv is encapsuled in MYrecv like this :
 
  int MYApi::MYrecv(MY_cn sd, const std::string data)
  {
 
strresult *r = new strresult;
const size_t L=8*1024;
size_t  len = L;
char buf[L];
 
r-first = MY_recv(sd, buf, len, flags, timeout);
if (!r-first)
  r-second.assign(buf, len);
return r;
  }
 
  in python code, I call
  err,data = api.MYrecv(cn, 0, 0)
 
 
  The problem :
 
  when I print data, I have got :
  HELLO��y 0�y
  0�y ��y
   i`�   0�y
  ���   ���L���L��-M
  etc...
  instead of
  HELLO.
 
  in MYrecv, when I make L = 5, it works
 
  what should I do to read just the right size so that when I print I get
  HELLO, GOODBYE, etc ... and not HELLO��y 0�y ,
  GOODBYE��y 0�y  etc ...
  thanks for your help
 


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



Re: data size issue with SSL_read( ) / SSL_write

2011-03-17 Thread David Schwartz

On 3/17/2011 6:40 AM, ikuzar wrote:


Why do we expect \r\n ? why not \0 ?


That's why you need to implement a protocol.

DS

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


Re: data size issue with SSL_read( ) / SSL_write

2011-03-17 Thread ikuzar
I am confused.
When I used a simple c++ program which uses SSL functions for the first
time, I need not implement  a protocol. when I tell SSL_write( ) to send 5
bytes and tell SSL_read( ) to read 10 bytes, the last reads 5 bytes ! (
doesn't it ? am I wrong ? I assume SSL reads expect \0 then it stop
reading). Anyway, when SSL_write( ) sends TEST, SSL_read( ) reads TEST
and not TEST��y 0�y ...

Now, in my python program, the difference between my simple c++ program is
that, I retrieve a string ( a_string.data( ), a_string.size( ) ) and tell
SLL_write through my API to send this string.



2011/3/17 David Schwartz dav...@webmaster.com

 On 3/17/2011 6:40 AM, ikuzar wrote:

  Why do we expect \r\n ? why not \0 ?


 That's why you need to implement a protocol.

 DS


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



Re: Handling Indirect CRL Issuer

2011-03-17 Thread Jeff Saremi
It looks like we need to support indirect CRL Issuers at least for CRL's
issued for ourselves.

I have done most of the work. It looks I don't quite know how to
generate CRLs with the indirect CRL issuer or I don't know how to
generate the CRL issuer's certificate using the root certificate.

So I have added the CRL issuer's cert to the trusted ones. But when I'm
trying to use the CRL i get stopped here:


crl_akid_check()
{
...
  if(X509_check_akid()
// this is where if fails


and inside X509_check_akid()

...
/* Check key ids (if present) */
if(akid-keyid  issuer-skid 
 ASN1_OCTET_STRING_cmp(akid-keyid, issuer-skid) )
return X509_V_ERR_AKID_SKID_MISMATCH;


There's definitely something I don't know about AKID's and how to set
them properly.

To help you out here are the certificates and CRLs (i have masked some
fields):

*** Our ROOT cert *
Certificate:
Data:
Version: 3 (0x2)
Serial Number: 0 (0x0)
Signature Algorithm: sha256WithRSAEncryption
Issuer: CN=TestMoregaRootCA, C=CA, O=TestMorega
Validity
Not Before: Jun  8 00:29:30 2010 GMT
Not After : Jun  3 00:29:30 2030 GMT
Subject: CN=TestMoregaRootCA, C=CA, O=TestMorega
Subject Public Key Info:
Public Key Algorithm: rsaEncryption
Public-Key: (2048 bit)
Modulus:
...
6c:68:70:a5:c1:7e:5e:b8:e4:82:ff:6d:c6:3
X509v3 extensions:
X509v3 Subject Key Identifier:
70:8F:22:BC:D7:55:20:6E:00:D7:3A:D3:70:40:F5:49:91:20:90:60
X509v3 Authority Key Identifier:

keyid:70:8F:22:BC:D7:55:20:6E:00:D7:3A:D3:70:40:F5:49:91:20:90:60
DirName:/CN=TestMoregaRootCA/C=CA/O=TestMorega
serial:00
X509v3 Key Usage: critical
Certificate Sign, CRL Sign
X509v3 Basic Constraints: critical
CA:TRUE



 CRL Issuer Cert issued by the root 
Certificate:
Data:
Version: 3 (0x2)
Serial Number: 20 (0x14)
Signature Algorithm: sha256WithRSAEncryption
Issuer: CN=TestMoregaRootCA, C=CA, O=TestMorega
Validity
Not Before: Mar 16 18:31:26 2011 GMT
Not After : Mar 11 18:31:26 2031 GMT
Subject: C=CA, O=TestMorega, CN=TestMoregaCRLIssuer
Subject Public Key Info:
Public Key Algorithm: rsaEncryption
Public-Key: (1024 bit)
Modulus:
...
1c:52:ce:81:2c:50:52:30:43
Exponent: 65537 (0x10001)
X509v3 extensions:
X509v3 Basic Constraints: critical
CA:FALSE
X509v3 Subject Key Identifier:
7F:AC:68:90:EE:3C:8B:7B:6D:0E:A0:71:68:BE:57:D0:45:42:E9:C6
X509v3 Authority Key Identifier:

keyid:70:8F:22:BC:D7:55:20:6E:00:D7:3A:D3:70:40:F5:49:91:20:90:60
DirName:/CN=TestMoregaRootCA/C=CA/O=TestMorega
serial:00
X509v3 Key Usage: critical
Digital Signature, CRL Sign


 A sample CRL issued by the Indirect CRL Issuer 
Certificate Revocation List (CRL):
Version 2 (0x1)
Signature Algorithm: sha256WithRSAEncryption
Issuer: /C=CA/O=TestMorega/CN=TestMoregaCRLIssuer
Last Update: Mar 17 12:56:55 2011 GMT
Next Update: Apr 16 12:56:55 2011 GMT
CRL extensions:
X509v3 Authority Key Identifier:

keyid:7F:AC:68:90:EE:3C:8B:7B:6D:0E:A0:71:68:BE:57:D0:45:42:E9:C6
DirName:/CN=TestMoregaRootCA/C=CA/O=TestMorega
serial:14
X509v3 Issuing Distrubution Point: critical
Full Name:
  URI:http://localhost/
Indirect CRL
Authority Information Access:
CA Issuers - URI:http://localhost/crlissuer.cer
__
OpenSSL Project http://www.openssl.org
User Support Mailing Listopenssl-users@openssl.org
Automated List Manager   majord...@openssl.org


How can I make CertificateIssuer extension show up in CRL Entries?

2011-03-17 Thread Jeff Saremi
I'm generating my CRLs using openssl ca command.  In the CRL entry
extension list, I can see X509v3 CRL Reason Code but I'd like to also
include the certificate issuer. (I think this is needed if an issuer
does the issuing indirectly for another CA).

Is there a command line option of config entry for that?
thanks
jeff
__
OpenSSL Project http://www.openssl.org
User Support Mailing Listopenssl-users@openssl.org
Automated List Manager   majord...@openssl.org


Re: How can I make CertificateIssuer extension show up in CRL Entries?

2011-03-17 Thread Dr. Stephen Henson
On Thu, Mar 17, 2011, Jeff Saremi wrote:

 I'm generating my CRLs using openssl ca command.  In the CRL entry
 extension list, I can see X509v3 CRL Reason Code but I'd like to also
 include the certificate issuer. (I think this is needed if an issuer
 does the issuing indirectly for another CA).
 
 Is there a command line option of config entry for that?

That isn't currently supported in the ca utility. 

Steve.
--
Dr Stephen N. Henson. OpenSSL project core developer.
Commercial tech support now available see: http://www.openssl.org
__
OpenSSL Project http://www.openssl.org
User Support Mailing Listopenssl-users@openssl.org
Automated List Manager   majord...@openssl.org


Re: Handling Indirect CRL Issuer

2011-03-17 Thread Dr. Stephen Henson
On Thu, Mar 17, 2011, Jeff Saremi wrote:

 It looks like we need to support indirect CRL Issuers at least for CRL's
 issued for ourselves.
 

If you don't mind my asking, why do you think you need to do that?

I'm curious because so far you're the only person who has needed that
functionality and I'm wondering if an alternative solution might be more
appropriate.

Steve.
--
Dr Stephen N. Henson. OpenSSL project core developer.
Commercial tech support now available see: http://www.openssl.org
__
OpenSSL Project http://www.openssl.org
User Support Mailing Listopenssl-users@openssl.org
Automated List Manager   majord...@openssl.org


Re: data size issue with SSL_read( ) / SSL_write

2011-03-17 Thread David Schwartz

On 3/17/2011 7:43 AM, ikuzar wrote:


I am confused.
When I used a simple c++ program which uses SSL functions for the first
time, I need not implement  a protocol. when I tell SSL_write( ) to send
5 bytes and tell SSL_read( ) to read 10 bytes, the last reads 5 bytes !
( doesn't it ? am I wrong ? I assume SSL reads expect \0 then it stop
reading).


No, that's not what it does. When you call SSL_read, it gives you 
however many bytes it has available at that time, up to a maximum of the 
number of bytes you asked for. If no data is available and the socket is 
blocking, it blocks until it has some data to give you and gives you 
that much.


It has no way to know when to stop reading. That's *your* job when you 
implement the protocol.


TCP and SSL are byte stream protocols that do not preserve message 
boundaries. If you call SSL_write and send 10 bytes, you should 
completely expect that you might call SSL_read 10 times and get 1 byte 
each time or you might get all 10 bytes in a one read. Or you might get 
5 bytes and then 5 more bytes. It's a byte stream -- nothing 'glues' the 
bytes together.


If you want to end a 'message' with a \0 and read until you read a \0, 
then write code to do that. YOU MUST IMPLEMENT A PROTOCOL ON TOP OF SSL.


DS

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


RE: Question regarding PKCS7_verify

2011-03-17 Thread prk j

Hi,
 
I am having trouble again with verifying certs in PKCS7 structure.
 
Setting purpose to 'any' using openssl api worked for very first time.
From second run onwards it keep throwing 
errror:0B086079:lib(11):fun(134):reason(121)
 
I believe the error is - x509 certificate 
routines:X509_STORE_CTX_purpose_inherit:unknown purpose id.
 
But on openssl commans line it verifies fine.
 
I could not figure out what the problem is here. Could someone tell me what 
wrong with setting purpose to 'any'?
 
Any help is greatly appreciated.
 
Thanks,
Prkj
 


From: prkj...@hotmail.com
To: openssl-users@openssl.org
Subject: RE: Question regarding PKCS7_verify
Date: Thu, 10 Mar 2011 13:49:08 -0800




Thanks for quick response.

Adding -purpose any surely works.

I had to change my code to get certs from PKCS7 structure and create X509 store 
context and set purpose to X509_PURPOSE_ANY.
This approach works.

But was wondering if it is problem with certificates or with openssl API itself.
Currently openssl version I am using is 0.9.8g. 

I remember it was working with 0.9.7. Or it never checked or ignored purpose.

Thanks for your help.
Prkj


 Date: Thu, 10 Mar 2011 22:05:03 +0100
 From: st...@openssl.org
 To: openssl-users@openssl.org
 Subject: Re: Question regarding PKCS7_verify
 
 On Thu, Mar 10, 2011, prk j wrote:
 
  
  Hi,
  
  I am new at using openssl API's. Here is my situation.
  
  I have following set of certificates with X509 extensions defined for code 
  signing in PKCS#7 format.
  
  Root CA - Key usage (critical): Certificate Sign, CRL Sign
  CVC Sub- CA - Key usage (critical): Certificate Sign, CRL Sign
  CVC cert - Key usage (critical): Digital Signature, Key Encipherment. 
  Extended Key Usage (critical): Code Signing
  
  PKCS#7 signature includes CVC Sub-CA and CVC certs. So when I verify the 
  signature using PKCS7_verify() I am getting 
  error: unsupported certificate purpose.
  
  I tried openssl smime command line utility. It fails with same error. 
  Following is the command I am using:
  
  openssl smime -verify -CAfile Root-CA -inform PEM -in pk7blob -content 
  data-signed
  Verification failure
  3420:error:21075075:PKCS7 routines:PKCS7_verify:certificate verify 
  error:pk7_smi
  me.c:231:Verify error:unsupported certificate purpose
  
  If I use '-noverify', signature itself is verified successfully.
  
  I am not sure why it is failing even Code Signing is mentioned in 
  Extended Key usage.
  
  Any help is appreciated.
  
 
 It is failing because the smime utility by default checks for email siging and
 the extended key usage is critical and doesn't support that.
 
 See if adding -purpose any to the command line helps.
 
 Steve.
 --
 Dr Stephen N. Henson. OpenSSL project core developer.
 Commercial tech support now available see: http://www.openssl.org
 __
 OpenSSL Project http://www.openssl.org
 User Support Mailing List openssl-users@openssl.org
 Automated List Manager majord...@openssl.org
  

timestamping DETACHED SMIME

2011-03-17 Thread Christian Weber

Hi all,

due to the new streaming support in OpenSSL 1.0.0d the calculations for
completing the signature are delayed now. I guess streaming support was
meant especially for DETACHED SMIME, but complicates the handling.

The PKCS7_sign() routine still does most of the initialization on the p7
structure, but finalizing (i.e. call of PKCS7_final()) is intenionally delayed.

Currently PKCS7_final() is called in the last line of SMIME_write_PKCS7(),
which is (or at least previously was) the SMIME output routine.

Due to this delay it seems difficult to add a timestamp over the signature
which needs the signature value, of course.

Does anyone know how to interfere the output generation to add an unsigned
attribute (like a timestamp) when the signature is already created, but not
yet written to the output?

Alternatively the finalization might be performed within or right after
PKCS7_sign(), just as in the old manner, but then the contents happens to
be processed twice (hash calculation and signature processing) when the
data is written, because the output routine heavily depends on the new
auxiliary asn1 callback.

Any hint? What am i missing?

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


RE: verify trusted certificates: ts response

2011-03-17 Thread Dave Thompson
   From: owner-openssl-us...@openssl.org On Behalf Of Yessica De
Ascencao
   Sent: Wednesday, 16 March, 2011 16:23

   How I can verify a document that was signed with a certificate of
level three.
   That is, I have a Root CA, then a certification authority and
finally 
 the certificate whichsigned the document.
   How I can do to check the list of trusted certificates.

Actually you're verifying a timestamped signature, not just a signature; 
the principles are similar but the details are different.

   This is because I have a Root CA that issued a CERTIFIED for TSA,
and 
 the TSAissued a certificate for a TSS which is implemented with openTSA.
When applied

   . / openssl ts-verify-data-file-in response9.tsr
ACstamping-SHA256.pem cafile

That's bogus and can't possibly have done what you say. You must mean 
  ./openssl ts -verify -data file -in rspfile -CAfile cafile 
(assuming openssl, or a link to it, is in your data directory; 
that's usually not best practice, although the program doesn't mind).
Spacing, presence or absence of hyphens, and capitalization are all
critical.

   throws ... ts_rsp_verify.c:246: unable to get issuer certificate

Concatenate (at least) those three (PEM) certs into one file 
and give that to -CAfile, or put them as separate (PEM) files 
in a directory *with hashlinks* and give that to -CApath.
I think it also works to use a combination, but that's confusing.



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


RE: how to desable data compression

2011-03-17 Thread Dave Thompson
   From: owner-openssl-us...@openssl.org On Behalf Of ikuzar
   Sent: Wednesday, 16 March, 2011 11:21
(topposting fixed)
   2011/3/15 Dave Thompson dthomp...@prinpay.com

   Option SSL_OP_NO_COMPRESSION is commented as
   /* Don't use compression even if supported */
   and is used in what looks like the right places.

   Could you tell me how to use this option ? in which function ? 
   I found something like below in the internet 
 ( I did not find on OpenSSL website )

   #ifndef OPENSSL_NO_COMP
   if (!(s-options  SSL_OP_NO_COMPRESSION))

   len += SSL3_RT_MAX_COMPRESSED_OVERHEAD;

That's in the openssl source, specifically ssl/s3_both.c .
There are several other uses in s3_ code and one in s23_clnt.c ;
that's what I meant by looks like the right places.

You don't write that. If you have downloaded the source 
and built it, just look in your source tree. If you haven't 
you can download the source and just untar it and look at it, 
without actually building it. But judging from the level of 
your questions I doubt you're ready to understand it.

All SSL_OP_ options are set with SSL_CTX_set_options before creating 
the SSL object from the CTX object, and/or SSL_set_options afterward. 
'man SSL_set_options' if on Unix, although this particular option 
seems to have been missed in the documentation.

   but I do not know how to write in my source code. My source code is
very simple :
  cli_meth = TLSv1_method();
  cli_ctx = SSL_CTX_new(cli_meth);

so either do SSL_CTX_set_options here 

  SSL *cli_ssl = SSL_new(cli_ctx);
  SSL_set_fd(cli_ssl, s_cli)

or do SSL_set_options here (after the SSL_new but before the SSL_connect) 

  SSL_connect(cli_ssl)
  etc ...





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


Error while verifying X509 certificate

2011-03-17 Thread prk j

Hi,

I have following set of certificates with X509 extensions defined for code 
signing in PKCS7 format.

Root CA - Key usage (critical): Certificate Sign, CRL Sign
CVC Sub-CA - Key usage (critical): Certificate Sign, CRL Sign
CVC cert - Key usage(critical): Digital Signature, Key Encipherment. Extended 
Key Usage(critical): Code Sigining

PKCS#7 signature includes CVC sub-CA and CVC certs. When I verify the signature 
using PKCS7_verify() I am getting
error:  unsupported certificate purpose

As a work-around suggested by Dr.Stephen I tried setting purpose to any and it 
works fine using following command line:

openssl smime -verify -CAfile Root-CA -purpose any -inform PEM -in pk7blob 
-content data-signed

But fails when using Openssl API's and the error is 
X509_STORE_CTX_purpose_inherit: unknown purpose id.

Following is the code snippet. Most of it is taken from PKCS7_verify() itself 
in pkcs7_smime.c

void my_verify_api(PKCS7 *pkcs7, unsigned char *signed_data, int s_len)
{
/* Root CA */
static unsigned char my_root_ca[900]={..};
BIO*bio_t;

const unsigned char *der_cert = my_root_ca;
X509_STORE  *cert_store = NULL;
X509  *x509 = NULL;

STACK_OF(X509)*signers;
X509*signer;
X509_STORE_CTXcert_ctx;
inti, k, num_signers;

if (!bio_t = BIO_new_mem_buf((void *)signed_data, s_len))) {
printf(BIO_new_mem_buf failed\n\n);
goto end;
}
OpenSSL_add_all_algorithms();

x509 = d2i_X509(NULL, der_cert, sizeof(my_root_ca));

if (x509 == NULL) {
printf(x509 is NULL.\n);
goto end;
}

cert_store=X509_STORE_new();
if (cert_store == NULL) {
printf(Failed to create new cert store using X509_STORE_new().\n);
goto end;
}

X509_STORE_add_cert(cert_store,x509);

signers = PKCS7_get0_signers(pkcs7, NULL, 0);

if (!signers) {
printf(Error getting signers--\n);
goto end;
}
num_signers = sk_X509_num(signers);
printf(num_signers: %d\n, num_signers);

for (k = 0; k  num_signers; k++) {
signer = sk_X509_value(signers, k);
if (!X509_STORE_CTX_init(cert_ctx, cert_store, signer, 
pkcs7-d.sign-cert)) {
printf(X509_STORE_CTX_init failed.\n);
sk_X509_free(signers);
goto end;
}

X509_STORE_CTX_set_purpose(cert_ctx, X509_PURPOSE_ANY);

i = X509_verify_cert(cert_ctx);

X509_STORE_CTX_cleanup(cert_ctx);
if (i = 0) {
unsigned long e;
const char *file = NULL, *data = NULL;
int line, flgs;

while ((e = ERR_get_error_line_data(file, line, data, flgs))) {
printf(Error: %d\nError String: %s\n, e, ERR_error_string(e, 
NULL));
if (data) {
printf(data: %s\n, data);
}
}
ERR_clear_error();
sk_X509_free(signers);
goto end;
} else {
printf(Certificate got verified--\n\n);
}
}
sk_X509_free(signers);

end:
if (x509 != NULL) {
X509_free(x509);
}
if (cert_store != NULL) {
X509_STORE_free(cert_store);
}
if (bio_t) {
BIO_flush(bio_t);
BIO_free_all(bio_t);
}
EVP_cleanup();
}

Am I doing something wrong here?

Any help is appreciated.

Thanks,
Prkj