Skip to content

Commit 03004d0

Browse files
authored
Merge pull request #36 from desktop/separate-helper-trampoline
Create a separate credential helper trampoline
2 parents ac8a04f + fd06e4c commit 03004d0

6 files changed

+194
-88
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ The equivalent Bash shell code looks like this:
6060

6161
```sh
6262
# environment variable
63-
GIT_ASKPASS="C:/some/path/to/desktop-trampoline.exe" \
63+
GIT_ASKPASS="C:/some/path/to/desktop-askpass-trampoline.exe" \
6464
# ensure Git doesn't block the process waiting for the user to provide input
6565
GIT_TERMINAL_PROMPT=0 \
6666
git \

binding.gyp

+28-47
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,8 @@
11
{
2-
'targets': [
3-
{
4-
'target_name': 'desktop-trampoline',
2+
'target_defaults': {
53
'defines': [
64
"NAPI_VERSION=<(napi_build_version)",
75
],
8-
'type': 'executable',
9-
'sources': [
10-
'src/desktop-trampoline.c',
11-
'src/socket.c'
12-
],
136
'include_dirs': [
147
'<!(node -p "require(\'node-addon-api\').include_dir")',
158
'include'
@@ -42,62 +35,50 @@
4235
'msvs_settings': {
4336
'VCCLCompilerTool': { 'ExceptionHandling': 1 },
4437
},
38+
'conditions': [
39+
['OS=="win"', { 'defines': [ 'WINDOWS' ] }]
40+
]
41+
},
42+
'targets': [
43+
{
44+
'target_name': 'desktop-askpass-trampoline',
45+
'type': 'executable',
46+
'sources': [
47+
'src/desktop-trampoline.c',
48+
'src/socket.c'
49+
],
4550
'conditions': [
4651
['OS=="win"', {
47-
'defines': [ 'WINDOWS' ],
4852
'link_settings': {
4953
'libraries': [ 'Ws2_32.lib' ]
5054
}
5155
}]
5256
]
5357
},
5458
{
55-
'target_name': 'ssh-wrapper',
59+
'target_name': 'desktop-credential-helper-trampoline',
60+
'type': 'executable',
5661
'defines': [
57-
"NAPI_VERSION=<(napi_build_version)",
62+
'CREDENTIAL_HELPER'
5863
],
59-
'type': 'executable',
6064
'sources': [
61-
'src/ssh-wrapper.c'
62-
],
63-
'include_dirs': [
64-
'<!(node -p "require(\'node-addon-api\').include_dir")',
65-
'include'
66-
],
67-
'xcode_settings': {
68-
'OTHER_CFLAGS': [
69-
'-Wall',
70-
'-Werror',
71-
'-Werror=format-security',
72-
'-fPIC',
73-
'-D_FORTIFY_SOURCE=1',
74-
'-fstack-protector-strong'
75-
]
76-
},
77-
'cflags!': [
78-
'-Wall',
79-
'-Werror',
80-
'-fPIC',
81-
'-pie',
82-
'-D_FORTIFY_SOURCE=1',
83-
'-fstack-protector-strong',
84-
'-Werror=format-security',
85-
'-fno-exceptions'
86-
],
87-
'cflags_cc!': [ '-fno-exceptions' ],
88-
'ldflags!': [
89-
'-z relro',
90-
'-z now'
65+
'src/desktop-trampoline.c',
66+
'src/socket.c'
9167
],
92-
'msvs_settings': {
93-
'VCCLCompilerTool': { 'ExceptionHandling': 1 },
94-
},
9568
'conditions': [
96-
# For now only build it for macOS, since it's not needed on Windows
9769
['OS=="win"', {
98-
'defines': [ 'WINDOWS' ],
70+
'link_settings': {
71+
'libraries': [ 'Ws2_32.lib' ]
72+
}
9973
}]
10074
]
10175
},
76+
{
77+
'target_name': 'ssh-wrapper',
78+
'type': 'executable',
79+
'sources': [
80+
'src/ssh-wrapper.c'
81+
],
82+
},
10283
],
10384
}

index.d.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
export function getDesktopTrampolinePath(): string
2-
export function getDesktopTrampolineFilename(): string
1+
export function getDesktopAskpassTrampolinePath(): string
2+
export function getDesktopAskpassTrampolineFilename(): string
3+
4+
export function getDesktopCredentialHelperTrampolinePath(): string
5+
export function getDesktopCredentialHelperTrampolineFilename(): string
36

47
export function getSSHWrapperPath(): string
58
export function getSSHWrapperFilename(): string

index.js

+24-7
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,33 @@
11
const Path = require('path')
22

3-
function getDesktopTrampolinePath() {
3+
function getDesktopAskpassTrampolinePath() {
44
return Path.join(
55
__dirname,
66
'build',
77
'Release',
8-
getDesktopTrampolineFilename()
8+
getDesktopAskpassTrampolineFilename()
99
)
1010
}
1111

12-
function getDesktopTrampolineFilename() {
12+
function getDesktopAskpassTrampolineFilename() {
1313
return process.platform === 'win32'
14-
? 'desktop-trampoline.exe'
15-
: 'desktop-trampoline'
14+
? 'desktop-askpass-trampoline.exe'
15+
: 'desktop-askpass-trampoline'
16+
}
17+
18+
function getDesktopCredentialHelperTrampolinePath() {
19+
return Path.join(
20+
__dirname,
21+
'build',
22+
'Release',
23+
getDesktopCredentialHelperTrampolineFilename()
24+
)
25+
}
26+
27+
function getDesktopCredentialHelperTrampolineFilename() {
28+
return process.platform === 'win32'
29+
? 'desktop-credential-helper-trampoline.exe'
30+
: 'desktop-credential-helper-trampoline'
1631
}
1732

1833
function getSSHWrapperPath() {
@@ -24,8 +39,10 @@ function getSSHWrapperFilename() {
2439
}
2540

2641
module.exports = {
27-
getDesktopTrampolinePath,
28-
getDesktopTrampolineFilename,
42+
getDesktopAskpassTrampolinePath,
43+
getDesktopAskpassTrampolineFilename,
44+
getDesktopCredentialHelperTrampolinePath,
45+
getDesktopCredentialHelperTrampolineFilename,
2946
getSSHWrapperPath,
3047
getSSHWrapperFilename,
3148
}

src/desktop-trampoline.c

+20-5
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@
99
#define BUFFER_LENGTH 4096
1010
#define MAXIMUM_NUMBER_LENGTH 33
1111

12+
#ifdef CREDENTIAL_HELPER
13+
#define DESKTOP_TRAMPOLINE_IDENTIFIER "CREDENTIALHELPER"
14+
#else
15+
#define DESKTOP_TRAMPOLINE_IDENTIFIER "ASKPASS"
16+
#endif
17+
18+
1219
#define WRITE_STRING_OR_EXIT(dataName, dataString) \
1320
if (writeSocket(socket, dataString, strlen(dataString) + 1) != 0) { \
1421
printSocketError("ERROR: Couldn't send " dataName); \
@@ -17,9 +24,8 @@ if (writeSocket(socket, dataString, strlen(dataString) + 1) != 0) { \
1724

1825
// This is a list of valid environment variables that GitHub Desktop might
1926
// send or expect to receive.
20-
#define NUMBER_OF_VALID_ENV_VARS 2
27+
#define NUMBER_OF_VALID_ENV_VARS 1
2128
static const char *sValidEnvVars[NUMBER_OF_VALID_ENV_VARS] = {
22-
"DESKTOP_TRAMPOLINE_IDENTIFIER",
2329
"DESKTOP_TRAMPOLINE_TOKEN",
2430
};
2531

@@ -81,8 +87,9 @@ int runTrampolineClient(SOCKET *outSocket, int argc, char **argv, char **envp) {
8187
}
8288

8389
// Get the number of environment variables
84-
char *validEnvVars[NUMBER_OF_VALID_ENV_VARS];
85-
int envc = 0;
90+
char *validEnvVars[NUMBER_OF_VALID_ENV_VARS + 1];
91+
validEnvVars[0] = "DESKTOP_TRAMPOLINE_IDENTIFIER=" DESKTOP_TRAMPOLINE_IDENTIFIER;
92+
int envc = 1;
8693
for (char **env = envp; *env != 0; env++) {
8794
if (isValidEnvVar(*env)) {
8895
validEnvVars[envc] = *env;
@@ -100,7 +107,15 @@ int runTrampolineClient(SOCKET *outSocket, int argc, char **argv, char **envp) {
100107
WRITE_STRING_OR_EXIT("environment variable", validEnvVars[idx]);
101108
}
102109

103-
// TODO: send stdin stuff?
110+
char stdinBuffer[BUFFER_LENGTH + 1];
111+
int stdinBytes = 0;
112+
113+
#ifdef CREDENTIAL_HELPER
114+
stdinBytes = fread(stdinBuffer, sizeof(char), BUFFER_LENGTH, stdin);
115+
#endif
116+
117+
stdinBuffer[stdinBytes] = '\0';
118+
WRITE_STRING_OR_EXIT("stdin", stdinBuffer);
104119

105120
char buffer[BUFFER_LENGTH + 1];
106121
size_t totalBytesRead = 0;

0 commit comments

Comments
 (0)