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.
With the release of wget 1.13 in August 2011 this section is most probably outdated.
There is a known bug (here, here, and here) in wget 1.12 which prevents successful SSL connections to many sites. Dyndns.com is one such site, wget reports:
ERROR: certificate common name `*.dyndns.com' doesn't match requested host name `dyndns.com'.
To connect to dyndns.com 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.
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.
- Create the wget/libSSL certificate directory:
mkdir -p /etc/ssl/certs
- So wget knows where to look, update
/etc/profileand add the line:
- Update shell:
- you can also use
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.
Let say we want to install the root certificate authority for dyndns.org. The domain https://members.dyndns.org 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 file.
The first step is installing
opkg install openssl-util
Now you can use either the manual method or the add-cert.sh 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.
cd /etc/ssl/certs wget http://www.geotrust.com/resources/root_certificates/certificates/Equifax_Secure_Certificate_Authority.cer ##### create link using the hash value from openssl ##### # store certificate hash value in HASH append .0 HASH=`openssl x509 -hash -noout -in Equifax_Secure_Certificate_Authority.cer`.0 # create link ln -s Equifax_Secure_Certificate_Authority.cer $HASH
Note: If another cert has the same hash use suffix
.2 instead of
.0. To see the hash value type
Place this script in a file named add-cert.sh, using an editor like vi or nano (if installed). ``chmod +x add-cert.sh`` to mark it executable, then use it like this:
wget example.com/certificate.cer ./add-cert.sh certificate.cer
#!/bin/sh # author: joda openssl=/usr/bin/openssl certdir=$SSL_CERT_DIR if [ ! -f $openssl ]; then echo "ERROR: Can't find $openssl. openssl-util installed?" >&2 fi if [[ "$1" = "-f" ]]; then overwrite=1 shift # remove $1 fi if [ -f "$1" ]; then certfile=$1 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; fi 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 suffix=0 while [ "1" -ne "$overwrite" ] && [ -h "$certdir/$HASH.$suffix" ]; do let "suffix += 1" done echo " linking $HASH.$suffix -> $certname" if [ $overwrite ]; then ln -sf "$certname" "$certdir/$HASH.$suffix" else ln -s "$certname" "$certdir/$HASH.$suffix" fi else 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 fi
Solution: Move old wget until new wget is installed ("opkg install" needs wget)
Using SSH/Telnet shell:
ln -sf /bin/busybox /bin/wget rm /usr/bin/wget opkg install wget rm /bin/wget
— joda 2010/06/19 20:57
doc/howto/wget-ssl-certs.txt · Last modified: 2012/12/03 21:04 by avalon