From 83a9952c53d363769b12d54e1312a72ecd8382e7 Mon Sep 17 00:00:00 2001 From: Slava Karpenko Date: Tue, 4 Aug 2015 20:36:00 +0300 Subject: [PATCH 1/3] Added support for git_cred_ssh_key_memory_new GTCredentials Added +[GTCredential credentialWithUserName:publicKeyString:privateKeyString:passphrase:error:] to support libgit2 git_cred_ssh_key_memory_new() credentials. --- ObjectiveGit/GTCredential.h | 12 ++++++++++++ ObjectiveGit/GTCredential.m | 13 +++++++++++++ 2 files changed, 25 insertions(+) diff --git a/ObjectiveGit/GTCredential.h b/ObjectiveGit/GTCredential.h index 54c6110ff..a56fa3e8b 100644 --- a/ObjectiveGit/GTCredential.h +++ b/ObjectiveGit/GTCredential.h @@ -74,6 +74,18 @@ NS_ASSUME_NONNULL_BEGIN /// Return a new GTCredential instance, or nil if an error occurred + (nullable instancetype)credentialWithUserName:(NSString *)userName publicKeyURL:(nullable NSURL *)publicKeyURL privateKeyURL:(NSURL *)privateKeyURL passphrase:(nullable NSString *)passphrase error:(NSError **)error; +/// Create a credential object from a SSH keyfile data string +/// +/// userName - The username to authenticate as. Must not be nil. +/// publicKeyString - The string containing the public key for that user. +/// Can be omitted to reconstruct the public key from the private key. +/// privateKeyString - The URL to the private key for that user. Must not be nil. +/// passphrase - The passPhrase for the private key. Optional if the private key has no password. +/// error - If not NULL, set to any errors that occur. +/// +/// Return a new GTCredential instance, or nil if an error occurred ++ (nullable instancetype)credentialWithUserName:(NSString *)userName publicKeyString:(nullable NSString *)publicKeyString privateKeyString:(NSString *)privateKeyString passphrase:(nullable NSString *)passphrase error:(NSError **)error; + /// The underlying `git_cred` object. - (git_cred *)git_cred __attribute__((objc_returns_inner_pointer)); diff --git a/ObjectiveGit/GTCredential.m b/ObjectiveGit/GTCredential.m index d75a9d377..03c43e326 100644 --- a/ObjectiveGit/GTCredential.m +++ b/ObjectiveGit/GTCredential.m @@ -71,6 +71,19 @@ + (instancetype)credentialWithUserName:(NSString *)userName publicKeyURL:(NSURL return [[self alloc] initWithGitCred:cred]; } ++ (instancetype)credentialWithUserName:(NSString *)userName publicKeyString:(NSString *)publicKeyString privateKeyString:(NSString *)privateKeyString passphrase:(NSString *)passphrase error:(NSError **)error { + NSParameterAssert(privateKeyString != nil); + + git_cred *cred; + int gitError = git_cred_ssh_key_memory_new(&cred, userName.UTF8String, publicKeyString.UTF8String, privateKeyString.UTF8String, passphrase.UTF8String); + if (gitError != GIT_OK) { + if (error) *error = [NSError git_errorFor:gitError description:@"Failed to create credentials object" failureReason:@"There was an error creating a credential object for username %@ with the provided public/private key pair.\nPublic key: %@\nPrivate key: %@", userName, publicKeyString, privateKeyString]; + return nil; + } + + return [[self alloc] initWithGitCred:cred]; +} + - (instancetype)initWithGitCred:(git_cred *)cred { NSParameterAssert(cred != nil); self = [self init]; From 9011caf4c10b0c5270e8b5446a5e3bcd29f63987 Mon Sep 17 00:00:00 2001 From: Slava Karpenko Date: Thu, 13 Aug 2015 17:27:36 +0300 Subject: [PATCH 2/3] Indentation and commenting fixes Fixed indentation on one of the lines (was a tad off); Removed references to nilability as nullable keyword indicates that. Didn't touch other functions I didn't author. --- ObjectiveGit/GTCredential.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ObjectiveGit/GTCredential.h b/ObjectiveGit/GTCredential.h index a56fa3e8b..5ecf3c7d2 100644 --- a/ObjectiveGit/GTCredential.h +++ b/ObjectiveGit/GTCredential.h @@ -76,10 +76,10 @@ NS_ASSUME_NONNULL_BEGIN /// Create a credential object from a SSH keyfile data string /// -/// userName - The username to authenticate as. Must not be nil. +/// userName - The username to authenticate as. /// publicKeyString - The string containing the public key for that user. -/// Can be omitted to reconstruct the public key from the private key. -/// privateKeyString - The URL to the private key for that user. Must not be nil. +/// Can be omitted to reconstruct the public key from the private key. +/// privateKeyString - The URL to the private key for that user. /// passphrase - The passPhrase for the private key. Optional if the private key has no password. /// error - If not NULL, set to any errors that occur. /// From 3fc761aab2a1965b15e695e4ff06fefb1d959c94 Mon Sep 17 00:00:00 2001 From: Slava Karpenko Date: Thu, 13 Aug 2015 20:38:17 +0300 Subject: [PATCH 3/3] Pointing to libgit2 that supports -- libssh2_userauth_publickey_frommemory --- External/libgit2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/External/libgit2 b/External/libgit2 index abbe17ef1..c27b4afcd 160000 --- a/External/libgit2 +++ b/External/libgit2 @@ -1 +1 @@ -Subproject commit abbe17ef1ffbc264101808829a3317c1c805df96 +Subproject commit c27b4afcdd80f5a45d7120044bf3d78272181abb