TLS
Transport Layer Security
An encrypted communication protocol. Successor to SSL. The basis of HTTPS.
Transport Layer Security
An encrypted communication protocol. Successor to SSL. The basis of HTTPS.
TLS (Transport Layer Security) is a cryptographic protocol that ensures the confidentiality and integrity of data in internet communication. As the successor to SSL (Secure Sockets Layer), the name SSL disappeared into history after TLS 1.0 was released in 1999, but the industry still customarily uses the expression 'SSL certificate'. Currently, more than 95% of web traffic is encrypted with TLS.
The TLS Handshake is the negotiation process by which a client and a server establish a secure connection. When the client sends the TLS versions and cipher suites it supports, the server makes a selection and sends its certificate. The client verifies the certificate through a CA (Certificate Authority), then exchanges a session key and begins symmetric encrypted communication. In TLS 1.3, this process has been shortened to 1-RTT (round-trip time), greatly improving connection speed.
TLS 1.3 (RFC 8446, 2018) achieved groundbreaking improvements in both security and performance. Vulnerable cryptographic algorithms (RC4, 3DES, SHA-1) were removed, and Perfect Forward Secrecy (PFS) was made mandatory, so even if past session keys are leaked, earlier communications cannot be decrypted. With the 0-RTT reconnection feature, encrypted data can be sent immediately, without delay, to a server that was previously connected to.
With the advent of Let's Encrypt, TLS certificate issuance became free, and the adoption of HTTPS spread rapidly. mTLS (Mutual TLS) is a method in which not only the server but also the client proves its identity with a certificate, and it is used as a necessity in communication between microservices and in zero trust architectures. Setting the HSTS (HTTP Strict Transport Security) header can force the browser to connect to the domain only over HTTPS.
import ssl
import socket
import requests
# TLS 컨텍스트 생성 (기본 설정)
context = ssl.create_default_context()
# TLS 1.3만 허용 (최신 보안)
context.minimum_version = ssl.TLSVersion.TLSv1_3
context.maximum_version = ssl.TLSVersion.TLSv1_3
# TLS 연결로 소켓 래핑
hostname = "google.com"
with socket.create_connection((hostname, 443)) as sock:
with context.wrap_socket(sock, server_hostname=hostname) as ssock:
print(f"TLS 버전: {ssock.version()}") # TLSv1.3
print(f"암호화 스위트: {ssock.cipher()}")
# requests로 HTTPS 요청 (인증서 검증)
response = requests.get("https://api.example.com", verify=True)
# 자체 서명 인증서 사용 시
response = requests.get(
"https://internal.example.com",
verify="/path/to/ca-bundle.crt",
cert=("/path/to/client.crt", "/path/to/client.key") # mTLS
)
# 인증서 정보 확인
cert = ssock.getpeercert()
print(f"발급자: {cert['issuer']}")
print(f"만료일: {cert['notAfter']}")
# 서버 TLS 버전 및 인증서 확인
openssl s_client -connect google.com:443 -tls1_3
openssl s_client -connect example.com:443 -servername example.com
# 인증서 상세 정보 확인
echo | openssl s_client -connect google.com:443 2>/dev/null | \
openssl x509 -noout -text
# 인증서 만료일 확인
echo | openssl s_client -connect google.com:443 2>/dev/null | \
openssl x509 -noout -dates
# Let's Encrypt 인증서 발급 (certbot)
sudo certbot certonly --standalone -d example.com
sudo certbot certonly --webroot -w /var/www/html -d example.com
# 인증서 자동 갱신 테스트
sudo certbot renew --dry-run
# 자체 서명 인증서 생성 (개발용)
openssl req -x509 -newkey rsa:4096 -sha256 -days 365 \
-nodes -keyout server.key -out server.crt \
-subj "/CN=localhost" \
-addext "subjectAltName=DNS:localhost,IP:127.0.0.1"
# TLS 버전별 테스트
openssl s_client -connect example.com:443 -tls1_2
openssl s_client -connect example.com:443 -tls1_3
# 지원 암호화 스위트 확인
nmap --script ssl-enum-ciphers -p 443 example.com
const https = require('https');
const tls = require('tls');
const fs = require('fs');
// HTTPS 서버 생성 (TLS 1.3 강제)
const server = https.createServer({
key: fs.readFileSync('server.key'),
cert: fs.readFileSync('server.crt'),
minVersion: 'TLSv1.3',
maxVersion: 'TLSv1.3'
}, (req, res) => {
res.writeHead(200);
res.end('Hello TLS 1.3!');
});
// mTLS 서버 (클라이언트 인증서 요구)
const mtlsServer = https.createServer({
key: fs.readFileSync('server.key'),
cert: fs.readFileSync('server.crt'),
ca: fs.readFileSync('ca.crt'),
requestCert: true,
rejectUnauthorized: true
}, (req, res) => {
const clientCert = req.socket.getPeerCertificate();
console.log(`클라이언트 CN: ${clientCert.subject.CN}`);
res.end('mTLS 인증 성공!');
});
// TLS 연결 정보 확인
const options = { host: 'google.com', port: 443, servername: 'google.com' };
const socket = tls.connect(options, () => {
console.log('TLS 버전:', socket.getProtocol()); // TLSv1.3
console.log('암호화:', socket.getCipher().name);
console.log('인증서:', socket.getPeerCertificate().subject);
socket.end();
});
server.listen(443);
"The server currently supports TLS 1.0 and 1.1 as well, and this is a security vulnerability. Under PCI DSS requirements, only TLS 1.2 or higher should be allowed, and if possible, it's better to upgrade to TLS 1.3. In the nginx configuration, you can restrict it with ssl_protocols TLSv1.2 TLSv1.3;."
"In the TLS Handshake, when the client sends a ClientHello, the server responds with a ServerHello and its certificate, and after the key exchange, they communicate with encryption using a symmetric key. In TLS 1.3, it has been reduced to 1-RTT, and Perfect Forward Secrecy has been made mandatory, so even if a key is leaked, past communications cannot be decrypted."
"mTLS should be applied to communication between microservices. If you use the Istio service mesh, the sidecar proxy handles mTLS automatically, and certificate rotation is also automated. The HSTS header should also be set to max-age=31536000; includeSubDomains; preload to prevent downgrade attacks."
Take a mock interview on this topic → WIA SOOM AI Interview · Start for free
TLS 1.0 and 1.1 have known vulnerabilities such as POODLE and BEAST, so they should no longer be used. Major browsers have discontinued support for TLS 1.0/1.1 since 2020. Be sure to use TLS 1.2 or higher.
When a certificate expires, the browser displays a warning and users leave. Let's Encrypt certificates need to be renewed every 90 days. Register certbot renew in cron, or use an automatic renewal service such as AWS Certificate Manager.
Loading HTTP resources on an HTTPS page triggers security warnings and causes some resources to be blocked. Serve all resources (images, scripts, APIs) over HTTPS, and set the Content-Security-Policy: upgrade-insecure-requests header.
Allow only TLS 1.3 + TLS 1.2, set the HSTS header, enable OCSP Stapling, and allow only strong cipher suites (ECDHE, AES-GCM). Verify the configuration with SSL Labs (ssllabs.com/ssltest), aiming for an A+ rating.