Lesson 16 intermediate

Session and Presentation Layers

What OSI layers 5 and 6 do and where those jobs live today: sessions, checkpoints and RPC (from Sun RPC to gRPC), PPTP and why it is obsolete, character encoding, Base64 and MIME, serialization formats, compression, and SSL/TLS with certificates and the TLS 1.3 handshake.

In the TCP/IP model there is no separate session or presentation layer: those jobs are done by the application or by libraries it uses. But the jobs themselves are real and every networked program needs them: keep track of a conversation (session) and agree on how data is represented and protected (presentation). Knowing them helps you understand TLS, RPC frameworks, email attachments and why text sometimes turns into é garbage.

Session layer: managing conversations

The session layer’s classic responsibilities:

  • Establish, maintain and end a dialogue between two applications.
  • Dialog control: who may talk when (half or full duplex at the conversation level).
  • Synchronization and checkpoints: mark points in a long transfer so it can resume from the last checkpoint instead of the start.
  • Authentication and session state: remember who the user is across many requests.

Where you see these ideas today:

IdeaModern example
Session stateWeb login cookies and session tokens, kept on top of stateless HTTP
Session resumptionTLS session tickets, which skip most of the handshake for returning clients
CheckpointsResumable downloads with HTTP Range requests, rsync --partial
Dialog controlSIP call setup, the WebSocket opening handshake
$ curl -s -o part1 -r 0-1048575 https://example.com/big.iso
$ curl -s -C - -o big.iso https://example.com/big.iso

-r downloads a byte range and -C - resumes from where the file ends: checkpointing on top of HTTP.

Remote Procedure Call (RPC)

RPC lets a program call a function on another machine as if it were local. A stub on the client turns the call and its arguments into a message (marshalling), sends it, waits, and turns the reply back into a return value. The network becomes almost invisible, which is both the strength and the danger: remote calls can be slow or fail halfway, and code must handle that.

GenerationExamplesEncoding
ClassicSun ONC RPC (used by NFS), DCE/RPC and Microsoft RPC (used by Active Directory)XDR, NDR
Web eraXML-RPC, SOAP, JSON-RPCXML, JSON
TodaygRPC (HTTP/2, Protocol Buffers), Thrift, JSON-RPC in tools like the Language Server Protocol and MCPBinary or JSON
$ rpcinfo -p nfs-server.lan | head -4
   program vers proto   port  service
    100000    4   tcp    111  portmapper
    100003    4   tcp   2049  nfs
    100005    3   udp  20048  mountd
$ grpcurl -plaintext localhost:50051 list
grpc.health.v1.Health
orders.v1.OrderService

PPTP

The Point-to-Point Tunneling Protocol was an early Microsoft VPN: a control session on TCP 1723 plus GRE to carry PPP frames. Its authentication (MS-CHAPv2) and encryption (MPPE) were broken years ago, and an attacker can recover the password from a captured session. Do not use PPTP. Use WireGuard, IPsec/IKEv2 or a TLS-based VPN instead. Some textbooks list it under the session layer because it manages the tunnel’s session.

Presentation layer: the shape of data

The presentation layer makes sure the receiver can understand what the sender meant. Three jobs: translation (encoding and format), compression and encryption.

Character encoding

Text is just bytes until both sides agree on an encoding. UTF-8 is the standard today: ASCII characters take one byte, others take two to four.

$ printf 'é' | xxd
00000000: c3a9                                     ..
$ printf 'é' | iconv -f latin1 -t utf-8
é

The second command decodes UTF-8 bytes as if they were Latin-1, producing the infamous é. Mojibake like that always means a sender and receiver disagree on the encoding. HTTP declares it in Content-Type: text/html; charset=utf-8.

Base64 and MIME

Many protocols (email especially) were designed for 7-bit text. Base64 encodes any bytes using 64 safe characters, at a cost of about 33% more size.

$ printf 'Network' | base64
TmV0d29yaw==
$ echo 'TmV0d29yaw==' | base64 -d
Network

MIME (Multipurpose Internet Mail Extensions) lets one email carry several parts: plain text, HTML and attachments, each with its own content type and encoding:

Content-Type: multipart/mixed; boundary="b1"

--b1
Content-Type: text/plain; charset=utf-8

Report attached.
--b1
Content-Type: application/pdf; name="report.pdf"
Content-Transfer-Encoding: base64

JVBERi0xLjcKJcfsj6IKNSAwIG9iago8PC9MZW5ndGggNiAwIFIvRmlsdGVyIC9GbGF0ZUR...
--b1--

MIME types escaped email long ago: HTTP’s Content-Type: application/json and image/webp are MIME types too.

Serialization formats

FormatStyleStrength
JSONTextHuman readable, universal in web APIs
XMLTextSchemas and namespaces; SOAP and many enterprise systems
YAMLTextConfig files (Kubernetes, Ansible)
Protocol BuffersBinarySmall, fast, typed; used by gRPC
MessagePack, CBOR, AvroBinaryCompact JSON-like data, IoT, data pipelines

Binary formats also settle byte order: networks send multi-byte numbers big-endian (“network byte order”), while x86 and ARM CPUs store them little-endian, so code converts with functions like htons().

Compression

Compressing before sending saves bandwidth, especially for text. Browsers announce what they accept and servers pick one:

$ curl -sI -H 'Accept-Encoding: br, gzip' https://blog.jefersonjeronimoai.online/ | grep -i content-encoding
Content-Encoding: br

This blog answered with Brotli because the request said it accepts br.

Common choices are gzip, Brotli (br) and Zstandard (zstd). Already compressed data (JPEG, MP4, ZIP) gains nothing from a second pass.

SSL and TLS

TLS (Transport Layer Security) encrypts and authenticates a connection. SSL was its predecessor; every SSL version and TLS 1.0 and 1.1 are deprecated, so “SSL certificate” today really means a certificate used with TLS 1.2 or 1.3.

TLS provides three things:

  • Confidentiality: nobody on the path can read the data.
  • Integrity: nobody can change it without detection.
  • Authentication: the server proves its identity with a certificate signed by a trusted certificate authority (CA). Optionally the client does too (mutual TLS).

The TLS 1.3 handshake (one round trip)

  1. ClientHello: supported versions and cipher suites, a key share for key exchange, and the server name (SNI) so one IP can host many sites.
  2. ServerHello: chosen cipher and the server’s key share. Both sides now derive the same session keys (ECDHE), and everything after this is encrypted.
  3. The server sends its certificate and a signature proving it owns the private key, then Finished.
  4. The client checks the certificate chain, name and expiry, sends Finished, and application data flows.

Because keys come from a fresh exchange each time, TLS 1.3 always has forward secrecy: stealing the server’s private key later does not decrypt recorded traffic.

$ openssl s_client -connect blog.jefersonjeronimoai.online:443 -servername blog.jefersonjeronimoai.online </dev/null 2>/dev/null | grep -E 'Protocol|Cipher|Verify return'
Protocol  : TLSv1.3
Cipher    : TLS_AES_256_GCM_SHA384
Verify return code: 0 (ok)
$ echo | openssl s_client -connect blog.jefersonjeronimoai.online:443 -servername blog.jefersonjeronimoai.online 2>/dev/null | openssl x509 -noout -subject -issuer -dates
subject=CN=blog.jefersonjeronimoai.online
issuer=C=US, O=Let's Encrypt, CN=YE1
notBefore=Nov 16 16:00:25 2026 GMT
notAfter=Feb 14 16:00:24 2027 GMT

The second command prints who a certificate was issued to, who signed it and when it expires, the first thing to check when browsers show certificate errors. Expired certificates remain one of the most common causes of outages, which is why automated renewal with ACME (Let’s Encrypt, certbot) is the norm.

Exercise

An API response shows café instead of café. What is the most likely cause?

  1. The TLS certificate expired
  2. Compression corrupted the response
  3. UTF-8 bytes were decoded with a different encoding such as Latin-1
  4. The response was Base64 encoded
Show answer

Answer: C. é is two bytes in UTF-8 (c3 a9). Reading them as Latin-1 shows two characters, Ã and ©. Fix the declared or assumed charset.

Exercise

What does SNI in the TLS ClientHello allow?

  1. Encrypting the handshake before keys exist
  2. Hosting many HTTPS sites with different certificates on one IP address
  3. Compressing TLS records
  4. Skipping certificate validation
Show answer

Answer: B. The client names the site it wants in the ClientHello, so the server can pick the right certificate. Without SNI, each HTTPS site needed its own IP.

Exercise

Why should PPTP no longer be used for VPNs?

  1. Its authentication and encryption are broken, so captured sessions can be cracked
  2. It only works over IPv6
  3. It cannot pass through switches
  4. It requires a TLS certificate
Show answer

Answer: A. MS-CHAPv2 and MPPE are cryptographically broken. Modern options are WireGuard, IPsec/IKEv2 or TLS-based VPNs.

Key takeaways

  • Session jobs (state, resumption, checkpoints) live in applications and libraries today.
  • RPC turns remote calls into messages; gRPC with Protocol Buffers is the modern standard.
  • Encoding mismatches cause mojibake; UTF-8 is the default you should use.
  • Base64 and MIME let binary data and attachments travel through text protocols.
  • TLS 1.3 gives confidentiality, integrity and authentication in one round trip; SSL and TLS 1.0/1.1 are dead.

FAQ

Is HTTPS the same as TLS?

HTTPS is HTTP carried inside TLS. TLS also protects many other protocols: SMTP with STARTTLS, IMAPS, LDAPS, DNS over TLS and QUIC.

What is mutual TLS?

Both sides present certificates. Service meshes such as Istio and Linkerd use mTLS between microservices so every call is encrypted and every service proves who it is.

Is Base64 encryption?

No. Anyone can decode it instantly. It only makes binary data safe to carry in text. Kubernetes Secrets being Base64 encoded is a common misunderstanding: they still need encryption at rest.

Why does TLS 1.3 have fewer cipher suites than TLS 1.2?

It removed every weak or risky option (RSA key exchange, CBC modes, SHA-1, RC4) and kept only a few modern AEAD ciphers. Fewer choices means fewer ways to misconfigure it.

↑ ↓ navigate Enter open Esc close