ITCS 310 · Network Security · Week 09
Transport Level Security: TLS & HTTPS
أمان طبقة النقل: بروتوكول TLS و HTTPS
HTTP vs HTTPS TLS 1.2 & RSA TLS 1.3 & Diffie-Hellman ملزمة ثنائية اللغة
ACADEZI.COM
College of Information Technology
Detailed Teaching Guide · دليل تدريس مفصّل
مكونات الرابط (URL Breakdown) URL Breakdown §1
عندما تكتب رابطاً في المتصفح، يتكون هذا الرابط من عدة أجزاء رئيسية :
When you type a URL into your browser, it consists of several key parts :
http:// eestore.net /product/electric/ phone
Protocol (البروتوكول)
Domain (النطاق)
Path (المسار)
Resource (المورد)
الخطوات الرئيسية عند طلب موقع (Main Steps) What happens when you type a URL? §2
عند كتابة الرابط، تمر العملية بعدة خطوات للوصول إلى الخادم وعرض الصفحة :
When typing the URL, the process goes through several steps to reach the server and display the page :
1
كتابة الرابط
Type URL
تقوم بكتابة الرابط في المتصفح (مثال: http://eestore.net/...).
You type the URL in the browser.
2
البحث عن الـ IP (الذاكرة المؤقتة أو DNS)
DNS Lookup (Cache or Resolver)
يبحث المتصفح عن عنوان IP في ذاكرته المؤقتة (Cache) . إذا لم يجده، يقوم باستعلام DNS متكرر (Recursive Lookup) عبر نظام التشغيل للبحث عنه . الغرض هو تحويل اسم النطاق (Domain) إلى عنوان IP .
Browser looks up IP in cache . If not found, it uses recursive DNS lookup through the OS . The goal is to convert the Domain Name to an IP address .
3
المصافحة الثلاثية عبر TCP
TCP Handshake
يؤسس المتصفح اتصال TCP مع الخادم عبر عملية المصافحة الثلاثية (Three-way handshake) .
Browser performs TCP Three-way handshake process with the server .
4
إرسال واستقبال HTTP
HTTP Request & Response
يرسل المتصفح طلب HTTP للخادم، ويرد الخادم باستجابة HTTP التي تحتوي على بيانات الصفحة .
Browser sends HTTP request, and Server replies with HTTP response .
بروتوكول HTTP (المشكلة) The HTTP Protocol (The Problem) §3
في بروتوكول HTTP، يتم الاتصال بين المتصفح والخادم بـ نص واضح (Plaintext) عبر المنفذ 80 . هذا يعني أن أي بيانات تُرسل (مثل كلمات المرور أو أرقام بطاقات الائتمان) يمكن قراءتها بواسطة أي شخص قادر على اعتراض الاتصال .
In HTTP, communication between browser and server is in plaintext over Port 80 . Entered passwords or credit card numbers sent over the internet can be read by anyone who can intercept it .
Browser
Plaintext Communication
Server (Port 80)
Credit Card / Password
بروتوكول HTTPS (الحل) The HTTPS Protocol (The Solution) §4
لحل مشكلة الاتصال بالنص الواضح، نستخدم HTTPS وهو امتداد لبروتوكول HTTP لتأمين اتصالات الإنترنت . يرسل البيانات بشكل مشفر (Encrypted) عبر المنفذ 443 بحيث تكون البيانات مقروءة فقط للمرسل والمستقبل .
To solve the plaintext problem, we use HTTPS, an extension of HTTP to secure internet connections . It sends data in an encrypted form over Port 443, readable only to the sender and receiver .
Browser
Encrypted Communication 🔒
Server (Port 443)
********************
كيف يعمل؟ يستخدم HTTPS بروتوكول TLS (Transport Layer Security)، وهو خليفة بروتوكول SSL، لتوفير أمان مُحسّن . إذا اعترض خصم (Adversary) هذه البيانات المشفرة، فلن يرى سوى بيانات غير قابلة للاستخدام .
How? HTTPS uses TLS, a successor of SSL, providing improved security . If encrypted data is intercepted by an adversary, all they can see is unusable data .
أين تقع هذه البروتوكولات؟ Relative Location of Security Facilities §5
مستوى الأمان Security Levelالبروتوكولات المستخدمة Protocols
Application LevelKerberos, S/MIME, SSH
Transport LevelSSL or TLS
Network LevelIPSec
الإجراء الرئيسي لبروتوكول TLS TLS: Main Procedure §6
تتكون عملية الاتصال الآمن من 4 مراحل رئيسية :
The secure connection process consists of 4 main phases :
1. TCP Handshake
تأسيس الاتصال باستخدام بروتوكول مصافحة TCP .
Establish connection using TCP handshake .
2. Certificate Check
العميل يرسل الإصدار المدعوم وخوارزميات التشفير (Cipher suite). الخادم يختار الخوارزميات ويرسل شهادته التي تحتوي على مفتاحه العام .
Client sends supported version & cipher suites. Server chooses options and sends its certificate containing its public key .
3. Key Exchange
العميل يُولد مفتاح جلسة (Session key)، ويُشفره باستخدام المفتاح العام للخادم (تشفير غير متماثل Asymmetric)، ثم يرسله للخادم للاتفاق على مفتاح سري مشترك .
Client generates a session key, encrypts it with server's public key (Asymmetric), and sends it to agree on a shared secret .
4. Data Transmission
يتم تبادل البيانات بين العميل والخادم باستخدام التشفير المتماثل (Symmetric key) المُتفق عليه .
Data exchanged using the agreed Symmetric session key .
تفاصيل تبادل الرسائل في مصافحة TLS 1.2 TLS 1.2 Handshake Message Sequence Details §7
الخطوة Step الاتجاه Direction الرسالة Message المحتويات الرئيسية والغرض Contents & Purpose
1Client → ServerClientHello TLS version, ClientRandom (32-byte), supported cipher suites, Session ID.
Purpose: Proposes security parameters .
2Server → ClientServerHello Selected TLS version, ServerRandom (32-byte), chosen cipher suite, Session ID.
Purpose: Chooses cryptographic parameters .
3Server → ClientCertificate Server's X.509 certificate containing public key, domain, CA signature.
Purpose: Authenticates server identity . Client verifies it.
4Server → ClientServerHelloDone No data.
Purpose: Indicates server finished its hello messages .
5Client → ServerClientKeyExchange Encrypted pre-master secret (using RSA) or DH public value.
Purpose: Establishes shared secret .
6Client → ServerChangeCipherSpec Protocol switch indicator.
Purpose: Signals start of encrypted communication .
7Client → ServerFinished Hash of handshake messages encrypted with session key.
Purpose: Verifies handshake integrity .
8Server → ClientChangeCipherSpec Protocol switch indicator.
Purpose: Server begins encrypted communication .
9Server → ClientFinished Encrypted handshake hash.
Purpose: Confirms secure handshake completion .
10Client ↔ ServerApplication Data Encrypted HTTP/HTTPS data.
Purpose: Secure data exchange begins using Symmetric key .
تفاصيل تبادل المفاتيح باستخدام RSA RSA Key Exchange Details §8
هذه العملية تُستخدم لتوليد سر مشترك لإنشاء مفاتيح الجلسة في TLS 1.2 .
This process is used to generate a mutual shared secret to create session keys in TLS 1.2 .
1
توليد الـ Seed
Generate Seed
يولد العميل قيمة عشوائية تسمى Pre-Master Secret .
Client generates a random seed value (Pre-Master Secret) .
2
التشفير والإرسال
Encrypt and Send
يشفر العميل الـ Pre-Master Secret باستخدام المفتاح العام للخادم، ويرسله للخادم عبر الشبكة .
Client encrypts it with server's public key, sends encrypted Pre-Master Secret to server .
3
فك التشفير وتوليد مفاتيح الجلسة
Decrypt and Generate Session Keys
يفك الخادم تشفير القيمة باستخدام مفتاحه الخاص . الآن يمتلك الطرفان سراً مشتركاً. يقومان بحساب الـ Master Secret باستخدام دالة عشوائية (PRF) تُدخل فيها القيم العشوائية السابقة . ثم تُشتق مفاتيح الجلسة المتماثلة (Session Keys) التي ستُستخدم لتشفير البيانات .
Server decrypts with its private key . Both sides have a mutual shared secret. They compute Master Secret = PRF(premaster, client_random, server_random), then derive symmetric Session Keys for data encryption .
لماذا نستخدم التشفير المتماثل (Symmetric) لتبادل البيانات؟ التشفير غير المتماثل (مثل RSA) مُكلف حسابياً (computationally expensive) وغير مناسب لنقل كميات كبيرة من البيانات (bulk data transmission) . لذا نستخدمه فقط لتبادل المفاتيح، ثم ننتقل للتشفير المتماثل .
Why symmetric encryption for data? Asymmetric encryption is computationally expensive; it is not suitable for bulk data transmission .
مشاكل نهج RSA (في الإصدار TLS 1.2) So Far - HTTPS Using RSA Approach (TLS v.1.2) Issues §9
النهج السابق (TLS 1.2 باستخدام RSA) يعاني من مشكلتين أساسيتين :
The discussed approach (TLS 1.2 using RSA) has two main issues :
1. Slow Protocol
بروتوكول بطيء
يستغرق جولتين كاملتين (Two network round trips) بين العميل والخادم لإكمال المصافحة (واحدة للاتفاق على الخوارزميات، والثانية لتبادل المفتاح) .
Takes two network round trips to complete handshake (Agree on Suite + Exchange Key) → slow protocol .
2. Insecure Key Exchange
تبادل مفاتيح غير آمن كلياً
يتم إرسال Pre-Master Key مُشفراً. إذا حصل مهاجم (Adversary) على المفتاح الخاص للخادم (حتى في المستقبل)، سيمكنه فك تشفير هذا المفتاح، ومن ثم فك تشفير كل الجلسة!
Main issue: sending Pre-Master key. Adversary who has server's private key can know the Pre-Master Key → insecure protocol .
الإصدار الأحدث: TLS 1.3 (الحل) HTTPS Using Diffie Hellman Approach = TLS V. 1.3 §10
أحدث إصدار هو TLS 1.3، مدعوم في جميع المتصفحات الرئيسية . يتغلب على مشاكل إرسال الـ Pre-Master Secret المُشفر الموجودة في RSA . يُحسن عملية المصافحة بحيث يتم تقليل جولات الشبكة (Network rounds) إلى جولة واحدة فقط (One trip) بدلاً من جولتين .
Latest version is TLS 1.3. Supported on all major browsers . Overcomes the issue of sending encrypted Pre-Master Secret in RSA . Optimizes handshake process: network rounds are reduced to one trip .
كيف يعمل Diffie-Hellman في تبادل المفاتيح؟ Diffie-Hellman for Key Exchange §11
المبدأ: إرسال معلومات حول المفتاح، وليس إرسال المفتاح الفعلي نفسه .
Principle: Send information about the key, but not sending the actual key .
Mechanism
الآلية
يتم دمج المفتاح الخاص مع المفتاح العام (Combining Private with Public)، والنتيجة هي ما يُرسل عبر الشبكة، وهي غير قابلة للكسر (Unbreakable) . المفاتيح الخاصة لا تُرسل أبداً عبر الشبكة .
Combining Private with Public → Can be sent over the wire (Unbreakable) . Private keys are never sent over the wire; only the public key .
TLS 1.3 Implementation
تطبيقها في TLS 1.3
يستخدم TLS 1.3 مفتاح Diffie-Hellman عام عابر (Ephemeral). يتم توليد مفاتيح خاصة جديدة في كل مرة (مما يوفر ميزة السرية التامة للأمام Forward Secrecy) . عن طريق دمج المفاتيح الثلاثة، يمكن للطرفين توليد المفتاح المتماثل .
In TLS 1.3: Ephemeral Diffie-Hellman public key is used, private keys are generated each time . Combining keys can generate the symmetric key by the party .
Diffie-Hellman Key Exchange Logic
Client Private Key
+ Public Key ↔ Public Key +
Server Private Key
= Identical Symmetric Session Key =
ملاحظات ختامية حول TLS TLS Remarks & Summary §12
  • يُستخدم TLS لتأمين (تشفير) البيانات المرسلة عبر الشبكة .
  • TLS هو البروتوكول اللاحق (Successor) لبروتوكول SSL (Secure Socket Layer) .
  • يمكن استخدام TLS مع بروتوكولات تطبيق مختلفة :
    TLS + HTTP = HTTPS
    TLS + SMTP = SMTPS
    TLS + FTP = FTPS
TLS secures data over the network and is the successor of SSL . It can be combined with different protocols (HTTPS, SMTPS, FTPS) .