-
Notifications
You must be signed in to change notification settings - Fork 897
SSH API Implementation #852
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
8000ec8
d764538
4399842
7d01462
cf0fbdc
88915fa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
False |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
using System; | ||
using System.Runtime.Serialization; | ||
using LibGit2Sharp.Core; | ||
|
||
namespace LibGit2Sharp | ||
{ | ||
/// <summary> | ||
/// The exception that is thrown when an operation which requires an | ||
/// authentication fails. | ||
/// </summary> | ||
[Serializable] | ||
public class AuthenticationException : LibGit2SharpException | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="LibGit2Sharp.AuthenticationException"/> class. | ||
/// </summary> | ||
public AuthenticationException() | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="LibGit2Sharp.AuthenticationException"/> class with a specified error message. | ||
/// </summary> | ||
/// <param name="message">A message that describes the error.</param> | ||
public AuthenticationException(string message) | ||
: base(message) | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="LibGit2Sharp.AuthenticationException"/> class with a specified error message and a reference to the inner exception that is the cause of this exception. | ||
/// </summary> | ||
/// <param name="message">The error message that explains the reason for the exception.</param> | ||
/// <param name="innerException">The exception that is the cause of the current exception. If the <paramref name="innerException"/> parameter is not a null reference, the current exception is raised in a catch block that handles the inner exception.</param> | ||
public AuthenticationException(string message, Exception innerException) | ||
: base(message, innerException) | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="LibGit2Sharp.AuthenticationException"/> class with a serialized data. | ||
/// </summary> | ||
/// <param name="info">The <see cref="SerializationInfo"/> that holds the serialized object data about the exception being thrown.</param> | ||
/// <param name="context">The <see cref="StreamingContext"/> that contains contextual information about the source or destination.</param> | ||
protected AuthenticationException(SerializationInfo info, StreamingContext context) | ||
: base(info, context) | ||
{ | ||
} | ||
|
||
internal AuthenticationException(string message, GitErrorCode code, GitErrorCategory category) | ||
: base(message, code, category) | ||
{ | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -398,6 +398,24 @@ internal static extern int git_cred_userpass_plaintext_new( | |
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof (StrictUtf8Marshaler))] string username, | ||
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof (StrictUtf8Marshaler))] string password); | ||
|
||
[DllImport(libgit2)] | ||
internal static extern int git_cred_ssh_key_new( | ||
out IntPtr cred, | ||
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string username, | ||
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string publickey, | ||
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string privatekey, | ||
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string passphrase); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is most likely wrong, we need an ASCII string passed, from what I saw. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. /cc @carlosmn There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see why we would want to restrict this to ASCII. UTF-8 is compatible with ASCII and what happens if I write my password in Spanish or German? I would need more letters than ASCII there. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, dunno why sending the passphrase in the current state isn't succeeding authentication. I thought maybe libssh2 or something didn't support unicode, I'll investigate |
||
|
||
[DllImport(libgit2)] | ||
internal static extern int git_cred_username_new( | ||
out IntPtr cred, | ||
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string username); | ||
|
||
[DllImport(libgit2)] | ||
internal static extern int git_cred_ssh_key_from_agent( | ||
out IntPtr cred, | ||
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string username); | ||
|
||
[DllImport(libgit2)] | ||
internal static extern int git_describe_commit( | ||
out DescribeResultSafeHandle describe, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using System; | ||
using LibGit2Sharp.Core; | ||
|
||
namespace LibGit2Sharp | ||
{ | ||
/// <summary> | ||
/// Class that holds SSH agent credentials for remote repository access. | ||
/// </summary> | ||
public sealed class SshAgentCredentials : Credentials | ||
{ | ||
/// <summary> | ||
/// Callback to acquire a credential object. | ||
/// </summary> | ||
/// <param name="cred">The newly created credential object.</param> | ||
/// <returns>0 for success, < 0 to indicate an error, > 0 to indicate no credential was acquired.</returns> | ||
protected internal override int GitCredentialHandler(out IntPtr cred) | ||
{ | ||
if (Username == null) | ||
{ | ||
throw new InvalidOperationException("SshAgentCredentials contains a null Username."); | ||
} | ||
|
||
return NativeMethods.git_cred_ssh_key_from_agent(out cred, Username); | ||
} | ||
|
||
/// <summary> | ||
/// Username for SSH authentication. | ||
/// </summary> | ||
public string Username { get; set; } | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
using System; | ||
using LibGit2Sharp.Core; | ||
|
||
namespace LibGit2Sharp | ||
{ | ||
/// <summary> | ||
/// Class that holds SSH username with key credentials for remote repository access. | ||
/// </summary> | ||
public sealed class SshUserKeyCredentials : Credentials | ||
{ | ||
/// <summary> | ||
/// Callback to acquire a credential object. | ||
/// </summary> | ||
/// <param name="cred">The newly created credential object.</param> | ||
/// <returns>0 for success, < 0 to indicate an error, > 0 to indicate no credential was acquired.</returns> | ||
protected internal override int GitCredentialHandler(out IntPtr cred) | ||
{ | ||
if (Username == null) | ||
{ | ||
throw new InvalidOperationException("SshUserKeyCredentials contains a null Username."); | ||
} | ||
|
||
if (Passphrase == null) | ||
{ | ||
throw new InvalidOperationException("SshUserKeyCredentials contains a null Passphrase."); | ||
} | ||
|
||
if (PublicKey == null) | ||
{ | ||
throw new InvalidOperationException("SshUserKeyCredentials contains a null PublicKey."); | ||
} | ||
|
||
if (PrivateKey == null) | ||
{ | ||
throw new InvalidOperationException("SshUserKeyCredentials contains a null PrivateKey."); | ||
} | ||
|
||
return NativeMethods.git_cred_ssh_key_new(out cred, Username, PublicKey, PrivateKey, Passphrase); | ||
} | ||
|
||
/// <summary> | ||
/// Username for SSH authentication. | ||
/// </summary> | ||
public string Username { get; set; } | ||
|
||
/// <summary> | ||
/// Public key file location for SSH authentication. | ||
/// </summary> | ||
public string PublicKey { get; set; } | ||
|
||
/// <summary> | ||
/// Private key file location for SSH authentication. | ||
/// </summary> | ||
public string PrivateKey { get; set; } | ||
|
||
/// <summary> | ||
/// Passphrase for SSH authentication. | ||
/// </summary> | ||
public string Passphrase { get; set; } | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using System; | ||
using LibGit2Sharp.Core; | ||
|
||
namespace LibGit2Sharp | ||
{ | ||
/// <summary> | ||
/// Class that holds username query credentials for remote repository access. | ||
/// </summary> | ||
public sealed class UsernameQueryCredentials : Credentials | ||
{ | ||
/// <summary> | ||
/// Callback to acquire a credential object. | ||
/// </summary> | ||
/// <param name="cred">The newly created credential object.</param> | ||
/// <returns>0 for success, < 0 to indicate an error, > 0 to indicate no credential was acquired.</returns> | ||
protected internal override int GitCredentialHandler(out IntPtr cred) | ||
{ | ||
if (Username == null) | ||
{ | ||
throw new InvalidOperationException("UsernameQueryCredentials contains a null Username."); | ||
} | ||
|
||
return NativeMethods.git_cred_username_new(out cred, Username); | ||
} | ||
|
||
/// <summary> | ||
/// Username for querying the server for supported authentication. | ||
/// </summary> | ||
public string Username { get; set; } | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea. I will.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, SshInteractive isn't implemented. So it's fine like this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I won't be implementing interactive support due to lack of time at the moment. Maybe later, since it requires exposing structs from libssh2 land and lots of binding.
Sorry. 🍶