Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
PKI/Certificate.h
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
4#ifndef _Stroika_Foundation_Cryptography_Certificate_h_
5#define _Stroika_Foundation_Cryptography_Certificate_h_ 1
6
7#include "Stroika/Foundation/StroikaPreComp.h"
8
9#include <memory>
10
11#include "Stroika/Foundation/Common/Common.h"
12#include "Stroika/Foundation/Containers/Mapping.h"
13#include "Stroika/Foundation/Cryptography/PKI/PrivateKey.h"
17
18namespace Stroika::Foundation::Cryptography::PKI::Certificate {
19
20 using Characters::String;
21 using Containers::Mapping;
22 using Time::DateTime;
23 using Traversal::Range;
24
25 /**
26 * EG Subject: C=US, ST=California, L=San Francisco, O=Wikimedia Foundation, Inc., CN=*.wikipedia.org
27 */
28 struct SubjectInfo {
29 String fCountry;
30 String fOrganization;
31 String fCommonName;
32
33 String ToString () const;
34 };
35
36 /**
37 */
38 class IRep {
39 public:
40 virtual ~IRep () = default;
41
42 // Not Before thru Not After
43 virtual Range<DateTime> GetValidDates () const = 0;
44 virtual SubjectInfo GetSubject () const = 0;
45 };
46
47 /**
48 */
49 struct Ptr : shared_ptr<IRep> {
50 using inherited = shared_ptr<IRep>;
51 /**
52 */
53 using inherited::inherited;
54
55 // I THINK consists of mapping of assertions (?) or sequence? key-value pairs.. - sb able to retrive and maybe
56 // add to/update?
57 SubjectInfo GetSubject () const
58 {
59 return get ()->GetSubject ();
60 }
61 Range<DateTime> GetValidDates () const
62 {
63 return get ()->GetValidDates ();
64 }
65 nonvirtual Characters::String ToString () const;
66 };
67
68 /**
69 * \brief data used to create a self-signed certificate.
70 *
71 * A private-key/public certificate pair is required to operate SSL, but sometimes you want to run
72 * SSL connecting to a host without the usual PKI checking to validate its DNS name (say by IP address
73 * or in some private compute situation, like within a home). In such cases, and probably others, its handy
74 * to be able to create a key/cert pair, but without the usual trusted validator of subject (domain) ownership.
75 */
77 // Not Before thru Not After
78 Range<DateTime> fValidDates{Time::DateTime::Now (), Time::DateTime::Now () + Time::Duration{"PT1Y"sv}};
79 SubjectInfo fSubject;
80 optional<String> fSubjectAlternativeName; // SAN
81 };
82
83 /**
84 * \brief generate a new self-signed certificate (and private key)
85 * \see https://stackoverflow.com/questions/256405/programmatically-create-x509-certificate-using-openssl
86 */
87 tuple<PrivateKey::Ptr, Ptr> New (const SelfSignedCertParams& params);
88
89 // and example loading PEM .CER files...
90 // (regtests)
91 // @todo add 'make self-signed-cert' https://stackoverflow.com/questions/256405/programmatically-create-x509-certificate-using-openssl
92
93}
94
95/*
96 ********************************************************************************
97 ***************************** Implementation Details ***************************
98 ********************************************************************************
99 */
100
101#endif /*_Stroika_Foundation_Cryptography_Certificate_h_*/
String is like std::u32string, except it is much easier to use, often much more space efficient,...
Definition String.h:201
Duration is a chrono::duration<double> (=.
Definition Duration.h:96