diff --git a/Makefile b/Makefile
index 571ada8ce7fb0af61ee156e3624b8b7439ecc2a5..1b7d0e0281265ab0b7df5c579600860f4a722a6a 100644
--- a/Makefile
+++ b/Makefile
@@ -14,17 +14,17 @@ test: clean
 	./ssl-ca gen www
 	test "$$(openssl rsa -noout -check -in keys/www)" = "RSA key ok"
 	openssl verify -CAfile CA.crt certs/www
-	test "$$(openssl x509 -in certs/www -issuer -noout)" = "issuer= /CN=*.*.ssl-ca"
-	test "$$(openssl x509 -in certs/www -subject -noout)" = "subject= /CN=*.*.www.ssl-ca"
+	test "$$(openssl x509 -in certs/www -issuer -noout)" = "issuer= /CN=ssl-ca"
+	test "$$(openssl x509 -in certs/www -subject -noout)" = "subject= /CN=www.ssl-ca"
 	openssl genrsa -out keys/smtp
 	./ssl-ca sign
 	openssl verify -CAfile CA.crt certs/smtp
-	test "$$(openssl x509 -in certs/smtp -issuer -noout)" = "issuer= /CN=*.*.ssl-ca"
-	test "$$(openssl x509 -in certs/smtp -subject -noout)" = "subject= /CN=*.*.smtp.ssl-ca"
+	test "$$(openssl x509 -in certs/smtp -issuer -noout)" = "issuer= /CN=ssl-ca"
+	test "$$(openssl x509 -in certs/smtp -subject -noout)" = "subject= /CN=smtp.ssl-ca"
 	./ssl-ca resign
 	openssl verify -CAfile CA.crt certs/www
 	openssl verify -CAfile CA.crt certs/smtp
-	test "$$(openssl x509 -in certs/www -issuer -noout)" = "issuer= /CN=*.*.ssl-ca"
-	test "$$(openssl x509 -in certs/www -subject -noout)" = "subject= /CN=*.*.www.ssl-ca"
-	test "$$(openssl x509 -in certs/smtp -issuer -noout)" = "issuer= /CN=*.*.ssl-ca"
-	test "$$(openssl x509 -in certs/smtp -subject -noout)" = "subject= /CN=*.*.smtp.ssl-ca"
+	test "$$(openssl x509 -in certs/www -issuer -noout)" = "issuer= /CN=ssl-ca"
+	test "$$(openssl x509 -in certs/www -subject -noout)" = "subject= /CN=www.ssl-ca"
+	test "$$(openssl x509 -in certs/smtp -issuer -noout)" = "issuer= /CN=ssl-ca"
+	test "$$(openssl x509 -in certs/smtp -subject -noout)" = "subject= /CN=smtp.ssl-ca"
diff --git a/ssl-ca b/ssl-ca
index 49a036b327c72a303f20e6104e6e6710f32dfeaf..8351a4f586e69d1947ae42c8348ecaa6cd44cb73 100755
--- a/ssl-ca
+++ b/ssl-ca
@@ -1,7 +1,6 @@
 #!/bin/sh -e
 
 test $(which openssl) || ( echo "Can't find openssl."; exit 1)
-export domain="$(basename $PWD)"
 seed="$(hexdump -n10 -e '10/1 "%02o" "\n"' /dev/urandom)"
 config=\
 "[ ca ]
@@ -33,13 +32,15 @@ RANDFILE = /dev/urandom
 #O = Organization name
 #OU = Organizational unit
 #emailAddress = email address
-CN = *.*.\${ENV::domain}
+CN = \${ENV::domain}
 
 [ v3_ca ]
 basicConstraints = CA:true
+subjectAltName = DNS:*.\${ENV::domain}, DNS:*.*.\${ENV::domain}
 
 [ v3_req ]
 basicConstraints = CA:false
+subjectAltName = DNS:*.\${ENV::domain}
 "
 
 usage () {
@@ -47,6 +48,7 @@ usage () {
 }
 
 init () {
+    export domain="$(basename $PWD)"
     mkdir -p certs keys
     if [ -e openssl.cnf ]
     then
@@ -92,6 +94,7 @@ sign_key () {
     openssl req \
         -key keys/$1 \
         -new \
+        -reqexts v3_req \
         -config openssl.cnf \
         -out "$csr"
     openssl x509 \
@@ -101,6 +104,7 @@ sign_key () {
         -CA CA.crt \
         -set_serial $seed \
         -extensions v3_req \
+        -extfile openssl.cnf \
         -CAkey CA.key
     rm "$csr"
 }