Verifying self-signed certificate

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Verifying self-signed certificate

iruvopenssl
Greetings,

I guess this question must have been asked quite a lot over here,
but I couldn't find any traces of it
so I guess I'll repeat it.

I can't seem to be able to verify (using 'openssl verify') -
without openssl spitting a X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT -
a server certificate that was signed with a custom-made CA even
though I pass the CA certificate using the -CAfile switch.
I've tried -purpose and also using -CApath instead of -CAfile but
to no avail.

Is this a feature, a bug or am I just doing it wrong?

Shouldn't a self-signed certificate get verified when a user
_manually_ also passes a certificate he considers trusted?

Also, is there any documentation on how SSL_CTX_set_cert_store() be
used? It seems to me that it's the correct way to validate
a self-signed certificate through the OpenSSL API.

Many thanks!

PS: Sorry, if this reaches the mailing list multiple times, I
screwed up a bit :)

______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    [hidden email]
Automated List Manager                           [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: Verifying self-signed certificate

Dr. Stephen Henson
On Mon, Nov 29, 2010, [hidden email] wrote:

> Greetings,
>
> I guess this question must have been asked quite a lot over here,
> but I couldn't find any traces of it
> so I guess I'll repeat it.
>
> I can't seem to be able to verify (using 'openssl verify') -
> without openssl spitting a X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT -
> a server certificate that was signed with a custom-made CA even
> though I pass the CA certificate using the -CAfile switch.
> I've tried -purpose and also using -CApath instead of -CAfile but
> to no avail.
>
> Is this a feature, a bug or am I just doing it wrong?
>

Impossible to tell without seeing the actual certificate and the precise
command line you use.

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                    [hidden email]
Automated List Manager                           [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: Verifying self-signed certificate

iruvopenssl
In reply to this post by iruvopenssl
On Mon, 29 Nov 2010 20:05:43 +0200 "Dr. Stephen Henson"
<[hidden email]> wrote:

>On Mon, Nov 29, 2010, [hidden email] wrote:
>
>> Greetings,
>>
>> I guess this question must have been asked quite a lot over
>here,
>> but I couldn't find any traces of it
>> so I guess I'll repeat it.
>>
>> I can't seem to be able to verify (using 'openssl verify') -
>> without openssl spitting a
>X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT -
>> a server certificate that was signed with a custom-made CA even
>> though I pass the CA certificate using the -CAfile switch.
>> I've tried -purpose and also using -CApath instead of -CAfile
>but
>> to no avail.
>>
>> Is this a feature, a bug or am I just doing it wrong?
>>
>
>Impossible to tell without seeing the actual certificate and the
>precise
>command line you use.
>
>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-
>[hidden email]
>Automated List Manager                          
>[hidden email]

Greetings!

I'm doing nothing funky:
$ openssl genrsa -des3 -out ca.key 4096
$ openssl req -new -x509 -days 365 -key ca.key -out ca.crt
$ openssl genrsa -des3 -out server.key 4096
$ openssl req -new -key server.key -out server.csr
$ openssl x509 -req -in server.csr -CA ca.crt -CAkey ca.key -
set_serial 01 -out server.crt

Giving to every option (company name, etc.) the default value:
So for example, my server.crt's issuer line is:
Issuer: C=AU, ST=Some-State, O=Internet Widgits Pty Ltd
and my ca.crt's subject line is:
Subject: C=AU, ST=Some-State, O=Internet Widgits Pty Ltd

I'm trying to verify them with something like that:
"
$ openssl verify -CAfile ca.crt server.crt
server.crt: C = AU, ST = Some-State, O = Internet Widgits Pty Ltd
error 18 at 0 depth lookup:self signed certificate
OK
"
but like I said in my original post I've tried the -purpose
-CApath etc. switches as well.

Can you reproduce this?

Thank you very much for the reply!

______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    [hidden email]
Automated List Manager                           [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: Verifying self-signed certificate

Dr. Stephen Henson
On Tue, Nov 30, 2010, [hidden email] wrote:

> On Mon, 29 Nov 2010 20:05:43 +0200 "Dr. Stephen Henson"
> <[hidden email]> wrote:
> Greetings!
>
> I'm doing nothing funky:
> $ openssl genrsa -des3 -out ca.key 4096
> $ openssl req -new -x509 -days 365 -key ca.key -out ca.crt
> $ openssl genrsa -des3 -out server.key 4096
> $ openssl req -new -key server.key -out server.csr
> $ openssl x509 -req -in server.csr -CA ca.crt -CAkey ca.key -
> set_serial 01 -out server.crt
>
> Giving to every option (company name, etc.) the default value:
> So for example, my server.crt's issuer line is:
> Issuer: C=AU, ST=Some-State, O=Internet Widgits Pty Ltd
> and my ca.crt's subject line is:
> Subject: C=AU, ST=Some-State, O=Internet Widgits Pty Ltd
>

Well that's one problem, if your certificates have the same issuer and subject
names then you'll end up with what looks like a self-signed certificate. Try
giving the server certificate different values from the CA.

If there were any extensions in the server certificate that wouldn't happen
but the command you create the server certificate with doesn't include any and
ends up creating the deprecated V1 certificate format.

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                    [hidden email]
Automated List Manager                           [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: Verifying self-signed certificate

Kyle Hamilton
In reply to this post by iruvopenssl


On Mon, Nov 29, 2010 at 3:36 PM, Dr. Stephen Henson <[hidden email]> wrote:
>
> If there were any extensions in the server certificate that wouldn't happen
> but the command you create the server certificate with doesn't include any and
> ends up creating the deprecated V1 certificate format.

Should this behavior be changed to create a V3 certificate with no extensions by default?  There isn't much call for the creation of V1 certs, and as this case shows the default behavior creates counterintuitive behavior.

-Kyle H

smime.p7s (5K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Verifying self-signed certificate

iruvopenssl
In reply to this post by iruvopenssl


On Tue, 30 Nov 2010 01:36:16 +0200 "Dr. Stephen Henson"
<[hidden email]> wrote:

>On Tue, Nov 30, 2010, [hidden email] wrote:
>
>> On Mon, 29 Nov 2010 20:05:43 +0200 "Dr. Stephen Henson"
>> <[hidden email]> wrote:
>> Greetings!
>>
>> I'm doing nothing funky:
>> $ openssl genrsa -des3 -out ca.key 4096
>> $ openssl req -new -x509 -days 365 -key ca.key -out ca.crt
>> $ openssl genrsa -des3 -out server.key 4096
>> $ openssl req -new -key server.key -out server.csr
>> $ openssl x509 -req -in server.csr -CA ca.crt -CAkey ca.key -
>> set_serial 01 -out server.crt
>>
>> Giving to every option (company name, etc.) the default value:
>> So for example, my server.crt's issuer line is:
>> Issuer: C=AU, ST=Some-State, O=Internet Widgits Pty Ltd
>> and my ca.crt's subject line is:
>> Subject: C=AU, ST=Some-State, O=Internet Widgits Pty Ltd
>>
>
>Well that's one problem, if your certificates have the same issuer
>and subject
>names then you'll end up with what looks like a self-signed
>certificate. Try
>giving the server certificate different values from the CA.
>
>If there were any extensions in the server certificate that
>wouldn't happen
>but the command you create the server certificate with doesn't
>include any and
>ends up creating the deprecated V1 certificate format.
>
>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-
>[hidden email]
>Automated List Manager                          
>[hidden email]

Heh, I didn't think of this :)

Thank you very much, it's now working!

______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    [hidden email]
Automated List Manager                           [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: Verifying self-signed certificate

Manoj
Hi,

Can you post the complete command to generate the self signed certificate , the case where the verification worked for you?

Thanks
Reply | Threaded
Open this post in threaded view
|

Re: Verifying self-signed certificate

Martin Hecht
Hi Manoj,

if you want to generate just one selfsigned
certificate, this would be the easiest:

# generate key and self signed cert with one command
openssl req -x509 -nodes -days 3650 \
 -subj '/C=DE/ST=some-state/L=somewhere/CN=example.com' \
 -newkey rsa:1024 -keyout key.pem -out cert.pem

# verify it "against itself"
openssl verify -CAfile cert.pem cert.pem

Is this what you are looking for? However,
if you want to use the demoCA built-in with
openssl (which is a strange approach for generating
selfsigned certificates) it would look like this:

# first generate a key
openssl genrsa -out key.pem 2048

# generate a request with this key
openssl req -new -key key.pem \
 -subj '/C=DE/ST=some-state/L=somewhere/O=Test/CN=example.com' \
 -out req.pem

# create the directory structures needed (see your openssl.cnf)
mkdir -p ./demoCA/newcerts
touch ./demoCA/index.txt
echo 00 > ./demoCA/serial

# issue a selfsigned certificate
openssl ca -in req.pem -keyfile key.pem -selfsign -out file.pem

# verify it
openssl verify -CAfile file.pem file.pem

# or you could have a look at the one which ends up in the
# directory where newly issued certificates are stored
openssl verify -CAfile file.pem demoCA/newcerts/00.pem

# look at the file in text form, just to complete the list
# of widely used commands :-)
openssl x509 -in file.pem -noout -text

PS: I have tested this with OpenSSL 0.9.8k in Ubuntu 10.04 LTS

best regards,
Martin

______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    [hidden email]
Automated List Manager                           [hidden email]