#[derive(Debug, Clone)]
pub struct SecurityConfig {
pub clock_skew_seconds: u64,
pub require_signed_assertions: bool,
pub require_signed_responses: bool,
pub require_encrypted_assertions: bool,
pub max_assertion_age_seconds: u64,
pub reject_signatures_with_ds_object: bool,
pub enforce_persistent_id_uniqueness: bool,
pub sanitize_relay_state: bool,
pub require_integrity_with_cbc: bool,
pub verify_destination: bool,
pub verify_recipient: bool,
pub check_client_address: bool,
}
impl Default for SecurityConfig {
fn default() -> Self {
Self {
clock_skew_seconds: 180, require_signed_assertions: true, require_signed_responses: false, require_encrypted_assertions: false, max_assertion_age_seconds: 300, reject_signatures_with_ds_object: true, enforce_persistent_id_uniqueness: true, sanitize_relay_state: true, require_integrity_with_cbc: true, verify_destination: true,
verify_recipient: true,
check_client_address: false, }
}
}
impl SecurityConfig {
pub fn new() -> Self {
Self::default()
}
pub fn permissive() -> Self {
Self {
clock_skew_seconds: 600, require_signed_assertions: false,
require_signed_responses: false,
require_encrypted_assertions: false,
max_assertion_age_seconds: 3600, reject_signatures_with_ds_object: false,
enforce_persistent_id_uniqueness: false,
sanitize_relay_state: false,
require_integrity_with_cbc: false,
verify_destination: false,
verify_recipient: false,
check_client_address: false,
}
}
pub fn strict() -> Self {
Self {
clock_skew_seconds: 180, require_signed_assertions: true,
require_signed_responses: true,
require_encrypted_assertions: true,
max_assertion_age_seconds: 180, reject_signatures_with_ds_object: true,
enforce_persistent_id_uniqueness: true,
sanitize_relay_state: true,
require_integrity_with_cbc: true,
verify_destination: true,
verify_recipient: true,
check_client_address: true, }
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_default_config() {
let config = SecurityConfig::default();
assert_eq!(config.clock_skew_seconds, 180);
assert!(config.require_signed_assertions);
assert!(!config.require_signed_responses);
assert!(!config.require_encrypted_assertions);
assert_eq!(config.max_assertion_age_seconds, 300);
assert!(config.reject_signatures_with_ds_object);
assert!(config.enforce_persistent_id_uniqueness);
assert!(config.sanitize_relay_state);
assert!(config.require_integrity_with_cbc);
assert!(config.verify_destination);
assert!(config.verify_recipient);
assert!(!config.check_client_address);
}
#[test]
fn test_permissive_config() {
let config = SecurityConfig::permissive();
assert_eq!(config.clock_skew_seconds, 600);
assert!(!config.require_signed_assertions);
assert!(!config.verify_destination);
assert!(!config.verify_recipient);
assert!(!config.check_client_address);
}
#[test]
fn test_strict_config() {
let config = SecurityConfig::strict();
assert_eq!(config.clock_skew_seconds, 180);
assert!(config.require_signed_assertions);
assert!(config.require_signed_responses);
assert!(config.require_encrypted_assertions);
assert!(config.verify_destination);
assert!(config.verify_recipient);
assert!(config.check_client_address);
}
#[test]
fn test_config_clone() {
let config = SecurityConfig::new();
let cloned = config.clone();
assert_eq!(config.clock_skew_seconds, cloned.clock_skew_seconds);
assert_eq!(
config.require_signed_assertions,
cloned.require_signed_assertions
);
}
}