<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="http://thelinuxsource.org/skins/common/feed.css?303"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://thelinuxsource.org/index.php?action=history&amp;feed=atom&amp;title=Cert_Mgmt</id>
		<title>Cert Mgmt - Revision history</title>
		<link rel="self" type="application/atom+xml" href="http://thelinuxsource.org/index.php?action=history&amp;feed=atom&amp;title=Cert_Mgmt"/>
		<link rel="alternate" type="text/html" href="http://thelinuxsource.org/index.php?title=Cert_Mgmt&amp;action=history"/>
		<updated>2026-04-15T23:58:13Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.23.15</generator>

	<entry>
		<id>http://thelinuxsource.org/index.php?title=Cert_Mgmt&amp;diff=66&amp;oldid=prev</id>
		<title>Support: Created page with &quot;====  Convert a certificate file (.crt) to .pem ====  # openssl x509 -in cert.crt -outform pem -out cert.pem  ====  Convert a certificate file and a private key with a CA cert...&quot;</title>
		<link rel="alternate" type="text/html" href="http://thelinuxsource.org/index.php?title=Cert_Mgmt&amp;diff=66&amp;oldid=prev"/>
				<updated>2017-05-09T18:16:40Z</updated>
		
		<summary type="html">&lt;p&gt;Created page with &amp;quot;====  Convert a certificate file (.crt) to .pem ====  # openssl x509 -in cert.crt -outform pem -out cert.pem  ====  Convert a certificate file and a private key with a CA cert...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;====  Convert a certificate file (.crt) to .pem ====&lt;br /&gt;
 # openssl x509 -in cert.crt -outform pem -out cert.pem&lt;br /&gt;
&lt;br /&gt;
====  Convert a certificate file and a private key with a CA cert or intermediate bundle to PKCS#12 (.pfx .p12) ====&lt;br /&gt;
 # openssl pkcs12 -export -out certificate.pfx -inkey privateKey.key -in certificate.crt -certfile CACert.crt&lt;br /&gt;
&lt;br /&gt;
====  Convert a certificate file and a private key to PKCS#12 (.pfx .p12) ====&lt;br /&gt;
 # openssl pkcs12 -export -out certificate.pfx -inkey privateKey.key -in certificate.crt&lt;br /&gt;
&lt;br /&gt;
====  Convert a certificate file and a private key to PKCS#12 (.pfx .p12) with a friendlyName (used for Remedy cert) ====&lt;br /&gt;
 # openssl pkcs12 -export -out certificate.pfx -inkey privateKey.key -in certificate.crt -name mycert&lt;br /&gt;
&lt;br /&gt;
====  Convert a certificate file, or a CA cert, or an intermediate bundle to PKCS#12 (.pfx .p12) ====&lt;br /&gt;
 # openssl pkcs12 -export -out certificate.pfx -nokeys -nodes -in certificate.crt&lt;br /&gt;
&lt;br /&gt;
====  Convert a PKCS#12 file (.pfx .p12) containing a private key and certificates to PEM ====&lt;br /&gt;
Note: you can add -nocerts to only output the private key or add -nokeys to only output the certificates&lt;br /&gt;
 # openssl pkcs12 -in keyStore.pfx -out keyStore.pem -nodes&lt;br /&gt;
&lt;br /&gt;
====  Convert a PKCS#12 file (.pfx .p12) containing a private key and certificates to separate .crt/.key files ====&lt;br /&gt;
 # openssl pkcs12 -in keyStore.pfx -out keyStore.key -nocerts&lt;br /&gt;
 # openssl pkcs12 -in keyStore.pfx -out keyStore.crt -nokeys&lt;br /&gt;
&lt;br /&gt;
====  Convert a CRL/Certificate Revocation List file (.crl) to PEM (allows grep'ing for serial numbers) ====&lt;br /&gt;
 # openssl crl -inform DER -text -in gds1-53.crl -out gds1-53.pem&lt;br /&gt;
&lt;br /&gt;
====  Convert a OpenSSL &amp;gt;= 1.0 key file to a OpenSSL &amp;lt; 1.0 format key file ====&lt;br /&gt;
 # openssl rsa -in privateKey.pem -des3 -out newPrivateKey.pem&lt;br /&gt;
&lt;br /&gt;
====  Remove a passphrase from (or decrypt) a private key ====&lt;br /&gt;
 # openssl rsa -in privateKey.pem -out newPrivateKey.pem&lt;br /&gt;
&lt;br /&gt;
====  View expiry dates on a cert (works on most certs, .crt, .pem, etc.) ====&lt;br /&gt;
 # openssl x509 -noout -dates -in certificate.crt&lt;br /&gt;
&lt;br /&gt;
====  View URL/CN on a cert (works on most certs, .crt, .pem, etc.) ====&lt;br /&gt;
 # openssl x509 -noout -subject -in certificate.crt&lt;br /&gt;
&lt;br /&gt;
====  View a text dump of a cert's settings and configuration (works on most certs, .crt, .pem, etc.) ====&lt;br /&gt;
 # openssl x509 -noout -text -in certificate.crt&lt;br /&gt;
&lt;br /&gt;
====  View a text dump of a p7b cert ====&lt;br /&gt;
 # openssl pkcs7 -text -noout -print_certs -in gd_iis_intermediates.p7b&lt;br /&gt;
&lt;br /&gt;
====  View all ciphers available in the currently installed openssh ====&lt;br /&gt;
 # openssl ciphers 'ALL:eNULL' | sed -e 's/:/n/g' | sort&lt;br /&gt;
&lt;br /&gt;
====  View a cert bundle (file with many certs) ====&lt;br /&gt;
the problem with trying to query a cert bundle, openssl will only read the first cert in the bundle, so to query all of the certs, they would all need to be broken out into many files each containing only one of the certs from the bundle. But, here's how you can do that:&lt;br /&gt;
Note: you should do this in a temp dir/temp work area. ca-bundle.crt currently has approx. 170 certs, so this will gen approx. 170 files&lt;br /&gt;
 SCRIPT:&lt;br /&gt;
 # cat certsplit&lt;br /&gt;
 F=$1&lt;br /&gt;
 csplit -k -f $F -b '-%03d' -z $F '/END CERTIFICATE/+1' {*}&lt;br /&gt;
 # ./certsplit ca-bundle.crt&lt;br /&gt;
 # for C in ca-bundle.crt-* ; do echo $C ; openssl x509 -noout -subject -dates -in $C ; done&lt;br /&gt;
 OR command line:&lt;br /&gt;
 # F=ca-bundle.crt ; csplit -k -f $F -b '-%03d' -z $F '/END CERTIFICATE/+1' {*}&lt;br /&gt;
 # for C in ca-bundle.crt-* ; do echo $C ; openssl x509 -noout -subject -dates -in $C ; done&lt;br /&gt;
&lt;br /&gt;
====  Certificate Authority setup ====&lt;br /&gt;
A CA tree already exists on every system under /etc/pki/CA, to generate certs;&lt;br /&gt;
 # /etc/pki/tls/misc/CA -?&lt;br /&gt;
&lt;br /&gt;
Running the CA script with a modified openssl.cnf&lt;br /&gt;
 # SSLEAY_CONFIG=&amp;quot;-config /tmp/openssl.cnf&amp;quot; /etc/pki/tls/misc/CA -newca&lt;br /&gt;
&lt;br /&gt;
Generating sha256 certs&lt;br /&gt;
Make a copy of openssl.cnf&lt;br /&gt;
openssl.cnf, set [ CA_default ] and [ req ] sections&lt;br /&gt;
 75c75&lt;br /&gt;
 &amp;lt; default_md    = sha256                # use public key default MD&lt;br /&gt;
 ---&lt;br /&gt;
 &amp;gt; default_md    = default               # use public key default MD&lt;br /&gt;
 107c107&lt;br /&gt;
 &amp;lt; default_md            = sha256&lt;br /&gt;
 ---&lt;br /&gt;
 &amp;gt; default_md            = sha1&lt;br /&gt;
&lt;br /&gt;
Change number of days&lt;br /&gt;
Make a copy of the CA script and openssl.cnf&lt;br /&gt;
openssl.cnf, set [ CA_default ] section&lt;br /&gt;
 73c73&lt;br /&gt;
 &amp;lt; default_days  = 1825          # how long to certify for&lt;br /&gt;
 ---&lt;br /&gt;
 &amp;gt; default_days  = 365                   # how long to certify for&lt;br /&gt;
 &lt;br /&gt;
 CA, set CADAYS&lt;br /&gt;
 &lt;br /&gt;
 64c64&lt;br /&gt;
 &amp;lt; CADAYS=&amp;quot;-days 1825&amp;quot;   # 5 years&lt;br /&gt;
 ---&lt;br /&gt;
 &amp;gt; CADAYS=&amp;quot;-days 1095&amp;quot;   # 3 years&lt;br /&gt;
&lt;br /&gt;
====  Generating certs with extended attributes ====&lt;br /&gt;
Example for multiple DNS names (CN's)&lt;br /&gt;
&lt;br /&gt;
1. make a copy of the openssl config file (the changes will be specific to this one new cert being generated)&lt;br /&gt;
 # cp /etc/pki/tls/openssl.cnf /etc/pki/tls/openssl.cnf-www&lt;br /&gt;
&lt;br /&gt;
2. modify the new config file&lt;br /&gt;
 # vi /etc/pki/tls/openssl.cnf-www&lt;br /&gt;
 UNDER [ req ] section, uncomment/change;&lt;br /&gt;
 # req_extensions = v3_req # The extensions to add to a certificate request&lt;br /&gt;
 TO&lt;br /&gt;
 req_extensions = v3_req # The extensions to add to a certificate request&lt;br /&gt;
 UNDER [ v3_req ] section, add your extended attributes, add the following line;&lt;br /&gt;
 subjectAltName = DNS:www.example.com, DNS:example.com&lt;br /&gt;
&lt;br /&gt;
3. run a openssl cert generation command using the new config file&lt;br /&gt;
 # openssl req -config /etc/pki/tls/openssl.cnf-www -utf8 -new -key www.example.com.key -out www.example.com.csr&lt;br /&gt;
&lt;br /&gt;
====  Add / Remove Certs To / From a Keystore ====&lt;br /&gt;
Note : default passwords are &amp;quot;changeit&amp;quot; or &amp;quot;changeme&amp;quot;, default alias is &amp;quot;mykey&amp;quot;&lt;br /&gt;
 # keytool -import -file cert.crt -keystore keystorefilename -alias certalias&lt;br /&gt;
 # keytool -delete -alias certalias -keystore keystorefilename&lt;br /&gt;
&lt;br /&gt;
====  List Certs in a Keystore ====&lt;br /&gt;
 # keytool -list -keystore keystorefilename&lt;br /&gt;
 Enter keystore password:&lt;br /&gt;
 &lt;br /&gt;
 Keystore type: JKS&lt;br /&gt;
 Keystore provider: SUN&lt;br /&gt;
 Your keystore contains 1 entry&lt;br /&gt;
 &lt;br /&gt;
 somecertalias, Dec 6, 2014, PrivateKeyEntry,&lt;br /&gt;
 Certificate fingerprint (MD5): 8D:5F:25:16:F0:53:99:FF:35:64:9E:9B:1D:FC:27:FF&lt;br /&gt;
&lt;br /&gt;
====  Export a Cert from a Keystore ====&lt;br /&gt;
Note : default passwords are &amp;quot;changeit&amp;quot; or &amp;quot;changeme&amp;quot;, default alias is &amp;quot;mykey&amp;quot;&lt;br /&gt;
 # keytool -export -alias certalias -file cert.crt -keystore keystorefilename&lt;br /&gt;
 Example:&lt;br /&gt;
 # keytool -export -alias ci-test-1 -file /tmp/ci-test.crt -keystore jssecacerts&lt;br /&gt;
 &lt;br /&gt;
 Hint : check content of exported cert&lt;br /&gt;
 # keytool -printcert -v -file star.example.com&lt;br /&gt;
&lt;br /&gt;
====  Jar Signing ====&lt;br /&gt;
 # jarsigner -verbose -keystore keystorefilename -storepass keystorepassword -keypass certkeypassword jarfilenametosign.jar aliasinkeystoreforcertkey&lt;br /&gt;
OR with Date Stamp, &amp;quot;-tsa&amp;quot; = Time Stamp Authority (below -tsa option specific for Godaddy certs)&lt;br /&gt;
 # jarsigner -verbose -keystore keystorefilename -storepass keystorepassword -keypass certkeypassword -tsa [http://tsa.starfieldtech.com/] jarfilenametosign.jar aliasinkeystoreforcertkey&lt;br /&gt;
OR if proxy is required&lt;br /&gt;
 # jarsigner -J-Dhttp.proxyHost=sc9-proxy.example.net -J-Dhttp.proxyPort=3128 -verbose -keystore keystorefilename -storepass keystorepassword -keypass certkeypassword -tsa [http://tsa.starfieldtech.com/] jarfilenametosign.jar aliasinkeystoreforcertkey&lt;br /&gt;
 &lt;br /&gt;
 updating: META-INF/MANIFEST.MF&lt;br /&gt;
 adding: META-INF/PRODUCTI.SF&lt;br /&gt;
 requesting a signature timestamp&lt;br /&gt;
 TSA location: [http://tsa.starfieldtech.com/]&lt;br /&gt;
 adding: META-INF/PRODUCTI.RSA&lt;br /&gt;
 adding: org/&lt;br /&gt;
 adding: org/openoces/&lt;br /&gt;
 adding: org/openoces/opensign/&lt;br /&gt;
 adding: org/openoces/opensign/client/&lt;br /&gt;
 adding: org/openoces/opensign/client/applet/&lt;br /&gt;
 adding: org/openoces/opensign/wrappers/microsoftcryptoapi/&lt;br /&gt;
 signing: org/openoces/opensign/wrappers/microsoftcryptoapi/MicrosoftCryptoApi.class&lt;br /&gt;
 signing: it-practice.license&lt;br /&gt;
 signing: opensign.license&lt;br /&gt;
 signing: opensign.version&lt;br /&gt;
&lt;br /&gt;
====  Verify Jar Signing ====&lt;br /&gt;
 # jarsigner -verify signedjarfilename.jar&lt;br /&gt;
 jar verified.&lt;br /&gt;
 OR for more info&lt;br /&gt;
 # jarsigner -verify -verbose -certs signedjarfilename.jar&lt;br /&gt;
&lt;br /&gt;
====  Troubleshooting ====&lt;br /&gt;
&lt;br /&gt;
=====  Test a ssl connection (https/imaps/pops/etc.s) =====&lt;br /&gt;
 # openssl s_client -connect 163.120.170.50:443&lt;br /&gt;
&lt;br /&gt;
=====  TXT_DB error number 2 =====&lt;br /&gt;
 failed to update database&lt;br /&gt;
 TXT_DB error number 2&lt;br /&gt;
 openssl command failed&lt;br /&gt;
&lt;br /&gt;
The cert you are trying to generate was already generated and is already listed in index.txt (ca/db/index.txt), you can edit index.txt and remove the line for the cert you are trying to generate. You should only get this error if you have set up a CA, and you are signing certs under that CA.&lt;br /&gt;
&lt;br /&gt;
=====  unknown pbe algorithm: TYPE=PBES2 =====&lt;br /&gt;
 unable to load private key&lt;br /&gt;
 unknown pbe algorithm: TYPE=PBES2&lt;br /&gt;
 pkcs12 algor cipherinit error&lt;br /&gt;
 pkcs12 pbe crypt error&lt;br /&gt;
 ASN1 lib&lt;br /&gt;
 PEM lib&lt;br /&gt;
&lt;br /&gt;
The key file was generated with openssl &amp;gt;= 1.0, a program built with OpenSSL &amp;lt; 1.0 fails to open the key file. OpenSSL &amp;gt;= 1.0 uses a different format for storing private keys and earlier versions are unable to open the file. Older versions are apparently able to open OpenSSL &amp;gt;= 1.0 key files which are not password protected. The key file needs to be converted to the pre OpenSSL &amp;gt;= 1.0 key file format.&lt;/div&gt;</summary>
		<author><name>Support</name></author>	</entry>

	</feed>