วันพฤหัสบดีที่ 1 ธันวาคม พ.ศ. 2554

CA Keystore/Truststore

Set up own Certificate Authority (need openssl for CA)

1. download openSSL from http://www.slproweb.com/products/Win32OpenSSL.html


2. สร้าง private key/certificate โดยคำสั่ง

C:\OpenSSL-Win32\bin> openssl req -x509 -new -config openssl.cfg -days 365 -out ./new/ca.pem -keyout ./new/ca_pk.pem
Pass: 123456

จากคำสั่งนี้จะได้ certificate ca.pem กับ private key ca_pk.pem


3. นำ certificate มาสร้าง CA truststore โดยคำสั่ง

C:\OpenSSL-Win32\bin> keytool -import -alias certificatekey -file ca.pem -keystore catruststore.jks



Create Keystore and Truststore for a user

1. สร้าง keystore

C:\OpenSSL-Win32\bin\new> keytool -genkey -alias certificatekey -keypass 123456 -keystore CertName.jks -storepass 123456 -validity 365

หรือ ถ้าขี้เกียจพิมพ์ เอาแบบรวดเร็วก็
C:\OpenSSL-Win32\bin\new> keytool -genkey -alias certificatekey -dname "cn=147.127.240.90, ou=IRIT, o=Sun, c=FR" -keypass 123456 -keystore CertName.jks -storepass 123456 -validity 365

ต้องใส่ค่าต่าง ๆ ให้ตรงกับใน ca.pem ถ้าใส่ไม่ตรงต้องไปแก้ openssl.cfg ดังนี้

dir = ./PEM/demoCA # Where everything is kept
policy = policy_anything # otherwise, has to put exactly the same information


2. สร้าง certificate ที่ request การ sign

C:\OpenSSL-Win32\bin\new> keytool -certreq -alias certificatekey -file CertName_csr.pem -keypass 123456 -keystore CertName.jks -storepass 123456

จะได้ output คือ CertName_csr.pem


3. sign CSR (certificate)

C:\OpenSSL-Win32\bin> openssl ca -config openssl.cfg -days 365 -in ./new/CertName_csr.pem -out ./new/CertName.pem -cert ./new/ca.pem -keyfile ./new/ca_pk.pem


4. แปลงไฟล์ในรูปแบบ PEM format
openssl x509 -in ./new/CertName.pem -out ./new/CertName.pem -outform PEM


5. เอา certificate มาต่อกัน
copy CertName.pem + X509CA\ca\new_ca.pem CertName.chain


6. update keystore (private key)
keytool -import -file CertName.chain -keypass 123456 -keystore CertName.jks -storepass 123456


7. สร้าง truststore (public key)
C:\OpenSSL-Win32\bin\new>keytool -import -alias certificatekey -file CertName.chain -keystore truststore.jks


8. ดูผล โดยการ
keytool -list -v -keystore CertName.jks => จะมี Entry type: PrivateKeyEntry และ Entry type: trustedCertEntry
keytool -list -v -keystore truststore.jks => จะมี Entry type: trustedCertEntry อย่างเดียว


Reference links:
==== CA ======
http://fusesource.com/docs/esb/4.3/amq_security/i305191.html
http://fusesource.com/docs/esb/4.3/amq_security/i382664.html
http://www.linuxquestions.org/questions/linux-networking-3/trouble-generating-ssl-certificates-116973/
http://www.g-loaded.eu/2005/11/10/be-your-own-ca/
http://www.tldp.org/HOWTO/SSL-Certificates-HOWTO/index.html

Keytool: http://www.techbrainwave.com/?p=953

Dynamic keystore: http://jcalcote.wordpress.com/2010/06/22/managing-a-dynamic-java-trust-store/

ไม่มีความคิดเห็น: