On Tue, Nov 22, 2005 at 01:35:22PM -0000, Mark wrote:
> Hi,
> 
> Thanks for all the help everyone.
> 
> > We're signing the certificates for users. They call up the servers and
> > present a certificate which authorises them. The root certificate is
> > stored on the servers, and the fingerprint of it is stored in custom
> > silicon (so no-one can change the entire heirarchy). This is because
> > some of the systems are not online and hence can't "call home" to
> > check they have the correct root CA and one concern is physical
> > subversion of the CA cert stored on the server's hard drive (both the
> > users and the servers are out of our physical control, in essence).
> > 
> > The user certificates contain a list of servers they're allowed to
> > access, along with which IPs they can do it from (so that stealing a
> > copy of the certificate AND the private key won't let you access a
> > server illicitly).
> 
> Could you give me some examples of how this is achieved. I am still
> unsure of the exact commands/parameters to use, especially when it
> comes to set up the client(s).

I wrote a makefile for it;


.PRECIOUS:      %.priv %.req

SSL_ROOT := /home/katie/share/Apps/openssl-0.9.8
SSL_APPS_DIR := $(SSL_ROOT)/apps
OPENSSL := $(SSL_APPS_DIR)/openssl
KEY_LEN:=       512
CA_DIR := ca/
CA_CERTS_DIR := $(CA_DIR)/certs/
CA_CONFIG := $(CA_DIR)/CAss.cnf
CA_PRIV_DIR := $(CA_DIR)/priv/

CLIENT_KEY      := cl.priv
SERVER_KEY      := sv.priv
CA_KEY  := $(CA_PRIV_DIR)/ca.priv

CLIENT_CERT     := cl.cert
SERVER_CERT     := sv.cert
ROOT_CERT       :=  $(CA_DIR)/certs/root.cert

ALL_KEYS        := $(CLIENT_KEY) $(SERVER_KEY) $(CA_KEY)

OPENSSL_CONF    :=      $(CA_CONFIG)
export OPENSSL_CONF

certs:  $(ALLKEYS) $(ROOT_CERT) $(SERVER_CERT) $(CLIENT_CERT) certificates

.PRECIOUS:      %.priv %.req

%.priv:
        @echo "----------------------------------------------------"
        @echo "       Creating a keypair"
        @echo "----------------------------------------------------"
        $(OPENSSL) genrsa -out $*.priv $(KEY_LEN)
        $(OPENSSL) rsa -in $*.priv -pubout -out $*.pub

%.req:  %.cnf   %.priv
        @echo "----------------------------------------------------"
        @echo "       Creating a certificate request"
        @echo "----------------------------------------------------"
        $(OPENSSL) req -config $*.cnf -new -key $*.priv -out $*.req -outform PEM

$(ROOT_CERT):   $(CA_KEY)
        @echo "----------------------------------------------------"
        @echo "       Creating a root certificate"
        @echo "----------------------------------------------------"
        $(OPENSSL) req -x509 -new -days 10000 -key $(CA_KEY) -out $(ROOT_CERT) 
-outform PEM  -config $(CA_CONFIG)
        $(OPENSSL) x509 -noout -text -in $(ROOT_CERT)

%.cert:         $(ROOT_CERT) %.req
        @echo "----------------------------------------------------"
        @echo "       Signing a certificate"
        @echo "----------------------------------------------------"
        $(OPENSSL) ca -batch -in $*.req -out $*.cert -config $(CA_CONFIG)

certificates:   $(ROOT_CERT)
        mkdir -p certificates
        hash=`openssl x509 -hash -in $(ROOT_CERT) | head -1`;cp $(ROOT_CERT) 
certificates/$$hash.0

%.reqshow:
        $(OPENSSL) req -in $*.req -text -noout

%.certshow:
        $(OPENSSL) x509 -in $*.cert -text -noout


And then we say "make certs" and it makes the certificates up to date.

You do this;


At the CA end, we create ca.pub and ca.priv which are our keys.
        We turn ca.priv into a self signed root certificate.
        The line involving the "hash" command makes a certificate named by 
digest (?) which is XXXXXXX.0 which is
                used when you point at a directory for the certs.

Create cl.pub and cl.priv which are the keys.
        cl.priv and cl.cnf (the request configuration) make cl.req which is a 
certificate request.
        cl.req gets turned into cl.cert by using the ca.cert and ca.priv.

sv.* (the server's end) uses exactly the same processes.


        
At actual connection time, each end loads;

        Its certificate (cl.cert, say) using SSL_CTX_use_certificate_file
                This is presented to the other end.
        Its private key (cl.priv) using SSL_CTX_use_PrivateKey_file
                This is so we can verify we are the certificate holder.
        It then points at the directory containing the digest-named CA certs 
using SSL_CTX_load_verify_locations
                This is so we can check the other end's cert was signed by the 
CA we trust.

There's a slight asymmetry in that you have to faff with the
PEER_mumble flags to get the client end to present a cert, and hand
check if one arrived or not (the server end is handled by
OpenSSL). ITSR it's something like you can set failure if a client
cert arrived and wasn't valid, but not if it just didn't send one.

Once all that's happened, both ends are talking to each other, they're
both authenticated, and then we get the certs from the connections using;

        SSL_get_peer_certificate

And then read out verification data using

        X509_get_ext_d2i

etc. All our extension data is just plain strings which we then hand off for 
more processing.

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

Reply via email to