probably broken
This commit is contained in:
parent
aa3cf130b3
commit
86b3d3ce62
@ -10,7 +10,6 @@ import (
|
|||||||
"encoding/base32"
|
"encoding/base32"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/majestrate/configparser"
|
"github.com/majestrate/configparser"
|
||||||
"github.com/majestrate/nacl"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
@ -240,7 +239,7 @@ func GenSRNdConfig() *configparser.Configuration {
|
|||||||
sect.Add("json-api", "0")
|
sect.Add("json-api", "0")
|
||||||
sect.Add("json-api-username", "fucking-change-this-value")
|
sect.Add("json-api-username", "fucking-change-this-value")
|
||||||
sect.Add("json-api-password", "seriously-fucking-change-this-value")
|
sect.Add("json-api-password", "seriously-fucking-change-this-value")
|
||||||
secret_bytes := nacl.RandBytes(8)
|
secret_bytes := randbytes(8)
|
||||||
secret := base32.StdEncoding.EncodeToString(secret_bytes)
|
secret := base32.StdEncoding.EncodeToString(secret_bytes)
|
||||||
sect.Add("api-secret", secret)
|
sect.Add("api-secret", secret)
|
||||||
|
|
||||||
|
15
contrib/backends/srndv2/src/srnd/crypto_nacl.go
Normal file
15
contrib/backends/srndv2/src/srnd/crypto_nacl.go
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
package srnd
|
||||||
|
|
||||||
|
import "github.com/majestrate/nacl"
|
||||||
|
|
||||||
|
func nacl_cryptoVerifyFucky(hash, sig, pk []byte) bool {
|
||||||
|
return nacl.CryptoVerifyFucky(hash, sig, pk)
|
||||||
|
}
|
||||||
|
|
||||||
|
func nacl_cryptoSignFucky(hash, sk []byte) (sig []byte) {
|
||||||
|
return nacl.CryptoSignFucky(hash, sk)
|
||||||
|
}
|
||||||
|
|
||||||
|
func nacl_cryptoVerifyDetached(hash, sig, pk []byte) bool {
|
||||||
|
return nacl.CryptoVerifyDetached(hash, sig, pk)
|
||||||
|
}
|
@ -7,7 +7,6 @@ import (
|
|||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/majestrate/nacl"
|
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
@ -166,14 +165,10 @@ func (self *NNTPDaemon) WrapSign(nntp NNTPMessage) {
|
|||||||
if seed == nil {
|
if seed == nil {
|
||||||
log.Println("invalid secretkey will not sign")
|
log.Println("invalid secretkey will not sign")
|
||||||
} else {
|
} else {
|
||||||
kp := nacl.LoadSignKey(seed)
|
pk, sec := seedToKeyPair(seed)
|
||||||
defer kp.Free()
|
|
||||||
sec := kp.Secret()
|
|
||||||
sig := msgidFrontendSign(sec, nntp.MessageID())
|
sig := msgidFrontendSign(sec, nntp.MessageID())
|
||||||
pk := hexify(kp.Public())
|
|
||||||
nntp.Headers().Add("X-Frontend-Signature", sig)
|
nntp.Headers().Add("X-Frontend-Signature", sig)
|
||||||
nntp.Headers().Add("X-Frontend-Pubkey", pk)
|
nntp.Headers().Add("X-Frontend-Pubkey", hexify(pk))
|
||||||
log.Println("signed", nntp.MessageID(), "as from", pk)
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log.Println("sending", nntp.MessageID(), "unsigned")
|
log.Println("sending", nntp.MessageID(), "unsigned")
|
||||||
@ -467,8 +462,7 @@ func (self *NNTPDaemon) syncPull(proxy_type, proxy_addr, remote_addr string) {
|
|||||||
if reader {
|
if reader {
|
||||||
// we can do it
|
// we can do it
|
||||||
err = nntp.scrapeServer(self, conn)
|
err = nntp.scrapeServer(self, conn)
|
||||||
if err == nil {
|
if err == nil { // we succeeded
|
||||||
// we succeeded
|
|
||||||
log.Println(nntp.name, "Scrape successful")
|
log.Println(nntp.name, "Scrape successful")
|
||||||
nntp.Quit(conn)
|
nntp.Quit(conn)
|
||||||
conn.Close()
|
conn.Close()
|
||||||
|
@ -16,7 +16,6 @@ import (
|
|||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
"github.com/gorilla/sessions"
|
"github.com/gorilla/sessions"
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
"github.com/majestrate/nacl"
|
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"mime"
|
"mime"
|
||||||
@ -921,14 +920,9 @@ func (self *httpFrontend) handle_postRequest(pr *postRequest, b bannedFunc, e er
|
|||||||
}
|
}
|
||||||
// pack it before sending so that the article is well formed
|
// pack it before sending so that the article is well formed
|
||||||
// sign if needed
|
// sign if needed
|
||||||
if len(tripcode_privkey) == nacl.CryptoSignSeedLen() {
|
if len(tripcode_privkey) == 32 {
|
||||||
kp := nacl.LoadSignKey(tripcode_privkey)
|
pk, _ := seedToKeyPair(tripcode_privkey)
|
||||||
if kp == nil {
|
nntp.headers.Set("X-PubKey-Ed25519", hexify(pk))
|
||||||
e(errors.New("seed keypair was nil?"))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
defer kp.Free()
|
|
||||||
nntp.headers.Set("X-PubKey-Ed25519", hexify(kp.Public()))
|
|
||||||
nntp.Pack()
|
nntp.Pack()
|
||||||
err = self.daemon.store.RegisterPost(nntp)
|
err = self.daemon.store.RegisterPost(nntp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -10,7 +10,6 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/dchest/blake2b"
|
"github.com/dchest/blake2b"
|
||||||
"github.com/majestrate/nacl"
|
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"mime"
|
"mime"
|
||||||
@ -181,22 +180,15 @@ func signArticle(nntp NNTPMessage, seed []byte) (signed *nntpArticle, err error)
|
|||||||
mw.Write([]byte{10})
|
mw.Write([]byte{10})
|
||||||
if err == nil {
|
if err == nil {
|
||||||
// build keypair
|
// build keypair
|
||||||
kp := nacl.LoadSignKey(seed)
|
pk, sk := seedToKeyPair(seed)
|
||||||
if kp == nil {
|
|
||||||
log.Println("failed to load seed for signing article")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
defer kp.Free()
|
|
||||||
sk := kp.Secret()
|
|
||||||
pk := getSignPubkey(sk)
|
|
||||||
// sign it nigguh
|
// sign it nigguh
|
||||||
digest := sha.Sum(nil)
|
digest := sha.Sum(nil)
|
||||||
sig := cryptoSign(digest, sk)
|
sig := cryptoSignFucky(digest, sk)
|
||||||
// log that we signed it
|
// log that we signed it
|
||||||
// log.Printf("signed %s pubkey=%s sig=%s hash=%s", nntp.MessageID(), pk, sig, hexify(digest))
|
// log.Printf("signed %s pubkey=%s sig=%s hash=%s", nntp.MessageID(), pk, sig, hexify(digest))
|
||||||
signed.headers.Set("X-Signature-Ed25519-SHA512", sig)
|
signed.headers.Set("X-Signature-Ed25519-SHA512", sig)
|
||||||
signed.headers.Set("X-PubKey-Ed25519", pk)
|
signed.headers.Set("X-PubKey-Ed25519", hexify(pk[:]))
|
||||||
sig = cryptoSignNew(blake.Sum(nil), sk)
|
sig = cryptoSignProper(blake.Sum(nil), sk)
|
||||||
signed.headers.Set("X-Signature-Ed25519-BLAKE2B", sig)
|
signed.headers.Set("X-Signature-Ed25519-BLAKE2B", sig)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
@ -472,7 +464,7 @@ func verifyMessageSHA512(pk, sig string, body *io.LimitedReader, innerHandler fu
|
|||||||
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 nacl.CryptoVerifyFucky(hash, sig_bytes, pk_bytes) {
|
if nacl_cryptoVerifyFucky(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")
|
||||||
@ -510,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 nacl.CryptoVerifyDetached(hash, sig_bytes, pk_bytes) {
|
if nacl_cryptoVerifyDetached(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")
|
||||||
|
@ -13,7 +13,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"github.com/gorilla/csrf"
|
"github.com/gorilla/csrf"
|
||||||
"github.com/gorilla/sessions"
|
"github.com/gorilla/sessions"
|
||||||
"github.com/majestrate/nacl"
|
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
@ -416,12 +415,9 @@ func (self httpModUI) CheckPubkey(pubkey, scope string) (bool, error) {
|
|||||||
func (self httpModUI) CheckKey(privkey, scope string) (bool, error) {
|
func (self httpModUI) CheckKey(privkey, scope string) (bool, error) {
|
||||||
privkey_bytes, err := hex.DecodeString(privkey)
|
privkey_bytes, err := hex.DecodeString(privkey)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
kp := nacl.LoadSignKey(privkey_bytes)
|
pk, _ := seedToKeyPair(privkey_bytes)
|
||||||
if kp != nil {
|
pubkey := hex.EncodeToString(pk)
|
||||||
defer kp.Free()
|
return self.CheckPubkey(pubkey, scope)
|
||||||
pubkey := hex.EncodeToString(kp.Public())
|
|
||||||
return self.CheckPubkey(pubkey, scope)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
log.Println("invalid key format for key", privkey)
|
log.Println("invalid key format for key", privkey)
|
||||||
return false, err
|
return false, err
|
||||||
|
@ -6,12 +6,12 @@ package srnd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
|
"crypto/rand"
|
||||||
"crypto/sha1"
|
"crypto/sha1"
|
||||||
"crypto/sha512"
|
"crypto/sha512"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/majestrate/nacl"
|
|
||||||
"golang.org/x/crypto/curve25519"
|
"golang.org/x/crypto/curve25519"
|
||||||
"golang.org/x/crypto/ed25519"
|
"golang.org/x/crypto/ed25519"
|
||||||
"io"
|
"io"
|
||||||
@ -104,9 +104,15 @@ func OpenFileWriter(fname string) (io.WriteCloser, error) {
|
|||||||
return os.Create(fname)
|
return os.Create(fname)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func randbytes(l int) []byte {
|
||||||
|
b := make([]byte, l)
|
||||||
|
io.ReadFull(rand.Reader, b)
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
||||||
// make a random string
|
// make a random string
|
||||||
func randStr(length int) string {
|
func randStr(length int) string {
|
||||||
return hex.EncodeToString(nacl.RandBytes(length))[length:]
|
return hex.EncodeToString(randbytes(length))[length:]
|
||||||
}
|
}
|
||||||
|
|
||||||
// time for right now as int64
|
// time for right now as int64
|
||||||
@ -212,7 +218,7 @@ func i2pDestHashLen() int {
|
|||||||
// generate a new encryption key for it
|
// generate a new encryption key for it
|
||||||
// return the encryption key and the encrypted address
|
// return the encryption key and the encrypted address
|
||||||
func newAddrEnc(addr string) (string, string) {
|
func newAddrEnc(addr string) (string, string) {
|
||||||
key_bytes := nacl.RandBytes(encAddrBytes())
|
key_bytes := randbytes(encAddrBytes())
|
||||||
key := base64.StdEncoding.EncodeToString(key_bytes)
|
key := base64.StdEncoding.EncodeToString(key_bytes)
|
||||||
return key, encAddr(addr, key)
|
return key, encAddr(addr, key)
|
||||||
}
|
}
|
||||||
@ -291,13 +297,16 @@ func ValidNewsgroup(newsgroup string) bool {
|
|||||||
return newsgroupValidFormat(newsgroup)
|
return newsgroupValidFormat(newsgroup)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func genKeypair() (pk, sk []byte) {
|
||||||
|
sk = randbytes(32)
|
||||||
|
pk, _ = seedToKeyPair(sk)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// generate a new signing keypair
|
// generate a new signing keypair
|
||||||
// public, secret
|
// public, secret
|
||||||
func newSignKeypair() (string, string) {
|
func newSignKeypair() (string, string) {
|
||||||
kp := nacl.GenSignKeypair()
|
pk, sk := genKeypair()
|
||||||
defer kp.Free()
|
|
||||||
pk := kp.Public()
|
|
||||||
sk := kp.Seed()
|
|
||||||
return hex.EncodeToString(pk), hex.EncodeToString(sk)
|
return hex.EncodeToString(pk), hex.EncodeToString(sk)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -387,15 +396,16 @@ func hexify(data []byte) string {
|
|||||||
// extract pubkey from secret key
|
// extract pubkey from secret key
|
||||||
// return as hex
|
// return as hex
|
||||||
func getSignPubkey(sk []byte) string {
|
func getSignPubkey(sk []byte) string {
|
||||||
k, _ := nacl.GetSignPubkey(sk)
|
_, pk := seedToKeyPair(sk)
|
||||||
return hexify(k)
|
return hexify(pk)
|
||||||
}
|
}
|
||||||
|
|
||||||
// sign data with secret key the fucky srnd way
|
// sign data with secret key the fucky srnd way
|
||||||
// return signature as hex
|
// return signature as hex
|
||||||
func cryptoSign(h, sk []byte) string {
|
// XXX: DEPRECATED
|
||||||
|
func cryptoSignFucky(h, sk []byte) string {
|
||||||
// sign
|
// sign
|
||||||
sig := nacl.CryptoSignFucky(h, sk)
|
sig := nacl_cryptoSignFucky(h, sk)
|
||||||
if sig == nil {
|
if sig == nil {
|
||||||
return "[failed to sign]"
|
return "[failed to sign]"
|
||||||
}
|
}
|
||||||
@ -403,19 +413,20 @@ func cryptoSign(h, sk []byte) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// convert seed to secret key
|
// convert seed to secret key
|
||||||
func seedToSecretNew(seed []byte) (full ed25519.PrivateKey) {
|
func seedToKeyPair(seed []byte) (full ed25519.PrivateKey, pub ed25519.PublicKey) {
|
||||||
var out [32]byte
|
|
||||||
var in [32]byte
|
var in [32]byte
|
||||||
|
var out [32]byte
|
||||||
copy(in[:], seed[0:32])
|
copy(in[:], seed[0:32])
|
||||||
curve25519.ScalarBaseMult(&out, &in)
|
curve25519.ScalarBaseMult(&out, &in)
|
||||||
|
copy(pub[:], out[:])
|
||||||
copy(full[:], in[:])
|
copy(full[:], in[:])
|
||||||
copy(full[:32], out[:])
|
copy(full[:32], pub[:])
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func cryptoSignNew(h, sk []byte) string {
|
func cryptoSignProper(h, sk []byte) string {
|
||||||
// convert key
|
// convert key
|
||||||
key := seedToSecretNew(sk)
|
key, _ := seedToKeyPair(sk)
|
||||||
// sign
|
// sign
|
||||||
sig := ed25519.Sign(key, h)
|
sig := ed25519.Sign(key, h)
|
||||||
if sig == nil {
|
if sig == nil {
|
||||||
@ -429,7 +440,7 @@ func cryptoSignNew(h, sk []byte) string {
|
|||||||
func parseTripcodeSecret(str string) []byte {
|
func parseTripcodeSecret(str string) []byte {
|
||||||
// try decoding hex
|
// try decoding hex
|
||||||
raw := unhex(str)
|
raw := unhex(str)
|
||||||
keylen := nacl.CryptoSignSeedLen()
|
keylen := 32
|
||||||
if raw == nil || len(raw) != keylen {
|
if raw == nil || len(raw) != keylen {
|
||||||
// treat this as a "regular" chan tripcode
|
// treat this as a "regular" chan tripcode
|
||||||
// decode as bytes then pad the rest with 0s if it doesn't fit
|
// decode as bytes then pad the rest with 0s if it doesn't fit
|
||||||
@ -670,17 +681,17 @@ func extractRealIP(r *http.Request) (ip string, err error) {
|
|||||||
|
|
||||||
func serverPubkeyIsValid(pubkey string) bool {
|
func serverPubkeyIsValid(pubkey string) bool {
|
||||||
b := unhex(pubkey)
|
b := unhex(pubkey)
|
||||||
return b != nil && len(b) == nacl.CryptoSignPubKeySize()
|
return b != nil && len(b) == 32
|
||||||
}
|
}
|
||||||
|
|
||||||
func verifyFrontendSig(pubkey, sig, msgid string) bool {
|
func verifyFrontendSig(pubkey, sig, msgid string) bool {
|
||||||
s := unhex(sig)
|
s := unhex(sig)
|
||||||
k := unhex(pubkey)
|
k := unhex(pubkey)
|
||||||
h := sha512.Sum512([]byte(msgid))
|
h := sha512.Sum512([]byte(msgid))
|
||||||
return nacl.CryptoVerifyFucky(h[:], s, k)
|
return nacl_cryptoVerifyFucky(h[:], s, k)
|
||||||
}
|
}
|
||||||
|
|
||||||
func msgidFrontendSign(sk []byte, msgid string) string {
|
func msgidFrontendSign(sk []byte, msgid string) string {
|
||||||
h := sha512.Sum512([]byte(msgid))
|
h := sha512.Sum512([]byte(msgid))
|
||||||
return cryptoSign(h[:], sk)
|
return cryptoSignFucky(h[:], sk)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user