Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
git2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
git2
Commits
ee7040fd
Commit
ee7040fd
authored
Nov 20, 2013
by
Alessandro Ghedini
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ssh: add support for ssh-agent authentication
parent
43cb8b32
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
74 additions
and
2 deletions
+74
-2
src/transports/cred.c
+22
-0
src/transports/ssh.c
+52
-2
No files found.
src/transports/cred.c
View file @
ee7040fd
...
...
@@ -165,6 +165,28 @@ int git_cred_ssh_key_new(
return
0
;
}
int
git_cred_ssh_key_from_agent
(
git_cred
**
cred
,
const
char
*
username
)
{
git_cred_ssh_key
*
c
;
assert
(
cred
);
c
=
git__calloc
(
1
,
sizeof
(
git_cred_ssh_key
));
GITERR_CHECK_ALLOC
(
c
);
c
->
parent
.
credtype
=
GIT_CREDTYPE_SSH_KEY
;
c
->
parent
.
free
=
ssh_key_free
;
if
(
username
)
{
c
->
username
=
git__strdup
(
username
);
GITERR_CHECK_ALLOC
(
c
->
username
);
}
c
->
privatekey
=
NULL
;
*
cred
=
&
c
->
parent
;
return
0
;
}
int
git_cred_ssh_custom_new
(
git_cred
**
cred
,
const
char
*
username
,
...
...
src/transports/ssh.c
View file @
ee7040fd
...
...
@@ -235,6 +235,50 @@ static int git_ssh_extract_url_parts(
return
0
;
}
static
int
ssh_agent_auth
(
LIBSSH2_SESSION
*
session
,
git_cred_ssh_key
*
c
)
{
int
rc
=
LIBSSH2_ERROR_NONE
;
struct
libssh2_agent_publickey
*
curr
,
*
prev
=
NULL
;
LIBSSH2_AGENT
*
agent
=
libssh2_agent_init
(
session
);
if
(
agent
==
NULL
)
return
-
1
;
rc
=
libssh2_agent_connect
(
agent
);
if
(
rc
!=
LIBSSH2_ERROR_NONE
)
goto
shutdown
;
rc
=
libssh2_agent_list_identities
(
agent
);
if
(
rc
!=
LIBSSH2_ERROR_NONE
)
goto
shutdown
;
while
(
1
)
{
rc
=
libssh2_agent_get_identity
(
agent
,
&
curr
,
prev
);
if
(
rc
<
0
)
goto
shutdown
;
if
(
rc
==
1
)
goto
shutdown
;
rc
=
libssh2_agent_userauth
(
agent
,
c
->
username
,
curr
);
if
(
rc
==
0
)
break
;
prev
=
curr
;
}
shutdown:
libssh2_agent_disconnect
(
agent
);
libssh2_agent_free
(
agent
);
return
rc
;
}
static
int
_git_ssh_authenticate_session
(
LIBSSH2_SESSION
*
session
,
const
char
*
user
,
...
...
@@ -253,8 +297,14 @@ static int _git_ssh_authenticate_session(
case
GIT_CREDTYPE_SSH_KEY
:
{
git_cred_ssh_key
*
c
=
(
git_cred_ssh_key
*
)
cred
;
user
=
c
->
username
?
c
->
username
:
user
;
rc
=
libssh2_userauth_publickey_fromfile
(
session
,
c
->
username
,
c
->
publickey
,
c
->
privatekey
,
c
->
passphrase
);
if
(
c
->
privatekey
)
rc
=
libssh2_userauth_publickey_fromfile
(
session
,
c
->
username
,
c
->
publickey
,
c
->
privatekey
,
c
->
passphrase
);
else
rc
=
ssh_agent_auth
(
session
,
c
);
break
;
}
case
GIT_CREDTYPE_SSH_CUSTOM
:
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment