Skip to content
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

Replace keychain with go keychain #130

Merged
merged 5 commits into from
Aug 7, 2017
Merged

Conversation

lox
Copy link
Collaborator

@lox lox commented Aug 5, 2017

I've been meaning to do this for ages, but finally got around to putting in the PR's to https://github.com/keybase/go-keychain that will let us entirely replace our long-ago-forked custom keychain interaction code. So much joy in this diff.

keybase/go-keychain#12
keybase/go-keychain#13

@lox lox requested review from pda and mtibben August 5, 2017 04:47
Copy link
Collaborator

@pda pda left a comment

Choose a reason for hiding this comment

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

Much nicer 👍

I don't have my Mac handy, but it seems to build and work correctly with go version go1.8.3 linux/amd64.

)

const (
keychainAccessGroup = "ACE1234DEF.com.99designs.aws-vault"
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't fully understand what this is, but looks like it maps to kSecAttrAccessGroup which doesn't sound necessary in this use-case, and ACE1234DEF looks suspiciously like sample data.

Access groups are used to share keychain items among two or more apps.

It's being passed to gokeychain.NewGenericPassword() which calls SetAccessGroup() which calls k.SetString(AccessGroupKey, ag) which treats empty string as unset. So perhaps we should just pass an empty string to gokeychain.NewGenericPassword()? Or is this actually doing something?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yup, agreed. It's for sharing items between a family of apps, which we don't need.

return &keychain{
path: filepath.Join(home, "/Library/Keychains/"+name+".keychain"),
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is one change that probably needs testing. The new code uses simply name +".keychain", vs the old one that references the full path. It works fine on my machine which is 10.12.6.

newItem.SetLabel(item.Label)
newItem.SetDescription(item.Description)
newItem.SetData(item.Data)
newItem.SetSynchronizable(gokeychain.SynchronizableNo)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I like that this is more specific. I wonder what the old default was.

}

return err
return gokeychain.AddItem(item)
Copy link
Member

Choose a reason for hiding this comment

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

I'm getting a compile error?

$ go build github.com/99designs/aws-vault
# github.com/99designs/aws-vault/keyring
keyring/keychain.go:85: cannot use item (type Item) as type keychain.Item in argument to keychain.AddItem

Copy link
Member

Choose a reason for hiding this comment

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

s/item/newItem/ works

@mtibben
Copy link
Member

mtibben commented Aug 6, 2017

All looks good to me

@lox
Copy link
Collaborator Author

lox commented Aug 6, 2017

We really need some sort of CI for this project.

@mtibben
Copy link
Member

mtibben commented Aug 6, 2017

Actually, I have spotted a difference in behaviour. When creating a keychain, v3.7.1 prompts for a password. This version does not. Is that intentional?

@lox
Copy link
Collaborator Author

lox commented Aug 6, 2017

Nope, not intentional.

@lox
Copy link
Collaborator Author

lox commented Aug 6, 2017

Good spotting.

if count > 0 {
a = make([]C.CFTypeRef, count)
C.CFArrayGetValues(cfArray, C.CFRange{0, count}, (*unsafe.Pointer)(&a[0]))
if k.passphrase != "" {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

🤦‍♂️

@lox
Copy link
Collaborator Author

lox commented Aug 7, 2017

Verified this works.

@lox lox merged commit 5777f2d into master Aug 7, 2017
@lox lox deleted the replace-keychain-with-go-keychain branch August 7, 2017 22:33
@lox lox mentioned this pull request Aug 8, 2017
@joho
Copy link
Contributor

joho commented Aug 15, 2017

Hey, I was just going through documenting/tidying stuff in the keyring extraction I did.

Looks like keybase/go-keychain#13 never merged. I'm wondering if there's a bug hidden somewhere and it's no longer doing what we think it does.

@lox
Copy link
Collaborator Author

lox commented Aug 15, 2017

Nah, those folks just take a while to respond sometimes.

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.

None yet

4 participants