You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

federation.go 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // Copyright 2021 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package setting
  4. import (
  5. "code.gitea.io/gitea/modules/log"
  6. "github.com/go-fed/httpsig"
  7. )
  8. // Federation settings
  9. var (
  10. Federation = struct {
  11. Enabled bool
  12. ShareUserStatistics bool
  13. MaxSize int64
  14. Algorithms []string
  15. DigestAlgorithm string
  16. GetHeaders []string
  17. PostHeaders []string
  18. }{
  19. Enabled: false,
  20. ShareUserStatistics: true,
  21. MaxSize: 4,
  22. Algorithms: []string{"rsa-sha256", "rsa-sha512", "ed25519"},
  23. DigestAlgorithm: "SHA-256",
  24. GetHeaders: []string{"(request-target)", "Date"},
  25. PostHeaders: []string{"(request-target)", "Date", "Digest"},
  26. }
  27. )
  28. // HttpsigAlgs is a constant slice of httpsig algorithm objects
  29. var HttpsigAlgs []httpsig.Algorithm
  30. func loadFederationFrom(rootCfg ConfigProvider) {
  31. if err := rootCfg.Section("federation").MapTo(&Federation); err != nil {
  32. log.Fatal("Failed to map Federation settings: %v", err)
  33. } else if !httpsig.IsSupportedDigestAlgorithm(Federation.DigestAlgorithm) {
  34. log.Fatal("unsupported digest algorithm: %s", Federation.DigestAlgorithm)
  35. return
  36. }
  37. // Get MaxSize in bytes instead of MiB
  38. Federation.MaxSize = 1 << 20 * Federation.MaxSize
  39. HttpsigAlgs = make([]httpsig.Algorithm, len(Federation.Algorithms))
  40. for i, alg := range Federation.Algorithms {
  41. HttpsigAlgs[i] = httpsig.Algorithm(alg)
  42. }
  43. }