May 19, 2012

Creating Multi Domain Java Key Store

You often may need to access to a host with different host headers. By means of the subjectAltName field introduced in X.509 v3, we are able to specify multiple domains in a single certificate. You can create certificate requests including subjectAltName field by openssl tool. On the other hand, lots of applications require certificates in Java Key Stores. In our case, we should have achieved to configure VMware View Connection Servers with multiple host headers. Since i am familiar with openssl, i have done it in the following way.
First of all create a configuration file;
# my.cnf
[ req ]
distinguished_name= req_distinguished_name
default_days  = 1460 # (4 years)
encrypt_key  = no
default_bits  = 1024
string_mask  = nombstr
req_extensions  = v3_req # Extensions to add to certificate request

[ req_distinguished_name ]
countryName   = Country Name (2 letter code)
countryName_default  = TR
stateOrProvinceName  = State or Province Name (full name)
stateOrProvinceName_default = Istanbul
localityName   = Locality Name (eg, city)
localityName_default  = Istanbul
0.organizationName  = Organization Name (eg, company)
0.organizationName_default = MyOrganization
organizationalUnitName  = Organizational Unit Name (eg, section)
organizationalUnitName_default = MyUnit
emailAddress   = Email Address
emailAddress_default  =
commonName   = Common Name (eg, YOUR name)
commonName_default  =

[ v3_req ]
subjectAltName = @alt_names

DNS.1 = view
DNS.2 = viewconn01
DNS.3 = viewconn02
DNS.4 = view.mydomain.intra
DNS.5 = viewconn01.mydomain.intra
DNS.6 = viewconn02.mydomain.intra
DNS.7 =
Then, create the certificate request and the private key using the configuration file;
$ openssl req -batch -new -config req.cnf -out req.pem -keyout key.pem
Generating a 1024 bit RSA private key
writing new private key to 'key.pem'
Verify that your host headers are listed in the X509v3 Subject Alternative Name section
$ openssl req -in req.pem -noout -text
Certificate Request:
        Version: 0 (0x0)
        Subject: C=TR, ST=Istanbul, L=Istanbul, O=MyOrganization, OU=MyUnit/,
        Subject Public Key Info:
            Public Key Algorithm: rsaEncryption
                Public-Key: (1024 bit)
                Exponent: 65537 (0x10001)
        Requested Extensions:
            X509v3 Subject Alternative Name:
                DNS:view, DNS:viewconn01, DNS:viewconn02, DNS:view.mydomain.intra, DNS:viewconn01.mydomain.intra, DNS:viewconn02.mydomain.intra,
    Signature Algorithm: sha1WithRSAEncryption
Now, the multi domain certificate request is created. You should make it signed by the Certificate Authority. After getting the signed certifate in PEM format we need to import the certificate into JKS (Java Key Store). You can import the certificates by ImportKey (Thanks to Joachim Karrer and Jens Carlberg), but first you have to convert base64 encoded PEM files to DER format.
openssl x509 -in cert.pem -out cert.der -outform der
openssl pkcs8 -topk8 -nocrypt -in key.pem -inform PEM -out key.der -outform der
You can download the source ( or the compiled (ImportKey.class) one, run it as follows
$ java ImportKey key.der cert.der
Using keystore-file : /home/user/keystore.ImportKey
One certificate, no chain.
Key and certificate stored.
Alias:importkey  Password:importkey
Now it is time to configure VMware View Connection Server to make it use newly generated JKS.
Type the following lines into the file.

C:\Program Files\VMware\VMware View\Server\sslgateway\conf\
Then restart the "VMware View Connection Server" service;
>net stop "VMware View Connection Server"
The VMware View Connection Server service is stopping........
The VMware View Connection Server service was stopped successfully.

>net start "VMware View Connection Server"
The VMware View Connection Server service is starting.
The VMware View Connection Server service was started successfully.
When you browse your host headers, everything should be fine and certificate details should look similar to those below.


  1. hi,

    I follow your steps and LOST at below:
    1) where to get this file "cert.pem"?
    "openssl x509 -in cert.pem -out cert.der -outform der"

    2) can replace "Keytool.exe" with " java ImportKey key.der cert.der" ?

    many thanks

  2. Hi Thomas,
    1) You should send the req.pem (Certificate Request) to the CA (Certificate Authority) and make it signed. Then, you can rename it as cert.pem.
    If you want to sign the request with openssl by yourself, make sure to use "copy_extensions = copy" directive while signing with CA certificate. Otherwise it drops the extensions including subjectAltName.

    2) Keytool is not able import existing private keys, this is why we need to use ImportKey.