Skip to content

Commit 606f6e2

Browse files
committed
cert: move cert enums & struct to its own header
1 parent 8bf0f7e commit 606f6e2

File tree

5 files changed

+133
-101
lines changed

5 files changed

+133
-101
lines changed

include/git2.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "git2/blame.h"
1616
#include "git2/branch.h"
1717
#include "git2/buffer.h"
18+
#include "git2/cert.h"
1819
#include "git2/checkout.h"
1920
#include "git2/cherrypick.h"
2021
#include "git2/clone.h"

include/git2/cert.h

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
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+
#ifndef INCLUDE_git_cert_h__
8+
#define INCLUDE_git_cert_h__
9+
10+
#include "common.h"
11+
12+
/**
13+
* @file git2/cert.h
14+
* @brief Git certificate objects
15+
* @defgroup git_cert Certificate objects
16+
* @ingroup Git
17+
* @{
18+
*/
19+
GIT_BEGIN_DECL
20+
21+
/**
22+
* Type of host certificate structure that is passed to the check callback
23+
*/
24+
typedef enum git_cert_t {
25+
/**
26+
* No information about the certificate is available. This may
27+
* happen when using curl.
28+
*/
29+
GIT_CERT_NONE,
30+
/**
31+
* The `data` argument to the callback will be a pointer to
32+
* the DER-encoded data.
33+
*/
34+
GIT_CERT_X509,
35+
/**
36+
* The `data` argument to the callback will be a pointer to a
37+
* `git_cert_hostkey` structure.
38+
*/
39+
GIT_CERT_HOSTKEY_LIBSSH2,
40+
/**
41+
* The `data` argument to the callback will be a pointer to a
42+
* `git_strarray` with `name:content` strings containing
43+
* information about the certificate. This is used when using
44+
* curl.
45+
*/
46+
GIT_CERT_STRARRAY,
47+
} git_cert_t;
48+
49+
/**
50+
* Parent type for `git_cert_hostkey` and `git_cert_x509`.
51+
*/
52+
struct git_cert {
53+
/**
54+
* Type of certificate. A `GIT_CERT_` value.
55+
*/
56+
git_cert_t cert_type;
57+
};
58+
59+
/**
60+
* Callback for the user's custom certificate checks.
61+
*
62+
* @param cert The host certificate
63+
* @param valid Whether the libgit2 checks (OpenSSL or WinHTTP) think
64+
* this certificate is valid
65+
* @param host Hostname of the host libgit2 connected to
66+
* @param payload Payload provided by the caller
67+
* @return 0 to proceed with the connection, < 0 to fail the connection
68+
* or > 0 to indicate that the callback refused to act and that
69+
* the existing validity determination should be honored
70+
*/
71+
typedef int GIT_CALLBACK(git_transport_certificate_check_cb)(git_cert *cert, int valid, const char *host, void *payload);
72+
73+
/**
74+
* Type of SSH host fingerprint
75+
*/
76+
typedef enum {
77+
/** MD5 is available */
78+
GIT_CERT_SSH_MD5 = (1 << 0),
79+
/** SHA-1 is available */
80+
GIT_CERT_SSH_SHA1 = (1 << 1),
81+
} git_cert_ssh_t;
82+
83+
/**
84+
* Hostkey information taken from libssh2
85+
*/
86+
typedef struct {
87+
git_cert parent; /**< The parent cert */
88+
89+
/**
90+
* A hostkey type from libssh2, either
91+
* `GIT_CERT_SSH_MD5` or `GIT_CERT_SSH_SHA1`
92+
*/
93+
git_cert_ssh_t type;
94+
95+
/**
96+
* Hostkey hash. If type has `GIT_CERT_SSH_MD5` set, this will
97+
* have the MD5 hash of the hostkey.
98+
*/
99+
unsigned char hash_md5[16];
100+
101+
/**
102+
* Hostkey hash. If type has `GIT_CERT_SSH_SHA1` set, this will
103+
* have the SHA-1 hash of the hostkey.
104+
*/
105+
unsigned char hash_sha1[20];
106+
} git_cert_hostkey;
107+
108+
/**
109+
* X.509 certificate information
110+
*/
111+
typedef struct {
112+
git_cert parent; /**< The parent cert */
113+
114+
/**
115+
* Pointer to the X.509 certificate data
116+
*/
117+
void *data;
118+
119+
/**
120+
* Length of the memory block pointed to by `data`.
121+
*/
122+
size_t len;
123+
} git_cert_x509;
124+
125+
/** @} */
126+
GIT_END_DECL
127+
#endif

include/git2/proxy.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#define INCLUDE_git_proxy_h__
99

1010
#include "common.h"
11+
12+
#include "cert.h"
1113
#include "cred.h"
1214

1315
GIT_BEGIN_DECL
@@ -67,7 +69,7 @@ typedef struct {
6769
* connection to proceed. Returns 0 to allow the connection
6870
* or a negative value to indicate an error.
6971
*/
70-
git_transport_certificate_check_cb certificate_check;
72+
git_transport_certificate_check_cb certificate_check;
7173

7274
/**
7375
* Payload to be provided to the credentials and certificate

include/git2/transport.h

Lines changed: 1 addition & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "indexer.h"
1111
#include "net.h"
1212
#include "types.h"
13+
#include "cert.h"
1314
#include "cred.h"
1415

1516
/**
@@ -24,58 +25,6 @@ GIT_BEGIN_DECL
2425
/** Signature of a function which creates a transport */
2526
typedef int GIT_CALLBACK(git_transport_cb)(git_transport **out, git_remote *owner, void *param);
2627

27-
/**
28-
* Type of SSH host fingerprint
29-
*/
30-
typedef enum {
31-
/** MD5 is available */
32-
GIT_CERT_SSH_MD5 = (1 << 0),
33-
/** SHA-1 is available */
34-
GIT_CERT_SSH_SHA1 = (1 << 1),
35-
} git_cert_ssh_t;
36-
37-
/**
38-
* Hostkey information taken from libssh2
39-
*/
40-
typedef struct {
41-
git_cert parent; /**< The parent cert */
42-
43-
/**
44-
* A hostkey type from libssh2, either
45-
* `GIT_CERT_SSH_MD5` or `GIT_CERT_SSH_SHA1`
46-
*/
47-
git_cert_ssh_t type;
48-
49-
/**
50-
* Hostkey hash. If type has `GIT_CERT_SSH_MD5` set, this will
51-
* have the MD5 hash of the hostkey.
52-
*/
53-
unsigned char hash_md5[16];
54-
55-
/**
56-
* Hostkey hash. If type has `GIT_CERT_SSH_SHA1` set, this will
57-
* have the SHA-1 hash of the hostkey.
58-
*/
59-
unsigned char hash_sha1[20];
60-
} git_cert_hostkey;
61-
62-
/**
63-
* X.509 certificate information
64-
*/
65-
typedef struct {
66-
git_cert parent; /**< The parent cert */
67-
68-
/**
69-
* Pointer to the X.509 certificate data
70-
*/
71-
void *data;
72-
73-
/**
74-
* Length of the memory block pointed to by `data`.
75-
*/
76-
size_t len;
77-
} git_cert_x509;
78-
7928
/** @} */
8029
GIT_END_DECL
8130

include/git2/types.h

Lines changed: 1 addition & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -255,57 +255,10 @@ typedef struct git_remote_callbacks git_remote_callbacks;
255255
typedef int GIT_CALLBACK(git_transport_message_cb)(const char *str, int len, void *payload);
256256

257257

258-
/**
259-
* Type of host certificate structure that is passed to the check callback
260-
*/
261-
typedef enum git_cert_t {
262-
/**
263-
* No information about the certificate is available. This may
264-
* happen when using curl.
265-
*/
266-
GIT_CERT_NONE,
267-
/**
268-
* The `data` argument to the callback will be a pointer to
269-
* the DER-encoded data.
270-
*/
271-
GIT_CERT_X509,
272-
/**
273-
* The `data` argument to the callback will be a pointer to a
274-
* `git_cert_hostkey` structure.
275-
*/
276-
GIT_CERT_HOSTKEY_LIBSSH2,
277-
/**
278-
* The `data` argument to the callback will be a pointer to a
279-
* `git_strarray` with `name:content` strings containing
280-
* information about the certificate. This is used when using
281-
* curl.
282-
*/
283-
GIT_CERT_STRARRAY,
284-
} git_cert_t;
285-
286258
/**
287259
* Parent type for `git_cert_hostkey` and `git_cert_x509`.
288260
*/
289-
typedef struct {
290-
/**
291-
* Type of certificate. A `GIT_CERT_` value.
292-
*/
293-
git_cert_t cert_type;
294-
} git_cert;
295-
296-
/**
297-
* Callback for the user's custom certificate checks.
298-
*
299-
* @param cert The host certificate
300-
* @param valid Whether the libgit2 checks (OpenSSL or WinHTTP) think
301-
* this certificate is valid
302-
* @param host Hostname of the host libgit2 connected to
303-
* @param payload Payload provided by the caller
304-
* @return 0 to proceed with the connection, < 0 to fail the connection
305-
* or > 0 to indicate that the callback refused to act and that
306-
* the existing validity determination should be honored
307-
*/
308-
typedef int GIT_CALLBACK(git_transport_certificate_check_cb)(git_cert *cert, int valid, const char *host, void *payload);
261+
typedef struct git_cert git_cert;
309262

310263
/**
311264
* Opaque structure representing a submodule.

0 commit comments

Comments
 (0)