osxkeychain

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2015 License: MIT, MIT Imports: 6 Imported by: 0

README

go-osxkeychain

GoDoc

A golang binding for the OSX Keychain Service API.

Usage

	attributes := osxkeychain.GenericPasswordAttributes{
		ServiceName: "my service",
		AccountName: "my account",
		Password: []byte("password123"),
	}

	// Add the item
	err := osxkeychain.AddGenericPassword(&attributes)
	if err != nil {
		log.Fatal(err)
	}

	// Look it up subsequently
	password, err := FindGenericPassword(&attributes)
	if err != nil {
		t.Error(err)
	}

Documentation

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
)

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) error

AddGenericPassword adds a generic password to the Keychain defined in the attributes Keychain property. This will raise an error if the service and account name already exist as an item

func CreateKeychain

func CreateKeychain(path string, password string) error

CreateKeychain creates a Keychain from the provided password which must fit within 32-bits and be well-formed UTF-8

func CreateKeychainViaPrompt

func CreateKeychainViaPrompt(path string) error

CreateKeychain creates a Keychain via a pop-up prompt to the user

func DeleteKeychain

func DeleteKeychain(path string) error

DeleteKeychain deletes a Keychain

func FindAndRemoveGenericPassword

func FindAndRemoveGenericPassword(attributes *GenericPasswordAttributes) error

FindAndRemoveGenericPassword searches the Keychains defined in the attributes Keychain property (or the default if null) and removes the item if found.

func FindGenericPassword

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

FindGenericPassword searches the Keychains defined in the attributes Keychain property (or the default if null). It returns only the password found or an error

func GetAllAccountNames

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

GetAllAccountNames returns the account names for a given service across the provided keychains. If no keychains are provided, the default is used

func RemoveAndAddGenericPassword

func RemoveAndAddGenericPassword(attributes *GenericPasswordAttributes) error

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

Types

type GenericPasswordAttributes

type GenericPasswordAttributes struct {

	// ServiceName is the name of the service to add the item to
	ServiceName string

	// AccountName is the name of the account to add the item to
	AccountName string

	// Password is the password for the service
	Password []byte

	// TrustedApplications is a list of additional application paths
	// that will be given trusted access to the keychain item by default.
	// The application that creates the keychain item always has access, so
	// this list is for additional apps or executables.
	TrustedApplications []string

	// Keychain contains a list of keychain files to either search or add to. If this
	// is null or empty then the user's defaults will be used
	Keychain []string
}

GenericPasswordAttributes describes the attributes for a Keychain item All string fields must have size that fits in 32 bits and be UTF-8

Jump to

Keyboard shortcuts

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