Files
threshold/internal/kms/const.go
T
Jeff Mitchell 74544f6324 Encrypt tokens on the way out and decrypt on the way in (#302)
* Encrypt tokens on the way out and decrypt on the way in

This isn't a security feature related to tokens specifically; it's so
that we can discard cryptographically bad tokens before we ever hit the
DB. This way we can't pass through a DDoS to the database due to
fetching obviously invalid token values.

I'm using base58 to encode the resulting value as there aren't great
base62 options, and allowing base64 / and + values can hamper usability
by creating copying/highlighting breaks.
2020-08-25 00:20:50 -04:00

42 lines
1.0 KiB
Go

package kms
// KeyPurpose allows an application to specify the reason they need a key; this
// is used to select which DEK to return
type KeyPurpose uint
const (
// KeyPurposeUnknown is the default, and indicates that a correct purpose
// wasn't specified
KeyPurposeUnknown KeyPurpose = iota
// KeyPurposeDatabase is used for general encryption needs for most values
// in the database, excluding the oplog
KeyPurposeDatabase
// KeyPurposeOplog is used for oplogs
KeyPurposeOplog
// KeyPurposeRecovery is used for recovery access
KeyPurposeRecovery
// KeyPurposeTokens is used for token encryption
KeyPurposeTokens
)
// String returns the key purpose cast as a string, just so it can be called as
// a function instead of direct casting elsewhere, yw
func (k KeyPurpose) String() string {
switch k {
case KeyPurposeDatabase:
return "database"
case KeyPurposeOplog:
return "oplog"
case KeyPurposeRecovery:
return "recovery"
case KeyPurposeTokens:
return "tokens"
default:
return "unknown"
}
}