add tests and try making no libsodium version work properly
This commit is contained in:
parent
2983eb6fbd
commit
59ea3da355
@ -10,3 +10,9 @@ pure:
|
|||||||
|
|
||||||
clean:
|
clean:
|
||||||
GOPATH=$(REPO) go clean -v
|
GOPATH=$(REPO) go clean -v
|
||||||
|
|
||||||
|
test:
|
||||||
|
GOPATH=$(REPO) go test -v -tags libsodium srnd
|
||||||
|
|
||||||
|
test-pure:
|
||||||
|
GOPATH=$(REPO) go test -v srnd
|
||||||
|
44
contrib/backends/srndv2/src/srnd/crypto_test.go
Normal file
44
contrib/backends/srndv2/src/srnd/crypto_test.go
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
package srnd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"io"
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestVerify(t *testing.T) {
|
||||||
|
d := filepath.Join("testdata", "article.test.txt")
|
||||||
|
|
||||||
|
f, e := os.Open(d)
|
||||||
|
if e != nil {
|
||||||
|
t.Logf("os.Open returned error: %s", e)
|
||||||
|
t.Fail()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
r := bufio.NewReader(f)
|
||||||
|
|
||||||
|
msg, er := readMIMEHeader(r)
|
||||||
|
if er != nil {
|
||||||
|
t.Logf("readMIMEHeader returned error: %s", er)
|
||||||
|
t.Fail()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
b := &io.LimitedReader{
|
||||||
|
R: msg.Body,
|
||||||
|
N: 1000000000,
|
||||||
|
}
|
||||||
|
|
||||||
|
err := read_message_body(b, msg.Header, nil, ioutil.Discard, true, func(msg NNTPMessage) {
|
||||||
|
return
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
t.Logf("read_message_body returned error: %s", err)
|
||||||
|
t.Fail()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
@ -3,27 +3,44 @@
|
|||||||
package srnd
|
package srnd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"crypto/sha512"
|
||||||
"golang.org/x/crypto/curve25519"
|
"golang.org/x/crypto/curve25519"
|
||||||
|
"golang.org/x/crypto/ed25519"
|
||||||
)
|
)
|
||||||
|
|
||||||
func naclCryptoVerifyFucky(h, sig, pk []byte) bool {
|
func naclCryptoVerifyFucky(h, sig, pk []byte) bool {
|
||||||
return false
|
pub := make(ed25519.PublicKey, ed25519.PublicKeySize)
|
||||||
|
copy(pub, pk)
|
||||||
|
return ed25519.Verify(pub, h, sig)
|
||||||
}
|
}
|
||||||
|
|
||||||
func naclCryptoSignFucky(hash, sk []byte) []byte {
|
func naclCryptoSignFucky(hash, sk []byte) []byte {
|
||||||
return nil
|
sec := make(ed25519.PrivateKey, ed25519.PrivateKeySize)
|
||||||
}
|
copy(sec, sk)
|
||||||
|
return ed25519.Sign(sec, hash)
|
||||||
func naclCryptoVerifyDetached(hash, sig, pk []byte) bool {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
func naclCryptoSignDetached(hash, sk []byte) []byte {
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func naclSeedToKeyPair(seed []byte) (pk, sk []byte) {
|
func naclSeedToKeyPair(seed []byte) (pk, sk []byte) {
|
||||||
|
h := sha512.Sum512(seed)
|
||||||
|
sk = h[:]
|
||||||
|
sk[0] &= 248
|
||||||
|
sk[31] &= 63
|
||||||
|
sk[31] |= 64
|
||||||
|
|
||||||
|
// scalarmult magick shit
|
||||||
|
pk = scalarBaseMult(sk)
|
||||||
|
|
||||||
|
copy(sk[0:32], seed[0:32])
|
||||||
|
copy(sk[32:64], pk[0:32])
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var naclScalarBaseMult = curve25519.ScalarBaseMult
|
func scalarBaseMult(sk []byte) (pk []byte) {
|
||||||
|
var skey [32]byte
|
||||||
|
var pkey [32]byte
|
||||||
|
copy(skey[0:32], sk[0:32])
|
||||||
|
curve25519.ScalarBaseMult(&pkey, &skey)
|
||||||
|
pk = pkey[0:32]
|
||||||
|
return
|
||||||
|
}
|
||||||
|
@ -502,7 +502,7 @@ func verifyMessageBLAKE2B(pk, sig string, body *io.LimitedReader, innerHandler f
|
|||||||
hash := h.Sum(nil)
|
hash := h.Sum(nil)
|
||||||
log.Printf("hash=%s", hexify(hash))
|
log.Printf("hash=%s", hexify(hash))
|
||||||
log.Printf("sig=%s", hexify(sig_bytes))
|
log.Printf("sig=%s", hexify(sig_bytes))
|
||||||
if naclCryptoVerifyDetached(hash, sig_bytes, pk_bytes) {
|
if naclCryptoVerifyFucky(hash, sig_bytes, pk_bytes) {
|
||||||
log.Println("signature is valid :^)")
|
log.Println("signature is valid :^)")
|
||||||
} else {
|
} else {
|
||||||
err = errors.New("invalid signature")
|
err = errors.New("invalid signature")
|
||||||
|
@ -1,21 +0,0 @@
|
|||||||
package srnd
|
|
||||||
|
|
||||||
import "testing"
|
|
||||||
import "fmt"
|
|
||||||
import "github.com/majestrate/nacl"
|
|
||||||
|
|
||||||
func TestSignVerify(t *testing.T) {
|
|
||||||
|
|
||||||
msgid := "<asd@asd.asd>"
|
|
||||||
secret := "asdasdasd"
|
|
||||||
seed := parseTripcodeSecret(secret)
|
|
||||||
kp := nacl.LoadSignKey(seed)
|
|
||||||
defer kp.Free()
|
|
||||||
pubkey := hexify(kp.Public())
|
|
||||||
seckey := kp.Secret()
|
|
||||||
sig := msgidFrontendSign(seckey, msgid)
|
|
||||||
fmt.Println(sig, pubkey, msgid)
|
|
||||||
if !verifyFrontendSig(pubkey, sig, msgid) {
|
|
||||||
t.Fail()
|
|
||||||
}
|
|
||||||
}
|
|
23
contrib/backends/srndv2/src/srnd/testdata/article.test.txt
vendored
Normal file
23
contrib/backends/srndv2/src/srnd/testdata/article.test.txt
vendored
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
Subject: My moderation decision/perspective
|
||||||
|
From: mgs <poster@web.oniichan.onion>
|
||||||
|
X-Signature-Ed25519-SHA512: 6e0478722d0de3c0896e8aa7bd9bb1fa94ba6831faf0c54c4aa1d91a191382f85ae57833a6e00f1d4da53048df0e0cb8402df5f952948aa53fb5788ca9242f02
|
||||||
|
X-Frontend-Pubkey: b1dcaa6ba60c1381a5823c3c61c995afeaead79896f95f9748da5fe1cf6ea43f
|
||||||
|
Path: web.oniichan.onion
|
||||||
|
Content-Type: message/rfc822; charset=UTF-8
|
||||||
|
Newsgroups: overchan.moderation
|
||||||
|
Message-ID: <b880c1483096181@web.oniichan.onion>
|
||||||
|
Date: Fri, 30 Dec 2016 11:09:41 +0000
|
||||||
|
X-PubKey-Ed25519: 9a659a2c761009374b510f2eb133cf7e67220f93c8912fd4668c601144823121
|
||||||
|
X-Frontend-Signature: 11eb01c8a137e29f4e7a8b25a2cf38b5d913db9d4faaca5c5f8946b0e7f83d826bd3af6c9fc6a40c1091c09ad437b2b9d9aa41617c63a464e5b1833ed77fe202
|
||||||
|
|
||||||
|
Path: web.oniichan.onion
|
||||||
|
Content-Type: text/plain; charset=utf-8
|
||||||
|
Newsgroups: overchan.moderation
|
||||||
|
Subject: My moderation decision/perspective
|
||||||
|
From: mgs <poster@web.oniichan.onion>
|
||||||
|
Message-ID: <b880c1483096181@web.oniichan.onion>
|
||||||
|
Date: Fri, 30 Dec 2016 11:09:41 +0000
|
||||||
|
|
||||||
|
Like the subject says, I will update in this thread on decisions I made on ctl with briefs/explanations. Anyone is actually welcomed to comment, discuss, and opinionate here, but not spam. If anyone uses this very thread to spam, I will delete, the node owners will see it, and I will reply it here exactly saying so.
|
||||||
|
|
||||||
|
Iow: please critique.
|
Reference in New Issue
Block a user