Replace blake2b by sha512 (as it is not yet available on alpine

This commit is contained in:
nemunaire 2018-02-21 01:51:06 +01:00 committed by Pierre-Olivier Mercier
parent 78e94d4766
commit 6df70342af
4 changed files with 7 additions and 12 deletions

View file

@ -17,7 +17,7 @@ token_generator() {
do do
echo -n :${d} echo -n :${d}
done done
} | b2sum | cut -d ' ' -f 1 } | sha512sum | cut -d ' ' -f 1
} }
# JSON token format helper # JSON token format helper

View file

@ -61,7 +61,7 @@ N2=$((25 + $RANDOM % 50))
{ {
echo -n $N1 echo -n $N1
echo -n $N2 echo -n $N2
echo ${USER_PKEY:$N1:$N2} | b2sum | cut -d " " -f 1 echo -n ${USER_PKEY:$N1:$N2} | sha512sum | cut -d " " -f 1
} > /mnt/token4 } > /mnt/token4
sync sync

View file

@ -2,6 +2,7 @@ package main
import ( import (
"crypto/hmac" "crypto/hmac"
"crypto/sha512"
"encoding/hex" "encoding/hex"
"encoding/json" "encoding/json"
"errors" "errors"
@ -13,7 +14,6 @@ import (
"time" "time"
"github.com/julienschmidt/httprouter" "github.com/julienschmidt/httprouter"
"golang.org/x/crypto/blake2b"
) )
const IPgwDMZ = "172.23.200.1" const IPgwDMZ = "172.23.200.1"
@ -129,7 +129,7 @@ func challengeDisk(s *Student, t *givenToken, chid int) error {
return err return err
} }
expectedToken := blake2b.Sum512([]byte(pkey[n1:n2])) expectedToken := sha512.Sum512([]byte(pkey[n1:n2]))
if ! hmac.Equal(expectedToken[:], sum) { if ! hmac.Equal(expectedToken[:], sum) {
return errors.New("This is not the expected token.") return errors.New("This is not the expected token.")

View file

@ -1,19 +1,14 @@
package main package main
import ( import (
"crypto/sha512"
"fmt" "fmt"
"golang.org/x/crypto/blake2b"
) )
func GenerateToken(pkey []byte, id int, a... []byte) ([]byte, error) { func GenerateToken(pkey []byte, id int, a... []byte) ([]byte, error) {
h, err := blake2b.New(blake2b.Size, nil) h := sha512.New()
if err != nil {
return nil, err
}
h.Write(pkey) h.Write([]byte(fmt.Sprintf("%x:%d", pkey, id)))
h.Write([]byte(fmt.Sprintf(":%d", id)))
for _, v := range a { for _, v := range a {
h.Write([]byte(":")) h.Write([]byte(":"))