Skip to content

Commit

Permalink
Open the keychain and specify it for search, fixes #14
Browse files Browse the repository at this point in the history
  • Loading branch information
lox committed Sep 28, 2015
1 parent 4e18db1 commit 6058ff9
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions keyring/keychain.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,16 @@ func (k *OSXKeychain) Keys() ([]string, error) {
C.kSecMatchLimit: C.kSecMatchLimitAll,
C.kSecReturnAttributes: C.CFTypeRef(C.kCFBooleanTrue),
}

kref, err := openKeychain(k.path)
if err != nil {
return nil, err
}

searchArray := arrayToCFArray([]C.CFTypeRef{C.CFTypeRef(kref)})
defer C.CFRelease(C.CFTypeRef(searchArray))
query[C.kSecMatchSearchList] = C.CFTypeRef(searchArray)

queryDict := mapToCFDictionary(query)
defer C.CFRelease(C.CFTypeRef(queryDict))

Expand Down Expand Up @@ -270,6 +280,7 @@ func createKeychain(path string, promptUser bool, password string) (C.SecKeychai

// The returned SecKeychainRef, if non-nil, must be released via CFRelease.
func openKeychain(path string) (C.SecKeychainRef, error) {
log.Printf("opening keychain %s", path)
pathName := C.CString(path)
defer C.free(unsafe.Pointer(pathName))

Expand Down

0 comments on commit 6058ff9

Please sign in to comment.