Commit e0406596 authored by Lukas Matt's avatar Lukas Matt Committed by GitHub

Merge pull request #14 from ganggo/fix_sig_creation

Use URLEncoding instead of StdEncoding for signature creation
parents 9abcf5ee 3368c867
......@@ -29,7 +29,7 @@ var TEST_MAGIC_PAYLOAD = []byte(`<me:env xmlns:me="http://salmon-protocol.org/ns
<me:data type="application/xml">PHg-PC94Pg==</me:data>
<me:encoding>base64url</me:encoding>
<me:alg>RSA-SHA256</me:alg>
<me:sig key_id="ZGlhc3BvcmFfMm5kQGxvY2FsaG9zdDozMDAx">PIlS0XhUHGqSsoGKP2efeitDKv7uO0ekNoDQPm5lk844muzMPk7iK9t6T3ageqIsl14xmnInDGKlbrM49JiuYB4aFKEwqHAIEj2axCjdm6HRF5mv+2nhVjKISx+AcuKY1Rav9pKQoQqphRm8p9CQr632TK5mkFfBAeGpyJE8I3WNwguy9AozR+ym0b3MrbDhHxpzGxcRAvjyzbRMfvLhOlVKauaIEGDVN6nbBXVSY4hSBYu38+02PyGuyPjjlBJHNIPQXUL9dcSq/LXs/ElwQA2JBLwF6+opQvIBDbjUVkX4spKo/uRNEAlFuR4Ul+bi/Y7+ssoD3DrMHN4Fg2hx5w==</me:sig>
<me:sig key_id="ZGlhc3BvcmFfMm5kQGxvY2FsaG9zdDozMDAx">PIlS0XhUHGqSsoGKP2efeitDKv7uO0ekNoDQPm5lk844muzMPk7iK9t6T3ageqIsl14xmnInDGKlbrM49JiuYB4aFKEwqHAIEj2axCjdm6HRF5mv-2nhVjKISx-AcuKY1Rav9pKQoQqphRm8p9CQr632TK5mkFfBAeGpyJE8I3WNwguy9AozR-ym0b3MrbDhHxpzGxcRAvjyzbRMfvLhOlVKauaIEGDVN6nbBXVSY4hSBYu38-02PyGuyPjjlBJHNIPQXUL9dcSq_LXs_ElwQA2JBLwF6-opQvIBDbjUVkX4spKo_uRNEAlFuR4Ul-bi_Y7-ssoD3DrMHN4Fg2hx5w==</me:sig>
</me:env>`)
func TestMagicEnvelope(t *testing.T) {
......
......@@ -59,14 +59,14 @@ func (signature *Signature) Sign(privKey *rsa.PrivateKey, sig *string) error {
signature.Err = err
return err
}
*sig = base64.StdEncoding.EncodeToString(bytes)
*sig = base64.URLEncoding.EncodeToString(bytes)
return nil
}
func (signature *Signature) Verify(order string, pubKey *rsa.PublicKey) bool {
sig, err := base64.StdEncoding.DecodeString(signature.entity.Signature())
sig, err := base64.URLEncoding.DecodeString(signature.entity.Signature())
if err != nil {
sig, err = base64.URLEncoding.DecodeString(signature.entity.Signature())
sig, err = base64.StdEncoding.DecodeString(signature.entity.Signature())
if err != nil {
signature.Err = err
return false
......
......@@ -19,6 +19,7 @@ package federation
import (
"testing"
"encoding/base64"
)
func TestSignatureInterface(t *testing.T) {
......@@ -49,4 +50,15 @@ func TestSignatureInterface(t *testing.T) {
"author created_at guid parent_guid text", &priv.PublicKey) {
t.Errorf("Expected to be a valid signature, got invalid")
}
sigBytes, err := base64.URLEncoding.DecodeString(sig)
if err != nil {
t.Errorf("Some error occured while parsing: %v", err)
}
sig = base64.StdEncoding.EncodeToString(sigBytes)
if !signature.New(EntityComment{AuthorSignature: sig}).Verify(
"author created_at guid parent_guid text", &priv.PublicKey) {
t.Errorf("Expected to be a valid signature, got invalid")
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment