My favorites | Sign in
Project Home Downloads Wiki Issues
Search
for
LinuxCertManagement  
Configuring SSL certificates on Linux.
Linux, SSL
Updated Oct 12, 2010 by wtc%chromium.org@gtempaccount.com

NOTE: SSL client authentication with personal certificates does not work completely in Linux, see issue 16830 and issue 25241.

Introduction

On Linux, Chromium uses the NSS Shared DB. Rather than reinvent the wheel and create another certificate configuration tool, we are going to wait for a system certificate configuration utility to be created and launch that. In the mean time, you can configure certificates with the NSS command line tools.

Details

Get the tools

  • Debian/Ubuntu: sudo apt-get install libnss3-tools
  • Fedora: su -c "yum install nss-tools"
  • Gentoo: su -c "echo 'dev-libs/nss utils' >> /etc/portage/package.use && emerge dev-libs/nss" (You need to launch all commands below with the nss prefix, e.g., nsscertutil.)
  • Opensuse: sudo zypper install mozilla-nss-tools

List all certificates

certutil -d sql:$HOME/.pki/nssdb -L

Ubuntu Jaunty error

Above (and most commands) gives:

certutil: function failed: security library: invalid arguments.

Package version 3.12.3.1-0ubuntu0.9.04.2

List details of a certificate

certutil -d sql:$HOME/.pki/nssdb -L -n <certificate nickname>

Add a certificate

certutil -d sql:$HOME/.pki/nssdb -A -t <TRUSTARGS> -n <certificate nickname> -i <certificate filename>

The TRUSTARGS are three strings of zero or more alphabetic characters, separated by commas. They define how the certificate should be trusted for SSL, email, and object signing, and are explained in the certutil docs or Meena's blog post on trust flags.

For example, to trust a root CA certificate for issuing SSL server certificates, use

certutil -d sql:$HOME/.pki/nssdb -A -t "C,," -n <certificate nickname> -i <certificate filename>

To import an intermediate CA certificate, use

certutil -d sql:$HOME/.pki/nssdb -A -t ",," -n <certificate nickname> -i <certificate filename>

Note: to trust a self-signed server certificate, we should use

certutil -d sql:$HOME/.pki/nssdb -A -t "P,," -n <certificate nickname> -i <certificate filename>

Unfortunately that doesn't work because of NSS bug 531160. To work around the NSS bug, you have to trust it as a CA using the "C,," trust flags.

Add a personal certificate and private key for SSL client authentication

Use the command:

pk12util -d sql:$HOME/.pki/nssdb -i PKCS12_file.p12

to import a personal certificate and private key stored in a PKCS #12 file. The TRUSTARGS of the personal certificate will be set to "u,u,u".

Delete a certificate

certutil -d sql:$HOME/.pki/nssdb -D -n <certificate nickname>

Comment by jan.javo...@gmail.com, Feb 18, 2010

The above methods failed for me, using Gentoo and nss-3.12.5-r1 However, following information at https://wiki.mozilla.org/NSS_Shared_DB_Howto , I changed the -d parameter to omit sql: and added NSS_DEFAULT_DB_TYPE="sql" on the line before the command invocation (instead of exporting the environment variable). In this manner, everything worked perfectly with no warning messages. In addition, I have been able to add user certificates as .pkcs12 files using:

NSS_DEFAULT_DB_TYPE="sql" pk12util -d $HOME/.pki/nssdb -i <path_to_cert_file> -n "This Cert's Nick".

Comment by tgulacs...@gmail.com, Feb 27, 2010

To get a site's certificate:

echo QUIT | openssl s_client -connect site:443 | sed -ne '/BEGIN CERT/,/END CERT/p'
Comment by vincenzo.romano, Mar 10, 2010

The error is also in Ubuntu Karmic. But what is the solution/workaround?

Comment by nicolas....@gmail.com, Mar 18, 2010

You will also need to pass the following flag to chrome if you want to have SSL support: --auto-ssl-client-auth, eg:

$ google-chrome --auto-ssl-client-auth 
Comment by akaih...@gmail.com, Mar 21, 2010

Chromium just sits there trying to connect and this is what I see on the console:

$ chromium-browser --auto-ssl-client-auth
3601:3612:9920367083:ERROR:net/socket/ssl_client_socket_nss.cc(1052)? handshake failed; NSS error code -5938, net_error -107
3601:3612:9981604894:ERROR:net/socket/ssl_client_socket_nss.cc(1052)? handshake failed; NSS error code -5938, net_error -107

I've verified with certutil that my personal certificate has been imported successfully. This is on Ubuntu 10.04 Lucid (pre-release) with Chromium 5.0.307.9. I used the --auto-ssl-client-auth option as advised by nicolas.pinto.

Comment by mahes...@gmail.com, Mar 24, 2010

On Ubuntu (Karmic) I have just unchecked check for server certificate revocation to make it work for the time being. Is there a better solution available?

Comment by paolodi...@gmail.com, Apr 6, 2010

same here

pow@debian:~/Downloads/s4$ google-chrome --auto-ssl-client-auth [6026:6041:9641614080:ERROR:net/socket/ssl_client_socket_nss.cc(1275)] handshake failed; NSS error code -8054, net_error -2

unchecking "check for server certificate revocation" also doesn't work for me

using google chrome 5.0.366.2 dev on Debian Unstable

Comment by chinainv...@gmail.com, Apr 15, 2010

Linux google-chrome 成功导入证书: http://blog.csdn.net/chinainvent/archive/2010/04/15/5490371.aspx

Comment by nicolas....@gmail.com, May 11, 2010

Quick update: the '5.0.375.38 beta' version does not need the --auto-ssl-client-auth option.

Comment by vgvvic...@gmail.com, May 26, 2010

Intento abrir la sesión a la intranet de mi universidad (UPV) y me devuelve el error: Certificado del servidor no válido. En cambio con firefox entro sin ningún tipo de problema y antes con chrome también, me ha sucedido tras actualizar. ¿Que me proponéis? gracias

Comment by henegg...@gmail.com, May 28, 2010

So, all I want is for Chromium to stop nagging about a self-signed local server certificate. I added the certificate as described but still the red page comes up. What am I missing? Ubuntu 10.04 LTS, Chromium 5.0.342.9 (43360) Ubuntu

Comment by yocum...@gmail.com, Jun 10, 2010

Here's a quick-n-dirty script to help manage your certs (especially if they expire every 7 days like personal Kerberized CA (KCA) certs do at Fermilab):

#!/bin/bash

DB="-d sql:$HOME/.pki/nssdb"

case "$1" in

list)
certutil $DB -L
;; details)
certutil $DB -L -n "$2"
;; add-ca)
certutil $DB -A -t "$2" -n "$3" -i "$4"
;; add)
pk12util $DB -i "$2"
;; del)
certutil $DB -D -n "$2"
;;
  • echo "Usage [list|details|add-ca|add|del]" echo " \"details\" requires <nickname>" echo " \"add-ca\" requires <trustargs> <nickname> <certificate filename>" echo " \"add\" requires <filename>" echo " \"del\" requires <nickname>" exit 1
;;
esac ~

Comment by marwansh...@gmail.com, Jun 14, 2010

thanks for the info

Comment by marcosor...@gmail.com, Jun 29, 2010

There is a tool in Mozilla repository for OpenSUSE called nss-manager that is a standalone GUI for managing NSS certificates.

You can also find it on http://software.opensuse.org/search

Comment by Kinse...@gmail.com, Jul 12, 2010

I'm on 64-bit Karmic and am having the same problem identified above (the less than illuminating "certutil: function failed: security library: invalid arguments" error). Short of peeking inside the code, does anyone know a way to coerce certutil to spit-out more error details? I'd really like to get this fixed, but I've got next to no information to work with at the moment... It's frustrating ><

Comment by moses.ja...@gmail.com, Jul 19, 2010

I have no comments at present.

Comment by Pho...@gmail.com, Jul 28, 2010

It's so complex!

Comment by al.grav...@gmail.com, Aug 5, 2010

Thanks to the Chromium dev and contributors. keep up the work on documentation.

Comment by nicolas....@gmail.com, Aug 16, 2010

nicolas@nicolas-desktop:/home/nicolas$ certutil -d sql:/home/nicolas/.pki/nssdb -L

Certificate Nickname Trust Attributes

SSL,S/MIME,JAR/XPI

That's all I get. Something must be wrong. Where are all the certificates like the CA from VeriSign? e.g.? They must be definitely available somewhere in my system as my banking site works without complaints ...

Comment by pddeme...@gmail.com, Aug 18, 2010

It's not mentioned here, but exporting a certificate to a PKCS12 file is easy:

pk12util -d sql:$HOME/.pki/nssdb -o out.p12 -n "certificate name"

Comment by rimez...@gmail.com, Aug 24, 2010

Ugh. What about non-technical people using Linux! I'm utterly confused!

Comment by aleksand...@gmail.com, Aug 27, 2010

A fix for the certutil: function failed: security library: invalid arguments. error:

The database directory is apparently corrupted.

Move it to some backup location, then recreate it:

mv ~/.pki/nssdb ~/.pki/nssdb.backup
mkdir ~/.pki/nssdb
chmod 700 ~/.pki/nssdb
certutil -d sql:$HOME/.pki/nssdb -N

Then try listing contents (should be empty):

certutil -d sql:$HOME/.pki/nssdb -L

Certificate Nickname                                         Trust Attributes
                                                             SSL,S/MIME,JAR/XPI

Now you should be able to add certs as documented.

Comment by jonsaf...@gmail.com, Sep 1, 2010

At least create a graphical front-end to the NSS shared DB, as part of the Chrome browser.

Comment by csarven, Sep 2, 2010

I'm trying to delete two certs that I have, however, I'm unable to enter the correct certificate name (if any). I have:

$ certutil -d sql:$HOME/.pki/nssdb -L

Certificate Nickname Trust Attributes

SSL,S/MIME,JAR/XPI

NSS Certificate DB:http://csarven.ca/#i's Not a Certification Authority ID u,u,u NSS Certificate DB:http://csarven.ca/#i's Not a Certification Authority ID u,u,u

Not sure what to put for cert-name here:

certutil -d sql:$HOME/.pki/nssdb -D -n

I have tried the CN, which is http://csarven.ca/#i, however that didn't work. Is there a way to get this info?

Comment by robbie.h...@gmail.com, Sep 10, 2010

My short adventure using this with SAP's site to set up a client cert: The browser downloads a 'cert file' that is actually a multipart mime message. Once I used munpack to extract the cert, the certutil command above worked to import it. I hope that's helpful to someone!

Comment by peter.le...@gmail.com, Sep 30, 2010

Adding a personal certificate that way works, but be wary - it is a major SECURITY RISK!!! You're precious private key is not encrypted this way. Anyone that could copy your $HOME/.pki/nssdb dir can authenticate as YOU! This is absolutely a no-go for using Chrome with Internet banking or similar.

Comment by paul.im...@gmail.com, Oct 2, 2010

Agreed by some that posted.. This is complex. Can someone create a script to help with this?

Comment by james.b.franklin, Oct 8, 2010

Why can't the Chromium developers simply use whatever method Firefox uses? Why is this so hard. Is not Firefox source code available under a license that permits another free browser such as Chrome to use it.... This is an unacceptable situation given the capacity for Google to create what we need!

Comment by skaiuoq...@gmail.com, Oct 11, 2010

They are using what FireFox? uses. All the commands here are from Mozilla tools. They simply didn't spend resources in providing it a Chrome/ium GUI.

Comment by james.b.franklin, Oct 12, 2010

When I use firefox, I can use my CAC (government issued smart card) to access websites because Firefox presents me with a PIN prompt and certificate selection (via libcoolkeypk11.so). Chrome(ium) does none of that so what exactly are they using? Chrome(ium) developers can't create a connection to libcoolkeypk11.so or can't create a couple of dialogs? This is crazy!

Comment by ear9mrn@gmail.com, Oct 23, 2010

I found this method for adding self signed certificates with Ubuntu (assume it will work with other distros.

http://blog.avirtualhome.com/2010/02/02/adding-ssl-certificates-to-google-chrome-linux-ubuntu/

Worked for me first time :-) Why cant google add this little script to add a self signed cert? Maybe someone (I could try) write a plugin to do this.

#!/bin/sh
#
# usage:  import-cert.sh remote.host.name [port]
#
REMHOST=$1
REMPORT=${2:-443}
exec 6>&1
exec > $REMHOST
echo | openssl s_client -connect ${REMHOST}:${REMPORT} 2>&1 |sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p'
certutil -d sql:$HOME/.pki/nssdb -A -t TC -n "$REMHOST" -i $REMHOST 
exec 1>&6 6>&-
Comment by ear9mrn@gmail.com, Oct 23, 2010

If you get an error with the above method try removing any old certs and re-try:

certutil -D -n <the name> -d sql:$HOME/.pki/nssdb
Comment by christia...@gmail.com, Oct 23, 2010

For those who still encounter problems with the verification of self-signed server certificates, it appears that chromium expects the certificate to include the URL of the server under "Common Name (CN". This is a little bit surprising since openssl would suggest "(eg, YOUR name)" here.

Comment by mir...@gmail.com, Nov 2, 2010

I found a pretty easy way. Add your certificates into Firefox. There is a pretty good GUI. Then according to this howto convert and move FF database info .pki/nssdb one.

https://wiki.mozilla.org/NSS_Shared_DB_Howto

Comment by sandworm...@gmail.com, Nov 9, 2010

Ok, so I'm going to try and make this as nice as possible. The steps above are very frustrating for Fedora 14.

Step 1: yum install nss-tools Results: successful

Step 2: List all certificates certutil -d sql:$HOME/.pki/nssdb -L Result: FAIL

Notes: certutil: function failed: security library: bad database. rpm -qa | grep nss-tools nss-tools-3.12.8-2.fc14.x86_64

Comment: Does this really need to be this difficult to simply import a certificate??

Comment by kehanhar...@gmail.com, Nov 22, 2010

Google Chrome Stable 7.0.517.44 , Ubuntu 10.04 OK I managed to get this working using the above instructions. To get the certificate I clicked the proceed anyway button on the red warning page, then clicked on the crossed out https: in the url> Certificate Information>Details>Export...>PKCS#6, certificate chain>Save Then:

sudo apt-get install libnss3-tools
certutil -d sql:$HOME/.pki/nssdb -L
certutil -d sql:$HOME/.pki/nssdb -A -t "C,," -n <nickname> -i <filename>
#verify the certificate's in there
certutil -d sql:$HOME/.pki/nssdb -L

Now restart Chrome (I did it without restarting and it didn't work)

Comment by pesc...@gmail.com, Dec 2, 2010

I got an Error 207 (net::ERR_CERT_INVALID) from Chromium 8.0.552.208 when importing an S/MIME Certificate (from startssl.com).

The keys were generated and stored in key4.db but startssl wouldn't deliver (or recreate) the certificate again without the key into firefox. Used the above Howto at mozilla.org and made the two links and voilà.

Comment by pcana...@gmail.com, Dec 9, 2010

That's nice tgulacsi78. Thanks. I added to it somewhat to create a script:

#!/bin/bash 
echo QUIT | openssl s_client -connect "$1":443 | sed -ne '/BEGIN CERT/,/END CERT/p' > /tmp/"$1" 
certutil -d sql:$HOME/.pki/nssdb -A -t "C,," -n "$1" -i /tmp/"$1" && rm /tmp/"$1"

I saved that in "addcert.sh". Usage is: addcert.sh <site_to_add>

e.g. addcert.sh test.com

Comment by akro...@gmail.com, Dec 19, 2010

I would be quite nice to your customers to "reinvent the wheel"! Mozilla didn't mind that and gave us nice tools in their products...

Comment by maxad...@gmail.com, Jan 5, 2011

I see, you don't want to reinvent the whell. But the whell doesn't exist yet. There isn't a graphical front-end to NSS command line tool.

Comment by mail%cha...@gtempaccount.com, Jan 7, 2011

On Ubuntu Karmic, I didn't see any built-in certificates with this command:

certutil -d sql:$HOME/.pki/nssdb -L

However, with the "-h all" option I could see all the certs. i.e. this works if you can't see any built-in certs:

certutil -d sql:$HOME/.pki/nssdb -L -h all
Comment by ad...@panmicro.com.au, Jan 14, 2011

What a massive , gigantic stuff-around this all is and the reason that 'nix OS's haven't seen uptake.

Comment by attila.j...@gmail.com, Jan 30, 2011

nss prefix not needed for gentoo ~amd64

Comment by kai.hen...@gmail.com, Feb 1, 2011

certutil -d sql:$HOME/.pki/nssdb -L does not list any certificates. Just a "Certificate Nickname, Trust Attributes" header on my Arch system. :(

.pki/ .pki/nssdb .pki/nssdb/key4.db .pki/nssdb/cert9.db .pki/nssdb/pkcs11.txt

Comment by vtre...@gmail.com, Feb 14, 2011

2 ear9mm: yeah! script (Oct 23, 2010) do work for selfsigned server certs (instead of -t "P,,")

Comment by radek.an...@gmail.com, Feb 17, 2011

Oh come on. Where do we get a proper CERT management ?! I mean a window-based and not a console one....

Comment by fernandr...@gmail.com, Feb 21, 2011

vaya puta mierda

Comment by svent...@gmail.com, Feb 22, 2011

This is fixed in Unstable version (http://www.chromium.org/getting-involved/dev-channel). Not sure about Beta.

Comment by yaron.sh...@gmail.com, Mar 2, 2011

Can you say a few words on how this is fixed, e.g. is there going to be a GUI?

Thanks!

Comment by cercadel...@gmail.com, Apr 6, 2011

This has to be a joke! I'm testing Chromium, and it took me less than 10 minutes to determine that if it lacks such a simple thing as this, it simply doesn't work for me.

Comment by marcober...@gmail.com, May 31, 2011

Just to be fair, and end this thread on a positive note, after having gone to NSS hell and back I just simply downloaded the latest OpenSUSE Chrome RPM and it turns out to have a built-in certificate manager, having the regular type of functionality I'd been waiting for. Big thanks to Google folks, looks great.

Comment by asiyapet...@gmail.com, Jun 9, 2011

pk12util -d sql:$HOME/.pki/nssdb -i PKCS12_file.p12

Comment by t4cghcif, Jul 11, 2011

@marc are you kidding? There is no SSL Cert Manager (Using Chromium 14.0.803.0)

Comment by shrinat...@webyog.com, Jul 19, 2011

@t4cghcif : there is, atleast under 14.0.821. wrench > preferences > under the hood > manage certificates

Comment by Speeddy...@gmail.com, Jul 21, 2011

Looks like this is a problem:

[speeddy@tomcat chrome]$ ./google-chrome [8267:8303:12145525686:ERROR:x509_certificate_nss.cc(808)] CERT_PKIXVerifyCert for wiki.alertlogic.net failed err=-8179 [8267:8302:12145677990:ERROR:x509_certificate_nss.cc(808)] CERT_PKIXVerifyCert for nms.alertlogic.net failed err=-8179 this = 182618432 SetHotKey? true!

Imported keys by telling firefox to remember the exception, then copying the stores from ~/.mozilla/firefox/(profile.name) to /etc/pki/nssdb and ~/.pki/nssdb.

Then I ran the above command which started Chrome but did not allow the pages to work.

Comment by adamf...@gmail.com, Today (8 hours ago)

Note: google chrome is too stupid to use the cert it is given by the remote website if there's an old revoked one in .pki. Once a saved pki is revoked, google chrome is dead in the water. Clear out the cert, or more easily just rm -rf the whole .pki subdirectory and google will start behaving properly.


Sign in to add a comment
Powered by Google Project Hosting