Golfreeze.packetlove.com: Life style of Golfreeze Canon400D Family kammtan.com Jazz Freebsd Unix Linux System Admin guitar Music

All about unix linux freebsd and FAQ for Packetlove.com Web hosting , Mail hosting , VoIP + IP PBX server => all application on unix knowledges by golfreeze => Topic started by: golfreeze on มกราคม 23, 2011, 10:09:09 PM

Title: generate certificate for https website on freebsd , centos , debian
Post by: golfreeze on มกราคม 23, 2011, 10:09:09 PM
ปกติเรา สามารถ gen (.csr) request ssl cert ได้

ปกติแล้วผมจะใช้ openssl command ครับจัดยังไงนั้นไปดูกันเลย

โดยเริ่มสั่ง ตามนี้

ทำการสร้างคีย์ Key สำหรับ SSL ที่เป็น Key length ขนาด 2048 bit เพราะทาง NIST องค์กรจัดเรื่อง Key ssl
แนะนำให้ใช้เป็นขนาด 2048 bit ก่อน Jan 2014 เพื่อความปลอดภัยครับ ทำไมถึงเป็นเช่นนั้นจะอธิบายต่อไปในกระทู้ล่างๆ ครับผม
และก็ทำให้ support sha256

#openssl req -new -newkey rsa:2048 -nodes -sha256 -out web.csr
ใส่ข้อมูลต่างๆ ลงไปเช่น พวก ประเทศ ที่อยู่ office

ในกรณีถ้าไม่ได้ ไปซื้อ cert เพื่อความน่าเชื่อถือแล้ว แต่ว่าแค่ gen ใช้ในเครื่องก็สามารถ gen crt
ได้ดังนี้ ครับ
#openssl x509 -req -sha256 -days 365 -in /root/server.csr -signkey /root/server.key -out /root/server.crt
#/usr/bin/openssl req -x509 -sha256 -days 9000 -nodes -newkey rsa:4096 -keyout /etc/exim.key -out /etc/exim.cert

แล้ว copy ไปใน path ที่ไฟล์ extra/httpd-ssl.conf เรียกใช้งานดังนี้

SSLCertificateFile "/usr/local/etc/apache22/server.crt"
SSLCertificateKeyFile "/usr/local/etc/apache22/server.key"

เสร็จทำการ restart apache 1 ครั้ง
#/usr/local/etc/rc.d/apache22 restart

เสร็จแล้วลอง เข้าไปดู ข้อมูลใน certificate ได้ครับ

ถ้าจะสร้างเป็นแบบ SAN cert ที่มีหลายชื่อ ให้ใช้แบบนี้ครับ
#openssl req -new -newkey rsa:2048 -nodes -sha256 -out web.csr -config san.cnf

โดยที่ใน san.cnf มี configure ดังนี้
[ req ]
default_bits       = 2048
distinguished_name = req_distinguished_name
req_extensions = v3_req

[req_distinguished_name]
countryName = TH
countryName_default = TH
stateOrProvinceName = Bangkok
stateOrProvinceName_default = Bangkok
localityName = Pakkred
localityName_default = Pakkred
organizationalName = Packetlove
organizationalName_default = Packetlove
organizationalUnitName = IT
organizationalUnitName_default = IT
commonName                 = golfreeze.com
commonName_max = 64

[ v3_req ]
# Extensions to add to a certificate request
basicConstraints = CA:FALSE
keyUsage = nonRepudiation, digitalSignature, keyEncipherment
subjectAltName = @alt_names

[alt_names]
DNS.1   = 2golfreeze2.com
DNS.2   = prim.com
DNS.3   = pkl.com
DNS.4   = domain4.com
Title: Re: generate certificate for https website on freebsd
Post by: golfreeze on มกราคม 23, 2011, 10:09:19 PM
ในกรณี ที่ซื้อ cert จาก พวก เว็บ verisign , godaddy ไรงี้ ให้เราทำการ gen ค่าดังนี้

#openssl req -new -newkey rsa:2048 -nodes -sha256 -out web.csr
ใส่ค่า passparse
ใส่ข้อมูลต่างๆ ลงไปเช่น พวก ประเทศ ที่อยู่ office

แล้ว ส่งค่า web.csr เป็นไฟล์ cerificate request ไปให้ทางนั้น เค้าจะ gen server.crt มาให้เรา
แล้วเราก็นำมาเก็บไว้ใน path ที่ httpd-ssl.conf เรียกใช้ ครับ
Title: Re: generate certificate for https website on freebsd
Post by: golfreeze on มิถุนายน 21, 2011, 08:49:10 AM
ถ้าในกรณีที่ เราตั้งให้ apache ทำงานกับ pacemaker และก่อนหน้านั้นเราทำการตั้งค่า passparse ของ ตัว certificate ไว้นะครับ

จะทำให้เกิด error ประมาณว่า

"Init: Unable to read pass phrase [Hint: key introduced or changed before restart?]"

เกิดขึ้นที่ error log ของ ssl ได้ครับ

เราต้องทำการ แทรกตัว passparse key ลงไปกับตัว certificate key ครับโดยวิธีนี้

[root@xxx conf]# cd /etc/httpd/conf/ssl.key
[root@xxx ssl.key]# cp server.key server.key.new
[root@xxx ssl.key]# openssl rsa -in server.key.new -out server.key

ทำการใส่ค่า passparse ที่เราทำการตั้งไว้ก่อนหน้านี้ครับ
Enter pass phrase for server.key.new:
writing RSA key
[root@xxx ssl.key]# vi server.key

เราจะได้ไฟล์ server.key ที่มีการเพิ่ม passparse ไว้ข้างในแล้วครับ สามารถนำไฟล์นี้ ไปใช้ใน config "ssl.conf" ได้เลยครับผม

SSLCertificateKeyFile /etc/httpd/conf/ssl.key/server.key
Title: Re: generate certificate for https website on freebsd
Post by: golfreeze on กุมภาพันธ์ 22, 2013, 12:00:00 PM
เข้าไปเชครายละเอียด ของ cert ผ่าน command

เชคผ่าน Certificate Signing Request (CSR)
#openssl req -text -noout -verify -in CSR.csr

เชคผ่าน private key
#openssl rsa -in privateKey.key -check

เชคผ่าน certificate file
#openssl x509 -in certificate.crt -text -noout

เชคผ่าน PKCS#12 file (.pfx or .p12)
#openssl pkcs12 -info -in keyStore.p12

เชคผ่าน client cert ที่เว็บไซท์  www.paypal.com รวมถึงดู intermediate cert
#openssl s_client -connect www.paypal.com:443 (http://www.paypal.com:443)
#openssl s_client -connect smtp.ntt.co.th:465 | more

หลังจากเจอข้อมูล certificate สามารถ copy cert นั้นใส่ file notepad แล้วเปิดได้ -> c.crt
ก็จะทราบข้อมูลเพิ่มเติมได้ครับ
Title: Re: generate certificate for https website on freebsd
Post by: golfreeze on พฤษภาคม 14, 2013, 09:52:47 AM
 :) ปกติแล้วการ generate certificate เพื่อใช้งานกับ website หนึ่งนั้น
จะมีวิธีรูปแบบที่ใช้ encryption นั้นต่างๆ กันไป คือสร้างโดย คำสั่ง openssl บ้าง
ซึ่งก็จะแบ่งเป็นแบบ เข้ารหัส 128bit, 192bit , 256bit ซึ่งแต่ละตัวก็จะมีรอบของการเข้ารหัสที่เพิ่มไปเรื่อยๆ

เช่น 128 bit ก็จะมีการทำรหัสถึง 10 รอบ (cycle of repitation)
ซึ่งแต่ละรอบเองก็จะทำ
1.Key expansion
2.Initial round
3.Rounds
4.Final round

ซึ่งปัจจุบันการที่จะ hack certificate file ที่ gen เป็นขนาด 1024 bit ต้องใช้เวลานานถึง 6,000 ล้านๆปีเลยทีเดียว โดยผ่านวิธีการ brute force
ซึ่งถ้าไม่เป็นข้อมูลที่โคตรลับจริงๆ คงไม่เสียเวลาขนาดนั้น แท้ที่จริงการ hack ก็แค่ตอบสนองความมีอยู่ของความเป็นตัวเป็นตน สนองตัณหาความอยากของมนุษย์นั่นเอง
หลงว่าร่างกายจิตใจนี้เป็น ของเราจริงๆ ต้องการสร้างความยิ่งใหญ่ ให้กับตัวเอง แต่เมื่อท้ายที่สุดก็ต้องยอมรับกับความตาย กันทุกคน
ซึ่ง พระพุทธองค์ ท่านเคยบอกไว้ ว่า "ตัณหา เสมอกับห้วงน้ำ นั้นไม่มี"

และ ณ ปัจจุบันการใช้งาน certificate file ที่ความยาว 1024 bit ก็เริ่มจะไม่เป็นที่นิยม และทาง Nist (US National Institute of Standards and Technology’s)
องค์กรที่จัดระเบียบการจัดการ เรื่อง Key ก็ออกมาแนะนำว่า 1024bit RSA key นั้นไม่ควรใช้หลังจากปี 2010 แต่ให้หันมาใช้งานเป็น แบบ 2048bit แทนครับ เพื่อความปลอดภัยยิ่งขึ้น
ซึ่งหลังจาก วันที่ 1 Jan 2014 ถ้าจะใช้งาน certificate จะต้องใช้งานเป็น 2048-bit key length เป็นอย่างน้อย
Title: Re: generate certificate for https website on freebsd
Post by: golfreeze on พฤษภาคม 14, 2013, 09:54:35 AM
##certificate แบบ key length 2048bit ดีอย่างไรอ่านดูได้ที่นี่นะ ครับผม
http://www.thawte.com/resources/2048-bit-compliance/index.html
Title: Re: generate certificate for https website on freebsd
Post by: golfreeze on พฤษภาคม 14, 2013, 10:09:38 AM
การ Convert a DER file (.crt .cer .der) to PEM
#openssl x509 -inform der -in certificate.cer -out certificate.pem

การ Convert a PEM file to DER
#openssl x509 -outform der -in certificate.pem -out certificate.der

การ Convert a PKCS#12 file (.pfx .p12) containing a private key and certificates to PEM
#openssl pkcs12 -in keyStore.pfx -out keyStore.pem -nodes

Title: Re: generate certificate for https website on freebsd
Post by: golfreeze on พฤษภาคม 14, 2013, 10:20:58 AM
#Market share ในส่วนของ Certificate Provider ในปัจจุบัน
    Symantec (which owns VeriSign, Thawte and Geotrust) with 42.9% market share
    Comodo with 26%
    GoDaddy with 14%
    GlobalSign with 7.7%
Title: Re: generate certificate for https website on freebsd
Post by: golfreeze on พฤษภาคม 14, 2013, 02:37:28 PM
เรื่องการ crack certificate key length 1024bit , 768 bit
http://www.digicert.com/TimeTravel/math.htm
http://www.engadget.com/2010/03/09/1024-bit-rsa-encryption-cracked-by-carefully-starving-cpu-of-ele/
Title: Re: generate certificate for https website on freebsd , centos , debian
Post by: golfreeze on พฤษภาคม 16, 2013, 08:11:51 AM
สำหรับข้อแตกต่างระหว่าง SSLv2.0 กับ SSLv3.0

ต้องพูดถึงก่อนว่า SSL คืออะไร (Secure Socket Layer) ก็เป็น ตัวแอปที่ทำการเข้ารหัสข้อมูล เพื่อเพิ่มความปลอดภัยให้กับข้อมูล ที่มีการรับส่ง ระหว่าง
ผู้ใช้บริการระบบ และ เครื่องแม่ข่ายผู้ให้บริการระบบ ต่างๆ บนระบบ internet เพราะว่าถ้าเราไม่ทำการเข้ารหัสข้อมูล จะทำให้ผู้ไม่หวังดี
เข้าถึงข้อมูลนั้น แล้วสร้างความเสียหาย ให้กับข้อมูลนั้นได้

SSLv2.0 เป็นตัวระบบที่พัฒนาขึ้นมาโดย Netscape ตั้งแต่ปี 1994
SSLv3.0 เป็นตัวระบบที่พัฒนาขึ้นในปี ต่อมา คือปี 1995 เพื่อแก้รูรั่วของโปรแกรม SSL เอง

ซึ่งในมุมมองของด้านความปลอดภัย ที่ถูกแก้ไข ก็จะมี

1. SSL version 2.0 มีช่องโหว่เกี่ยวกับเรื่องของ "man-in-the-middle" คือผู้โจมตีสามารถเข้าไปแก้ไข จำนวนบิตที่ใช้ในการเข้ารหัสได้ คือแก้เป็น 40bit
ระหว่างที่มีการส่งข้อมูลไปจากฝั่งของผู้ใช้งาน เพื่อไปยังฝั่งของเครื่องแม่ข่ายเอง แล้วนำข้อมูลที่ได้ไปแกะรหัสได้ง่ายขึ้น  โดยที่ SSLv3.0 ทำการแก้ไขช่องโหว่ตรงจุดนี้
โดยการทำ Handshake กับขั้นตอนสุดท้ายในการส่งข้อมูลไปยัง ระบบแม่ข่าย

2. SSL version 2.0 มีจุดอ่อนด้อยเรื่อง MAC construction, ซึ่งถูกปรับปรุงใน SSLversion 3.0

3. SSL 2.0 มีการส่งค่าไปกับ padding MAC เพื่อใช้ในการเข้ารหัสข้อมูล ,
แต่ยกเว้นค่า padding-length เองที่ไม่ได้ทำการเข้ารหัสตัวมันด้วย เหล่า hacker จึงสามารถลบข้อมูลในส่วนนี้ได้ ในท้ายของข้อมูล
ซึ่งจุดนี้เองถูกแก้ไขปรับปรุงใน SSL version 3.0

4. ใน SSL 3.0, ใช้วิธีการเข้ารหัสข้อมูลแบบ Hash เป็นแบบ 128 bits ซึ่งมีการทำรอบของการเข้ารหัส Key ถึง 10 รอบ
และการส่งการเข้ารหัสเอง แต่ใน SSL version 2.0 ใช้แค่การเข้ารหัสแบบ 40 bits

อ่านเพิ่มเติมได้ที่่นี่ ครับ =>
http://stason.org/TULARC/security/ssl-talk/4-11-What-is-the-difference-between-SSL-2-0-and-3-0.html#.UZQtv0qgeZQ#ixzz2TPguJ3V5
Title: Re: generate certificate for https website on freebsd , centos , debian
Post by: golfreeze on มกราคม 07, 2014, 03:06:06 PM
#Cert SSL ราคาถูก

https://www.servertastic.com/cs/basket.asp (https://www.servertastic.com/cs/basket.asp)

#Cert SSL servertastic.com ในกรณีต้องการ re-issue certificate สามารถกรอกข้อมูล เลข order_id , mail , ชื่อweb ที่เราใช้งาน ssl ตาม URL ดังนี้
https://support.servertastic.com/how-do-i-re-issue-my-ssl-certificate/ (https://support.servertastic.com/how-do-i-re-issue-my-ssl-certificate/)
Title: Re: generate certificate for https website on freebsd , centos , debian
Post by: golfreeze on กุมภาพันธ์ 06, 2014, 04:35:19 PM
ปกติเราสามารถ generate certificate ให้กับ domain ที่ใช้งานขึ้นต้นด้วย www. ได้
โดยการ generate .csr ที่ระบุ common name เป็น www.domain.com (http://www.domain.com) ดังนั้น certificate (.crt) ที่ได้รับจาก CA Provider ก็จะสามารถใช้งานได้ทั้ง

www.domain.com (http://www.domain.com)  และ domain.com
ครับผม

ในถรณีถ้า genereate CSR file ให้กับ Cert ที่เป็น wildcard ในส่วนของ common name ให้ระบุเป็น *.domain.com เช่นต้องการสร้าง CSR ของ wildcard domain : packetlove.com

common name จะเป็น *.packetlove.com

หรือถ้ามีกรณี อยากใช้งานเป้น wildcard ของ sub domain เช่น *.th.packetlove.com ก็จะต้องทำการ ซื้อเป็น
*.th.packetlove.com ซึ่งตัว *.packetlove.com จะไม่รองรับ
** และเวลา validate TXT จะต้องไป validate กับ root domain ก็คือ packetlove.com ด้วยทุกครั้ง **
หรือขึ้นกับ requirement ของ CA provider
Title: Re: generate certificate for https website on freebsd , centos , debian
Post by: golfreeze on กันยายน 27, 2016, 11:12:04 PM
การสั่งซื้อ Cert Extended Validation หรือที่เรียกกันว่า EV Cert ซึ่งส่วนใหญ่จะเป็นการเพิ่มความน่าเชื่อถือให้มากขึ้นครับ
ซึ่งจะใช้กับเว็บพวก มี payment online หรือ เว็บธนาคาร ซะส่วนใหญ่ วันนี้ เลยอยากจะเล่าถึงวิธีการขอ cert แบบ EV กันครับ

ซึ่งจะมีศัพท์ทางเทคนิค อยู่ 3 ตัวหลักๆคือ
1. Requestor ซึ่งหมายถึงผู้ทำการขอ cert อาจจะเป็น reseller ที่ทำการสั่งซื้อ cert ให้ลูกค้าก็ได้ครับ
2. Subscriber หรือ Signer ซึ่งหมายถึง เจ้าของโดเมนที่ทำการสั่งซื้อ เช่น Packetlove.com จะซื้อ Cert EV ดังนั้น ควรเป็นผู้มีอำนาจในบริษัท ที่เป็นเจ้าของ domain Packetlove.com เป็นคนลงข้อมูล ชื่อ นามสกุล ของกรรมการ และ ที่อยู่ของบริษัท เป็นภาษาอังกฤษ
3. approver ซึ่งหมายถึงผู้อนุมัติให้ใช้ชื่อ domain นั้นๆ กับ cert EV ในที่นี่ก็หมายถึง ผู้มีอำนาจในบริษัท ที่เป็นเจ้าของ domain Packetlove.com เช่นกัน

เอกสารของบริษัท ที่ต้องเตรียม เพื่อทำการแปลจากภาษาไทย -> ภาษาอังกฤษ เพื่อการตรวจสอบข้อมูลโดย CA ก็จะมี
1. ใบรับรองบริษัท (นิติบุคคล) พร้อมให้กรรมการเซ็นต์ชื่อรับรอง + วันที่ + ตำแหน่ง + ตราประทับของบริษัท
2. ใบ ภพ 20 พร้อมให้กรรมการเซ็นต์ชื่อรับรอง + วันที่ + ตำแหน่ง + ตราประทับของบริษัท
แล้วทำการ สแกนข้อมูลส่งกลับให้ Requestor เพื่อทำการสั่งขอจด Cert EV ต่อไป

ขั้นตอนหลักๆจะมีดังนี้
1. ทำการยืนยันการจด EV Cert ในระบบคำขอ + generate request certificate (.csr) file พร้อมใส่ข้อมูล Cert ให้ครบ
2. ทำการตรวจเอกสารของ บริษัทที่จะจด พร้อมตรวจสอบใบรับรองบริษัท + ใบภพ 20
3. ทำการแปลเอกสารด้านบนเป็นภาษาอังกฤษ
4. หลังจากเอกสารเรียบร้อย จะมีการโทรจาก CA มายืนยันว่าทั้ง Requestor และ Approver + Signer ยืนยันการสั่งซื้อ EV Cert จริงๆ และมีตัวตนจริงๆ ใช่หรือเปล่า
5. หลังจากทุกขั้นตอนตรวจสอบเสร็จ ก็จะทำการออก Certificate ให้กับ Requestor เพื่อนำมาติดตั้งใน Web server ที่มี Openssl ทำงานอยู่ต่อไป
6. ก็เป็นอันเสร็จสิ้นครับ ทั้งหมดนี้ใช้เวลา อย่างมากสุด 5 วันทำการ อย่างเร็วสุด 3 วัน ทำการ ครับผม

ซึ่งทางบริษัทแพ็คเกตเลิฟ ไอทีเซอร์วิส แอนด์ คอนซัลติ้ง จำกัด สามารถทำการจด EV Cert ให้กับท่านที่สนใจได้
พร้อมให้คำปรึกษาในการดำเนินการครับ : )
Title: Re: generate certificate for https website on freebsd , centos , debian
Post by: golfreeze on มกราคม 11, 2017, 02:44:58 PM
##Convert from .crt to .pem
cat server.crt server.key > server.includesprivatekey.pem
Title: Re: generate certificate for https website on freebsd , centos , debian
Post by: golfreeze on มีนาคม 20, 2017, 10:01:10 AM
ทำไมต้องใช้งาน Intermediate Certificate หรือ Chain Certificate SSL

โดยปกติแล้วคุณไม่ต้องเรียกใช้งาน chain certificate ssl ด้วยซ้ำ
เพราะความเป็นจริงแล้วส่วนที่จำเป็นสุดของ การใช้งาน SSL ในเว็บเซิฟเวอร์คือต้องมี
SSLCertificateFile กับ SSLCertificateKey เพื่อการตรวจสอบ

แต่ในปัจจุบันนี้ถ้าคุณใช้งาน Certificate กับตัว WebServer: Apache นั้น เวลามี connection เข้ามาจาก Browser ของ client
โดยปกติแล้ว ฝั่งเว็บเซิฟเวอร์จะให้ข้อมูลตรวจสอบ 3way-handcheck ที่ถูกต้อง
คือตัว SSLCertificateFile เพื่อแจ้งว่าเป็น CA เจ้าใด , Cert หมดอายุหรือยัง , ถูกเพิกถอนใบรับรองหรือไม่

ซึ่งในส่วนของ Browser เองก็มีการเก็บข้อมูลของ CA cert(Root และ Intermediate) ขนาดใหญ่อยู่แล้วในตัว Browser แต่ละตัว
ซึ่งจะมีการ matching check กับทาง CA ว่า Cert ที่ฝั่งเว็บเซิฟเวอร์มีอยู่ ณ ปัจจุบันนั้นถูกต้องเพียงใด ซึ่งบางครั้ง Browser เอง
ไม่สามารถตรวจสอบได้ เนื่องจากว่าใน Browser ไม่มี root CA หรือ Intermediate Cert file 
ที่สามารถคุยกับ Certificate ที่อยู่ในเว็บเซิฟเวอร์ของคุณ
ดังนั้น Intermediate Cert file จึงเข้ามามีบทบาทในส่วนนี้ และเพื่อให้ Browser เข้าใจถึงความสัมพันธ์ที่แท้จริงของการตรวจสอบ
Chain cert : Certificate Key -> Intermediate file -> Certificate file และทำให้แก้ไขปัญหา เรื่องนี้ได้ครับ

เพื่อให้สะดวกขึ้นในคอนฟิคของ Webserver เช่น Apache เองจึงมี directive ที่แนะนำให้เพิ่มลงไปเป็น

SSLCertificateChainFile
หรือไม่ก็
SSLCACertificateFile
เป็นต้น
ซึ่งข้อมูลของสอง directive นี้สามารถ download เพิ่มเติมได้จาก CA Provider ตอนที่เราเจนสร้างขึ้นมาครับ

เช่นตัวอย่างคอนฟิคนี้จะมีการระบุครบทั้งสามเลยครับผม
Listen 443

SSLCertificateFile /home/web/certs/domainpkl.public.crt
SSLCertificateKeyFile /home/web/certs/domainpkl.private.key
SSLCertificateChainFile /home/web/certs/domainpkl.intermediate.crt

ซึ่งในส่วนนี้ถ้าลูกค้าใช้งาน SSL หรือติดตั้ง SSL กับทางบริษัทแพ็คเกตเลิฟฯ ทางเราจะดำเนินการให้เองครับ
ลูกค้าแค่จ่ายเงินแล้วจบ SSL จะถูกติดตั้งด้วยความถูกต้องและเพิ่มความน่าเชื่อให้กับเว็บไซต์ของท่าน ครับผม
ทีมงาน Packetlove.com
Title: Re: generate certificate for https website on freebsd , centos , debian
Post by: golfreeze on มีนาคม 21, 2017, 06:37:38 PM
วิธีการ import certificate from Window OS (certname.pfx) into Apache ssl key file (key.pem)
#openssl pkcs12 -in certname.pfx -nocerts -out key.pem -nodes

วิธีการ import certificate from Window OS (certname.pfx) into Apache ssl Cert file (cert.pem)
#openssl pkcs12 -in certname.pfx -nokeys -out cert.pem

วิธีการ export certificate จาก .crt (apache) -> .pfx ผ่าน openssl
How do I export, as a pfx file, my Certificate and Private Key from Apache?
In order to export the Certificate, Private Key and any intermediate certificate as a pfx file use the command below:
#openssl pkcs12 -export -in my.crt -inkey my.key -certfile my.bundle -out my.pfx
Title: Re: generate certificate for https website on freebsd , centos , debian
Post by: golfreeze on มีนาคม 21, 2017, 06:38:07 PM
Check a certificate

Check a certificate and return information about it(Signing authority, expiration date, etc.)

openssl x509 -in server.crt -text -noout
Check a key

Check the SSL key and verify the consistency.

openssl rsa -in server.key -check
Check a CSR

Verify the CSR and print CSR data filled in when generating the CSR.

openssl req -text -noout -verify -in server.csr
Verify a certificate and key matches

The following two commands will print out md5 sums of the certificate and key. These sums can be compared to verify that the certificate and key match.

openssl x509 -noout -modulus -in server.crt| openssl md5
openssl rsa -noout -modulus -in server.key| openssl md5
Title: Re: generate certificate for https website on freebsd , centos , debian
Post by: golfreeze on มีนาคม 26, 2017, 09:36:32 AM
ปกติแล้วถ้าตอนเราทำการเช็คความถูกต้องของการใส่ Chain cert ใน configure ของ WebServer
ในกรณีนี้ผมยกตัวอย่าง Apache + Mod_SSL นะครับ
หลังจากเราทำการใส่ Chain cert ลงไปแล้ว หลังจากนั้นทำการตรวจสอบแล้วพบว่า
ตรวจสอบกับ https://www.ssllabs.com/ssltest/

Chain issues : Incorrect order, Contains anchor
->เกิดมาจากการจัดลำดับของ CA-bundle สลับกันถึงขึ้นเป็น Incorrect order
->เกิดจากการผสมเอา CARoot กับ CA-bundle รวมในไฟล์เดียวกันถึงแสดงเป็น Contains anchor

แก้ไขโดยให้ทำการตรวจสอบ configure ในไฟล์คอนฟิค ssl.conf หรือ default-ssl.conf ว่าถูกต้องหรือเปล่า เช่น

#ควรใช้ไฟล์ที่ทาง CA ส่งมาเป็นไฟล์ ca-bundle.crt มาใส่ในส่วนนี้ แล้วลองทำการจัดเรียงลำดับให้ถูกต้องครับ
SSLCertificateChainFile /opt/ssl/ca-bundle.ca

#ควรใช้ไฟล์ที่ทาง CA ส่งมาให้เช่นไฟล์ AddTrustExternalCARoot.ca ใส่ในส่วนนี้
SSLCACertificateFile /opt/ssl/CARoot.ca

หลังจากนั้นทำการตรวจสอบกับ SSLLab อีกรอบ ก็จะทำให้แก้ไขปัญหา Incorrect order และ Contains anchor ได้ครับ  ;)

ทีมงาน Packetlove.com
เราให้บริการ Certificate SSL พร้อมการคอนฟิคและให้คำปรึกษาการใช้งาน SSL ครับ
Title: Re: generate certificate for https website on freebsd , centos , debian
Post by: golfreeze on มิถุนายน 16, 2017, 08:31:34 PM
ถ้าในกรณี มีการเช็คสถานะของ SSL บนเว็บนั้นๆ แล้วเจอ DH ที่เป็น CipherSuite เตือนว่ามีความเสี่ยงไม่ปลอดภัย
สามารถแก้ไขด้วยการ อัฟเกรด apache version จาก 2.2.x -> 2.4.x ได้ครับ
###ถ้าใน directadmin ก็เริ่มโดย
cd /usr/local/DirectAdmin/custombuild
./build set apache_ver 2.4
./build update
./build clean
./build apache n
./build php n
service httpd restart

##Increasing DHE strength on Apache 2.4.x

Apache HTTP Server (mod_ssl)

SSL parameters can globally be set in httpd.conf or within specific virtual hosts.

SSLCipherSuite          ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:AES:CAMELLIA:DES-CBC3-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!aECDH:!EDH-DSS-DES-CBC3-SHA:!EDH-RSA-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA

SSLHonorCipherOrder     on
DH Parameters

In newer versions of Apache (2.4.8 and newer) and OpenSSL 1.0.2 or later, you can directly specify your DH params file as follows:

SSLOpenSSLConfCmd DHParameters "{path to dhparams.pem}"
If you are using Apache with LibreSSL, or Apache 2.4.7 and OpenSSL 0.9.8a or later, you can append the DHparams you generated earlier to the end of your certificate file.

Reload configuration

sudo service apache2 reload
Title: Re: generate certificate for https website on freebsd , centos , debian
Post by: golfreeze on พฤศจิกายน 12, 2017, 09:20:57 AM
Convert your SSL Certificate to the Correct File Type

Different servers require different formats of SSL certificates. Our SSL converter tool converts between 6 different file formats quickly and easily. Choose the file format which is required: PEM, DER, PKCS#7, P7B, PKCS#12 or PFX.

DER format

Is a binary form of PEM. It has extension .der or .cer.

DER is typically used with Java platforms. Our Converter can change the type of certificate to this format - to change a private key, please use OpenSSL commands.

PKCS#7 or P7B format

Is usually stored in Base64 format and has extension .p7b or .p7c. Files in this format contain lines "-----BEGIN PKCS7-----" and "-----END PKCS7-----". This format is just for certificates, not for private keys.

PKCS#7 and P7B are installed on Microsoft Windows and Java Tomcat servers.

PKCS#12 or PFX format

Is a binary format storing the server certificate, intermediates certificates, and private key in one file. It usually has the extension .pfx or .p12. Typically, these are used on Windows machines.

When converting PFX format to PEM, one file will include all certificates and the private key.

To separate it, you need to open this file in a simple text editor, copy every single part (with BEGIN and END lines) to different files and save it as certificate.cer, CACert.cer and privatekey.key.
Title: Re: generate certificate for https website on freebsd , centos , debian
Post by: golfreeze on พฤศจิกายน 12, 2017, 10:01:28 AM
การใช้งาน Comodo กับ IIS8

วิธีการ convert จาก .crt -> .cer เพื่อนำไปใช้กับ IIS 8 (บน Window Server)
https://support.comodo.com/index.php?/Knowledgebase/Article/View/361/17/how-do-i-convert-crt-file-into-the-microsoft-cer-format

และตามด้วยการ import ลงไปยัง IIS 8
https://support.comodo.com/index.php?/Knowledgebase/Article/View/1159/37/certificate-installation-microsoft-iis-8x

ถ้าเราทำการ generate .csr จาก openssl แล้วทำการขอ .crt จาก CA ที่ Trust แล้ว
มีโจทย์ว่าต้องการนำ .crt ที่ได้มานั้น ไป import เป็น .pfx เพื่อใช้กับ Window server หรือ IIS 8.x ขึ้นไป จะมีวิธีการดังนี้
1.แปลงจาก p7b เพื่อทำการ import ใน mmc ของ Window server
2.แล้วทำรันการ  certutil เพื่อ repairstore
3.สุดท้ายค่อย export ออกมาเป็น .pfx ลงใน IIS 8.x Server
#certutil -repairstore my "PLACE_SERIAL_NUMBER_HERE"
https://www.ssl.com/how-to/fix-the-iis-7-no-private-key-error-message/
Title: Re: generate certificate for https website on freebsd , centos , debian
Post by: golfreeze on มีนาคม 25, 2018, 09:35:12 PM
การใช้งาน certbot + letencrypt บน centos6.x on Apache

##Reference link
https://certbot.eff.org/all-instructions/
https://certbot.eff.org/lets-encrypt/centos6-apache

เริ่มกันเลย โดยสามารถทำการ download และติดตั้ง python-certbot-apache
wget https://dl.eff.org/certbot-auto
chmod a+x certbot-auto
ทำการสร้าง ssl
./certbot-auto --apache certonly
Title: Re: generate certificate for https website on freebsd , centos , debian
Post by: golfreeze on กันยายน 22, 2018, 10:57:10 AM
In case Cert let encrypt expired , way to renew cert from let encrypt
#gitlab-ctl reconfigure

after that try to access your gitlab url again
https://www.packetlove.com
then check ssl valid date.
Title: Re: generate certificate for https website on freebsd , centos , debian
Post by: golfreeze on พฤศจิกายน 10, 2018, 11:33:43 AM
ในกรณีถ้าเจอ RSA PRIVATE KEY กับ header แบบนี้ แสดงว่ามี รหัสของ encrypted key ครับ
If you have an RSA PRIVATE KEY with headers that look something like:
-----BEGIN RSA PRIVATE KEY-----
Proc-Type: 4,ENCRYPTED
DEK-Info: DES-EDE3-CBC,D061ACF7F7A7D27F
then you would have a password encrypted key.

ให้ทำการ decrypted key โดย command openssl
openssl rsa -in /path/to/your/key -out /the/new/key

แล้วทำการ ปรับ configure ใน ssl.conf ใหม่อีกทีนะครับ
คราวนี้เวลา restart web server ก็ไม่ต้องใส่ passparse แล้ว