Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id B5C81200CD1 for ; Wed, 12 Jul 2017 07:11:16 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id B45AF167EF4; Wed, 12 Jul 2017 05:11:16 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id D24F7167EEB for ; Wed, 12 Jul 2017 07:11:15 +0200 (CEST) Received: (qmail 2952 invoked by uid 500); 12 Jul 2017 05:11:14 -0000 Mailing-List: contact users-help@qpid.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@qpid.apache.org Delivered-To: mailing list users@qpid.apache.org Received: (qmail 2941 invoked by uid 99); 12 Jul 2017 05:11:14 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 12 Jul 2017 05:11:14 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id 4005E18050B for ; Wed, 12 Jul 2017 05:11:13 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 2.285 X-Spam-Level: ** X-Spam-Status: No, score=2.285 tagged_above=-999 required=6.31 tests=[RCVD_IN_DNSWL_NONE=-0.0001, SPF_SOFTFAIL=0.972, URI_HEX=1.313] autolearn=disabled Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id 0pRgCvk3rVtG for ; Wed, 12 Jul 2017 05:11:10 +0000 (UTC) Received: from mwork.nabble.com (mwork.nabble.com [162.253.133.43]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with ESMTP id 9038E62677 for ; Wed, 12 Jul 2017 05:11:10 +0000 (UTC) Received: from mjim.nabble.com (unknown [162.253.133.84]) by mwork.nabble.com (Postfix) with ESMTP id 3AC4D521143EE for ; Tue, 11 Jul 2017 22:11:09 -0700 (MST) Date: Tue, 11 Jul 2017 22:11:09 -0700 (MST) From: Morgan Lindqvist To: users@qpid.apache.org Message-ID: <1499836269226-7664728.post@n2.nabble.com> Subject: [qpid C++] Problems addinng externally signed cert and key to certutil (NSS) database MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit archived-at: Wed, 12 Jul 2017 05:11:16 -0000 Hi All, Up till now I have used a own CA and signed the server and client certificates for my QPID C++ installation, this is working as it should from both the client and the server side. A new requirement have now been added which is that the root CA for the server certificate must be a trusted CA, not one that I made my self. I have been trying to adapt my procedure for adding the certificates so that I can add a certificate and key that is created by a trusted CA to the certutil (NSS) database but I am failing misserably. I am using the script below to add the server certificate and create the client certificate. The server certificate is created by Lets Encrypt and the client certificates is still created and signed by my own CA. -------- #!/bin/bash SERVER_CERT_DIR=serverTrusted CERT_PW_FILE=${SERVER_CERT_DIR}/cert_pw.txt #Create directory if missing mkdir -p ${SERVER_CERT_DIR} echo "# Create the password file to access the certificate DB" echo "# Use urandom for password generation" cat /dev/urandom | head -c 20 | base64 | md5sum | cut -d' ' -f1 > ${CERT_PW_FILE} chmod go-rwx ${CERT_PW_FILE} echo "# Create good quality noise" dd bs=256 count=1 if=/dev/urandom of=noise echo "# Create the Certificate and Key Database (-f is the password for database access)" certutil -N -d ${SERVER_CERT_DIR} -f ${CERT_PW_FILE} # CA echo "# Creating CA Certificate and store it in the database" certutil -S -n CA -d ${SERVER_CERT_DIR} -s "CN=MyOwnCA" -x -t "T,," -m 0 -v 21 -f ${CERT_PW_FILE} -z noise -2 "CA:TRUE" echo "# Extract ca.cert file from the database" certutil -L -n CA -d ${SERVER_CERT_DIR} -a -o ${SERVER_CERT_DIR}/ca.cert #server echo "# Convert PEM format from Lets Encrypt" sudo openssl x509 -outform pem -in /etc/letsencrypt/live/qpid.myDomain.com/cert.pem -out ${SERVER_CERT_DIR}/production.cert sudo chown ubuntu:ubuntu ${SERVER_CERT_DIR}/production.cert echo "# Add the trusted server certificate to the database (trusted peer)" certutil -A -n development -d ${SERVER_CERT_DIR} -i ${SERVER_CERT_DIR}/production.cert -t 'P,,' -f ${CERT_PW_FILE} echo "# Convert the key and add to database" sudo openssl rsa -outform der -in /etc/letsencrypt/live/qpid.myDomain.com/privkey.pem -out ${SERVER_CERT_DIR}/production.key sudo chown ubuntu:ubuntu ${SERVER_CERT_DIR}/production.key openssl rsa -inform DER -outform PEM -in ${SERVER_CERT_DIR}/production.key -out ${SERVER_CERT_DIR}/production-key.pem echo "# Create p12 key" openssl pkcs12 -export -inkey ${SERVER_CERT_DIR}/production-key.pem -in ${SERVER_CERT_DIR}/production.cert -out ${SERVER_CERT_DIR}/production-key.p12 -nodes -password pass:`cat ${CERT_PW_FILE}` echo "# Add server key to database" pk12util -d ${SERVER_CERT_DIR} -i ${SERVER_CERT_DIR}/production-key.p12 -w ${CERT_PW_FILE} -k ${CERT_PW_FILE} #client function createClient { echo "# Generate the client certificate" certutil -S -n $1 -d ${SERVER_CERT_DIR} -s "CN=$1" -c CA -t "P,," -v 21 -f ${CERT_PW_FILE} -z noise echo "# Export the key from the DB to a pkcs#12 file" pk12util -n $1 -d ${SERVER_CERT_DIR} -o ${SERVER_CERT_DIR}/$1.p12 -k ${CERT_PW_FILE} -w ${CERT_PW_FILE} echo "# Convert the key (nodes is no key encryption and passin is password input)" openssl pkcs12 -in ${SERVER_CERT_DIR}/$1.p12 -out ${SERVER_CERT_DIR}/$1.key -nodes -passin pass:`cat ${CERT_PW_FILE}` echo "# Export the certificate" certutil -L -n $1 -d ${SERVER_CERT_DIR} -a -o ${SERVER_CERT_DIR}/$1.cert } createClient client1 createClient client2 --------------- I am far from an expert when it comes to certificates, the above commands is the result from searching the web and trying to understand what should be done. If I use the openssl command the check the certificate that is used by the qpid instance I get the following result ---------------------- >openssl s_client -host qpid.myDomain.com -port 5671 -cert cert/serverTrusted/client1.cert -key cert/serverTrusted/client1.key CONNECTED(00000003) depth=0 CN = qpid.myDomain.com verify error:num=20:unable to get local issuer certificate verify return:1 depth=0 CN = qpid.myDomain.com verify error:num=21:unable to verify the first certificate verify return:1 --- Certificate chain 0 s:/CN=qpid.myDomain.com i:/C=US/O=Let's Encrypt/CN=Let's Encrypt Authority X3 --- ... ----------------------- If I use the same command to another site I have that is signed by Lets Encrypt it works as it should ----------------------- >openssl s_client -host www.myDomain.com CONNECTED(00000003) depth=2 O = Digital Signature Trust Co., CN = DST Root CA X3 verify return:1 depth=1 C = US, O = Let's Encrypt, CN = Let's Encrypt Authority X3 verify return:1 depth=0 CN = www.myDomain.com verify return:1 --- Certificate chain 0 s:/CN=www.myDomain.com i:/C=US/O=Let's Encrypt/CN=Let's Encrypt Authority X3 1 s:/C=US/O=Let's Encrypt/CN=Let's Encrypt Authority X3 i:/O=Digital Signature Trust Co./CN=DST Root CA X3 --- ... ------------------ From this I draw the conclusion that the openssl command have access to the trusted root CA from Lets Encryypt and that the reason that it can not verify the certificate when used in QPID is that I made something worng when inserting them into certutil (NSS) database. When a AMQP client connects to the QPID server the connection is disconnected on SSL level without any information on what might be wrong. Questions * Is it possible to sign the client certificates and the server certificates with different root CAs? * It looks like the certificate chain is missing parts in the qpid case. How do I get the whole chain into the database? * What am I doing wrong when inserting the server certificates into certutil (NSS) database? I am using the QPID binary from the PPA. Best Regatds, Morgan -- View this message in context: http://qpid.2158936.n2.nabble.com/qpid-C-Problems-addinng-externally-signed-cert-and-key-to-certutil-NSS-database-tp7664728.html Sent from the Apache Qpid users mailing list archive at Nabble.com. --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org For additional commands, e-mail: users-help@qpid.apache.org