From bf3502220fb3140db1d76ab2e436ac23d8ad8f8d Mon Sep 17 00:00:00 2001 From: Zlatin Balevsky Date: Sun, 3 Nov 2019 22:44:42 +0000 Subject: [PATCH] sign update queries as well --- core/src/main/groovy/com/muwire/core/Core.groovy | 2 +- .../groovy/com/muwire/core/update/UpdateClient.groovy | 11 +++++++++-- .../com/muwire/gui/MainFrameController.groovy | 5 ++++- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/core/src/main/groovy/com/muwire/core/Core.groovy b/core/src/main/groovy/com/muwire/core/Core.groovy index 65a869ae..eb9481c1 100644 --- a/core/src/main/groovy/com/muwire/core/Core.groovy +++ b/core/src/main/groovy/com/muwire/core/Core.groovy @@ -255,7 +255,7 @@ public class Core { cacheClient = new CacheClient(eventBus,hostCache, connectionManager, i2pSession, props, 10000) log.info("initializing update client") - updateClient = new UpdateClient(eventBus, i2pSession, myVersion, props, fileManager, me) + updateClient = new UpdateClient(eventBus, i2pSession, myVersion, props, fileManager, me, spk) eventBus.register(FileDownloadedEvent.class, updateClient) eventBus.register(UIResultBatchEvent.class, updateClient) diff --git a/core/src/main/groovy/com/muwire/core/update/UpdateClient.groovy b/core/src/main/groovy/com/muwire/core/update/UpdateClient.groovy index f55f2590..4ae050b2 100644 --- a/core/src/main/groovy/com/muwire/core/update/UpdateClient.groovy +++ b/core/src/main/groovy/com/muwire/core/update/UpdateClient.groovy @@ -21,7 +21,10 @@ import net.i2p.client.I2PSessionMuxedListener import net.i2p.client.SendMessageOptions import net.i2p.client.datagram.I2PDatagramDissector import net.i2p.client.datagram.I2PDatagramMaker +import net.i2p.crypto.DSAEngine import net.i2p.data.Base64 +import net.i2p.data.Signature +import net.i2p.data.SigningPrivateKey import net.i2p.util.VersionComparator @Log @@ -32,6 +35,7 @@ class UpdateClient { final MuWireSettings settings final FileManager fileManager final Persona me + final SigningPrivateKey spk private final Timer timer @@ -43,13 +47,15 @@ class UpdateClient { private volatile String text - UpdateClient(EventBus eventBus, I2PSession session, String myVersion, MuWireSettings settings, FileManager fileManager, Persona me) { + UpdateClient(EventBus eventBus, I2PSession session, String myVersion, MuWireSettings settings, + FileManager fileManager, Persona me, SigningPrivateKey spk) { this.eventBus = eventBus this.session = session this.myVersion = myVersion this.settings = settings this.fileManager = fileManager this.me = me + this.spk = spk timer = new Timer("update-client",true) } @@ -164,9 +170,10 @@ class UpdateClient { version = payload.version signer = payload.signer log.info("starting search for new version hash $payload.infoHash") + Signature sig = DSAEngine.getInstance().sign(updateInfoHash.getRoot(), spk) def searchEvent = new SearchEvent(searchHash : updateInfoHash.getRoot(), uuid : UUID.randomUUID(), oobInfohash : true) def queryEvent = new QueryEvent(searchEvent : searchEvent, firstHop : true, replyTo : me.destination, - receivedOn : me.destination, originator : me) + receivedOn : me.destination, originator : me, sig : sig.data) eventBus.publish(queryEvent) } } diff --git a/gui/griffon-app/controllers/com/muwire/gui/MainFrameController.groovy b/gui/griffon-app/controllers/com/muwire/gui/MainFrameController.groovy index 0feed647..7df909e2 100644 --- a/gui/griffon-app/controllers/com/muwire/gui/MainFrameController.groovy +++ b/gui/griffon-app/controllers/com/muwire/gui/MainFrameController.groovy @@ -135,11 +135,14 @@ class MainFrameController { def group = mvcGroup.createMVCGroup("SearchTab", uuid.toString(), params) model.results[uuid.toString()] = group + byte [] infoHashBytes = Base64.decode(infoHash) + Signature sig = DSAEngine.getInstance().sign(infoHashBytes, core.spk) + def searchEvent = new SearchEvent(searchHash : Base64.decode(infoHash), uuid:uuid, oobInfohash: true) core.eventBus.publish(new QueryEvent(searchEvent : searchEvent, firstHop : true, replyTo: core.me.destination, receivedOn: core.me.destination, - originator : core.me)) + originator : core.me, sig : sig.data)) } private int selectedDownload() {