diff options
Diffstat (limited to 'src/gmcerts.h')
-rw-r--r-- | src/gmcerts.h | 82 |
1 files changed, 81 insertions, 1 deletions
diff --git a/src/gmcerts.h b/src/gmcerts.h index a3df8f33..92a12a6a 100644 --- a/src/gmcerts.h +++ b/src/gmcerts.h | |||
@@ -1,8 +1,88 @@ | |||
1 | /* Copyright 2020 Jaakko Keränen <jaakko.keranen@iki.fi> | ||
2 | |||
3 | Redistribution and use in source and binary forms, with or without | ||
4 | modification, are permitted provided that the following conditions are met: | ||
5 | |||
6 | 1. Redistributions of source code must retain the above copyright notice, this | ||
7 | list of conditions and the following disclaimer. | ||
8 | 2. Redistributions in binary form must reproduce the above copyright notice, | ||
9 | this list of conditions and the following disclaimer in the documentation | ||
10 | and/or other materials provided with the distribution. | ||
11 | |||
12 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||
13 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
14 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
15 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR | ||
16 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
17 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
18 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON | ||
19 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
20 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
21 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ | ||
22 | |||
1 | #pragma once | 23 | #pragma once |
2 | 24 | ||
25 | #include <the_Foundation/ptrarray.h> | ||
26 | #include <the_Foundation/stringset.h> | ||
3 | #include <the_Foundation/tlsrequest.h> | 27 | #include <the_Foundation/tlsrequest.h> |
4 | 28 | ||
29 | iDeclareType(GmIdentity) | ||
30 | iDeclareTypeConstruction(GmIdentity) | ||
31 | iDeclareTypeSerialization(GmIdentity) | ||
32 | |||
33 | enum iGmIdentityFlags { | ||
34 | temporary_GmIdentityFlag = 0x1, /* not saved persistently */ | ||
35 | imported_GmIdentityFlag = 0x2, /* user-provided files */ | ||
36 | }; | ||
37 | |||
38 | struct Impl_GmIdentity { | ||
39 | iBlock fingerprint; | ||
40 | iTlsCertificate *cert; | ||
41 | iStringSet *useUrls; | ||
42 | iChar icon; | ||
43 | iString notes; /* private, local usage notes */ | ||
44 | int flags; | ||
45 | }; | ||
46 | |||
47 | iBool isUsed_GmIdentity (const iGmIdentity *); | ||
48 | iBool isUsedOn_GmIdentity (const iGmIdentity *, const iString *url); | ||
49 | |||
50 | void setUse_GmIdentity (iGmIdentity *, const iString *url, iBool use); | ||
51 | void clearUse_GmIdentity (iGmIdentity *); | ||
52 | |||
53 | const iString *name_GmIdentity(const iGmIdentity *); | ||
54 | |||
55 | /*----------------------------------------------------------------------------------------------*/ | ||
56 | |||
5 | iDeclareType(GmCerts) | 57 | iDeclareType(GmCerts) |
6 | iDeclareTypeConstructionArgs(GmCerts, const char *saveDir) | 58 | iDeclareTypeConstructionArgs(GmCerts, const char *saveDir) |
7 | 59 | ||
8 | iBool checkTrust_GmCerts (iGmCerts *, iRangecc domain, const iTlsCertificate *cert); | 60 | iBool checkTrust_GmCerts (iGmCerts *, iRangecc domain, const iTlsCertificate *cert); |
61 | |||
62 | /** | ||
63 | * Create a new self-signed TLS client certificate for identifying the user. | ||
64 | * @a commonName and the other name parameters are inserted in the subject field | ||
65 | * of the certificate. | ||
66 | * | ||
67 | * @param flags Identity flags. A temporary identity is not saved persistently and | ||
68 | * will be erased when the application is shut down. | ||
69 | * @param validUntil Expiration date. Must be in the future. | ||
70 | * | ||
71 | * @returns Created identity. GmCerts retains ownership of returned object. | ||
72 | */ | ||
73 | iGmIdentity * newIdentity_GmCerts (iGmCerts *, int flags, iDate validUntil, | ||
74 | const iString *commonName, const iString *email, | ||
75 | const iString *userId, const iString *domain, | ||
76 | const iString *org, const iString *country); | ||
77 | |||
78 | void deleteIdentity_GmCerts (iGmCerts *, iGmIdentity *identity); | ||
79 | |||
80 | const iString * certificatePath_GmCerts (const iGmCerts *, const iGmIdentity *identity); | ||
81 | |||
82 | iGmIdentity * identity_GmCerts (iGmCerts *, unsigned int id); | ||
83 | const iGmIdentity * constIdentity_GmCerts (const iGmCerts *, unsigned int id); | ||
84 | const iGmIdentity * identityForUrl_GmCerts (const iGmCerts *, const iString *url); | ||
85 | const iPtrArray * identities_GmCerts (const iGmCerts *); | ||
86 | |||
87 | void signIn_GmCerts (iGmCerts *, iGmIdentity *identity, const iString *url); | ||
88 | void signOut_GmCerts (iGmCerts *, const iString *url); | ||