50
50
51
51
function authenticate_ssh (libgit2credptr:: Ptr{Ptr{Void}} , p:: CredentialPayload , username_ptr)
52
52
creds = Base. get (p. credential):: SSHCredentials
53
- isusedcreds = checkused! (creds)
53
+
54
+ # Reset password on sucessive calls
55
+ if ! p. first_pass
56
+ creds. pass = " "
57
+ end
54
58
55
59
# Note: The same SSHCredentials can be used to authenticate separate requests using the
56
60
# same credential cache. e.g. using Pkg.update when there are two private packages.
@@ -74,15 +78,10 @@ function authenticate_ssh(libgit2credptr::Ptr{Ptr{Void}}, p::CredentialPayload,
74
78
# if username is not provided or empty, then prompt for it
75
79
username = username_ptr != Cstring (C_NULL ) ? unsafe_string (username_ptr) : " "
76
80
if isempty (username)
77
- uname = creds. user # check if credentials were already used
78
81
prompt_url = git_url (scheme= p. scheme, host= p. host)
79
- if ! isusedcreds
80
- username = uname
81
- else
82
- response = Base. prompt (" Username for '$prompt_url '" , default= uname)
83
- isnull (response) && return user_abort ()
84
- username = unsafe_get (response)
85
- end
82
+ response = Base. prompt (" Username for '$prompt_url '" , default= creds. user)
83
+ isnull (response) && return user_abort ()
84
+ username = unsafe_get (response)
86
85
end
87
86
88
87
prompt_url = git_url (scheme= p. scheme, host= p. host, username= username)
@@ -92,7 +91,7 @@ function authenticate_ssh(libgit2credptr::Ptr{Ptr{Void}}, p::CredentialPayload,
92
91
ENV [" SSH_KEY_PATH" ]
93
92
else
94
93
keydefpath = creds. prvkey # check if credentials were already used
95
- if isempty (keydefpath) || isusedcreds
94
+ if isempty (keydefpath)
96
95
defaultkeydefpath = joinpath (homedir ()," .ssh" ," id_rsa" )
97
96
if isempty (keydefpath) && isfile (defaultkeydefpath)
98
97
keydefpath = defaultkeydefpath
@@ -117,7 +116,7 @@ function authenticate_ssh(libgit2credptr::Ptr{Ptr{Void}}, p::CredentialPayload,
117
116
ENV [" SSH_PUB_KEY_PATH" ]
118
117
else
119
118
keydefpath = creds. pubkey # check if credentials were already used
120
- if isempty (keydefpath) || isusedcreds
119
+ if isempty (keydefpath)
121
120
if isempty (keydefpath)
122
121
keydefpath = privatekey* " .pub"
123
122
end
@@ -135,7 +134,7 @@ function authenticate_ssh(libgit2credptr::Ptr{Ptr{Void}}, p::CredentialPayload,
135
134
ENV [" SSH_KEY_PASS" ]
136
135
else
137
136
passdef = creds. pass # check if credentials were already used
138
- if ( isempty (passdef) || isusedcreds ) && is_passphrase_required (privatekey)
137
+ if isempty (passdef) && is_passphrase_required (privatekey)
139
138
if Sys. iswindows ()
140
139
response = Base. winprompt (
141
140
" Your SSH Key requires a password, please enter it now:" ,
@@ -151,15 +150,13 @@ function authenticate_ssh(libgit2credptr::Ptr{Ptr{Void}}, p::CredentialPayload,
151
150
end
152
151
passdef
153
152
end
154
- ((creds. user != username) || (creds. pass != passphrase) ||
155
- (creds. prvkey != privatekey) || (creds. pubkey != publickey)) && reset! (creds)
156
153
157
154
creds. user = username # save credentials
158
155
creds. prvkey = privatekey # save credentials
159
156
creds. pubkey = publickey # save credentials
160
157
creds. pass = passphrase
161
- else
162
- isusedcreds && return Cint (Error. EAUTH)
158
+ elseif ! p . first_pass
159
+ return Cint (Error. EAUTH)
163
160
end
164
161
165
162
return ccall ((:git_cred_ssh_key_new , :libgit2 ), Cint,
@@ -169,37 +166,39 @@ end
169
166
170
167
function authenticate_userpass (libgit2credptr:: Ptr{Ptr{Void}} , p:: CredentialPayload )
171
168
creds = Base. get (p. credential):: UserPasswordCredentials
172
- isusedcreds = checkused! (creds)
169
+
170
+ # Reset password on sucessive calls
171
+ if ! p. first_pass
172
+ creds. pass = " "
173
+ end
173
174
174
175
if creds. prompt_if_incorrect
175
176
username = creds. user
176
177
userpass = creds. pass
177
- prompt_url = git_url (scheme = p . scheme, host = p . host )
178
- if Sys . iswindows ( )
179
- if isempty (username) || isempty (userpass) || isusedcreds
178
+ if isempty (username) || isempty (userpass )
179
+ prompt_url = git_url (scheme = p . scheme, host = p . host )
180
+ if Sys . iswindows ()
180
181
response = Base. winprompt (" Please enter your credentials for '$prompt_url '" , " Credentials required" ,
181
182
isempty (username) ? p. username : username; prompt_username = true )
182
183
isnull (response) && return user_abort ()
183
184
username, userpass = unsafe_get (response)
184
- end
185
- elseif isusedcreds
186
- response = Base. prompt (" Username for '$prompt_url '" ,
187
- default= isempty (username) ? p. username : username)
188
- isnull (response) && return user_abort ()
189
- username = unsafe_get (response)
185
+ else
186
+ response = Base. prompt (" Username for '$prompt_url '" ,
187
+ default= isempty (username) ? p. username : username)
188
+ isnull (response) && return user_abort ()
189
+ username = unsafe_get (response)
190
190
191
- prompt_url = git_url (scheme= p. scheme, host= p. host, username= username)
192
- response = Base. prompt (" Password for '$prompt_url '" , password= true )
193
- isnull (response) && return user_abort ()
194
- userpass = unsafe_get (response)
195
- isempty (userpass) && return user_abort () # Ambiguous if EOF or newline
191
+ prompt_url = git_url (scheme= p. scheme, host= p. host, username= username)
192
+ response = Base. prompt (" Password for '$prompt_url '" , password= true )
193
+ isnull (response) && return user_abort ()
194
+ userpass = unsafe_get (response)
195
+ isempty (userpass) && return user_abort () # Ambiguous if EOF or newline
196
+ end
196
197
end
197
-
198
- ((creds. user != username) || (creds. pass != userpass)) && reset! (creds)
199
198
creds. user = username # save credentials
200
199
creds. pass = userpass # save credentials
201
- else
202
- isusedcreds && return Cint (Error. EAUTH)
200
+ elseif ! p . first_pass
201
+ return Cint (Error. EAUTH)
203
202
end
204
203
205
204
return ccall ((:git_cred_userpass_plaintext_new , :libgit2 ), Cint,
@@ -228,11 +227,7 @@ Credentials are checked in the following order (if supported):
228
227
**Note**: Due to the specifics of the `libgit2` authentication procedure, when
229
228
authentication fails, this function is called again without any indication whether
230
229
authentication was successful or not. To avoid an infinite loop from repeatedly
231
- using the same faulty credentials, the `checkused!` function can be called. This
232
- function returns `true` if the credentials were used.
233
- Using credentials triggers a user prompt for (re)entering required information.
234
- `UserPasswordCredentials` and `CachedCredentials` are implemented using a call
235
- counting strategy that prevents repeated usage of faulty credentials.
230
+ using the same faulty credentials, we will keep track of state using the payload.
236
231
"""
237
232
function credentials_callback (libgit2credptr:: Ptr{Ptr{Void}} , url_ptr:: Cstring ,
238
233
username_ptr:: Cstring ,
@@ -269,12 +264,16 @@ function credentials_callback(libgit2credptr::Ptr{Ptr{Void}}, url_ptr::Cstring,
269
264
allowed_types &= Cuint (0 ) # Unhandled credential type
270
265
end
271
266
end
267
+
268
+ p. first_pass = true
269
+ else
270
+ p. first_pass = false
272
271
end
273
272
274
273
# use ssh key or ssh-agent
275
274
if isset (allowed_types, Cuint (Consts. CREDTYPE_SSH_KEY))
276
275
if isnull (p. credential) || ! isa (unsafe_get (p. credential), SSHCredentials)
277
- creds = reset! ( SSHCredentials (p. username, " " , true ), - 1 )
276
+ creds = SSHCredentials (p. username, " " , true )
278
277
if ! isnull (p. cache)
279
278
credid = " ssh://$(p. host) "
280
279
creds = get_creds! (unsafe_get (p. cache), credid, creds)
@@ -287,7 +286,7 @@ function credentials_callback(libgit2credptr::Ptr{Ptr{Void}}, url_ptr::Cstring,
287
286
288
287
if isset (allowed_types, Cuint (Consts. CREDTYPE_USERPASS_PLAINTEXT))
289
288
if isnull (p. credential) || ! isa (unsafe_get (p. credential), UserPasswordCredentials)
290
- creds = reset! ( UserPasswordCredentials (p. username, " " , true ), - 1 )
289
+ creds = UserPasswordCredentials (p. username, " " , true )
291
290
if ! isnull (p. cache)
292
291
credid = " $(isempty (p. scheme) ? " ssh" : p. scheme) ://$(p. host) "
293
292
creds = get_creds! (unsafe_get (p. cache), credid, creds)
0 commit comments