This blog post gives background on setting up mqweb to use digital certificates. The IBM documentation in this area is missing a lot of information, and did not work for me. I started documenting how to set up the certificates for the mqweb support, and found I was having to explain details of what was needed, before giving the command to do it. I have also tried to cover it from a production environment, where you will use signed certificates, and automated deploy etc, instead of GUIs. I suggest you read it before trying to set up mqweb with TLS . Most of the content applies to the REST API as well as web browsers, but tools like CURL and Python are much easier to set up and use.
If I have made mistakes (and it is easy to do so) or there are better ways of doing things, please let me know.
- How certificates are used
- Different levels of mqweb security and authentication
- How is mqweb security set up
- The mqweb server end
- At the web browser
- How does the handshake work if certificates are being used?
- Commands to issue REST commands to MQWEB
- Setting up certificates.
- Distinguished names
- Certificate purpose for signed certificates
- Self signed certificate
- Strong protection
- Certificates expire
- Encrypting passwords in the config file
- Which keystores should I use
How certificates are used
As part of the TLS handshake to do authentication, a certificate is send from the sender to the end user to identify the server. If you are doing authentication with certificates, a “client” certificate is sent up to the server providing information about the subject (person) and how the certificate can be used, for example for authentication or just providing encryption.
You can have “self signed” certificates and certificates signed by a certificate authority.
With self signed, you need a copy of the certificate at each end of the connection, so the certificate received from the client is checked with the server’s copy. With more than one certificate, it quickly becomes impractical to use self signed certificates, and these would not be used in production. (Consider you have 100 partners you work with; you have 100 Linux servers you need to keep up to date; and on average, a certificate expires every week) . Also emailing a copy of the self signed certificate to a recipient is open to a “man in the middle” attack where your certificate is replaced with a bogus one, and so is not secure. Self signed are fine for test systems.
The term Certificate Authority(CA) is a term used for a chain of certificates which are used to sign other certificates. If both ends share a common certificate, then the receiver can validate the payload. Strictly, the CA owns the root certificate which certifies the rest of the chain.
With a signed certificate, a checksum of the certificate is encrypted by the signer, and appended to the certificate as part of the “signing process”. When the a certificate is sent to a recipient, it contains the certificate authority’s certificate. The recipient checks to make sure the certificate authorities match, then does the same calculation on the checksum and compares it with the value passed in the certificate. If they match the passed certificate is valid.
This means that the server only needs to have the certificate authority certificate chain in its trust store, it does not need the individual client certificates. Similarly when the server sends down the certificate to the browser, the browser does not need a copy of the certificate, just the CA chain. If you change the certificate at the server end, you do not need to change the browser end.
This greatly simplifies the use of digital certificates, as you only need one certificate in the server, to identify the server, each user needs just one certificate and there is no emailing of certificates.
CA signed certificates are more secure than self signed certificates, and the validation has stronger checks. A certificate has “extensions” which define how the certificate can be used, for example signing code, but not for authentication; it can be used to identify a server, but not an end user.
Certificates have a validate date range not-valid-before and not-valid-after. You need a process to renew certificates before they expire. This applies to the “client” certificate and the certificate authority certificate.
Certificate have a Distinquished Name, for example CN=colinpaice, OU=Test, O=IBM,C=GB. Where CN is Common Name, and is the user name, OU is Organization Unit, O is the Organization and C is the Country.
When I used curl with a self signed certificate I got
curl: (60) SSL certificate problem: self signed certificate in certificate chain
More details here: https://curl.haxx.se/docs/sslcerts.html
curl failed to verify the legitimacy of the server and therefore could not
establish a secure connection to it. To learn more about this situation and
how to fix it, please visit the web page mentioned above.
If you use the curl – – insecure option you avoid this message, and it works.
Different levels of mqweb security and authentication
There are different levels of security and authentication
- No TLS. Data flows between a web server and web browser in clear text. This is not used by mqweb.
- The server sends a certificate to the web browser. This provides an encryption key for traffic. It also provides the URL of the web server. For a CA signed certificate, the web browser then checks the URL coming from the web server, with the names in the certificate to make sure they match. This gives protection from a bad person trying to point your browser at their server using a different URL. If you are not using certificates to authenticate, you logon with userid and password. Data flowing is encrypted using information sent down in the certificate. This is used by mqweb.
- As 2), and in addition, a certificate is sent up from the client and used instead of entering a password and userid. This is configurable at the mqweb level. The certificate is validated by the server, and the Common Name is used as the userid. This means
- Every certificate needs a unique CN
- a password is not used
- DN:CN=colinpaice,O=SSS,OU=TEST,C=GB and DN:CN=colinpaice,O=SSS,OU=PROD,C=GB
would both be accepted for userid colinpaice if they both had the same CA.
In all cases the userid is checked with the information in the mqweb configuration xml file.
You can specify userids or groups in the xml file. It is better to specify groups than userids as it is less administration. If a person joins a department, or leaves a department, then you just have to update the group, not all of the configuration files.
How is mqweb security set up?
The mqweb server end
The server’s certificate and private key is stored in a key store – this store will have one, and can have many certificates and private keys
The certificates used for client authentication are stored in the trust store.
For example with the definition in the mqwebuser.xml
The keyStoreRef=”defaultKeyStore” says look for the definition with defaultKeyStore. This will point to a key store. Use the certificate with the name defined in the serverKeyAlias
the keystore /home/colinpaice/ssl/key.pkcs12 with certificate colincert will be used.
The trustStoreRef=”defaultTrustStore” says look for the definition with defaultTrustSstore. This will point to the trust store.
the trust store at location /home/colinpaice/ssl/key.jks will be used.
This needs to have the CA certificates, and any self signed certificates.
At the web browser
The web browser needs to have the self signed certificate or the CA certificate, for the certificate which is sent to the browser as part of the handshake “Hello I am the server”, so it can be validated. If the certificate cannot be validated, for example there was no copy of the self signed certificate, the browser will notify you and may allow you to accept the risk. This is insecure, and ok for a test environment.
If certificates are to be used for authentication, then the web browser also needs the user’s certificate and private key, along with with any CA certificates.
How does the handshake work if certificates are being used?
The web server extracts the specified certificate from the keystore and sends it to the web browser.
The certificate is validated either with the browser’s self signed copy, or with the browser’s copy of the CA certificates.
For a signed certificate, the url from the web server is checked with the names in the “Certificate Subject Alternate Name” extension within the certificate. For example IP:127.0.0.1
If client authentication is used, the certificates are read from the server’s trust store. The DN of the self signed certificates and the DN of the CA certificates are extracted and sent down to the browser.
The browser takes this list and checks through the “user” certificates in its key store, for those self signed certificates with a matching DN, or those certificates which have been signed by the CA.
The list of matching certificates is displayed for the user to select from.
If the mqweb server trust store had
- CN=colinpaice,ou=SSS1,o=SSS,C=GB self signed
- CN=CA,O=SSS,C=GB Certificate Authority
and the browser’s keystore had
- CN=colinpaice,ou=SSS1,o=SSS,C=GB self signed
- CN=colinpaice1,ou=ZZZZ,o=SSS,C=GB self signed
- CN=colinpaice2,ou=signed,o=SSS,C=GB signed by CN=CA,O=SSS,C=GB
- CN=colinpaice3,ou=signed,o=ZZZ,C=GB signed by CN=CA,O=ZZZ,C=GB
the list displayed to the user would indicate the following certificates
The Chrome and Firefox remember this decision until the browser is restarted, so if you want to change to use a different certificate – tough; you have to restart the browser.
The browsers use a keystore which you can access through the browser or commands like certutil or pk12util.
Commands to issue REST commands to MQWEB
If you use commands like curl, you can specify the certificate authority file, the user certificate, and the user private key using parameters. You do not need a keystore. For example 3 .pem files are used, one for the certificate, one for the private key and one for the CA certificates.
curl –cacert ./cacert.pem –cert ./colinpaice.pem:password –key colinpaice.key.pem https://127.0.0.1:9443/ibmmq/rest/v1/admin/qmgr
If you use python requests package you can issue “requests” and again specify the various files needed for the certificates.
Setting up certificates.
It is fairly complicated setting up certificates as there are many options.
Your organization will have standards you need to conform to. For example
The Distinquished Name (eg CN=colinpaice,ou=test,o=SSS,C=GB). Organisation is usually your enterprise name, OU could be department name, CN could be userid or other name. You can set up MQ channels to restrict the DN for example to containing ou=test,o=SSS,C=GB.
I set up a DN with C=GB,O=cpwebuser,CN=colinpaice. If I look at the certificate it has CN = colinpaice, O = cpwebuser, C = GB – in a different order.
If I look in the browser’s keystore, the certificates show up under the “O” value, so under “org-cpwebuser”.
As the CN is used as the userid, make sure it is the same case. On my linux machine my userid is colinpaice, the CN must be colinpaice.
Certificate purpose for signed certificates
If you create a certificate signed by a CA (even your private CA) the following checks are done during the TLS handshake.
- The certificate has been signed with “serverAuth” to allow it to be used to authorise servers.
- The key usage has been signed with “Authentication”
- The certificate has the IP address of the server.
If any one of these fail, the handshake fails.
A certificate can be used for many purposes, for example signing code, signing certificates (by a certificate authority). These properties are defined when the certificate is signed.
Both client and server certificates needs keyUsage = digitalSignature.
The Extended Key Usage (EKU) indicates the purpose, or what the certificate public key can be used for.
- A client certificate needs extendedKeyUsage = clientAuth
- A server certificate needs extendedKeyUsage = serverAuth.
The command openssl x509 -purpose -in colinpaice.pem -inform PEM -nocert gave
- SSL client : Yes
- SSL client CA : No
- SSL server : No
- SSL server CA : No
So we can see this has clientAuth key usage.
If these are not set up properly you can get errors about unauthorized access and “SSLHandshakeException: null cert chain” errors.
use openssl x509 -in colinpaice.pem -noout -text |less
and search for Usage
This gave me
X509v3 Key Usage:
X509v3 Extended Key Usage:
TLS Web Client Authentication
Self signed certificate
A self signed certificate is considered weaker than a signed certificate, and some of the checks are not done.
If you are using a self signed certificate, the certificate needs keyUsage = digitalSignature, keyCertSign , it does not need the IP address of the server, nor extendedKeyUsage.
It needs to be installed into the browser keystore as Trusted. If it is not flagged as trusted, then the browsers give errors, and may allow you to continue if you accept it the risk.
There are different strengths of encryption. Stronger ciphers take longer to break. Some encryption or hashing techniques are considered weak, and may not be accepted. For example SHA1 is weak (some browsers will not accept it), SHA256 and SHA348 are much stronger.
Some encryption can be offloaded to specialized chips, so have a smaller CPU cost. You need to use your enterprise standard levels of encryption and hashing.
All certificates (user and CA) have a valid date range. If they are used beyond their end date, you will get an error, and it will not work. You need to have a process in place to renew certificate, including CA certificates. If you use an external CA, it can take days to get a new certificate and deploy it.
Some processing need a keystore. For example Firefox and Chrome use a nss format keystore. The mqweb server needs a keystore to store the certificate to identify the server, and can use a truststore to contain remote authentication certificates.
There are a variety of tools to manage keystores. IBM provide GUI interfaces such as strmqikm, and a command line interfaces runmqikm. There is keytool from Oracle, and other tools such as openssl, pkcs12 and certutil.
There are different sorts of keystores
- nssdb – used by browsers to store keys
- pkcs12 has certificates and the private key
- cms contains keys certificate etc
- jks – Java keystore – used by java to contain certificates
Certificates can be in different formats
- .pem this is a certificate encoded in base 64 encoding. This may look like
- .der this is a binary format
I found it easiest to create certificates using openssl, and import them into the keystores, rather than use a GUI and then export them. This means it it can be scripted and automated, and requires less work.
Encrypting passwords in the config file
Keystores usually have a password.
For example in the mqwebuser.xml file is
This password can encrypted using the /opt/mqm/web/bin/securityUtility command. See here.
For example to encrypt the string “zpassword”
/opt/mqm/web/bin/securityUtility encode –encoding=aes zpassword gives
doing it again gave a different value
Your mqwebuser.xml file would then have
Which keystores should I use?
I used openssl to define and manage my certificates, because the IBM tools did not have all of the capabilities.
I used a pkcs12 (.pkcs12 or .p12) store for the keystore and a jks(.jks) store for the trust store.
Firefox and Chrome use a nssdb (Netscape) database. I used tools pkcs12 to insert certificates, and certutil to display and manage the database.