Documentation
¶
Overview ¶
Package isokey allows you to make and verify API keys without a database connection via HMAC signatures. The keys are scalable and persistent. All information is stored in the key, and with the client.
Package isokey allows you to make and verify API keys without a database connection via HMAC signatures. The keys are scalable and persistent. All information is stored in the key, and with the client.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrNoSecret = errors.New("No secret was found for the secret version.") ErrSymKeySize = fmt.Errorf("Key is not %v bytes long.", symKeyDigestSize) ErrBadSecret = errors.New("Secret is incorrect") ErrInvalid = errors.New("Key is expired or invalid.") )
Common errors
var ( ErrNoAsymKey = errors.New("No asym key was found for that SecretVersion") ErrNotECPublicKey = errors.New("Not elliptic curve public key") ErrAsymMessageSize = errors.New("Message portion not 20 bytes") ErrBadSignature = errors.New("Bad signature or message.") )
Asymmetric key errors
Functions ¶
func LoadPrivateKey ¶
func LoadPrivateKey(filename string) (privKey *ecdsa.PrivateKey, err error)
LoadPrivateKey loads an ASN.1 ECDSA private key from a file.
Types ¶
type AsymKeySigner ¶
type AsymKeySigner struct {
//PrivateKey is used if GetPrivateKey and KeyMap is nil
PrivateKey *ecdsa.PrivateKey
//PrivateKeyMap maps secret versions to secrets
PrivateKeyMap map[uint32]*ecdsa.PrivateKey
//GetPrivateKey allows you to dynamically use secrets.
//Returning nil indicates that no secret was found for the version
GetPrivateKey func(key *Key) *ecdsa.PrivateKey
}
AsymKeySigner facilitates the creation ECDSA API keys
func (*AsymKeySigner) Digest ¶
func (ks *AsymKeySigner) Digest(key *Key) (digest string, err error)
Digest signs the API key and digests it into it's base58 form. An error will only be returned if the corresponding key cannot be found from SecretVersion. if key.Made is zero it is set to the current time.
type AsymKeyVerifier ¶
type AsymKeyVerifier struct {
//PublicKey is used if GetPublicKey and KeyMap is nil
PublicKey *ecdsa.PublicKey
//PublicKeyMap maps secret versions to secrets
PublicKeyMap map[uint32]*ecdsa.PublicKey
//GetPublicKey allows you to dynamically use secrets.
//Returning nil indicates that no secret was found for the version
GetPublicKey func(key *Key) *ecdsa.PublicKey
//CustomInvalidate allows you to invalidate certain keys based off the Key's parameters (e.g when it was made.)
//CustomInvalidate is ran after the key's signature has been validated.
//This is useful to deal with cases revolving compromised users.
CustomInvalidate func(*Key) bool
}
AsymKeyVerifier verifies ECDSA signed API keys
func (*AsymKeyVerifier) Invalidate ¶
func (kv *AsymKeyVerifier) Invalidate(key *Key) bool
Invalidate invalidates a key
type Key ¶
type Key struct {
Made time.Time
Expires time.Time
SecretVersion uint32
UserID uint32
Flags uint32
}
Key is a self-contained algorithm agnostic API key
type SymKeyService ¶
type SymKeyService struct {
//Secret is used if GetSecret and SecretMap is nil
Secret []byte
//SecretMap maps secret versions to secrets
SecretMap map[uint32][]byte
//GetSecret allows you to dynamically use secrets.
//Returning nil indicates that no secret was found for the version
GetSecret func(key *Key) (secret []byte)
//CustomInvalidate allows you to invalidate certain keys based off the Key's parameters (e.g when it was made.)
//CustomInvalidate is ran after the key's signature has been validated.
//This is useful to deal with cases revolving compromised users.
CustomInvalidate func(*Key) bool
}
SymKeyService facilitates the creation and verification of symmetricly signed (HMAC) keys
func (*SymKeyService) Digest ¶
func (ks *SymKeyService) Digest(key *Key) (digest string, err error)
Digest converts the key into it's base58 form. An error will only be returned if the secret cannot be found from SecretVersion. if key.Made is zero it is set to the current time.
func (*SymKeyService) Invalidate ¶
func (ks *SymKeyService) Invalidate(key *Key) bool
Invalidate invalidates a key