# virtual mailhost certificate problem

## d99ma

Hello

I'm trying to follow the Virtual Mailhosting System with Postfix Guide but I'm stuck on step 5: SSL Certs for Postfix and Apache.

The instructions are as follows:

```

# cd /etc/ssl/

# nano -w openssl.cnf

// Change the following default values for your domain:

countryName_default

stateOrProvinceName_default

localityName_default

0.organizationName_default

commonName_default

emailAddress_default.

// If the variables are not already present, just add them in a sensible place.

# cd misc

# nano -w CA.pl

// We need to add -nodes to the # create a certificate and

// #create a certificate request code in order to let our new ssl

// certs be loaded without a password. Otherwise when you

// reboot your ssl certs will not be available.

# create a certificate

system ("$REQ -new -nodes -x509 -keyout newreq.pem -out newreq.pem $DAYS");

# create a certificate request

system ("$REQ -new -nodes -keyout newreq.pem -out newreq.pem $DAYS");

      

# ./CA.pl -newca

# ./CA.pl -newreq

# ./CA.pl -sign

# cp newcert.pem /etc/postfix

# cp newreq.pem /etc/postfix

# cp demoCA/cacert.pem /etc/postfix

// Now we do the same thing for apache

# openssl req -new > new.cert.csr

# openssl rsa -in privkey.pem -out new.cert.key

# openssl x509 -in new.cert.csr -out new.cert.cert -req -signkey new.cert.key -days 365

// Just leave the resulting certificates here for now.

// We'll install them after Apache is installed.

```

But on the step

```
# ./CA.pl -sign
```

I recieve the following error:

```

Using configuration from /etc/ssl/openssl.cnf

unable to load CA private key

10712:error:0E06D06C:configuration file routines:NCONF_get_string:no value:conf_lib.c:329:group=CA_default name=unique_subject

10712:error:0906D06C:PEM routines:PEM_read_bio:no start line:pem_lib.c:637:Expecting: ANY PRIVATE KEY

Signed certificate is in newcert.pem

```

What is wrong?

/Martin

```

#

# OpenSSL example configuration file.

# This is mostly being used for generation of certificate requests.

#

# This definition stops the following lines choking if HOME isn't

# defined.

HOME                    = .

RANDFILE                = $ENV::HOME/.rnd

# Extra OBJECT IDENTIFIER info:

#oid_file               = $ENV::HOME/.oid

oid_section             = new_oids

# To use this configuration file with the "-extfile" option of the

# "openssl x509" utility, name here the section containing the

# X.509v3 extensions to use:

# extensions            =

# (Alternatively, use a configuration file that has only

# X.509v3 extensions in its main [= default] section.)

[ new_oids ]

# We can add new OIDs in here for use by 'ca' and 'req'.

# Add a simple OID like this:

# testoid1=1.2.3.4

# Or use config file substitution like this:

# testoid2=${testoid1}.5.6

####################################################################

[ ca ]

default_ca      = CA_default            # The default ca section

####################################################################

[ CA_default ]

dir             = ./demoCA              # Where everything is kept

certs           = $dir/certs            # Where the issued certs are kept

crl_dir         = $dir/crl              # Where the issued crl are kept

database        = $dir/index.txt        # database index file.

#unique_subject = no                    # Set to 'no' to allow creation of

                                        # several ctificates with same subject.

new_certs_dir   = $dir/newcerts         # default place for new certs.

certificate     = $dir/cacert.pem       # The CA certificate

serial          = $dir/serial           # The current serial number

#crlnumber      = $dir/crlnumber        # the current crl number

                                        # must be commented out to leave a V1 CRL

crl             = $dir/crl.pem          # The current CRL

private_key     = $dir/private/cakey.pem # The private key

RANDFILE        = $dir/private/.rand    # private random number file

x509_extensions = usr_cert              # The extentions to add to the cert

# Comment out the following two lines for the "traditional"

# (and highly broken) format.

name_opt        = ca_default            # Subject Name options

cert_opt        = ca_default            # Certificate field options

# Extension copying option: use with caution.

# copy_extensions = copy

# Extensions to add to a CRL. Note: Netscape communicator chokes on V2 CRLs

# so this is commented out by default to leave a V1 CRL.

# crlnumber must also be commented out to leave a V1 CRL.

# crl_extensions        = crl_ext

default_days    = 365                   # how long to certify for

default_crl_days= 30                    # how long before next CRL

default_md      = md5                   # which md to use.

preserve        = no                    # keep passed DN ordering

# A few difference way of specifying how similar the request should look

# For type CA, the listed attributes must be the same, and the optional

# and supplied fields are just that :-)

policy          = policy_match

# For the CA policy

[ policy_match ]

countryName             = match

stateOrProvinceName     = match

organizationName        = match

organizationalUnitName  = optional

commonName              = supplied

emailAddress            = optional

# For the 'anything' policy

# At this point in time, you must list all acceptable 'object'

# types.

[ policy_anything ]

countryName             = optional

stateOrProvinceName     = optional

localityName            = optional

organizationName        = optional

organizationalUnitName  = optional

commonName              = supplied

emailAddress            = optional

####################################################################

[ req ]

default_bits            = 1024

default_keyfile         = privkey.pem

distinguished_name      = req_distinguished_name

attributes              = req_attributes

x509_extensions = v3_ca # The extentions to add to the self signed cert

# Passwords for private keys if not present they will be prompted for

# input_password = secret

# output_password = secret

# This sets a mask for permitted string types. There are several options.

# default: PrintableString, T61String, BMPString.

# pkix   : PrintableString, BMPString.

# utf8only: only UTF8Strings.

# nombstr : PrintableString, T61String (no BMPStrings or UTF8Strings).

# MASK:XXXX a literal mask value.

# WARNING: current versions of Netscape crash on BMPStrings or UTF8Strings

# so use this option with caution!

string_mask = nombstr

# req_extensions = v3_req # The extensions to add to a certificate request

[ req_distinguished_name ]

countryName                     = Country Name (2 letter code)

countryName_default             = SE

countryName_min                 = 2

countryName_max                 = 2

stateOrProvinceName             = State or Province Name (full name)

stateOrProvinceName_default     = Scania

localityName                    = Locality Name (eg, city)

localityName_default            = Malmo

0.organizationName              = Organization Name (eg, company)

0.organizationName_default      = IFKFF

# we can do this but it is not needed normally :-)

#1.organizationName             = Second Organization Name (eg, company)

#1.organizationName_default     = World Wide Web Pty Ltd

organizationalUnitName          = Organizational Unit Name (eg, section)

#organizationalUnitName_default =

commonName                      = Common Name (eg, YOUR name)

commonName_max                  = 64

commonName_default              = d99ma

emailAddress                    = Email Address

emailAddress_max                = 64

emailAddress_default            = d99ma@ifkff.org

# SET-ex3                       = SET extension number 3

[ req_attributes ]

challengePassword               = A challenge password

challengePassword_min           = 4

challengePassword_max           = 20

unstructuredName                = An optional company name

[ usr_cert ]

# These extensions are added when 'ca' signs a request.

# This goes against PKIX guidelines but some CAs do it and some software

# requires this to avoid interpreting an end user certificate as a CA.

basicConstraints=CA:FALSE

# Here are some examples of the usage of nsCertType. If it is omitted

# the certificate can be used for anything *except* object signing.

# This is OK for an SSL server.

# nsCertType                    = server

# For an object signing certificate this would be used.

# nsCertType = objsign

# For normal client use this is typical

# nsCertType = client, email

# and for everything including object signing:

# nsCertType = client, email, objsign

# This is typical in keyUsage for a client certificate.

# keyUsage = nonRepudiation, digitalSignature, keyEncipherment

# This will be displayed in Netscape's comment listbox.

nsComment                       = "OpenSSL Generated Certificate"

# PKIX recommendations harmless if included in all certificates.

subjectKeyIdentifier=hash

authorityKeyIdentifier=keyid,issuer:always

# This stuff is for subjectAltName and issuerAltname.

# Import the email address.

# subjectAltName=email:copy

# An alternative to produce certificates that aren't

# deprecated according to PKIX.

# subjectAltName=email:move

# Copy subject details

# issuerAltName=issuer:copy

#nsCaRevocationUrl              = http://www.domain.dom/ca-crl.pem

#nsBaseUrl

#nsRevocationUrl

#nsRenewalUrl

#nsCaPolicyUrl

#nsSslServerName

[ v3_req ]

# Extensions to add to a certificate request

basicConstraints = CA:FALSE

keyUsage = nonRepudiation, digitalSignature, keyEncipherment

[ v3_ca ]

# Extensions for a typical CA

# PKIX recommendation.

subjectKeyIdentifier=hash

authorityKeyIdentifier=keyid:always,issuer:always

# This is what PKIX recommends but some broken software chokes on critical

# extensions.

#basicConstraints = critical,CA:true

# So we do this instead.

basicConstraints = CA:true

# Key usage: this is typical for a CA certificate. However since it will

# prevent it being used as an test self-signed certificate it is best

# left out by default.

# keyUsage = cRLSign, keyCertSign

# Some might want this also

# nsCertType = sslCA, emailCA

# Include email address in subject alt name: another PKIX recommendation

# subjectAltName=email:copy

# Copy issuer details

# issuerAltName=issuer:copy

# DER hex encoding of an extension: beware experts only!

# obj=DER:02:03

# Where 'obj' is a standard or added object

# You can even override a supported extension:

# basicConstraints= critical, DER:30:03:01:01:FF

[ crl_ext ]

# CRL extensions.

# Only issuerAltName and authorityKeyIdentifier make any sense in a CRL.

# issuerAltName=issuer:copy

authorityKeyIdentifier=keyid:always,issuer:always

```

```

#!/usr/bin/perl

#

# CA - wrapper around ca to make it easier to use ... basically ca requires

#      some setup stuff to be done before you can use it and this makes

#      things easier between now and when Eric is convinced to fix it :-)

#

# CA -newca ... will setup the right stuff

# CA -newreq[-nodes] ... will generate a certificate request

# CA -sign ... will sign the generated request and output

#

# At the end of that grab newreq.pem and newcert.pem (one has the key

# and the other the certificate) and cat them together and that is what

# you want/need ... I'll make even this a little cleaner later.

#

#

# 12-Jan-96 tjh    Added more things ... including CA -signcert which

#                  converts a certificate to a request and then signs it.

# 10-Jan-96 eay    Fixed a few more bugs and added the SSLEAY_CONFIG

#                  environment variable so this can be driven from

#                  a script.

# 25-Jul-96 eay    Cleaned up filenames some more.

# 11-Jun-96 eay    Fixed a few filename missmatches.

# 03-May-96 eay    Modified to use 'ssleay cmd' instead of 'cmd'.

# 18-Apr-96 tjh    Original hacking

#

# Tim Hudson

# tjh@cryptsoft.com

#

# 27-Apr-98 snh    Translation into perl, fix existing CA bug.

#

#

# Steve Henson

# shenson@bigfoot.com

# default openssl.cnf file has setup as per the following

# demoCA ... where everything is stored

$SSLEAY_CONFIG=$ENV{"SSLEAY_CONFIG"};

$DAYS="-days 365";

$REQ="openssl req $SSLEAY_CONFIG";

$CA="openssl ca $SSLEAY_CONFIG";

$VERIFY="openssl verify";

$X509="openssl x509";

$PKCS12="openssl pkcs12";

$CATOP="./demoCA";

$CAKEY="cakey.pem";

$CACERT="cacert.pem";

$DIRMODE = 0777;

$RET = 0;

foreach (@ARGV) {

        if ( /^(-\?|-h|-help)$/ ) {

            print STDERR "usage: CA -newcert|-newreq|-newreq-nodes|-newca|-sign|-verify\n";

            exit 0;

        } elsif (/^-newcert$/) {

            # create a certificate

            system ("$REQ -new -nodes -x509 -keyout newreq.pem -out newreq.pem $DAYS");

            $RET=$?;

            print "Certificate (and private key) is in newreq.pem\n"

        } elsif (/^-newreq$/) {

            # create a certificate request

            system ("$REQ -new -nodes -keyout newreq.pem -out newreq.pem $DAYS");

            $RET=$?;

            print "Request (and private key) is in newreq.pem\n";

        } elsif (/^-newreq-nodes$/) {

            # create a certificate request

            system ("$REQ -new -nodes -keyout newreq.pem -out newreq.pem $DAYS");

            $RET=$?;

            print "Request (and private key) is in newreq.pem\n";

        } elsif (/^-newca$/) {

                # if explicitly asked for or it doesn't exist then setup the

                # directory structure that Eric likes to manage things

            $NEW="1";

            if ( "$NEW" || ! -f "${CATOP}/serial" ) {

                # create the directory hierarchy

                mkdir $CATOP, $DIRMODE;

                mkdir "${CATOP}/certs", $DIRMODE;

                mkdir "${CATOP}/crl", $DIRMODE ;

                mkdir "${CATOP}/newcerts", $DIRMODE;

                mkdir "${CATOP}/private", $DIRMODE;

                open OUT, ">${CATOP}/serial";

                print OUT "01\n";

                close OUT;

                open OUT, ">${CATOP}/index.txt";

                close OUT;

            }

            if ( ! -f "${CATOP}/private/$CAKEY" ) {

                print "CA certificate filename (or enter to create)\n";

                $FILE = <STDIN>;

                chop $FILE;

                # ask user for existing CA certificate

                if ($FILE) {

                    cp_pem($FILE,"${CATOP}/private/$CAKEY", "PRIVATE");

                    cp_pem($FILE,"${CATOP}/$CACERT", "CERTIFICATE");

                    $RET=$?;

                } else {

                    print "Making CA certificate ...\n";

                    system ("$REQ -new -x509 -keyout " .

                        "${CATOP}/private/$CAKEY -out ${CATOP}/$CACERT $DAYS");

                    $RET=$?;

                }

            }

        } elsif (/^-pkcs12$/) {

            my $cname = $ARGV[1];

            $cname = "My Certificate" unless defined $cname;

            system ("$PKCS12 -in newcert.pem -inkey newreq.pem " .

                        "-certfile ${CATOP}/$CACERT -out newcert.p12 " .

                        "-export -name \"$cname\"");

            $RET=$?;

            exit $RET;

        } elsif (/^-xsign$/) {

            system ("$CA -policy policy_anything -infiles newreq.pem");

            $RET=$?;

        } elsif (/^(-sign|-signreq)$/) {

            system ("$CA -policy policy_anything -out newcert.pem " .

                                                        "-infiles newreq.pem");

            $RET=$?;

            print "Signed certificate is in newcert.pem\n";

        } elsif (/^(-signCA)$/) {

            system ("$CA -policy policy_anything -out newcert.pem " .

                                        "-extensions v3_ca -infiles newreq.pem");

            $RET=$?;

            print "Signed CA certificate is in newcert.pem\n";

        } elsif (/^-signcert$/) {

            system ("$X509 -x509toreq -in newreq.pem -signkey newreq.pem " .

                                                                "-out tmp.pem");

            system ("$CA -policy policy_anything -out newcert.pem " .

                                                        "-infiles tmp.pem");

            $RET = $?;

            print "Signed certificate is in newcert.pem\n";

        } elsif (/^-verify$/) {

            if (shift) {

                foreach $j (@ARGV) {

                    system ("$VERIFY -CAfile $CATOP/$CACERT $j");

                    $RET=$? if ($? != 0);

                }

                exit $RET;

            } else {

                    system ("$VERIFY -CAfile $CATOP/$CACERT newcert.pem");

                    $RET=$?;

                    exit 0;

            }

        } else {

            print STDERR "Unknown arg $_\n";

            print STDERR "usage: CA -newcert|-newreq|-newreq-nodes|-newca|-sign|-verify\n";

            exit 1;

        }

}

exit $RET;

sub cp_pem {

my ($infile, $outfile, $bound) = @_;

open IN, $infile;

open OUT, ">$outfile";

my $flag = 0;

while (<IN>) {

        $flag = 1 if (/^-----BEGIN.*$bound/) ;

        print OUT $_ if ($flag);

        if (/^-----END.*$bound/) {

                close IN;

                close OUT;

                return;

        }

}

}

```

----------

## reconciledthief

I'm getting the same error.

Any ideas?

----------

## Teardrop

hi

i got the same problem. some research showed that openssl-0.9.7d-r2 has a bug. emerge the masked "e" version and it works.

hope that helps.

cu Teardrop

----------

## askar

Hi!

I have almost the same problem.

I'm trying to setup email system by reading the "Virtual Mailhosting

System with Postfix Guide".

I have a problem in section 5.

When I do

# ./CA.pl -newca

have error "unable to load certificate

2319:error:0906D06C:PEM routines:PEM_read_bio:no start

line:pem_lib.c:637:Expecting: TRUSTED CERTIFICATE".

I use version 0.9.7e of openssl.

Is this solvable problem at all?

askar

----------

## grapesmc

Same exact problem. Just spent like 4 hours messing with it and almost gave up and downloaded CentOs. This is killing me. I know that the version of ssl  and other stuff has probably changed since the document was put together, but man.... help?

----------

## askar

 *grapesmc wrote:*   

> Same exact problem. Just spent like 4 hours messing with it and almost gave up and downloaded CentOs. This is killing me. I know that the version of ssl  and other stuff has probably changed since the document was put together, but man.... help?

 

So you're using CentOS. How is it?

askar

----------

## grapesmc

I haven't gone for it yet - but it's Red Hat Enterprise... And I've been there before - minus the fees. Still hoping someone can save me on this issue, which I assume is something stupid, and not a show-stopper.

-- update... okay, after spending what seemed like a lifetime i found some info here: http://ldp.paradoxical.co.uk/HOWTO/SSL-Certificates-HOWTO/x120.html

basically, you need to edit the CA.pl to be this:

#$SSLEAY_CONFIG=$ENV{"SSLEAY_CONFIG"};

$SSLEAY_CONFIG="-config /etc/ssl/openssl.cnf";

and this:

#$CATOP="./demoCA';

$CATOP="/etc/ssl";

I am not sure who to notify who to update the document

----------

