crypto.go 678 B

123456789101112131415161718192021222324252627282930313233
  1. package crypto
  2. import (
  3. "net/http"
  4. "github.com/0xJacky/Nginx-UI/internal/crypto"
  5. "github.com/gin-gonic/gin"
  6. "github.com/google/uuid"
  7. "github.com/uozi-tech/cosy"
  8. )
  9. // GetPublicKey generates a new ED25519 key pair and registers it in the cache
  10. func GetPublicKey(c *gin.Context) {
  11. var data struct {
  12. Timestamp int64 `json:"timestamp" binding:"required"`
  13. Fingerprint string `json:"fingerprint" binding:"required"`
  14. }
  15. if !cosy.BindAndValid(c, &data) {
  16. return
  17. }
  18. params, err := crypto.GetCryptoParams()
  19. if err != nil {
  20. cosy.ErrHandler(c, err)
  21. return
  22. }
  23. c.JSON(http.StatusOK, gin.H{
  24. "public_key": params.PublicKey,
  25. "request_id": uuid.NewString(),
  26. })
  27. }