บทนำ
รายการ Context options สำหรับ transports ssl:// และ tls://
| peer_name | Peer name ที่จะใช้ หากไม่ตั้งค่า จะเดาจาก hostname ที่ใช้เปิด stream |
|---|---|
| verify_peer | ต้องการการตรวจสอบ SSL certificate ที่ใช้ ค่าเริ่มต้น TRUE |
| verify_peer_name | ต้องการการตรวจสอบ peer name ค่าเริ่มต้น TRUE |
| allow_self_signed | อนุญาต self-signed certificates ต้องการ verify_peer ค่าเริ่มต้น FALSE |
| cafile | พาธของไฟล์ Certificate Authority บน local filesystem เพื่อยืนยันตัวตน remote peer |
| capath | ต้องเป็น certificate directory ที่ hash ถูกต้องแล้ว |
| local_cert | พาธไปยังไฟล์ local certificate บน filesystem |
| local_pk | พาธไปยังไฟล์ local private key บน filesystem กรณีแยกไฟล์ certificate และ private key |
| passphrase | Passphrase ที่ใช้เข้ารหัสไฟล์ local_cert |
| CN_match | Common Name ที่คาดหวัง หาก Common Name ไม่ตรง การเชื่อมต่อจะล้มเหลว |
| verify_depth | ยกเลิกหาก certificate chain ลึกเกินไป |
| ciphers | ตั้งค่ารายการ ciphers ที่ใช้ได้ รูปแบบ string อธิบายใน ciphers(1) |
| capture_peer_cert | หาก TRUE จะสร้าง context option peer_certificate ที่มี peer certificate |
| capture_peer_cert_chain | หาก TRUE จะสร้าง peer_certificate_chain context option ที่มี certificate chain |
| SNI_enabled | หาก TRUE server name indication จะเปิดใช้งาน |
| SNI_server_name | หากตั้งค่า จะใช้เป็น server name สำหรับ SNI มิฉะนั้นจะเดาจาก hostname |
| disable_compression | หากตั้งค่า จะปิด TLS compression |
| peer_fingerprint | ยกเลิกการเชื่อมต่อเมื่อ remote certificate digest ไม่ตรงกับ hash ที่ระบุ |
| security_level | ตั้งค่า security level หากไม่ระบุ ใช้ default security level พร้อมใช้งานตั้งแต่ PHP 7.2.0 และ OpenSSL 1.1.0 |
ตัวอย่าง
ตัวอย่างนี้แสดง SSL context settings
$stream_context = stream_context_create([ 'ssl' => [ 'local_cert' => '/path/to/key.pem', 'peer_fingerprint' => openssl_x509_fingerprint(file_get_contents('/path/to/key.crt')), 'verify_peer' => false, 'verify_peer_name' => false, 'allow_self_signed' => true, 'verify_depth' => 0 ]]);