Skip to content

Add a GTCred wrapper. #254

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

Merged
merged 28 commits into from
Oct 1, 2013
Merged

Add a GTCred wrapper. #254

merged 28 commits into from
Oct 1, 2013

Conversation

tiennou
Copy link
Contributor

@tiennou tiennou commented Sep 10, 2013

This adds support to libgit2 cred.h API in advance of #224 and #252 (and push when the time comes). I'll obviously massage #224 to use it, and @isaac if you have the will (and time) to do the same with #252, that's cool, otherwise it can wait for another PR.

It feels more or less ready except for :

  • This isn't used anywhere, as we have no fetch/push support yet, and Add options argument to GTRepository cloneFromURL #252 "prevents" me from switching clone to it.
  • I have absolutely no idea how to test it because it depends on a working authenticated transport.
  • There's a big PARTIALIMPL in one of the class methods, because I was happily wrapping stuff around, but when the time came for me to look up LIBSSH2_USERAUTH_PUBLICKEY_SIGN_FUNC in libssh2, I just, like, shivered in fear when I saw the LIBSSH2_SESSION parameter. That parameter means that if libgit2 ever asks for a GIT_CREDTYPE_SSH_PUBLICKEY auth type, we have to traverse layers of C-code to get to the SSH layer and back again. As my experience with the libgit2 code is minimal, it will take some time for me to see if there's a general solution.

@tiennou
Copy link
Contributor Author

tiennou commented Sep 10, 2013

Heh, looks like it's in fact libgit2 that's gently pushing its LIBSSH2_SESSION so that we can do... something with it. So the third point above can be replaced by "requires libssh2 to be around" ;-).

@Readmore
Copy link

I'm looking for a way to clone a git repo with authentication ( ssh or https would work ). I'm assuming that is your goal here. How are you planning to implement the authenticated call? Will you be able to add username and password params to the clone call?

@tiennou
Copy link
Contributor Author

tiennou commented Sep 10, 2013

@Readmore Normally, the clone auth support will be added when this one and #252 are merged in.

@ghost ghost assigned jspahrsummers Sep 11, 2013
// A typedef block for the various methods that require authentication
typedef GTCred *(^GTCredBlock)(GTCredentialType allowedTypes, NSString *URL, NSString *username);

@interface GTCred : NSObject
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about GTCredential? That's more consistent with NSURLCredential and Cocoa's verbosity.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, will change it to GTCredential. I just got thrown of by libgit2's name for it ;-).

@jspahrsummers
Copy link
Contributor

What's the issue with using libssh? It can be installed via Homebrew, and #250 is adding it for iOS.

@tiennou
Copy link
Contributor Author

tiennou commented Sep 11, 2013

I'm sure I'm missing something, but I added "support" for libssh2 in #200, which was reverted because it broke CI. True, I never asked if the breakage was due to the iOS build or the OS X. But if libssh2 is now expected to be a "hard" dependency, then there's no issue anymore, and I just need to find some time to understand the 3rd auth type and why it's passing LIBSSH2_SESSION around (there's a reason for that, but right now it's out of my reach).

Conflicts:
	External/Configuration
	External/libgit2
	External/openssl
@jspahrsummers
Copy link
Contributor

@tiennou I think I've fixed all the libssh2 build issues on master, if you wanna merge it in and give that a shot.

@ghost ghost assigned jspahrsummers Sep 16, 2013
@tiennou
Copy link
Contributor Author

tiennou commented Sep 16, 2013

🍯

I added a GTCredentialProvider, in fact I like the idea ;-). I just made the default "implementation" wrap the old block API I had (for easy I-don't-want-to-subclass uses). I won't say more, I expect the documentation to do it for me ;-). Feel free to point out discrepancies, missing/unclear information.

Also I asked on SO about the GTCredentialTypeSSHPublicKey auth type, and it seems like we're supposed to sign data with it. I propose to make the corresponding GTCredential method private until this can be implemented...

This takes paths to key files, not actual key data.
That `GIT_SSH` define is needed in the project to make both `LIBSSH_SESSION` and the correct typedef for `git_cred_sign_callback` visible.

I do think it's a quirk of libgit2 though...
@tiennou
Copy link
Contributor Author

tiennou commented Sep 16, 2013

This more or less depends on libgit2/libgit2#1851 and libgit2/libgit2#1853 now (less on 1851, more on 1853 ;-)). I also made sufficient (I hope) research to implement the 3rd method, so it's now documented. I've built a basic clone app for that, so if there's interest in that, maybe I can put in in some Examples directory (I would have made a test, but SSH keys, passwords and test files don't go along too well).

__unsafe_unretained GTCredentialProvider *credProvider;
} GTCredentialAcquireCallbackInfo;

int GTCredentialAcquireCallback(git_cred **cred, const char *url, const char *username_from_url, unsigned int allowed_types, void *payload);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be done with a method on GTCredentialProvider now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh ? That's the C trampoline that calls GTCredentialProvider, so no, I can't do that. You're supposed to pass it to libgit2 APIs that take a git_cred_aquire_cb (as in the fetch example I've given above).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, sorry, you're right.

NSParameterAssert(privateKeyURL != nil);
NSString *publicKeyPath = publicKeyURL.filePathURL.path;
NSString *privateKeyPath = privateKeyURL.filePathURL.path;
NSAssert(privateKeyPath != nil, @"Invalid file URL passed: %@", privateKeyURL);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be an NSError, not an assertion (e.g., in case the path/URL is user-provided).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see two problems ;-). Maybe it's better to assert because it forces the developer to validate the path before blindly giving it to us (it's gonna get used while the operation is in progress, which means a network operation that is doomed to fail if you don't check before. The other problem is that our current NSError machinery isn't really adapted to non-libgit2 errors (yet ;-)).
Also, this assert merely checks that the user isn't passing anything else than a file:// URL in there (I'm asserting for nil just above, but we require a local path in there).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

About the "yet" part, would you prefer me to rename the category and make it our own GTError ? I don't plan on having any instance methods in there, just the current class methods less the git_ prefix. It's just that I find the category to be a bother, and git_errorForGitError: sounds a little too much git ;-).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine for now, I guess. Your points about validation are good.

@jspahrsummers
Copy link
Contributor

🍊

@tiennou
Copy link
Contributor Author

tiennou commented Sep 30, 2013

📗

typedef GTCredential *(^GTCredentialProviderBlock)(GTCredentialType allowedTypes, NSString *URL, NSString *userName);

@interface GTCredentialProvider ()
@property (nonatomic, readonly) GTCredentialProviderBlock credBlock;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should still be copy to indicate its implemented semantics.

@jspahrsummers
Copy link
Contributor

📘

@tiennou
Copy link
Contributor Author

tiennou commented Oct 1, 2013

🚗

@jspahrsummers
Copy link
Contributor

jspahrsummers added a commit that referenced this pull request Oct 1, 2013
@jspahrsummers jspahrsummers merged commit 10104b2 into master Oct 1, 2013
@jspahrsummers jspahrsummers deleted the git-cred branch October 1, 2013 18:36
phatblat pushed a commit to phatblat/objective-git that referenced this pull request Sep 13, 2014
@jspahrsummers jspahrsummers removed their assignment May 22, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants