Monday, August 5, 2019

JAVA Keytool utility for managaing server certificates

In our current set-up we've a .NET connector server for communication between AD and OIM which is running on Windows 64, for which we'll renew the server certificates. 

Please go through the complete post cause there are multiple fronts to this. 

STEP 1 : Generate a new certificate  :

Now, generate a new CSR and a private key using OPENSSL commands  : 




similarly as CSRs generated by keytool utility, you need to align with your CA authority for getting the .cer certificate filegenerated from the above csr file. 

STEP 2  : Find the Certificate store :  

If you're configuring a new connector server  : 

Run the following command from the command prompt:


This key is used for SSL communication by any client that connects to this .NET Connector Server, you will also need to update this key in the connector server IT resource along with the other properties. 

Open the C:\Program Files (x86)\Identity Connectors\Connector Server\ConnectorServer.exe.Config file for the entry : 


The certificate store mentioned in the ConnectorServer.exe.Config file must have only one certificate. If there is more than one certificates, then the .NET Connector Server will not start.
Run the following command to view the number of certificates present in the certificate store:


This will give you a certificate pop-up where you can check if the certiifctae is valid or not. 

STEP 3 : Create a new certificate store or delete the certiifcate from the old store : 

For creating a new certiifcate store use : 


For verifying a store : 


For deleting a certificate from an existing store : 





We can cehck the new store from windows MMC console  : 



STEP 4 :  Merge the private key and certificate  : 

For a proper ssl handshake, the server is required to have a private key paired with the public key embedded in the certificate. When a client connects, it is presented with the certificate. This allows for validation that the server is who it says it is based on trust of an issuance authority.
The certificate needs to have private key in order to decrypt the data from OIM, or you'll receive  the error : "The server mode SSL must use a certificate with 
the associated private key". 


To avoid it, run the below command on windows server : 
This will ask you for a password fpr the private key.


If you get the below ERROR : make sure you're using the right key-cer pair, and not the old key file.
No certificate matches private key

If you get the below ERROR : make sure the certificate was created by CA using base-64 encoded.cer format, and not a DER encoded .cer file.
unable to load certificate

Solution  : Import the certificate through MMC console as it is , and then export it to a  base-64 encoded.cer format. 




STEP 5 : Merge the new .pfx file in to your Personal console and Certificate store used in ConnectorServer.exe.Config file. 



STEP 6 : Import the same certs into all the oim managed server cacerts using keytool -import command. 

ISSUE  : Let's say you've lost the provate key of the cert file, so you can't merge it with a cer file in STEP 4 , for a temporary solution run this  : 

certutil -repairstore my "SerialNumber"

my  :Is the name for 'Personal' store, you can use other certificate store names as well.
SerialNumber : can be found under the certificate details tab. 

You'll get an output like :



How to make sure your certificate has the private key attached with it  ?


You'll get the bellow message displayed in the certificate "General" tab : 



What if I had created my CRS using Certutil and not OpnSSL ? 
The following syntax is used for certutil:

Since there is no way to specify private key file for –MergePFX parameter you must consider the following requirements:



How to get OpenSSL in my Windows server  : 

download it from here : 
OpenSSL.org – Binary Distributions
https://wiki.openssl.org/index.php/Binaries

unzip and keep the binarys as well as your .key and .cer file in the same folder where you'll execute the STEP 4. 



Now, I'm definetly no expert on openSSL (doing it for the first time) so here's a few good read to refer to in future  : 

OpenSSL : 

https://wiki.openssl.org/index.php/Command_Line_Utilities   // official page for all the verbs
https://phoenixnap.com/kb/openssl-tutorial-ssl-certificates-private-keys-csrs // myFav
https://www.freecodecamp.org/news/openssl-command-cheatsheet-b441be1e8c4a/  // goodread

CertUtil : 

https://docs.microsoft.com/en-us/previous-versions/orphan-topics/ws.10/cc772898%28v%3dws.10%29


AD connector server : 

http://rajnishbhatia19.blogspot.com/2008/05/ad-ssl-handshake-certificate-expired.html
https://support.microsoft.com/en-us/help/822406/clients-cannot-authenticate-with-a-server-after-you-obtain-a-new-certi
https://docs.oracle.com/cd/E52734_01/oim/OMDEV/icf.htm#BABIAAHF
https://docs.oracle.com/cd/E22999_01/doc.111/e20347/deploying-microsoft-active-directory-user-management-connector.htm#CMSAD280 


As always, Thanks for reading !























No comments:

Post a Comment