2020-08-19 16:47:18 -04:00
|
|
|
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
|
2020-08-20 13:34:03 -04:00
|
|
|
KeyPurposeUnknown KeyPurpose = iota
|
2020-08-19 16:47:18 -04:00
|
|
|
|
|
|
|
|
// KeyPurposeDatabase is used for general encryption needs for most values
|
|
|
|
|
// in the database, excluding the oplog
|
2020-08-20 13:34:03 -04:00
|
|
|
KeyPurposeDatabase
|
2020-08-19 16:47:18 -04:00
|
|
|
|
|
|
|
|
// KeyPurposeOplog is used for oplogs
|
2020-08-20 13:34:03 -04:00
|
|
|
KeyPurposeOplog
|
|
|
|
|
|
|
|
|
|
// KeyPurposeRecovery is used for recovery access
|
|
|
|
|
KeyPurposeRecovery
|
2020-08-25 00:20:50 -04:00
|
|
|
|
|
|
|
|
// KeyPurposeTokens is used for token encryption
|
|
|
|
|
KeyPurposeTokens
|
2020-09-02 14:37:19 -04:00
|
|
|
|
2020-09-03 13:24:34 -04:00
|
|
|
// KeyPurposeSessions is used as a base key to derive session-specific encryption keys
|
2020-09-02 14:37:19 -04:00
|
|
|
KeyPurposeSessions
|
2021-01-26 14:37:10 -05:00
|
|
|
|
|
|
|
|
// KeyPurposeOidc is used for encrypting oidc states included in
|
|
|
|
|
// authentication URLs
|
|
|
|
|
KeyPurposeOidc
|
2021-11-04 09:34:01 -04:00
|
|
|
|
|
|
|
|
// KeyPurposeAudit is used for audit operations
|
|
|
|
|
KeyPurposeAudit
|
2020-08-19 16:47:18 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// 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"
|
2020-08-20 13:34:03 -04:00
|
|
|
case KeyPurposeRecovery:
|
|
|
|
|
return "recovery"
|
2020-08-25 00:20:50 -04:00
|
|
|
case KeyPurposeTokens:
|
|
|
|
|
return "tokens"
|
2020-09-02 14:37:19 -04:00
|
|
|
case KeyPurposeSessions:
|
|
|
|
|
return "sessions"
|
2021-01-26 14:37:10 -05:00
|
|
|
case KeyPurposeOidc:
|
|
|
|
|
return "oidc"
|
2021-11-04 09:34:01 -04:00
|
|
|
case KeyPurposeAudit:
|
|
|
|
|
return "audit"
|
2020-09-02 14:37:19 -04:00
|
|
|
default:
|
|
|
|
|
return "unknown"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// KeyType allows the kms repo to return a map[KeyType]Key which can be easily
|
|
|
|
|
// used without type casting.
|
|
|
|
|
type KeyType uint
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
|
KeyTypeUnknown KeyType = iota
|
|
|
|
|
KeyTypeRootKey
|
|
|
|
|
KeyTypeRootKeyVersion
|
|
|
|
|
KeyTypeDatabaseKey
|
|
|
|
|
KeyTypeDatabaseKeyVersion
|
|
|
|
|
KeyTypeOplogKey
|
|
|
|
|
KeyTypeOplogKeyVersion
|
|
|
|
|
KeyTypeTokenKey
|
|
|
|
|
KeyTypeTokenKeyVersion
|
|
|
|
|
KeyTypeSessionKey
|
|
|
|
|
KeyTypeSessionKeyVersion
|
2021-01-26 14:37:10 -05:00
|
|
|
KeyTypeOidcKey
|
|
|
|
|
KeyTypeOidcKeyVersion
|
2021-11-04 09:34:01 -04:00
|
|
|
KeyTypeAuditKey
|
|
|
|
|
KeyTypeAuditKeyVersion
|
2020-09-02 14:37:19 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// String returns the key type cast as a string, just so it can be called as
|
|
|
|
|
// a function instead of direct casting elsewhere, yw
|
|
|
|
|
func (k KeyType) String() string {
|
|
|
|
|
switch k {
|
|
|
|
|
case KeyTypeRootKey:
|
|
|
|
|
return "rootKey"
|
|
|
|
|
case KeyTypeRootKeyVersion:
|
|
|
|
|
return "rootKeyVersion"
|
|
|
|
|
case KeyTypeDatabaseKey:
|
|
|
|
|
return "databaseKey"
|
|
|
|
|
case KeyTypeDatabaseKeyVersion:
|
|
|
|
|
return "databaseKeyVersion"
|
|
|
|
|
case KeyTypeOplogKey:
|
|
|
|
|
return "oplogKey"
|
|
|
|
|
case KeyTypeOplogKeyVersion:
|
|
|
|
|
return "oplogKeyVersion"
|
|
|
|
|
case KeyTypeTokenKey:
|
|
|
|
|
return "tokenKey"
|
|
|
|
|
case KeyTypeTokenKeyVersion:
|
|
|
|
|
return "tokenKeyVersion"
|
|
|
|
|
case KeyTypeSessionKey:
|
|
|
|
|
return "sessionKey"
|
|
|
|
|
case KeyTypeSessionKeyVersion:
|
|
|
|
|
return "sessionKeyVersion"
|
2021-01-26 14:37:10 -05:00
|
|
|
case KeyTypeOidcKey:
|
|
|
|
|
return "oidcKey"
|
|
|
|
|
case KeyTypeOidcKeyVersion:
|
|
|
|
|
return "oidcKeyVersion"
|
2021-11-04 09:34:01 -04:00
|
|
|
case KeyTypeAuditKey:
|
|
|
|
|
return "auditKey"
|
|
|
|
|
case KeyTypeAuditKeyVersion:
|
|
|
|
|
return "auditKeyVersion"
|
2020-09-02 14:37:19 -04:00
|
|
|
|
2020-08-19 16:47:18 -04:00
|
|
|
default:
|
|
|
|
|
return "unknown"
|
|
|
|
|
}
|
|
|
|
|
}
|