OpenWrt HOWTOs » SSL and Certificates in wget

SSL and Certificates in wget

This is a short tutorial on how to make wget (with libSSL) accept trusted certificate authorities. Without trusted certificate authorities, any party can pretend to be the site wget tries to contact. In addition to proving the server on the other end is who it says it is, using SSL means encryption will protect the request while in transit, e.g. a DDNS password.

Note: This probably won’t work for wget(matrixtunnel) and it can’t work for wget(nossl) because wget looks for the certificates in a libSSL dependand way. Please add information for other flavors of wget.

A Caveat

With the release of wget 1.13 in August 2011 this section is most probably outdated.

There is a known bug (herehereand here) in wget 1.12 which prevents successful SSL connections to many sites. is one such site, wget reports: ERROR: certificate common name `*' doesn't match requested host name `'.
To connect to insecurely, use `–no-check-certificate'.

The bug has been fixed, but wget hasn’t had a release since 22-Sep-2009. As of 16-Mar-2011, it looks like a new version of wget will be released “soon”, which will contain this patch. wget (1.13.4-1) is now available in the OpenWRT repositories.

Install wget (with SSL)

The default wget in OpenWRT is provided by Busybox, which does not support SSL. If you want to use SSL (https) URLs, you can install the real wget:

opkg update
opkg install wget

/usr/bin/wget points now to the full version.

Certificate Directory

  1. Create the wget/libSSL certificate directory:

    mkdir -p /etc/ssl/certs
  2. So wget knows where to look, update /etc/profile and add the line:

    export SSL_CERT_DIR=/etc/ssl/certs
  3. Update shell:

    source /etc/profile
  4. you can also use /etc/ssl/certs directory with curl –capath

Note: if you need SSL in your DDNS client, look also here using.wget

Adding root certificates

Most browsers/distributions/etc ship with root certificates from the major Certificate Authorities, such as VeriSign and GeoTrust. Root certificates are used to validate the certificates presented by servers. OpenWRT does not include root certificates, so it is up to you to install them.

Adding certificates through opkg

You can use opkg to install the certificates from the major CA

opkg install ca-certificates

Now you have the major root certificates installed in /etc/ssl/certs

Adding certificates manually

Let say we want to install the root certificate authority for The domain is signed by the “Equifax” root certificate. We need to download the root certificate, then place it in the certificate directory. Certificates in /etc/ssl/certs must be named after their hash value so that they can be found.

It is easier to find the root certificate with any modern web browser (e.g. firefox) by opening the site with https, viewing the certificate and exporting it from the browser to a pem or base64 cer file. Using openssl s_client allows for easy downloading of the remote server’s SSL certificate chain. You should verify the chain you get with another source such as your web browser.

The first step is installing openssl-util:

opkg install openssl-util

Now you can use either the manual method or the script below to install certs into /etc/ssl/certs. Make sure to use openssl from the OpenWrt device because if you try this from your linux PC, you may get a completely different hash for the same exact certificate due to a difference in the version of openssl.

shell prompt
cd /etc/ssl/certs
openssl s_client -connect < /dev/null > temporary.out
openssl x509 -outform PEM < temporary.out >
##### create link using the hash value from openssl #####
# store certificate hash value in HASH append .0
HASH=`openssl x509 -hash -noout -in`.0
# create link
ln -s $HASH

Note: If another cert has the same hash use suffix .1 or .2 instead of .0. To see the hash value type echo $HASH.

Adding certificates with

Place this script in a file named, using an editor like vi or nano (if installed). “chmod +x“ to mark it executable, then use it like this:

./ certificate.cer
# author: joda
if [ ! -f $openssl ]; then
  echo "ERROR: Can't find $openssl. openssl-util installed?" >&2
if [[ "$1" = "-f" ]]; then
   shift # remove $1
if [ -f "$1" ]; then
  certname=`basename $certfile`
  echo "Certificate $certname"
  echo "  copy to $certdir"
  if [ "1" -ne "$overwrite" ] && [ -f "$certdir/$certname" ]; then
    echo >&2
    echo "ERROR: certificate $certname exists" >&2
    exit 2;
  cp "$1" "$certdir/$certname"
  # create symbolic link from hash
  echo -n "  generating hash: "
  HASH=`$openssl x509 -hash -noout -in $certfile`
  echo "$HASH"
  # handle hash collisions
  while [ "1" -ne "$overwrite" ] && [ -h "$certdir/$HASH.$suffix" ]; do
    let "suffix += 1"
  echo "  linking $HASH.$suffix -> $certname"
  if [ $overwrite ]; then
    ln -sf "$certname" "$certdir/$HASH.$suffix"
    ln -s "$certname" "$certdir/$HASH.$suffix"
  echo >&2
  echo "ERROR: file does not exist $1" >&2
  echo >&2
  echo "This script adds (root) certificates for wget(ssl) to $certdir." >&2
  echo "SYNTAX: `basename $0` [Options] [x509-certificate]" >&2
  echo >&2
  echo "Option: -f      force overwriting if certificate exists" >&2

Trouble Shooting

Backfire 10.3 Conflict: /usr/bin/wget -> /bin/busybox blocks wget

Solution: Move old wget until new wget is installed (“opkg install” needs wget)

Using SSH/Telnet shell:

shell prompt
ln -sf /bin/busybox /bin/wget
rm /usr/bin/wget
opkg install wget
rm /bin/wget

— joda 2010/06/19 20:57

Confirm wget SSL root



发表评论 0

Your email address will not be published. Required fields are marked *