1 /*
2  * Copyright (C) the libgit2 contributors. All rights reserved.
3  *
4  * This file is part of libgit2, distributed under the GNU GPL v2 with
5  * a Linking Exception. For full terms see the included COPYING file.
6  */
7 module libgit2_d.cert;
8 
9 
10 /**
11  * @file git2/cert.h
12  * @brief Git certificate objects
13  * @defgroup git_cert Certificate objects
14  * @ingroup Git
15  * @{
16  */
17 extern (C):
18 nothrow @nogc:
19 public:
20 
21 /**
22  * Type of host certificate structure that is passed to the check callback
23  */
24 enum git_cert_t
25 {
26 	/**
27 	 * No information about the certificate is available. This may
28 	 * happen when using curl.
29 	 */
30 	GIT_CERT_NONE,
31 
32 	/**
33 	 * The `data` argument to the callback will be a pointer to
34 	 * the DER-encoded data.
35 	 */
36 	GIT_CERT_X509,
37 
38 	/**
39 	 * The `data` argument to the callback will be a pointer to a
40 	 * `git_cert_hostkey` structure.
41 	 */
42 	GIT_CERT_HOSTKEY_LIBSSH2,
43 
44 	/**
45 	 * The `data` argument to the callback will be a pointer to a
46 	 * `git_strarray` with `name:content` strings containing
47 	 * information about the certificate. This is used when using
48 	 * curl.
49 	 */
50 	GIT_CERT_STRARRAY,
51 }
52 
53 //Declaration name in C language
54 enum
55 {
56 	GIT_CERT_NONE = .git_cert_t.GIT_CERT_NONE,
57 	GIT_CERT_X509 = .git_cert_t.GIT_CERT_X509,
58 	GIT_CERT_HOSTKEY_LIBSSH2 = .git_cert_t.GIT_CERT_HOSTKEY_LIBSSH2,
59 	GIT_CERT_STRARRAY = .git_cert_t.GIT_CERT_STRARRAY,
60 }
61 
62 /**
63  * Parent type for `git_cert_hostkey` and `git_cert_x509`.
64  */
65 struct git_cert
66 {
67 	/**
68 	 * Type of certificate. A `GIT_CERT_` value.
69 	 */
70 	.git_cert_t cert_type;
71 }
72 
73 /**
74  * Callback for the user's custom certificate checks.
75  *
76  * Params:
77  *      cert = The host certificate
78  *      valid = Whether the libgit2 checks (OpenSSL or WinHTTP) think this certificate is valid
79  *      host = Hostname of the host libgit2 connected to
80  *      payload = Payload provided by the caller
81  *
82  * Returns: 0 to proceed with the connection, < 0 to fail the connection or > 0 to indicate that the callback refused to act and that the existing validity determination should be honored
83  */
84 alias git_transport_certificate_check_cb = int function(.git_cert* cert, int valid, const (char)* host, void* payload);
85 
86 /**
87  * Type of SSH host fingerprint
88  */
89 enum git_cert_ssh_t
90 {
91 	/**
92 	 * MD5 is available
93 	 */
94 	GIT_CERT_SSH_MD5 = 1 << 0,
95 
96 	/**
97 	 * SHA-1 is available
98 	 */
99 	GIT_CERT_SSH_SHA1 = 1 << 1,
100 
101 	/**
102 	 * SHA-256 is available
103 	 */
104 	GIT_CERT_SSH_SHA256 = 1 << 2,
105 }
106 
107 //Declaration name in C language
108 enum
109 {
110 	GIT_CERT_SSH_MD5 = .git_cert_ssh_t.GIT_CERT_SSH_MD5,
111 	GIT_CERT_SSH_SHA1 = .git_cert_ssh_t.GIT_CERT_SSH_SHA1,
112 	GIT_CERT_SSH_SHA256 = .git_cert_ssh_t.GIT_CERT_SSH_SHA256,
113 }
114 
115 /**
116  * Hostkey information taken from libssh2
117  */
118 struct git_cert_hostkey
119 {
120 	/**
121 	 * The parent cert
122 	 */
123 	.git_cert parent;
124 
125 	/**
126 	 * A hostkey type from libssh2, either
127 	 * `git_cert_ssh_t.GIT_CERT_SSH_MD5` or `git_cert_ssh_t.GIT_CERT_SSH_SHA1`
128 	 */
129 	.git_cert_ssh_t type = cast(.git_cert_ssh_t)(0);
130 
131 	/**
132 	 * Hostkey hash. If type has `git_cert_ssh_t.GIT_CERT_SSH_MD5` set, this will
133 	 * have the MD5 hash of the hostkey.
134 	 */
135 	ubyte[16] hash_md5;
136 
137 	/**
138 	 * Hostkey hash. If type has `git_cert_ssh_t.GIT_CERT_SSH_SHA1` set, this will
139 	 * have the SHA-1 hash of the hostkey.
140 	 */
141 	ubyte[20] hash_sha1;
142 
143 	/**
144 	 * Hostkey hash. If type has `GIT_CERT_SSH_SHA256` set, this will
145 	 * have the SHA-256 hash of the hostkey.
146 	 */
147 	ubyte[32] hash_sha256;
148 }
149 
150 /**
151  * X.509 certificate information
152  */
153 struct git_cert_x509
154 {
155 	/**
156 	 * The parent cert
157 	 */
158 	.git_cert parent;
159 
160 	/**
161 	 * Pointer to the X.509 certificate data
162 	 */
163 	void* data;
164 
165 	/**
166 	 * Length of the memory block pointed to by `data`.
167 	 */
168 	size_t len;
169 }
170 
171 /** @} */