commit 8a7d4978609d7a0d1fcf8ff24d0d2c377724aed3
parent 9f3f66b4104bb19c9a3beda0afb565041d097be8
Author: parazyd <parazyd@dyne.org>
Date: Fri, 8 Dec 2017 19:03:03 +0100
Whitespace fixes
Diffstat:
5 files changed, 2 insertions(+), 37 deletions(-)
diff --git a/cmd/dam-client/main.go b/cmd/dam-client/main.go
@@ -87,12 +87,10 @@ func main() {
"signature": encodedSig,
"secret": "",
}
-
- log.Println("Announcing keypair for:", vals["address"])
-
jsonVal, err := json.Marshal(vals)
lib.CheckError(err)
+ log.Println("Announcing keypair for:", vals["address"])
log.Println("Sending request")
resp, err := lib.HTTPPost("http://localhost:8080/announce", jsonVal)
lib.CheckError(err)
diff --git a/cmd/dam-dir/main.go b/cmd/dam-dir/main.go
@@ -86,9 +86,6 @@ func handlePost(rw http.ResponseWriter, request *http.Request) {
randString, err := lib.GenRandomASCII(64)
lib.CheckError(err)
- // FIXME: delete this line after debug mode
- log.Println("Secret:", randString)
-
secret, err := lib.EncryptMsg([]byte(randString), pubkey)
lib.CheckError(err)
@@ -118,7 +115,6 @@ func handlePost(rw http.ResponseWriter, request *http.Request) {
info["firstseen"] = n.Firstseen
info["valid"] = 0 // This should be 1 after the node is not considered malicious
}
-
log.Println("Writing to Redis")
redRet, err := RedisCli.HMSet(n.Address, info).Result()
lib.CheckError(err)
@@ -142,14 +138,12 @@ func handlePost(rw http.ResponseWriter, request *http.Request) {
log.Println("Secrets match!")
correct = true
}
-
if correct {
log.Printf("Welcoming %s to the network\n", n.Address)
ret := map[string]string{
"secret": "Welcome to the DECODE network!",
}
n.Valid = 0
-
jsonVal, err := json.Marshal(ret)
lib.CheckError(err)
diff --git a/pkg/lib/crypto.go b/pkg/lib/crypto.go
@@ -39,17 +39,14 @@ func SavePub(filename string, pubkey rsa.PublicKey) (bool, error) {
if err != nil {
return false, err
}
-
asn1Bytes, err := asn1.Marshal(pubkey)
if err != nil {
return false, err
}
-
var pemkey = &pem.Block{
Type: "RSA PUBLIC KEY",
Bytes: asn1Bytes,
}
-
err = pem.Encode(outfile, pemkey)
if err != nil {
return false, err
@@ -70,12 +67,10 @@ func SavePriv(filename string, privkey *rsa.PrivateKey) (bool, error) {
if err != nil {
return false, err
}
-
var pemkey = &pem.Block{
Type: "RSA PRIVATE KEY",
Bytes: x509.MarshalPKCS1PrivateKey(privkey),
}
-
err = pem.Encode(outfile, pemkey)
if err != nil {
return false, err
@@ -94,17 +89,14 @@ func LoadKeyFromFile(filename string) (*rsa.PrivateKey, error) {
if err != nil {
return nil, err
}
-
block, _ := pem.Decode(dat)
if block == nil {
return nil, errors.New("failed to parse PEM block containing the key")
}
-
priv, err := x509.ParsePKCS1PrivateKey(block.Bytes)
if err != nil {
return nil, err
}
-
return priv, nil
}
@@ -112,13 +104,11 @@ func LoadKeyFromFile(filename string) (*rsa.PrivateKey, error) {
func SignMsg(message []byte, privkey *rsa.PrivateKey) ([]byte, error) {
log.Println("Signing message...")
rng := rand.Reader
-
hashed := sha512.Sum512(message)
sig, err := rsa.SignPKCS1v15(rng, privkey, crypto.SHA512, hashed[:])
if err != nil {
return nil, err
}
-
return sig, nil
}
@@ -127,12 +117,10 @@ func SignMsg(message []byte, privkey *rsa.PrivateKey) ([]byte, error) {
func EncryptMsg(message []byte, pubkey *rsa.PublicKey) ([]byte, error) {
log.Println("Encrypting message...")
rng := rand.Reader
-
msg, err := rsa.EncryptPKCS1v15(rng, pubkey, message)
if err != nil {
return nil, err
}
-
return msg, nil
}
@@ -141,12 +129,10 @@ func EncryptMsg(message []byte, pubkey *rsa.PublicKey) ([]byte, error) {
func DecryptMsg(message []byte, privkey *rsa.PrivateKey) ([]byte, error) {
log.Println("Decrypting message...")
rng := rand.Reader
-
msg, err := rsa.DecryptPKCS1v15(rng, privkey, message)
if err != nil {
return nil, err
}
-
return msg, nil
}
@@ -154,13 +140,11 @@ func DecryptMsg(message []byte, privkey *rsa.PrivateKey) ([]byte, error) {
// RSA pubkey.
func VerifyMsg(message []byte, signature []byte, pubkey *rsa.PublicKey) (bool, error) {
log.Println("Verifying message signature")
-
hashed := sha512.Sum512(message)
err := rsa.VerifyPKCS1v15(pubkey, crypto.SHA512, hashed[:], signature)
if err != nil {
return false, err
}
-
log.Println("Signature valid")
return true, nil
}
@@ -171,13 +155,11 @@ func OnionFromPubkey(pubkey rsa.PublicKey) ([]byte, error) {
if err != nil {
return nil, err
}
-
hashed := sha1.New()
_, err = hashed.Write(asn1Bytes)
if err != nil {
return nil, err
}
-
encoded := strings.ToLower(base32.StdEncoding.EncodeToString(hashed.Sum(nil)))[:16]
encoded += ".onion"
@@ -189,13 +171,11 @@ func OnionFromPubkey(pubkey rsa.PublicKey) ([]byte, error) {
func ParsePubkey(pubkey []byte) (*rsa.PublicKey, error) {
var pub rsa.PublicKey
var ret *rsa.PublicKey
-
block, _ := pem.Decode(pubkey)
_, err := asn1.Unmarshal(block.Bytes, &pub)
if err != nil {
return nil, err
}
-
ret = &pub
return ret, nil
}
diff --git a/pkg/lib/helpers.go b/pkg/lib/helpers.go
@@ -37,7 +37,6 @@ func FetchHSPubkey(addr string) string {
cmd := exec.Command("dirauth.py", addr)
cmd.Stdout = &outb
cmd.Stderr = &errb
-
err := cmd.Start()
CheckError(err)
@@ -56,14 +55,12 @@ func ValidateReq(req map[string]string) ([]byte, bool) {
if req["nodetype"] != "node" {
return nil, false
}
-
// Validate address.
re, err := regexp.Compile("^[a-z2-7]{16}\\.onion$")
CheckError(err)
if len(re.FindString(req["address"])) != 22 {
return nil, false
}
-
// Address is valid, we try to fetch its pubkey from a HSDir
var pubkey string
var cnt = 0
@@ -83,7 +80,6 @@ func ValidateReq(req map[string]string) ([]byte, bool) {
}
time.Sleep(2000 * time.Millisecond)
}
-
// Validate signature.
msg := []byte(req["message"])
sig := []byte(req["signature"])
@@ -103,7 +99,6 @@ func ValidateReq(req map[string]string) ([]byte, bool) {
// application/json.
func HTTPPost(host string, data []byte) (*http.Response, error) {
socksify := false
-
parsedHost, err := url.Parse(host)
if err != nil {
return nil, err
@@ -112,7 +107,6 @@ func HTTPPost(host string, data []byte) (*http.Response, error) {
if strings.HasSuffix(hostname, ".onion") {
socksify = true
}
-
httpTransp := &http.Transport{}
httpClient := &http.Client{Transport: httpTransp}
if socksify {
@@ -123,7 +117,6 @@ func HTTPPost(host string, data []byte) (*http.Response, error) {
}
httpTransp.Dial = dialer.Dial
}
-
request, err := http.NewRequest("POST", host, bytes.NewBuffer(data))
if err != nil {
return nil, err
@@ -149,7 +142,6 @@ func GenRandomASCII(length int) (string, error) {
if err != nil {
return "", err
}
-
n := num.Int64()
if n > 32 && n < 127 {
res += string(n)
diff --git a/python/decodehs.py b/python/decodehs.py
@@ -54,5 +54,6 @@ def main():
stdout.flush()
sleep(10)
+
if __name__ == '__main__':
main()