osxkeychain

package module
v0.0.0-...-4565eaf Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 29, 2015 License: MIT Imports: 6 Imported by: 0

README

You may want keybase/go-keychain instead, which uses the newer keychain APIs and works for both iOS and OSX.

go-osxkeychain

Golang package for accessing and manipulating the Mac OS X Keychain.

GoDoc

Documentation

Rendered for darwin/amd64

Index

Constants

View Source
const (
	ErrUnimplemented     keychainError = C.errSecUnimplemented
	ErrParam             keychainError = C.errSecParam
	ErrAllocate          keychainError = C.errSecAllocate
	ErrNotAvailable      keychainError = C.errSecNotAvailable
	ErrReadOnly          keychainError = C.errSecReadOnly
	ErrAuthFailed        keychainError = C.errSecAuthFailed
	ErrNoSuchKeychain    keychainError = C.errSecNoSuchKeychain
	ErrInvalidKeychain   keychainError = C.errSecInvalidKeychain
	ErrDuplicateKeychain keychainError = C.errSecDuplicateKeychain
	ErrDuplicateCallback keychainError = C.errSecDuplicateCallback
	ErrInvalidCallback   keychainError = C.errSecInvalidCallback
	ErrDuplicateItem     keychainError = C.errSecDuplicateItem
	ErrItemNotFound      keychainError = C.errSecItemNotFound
	ErrBufferTooSmall    keychainError = C.errSecBufferTooSmall
	ErrDataTooLarge      keychainError = C.errSecDataTooLarge
	ErrNoSuchAttr        keychainError = C.errSecNoSuchAttr
	ErrInvalidItemRef    keychainError = C.errSecInvalidItemRef
	ErrInvalidSearchRef  keychainError = C.errSecInvalidSearchRef
	ErrNoSuchClass       keychainError = C.errSecNoSuchClass
	ErrNoDefaultKeychain keychainError = C.errSecNoDefaultKeychain
	ErrReadOnlyAttr      keychainError = C.errSecReadOnlyAttr
)

Error codes from https://developer.apple.com/library/mac/documentation/security/Reference/keychainservices/Reference/reference.html#//apple_ref/doc/uid/TP30000898-CH5g-CJBEABHG

Variables

This section is empty.

Functions

func AddGenericPassword

func AddGenericPassword(attributes *GenericPasswordAttributes) (err error)

AddGenericPassword adds a generic password with the given attributes to the default keychain.

func FindAndRemoveGenericPassword

func FindAndRemoveGenericPassword(attributes *GenericPasswordAttributes) error

FindAndRemoveGenericPassword finds a generic password with the given attributes in the default keychain and removes it if found. If not found, an error is returned.

func FindGenericPassword

func FindGenericPassword(attributes *GenericPasswordAttributes) ([]byte, error)

FindGenericPassword finds a generic password with the given attributes in the default keychain and returns the password field if found. If not found, an error is returned.

func GetAllAccountNames

func GetAllAccountNames(serviceName string) (accountNames []string, err error)

GetAllAccountNames returns a list of all account names for the given service name in the default keychain.

func RemoveAndAddGenericPassword

func RemoveAndAddGenericPassword(attributes *GenericPasswordAttributes) error

RemoveAndAddGenericPassword calls FindAndRemoveGenericPassword() with the given attributes (ignoring ErrItemNotFound) and then calls AddGenericPassword with the same attributes.

https://developer.apple.com/library/mac/documentation/Security/Reference/keychainservices/index.html says:

Do not delete a keychain item and recreate it in order to modify it; instead, use the SecKeychainItemModifyContent or SecKeychainItemModifyAttributesAndData function to modify an existing keychain item. When you delete a keychain item, you lose any access controls and trust settings added by the user or by other applications.

But this is a security problem, since a malicious app can delete a keychain item and recreate it with an ACL such that it can read it, and then wait for an app to write to it; see http://arxiv.org/abs/1505.06836 .

TODO: Add a test that this function doesn't actually do update-or-add. This would involve setting a separate attribute and then checking for it, though.

Types

type GenericPasswordAttributes

type GenericPasswordAttributes struct {
	ServiceName         string
	AccountName         string
	Password            []byte
	TrustedApplications []string
}

GenericPasswordAttributes holds all the info for a generic password in a keychain.

All string fields must have size that fits in 32 bits. All string fields except for Password must be encoded in UTF-8.

TrustedApplications is a list of additional application (paths) that should have access to the keychain item. The application that creates the keychain item always has access, so this list is for additional apps or executables.

func (*GenericPasswordAttributes) CheckValidity

func (attributes *GenericPasswordAttributes) CheckValidity() error

CheckValidity returns an error if any of the attributes in the given GenericPasswordAttributes are invalid. Otherwise, it returns nil.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL