Skip to content

Commit

Permalink
changed PK variable to SSH_KEY_PATH, added PbK guessing from PK
Browse files Browse the repository at this point in the history
  • Loading branch information
wildart committed May 15, 2016
1 parent 2b94616 commit 1e7fa83
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions base/libgit2/callbacks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -103,43 +103,47 @@ function credentials_callback(cred::Ptr{Ptr{Void}}, url_ptr::Cstring,
end
creds[:user, credid] = username # save credentials

# For SSH we need a public key location, look for environment vars SSH_* as well
publickey = if haskey(ENV,"SSH_PUB_KEY")
ENV["SSH_PUB_KEY"]
# For SSH we need a private key location
privatekey = if haskey(ENV,"SSH_KEY_PATH")
ENV["SSH_KEY_PATH"]
else
keydefpath = creds[:pubkey, credid] # check if credentials were already used
keydefpath = creds[:prvkey, credid] # check if credentials were already used
if keydefpath !== nothing && !isusedcreds
keydefpath # use cached value
else
keydefpath = if keydefpath === nothing
homedir()*"/.ssh/id_rsa.pub"
homedir()*"/.ssh/id_rsa"
end
prompt("Public key location for '$schema$username@$host'", default=keydefpath)
prompt("Private key location for '$schema$username@$host'", default=keydefpath)
end
end
creds[:pubkey, credid] = publickey # save credentials
creds[:prvkey, credid] = privatekey # save credentials

# For SSH we need a private key location
privatekey = if haskey(ENV,"SSH_PRV_KEY")
ENV["SSH_PRV_KEY"]
# For SSH we need a public key location, look for environment vars SSH_* as well
publickey = if haskey(ENV,"SSH_PUB_KEY_PATH")
ENV["SSH_PUB_KEY_PATH"]
else
keydefpath = creds[:prvkey, credid] # check if credentials were already used
keydefpath = creds[:pubkey, credid] # check if credentials were already used
if keydefpath !== nothing && !isusedcreds
keydefpath # use cached value
else
keydefpath = if keydefpath === nothing
homedir()*"/.ssh/id_rsa"
privatekey*".pub"
end
if isfile(keydefpath)
keydefpath
else
prompt("Public key location for '$schema$username@$host'", default=keydefpath)
end
prompt("Private key location for '$schema$username@$host'", default=keydefpath)
end
end
creds[:prvkey, credid] = privatekey # save credentials
creds[:pubkey, credid] = publickey # save credentials

passphrase = if haskey(ENV,"SSH_PRV_KEY_PASS")
ENV["SSH_PRV_KEY_PASS"]
passphrase = if haskey(ENV,"SSH_KEY_PASS")
ENV["SSH_KEY_PASS"]
else
passdef = creds[:pass, credid] # check if credentials were already used
passdef !== nothing && !isusedcreds ? passdef : prompt("Private key passphrase", password=true)
passdef !== nothing && !isusedcreds ? passdef : prompt("Passphrase for $privatekey", password=true)
end
creds[:pass, credid] = passphrase # save credentials

Expand Down

0 comments on commit 1e7fa83

Please sign in to comment.