Chapter 5
Chapter 5
Spring 2022
2/20/2022 Chapter 5 2
Web Security Considerations
2/20/2022 Chapter 5 3
Web Security Considerations
2/20/2022 Chapter 5 4
A Comparison of Threats on the Web
2/20/2022 Chapter 5 5
A Comparison of Threats on the Web
Threats Consequences Countermeasures
2/20/2022 Chapter 5 6
Relative Location of Security Facilities in the
TCP/IP Protocol Stack
2/20/2022 Chapter 5 7
Secure Sockets Layer (SSL)
• One of the most widely used security services (in the past)
• A general purpose service implemented as a set of protocols that rely
on TCP
• Could be provided as part of the underlying protocol suite and therefore be
transparent to applications
• Can be embedded in specific packages
2/20/2022 Chapter 5 8
2/20/2022 Chapter 5 9
Transport Layer Security (TLS)
2/20/2022 Chapter 5 10
Transport Layer Security (TLS)
2/20/2022 Chapter 5 11
Transport Layer Security (TLS)
• Differences include:
• Version number
• Message Authentication Code
• Pseudorandom function
• Alert keys
• Cipher suites
• Client certificate types
• Certificate_verify and Finished Messages
• Cryptographic computations
• Padding
2/20/2022 Chapter 5 12
TLS Architecture
2/20/2022 Chapter 5 13
TLS Protocol Stack
2/20/2022 Chapter 5 14
TLS Architecture
2/20/2022 Chapter 5 15
TLS Architecture
2/20/2022 Chapter 5 16
TLS Architecture
2/20/2022 Chapter 5 17
A session state is defined by the following
parameters:
• Session identifier
• An arbitrary byte sequence chosen by the server to identify an active or resumable
session state
• Peer certificate
• An X509.v3 certificate of the peer; this element of the state may be null
• Compression method
• The algorithm used to compress data prior to encryption
• Cipher spec
• Specifies the bulk data encryption algorithm and a hash algorithm used for MAC
calculation; also defines cryptographic attributes such as the hash_size
• Master secret
• 48-byte secret shared between the client and the server
• Is resumable
• A flag indicating whether the session can be used to initiate new connections
2/20/2022 Chapter 5 18
A connection state is defined by
the following parameters:
• Server and client random
• Byte sequences that are chosen by the server and client for each connection
• Server write MAC secret
• The secret key used in MAC operations on data sent by the server
• Client write MAC secret
• The secret key used in MAC operations on data sent by the client
• Server write key
• The secret encryption key for data encrypted by the server and decrypted by
the client
• Client write key
• The symmetric encryption key for data encrypted by the client and decrypted
by the server
2/20/2022 Chapter 5 19
A connection state is defined by
the following parameters:
• Initialization vectors
• When a block cipher in CBC mode is used, an initialization vector (IV) is
maintained for each key
• This field is first initialized by the TLS Handshake Protocol
• The final ciphertext block from each record is preserved for use as the IV with
the following record
• Sequence numbers
• Each party maintains separate sequence numbers for transmitted and
received messages for each connection
• When a party sends or receives a change cipher spec message, the
appropriate sequence number is set to zero
• Sequence numbers may not exceed 264 - 1
2/20/2022 Chapter 5 20
TLS Record Protocol
The TLS Record Protocol provides two services for TLS connections
• Confidentiality
• The Handshake Protocol defines a shared secret key that is used for conventional
encryption of TLS payloads
• Message integrity
• The Handshake Protocol also defines a shared secret key that is used to form a message
authentication code (MAC)
2/20/2022 Chapter 5 21
TLS Record Protocol
2/20/2022 Chapter 5 22
TLS Record Protocol
2/20/2022 Chapter 5 23
TLS Record Protocol
• For block encryption, padding may be added after the MAC prior to
encryption. The padding is in the form of a number of padding bytes
followed by a one byte indication of the length of the padding. The
padding can be any amount that results in a total that is a multiple of
the cipher’s block length, up to a maximum of 255 bytes.
• For example, if the cipher block length is 16 bytes (e.g., AES) and
if the plaintext (or compressed text if compression is used) plus MAC
plus padding length byte is 79 bytes long, then the padding length (in
bytes) can be 1, 17, 33, and so on, up to 161. At a padding length of
161, the total length is 79 + 161 = 240. A variable padding length may
be used to frustrate attacks based on an analysis of the lengths of
exchanged messages.
2/20/2022 Chapter 5 24
TLS Record Protocol
2/20/2022 Chapter 5 25
TLS Record Protocol
2/20/2022 Chapter 5 26
Change Cipher Spec Protocol
2/20/2022 Chapter 5 27
Alert Protocol
• The Alert Protocol is used to convey TLS-related alerts to the peer entity.
• As with other applications that use TLS, alert messages are compressed
and encrypted, as specified by the current state.
• Each message in this protocol consists of two bytes.
• The first byte takes the value warning (1) or fatal (2) to convey the severity
of the message.
• If the level is fatal, TLS immediately terminates the connection. Other
connections on the same session may continue, but no new connections
on this session may be established.
• The second byte contains a code that indicates the specific alert.
2/20/2022 Chapter 5 28
Alert Protocol
2/20/2022 Chapter 5 29
Alert Protocol
2/20/2022 Chapter 5 30
Alert Protocol
2/20/2022 Chapter 5 32
Alert Protocol
2/20/2022 Chapter 5 33
Alert Protocol
2/20/2022 Chapter 5 34
TLS Record Protocol Operation
2/20/2022 Chapter 5 35
TLS Record Format
2/20/2022 Chapter 5 36
TLS Record Protocol Payload
2/20/2022 Chapter 5 37
Handshake Protocol
2/20/2022 Chapter 5 38
Handshake Protocol
2/20/2022 Chapter 5 39
TLS Handshake Protocol Message Types
2/20/2022 Chapter 5 40
Handshake Protocol
2/20/2022 Chapter 5 41
Handshake Protocol Action
2/20/2022 Chapter 5 42
Phase 1. Establish Security Capabilities
2/20/2022 Chapter 5 44
Phase 1. Establish Security Capabilities
The first element of the Ciphersuite parameter is the key exchange method (i.e., the means by which the cryptographic keys
for conventional encryption and MAC are exchanged). The following key exchange methods are supported.
• RSA: The secret key is encrypted with the receiver’s RSA public key. A public-key certificate for the receiver’s key must be
made available.
• Fixed Diffie–Hellman: This is a Diffie–Hellman key exchange in which the server’s certificate contains the Diffie–Hellman
public parameters signed by the certificate authority (CA). That is, the public-key certificate contains the Diffie–Hellman
public-key parameters. The client provides its Diffie–Hellman public-key parameters either in a certificate, if client
authentication is required, or in a key exchange message. This method results in a fixed secret key between two peers
based on the Diffie–Hellman calculation using the fixed public keys.
• Ephemeral Diffie–Hellman: This technique is used to create ephemeral (temporary, one-time) secret keys. In this case, the
Diffie–Hellman public keys are exchanged and signed using the sender’s private RSA or DSS key. The receiver can use the
corresponding public key to verify the signature. Certificates are used to authenticate the public keys. This would appear
to be the most secure of the three Diffie–Hellman options because it results in a temporary, authenticated key.
• Anonymous Diffie–Hellman: The base Diffie–Hellman algorithm is used with no authentication. That is, each side sends its
public Diffie–Hellman parameters to the other with no authentication. This approach is vulnerable to man-in-the-middle
attacks, in which the attacker conducts anonymous Diffie–Hellman with both parties.
2/20/2022 Chapter 5 45
Phase 1. Establish Security Capabilities
2/20/2022 Chapter 5 46
Phase 2. Server Authentication and Key
Exchange
• The server begins this phase by sending its certificate if it needs to
be authenticated; the message contains one or a chain of X.509
certificates.
• The certificate message is required for any agreed-on key exchange
method except anonymous Diffie–Hellman. Note that if fixed Diffie–
Hellman is used, this certificate message functions as the server’s key
exchange message because it contains the server’s public Diffie–
Hellman parameters.
2/20/2022 Chapter 5 47
Phase 2. Server Authentication and Key
Exchange
• Next, a server_key_exchange message may be sent if it is required. It is not required in two
instances: (1) The server has sent a certificate with fixed Diffie–Hellman parameters; or (2) RSA
key exchange is to be used.
The server_key_exchange message is needed for the following:
• Anonymous Diffie–Hellman: The message content consists of the two global Diffie–Hellman
values (a prime number and a primitive root of that number) plus the server’s public Diffie–
Hellman key.
• Ephemeral Diffie–Hellman: The message content includes the three Diffie–Hellman parameters
provided for anonymous Diffie–Hellman plus a signature of those parameters.
• RSA key exchange (in which the server is using RSA but has a signature-only RSA key):
Accordingly, the client cannot simply send a secret key encrypted with the server’s public key.
Instead, the server must create a temporary RSA public/private key pair and use the
server_key_exchange message to send the public key. The message content includes the two
parameters of the temporary RSA public key (exponent and modulus) plus a signature of those
parameters.
2/20/2022 Chapter 5 48
Phase 2. Server Authentication and Key
Exchange
Next, a nonanonymous server (server not using anonymous Diffie–
Hellman) can request a certificate from the client. The
certificate_request message includes two parameters: certificate_type
and certificate_authorities.
The certificate type indicates the public-key algorithm and its use:
• RSA, signature only
• DSS, signature only
• RSA for fixed Diffie–Hellman; in this case the signature is used only
for authentication, by sending a certificate signed with RSA
• DSS for fixed Diffie–Hellman; again, used only for authentication
2/20/2022 Chapter 5 49
Phase 2. Server Authentication and Key
Exchange
• The second parameter in the certificate_request message is a list of
the distinguished names of acceptable certificate authorities.
• The final message in phase 2, and one that is always required, is the
server_done message, which is sent by the server to indicate the end
of the server hello and associated messages. After sending this
message, the server will wait for a client response. This message has
no parameters.
2/20/2022 Chapter 5 50
Phase 3. Client Authentication and Key
Exchange
• Upon receipt of the server_done message, the client should verify
that the server provided a valid certificate (if required) and check that
the server_hello parameters are acceptable. If all is satisfactory, the
client sends one or more messages back to the server.
• If the server has requested a certificate, the client begins this phase
by sending a certificate message. If no suitable certificate is available,
the client sends a no_certificate alert instead.
2/20/2022 Chapter 5 51
Phase 3. Client Authentication and Key
Exchange
Next is the client_key_exchange message, which must be sent in this phase.
The content of the message depends on the type of key exchange, as follows:
• RSA: The client generates a 48-byte pre-master secret and encrypts with
the public key from the server’s certificate or temporary RSA key from a
server_ key_exchange message. Its use to compute a master secret is
explained later.
• Ephemeral or Anonymous Diffie–Hellman: The client’s public Diffie–
Hellman parameters are sent.
• Fixed Diffie–Hellman: The client’s public Diffie–Hellman parameters
were sent in a certificate message, so the content of this message is null.
2/20/2022 Chapter 5 52
Phase 4. Finish
2/20/2022 Chapter 5 53
Cryptographic Computations
2/20/2022 Chapter 5 54
Pseudorandom Function
2/20/2022 Chapter 5 55
Pseudorandom Function
2/20/2022 Chapter 5 56
TLS Function P_hash(secret, seed)
2/20/2022 Chapter 5 57
Heartbeat Protocol
2/20/2022 Chapter 5 58
SSL/TLS ATTACKS
2/20/2022 Chapter 5 59
SSL/TLS ATTACKS
2/20/2022 Chapter 5 60
HTTPS (HTTP over SSL)
2/20/2022 Chapter 5 61
HTTPS (HTTP over SSL)
2/20/2022 Chapter 5 62
Connection Initiation
• For HTTPS, the agent acting as the HTTP client also acts as the TLS client
• The client initiates a connection to the server on the appropriate port and then
sends the TLS ClientHello to begin the TLS handshake
• When the TLS handshake has finished, the client may then initiate the first HTTP
request
• All HTTP data is to be sent as TLS application data
• There are three levels of awareness of a connection in HTTPS:
• At the HTTP level, an HTTP client requests a connection to an HTTP server by sending
a connection request to the next lowest layer
• Typically the next lowest layer is TCP, but it may also be TLS/SSL
• At the level of TLS, a session is established between a TLS client and a TLS server
• This session can support one or more connections at any time
• A TLS request to establish a connection begins with the establishment of a TCP
connection between the TCP entity on the client side and the TCP entity on the
server side
2/20/2022 Chapter 5 63
Connection Closure
• An HTTP client or server can indicate the closing of a connection by including the
following line in an HTTP record: Connection: close.
• The closure of an HTTPS connection requires that TLS close the connection with
the peer TLS entity on the remote side, which will involve closing the underlying
TCP connection
• TLS implementations must initiate an exchange of closure alerts before closing a
connection
• A TLS implementation may, after sending a closure alert, close the connection without
waiting for the peer to send its closure alert, generating an “incomplete close”
2/20/2022 Chapter 5 64
Secure Shell (SSH)
2/20/2022 Chapter 5 66
Secure Shell (SSH)
2/20/2022 Chapter 5 67
Transport Layer Protocol
• Server authentication occurs at the transport layer, based on the server possessing a
public/private key pair
• A server may have multiple host keys using multiple different asymmetric encryption
algorithms
• Multiple hosts may share the same host key
• The server host key is used during key exchange to authenticate the identity of the
host
• RFC 4251 dictates two alternative trust models:
• The client has a local database that associates each host name with the corresponding public
host key
• The host name-to-key association is certified by a trusted certification authority (CA); the
client only knows the CA root key and can verify the validity of all host keys certified by
accepted CAs
2/20/2022 Chapter 5 68
Packet Exchange
2/20/2022 Chapter 5 69
SSH
Transport
Layer
Protocol
Packet
Exchanges
2/20/2022 Chapter 5 70
Packet Exchange
2/20/2022 Chapter 5 71
Packet Exchange
2/20/2022 Chapter 5 72
SSH Transport Layer Protocol Packet
Formation
2/20/2022 Chapter 5 73
SSH Transport
Layer
Cryptographic
Algorithms
2/20/2022 Chapter 5 74
Authentication Methods
• Publickey
• The client sends a message to the server that contains the client’s public key, with
the message signed by the client’s private key
• When the server receives this message, it checks whether the supplied key is
acceptable for authentication and, if so, it checks whether the signature is correct
• Password
• The client sends a message containing a plaintext password, which is protected by
encryption by the Transport Layer Protocol
• Hostbased
• Authentication is performed on the client’s host rather than the client itself
• This method works by having the client send a signature created with the private key
of the client host
• Rather than directly verifying the user’s identity, the SSH server verifies the identity
of the client host
2/20/2022 Chapter 5 75
Connection Protocol
• The SSH Connection Protocol runs on top of the SSH Transport Layer Protocol and
assumes that a secure authentication connection is in use
• The secure authentication connection, referred to as a tunnel, is used by the Connection
Protocol to multiplex a number of logical channels
• Channel mechanism
• All types of communication using SSH are supported using separate channels
• Either side may open a channel
• For each channel, each side associates a unique channel number
• Channels are flow controlled using a window mechanism
• No data may be sent to a channel until a message is received to indicate that window space is
available
• The life of a channel progresses through three stages: opening a channel, data transfer, and
closing a channel
2/20/2022 Chapter 5 76
Example of
SSH
Connection
Protocol
Message
Exchange
2/20/2022 Chapter 5 77
Channel Types
2/20/2022 Chapter 5 78
Port Forwarding
2/20/2022 Chapter 5 79
Port Forwarding
2/20/2022 Chapter 5 80
SSH Transport
Layer Packet
Exchanges
2/20/2022 Chapter 5 81
Summary
• HTTPS
• Connection initiation
• Connection closure
2/20/2022 Chapter 5 82
Summary
2/20/2022 Chapter 5 83
2/20/2022 Chapter 5 84
Reference
• Stallings, W. "Network Security Essentials: Applications and
Standards." (2013).
2/20/2022 Chapter 5 85