Expose token.T in json + fix issue with new auth protocol
This commit is contained in:
parent
4e4e3b4422
commit
139a35c219
|
@ -3,6 +3,7 @@ package privacypass
|
||||||
import (
|
import (
|
||||||
"crypto/hmac"
|
"crypto/hmac"
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"git.openprivacy.ca/cwtch.im/tapir/primitives/core"
|
"git.openprivacy.ca/cwtch.im/tapir/primitives/core"
|
||||||
"git.openprivacy.ca/openprivacy/log"
|
"git.openprivacy.ca/openprivacy/log"
|
||||||
|
@ -122,3 +123,16 @@ func UnblindSignedTokenBatch(tokens []*Token, blindedTokens []BlindedToken, sign
|
||||||
}
|
}
|
||||||
return true
|
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,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
|
@ -16,16 +16,16 @@ func EDH(privateKey ed25519.PrivateKey, remotePublicKey ed25519.PublicKey) ([]by
|
||||||
var curve25519priv [32]byte
|
var curve25519priv [32]byte
|
||||||
|
|
||||||
PrivateKeyToCurve25519(&curve25519priv, &privKeyBytes)
|
PrivateKeyToCurve25519(&curve25519priv, &privKeyBytes)
|
||||||
curve25519pub, err := ed25519PublicKeyToCurve25519(remotePublicKey)
|
remoteCurve25519pub, err := ed25519PublicKeyToCurve25519New(remotePublicKey)
|
||||||
if err == nil {
|
if err != nil {
|
||||||
return nil, err
|
return []byte{}, err
|
||||||
}
|
}
|
||||||
secret, err := curve25519.X25519(curve25519priv[:], curve25519pub[:])
|
secret, err := curve25519.X25519(curve25519priv[:], remoteCurve25519pub[:])
|
||||||
return secret, err
|
return secret, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// reproduced from https://github.com/FiloSottile/age/blob/main/agessh/agessh.go#L190
|
// 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
|
// See https://blog.filippo.io/using-ed25519-keys-for-encryption and
|
||||||
// https://pkg.go.dev/filippo.io/edwards25519#Point.BytesMontgomery.
|
// https://pkg.go.dev/filippo.io/edwards25519#Point.BytesMontgomery.
|
||||||
p, err := new(edwards25519.Point).SetBytes(pk)
|
p, err := new(edwards25519.Point).SetBytes(pk)
|
||||||
|
|
Loading…
Reference in New Issue