PACS System 0.1.0
PACS DICOM system library
Loading...
Searching...
No Matches
tls_policy.cpp
Go to the documentation of this file.
1// BSD 3-Clause License
2// Copyright (c) 2021-2025, 🍀☀🌕🌥 🌊
3// See the LICENSE file in the project root for full license information.
4
6
8
9// ============================================================================
10// tls_profile string conversion
11// ============================================================================
12
13std::string_view to_string(tls_profile profile) noexcept {
14 switch (profile) {
16 return "BCP195-Basic";
18 return "BCP195-NonDowngrading";
20 return "BCP195-Extended";
21 }
22 return "Unknown";
23}
24
25std::optional<tls_profile> parse_tls_profile(std::string_view str) noexcept {
26 if (str == "BCP195-Basic" || str == "basic")
28 if (str == "BCP195-NonDowngrading" || str == "non-downgrading")
30 if (str == "BCP195-Extended" || str == "extended")
32 return std::nullopt;
33}
34
35// ============================================================================
36// tls_policy private constructor
37// ============================================================================
38
39tls_policy::tls_policy(tls_profile prof, uint16_t min_ver, uint16_t max_ver,
40 bool non_downgrade, cipher_suite_spec ciphers,
42 : profile_(prof),
43 min_version_(min_ver),
44 max_version_(max_ver),
45 non_downgrading_(non_downgrade),
46 ciphers_(std::move(ciphers)),
47 cert_constraints_(std::move(certs)) {}
48
49// ============================================================================
50// Factory methods
51// ============================================================================
52
57 true,
58 {std::string(kTls13Required), std::string(kTls12Recommended)},
59 {2048, 256, 5, true}};
60}
61
66 true,
67 {std::string(kTls13Required), std::string(kTls12Recommended)},
68 {2048, 256, 5, true}};
69}
70
75 true,
76 {std::string(kTls13Strict), ""},
77 {3072, 256, 4, true}};
78}
79
91
92// ============================================================================
93// Property accessors
94// ============================================================================
95
97 return profile_;
98}
99
100std::string_view tls_policy::profile_name() const noexcept {
101 return to_string(profile_);
102}
103
104uint16_t tls_policy::min_protocol_version() const noexcept {
105 return min_version_;
106}
107
108uint16_t tls_policy::max_protocol_version() const noexcept {
109 return max_version_;
110}
111
112bool tls_policy::non_downgrading() const noexcept {
113 return non_downgrading_;
114}
115
117 return ciphers_;
118}
119
123
124// ============================================================================
125// Validation
126// ============================================================================
127
128bool tls_policy::is_version_allowed(uint16_t version) const noexcept {
129 return version >= min_version_ && version <= max_version_;
130}
131
132bool tls_policy::is_rsa_key_acceptable(uint16_t bits) const noexcept {
133 return bits >= cert_constraints_.min_rsa_key_bits;
134}
135
136bool tls_policy::is_ecdsa_key_acceptable(uint16_t bits) const noexcept {
137 return bits >= cert_constraints_.min_ecdsa_curve_bits;
138}
139
140std::string_view tls_policy::tls13_ciphersuites() const noexcept {
141 return ciphers_.tls13_ciphers;
142}
143
144std::string_view tls_policy::tls12_ciphersuites() const noexcept {
145 return ciphers_.tls12_ciphers;
146}
147
148// ============================================================================
149// Utility functions
150// ============================================================================
151
157
158} // namespace kcenon::pacs::security
TLS security policy configuration.
Definition tls_policy.h:93
static tls_policy bcp195_extended_profile()
Create an extended profile (TLS 1.3 only)
uint16_t min_protocol_version() const noexcept
bool is_version_allowed(uint16_t version) const noexcept
Check if a TLS version is allowed by this policy.
const cipher_suite_spec & cipher_suites() const noexcept
std::string_view profile_name() const noexcept
tls_policy(tls_profile prof, uint16_t min_ver, uint16_t max_ver, bool non_downgrade, cipher_suite_spec ciphers, certificate_constraints certs)
static constexpr uint16_t kTls13Version
Definition tls_policy.h:211
std::string_view tls12_ciphersuites() const noexcept
Get the TLS 1.2 cipher suites string for OpenSSL.
static tls_policy bcp195_non_downgrading_profile()
Create a BCP 195 non-downgrading profile policy.
tls_profile profile() const noexcept
static constexpr std::string_view kTls13Required
TLS 1.3 required cipher suites (BCP 195)
Definition tls_policy.h:183
certificate_constraints cert_constraints_
Definition tls_policy.h:225
static constexpr std::string_view kTls12Recommended
TLS 1.2 BCP 195 recommended cipher suites.
Definition tls_policy.h:194
const certificate_constraints & cert_constraints() const noexcept
bool non_downgrading() const noexcept
uint16_t max_protocol_version() const noexcept
std::string_view tls13_ciphersuites() const noexcept
Get the TLS 1.3 cipher suites string for OpenSSL.
static constexpr std::string_view kTls13Strict
TLS 1.3 strict cipher suites (extended profile)
Definition tls_policy.h:189
bool is_rsa_key_acceptable(uint16_t bits) const noexcept
Check if an RSA key size meets minimum requirements.
static constexpr uint16_t kTls12Version
Definition tls_policy.h:210
static tls_policy from_profile(tls_profile profile)
Create a policy from a named profile.
static tls_policy bcp195_basic_profile()
Create a BCP 195 basic profile policy.
bool is_ecdsa_key_acceptable(uint16_t bits) const noexcept
Check if an ECDSA curve size meets minimum requirements.
std::optional< tls_profile > parse_tls_profile(std::string_view str) noexcept
Parse TLS profile from string.
constexpr auto to_string(anonymization_profile profile) noexcept -> std::string_view
Convert profile enum to string representation.
tls_profile
TLS policy profile levels.
Definition tls_policy.h:36
@ bcp195_basic
BCP 195 basic profile: TLS 1.2 minimum, standard cipher suites.
@ bcp195_non_downgrading
BCP 195 non-downgrading profile: TLS 1.2+ with no downgrade This is the DICOM PS3....
@ bcp195_extended
Extended profile: TLS 1.3 only, strictest cipher suites.
std::vector< tls_profile > available_tls_profiles()
Get a list of all available TLS profiles.
Certificate validation constraints.
Definition tls_policy.h:73
TLS cipher suite specification.
Definition tls_policy.h:62
std::string tls12_ciphers
TLS 1.2 cipher suites (OpenSSL cipher string format)
Definition tls_policy.h:67
std::string tls13_ciphers
TLS 1.3 cipher suites (OpenSSL ciphersuites string format)
Definition tls_policy.h:64
TLS security policy for BCP 195 compliance (DICOM PS3.15)