Blame include/git2/transport.h

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