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 /** SHA-256 is available */ 82 GIT_CERT_SSH_SHA256 = (1 << 2), 83 } git_cert_ssh_t; 84 85 /** 86 * Hostkey information taken from libssh2 87 */ 88 typedef struct { 89 git_cert parent; /**< The parent cert */ 90 91 /** 92 * A hostkey type from libssh2, either 93 * `GIT_CERT_SSH_MD5` or `GIT_CERT_SSH_SHA1` 94 */ 95 git_cert_ssh_t type; 96 97 /** 98 * Hostkey hash. If type has `GIT_CERT_SSH_MD5` set, this will 99 * have the MD5 hash of the hostkey. 100 */ 101 unsigned char hash_md5[16]; 102 103 /** 104 * Hostkey hash. If type has `GIT_CERT_SSH_SHA1` set, this will 105 * have the SHA-1 hash of the hostkey. 106 */ 107 unsigned char hash_sha1[20]; 108 109 /** 110 * Hostkey hash. If type has `GIT_CERT_SSH_SHA256` set, this will 111 * have the SHA-256 hash of the hostkey. 112 */ 113 unsigned char hash_sha256[32]; 114 } git_cert_hostkey; 115 116 /** 117 * X.509 certificate information 118 */ 119 typedef struct { 120 git_cert parent; /**< The parent cert */ 121 122 /** 123 * Pointer to the X.509 certificate data 124 */ 125 void *data; 126 127 /** 128 * Length of the memory block pointed to by `data`. 129 */ 130 size_t len; 131 } git_cert_x509; 132 133 /** @} */ 134 GIT_END_DECL 135 #endif 136