Комментарии (1)
Ответ сгенерирован нейросетью и может содержать ошибки
Что такое SSL
SSL (Secure Sockets Layer) и его современный преемник TLS (Transport Layer Security) — это критические технологии для безопасности интернета. В моей практике я постоянно тестирую SSL/TLS функциональность.
Определение
SSL (Secure Sockets Layer) — это криптографический протокол для безопасной передачи данных в интернете.
TLS (Transport Layer Security) — это современная версия SSL (SSL 3.1)
История
SSL 1.0 → SSL 2.0 (1995) → SSL 3.0 (1996)
↓
TLS 1.0 (1999, основанный на SSL 3.0)
TLS 1.1 (2006) → TLS 1.2 (2008) → TLS 1.3 (2018, current)
Зачем нужен SSL/TLS
1. Шифрование (Encryption)
Проблема: Без SSL, данные в открытом виде
User: Отправляю пароль 12345
Without SSL: Пароль передаётся в clear text
Hacker в сети: Может перехватить пароль
Result: Account hacked
With SSL: Пароль зашифрован
Hacker видит: Gibberish (случайные символы)
Result: Пароль в безопасности
2. Аутентификация (Authentication)
Проблема: Как знать, что это действительно example.com?
Without SSL: Нельзя проверить
Hacker создаёт fake example.com сайт
User думает это real, вводит пароль
Hacker получает пароль
With SSL: Certificate проверяет identity
Browser проверяет certificate
Fake сайт не имеет valid certificate
Browser показывает WARNING
3. Целостность (Integrity)
Проблема: Как знать что данные не были изменены?
Without SSL: Хакер может change сообщение
Original: "Transfer $10"
Intercepted & changed: "Transfer $10000"
User не знает
With SSL: Hash проверяет целостность
Если данные изменены → hash не совпадает
Error detected
Как работает SSL/TLS
TLS Handshake
Процесс:
1. Client Hello
Client → Server: "Hi, I support TLS 1.2, 1.3"
"I support these ciphers..."
2. Server Hello
Server → Client: "OK, we'll use TLS 1.2"
"I'll use this cipher suite"
"Here's my certificate"
3. Key Exchange
Client: "Verify certificate is valid ✓"
Client → Server: "Let's use this key"
Both: Use key for encryption
4. Finished
Client → Server: "I'm ready (encrypted)"
Server → Client: "I'm ready (encrypted)"
Result: Secure connection established
Time: ~100-200ms
После Handshake
Client ↔ Server: All data encrypted
Everything transmitted safely
SSL Certificate
Что это
Certificate — это цифровой документ, подтверждающий identity сервера
Certificate содержит:
- Domain name (example.com)
- Company name
- Valid dates (issued: Jan 2024, expires: Jan 2025)
- Public key (для encryption)
- Digital signature (от Certificate Authority)
Types of Certificates
1. Single Domain
Valid for: example.com only
Invalid for: www.example.com, api.example.com
2. Wildcard
Valid for: *.example.com
Includes: api.example.com, www.example.com, etc
Invalid for: example.com (without subdomain)
3. Multi-domain (SAN)
Valid for: example.com, api.example.com, admin.example.com
Specified in certificate
При тестировании SSL
Что я проверяю
1. Certificate validity
# Check if certificate is valid
def test_certificate_valid():
response = requests.get('https://api.example.com', verify=True)
# verify=True → проверить certificate
# If invalid → raises SSLError
assert response.status_code == 200
2. Expired certificate
Situation: Certificate expired on Jan 1, 2024
Today: Jan 15, 2024
Browser shows: "Your connection is not private"
"ERR_CERT_DATE_INVALID"
Test:
requests.get('https://expired.example.com')
→ SSLError: certificate expired
3. Self-signed certificate
Certificate: Created by company, not by CA
Browser shows: "Not trusted"
Test in development:
requests.get(url, verify=False) # Disable verification
Never do in production!
4. Certificate mismatch
Certificate issued for: api.example.com
User visits: payment.example.com
Browser shows: "Certificate doesn't match domain"
"ERR_CERT_COMMON_NAME_INVALID"
Test:
requests.get('https://wrong-domain.example.com')
→ SSLError: certificate mismatch
Curl commands для тестирования
# 1. Show certificate details
curl -vI https://example.com 2>&1 | grep -A 10 "certificate"
# 2. Check certificate expiry
openssl s_client -connect example.com:443 -showcerts | grep "Validity" -A 2
# 3. Show certificate info
openssl s_client -connect example.com:443 -showcerts | openssl x509 -text -noout
# 4. Test SSL version
curl -I --tlsv1.2 https://example.com # Should work
curl -I --sslv3 https://example.com # Should fail
# 5. Disable certificate verification (dev only!)
curl -k https://self-signed.example.com
Common SSL Issues When Testing
Issue 1: SSL_CERTIFICATE_VERIFY_FAILED
Причина: Certificate не доверенный
Solution:
import requests
from requests.packages.urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
response = requests.get(url, verify=False) # For testing only!
Issue 2: Certificate expired
Проверка:
echo | openssl s_client -connect example.com:443 2>/dev/null | openssl x509 -noout -dates
output:
notBefore=Jan 1 10:00:00 2023 GMT
notAfter=Jan 1 10:00:00 2024 GMT
Issue 3: Mixed content
Проблема: Some resources loaded via HTTP, some via HTTPS
<!-- Page HTTPS -->
<img src="http://example.com/image.jpg"> ✗ HTTP
<script src="https://example.com/js"></script> ✓ HTTPS
Browser shows: "Not secure"
Test:
// Check for mixed content
cy.visit('https://example.com')
cy.window().then(win => {
const hasInsecureContent = win.location.protocol === 'https' &&
document.querySelectorAll('[src^="http:"]').length > 0
expect(hasInsecureContent).to.be.false
})
TLS версии
Supported versions
✓ TLS 1.2 (2008, still widely supported)
✓ TLS 1.3 (2018, modern, recommended)
✗ TLS 1.1 и ниже (deprecated, insecure)
✗ SSL 3.0 и ниже (very old, very insecure)
При тестировании
# Check which TLS versions supported
nmap --script ssl-enum-ciphers -p 443 example.com
Output:
TLSv1.0: weak # Not recommended
TLSv1.2: strong # OK
TLSv1.3: strong # Best
# Test specific version
curl --tlsv1.3 https://example.com # Should work
curl --tlsv1.0 https://example.com # May work but not recommended
Cipher Suites
Cipher suite — это набор алгоритмов для encryption
Example cipher suite:
TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384
Breakdown:
- TLS: Protocol version
- ECDHE: Key exchange algorithm
- RSA: Authentication algorithm
- AES_256_GCM: Encryption algorithm (256-bit)
- SHA384: Hashing algorithm
Weak vs Strong
✗ Weak (avoid):
- MD5, SHA1
- DES, 3DES (40-bit, 56-bit keys)
- RC4
✓ Strong (use):
- SHA256, SHA384, SHA512
- AES-256
- ECDHE
Check server cipher suites
openssl s_client -connect example.com:443 -tlsv1.3 2>/dev/null | grep "Cipher"
Output:
Cipher: TLS_AES_256_GCM_SHA384
SSL/TLS Security best practices
For testing
# ✓ Good: Verify certificate
response = requests.get('https://api.example.com', verify=True)
# ❌ Bad: Disable verification
response = requests.get('https://api.example.com', verify=False)
# Only use verify=False for local testing with self-signed certs!
For development
# Generate self-signed certificate (for local testing)
openssl req -x509 -newkey rsa:4096 -nodes -out cert.pem -keyout key.pem -days 365
# Use in development server
python app.py --cert=cert.pem --key=key.pem
For production
# Get certificate from Certificate Authority (Let's Encrypt is free)
# Use proper tools: certbot, acme.sh
certbot certonly --nginx -d example.com
# Auto-renew (expires after 90 days)
certbot renew --dry-run
SSL pinning
Concept: "Pin" specific certificate to prevent MITM attacks
# Without pinning:
request → can be intercepted by proxy
# With pinning:
request → verify that it's the EXPECTED certificate
if not: reject connection
# Test implementation:
def test_certificate_pinning():
cert_sha256 = "abc123..."
response = requests.get(url)
# Verify certificate hash
peer_cert = ssl.get_server_certificate((host, port))
cert_hash = hashlib.sha256(peer_cert.encode()).hexdigest()
assert cert_hash == cert_sha256
Practical examples from my work
Example 1: Mobile app HTTPS testing
Project: iOS banking app
Requirement: All API calls over HTTPS
Test:
1. Charles proxy intercept requests
2. Check: all requests to https://api.example.com
3. No requests to http://
4. Certificate pinning working (can't intercept)
Result: ✓ Secure
Example 2: Certificate renewal testing
Problem: Certificate expires in 30 days
Test:
1. Get certificate details
openssl s_client -connect example.com:443 | grep "notAfter"
notAfter=Jan 31, 2024
2. Alert admin to renew
3. After renewal:
- New certificate date: Jan 31, 2025
- No service interruption
- All users can still connect
Monitoring: Set alert for 30 days before expiry
Summary
SSL/TLS is critical for security.
Key points:
- Encryption: Data protected from eavesdropping
- Authentication: Verify server identity
- Integrity: Detect tampering
When testing:
- ✓ Check certificate validity
- ✓ Verify TLS version (1.2+)
- ✓ Ensure HTTPS everywhere
- ✓ No mixed content
- ✓ Certificate pinning (if needed)
- ✗ Never disable in production
As QA, understanding SSL/TLS is essential because:
- Security is critical in modern apps
- Need to test HTTPS endpoints
- Need to verify certificates
- Need to troubleshoot SSL errors
- GDPR compliance requires HTTPS