Переглянути джерело

Use libgin encrypt method for DOI request verification

Achilleas Koutsou 6 роки тому
батько
коміт
4f1a668604
3 змінених файлів з 9 додано та 41 видалено
  1. 3 33
      routes/doi.go
  2. 3 5
      vendor/github.com/G-Node/libgin/libgin/dex.go
  3. 3 3
      vendor/vendor.json

+ 3 - 33
routes/doi.go

@@ -1,19 +1,16 @@
 package routes
 
 import (
-	"crypto/aes"
-	"crypto/cipher"
-	"crypto/rand"
-	"encoding/base64"
-	"io"
 	"net/http"
 	"net/url"
 
 	"github.com/G-Node/gogs/pkg/context"
 	"github.com/G-Node/gogs/pkg/setting"
+	"github.com/G-Node/libgin/libgin"
 	log "gopkg.in/clog.v1"
 )
 
+// RequestDOI sends a registration request to the configured DOI service
 func RequestDOI(c *context.Context) {
 	if !c.Repo.IsAdmin() {
 		c.Status(http.StatusUnauthorized)
@@ -22,8 +19,7 @@ func RequestDOI(c *context.Context) {
 
 	repo := c.Repo.Repository.FullName()
 	username := c.User.Name
-	// verification := c.GetCookie(setting.SessionConfig.CookieName)
-	verification, err := encrypt([]byte(setting.DOI.Key), repo+username)
+	verification, err := libgin.EncryptURLString([]byte(setting.DOI.Key), repo+username)
 	if err != nil {
 		log.Error(2, "Could not encrypt secret key: %s", err)
 		c.Status(http.StatusInternalServerError)
@@ -43,29 +39,3 @@ func RequestDOI(c *context.Context) {
 	log.Trace(target)
 	c.RawRedirect(target)
 }
-
-// NOTE: TEMPORARY COPY FROM gin-doi
-
-// encrypt string to base64 crypto using AES
-func encrypt(key []byte, text string) (string, error) {
-	plaintext := []byte(text)
-
-	block, err := aes.NewCipher(key)
-	if err != nil {
-		return "", err
-	}
-
-	// The IV needs to be unique, but not secure. Therefore it's common to
-	// include it at the beginning of the ciphertext.
-	ciphertext := make([]byte, aes.BlockSize+len(plaintext))
-	iv := ciphertext[:aes.BlockSize]
-	if _, err := io.ReadFull(rand.Reader, iv); err != nil {
-		return "", err
-	}
-
-	stream := cipher.NewCFBEncrypter(block, iv)
-	stream.XORKeyStream(ciphertext[aes.BlockSize:], plaintext)
-
-	// convert to base64
-	return base64.URLEncoding.EncodeToString(ciphertext), nil
-}

+ 3 - 5
vendor/github.com/G-Node/libgin/libgin/dex.go

@@ -9,11 +9,9 @@ import (
 // NOTE: TEMPORARY COPY FROM gin-dex
 
 type SearchRequest struct {
-	Token  string
-	CsrfT  string
-	UserID int64
-	Query  string
-	SType  int64
+	Keywords string
+	SType    int
+	RepoIDs  []int64
 }
 
 const (

+ 3 - 3
vendor/vendor.json

@@ -50,10 +50,10 @@
 			"revision": ""
 		},
 		{
-			"checksumSHA1": "BBQVBKXpzAPMbi0tLh4vY41r6hg=",
+			"checksumSHA1": "lvEZk52xVuofWjkVCKDjjcq0Ayw=",
 			"path": "github.com/G-Node/libgin/libgin",
-			"revision": "3786fb1dd6179032053d6aeb853f8f84d3f24f18",
-			"revisionTime": "2019-06-28T14:39:41Z"
+			"revision": "23dd4e2b41f75e2a5f99914d7e8050a09368372c",
+			"revisionTime": "2019-06-28T14:56:37Z"
 		},
 		{
 			"checksumSHA1": "s+CthU3jnDZx1F6sOfsEvRLFjBE=",