PACS System 0.1.0
PACS DICOM system library
Loading...
Searching...
No Matches
tls_policy.h
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
21#pragma once
22
23#include <cstdint>
24#include <optional>
25#include <string>
26#include <string_view>
27#include <vector>
28
29namespace kcenon::pacs::security {
30
47
51[[nodiscard]] std::string_view to_string(tls_profile profile) noexcept;
52
56[[nodiscard]] std::optional<tls_profile> parse_tls_profile(
57 std::string_view str) noexcept;
58
64 std::string tls13_ciphers;
65
67 std::string tls12_ciphers;
68};
69
75 uint16_t min_rsa_key_bits{2048};
76
78 uint16_t min_ecdsa_curve_bits{256};
79
81 uint8_t max_chain_depth{5};
82
85};
86
94public:
102 [[nodiscard]] static tls_policy bcp195_basic_profile();
103
114 [[nodiscard]] static tls_policy bcp195_non_downgrading_profile();
115
123 [[nodiscard]] static tls_policy bcp195_extended_profile();
124
128 [[nodiscard]] static tls_policy from_profile(tls_profile profile);
129
132
133 [[nodiscard]] tls_profile profile() const noexcept;
134 [[nodiscard]] std::string_view profile_name() const noexcept;
135
136 [[nodiscard]] uint16_t min_protocol_version() const noexcept;
137 [[nodiscard]] uint16_t max_protocol_version() const noexcept;
138
139 [[nodiscard]] bool non_downgrading() const noexcept;
140
141 [[nodiscard]] const cipher_suite_spec& cipher_suites() const noexcept;
142 [[nodiscard]] const certificate_constraints& cert_constraints() const noexcept;
143
145
148
153 [[nodiscard]] bool is_version_allowed(uint16_t version) const noexcept;
154
159 [[nodiscard]] bool is_rsa_key_acceptable(uint16_t bits) const noexcept;
160
165 [[nodiscard]] bool is_ecdsa_key_acceptable(uint16_t bits) const noexcept;
166
170 [[nodiscard]] std::string_view tls13_ciphersuites() const noexcept;
171
175 [[nodiscard]] std::string_view tls12_ciphersuites() const noexcept;
176
178
181
183 static constexpr std::string_view kTls13Required =
184 "TLS_AES_256_GCM_SHA384:"
185 "TLS_AES_128_GCM_SHA256:"
186 "TLS_CHACHA20_POLY1305_SHA256";
187
189 static constexpr std::string_view kTls13Strict =
190 "TLS_AES_256_GCM_SHA384:"
191 "TLS_CHACHA20_POLY1305_SHA256";
192
194 static constexpr std::string_view kTls12Recommended =
195 "ECDHE-ECDSA-AES256-GCM-SHA384:"
196 "ECDHE-RSA-AES256-GCM-SHA384:"
197 "ECDHE-ECDSA-CHACHA20-POLY1305:"
198 "ECDHE-RSA-CHACHA20-POLY1305:"
199 "ECDHE-ECDSA-AES128-GCM-SHA256:"
200 "ECDHE-RSA-AES128-GCM-SHA256";
201
203
206
208 static constexpr uint16_t kTls10Version = 0x0301;
209 static constexpr uint16_t kTls11Version = 0x0302;
210 static constexpr uint16_t kTls12Version = 0x0303;
211 static constexpr uint16_t kTls13Version = 0x0304;
212
214
215private:
216 tls_policy(tls_profile prof, uint16_t min_ver, uint16_t max_ver,
217 bool non_downgrade, cipher_suite_spec ciphers,
219
221 uint16_t min_version_;
222 uint16_t max_version_;
226};
227
231[[nodiscard]] std::vector<tls_profile> available_tls_profiles();
232
233} // 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
static constexpr uint16_t kTls10Version
OpenSSL TLS version constants for reference.
Definition tls_policy.h:208
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 kTls11Version
Definition tls_policy.h:209
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
uint16_t min_rsa_key_bits
Minimum RSA key size in bits.
Definition tls_policy.h:75
uint16_t min_ecdsa_curve_bits
Minimum ECDSA curve size (P-256 = 256, P-384 = 384)
Definition tls_policy.h:78
bool require_peer_verification
Require peer certificate verification.
Definition tls_policy.h:84
uint8_t max_chain_depth
Maximum certificate chain depth.
Definition tls_policy.h:81
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