Expose token.T in json + fix issue with new auth protocol

This commit is contained in:
Sarah Jamie Lewis 2022-10-24 13:00:45 -07:00
parent 4e4e3b4422
commit 139a35c219
2 changed files with 19 additions and 5 deletions

View File

@ -3,6 +3,7 @@ package privacypass
import (
"crypto/hmac"
"crypto/rand"
"encoding/json"
"fmt"
"git.openprivacy.ca/cwtch.im/tapir/primitives/core"
"git.openprivacy.ca/openprivacy/log"
@ -122,3 +123,16 @@ func UnblindSignedTokenBatch(tokens []*Token, blindedTokens []BlindedToken, sign
}
return true
}
// MarshalJSON - in order to store tokens in a serialized form we need to expose the private, unexported value
// `t`. Note that `r` is not needed to spend the token, and as such we effectively destroy it when we serialize.
// Ideally, go would let us do this with an annotation, alas.
func (t Token) MarshalJSON() ([]byte, error) {
return json.Marshal(struct {
T []byte `json:"t"`
W *ristretto.Element
}{
T: t.t,
W: t.W,
})
}

View File

@ -16,16 +16,16 @@ func EDH(privateKey ed25519.PrivateKey, remotePublicKey ed25519.PublicKey) ([]by
var curve25519priv [32]byte
PrivateKeyToCurve25519(&curve25519priv, &privKeyBytes)
curve25519pub, err := ed25519PublicKeyToCurve25519(remotePublicKey)
if err == nil {
return nil, err
remoteCurve25519pub, err := ed25519PublicKeyToCurve25519New(remotePublicKey)
if err != nil {
return []byte{}, err
}
secret, err := curve25519.X25519(curve25519priv[:], curve25519pub[:])
secret, err := curve25519.X25519(curve25519priv[:], remoteCurve25519pub[:])
return secret, err
}
// reproduced from https://github.com/FiloSottile/age/blob/main/agessh/agessh.go#L190
func ed25519PublicKeyToCurve25519(pk ed25519.PublicKey) ([]byte, error) {
func ed25519PublicKeyToCurve25519New(pk ed25519.PublicKey) ([]byte, error) {
// See https://blog.filippo.io/using-ed25519-keys-for-encryption and
// https://pkg.go.dev/filippo.io/edwards25519#Point.BytesMontgomery.
p, err := new(edwards25519.Point).SetBytes(pk)