diff --git a/server/ente/enc_data.go b/server/ente/enc_data.go new file mode 100644 index 000000000..db54deeb2 --- /dev/null +++ b/server/ente/enc_data.go @@ -0,0 +1,28 @@ +package ente + +import ( + "database/sql/driver" + "encoding/json" + "fmt" +) + +// EncData is a struct that holds an encrypted data and related nonce. +type EncData struct { + Data string `json:"data"` + Nonce string `json:"nonce"` +} + +// Value implements the driver.Valuer interface, allowing EncString to be used as a SQL value. +func (e EncData) Value() (driver.Value, error) { + return json.Marshal(e) +} + +// Scan implements the sql.Scanner interface, allowing EncString to be scanned from SQL queries. +func (e *EncData) Scan(value interface{}) error { + // Convert to bytes if necessary (depends on the driver, pq returns []byte for JSONB) + b, ok := value.([]byte) + if !ok { + return fmt.Errorf("type assertion to []byte failed") + } + return json.Unmarshal(b, &e) +} diff --git a/server/ente/passkey.go b/server/ente/passkey.go index 0ed41965c..a975b5221 100644 --- a/server/ente/passkey.go +++ b/server/ente/passkey.go @@ -12,3 +12,26 @@ type Passkey struct { } var MaxPasskeys = 10 + +type EnablePassKeyRecovery struct { + UserID int64 `json:"userID" binding:"required"` + ResetKey string `json:"resetKey" binding:"required"` + EncResetKey EncData `json:"encResetKey" binding:"required"` +} + +type AccountRecoveryStatus struct { + // AllowAdminReset is a boolean that determines if the admin can reset the user's MFA. + // If true, in the event that the user loses their MFA device, the admin can reset the user's MFA. + AllowAdminReset bool `json:"allowAdminReset" binding:"required"` + IsPassKeyResetEnabled bool `json:"isPassKeyResetEnabled" binding:"required"` +} + +type PasseKeyResetChallengeResponse struct { + EncResetKey string `json:"encResetKey" binding:"required"` + EncResetKeyNonce string `json:"encResetKeyNonce" binding:"required"` +} + +type ResetPassKey struct { + SessionID string `json:"sessionID" binding:"required"` + RestKey string `json:"resetKey" binding:"required"` +}