เข้ารหัสการรับส่งแอพไคลเอน

/th/images/install-stunnel-on-windows.png

เครื่องมือ STANNEL สามารถใช้เป็นบริการพร็อกซีเพื่อสร้างอุโมงค์ TLS ที่ปลอดภัยสำหรับแอพเครือข่ายไคลเอนต์-เซิร์ฟเวอร์ที่ไม่รองรับการเข้ารหัสด้วยตนเอง ในบางกรณีการใช้เครื่องมือนี้จะดีกว่าเพื่อรักษาความปลอดภัยการเข้าถึงระยะไกลไปยังแอพเดียว (บริการ) แทนที่จะใช้โซลูชัน VPN ที่มีคุณสมบัติครบถ้วน

ที่

ทำให้ตกใจ

บริการสามารถเรียกใช้ในโหมดเซิร์ฟเวอร์หรือไคลเอนต์ ในโหมดไคลเอนต์ Stunnel ได้รับปริมาณการใช้งานจากแอพไคลเอนต์เข้ารหัสแล้วส่งไปยังเซิร์ฟเวอร์ การจราจรถูกถอดรหัสในไฟล์

STANNEL SERVER

จากนั้นส่งไปยังแอพหรือบริการเป้าหมาย สิ่งสำคัญคือผู้ดูแลระบบ

ไม่จำเป็นต้องแก้ไขไคลเอนต์หรือส่วนเซิร์ฟเวอร์ของแอพ

ใบรับรอง

สามารถใช้สำหรับการรับรองความถูกต้องของลูกค้า Stunnel รองรับทั้ง Windows และ Linux

มาดูวิธีการใช้ Stunnel เพื่อสร้างการเข้าถึงที่ปลอดภัยระหว่างไคลเอนต์และเซิร์ฟเวอร์ ในตัวอย่างนี้เซิร์ฟเวอร์เป็นโฮสต์ Windows ที่มีเว็บเซิร์ฟเวอร์ IIS ที่ใช้เว็บไซต์ HTTP ที่ไม่ได้เข้ารหัส งานคือการ จำกัด การเข้าถึงเว็บไซต์นี้จากลูกค้าที่มีการรับรองความถูกต้องของใบรับรองและเพื่อเปิดใช้งานการเข้ารหัสการรับส่งข้อมูล

การกำหนดค่าเซิร์ฟเวอร์ stunnel บน Windows

ดาวน์โหลดตัวติดตั้ง smunnel สำหรับ windows จาก https://www.stunnel.org/downloads.html และติดตั้งด้วยการตั้งค่าเริ่มต้นรวมถึง openssl

/th/images/install-stunnel-on-windows.png

ขั้นตอนต่อไปคือการสร้างคีย์และใบรับรองสำหรับ CA, Server และไคลเอนต์ เปิดพรอมต์คำสั่งและนำทางไปยังไดเรกทอรี:

cd" c: \ program files (x86) \ stunnel \ bin "

สร้างคีย์ CA:

openssl genpkey-algorithm rsa-out ca.key

ในกรณีนี้เราไม่ได้ใช้วลีรหัสผ่านเพื่อปกป้องคีย์ส่วนตัวใบรับรอง

สร้างใบรับรอง CA:

`openssl req-new-x509-key ca.key-out ca.crt-subj" /o=woshubltd/ou=it/cn=ca_webserver1.com "

เพิ่มข้อมูลเกี่ยวกับใบรับรองในฟิลด์ SUBJ เพื่อการระบุตัวตนที่ง่าย

สร้างคีย์ส่วนตัวสำหรับเซิร์ฟเวอร์:

openssl genpkey-algorithm rsa-out server.key

สร้างคำขอลงนามใบรับรอง (CSR):

openssl req-key server.key-new-new-new-out server.csr

ใช้รูท CA เพื่อลงนามในใบรับรองเซิร์ฟเวอร์

openssl x509-req-in server.csr-ca ca.crt-cakey ca.key-cacreate-out server.crt-days 365-subj" /o=woshubltd/ou=it/cn=server\_webserver1.com "

ตอนนี้สร้างคีย์ส่วนตัวสำหรับลูกค้า:

openssl genpkey-algorithm rsa-out client.key

สร้างคำขอสำหรับใบรับรองลูกค้า:

client openssl req-key.key-new-new-out.csr

ลงชื่อเข้าใช้ใบรับรองลูกค้า:

openssl x509-req-in client.csr-ca ca.crt-cakey ca.key-cacreate-out client.crt-days 365-subj" /o=woshubltd/ou=it/cn=client1\_webserver1.com " `

บนเว็บเซิร์ฟเวอร์คัดลอกไฟล์ ca.crt, server.crt และเซิร์ฟเวอร์ไปยังไฟล์ c: \ program (x86) \ Stunnel \ config โฟลเดอร์

/th/images/generate-stunnel-certificates.png

แก้ไขไฟล์ stunnel.conf (คุณสามารถล้างการตั้งค่าเริ่มต้น) และเพิ่มการกำหนดค่าต่อไปนี้:


; Write logs to stunnel.logdebug = infooutput = stunnel.log; Strong encryption settings. We assume that both devices have modern CPUs that support AES hardware acceleration. If such encryption settings cause server performance degradation under heavy traffic, you can simplify them.options = CIPHER_SERVER_PREFERENCEoptions = NO_SSLv2options = NO_SSLv3options = NO_TLSv1sslVersion = TLSv1.2sslVersion = TLSv1.3ciphers = ECDHE-RSA-AES256-GCM-SHA384; names (paths) to certificate filescert = server.crtkey = server.keyCAfile = ca.crt; This section contains the configuration of the service that the client will access via Stunnel.ITPoral; This is the IP address and port on which the Stunnel instance should listen for connections.accept = 192.168.158.144:443; or accept = 443; The IP address and port of the service to which the connection should be redirected. In our case, this is a local HTTP site.connect = 127.0.0.1:80; or connect = 80; Always check the remote computer's client certificate. Clients without a certificate will not be able to connect to the service.verify=2

เปิดพอร์ตที่ระบุใน Windows Defender Firewall เพื่อให้สามารถเชื่อมต่อขาเข้าได้ คุณสามารถสร้างกฎไฟร์วอลล์กับ PowerShell

new-netfirewallrule-displayname" itporal\_stunnel\_443 "-direction inbound-localport 443-Protocol TCP-Action อนุญาต

บล็อกการเชื่อมต่อภายนอกไปยังพอร์ต TCP ที่ไม่ปลอดภัย 80 ที่ระดับเราเตอร์หรือระดับไฟร์วอลล์

เรียกใช้ stunnel.exe และตรวจสอบบันทึก GUI เพื่อให้แน่ใจว่าการกำหนดค่าของคุณไม่มีข้อผิดพลาด อินเตอร์เฟสกราฟิกช่วยให้อ่านไฟล์การกำหนดค่าได้อย่างรวดเร็วและดูบันทึกข้อผิดพลาดทันทีซึ่งทำให้การดีบักง่ายขึ้น

1 /th/images/stunnel-server-connection-log-on-windows.png

ปิด stunnel.exe gui โดยคลิกที่สิ้นสุดในเมนูจากนั้นเริ่ม smunnel เป็นบริการ Windows เรียกใช้คำสั่ง:

" c: \ program files (x86) \ stunnel \ bin \ stunnel.exe "-install" c: \ program files (x86) \ stunnel \ config \ stunnel.conf "

บริการ wrapper tls smunnel จะถูกสร้างขึ้น เริ่มต้น:

wrapper เริ่มให้บริการ

กระบวนการ stunnel ฟังบนพอร์ต 443 เมื่อเริ่มต้น

/th/images/install-stunnel-tls-wrapper-service-on-windows.png

ตัวอย่างการกำหนดค่าไคลเอ็นต์ของ client บน Windows

จากนั้นติดตั้ง stunnel จากการกระจายเดียวกันบนอุปกรณ์ Windows ไคลเอนต์ จากนั้นคัดลอกไฟล์ ca.crt, client.crt และ client.key จากเซิร์ฟเวอร์ไปยังไฟล์ c: \ program (x86) \ stunnel \ config โฟลเดอร์

เพิ่มสิ่งต่อไปนี้ในไฟล์การกำหนดค่า smunnel.conf:


ITPoral; Run Stunnel in the client mode.client = yes; Specify the IP address and TCP port through which your service will be accessible to your clients.accept = localhost:8080; the address of the stunnel server to redirect connections toconnect = 192.168.158.144:443; certificate pathsCAfile = ca.crtcert = client.crtkey = client.key; Certificates must be checked explicitly when establishing a connection.verify=2

บันทึกไฟล์การกำหนดค่า ก่อนอื่นให้เรียกใช้ Stunnel ด้วยตนเองและตรวจสอบบันทึกสำหรับข้อผิดพลาด ตอนนี้เมื่อคุณเข้าถึงที่อยู่ localhost: 8080 จากเบราว์เซอร์ Stunnel จะเปลี่ยนเส้นทางการเชื่อมต่อไปยังเซิร์ฟเวอร์ระยะไกล

/th/images/stunnel-redirect-traffic-by-creating-a-secure-tls.png

เพื่อความสะดวกคุณสามารถรวมใบรับรองและคีย์ลงในไฟล์เดียว ตัวอย่างเช่น:

get-cintent client.key, client.crt | set-content client.pem

ในกรณีนี้ระบุเฉพาะต่อไปนี้ในไฟล์การกำหนดค่า STANNEL:


cert = client1.pem

หากทุกอย่างทำงานได้อย่างถูกต้องคุณสามารถเรียกใช้ Stunnel บนลูกค้าเป็นบริการ

stunnel.exe-install

/th/images/stunnel-exe-install-run-client-on-windows.png

ในการเพิกถอนใบรับรอง (ตัวอย่างเช่นที่ถูกบุกรุก) ให้เพิ่มตัวเลือก CRLPATH ในการกำหนดค่าเซิร์ฟเวอร์ Stunnel ระบุเส้นทางไปยังโฟลเดอร์ที่ใบรับรองที่ถูกเพิกถอน (รายการการเพิกถอนใบรับรอง) ในรูปแบบ PEM จะถูกจัดเก็บ

คุณยังสามารถใช้ตัวเลือก Capath เพื่อระบุตำแหน่งของโฟลเดอร์ที่มีใบรับรองที่อนุญาต

*ลิงค์แหล่งที่มา:

https://www.stunnel.org/downloads.html สร้างกฎไฟร์วอลล์กับ PowerShell