package keychain
import "github.com/keybase/go-keychain"
Index ¶
- Constants
- Variables
- func AddItem(item Item) error
- func ArrayToCFArray(a []C.CFTypeRef) C.CFArrayRef
- func BytesToCFData(b []byte) (C.CFDataRef, error)
- func CFArrayToArray(cfArray C.CFArrayRef) (a []C.CFTypeRef)
- func CFDataToBytes(cfData C.CFDataRef) ([]byte, error)
- func CFDateToTime(d C.CFDateRef) time.Time
- func CFDictionaryToMap(cfDict C.CFDictionaryRef) (m map[C.CFTypeRef]C.CFTypeRef)
- func CFNumberToInterface(cfNumber C.CFNumberRef) interface{}
- func CFStringToString(s C.CFStringRef) string
- func CFTypeDescription(ref C.CFTypeRef) string
- func Convert(ref C.CFTypeRef) (interface{}, error)
- func ConvertCFDictionary(d C.CFDictionaryRef) (map[interface{}]interface{}, error)
- func ConvertMapToCFDictionary(attr map[string]interface{}) (C.CFDictionaryRef, error)
- func DeleteGenericPasswordItem(service string, account string) error
- func DeleteItem(item Item) error
- func GetAccountsForService(service string) ([]string, error)
- func GetGenericPassword(service string, account string, label string, accessGroup string) ([]byte, error)
- func GetGenericPasswordAccounts(service string) ([]string, error)
- func Int32ToCFNumber(u int32) C.CFNumberRef
- func MapToCFDictionary(m map[C.CFTypeRef]C.CFTypeRef) (C.CFDictionaryRef, error)
- func QueryItemRef(item Item) (C.CFTypeRef, error)
- func RandBytes(length int) ([]byte, error)
- func RandomID(prefix string) (string, error)
- func Release(ref C.CFTypeRef)
- func StringToCFString(s string) (C.CFStringRef, error)
- func TimeToCFDate(t time.Time) C.CFDateRef
- func UpdateItem(queryItem Item, updateItem Item) error
- type Accessible
- type Convertable
- type Error
- type Item
- func NewGenericPassword(service string, account string, label string, data []byte, accessGroup string) Item
- func NewItem() Item
- func (k *Item) SetAccessGroup(ag string)
- func (k *Item) SetAccessible(accessible Accessible)
- func (k *Item) SetAccount(a string)
- func (k *Item) SetAuthenticationType(s string)
- func (k *Item) SetComment(s string)
- func (k *Item) SetData(b []byte)
- func (k *Item) SetDescription(s string)
- func (k *Item) SetInt32(key string, v int32)
- func (k *Item) SetLabel(l string)
- func (k *Item) SetMatchLimit(matchLimit MatchLimit)
- func (k *Item) SetPath(s string)
- func (k *Item) SetPort(v int32)
- func (k *Item) SetProtocol(s string)
- func (k *Item) SetReturnAttributes(b bool)
- func (k *Item) SetReturnData(b bool)
- func (k *Item) SetReturnRef(b bool)
- func (k *Item) SetSecClass(sc SecClass)
- func (k *Item) SetServer(s string)
- func (k *Item) SetService(s string)
- func (k *Item) SetString(key string, s string)
- func (k *Item) SetSynchronizable(sync Synchronizable)
- type MatchLimit
- type QueryResult
- type SecClass
- type Synchronizable
Constants ¶
const ( // SynchronizableDefault is the default setting SynchronizableDefault Synchronizable = 0 // SynchronizableAny is for kSecAttrSynchronizableAny SynchronizableAny = 1 // SynchronizableYes enables synchronization SynchronizableYes = 2 // SynchronizableNo disables synchronization SynchronizableNo = 3 )
const ( // AccessibleDefault is the default AccessibleDefault Accessible = 0 // AccessibleWhenUnlocked is when unlocked AccessibleWhenUnlocked = 1 // AccessibleAfterFirstUnlock is after first unlock AccessibleAfterFirstUnlock = 2 // AccessibleAlways is always AccessibleAlways = 3 // AccessibleWhenPasscodeSetThisDeviceOnly is when passcode is set AccessibleWhenPasscodeSetThisDeviceOnly = 4 // AccessibleWhenUnlockedThisDeviceOnly is when unlocked for this device only AccessibleWhenUnlockedThisDeviceOnly = 5 // AccessibleAfterFirstUnlockThisDeviceOnly is after first unlock for this device only AccessibleAfterFirstUnlockThisDeviceOnly = 6 // AccessibleAccessibleAlwaysThisDeviceOnly is always for this device only AccessibleAccessibleAlwaysThisDeviceOnly = 7 )
const ( // MatchLimitDefault is the default MatchLimitDefault MatchLimit = 0 // MatchLimitOne limits to one result MatchLimitOne = 1 // MatchLimitAll is no limit MatchLimitAll = 2 )
Variables ¶
var ( // ErrorUnimplemented corresponds to errSecUnimplemented result code ErrorUnimplemented = Error(C.errSecUnimplemented) // ErrorParam corresponds to errSecParam result code ErrorParam = Error(C.errSecParam) // ErrorAllocate corresponds to errSecAllocate result code ErrorAllocate = Error(C.errSecAllocate) // ErrorNotAvailable corresponds to errSecNotAvailable result code ErrorNotAvailable = Error(C.errSecNotAvailable) // ErrorAuthFailed corresponds to errSecAuthFailed result code ErrorAuthFailed = Error(C.errSecAuthFailed) // ErrorDuplicateItem corresponds to errSecDuplicateItem result code ErrorDuplicateItem = Error(C.errSecDuplicateItem) // ErrorItemNotFound corresponds to errSecItemNotFound result code ErrorItemNotFound = Error(C.errSecItemNotFound) // ErrorInteractionNotAllowed corresponds to errSecInteractionNotAllowed result code ErrorInteractionNotAllowed = Error(C.errSecInteractionNotAllowed) // ErrorDecode corresponds to errSecDecode result code ErrorDecode = Error(C.errSecDecode) // ErrorNoSuchKeychain corresponds to errSecNoSuchKeychain result code ErrorNoSuchKeychain = Error(C.errSecNoSuchKeychain) // ErrorNoAccessForItem corresponds to errSecNoAccessForItem result code ErrorNoAccessForItem = Error(C.errSecNoAccessForItem) // ErrorReadOnly corresponds to errSecReadOnly result code ErrorReadOnly = Error(C.errSecReadOnly) // ErrorInvalidKeychain corresponds to errSecInvalidKeychain result code ErrorInvalidKeychain = Error(C.errSecInvalidKeychain) // ErrorDuplicateKeyChain corresponds to errSecDuplicateKeychain result code ErrorDuplicateKeyChain = Error(C.errSecDuplicateKeychain) // ErrorWrongVersion corresponds to errSecWrongSecVersion result code ErrorWrongVersion = Error(C.errSecWrongSecVersion) // ErrorReadonlyAttribute corresponds to errSecReadOnlyAttr result code ErrorReadonlyAttribute = Error(C.errSecReadOnlyAttr) // ErrorInvalidSearchRef corresponds to errSecInvalidSearchRef result code ErrorInvalidSearchRef = Error(C.errSecInvalidSearchRef) // ErrorInvalidItemRef corresponds to errSecInvalidItemRef result code ErrorInvalidItemRef = Error(C.errSecInvalidItemRef) // ErrorDataNotAvailable corresponds to errSecDataNotAvailable result code ErrorDataNotAvailable = Error(C.errSecDataNotAvailable) // ErrorDataNotModifiable corresponds to errSecDataNotModifiable result code ErrorDataNotModifiable = Error(C.errSecDataNotModifiable) // ErrorInvalidOwnerEdit corresponds to errSecInvalidOwnerEdit result code ErrorInvalidOwnerEdit = Error(C.errSecInvalidOwnerEdit) // ErrorUserCanceled corresponds to errSecUserCanceled result code ErrorUserCanceled = Error(C.errSecUserCanceled) )
var ( // ServiceKey is for kSecAttrService ServiceKey = attrKey(C.CFTypeRef(C.kSecAttrService)) // ServerKey is for kSecAttrServer ServerKey = attrKey(C.CFTypeRef(C.kSecAttrServer)) // ProtocolKey is for kSecAttrProtocol ProtocolKey = attrKey(C.CFTypeRef(C.kSecAttrProtocol)) // AuthenticationTypeKey is for kSecAttrAuthenticationType AuthenticationTypeKey = attrKey(C.CFTypeRef(C.kSecAttrAuthenticationType)) // PortKey is for kSecAttrPort PortKey = attrKey(C.CFTypeRef(C.kSecAttrPort)) // PathKey is for kSecAttrPath PathKey = attrKey(C.CFTypeRef(C.kSecAttrPath)) // LabelKey is for kSecAttrLabel LabelKey = attrKey(C.CFTypeRef(C.kSecAttrLabel)) // AccountKey is for kSecAttrAccount AccountKey = attrKey(C.CFTypeRef(C.kSecAttrAccount)) // AccessGroupKey is for kSecAttrAccessGroup AccessGroupKey = attrKey(C.CFTypeRef(C.kSecAttrAccessGroup)) // DataKey is for kSecValueData DataKey = attrKey(C.CFTypeRef(C.kSecValueData)) // DescriptionKey is for kSecAttrDescription DescriptionKey = attrKey(C.CFTypeRef(C.kSecAttrDescription)) // CommentKey is for kSecAttrComment CommentKey = attrKey(C.CFTypeRef(C.kSecAttrComment)) // CreationDateKey is for kSecAttrCreationDate CreationDateKey = attrKey(C.CFTypeRef(C.kSecAttrCreationDate)) // ModificationDateKey is for kSecAttrModificationDate ModificationDateKey = attrKey(C.CFTypeRef(C.kSecAttrModificationDate)) )
AccessibleKey is key for kSecAttrAccessible
MatchLimitKey is key type for MatchLimit
ReturnAttributesKey is key type for kSecReturnAttributes
ReturnDataKey is key type for kSecReturnData
ReturnRefKey is key type for kSecReturnRef
SecClassKey is the key type for SecClass
SynchronizableKey is the key type for Synchronizable
Functions ¶
func AddItem ¶
AddItem adds a Item to a Keychain
func ArrayToCFArray ¶
ArrayToCFArray will return a CFArrayRef and if non-nil, must be released with Release(ref).
func BytesToCFData ¶
BytesToCFData will return a CFDataRef and if non-nil, must be released with Release(ref).
func CFArrayToArray ¶
CFArrayToArray converts a CFArrayRef to an array of CFTypes.
func CFDataToBytes ¶
CFDataToBytes converts CFData to bytes.
func CFDateToTime ¶
CFDateToTime will convert the given CFDateRef to a time.Time.
func CFDictionaryToMap ¶
CFDictionaryToMap converts CFDictionaryRef to a map.
func CFNumberToInterface ¶
func CFNumberToInterface(cfNumber C.CFNumberRef) interface{}
CFNumberToInterface converts the CFNumberRef to the most appropriate numeric type. This code is from github.com/kballard/go-osx-plist.
func CFStringToString ¶
CFStringToString converts a CFStringRef to a string.
func CFTypeDescription ¶
CFTypeDescription returns type string for CFTypeRef.
func Convert ¶
Convert converts a CFTypeRef to a go instance.
func ConvertCFDictionary ¶
ConvertCFDictionary converts a CFDictionary to map (deep).
func ConvertMapToCFDictionary ¶
ConvertMapToCFDictionary converts a map to a CFDictionary and if non-nil, must be released with Release(ref).
func DeleteGenericPasswordItem ¶
DeleteGenericPasswordItem removes a generic password item.
func DeleteItem ¶
DeleteItem removes a Item
func GetAccountsForService ¶
GetAccountsForService is deprecated
func GetGenericPassword ¶
func GetGenericPassword(service string, account string, label string, accessGroup string) ([]byte, error)
GetGenericPassword returns password data for service and account. This is a convenience method. If item is not found returns nil, nil.
func GetGenericPasswordAccounts ¶
GetGenericPasswordAccounts returns generic password accounts for service. This is a convenience method.
func Int32ToCFNumber ¶
Int32ToCFNumber will return a CFNumberRef, must be released with Release(ref).
func MapToCFDictionary ¶
MapToCFDictionary will return a CFDictionaryRef and if non-nil, must be released with Release(ref).
func QueryItemRef ¶
QueryItemRef returns query result as CFTypeRef. You must release it when you are done.
func RandBytes ¶
RandBytes returns random bytes of length
func RandomID ¶
RandomID returns random ID (base32) string with prefix, using 256 bits as recommended by tptacek: https://gist.github.com/tqbf/be58d2d39690c3b366ad
func Release ¶
func Release(ref C.CFTypeRef)
Release releases memory pointed to by a CFTypeRef.
func StringToCFString ¶
StringToCFString will return a CFStringRef and if non-nil, must be released with Release(ref).
func TimeToCFDate ¶
TimeToCFDate will convert the given time.Time to a CFDateRef, which must be released with Release(ref).
func UpdateItem ¶
UpdateItem updates the queryItem with the parameters from updateItem
Types ¶
type Accessible ¶
type Accessible int
Accessible is the items accessibility
type Convertable ¶
Convertable knows how to convert an instance to a CFTypeRef.
type Error ¶
type Error int
Error defines keychain errors
func (Error) Error ¶
type Item ¶
type Item struct {
// contains filtered or unexported fields
}
Item for adding, querying or deleting.
func NewGenericPassword ¶
func NewGenericPassword(service string, account string, label string, data []byte, accessGroup string) Item
NewGenericPassword creates a generic password item with the default keychain. This is a convenience method.
func NewItem ¶
func NewItem() Item
NewItem is a new empty keychain item
func (*Item) SetAccessGroup ¶
SetAccessGroup sets the access group attribute
func (*Item) SetAccessible ¶
func (k *Item) SetAccessible(accessible Accessible)
SetAccessible sets the accessible attribute
func (*Item) SetAccount ¶
SetAccount sets the account attribute
func (*Item) SetAuthenticationType ¶
SetAuthenticationType sets the authentication type attribute (for internet password items)
func (*Item) SetComment ¶
SetComment sets the comment attribute
func (*Item) SetData ¶
SetData sets the data attribute
func (*Item) SetDescription ¶
SetDescription sets the description attribute
func (*Item) SetInt32 ¶
SetInt32 sets an int32 attribute for a string key
func (*Item) SetLabel ¶
SetLabel sets the label attribute
func (*Item) SetMatchLimit ¶
func (k *Item) SetMatchLimit(matchLimit MatchLimit)
SetMatchLimit sets the match limit
func (*Item) SetPath ¶
SetPath sets the path attribute (for internet password items)
func (*Item) SetPort ¶
SetPort sets the port attribute (for internet password items)
func (*Item) SetProtocol ¶
SetProtocol sets the protocol attribute (for internet password items) Example values are: "htps", "http", "smb "
func (*Item) SetReturnAttributes ¶
SetReturnAttributes sets the return value type on query
func (*Item) SetReturnData ¶
SetReturnData enables returning data on query
func (*Item) SetReturnRef ¶
SetReturnRef enables returning references on query
func (*Item) SetSecClass ¶
SetSecClass sets the security class
func (*Item) SetServer ¶
SetServer sets the server attribute (for internet password items)
func (*Item) SetService ¶
SetService sets the service attribute (for generic application items)
func (*Item) SetString ¶
SetString sets a string attibute for a string key
func (*Item) SetSynchronizable ¶
func (k *Item) SetSynchronizable(sync Synchronizable)
SetSynchronizable sets the synchronizable attribute
type MatchLimit ¶
type MatchLimit int
MatchLimit is whether to limit results on query
type QueryResult ¶
type QueryResult struct { // For generic application items Service string // For internet password items Server string Protocol string AuthenticationType string Port int32 Path string Account string AccessGroup string Label string Description string Comment string Data []byte CreationDate time.Time ModificationDate time.Time }
QueryResult stores all possible results from queries. Not all fields are applicable all the time. Results depend on query.
func QueryItem ¶
func QueryItem(item Item) ([]QueryResult, error)
QueryItem returns a list of query results.
type SecClass ¶
type SecClass int
SecClass is the items class code
var ( /* kSecClassGenericPassword item attributes: kSecAttrAccess (OS X only) kSecAttrAccessGroup (iOS; also OS X if kSecAttrSynchronizable specified) kSecAttrAccessible (iOS; also OS X if kSecAttrSynchronizable specified) kSecAttrAccount kSecAttrService */ SecClassGenericPassword SecClass = 1 SecClassInternetPassword SecClass = 2 )
Keychain Item Classes
type Synchronizable ¶
type Synchronizable int
Synchronizable is the items synchronizable status
Source Files ¶
corefoundation.go datetime.go keychain.go macos.go util.go
Directories ¶
Path | Synopsis |
---|---|
bind | |
bindtest | |
secretservice |
- Version
- v0.0.1 (latest)
- Published
- Feb 27, 2025
- Platform
- darwin/amd64
- Imports
- 11 packages
- Last checked
- now –
Tools for package owners.