Skip to content

Commit f90ed64

Browse files
committed
Track SSH agent state in CredentialPayload
1 parent 66ba3eb commit f90ed64

File tree

4 files changed

+10
-19
lines changed

4 files changed

+10
-19
lines changed

base/libgit2/callbacks.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,16 @@ function authenticate_ssh(libgit2credptr::Ptr{Ptr{Void}}, p::CredentialPayload,
6161
errcls, errmsg = Error.last_error()
6262
if errcls != Error.None
6363
# Check if we used ssh-agent
64-
if creds.usesshagent == "U"
65-
creds.usesshagent = "E" # reported ssh-agent error, disables ssh agent use for the future
64+
if p.use_ssh_agent == 'U'
65+
p.use_ssh_agent = 'E' # reported ssh-agent error, disables ssh agent use for the future
6666
end
6767
end
6868

6969
# first try ssh-agent if credentials support its usage
70-
if creds.usesshagent == "Y" || creds.usesshagent == "U"
70+
if p.use_ssh_agent == 'Y' || p.use_ssh_agent == 'U'
7171
err = ccall((:git_cred_ssh_key_from_agent, :libgit2), Cint,
7272
(Ptr{Ptr{Void}}, Cstring), libgit2credptr, username_ptr)
73-
creds.usesshagent = "U" # used ssh-agent only one time
73+
p.use_ssh_agent = 'U' # used ssh-agent only one time
7474
err == 0 && return Cint(0)
7575
end
7676

@@ -221,7 +221,7 @@ For `LibGit2.Consts.CREDTYPE_SSH_KEY` type, if the payload contains fields:
221221
Typing `^D` (control key together with the `d` key) will abort the credential prompt.
222222
223223
Credentials are checked in the following order (if supported):
224-
- ssh key pair (`ssh-agent` if specified in payload's `usesshagent` field)
224+
- ssh key pair (`ssh-agent` if specified in payload's `use_ssh_agent` field)
225225
- plain text
226226
227227
**Note**: Due to the specifics of the `libgit2` authentication procedure, when

base/libgit2/types.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,10 +1100,9 @@ mutable struct SSHCredentials <: AbstractCredentials
11001100
pass::String
11011101
prvkey::String
11021102
pubkey::String
1103-
usesshagent::String # used for ssh-agent authentication
11041103
prompt_if_incorrect::Bool # Whether to allow interactive prompting if the credentials are incorrect
11051104
function SSHCredentials(u::AbstractString,p::AbstractString,prvkey::AbstractString,pubkey::AbstractString,prompt_if_incorrect::Bool=false)
1106-
c = new(u,p,prvkey,pubkey,"Y",prompt_if_incorrect)
1105+
c = new(u,p,prvkey,pubkey,prompt_if_incorrect)
11071106
finalizer(c, securezero!)
11081107
return c
11091108
end
@@ -1148,13 +1147,14 @@ mutable struct CredentialPayload <: Payload
11481147
credential::Nullable{AbstractCredentials}
11491148
cache::Nullable{CachedCredentials}
11501149
first_pass::Bool
1150+
use_ssh_agent::Char
11511151
scheme::String
11521152
username::String
11531153
host::String
11541154
path::String
11551155

11561156
function CredentialPayload(credential::Nullable{<:AbstractCredentials}, cache::Nullable{CachedCredentials})
1157-
new(credential, cache, true, "", "", "", "")
1157+
new(credential, cache, true, 'Y', "", "", "", "")
11581158
end
11591159
end
11601160

test/libgit2-helpers.jl

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,7 @@ function credential_loop(
6565
use_ssh_agent::Bool=false)
6666

6767
if !use_ssh_agent
68-
if isnull(payload.cache)
69-
payload.cache = Nullable(CachedCredentials())
70-
end
71-
cache = get(payload.cache)
72-
73-
m = match(LibGit2.URL_REGEX, url)
74-
default_cred = SSHCredentials(true)
75-
default_cred.usesshagent = "N"
76-
LibGit2.get_creds!(cache, "ssh://$(m[:host])", default_cred)
68+
payload.use_ssh_agent = 'N'
7769
end
7870

7971
credential_loop(valid_credential, url, user, 0x000046, payload)

test/libgit2.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1921,9 +1921,8 @@ mktempdir() do dir
19211921
include($LIBGIT2_HELPER_PATH)
19221922
valid_cred = LibGit2.SSHCredentials($username, $passphrase, $valid_p_key, $(valid_p_key * ".pub"))
19231923
invalid_cred = LibGit2.SSHCredentials($username, "", $invalid_key, $(invalid_key * ".pub"))
1924-
invalid_cred.usesshagent = "N" # Disable SSH agent use
19251924
payload = CredentialPayload(Nullable(invalid_cred))
1926-
credential_loop(valid_cred, $url, $username, payload)
1925+
credential_loop(valid_cred, $url, $username, payload, use_ssh_agent=false)
19271926
end
19281927

19291928
# Explicitly provided credential is correct

0 commit comments

Comments
 (0)