Skip to content

Commit

Permalink
Fix cert for loopback
Browse files Browse the repository at this point in the history
  • Loading branch information
purplesyringa committed May 28, 2018
1 parent 3a7744a commit cb56f5e
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions plugins/P2P-messages/UiWebsocketPlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def handlePeerBroadcast(self, to, message, privatekey=None, peer_count=5, broadc
"site": self.site.address
}

all_message, msg_hash = self.peerGenerateMessage(all_message, privatekey)
all_message, msg_hash, cert = self.peerGenerateMessage(all_message, privatekey)

peers = self.site.getConnectedPeers()
if len(peers) < peer_count: # Add more, non-connected peers if necessary
Expand All @@ -73,7 +73,7 @@ def handlePeerBroadcast(self, to, message, privatekey=None, peer_count=5, broadc
"hash": msg_hash,
"message": message,
"signed_by": all_message["signature"].split("|")[0] if all_message["signature"] else "",
"cert": all_message["cert"],
"cert": cert,
"broadcast": True
})

Expand All @@ -83,7 +83,7 @@ def handlePeerBroadcast(self, to, message, privatekey=None, peer_count=5, broadc
"hash": msg_hash,
"message": message,
"signed_by": all_message["signature"].split("|")[0] if all_message["signature"] else "",
"cert": all_message["cert"],
"cert": cert,
"broadcast": True
})

Expand Down Expand Up @@ -142,7 +142,7 @@ def handlePeerSend(self, to_, ip, message, privatekey=None, to=None):
if to:
all_message["to"] = to

all_message, msg_hash = self.peerGenerateMessage(all_message, privatekey)
all_message, msg_hash, cert = self.peerGenerateMessage(all_message, privatekey)

# Send message
self.site.p2p_to[msg_hash] = gevent.event.AsyncResult()
Expand All @@ -160,6 +160,7 @@ def p2pGetSignature(self, hash, data, privatekey):
# Using site privatekey
privatekey = self.user.getSiteData(self.site.address).get("privatekey")
cert = None
cert_text = ""
elif not privatekey and privatekey is not None:
# Using user privatekey
privatekey = self.user.getAuthPrivatekey(self.site.address)
Expand All @@ -169,14 +170,17 @@ def p2pGetSignature(self, hash, data, privatekey):
site_data = self.user.getSiteData(self.site.address, create=False)
cert_issuer = site_data["cert"]
cert = [cert["auth_type"], cert["auth_user_name"], cert_issuer, cert["cert_sign"]]
cert_text = "%s/%s@%s" % tuple(cert[:3])
else:
cert_text = ""

# Generate signature
if privatekey:
from Crypt import CryptBitcoin
address = CryptBitcoin.privatekeyToAddress(privatekey)
return "%s|%s" % (address, CryptBitcoin.sign("%s|%s|%s" % (address, hash, data), privatekey)), cert
return "%s|%s" % (address, CryptBitcoin.sign("%s|%s|%s" % (address, hash, data), privatekey)), cert, cert_text
else:
return "", None
return "", None, None


def actionPeerInvalid(self, to, hash):
Expand All @@ -192,13 +196,13 @@ def peerGenerateMessage(self, all_message, privatekey=None):
all_message = json.dumps(all_message)
nonce = str(random.randint(0, 1000000000))
msg_hash = hashlib.sha256("%s,%s" % (nonce, all_message)).hexdigest()
signature, cert = self.p2pGetSignature(msg_hash, all_message, privatekey)
signature, cert, cert_text = self.p2pGetSignature(msg_hash, all_message, privatekey)
return {
"raw": all_message,
"signature": signature,
"cert": cert,
"nonce": nonce
}, msg_hash
}, msg_hash, cert_text


def peerCheckMessage(self, to, message):
Expand Down

0 comments on commit cb56f5e

Please sign in to comment.