StormByte-Crypto 3.1.0
C++26 cryptography module of the StormByte suite
Loading...
Searching...
No Matches
tls_peer.hxx
Go to the documentation of this file.
1/*
2 * Copyright (C) 2024-2026 David C. Manuelda (StormBytePP)
3 *
4 * This file is part of StormByte-Crypto.
5 *
6 * StormByte-Crypto original source is dual-licensed:
7 *
8 * 1. GNU Lesser General Public License v3.0 (or later)
9 * You may redistribute and/or modify this file under the terms of the
10 * GNU Lesser General Public License as published by the Free Software
11 * Foundation, either version 3 of the License, or (at your option)
12 * any later version.
13 *
14 * 2. Commercial license
15 * Alternatively, this file may be used under the terms of a commercial
16 * license agreement with the copyright holder
17 * (David C. Manuelda <StormByte@gmail.com>).
18 *
19 * Both licenses apply only to original StormByte-Crypto source in this
20 * repository. They do not cover other StormByte modules or any third-party
21 * material shipped with this repository (including everything under
22 * thirdparty/, in particular Crypto++, bundled libbzip2, the StormByte-Buffer
23 * tree and the StormByte suite it vendors), which remains under its own license.
24 *
25 * Neither license grants any patent rights. Any patent licenses required
26 * to use this software or third-party components must be obtained separately
27 * from the patent holders.
28 *
29 * StormByte-Crypto is distributed in the hope that it will be useful,
30 * but WITHOUT ANY WARRANTY; without even the implied warranty of
31 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32 * GNU Lesser General Public License for more details.
33 *
34 * You should have received a copy of the GNU Lesser General Public License
35 * version 3 along with StormByte-Crypto. If not, see
36 * <https://www.gnu.org/licenses/lgpl-3.0.html>.
37 *
38 * SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-StormByte-Commercial
39 */
40
41#pragma once
42
44
49namespace StormByte {
54 namespace Crypto {
59 namespace X509 {
82
89 public:
93 TLSPeerFailure() noexcept;
94
100 explicit TLSPeerFailure(TLSPeerError code, std::size_t index = 0) noexcept;
101
107 explicit TLSPeerFailure(PurposeError detail, std::size_t index) noexcept;
108
114 explicit TLSPeerFailure(IdentityError detail, std::size_t index = 0) noexcept;
115
120 TLSPeerFailure(const TLSPeerFailure& other) noexcept;
121
127
131 ~TLSPeerFailure() noexcept;
132
138 TLSPeerFailure& operator=(const TLSPeerFailure& other) noexcept;
139
145 TLSPeerFailure& operator=(TLSPeerFailure&& other) noexcept;
146
151 TLSPeerError Code() const noexcept;
152
157 std::size_t CertificateIndex() const noexcept;
158
163 PurposeError PurposeDetail() const noexcept;
164
170
171 private:
172 TLSPeerError m_code;
173 std::size_t m_index;
174 PurposeError m_purpose;
175 IdentityError m_identity;
176 };
177 }
178 }
179}
180
182
187namespace StormByte {
192 namespace Crypto {
197 namespace X509 {
202
212 public:
216 TLSPeerVerifier() = delete;
217
222 TLSPeerVerifier(const TLSPeerVerifier& other) = delete;
223
229
234
241
248
293 std::span<const Certificate> intermediates, const Certificate& anchor,
294 TimePoint at, TLSRole role, const SubjectAltName* identity = nullptr);
295 };
296 }
297 }
298}
Immutable, strictly DER-parsed X.509 certificate.
Definition certificate.hxx:262
One supported subjectAltName entry (a DNS name or an IP address).
Definition certificate.hxx:156
std::size_t CertificateIndex() const noexcept
Returns the certificate position.
TLSPeerFailure() noexcept
Constructs an invalid-certificate failure at the leaf.
PurposeError PurposeDetail() const noexcept
Returns the preserved purpose error.
IdentityError IdentityDetail() const noexcept
Returns the preserved identity error.
TLSPeerError Code() const noexcept
Returns the failure category.
TLSPeerVerifier(TLSPeerVerifier &&other)=delete
Non-movable stateless verifier.
TLSPeerVerifier()=delete
Non-instantiable stateless verifier.
static ExpectedTLSPeer Verify(const Certificate &leaf, std::span< const Certificate > intermediates, const Certificate &anchor, TimePoint at, TLSRole role, const SubjectAltName *identity=nullptr)
Verifies an ordered chain, signing purpose and optional SAN identity.
TLSPeerVerifier & operator=(TLSPeerVerifier &&other)=delete
Move assignment is unavailable.
TLSPeerVerifier(const TLSPeerVerifier &other)=delete
Non-copyable stateless verifier.
~TLSPeerVerifier()=delete
No instances exist to destroy.
TLSPeerVerifier & operator=(const TLSPeerVerifier &other)=delete
Copy assignment is unavailable.
STORMBYTE_DECLARE_MAYBE_SAFE(class StormByte::System::Device::Access)
X.509 certificate parsing and chain verification.
StormByte::Expected< void, TLSPeerFailure > ExpectedTLSPeer
Offline peer-certificate success or a detailed, indexed failure.
Definition tls_peer.hxx:201
TLSRole
Certificate signing role in TLS 1.3 (RFC 8446 ยง4.4.2.2).
Definition certificate.hxx:119
PurposeError
Errors of narrowly scoped certificate-purpose checks.
Definition certificate.hxx:136
@ InvalidCertificate
Certificate is empty or moved from.
Definition certificate.hxx:138
@ UnsupportedRole
Role is not Server or Client.
Definition certificate.hxx:137
std::chrono::sys_seconds TimePoint
Point in time with second precision, as stored in certificates.
Definition certificate.hxx:75
TLSPeerError
Failures of the constrained, offline TLS signing-certificate verifier.
Definition tls_peer.hxx:64
@ SignatureOrIssuerMismatch
Ordered issuer name or certificate signature does not verify.
Definition tls_peer.hxx:74
@ NotCA
Issuer is not a version 3 CA.
Definition tls_peer.hxx:71
@ Purpose
PurposeDetail supplies the exact EKU/KU failure.
Definition tls_peer.hxx:79
@ UnsupportedIdentity
Identity kind is neither DNS nor IP.
Definition tls_peer.hxx:67
@ IssuerKeyUsageNotAllowed
Present issuer KU lacks keyCertSign.
Definition tls_peer.hxx:72
@ InvalidTime
Caller time is outside a certificate's inclusive validity interval.
Definition tls_peer.hxx:69
@ UnsupportedAlgorithm
Signature or public key is outside the documented subset.
Definition tls_peer.hxx:75
@ MissingServerIdentity
A server requires an expected DNS or IP identity.
Definition tls_peer.hxx:66
@ UnsupportedCriticalExtension
Critical extension is not fully processed by this verifier.
Definition tls_peer.hxx:76
@ PathLengthExceeded
Supplied CA count exceeds an issuer's pathLenConstraint.
Definition tls_peer.hxx:73
@ LeafIsCA
Peer leaf must not be a CA.
Definition tls_peer.hxx:70
@ Identity
IdentityDetail supplies the exact SAN failure.
Definition tls_peer.hxx:80
@ UnsupportedConstraint
Present path restriction requires unsupported processing.
Definition tls_peer.hxx:77
@ MalformedExtension
Relevant extension has invalid DER or inconsistent semantics.
Definition tls_peer.hxx:78
IdentityError
Errors of subjectAltName extraction and expected-identity verification.
Definition certificate.hxx:107
Crypto module of the StormByte suite.
Definition aead.hxx:53
Root namespace of the StormByte suite.
std::conditional_t< Type::Reference< T >, std::expected< std::reference_wrapper< std::remove_reference_t< T > >, Safe::Shared< E > >, std::expected< T, Safe::Shared< E > > > Expected
STL namespace.
#define STORMBYTE_CRYPTO_PUBLIC
Definition visibility.h:53