Skip to content

Commit 74c6e08

Browse files
committed
http transport: provide proxy credentials
1 parent 496da38 commit 74c6e08

File tree

4 files changed

+19
-8
lines changed

4 files changed

+19
-8
lines changed

src/transports/auth.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@
1111
#include "buffer.h"
1212

1313
static int basic_next_token(
14-
git_buf *out, git_http_auth_context *ctx, git_cred *c)
14+
git_buf *out,
15+
git_http_auth_context *ctx,
16+
const char *header_name,
17+
git_cred *c)
1518
{
1619
git_cred_userpass_plaintext *cred;
1720
git_buf raw = GIT_BUF_INIT;
@@ -29,7 +32,7 @@ static int basic_next_token(
2932
git_buf_printf(&raw, "%s:%s", cred->username, cred->password);
3033

3134
if (git_buf_oom(&raw) ||
32-
git_buf_puts(out, "Authorization: Basic ") < 0 ||
35+
git_buf_printf(out, "%s: Basic ", header_name) < 0 ||
3336
git_buf_encode_base64(out, git_buf_cstr(&raw), raw.size) < 0 ||
3437
git_buf_puts(out, "\r\n") < 0)
3538
goto on_error;

src/transports/auth.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ struct git_http_auth_context {
3131
int (*set_challenge)(git_http_auth_context *ctx, const char *challenge);
3232

3333
/** Gets the next authentication token from the context */
34-
int (*next_token)(git_buf *out, git_http_auth_context *ctx, git_cred *cred);
34+
int (*next_token)(git_buf *out, git_http_auth_context *ctx, const char *header_name, git_cred *cred);
3535

3636
/** Frees the authentication context */
3737
void (*free)(git_http_auth_context *ctx);

src/transports/auth_negotiate.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ static int negotiate_set_challenge(
7373
static int negotiate_next_token(
7474
git_buf *buf,
7575
git_http_auth_context *c,
76+
const char *header_name,
7677
git_cred *cred)
7778
{
7879
http_auth_negotiate_context *ctx = (http_auth_negotiate_context *)c;
@@ -155,7 +156,7 @@ static int negotiate_next_token(
155156
goto done;
156157
}
157158

158-
git_buf_puts(buf, "Authorization: Negotiate ");
159+
git_buf_printf(buf, "%s: Negotiate ", header_name);
159160
git_buf_encode_base64(buf, output_token.value, output_token.length);
160161
git_buf_puts(buf, "\r\n");
161162

src/transports/http.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ static const char *receive_pack_service_url = "/git-receive-pack";
3737
static const char *get_verb = "GET";
3838
static const char *post_verb = "POST";
3939

40+
#define AUTH_HEADER_SERVER "Authorization"
41+
#define AUTH_HEADER_PROXY "Proxy-Authorization"
42+
4043
#define SERVER_TYPE_REMOTE "remote"
4144
#define SERVER_TYPE_PROXY "proxy"
4245

@@ -179,7 +182,10 @@ static int auth_context_match(
179182
return 0;
180183
}
181184

182-
static int apply_credentials(git_buf *buf, http_server *server)
185+
static int apply_credentials(
186+
git_buf *buf,
187+
http_server *server,
188+
const char *header_name)
183189
{
184190
git_cred *cred = server->cred;
185191
git_http_auth_context *context;
@@ -205,7 +211,7 @@ static int apply_credentials(git_buf *buf, http_server *server)
205211
if (!context)
206212
return 0;
207213

208-
return context->next_token(buf, context, cred);
214+
return context->next_token(buf, context, header_name, cred);
209215
}
210216

211217
static int gen_request(
@@ -253,8 +259,9 @@ static int gen_request(
253259
git_buf_printf(buf, "%s\r\n", t->owner->custom_headers.strings[i]);
254260
}
255261

256-
/* Apply credentials to the request */
257-
if (apply_credentials(buf, &t->server) < 0)
262+
/* Apply proxy and server credentials to the request */
263+
if (apply_credentials(buf, &t->proxy, AUTH_HEADER_PROXY) < 0 ||
264+
apply_credentials(buf, &t->server, AUTH_HEADER_SERVER) < 0)
258265
return -1;
259266

260267
git_buf_puts(buf, "\r\n");

0 commit comments

Comments
 (0)