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
echo -n :${d}
done
} | b2sum | cut -d ' ' -f 1
} | sha512sum | cut -d ' ' -f 1
}
# JSON token format helper

View File

@ -61,7 +61,7 @@ N2=$((25 + $RANDOM % 50))
{
echo -n $N1
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
sync

View File

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

View File

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