From 72115a1185889f7d9eca54b5263665bf6696a3bb Mon Sep 17 00:00:00 2001 From: wgilster Date: Sat, 15 Oct 2016 09:47:43 -0500 Subject: [PATCH] Attempt to fix BLOCKING call --- .../security/keystore/IncomingHttpTunnel.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/host/src/main/java/org/area515/resinprinter/security/keystore/IncomingHttpTunnel.java b/host/src/main/java/org/area515/resinprinter/security/keystore/IncomingHttpTunnel.java index 3e0dd17f3..44dcaf1fa 100644 --- a/host/src/main/java/org/area515/resinprinter/security/keystore/IncomingHttpTunnel.java +++ b/host/src/main/java/org/area515/resinprinter/security/keystore/IncomingHttpTunnel.java @@ -101,14 +101,18 @@ public IncomingHttpTunnel(RendezvousClient server, URI rendezvousServerWebSocket public void sendCertificateTrustExchange(PhotonicCrypto fromLocalCrypto, UUID toRemote) throws CertificateEncodingException, JsonProcessingException, IOException { ObjectMapper mapper = new ObjectMapper(new JsonFactory()); Message message = fromLocalCrypto.buildCertificateTrustMessage(toRemote); - session.getRemote().sendBytes(ByteBuffer.wrap(mapper.writeValueAsBytes(message))); + synchronized (session.getRemote()) { + session.getRemote().sendBytes(ByteBuffer.wrap(mapper.writeValueAsBytes(message))); + } //TODO: Someday we should wait for an accept friend response from the remote. } public void sendKeyExchange(PhotonicCrypto crypto) throws CertificateExpiredException, CertificateNotYetValidException, InvalidKeyException, InvalidNameException, NoSuchAlgorithmException, SignatureException, NoSuchPaddingException, IllegalBlockSizeException, BadPaddingException, JsonProcessingException, IOException { ObjectMapper mapper = new ObjectMapper(new JsonFactory()); Message message = crypto.buildKeyExchange(); - session.getRemote().sendBytes(ByteBuffer.wrap(mapper.writeValueAsBytes(message))); + synchronized (session.getRemote()) { + session.getRemote().sendBytes(ByteBuffer.wrap(mapper.writeValueAsBytes(message))); + } //TODO: Someday we should wait for a key receipt message } @@ -277,7 +281,9 @@ public void onMessage(byte buf[], int offset, int length) { buffer.put(responseString.getBytes()); buffer.put(response); Message outMessage = connection.getCrypto().buildEncryptedMessage(buffer); - session.getRemote().sendBytes(ByteBuffer.wrap(mapper.writeValueAsBytes(outMessage))); + synchronized (session.getRemote()) { + session.getRemote().sendBytes(ByteBuffer.wrap(mapper.writeValueAsBytes(outMessage))); + } } catch (IOException | InvalidNameException | InvalidAlgorithmParameterException | InvalidKeyException | IllegalBlockSizeException | BadPaddingException | NoSuchPaddingException | NoSuchAlgorithmException e) { logger.error(e); }