|
| 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 |
0 commit comments