Security Assertion Markup Language (SAML) employs robust security mechanisms to ensure secure identity federation. This post examines SAML’s cryptographic foundations, focusing on XML Digital Signatures, XML Encryption, X.509 certificate verification, and defenses against replay attacks.
1. XML Digital Signatures in SAML
SAML messages utilize XML Digital Signature (XML DSig) to guarantee message integrity and authenticity through asymmetric cryptography.
Implementation Details:
- Signature Generation:
- Apply canonicalization (typically Exclusive XML Canonicalization) to normalize the XML structure
- Generate a message digest using SHA-256 or stronger algorithms
- Encrypt the digest with the sender’s private key
- Embed the signature in a
<ds:Signature>
element containing:- SignedInfo (canonicalization method, signature algorithm, references)
- SignatureValue
- KeyInfo (optional X.509 certificate)
Verification Process:
- Validate the certificate chain and revocation status
- Re-canonicalize the signed elements
- Recompute the digest and compare with the decrypted signature
- Verify the signature covers all required elements
2. XML Encryption in SAML
SAML implements XML Encryption to protect sensitive assertion data through a hybrid encryption approach.
Encryption Workflow:
- Generate a random symmetric key (AES-256 recommended)
- Encrypt the payload data with the symmetric key
- Encrypt the symmetric key with the recipient’s public key (RSA-OAEP preferred)
- Structure the encrypted data as:
<EncryptedData>
containing:- Encryption method
- CipherValue
- KeyInfo with encrypted key
- Optional
<EncryptedKey>
for key transport
Decryption Considerations:
- Implement proper key wrapping for symmetric key protection
- Support multiple encryption algorithms for interoperability
- Validate encrypted data size limitations
3. X.509 Certificate Validation
Proper certificate handling is critical for SAML security operations.
Comprehensive Validation Checklist:
-
Chain Validation:
- Verify root CA trust
- Check intermediate certificates
- Validate path constraints
-
Certificate Properties:
- Confirm valid time window
- Verify key usage extensions
- Check subject alternative names
-
Revocation Checking:
- Implement OCSP stapling
- Support CRL distribution points
- Enforce revocation checking policies
Operational Best Practices:
- Maintain separate certificates for signing and encryption
- Implement certificate pinning where appropriate
- Enforce strong cryptographic algorithms (minimum RSA-2048, ECDSA-256)
4. Replay Attack Mitigation
SAML implementations must incorporate multiple defenses against message replay.
Defensive Strategies:
-
Temporal Controls:
- Enforce strict
<Conditions>
time windows (recommended ≤5 minutes) - Validate
<IssueInstant>
timestamps - Implement clock synchronization (NTP)
- Enforce strict
-
Message Tracking:
- Maintain an assertion ID registry
- Implement sliding window expiration
- Log all processed assertions
-
Protocol Enhancements:
- Require
<SubjectConfirmation>
elements - Implement signed audience restrictions
- Enforce one-time-use policies
- Require
-
Operational Safeguards:
- Monitor for duplicate message IDs
- Implement rate limiting
- Conduct regular security audits
Security Implementation Checklist
For production SAML deployments:
- Enforce XML signature verification
- Implement mandatory element encryption
- Configure strict certificate validation
- Deploy replay protection mechanisms
- Maintain comprehensive security logging
These security measures form the foundation of trustworthy SAML implementations, ensuring secure identity propagation across organizational boundaries while maintaining compliance with security best practices.