|
@@ -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
|
|
|
-}
|