squid cache proxy
การนำ Squid มาทำ transparent proxy ส่วนใหญ่จะใน website ต่างๆจะบอกแต่วิธีทำ transparent สำหรับ http (port 80) อย่างเดียว ซึ่งจริงๆแล้ว squid สามารถทำ transparent สำหรับ https (port 443) ได้เช่นกัน แต่ถ้าเราจัดการให้ iptables ทำการ forward https traffic ไปยัง port 3128 (สมมติว่า proxy เปิด port 3128 สำหรับการทำ transparent proxy เอาไว้) เมื่อลองทดสอบดูกลับพบว่าไม่สามารถสามารถใช้งานได้

ทำไมถึงไม่สามารถใช้ squid ทำเป็น tranparent proxy สำหรับ https ได้ เพราะว่า https connection มีการเข้ารหัสก่อนการรับส่งข้อมูล โดยใช้ certificate และ public key private key ซึ่งจะทำให้ squid ที่ทำหน้าที่เป็นตัวกลาง หรือ man in the middle ไม่สามารถถอดและเข้ารหัสใหม่เพื่อดูข้อมูล header ได้ ดังนั้นการแก้ไขปัญหาข้างต้นจะต้องทำให้ squid เป็นตัวกลางได้อย่างสมบูรณ์จะต้อง sign certificate และ public private key สำหรับ squid ขึ้นมาอีกชุดหนึ่ง เพื่อเอาไว้สื่อสารระหว่าง squid กับ client ที่ทำการร้องขอการใช้งาน https

สำหรับการ sign certificate สามารถทำได้ทั้งแบบ sign certificate จาก Certificate Authority (CA) ต่างๆ และ self signed certificates หรือ sign เอง ซึ่งจะมีข้อเสียคือ เวลาเข้าเวปต่างๆ browser จะขึ้นเตือนผู้ใช้ว่า certificates นี้ไม่มีความน่าเชื่อถือ ตามรูปด้านล่าง

site's security certificate is not trusted

เอาละมาถึงขั้นตอนการ config transparent proxy สำหรับ https กัน โดยจะมีขั้นตอนคร่าวๆดังนี้

  1. สร้าง certificate และ public private key
  2. Config iptables
  3. Config squid ให้สามารถทำ transparent proxy สำหรับ https

สำหรับขั้นตอนการทำ transparent proxy สำหรับ https อย่างละเอียดสามารถทำตามขั้นตอนด้านล่างได้เลย

  1. สร้าง certificate และ public private key ด้วยการใช้ genkey utility
    • ติดตั้ง crypto-utils ถ้ามีแล้วข้ามขั้นตอนนี้ได้เลย
      [shell][root@ezylinux ~]# yum -y install crypto-utils[/shell]
    • รันคำสั่ง genkey เพื่อสร้าง certificate และ public private key
      [shell][root@ezylinux ~]# genkey -days 365 squidserver.ezylinux.com[/shell]

      • เลือก next.
      • เลือก 1024
      • จากนั้นจะขึ้นหัวข้อ Generate CSR ให้เลือก no และโปรแกรมจะให้กรอกรายละเอียดต่างๆ ตามตัวอย่างด้านล่าง
        Country Name (ISO 2 letter code) TH
        State or Province Name (full name) Bangkok
        Locality Name (e.g. city) Bangkok
        Organization Name (eg, company) Ezylinux co ltd
        Organizational Unit Name (eg, section)
        Common Name (fully qualified domain name) squidserver.ezylinux.com
      • และกด next
      • เลือก next (ไม่ต้องเลือก Encrypt the private key)
      • เมื่อเสร็จขั้นตอนนี้แล้ว Certificate และ key จะเก็บอยู่ที่
        /etc/pki/tls/certs/ สำหรับ Certificate
        /etc/pki/tls/private/ สำหรับ key
  2. Config iptables
    [shell][root@ezylinux ~]# iptables -t nat -A PREROUTING -i eth0 -p tcp –dport 443 -j REDIRECT –to-port 3129[/shell]
  3. Config squid
    แก้ไขไฟล์ /etc/squid/squid.conf โดยเพิ่ม
    [text]https_port 3129 transparent cert=/”path to server.crt” key=/”path to server.key”[/text]ตัวอย่างเช่น
    [text]https_port 3129 transparent cert=/etc/pki/tls/certs/squidserver.ezylinux.com.crt key=/etc/pki/tls/private/squidserver.ezylinux.com.key[/text]

อ่านวิธีการ Setup transparent proxy ด้วย squid