feat: External Migration

This commit is contained in:
Roi Feng
2025-06-18 18:20:07 -04:00
parent ae94e5a7ce
commit f32fb3836b
3 changed files with 53 additions and 2 deletions

View File

@ -71,7 +71,7 @@ func genExternalMigrationSessionID(reqData dataType.UserRequest, ruleSet config.
return []byte(fmt.Sprintf("%s:%s", fmt.Sprintf("%d", time.Now().Unix()), fmt.Sprintf("%x", mac.Sum(nil))))
}
func verifyExternalMigrationSessionIDCookie(reqData dataType.UserRequest, ruleSet config.RuleSet) bool {
func VerifyExternalMigrationSessionIDCookie(reqData dataType.UserRequest, ruleSet config.RuleSet) bool {
if reqData.ToriiSessionID == "" {
return false
}
@ -95,3 +95,9 @@ func verifyExternalMigrationSessionIDCookie(reqData dataType.UserRequest, ruleSe
return hmac.Equal([]byte(computedHash), []byte(expectedHash))
}
func CalculateExternalMigrationHMAC(sessionID, timestampStr, secretKey string) string {
mac := hmac.New(sha512.New, []byte(secretKey))
mac.Write([]byte(fmt.Sprintf("%s%s", sessionID, timestampStr)))
return fmt.Sprintf("%x", mac.Sum(nil))
}