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.

signing.go 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // Copyright 2020 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package misc
  5. import (
  6. "fmt"
  7. "net/http"
  8. "code.gitea.io/gitea/modules/context"
  9. asymkey_service "code.gitea.io/gitea/services/asymkey"
  10. )
  11. // SigningKey returns the public key of the default signing key if it exists
  12. func SigningKey(ctx *context.APIContext) {
  13. // swagger:operation GET /signing-key.gpg miscellaneous getSigningKey
  14. // ---
  15. // summary: Get default signing-key.gpg
  16. // produces:
  17. // - text/plain
  18. // responses:
  19. // "200":
  20. // description: "GPG armored public key"
  21. // schema:
  22. // type: string
  23. // swagger:operation GET /repos/{owner}/{repo}/signing-key.gpg repository repoSigningKey
  24. // ---
  25. // summary: Get signing-key.gpg for given repository
  26. // produces:
  27. // - text/plain
  28. // parameters:
  29. // - name: owner
  30. // in: path
  31. // description: owner of the repo
  32. // type: string
  33. // required: true
  34. // - name: repo
  35. // in: path
  36. // description: name of the repo
  37. // type: string
  38. // required: true
  39. // responses:
  40. // "200":
  41. // description: "GPG armored public key"
  42. // schema:
  43. // type: string
  44. path := ""
  45. if ctx.Repo != nil && ctx.Repo.Repository != nil {
  46. path = ctx.Repo.Repository.RepoPath()
  47. }
  48. content, err := asymkey_service.PublicSigningKey(path)
  49. if err != nil {
  50. ctx.Error(http.StatusInternalServerError, "gpg export", err)
  51. return
  52. }
  53. _, err = ctx.Write([]byte(content))
  54. if err != nil {
  55. ctx.Error(http.StatusInternalServerError, "gpg export", fmt.Errorf("Error writing key content %v", err))
  56. }
  57. }