Blame include/git2/transport.h

Packit Service 20376f
/*
Packit Service 20376f
 * Copyright (C) the libgit2 contributors. All rights reserved.
Packit Service 20376f
 *
Packit Service 20376f
 * This file is part of libgit2, distributed under the GNU GPL v2 with
Packit Service 20376f
 * a Linking Exception. For full terms see the included COPYING file.
Packit Service 20376f
 */
Packit Service 20376f
#ifndef INCLUDE_git_transport_h__
Packit Service 20376f
#define INCLUDE_git_transport_h__
Packit Service 20376f
Packit Service 20376f
#include "indexer.h"
Packit Service 20376f
#include "net.h"
Packit Service 20376f
#include "types.h"
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * @file git2/transport.h
Packit Service 20376f
 * @brief Git transport interfaces and functions
Packit Service 20376f
 * @defgroup git_transport interfaces and functions
Packit Service 20376f
 * @ingroup Git
Packit Service 20376f
 * @{
Packit Service 20376f
 */
Packit Service 20376f
GIT_BEGIN_DECL
Packit Service 20376f
Packit Service 20376f
/** Signature of a function which creates a transport */
Packit Service 20376f
typedef int (*git_transport_cb)(git_transport **out, git_remote *owner, void *param);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Type of SSH host fingerprint
Packit Service 20376f
 */
Packit Service 20376f
typedef enum {
Packit Service 20376f
	/** MD5 is available */
Packit Service 20376f
	GIT_CERT_SSH_MD5 = (1 << 0),
Packit Service 20376f
	/** SHA-1 is available */
Packit Service 20376f
	GIT_CERT_SSH_SHA1 = (1 << 1),
Packit Service 20376f
} git_cert_ssh_t;
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Hostkey information taken from libssh2
Packit Service 20376f
 */
Packit Service 20376f
typedef struct {
Packit Service 20376f
	git_cert parent;
Packit Service 20376f
Packit Service 20376f
	/**
Packit Service 20376f
	 * A hostkey type from libssh2, either
Packit Service 20376f
	 * `GIT_CERT_SSH_MD5` or `GIT_CERT_SSH_SHA1`
Packit Service 20376f
	 */
Packit Service 20376f
	git_cert_ssh_t type;
Packit Service 20376f
Packit Service 20376f
	/**
Packit Service 20376f
	 * Hostkey hash. If type has `GIT_CERT_SSH_MD5` set, this will
Packit Service 20376f
	 * have the MD5 hash of the hostkey.
Packit Service 20376f
	 */
Packit Service 20376f
	unsigned char hash_md5[16];
Packit Service 20376f
Packit Service 20376f
	/**
Packit Service 20376f
	 * Hostkey hash. If type has `GIT_CERT_SSH_SHA1` set, this will
Packit Service 20376f
	 * have the SHA-1 hash of the hostkey.
Packit Service 20376f
	 */
Packit Service 20376f
	unsigned char hash_sha1[20];
Packit Service 20376f
} git_cert_hostkey;
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * X.509 certificate information
Packit Service 20376f
 */
Packit Service 20376f
typedef struct {
Packit Service 20376f
	git_cert parent;
Packit Service 20376f
	/**
Packit Service 20376f
	 * Pointer to the X.509 certificate data
Packit Service 20376f
	 */
Packit Service 20376f
	void *data;
Packit Service 20376f
	/**
Packit Service 20376f
	 * Length of the memory block pointed to by `data`.
Packit Service 20376f
	 */
Packit Service 20376f
	size_t len;
Packit Service 20376f
} git_cert_x509;
Packit Service 20376f
Packit Service 20376f
/*
Packit Service 20376f
 *** Begin interface for credentials acquisition ***
Packit Service 20376f
 */
Packit Service 20376f
Packit Service 20376f
/** Authentication type requested */
Packit Service 20376f
typedef enum {
Packit Service 20376f
	/* git_cred_userpass_plaintext */
Packit Service 20376f
	GIT_CREDTYPE_USERPASS_PLAINTEXT = (1u << 0),
Packit Service 20376f
Packit Service 20376f
	/* git_cred_ssh_key */
Packit Service 20376f
	GIT_CREDTYPE_SSH_KEY = (1u << 1),
Packit Service 20376f
Packit Service 20376f
	/* git_cred_ssh_custom */
Packit Service 20376f
	GIT_CREDTYPE_SSH_CUSTOM = (1u << 2),
Packit Service 20376f
Packit Service 20376f
	/* git_cred_default */
Packit Service 20376f
	GIT_CREDTYPE_DEFAULT = (1u << 3),
Packit Service 20376f
Packit Service 20376f
	/* git_cred_ssh_interactive */
Packit Service 20376f
	GIT_CREDTYPE_SSH_INTERACTIVE = (1u << 4),
Packit Service 20376f
Packit Service 20376f
	/**
Packit Service 20376f
	 * Username-only information
Packit Service 20376f
	 *
Packit Service 20376f
	 * If the SSH transport does not know which username to use,
Packit Service 20376f
	 * it will ask via this credential type.
Packit Service 20376f
	 */
Packit Service 20376f
	GIT_CREDTYPE_USERNAME = (1u << 5),
Packit Service 20376f
Packit Service 20376f
	/**
Packit Service 20376f
	 * Credentials read from memory.
Packit Service 20376f
	 *
Packit Service 20376f
	 * Only available for libssh2+OpenSSL for now.
Packit Service 20376f
	 */
Packit Service 20376f
	GIT_CREDTYPE_SSH_MEMORY = (1u << 6),
Packit Service 20376f
} git_credtype_t;
Packit Service 20376f
Packit Service 20376f
/* The base structure for all credential types */
Packit Service 20376f
typedef struct git_cred git_cred;
Packit Service 20376f
Packit Service 20376f
struct git_cred {
Packit Service 20376f
	git_credtype_t credtype;
Packit Service 20376f
	void (*free)(git_cred *cred);
Packit Service 20376f
};
Packit Service 20376f
Packit Service 20376f
/** A plaintext username and password */
Packit Service 20376f
typedef struct {
Packit Service 20376f
	git_cred parent;
Packit Service 20376f
	char *username;
Packit Service 20376f
	char *password;
Packit Service 20376f
} git_cred_userpass_plaintext;
Packit Service 20376f
Packit Service 20376f
Packit Service 20376f
/*
Packit Service 20376f
 * If the user hasn't included libssh2.h before git2.h, we need to
Packit Service 20376f
 * define a few types for the callback signatures.
Packit Service 20376f
 */
Packit Service 20376f
#ifndef LIBSSH2_VERSION
Packit Service 20376f
typedef struct _LIBSSH2_SESSION LIBSSH2_SESSION;
Packit Service 20376f
typedef struct _LIBSSH2_USERAUTH_KBDINT_PROMPT LIBSSH2_USERAUTH_KBDINT_PROMPT;
Packit Service 20376f
typedef struct _LIBSSH2_USERAUTH_KBDINT_RESPONSE LIBSSH2_USERAUTH_KBDINT_RESPONSE;
Packit Service 20376f
#endif
Packit Service 20376f
Packit Service 20376f
typedef int (*git_cred_sign_callback)(LIBSSH2_SESSION *session, unsigned char **sig, size_t *sig_len, const unsigned char *data, size_t data_len, void **abstract);
Packit Service 20376f
typedef void (*git_cred_ssh_interactive_callback)(const char* name, int name_len, const char* instruction, int instruction_len, int num_prompts, const LIBSSH2_USERAUTH_KBDINT_PROMPT* prompts, LIBSSH2_USERAUTH_KBDINT_RESPONSE* responses, void **abstract);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * A ssh key from disk
Packit Service 20376f
 */
Packit Service 20376f
typedef struct git_cred_ssh_key {
Packit Service 20376f
	git_cred parent;
Packit Service 20376f
	char *username;
Packit Service 20376f
	char *publickey;
Packit Service 20376f
	char *privatekey;
Packit Service 20376f
	char *passphrase;
Packit Service 20376f
} git_cred_ssh_key;
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Keyboard-interactive based ssh authentication
Packit Service 20376f
 */
Packit Service 20376f
typedef struct git_cred_ssh_interactive {
Packit Service 20376f
	git_cred parent;
Packit Service 20376f
	char *username;
Packit Service 20376f
	git_cred_ssh_interactive_callback prompt_callback;
Packit Service 20376f
	void *payload;
Packit Service 20376f
} git_cred_ssh_interactive;
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * A key with a custom signature function
Packit Service 20376f
 */
Packit Service 20376f
typedef struct git_cred_ssh_custom {
Packit Service 20376f
	git_cred parent;
Packit Service 20376f
	char *username;
Packit Service 20376f
	char *publickey;
Packit Service 20376f
	size_t publickey_len;
Packit Service 20376f
	git_cred_sign_callback sign_callback;
Packit Service 20376f
	void *payload;
Packit Service 20376f
} git_cred_ssh_custom;
Packit Service 20376f
Packit Service 20376f
/** A key for NTLM/Kerberos "default" credentials */
Packit Service 20376f
typedef struct git_cred git_cred_default;
Packit Service 20376f
Packit Service 20376f
/** Username-only credential information */
Packit Service 20376f
typedef struct git_cred_username {
Packit Service 20376f
	git_cred parent;
Packit Service 20376f
	char username[1];
Packit Service 20376f
} git_cred_username;
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Check whether a credential object contains username information.
Packit Service 20376f
 *
Packit Service 20376f
 * @param cred object to check
Packit Service 20376f
 * @return 1 if the credential object has non-NULL username, 0 otherwise
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_cred_has_username(git_cred *cred);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Create a new plain-text username and password credential object.
Packit Service 20376f
 * The supplied credential parameter will be internally duplicated.
Packit Service 20376f
 *
Packit Service 20376f
 * @param out The newly created credential object.
Packit Service 20376f
 * @param username The username of the credential.
Packit Service 20376f
 * @param password The password of the credential.
Packit Service 20376f
 * @return 0 for success or an error code for failure
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_cred_userpass_plaintext_new(
Packit Service 20376f
	git_cred **out,
Packit Service 20376f
	const char *username,
Packit Service 20376f
	const char *password);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Create a new passphrase-protected ssh key credential object.
Packit Service 20376f
 * The supplied credential parameter will be internally duplicated.
Packit Service 20376f
 *
Packit Service 20376f
 * @param out The newly created credential object.
Packit Service 20376f
 * @param username username to use to authenticate
Packit Service 20376f
 * @param publickey The path to the public key of the credential.
Packit Service 20376f
 * @param privatekey The path to the private key of the credential.
Packit Service 20376f
 * @param passphrase The passphrase of the credential.
Packit Service 20376f
 * @return 0 for success or an error code for failure
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_cred_ssh_key_new(
Packit Service 20376f
	git_cred **out,
Packit Service 20376f
	const char *username,
Packit Service 20376f
	const char *publickey,
Packit Service 20376f
	const char *privatekey,
Packit Service 20376f
	const char *passphrase);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Create a new ssh keyboard-interactive based credential object.
Packit Service 20376f
 * The supplied credential parameter will be internally duplicated.
Packit Service 20376f
 *
Packit Service 20376f
 * @param username Username to use to authenticate.
Packit Service 20376f
 * @param prompt_callback The callback method used for prompts.
Packit Service 20376f
 * @param payload Additional data to pass to the callback.
Packit Service 20376f
 * @return 0 for success or an error code for failure.
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_cred_ssh_interactive_new(
Packit Service 20376f
	git_cred **out,
Packit Service 20376f
	const char *username,
Packit Service 20376f
	git_cred_ssh_interactive_callback prompt_callback,
Packit Service 20376f
	void *payload);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Create a new ssh key credential object used for querying an ssh-agent.
Packit Service 20376f
 * The supplied credential parameter will be internally duplicated.
Packit Service 20376f
 *
Packit Service 20376f
 * @param out The newly created credential object.
Packit Service 20376f
 * @param username username to use to authenticate
Packit Service 20376f
 * @return 0 for success or an error code for failure
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_cred_ssh_key_from_agent(
Packit Service 20376f
	git_cred **out,
Packit Service 20376f
	const char *username);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Create an ssh key credential with a custom signing function.
Packit Service 20376f
 *
Packit Service 20376f
 * This lets you use your own function to sign the challenge.
Packit Service 20376f
 *
Packit Service 20376f
 * This function and its credential type is provided for completeness
Packit Service 20376f
 * and wraps `libssh2_userauth_publickey()`, which is undocumented.
Packit Service 20376f
 *
Packit Service 20376f
 * The supplied credential parameter will be internally duplicated.
Packit Service 20376f
 *
Packit Service 20376f
 * @param out The newly created credential object.
Packit Service 20376f
 * @param username username to use to authenticate
Packit Service 20376f
 * @param publickey The bytes of the public key.
Packit Service 20376f
 * @param publickey_len The length of the public key in bytes.
Packit Service 20376f
 * @param sign_callback The callback method to sign the data during the challenge.
Packit Service 20376f
 * @param payload Additional data to pass to the callback.
Packit Service 20376f
 * @return 0 for success or an error code for failure
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_cred_ssh_custom_new(
Packit Service 20376f
	git_cred **out,
Packit Service 20376f
	const char *username,
Packit Service 20376f
	const char *publickey,
Packit Service 20376f
	size_t publickey_len,
Packit Service 20376f
	git_cred_sign_callback sign_callback,
Packit Service 20376f
	void *payload);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Create a "default" credential usable for Negotiate mechanisms like NTLM
Packit Service 20376f
 * or Kerberos authentication.
Packit Service 20376f
 *
Packit Service 20376f
 * @return 0 for success or an error code for failure
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_cred_default_new(git_cred **out);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Create a credential to specify a username.
Packit Service 20376f
 *
Packit Service 20376f
 * This is used with ssh authentication to query for the username if
Packit Service 20376f
 * none is specified in the url.
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_cred_username_new(git_cred **cred, const char *username);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Create a new ssh key credential object reading the keys from memory.
Packit Service 20376f
 *
Packit Service 20376f
 * @param out The newly created credential object.
Packit Service 20376f
 * @param username username to use to authenticate.
Packit Service 20376f
 * @param publickey The public key of the credential.
Packit Service 20376f
 * @param privatekey The private key of the credential.
Packit Service 20376f
 * @param passphrase The passphrase of the credential.
Packit Service 20376f
 * @return 0 for success or an error code for failure
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_cred_ssh_key_memory_new(
Packit Service 20376f
	git_cred **out,
Packit Service 20376f
	const char *username,
Packit Service 20376f
	const char *publickey,
Packit Service 20376f
	const char *privatekey,
Packit Service 20376f
	const char *passphrase);
Packit Service 20376f
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Free a credential.
Packit Service 20376f
 *
Packit Service 20376f
 * This is only necessary if you own the object; that is, if you are a
Packit Service 20376f
 * transport.
Packit Service 20376f
 *
Packit Service 20376f
 * @param cred the object to free
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(void) git_cred_free(git_cred *cred);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Signature of a function which acquires a credential object.
Packit Service 20376f
 *
Packit Service 20376f
 * @param cred The newly created credential object.
Packit Service 20376f
 * @param url The resource for which we are demanding a credential.
Packit Service 20376f
 * @param username_from_url The username that was embedded in a "user\@host"
Packit Service 20376f
 *                          remote url, or NULL if not included.
Packit Service 20376f
 * @param allowed_types A bitmask stating which cred types are OK to return.
Packit Service 20376f
 * @param payload The payload provided when specifying this callback.
Packit Service 20376f
 * @return 0 for success, < 0 to indicate an error, > 0 to indicate
Packit Service 20376f
 *       no credential was acquired
Packit Service 20376f
 */
Packit Service 20376f
typedef int (*git_cred_acquire_cb)(
Packit Service 20376f
	git_cred **cred,
Packit Service 20376f
	const char *url,
Packit Service 20376f
	const char *username_from_url,
Packit Service 20376f
	unsigned int allowed_types,
Packit Service 20376f
	void *payload);
Packit Service 20376f
Packit Service 20376f
/** @} */
Packit Service 20376f
GIT_END_DECL
Packit Service 20376f
#endif