From c6559631a23a92c60b75f9ee07e9b9f06dc2dcd3 Mon Sep 17 00:00:00 2001 From: Gert-Jan van der Heiden Date: Wed, 23 Dec 2020 18:09:17 +0100 Subject: [PATCH 01/25] [#130](https://github.com/hap-java/HAP-Java/pull/130) --- CHANGES.md | 1 + pom.xml | 14 ++++---------- .../hapjava/server/impl/HomekitUtils.java | 2 +- .../server/impl/crypto/ChachaDecoder.java | 8 ++------ .../server/impl/crypto/ChachaEncoder.java | 4 +--- .../hapjava/server/impl/pairing/ByteUtils.java | 2 +- .../impl/pairing/ClientEvidenceRoutineImpl.java | 4 +--- .../impl/pairing/HomekitSRP6ServerSession.java | 17 ++++++++++------- .../hapjava/server/impl/pairing/SrpHandler.java | 4 ++-- .../impl/pairing/TypeLengthValueUtils.java | 2 +- 10 files changed, 24 insertions(+), 34 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 758ddf6f7..cfa0188e1 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -14,6 +14,7 @@ * Valid values are supported for enum characteristics instead of min and max values * Supported valid states for Thermostat, SecuritySystem, HeaterCooler and HumidifierDehumidifier [#108] [#120](https://github.com/hap-java/HAP-Java/pull/120) * Support for FilterMaintenance. Can be used as a linked service for an Air Purifier [#124](https://github.com/hap-java/HAP-Java/pull/124) +* Update crypto libs [#130](https://github.com/hap-java/HAP-Java/pull/130) # HAP-Java 1.1.5 diff --git a/pom.xml b/pom.xml index 5faf6eafc..5ffbd9609 100644 --- a/pom.xml +++ b/pom.xml @@ -100,13 +100,13 @@ com.nimbusds srp6a - 1.5.2 + 2.1.0 org.bouncycastle bcprov-jdk15on - 1.51 + 1.67 @@ -115,22 +115,16 @@ 1.0.1 - - org.zeromq - curve25519-java - 0.1.0 - - javax.json javax.json-api - 1.0 + 1.1.4 org.glassfish javax.json - 1.0.4 + 1.1.4 diff --git a/src/main/java/io/github/hapjava/server/impl/HomekitUtils.java b/src/main/java/io/github/hapjava/server/impl/HomekitUtils.java index 9b5b2b8ee..9facbeb0b 100644 --- a/src/main/java/io/github/hapjava/server/impl/HomekitUtils.java +++ b/src/main/java/io/github/hapjava/server/impl/HomekitUtils.java @@ -14,7 +14,7 @@ public class HomekitUtils { private static volatile SecureRandom secureRandom; public static BigInteger generateSalt() { - return new BigInteger(SRP6Routines.generateRandomSalt(16)); + return new BigInteger(new SRP6Routines().generateRandomSalt(16)); } public static byte[] generateKey() throws InvalidAlgorithmParameterException { diff --git a/src/main/java/io/github/hapjava/server/impl/crypto/ChachaDecoder.java b/src/main/java/io/github/hapjava/server/impl/crypto/ChachaDecoder.java index 4c74a469d..9b9c2cc5d 100644 --- a/src/main/java/io/github/hapjava/server/impl/crypto/ChachaDecoder.java +++ b/src/main/java/io/github/hapjava/server/impl/crypto/ChachaDecoder.java @@ -5,8 +5,6 @@ import org.bouncycastle.crypto.generators.Poly1305KeyGenerator; import org.bouncycastle.crypto.params.KeyParameter; import org.bouncycastle.crypto.params.ParametersWithIV; -import org.bouncycastle.crypto.tls.AlertDescription; -import org.bouncycastle.crypto.tls.TlsFatalAlert; import org.bouncycastle.util.Arrays; public class ChachaDecoder { @@ -28,7 +26,7 @@ public byte[] decodeCiphertext(byte[] receivedMAC, byte[] additionalData, byte[] byte[] calculatedMAC = PolyKeyCreator.create(macKey, additionalData, ciphertext); if (!Arrays.constantTimeAreEqual(calculatedMAC, receivedMAC)) { - throw new TlsFatalAlert(AlertDescription.bad_record_mac); + throw new IOException("received an incorrect MAC"); } byte[] output = new byte[ciphertext.length]; @@ -45,9 +43,7 @@ private KeyParameter initRecordMAC(ChaChaEngine cipher) { byte[] firstBlock = new byte[64]; cipher.processBytes(firstBlock, 0, firstBlock.length, firstBlock, 0); - // NOTE: The BC implementation puts 'r' after 'k' - System.arraycopy(firstBlock, 0, firstBlock, 32, 16); - KeyParameter macKey = new KeyParameter(firstBlock, 16, 32); + KeyParameter macKey = new KeyParameter(firstBlock, 0, 32); Poly1305KeyGenerator.clamp(macKey.getKey()); return macKey; } diff --git a/src/main/java/io/github/hapjava/server/impl/crypto/ChachaEncoder.java b/src/main/java/io/github/hapjava/server/impl/crypto/ChachaEncoder.java index 3304e7d9a..3649844eb 100644 --- a/src/main/java/io/github/hapjava/server/impl/crypto/ChachaEncoder.java +++ b/src/main/java/io/github/hapjava/server/impl/crypto/ChachaEncoder.java @@ -39,9 +39,7 @@ private KeyParameter initRecordMAC(ChaChaEngine cipher) { byte[] firstBlock = new byte[64]; cipher.processBytes(firstBlock, 0, firstBlock.length, firstBlock, 0); - // NOTE: The BC implementation puts 'r' after 'k' - System.arraycopy(firstBlock, 0, firstBlock, 32, 16); - KeyParameter macKey = new KeyParameter(firstBlock, 16, 32); + KeyParameter macKey = new KeyParameter(firstBlock, 0, 32); Poly1305KeyGenerator.clamp(macKey.getKey()); return macKey; } diff --git a/src/main/java/io/github/hapjava/server/impl/pairing/ByteUtils.java b/src/main/java/io/github/hapjava/server/impl/pairing/ByteUtils.java index 6516e2e29..e65beec3c 100644 --- a/src/main/java/io/github/hapjava/server/impl/pairing/ByteUtils.java +++ b/src/main/java/io/github/hapjava/server/impl/pairing/ByteUtils.java @@ -22,7 +22,7 @@ public static byte[] joinBytes(byte[]... piece) { return ret; } - public static byte[] toByteArray(BigInteger i) { + public static byte[] toUnsignedByteArray(BigInteger i) { byte[] array = i.toByteArray(); if (array[0] == 0) { array = Arrays.copyOfRange(array, 1, array.length); diff --git a/src/main/java/io/github/hapjava/server/impl/pairing/ClientEvidenceRoutineImpl.java b/src/main/java/io/github/hapjava/server/impl/pairing/ClientEvidenceRoutineImpl.java index 16c514707..0d55985f9 100644 --- a/src/main/java/io/github/hapjava/server/impl/pairing/ClientEvidenceRoutineImpl.java +++ b/src/main/java/io/github/hapjava/server/impl/pairing/ClientEvidenceRoutineImpl.java @@ -8,9 +8,7 @@ class ClientEvidenceRoutineImpl implements ClientEvidenceRoutine { - public ClientEvidenceRoutineImpl() { - // TODO Auto-generated constructor stub - } + public ClientEvidenceRoutineImpl() {} /** * Calculates M1 according to the following formula: diff --git a/src/main/java/io/github/hapjava/server/impl/pairing/HomekitSRP6ServerSession.java b/src/main/java/io/github/hapjava/server/impl/pairing/HomekitSRP6ServerSession.java index 3841d9fb7..116fced13 100644 --- a/src/main/java/io/github/hapjava/server/impl/pairing/HomekitSRP6ServerSession.java +++ b/src/main/java/io/github/hapjava/server/impl/pairing/HomekitSRP6ServerSession.java @@ -8,6 +8,7 @@ import com.nimbusds.srp6.SRP6Session; import com.nimbusds.srp6.URoutineContext; import java.math.BigInteger; +import java.security.MessageDigest; /** * This is a slightly modified version of the SRP6ServerSession class included with nimbus. The only @@ -74,6 +75,8 @@ public static enum State { /** The current SRP-6a auth state. */ private State state; + private MessageDigest digest; + /** * Creates a new server-side SRP-6a authentication session and sets its state to {@link * State#INIT}. @@ -92,7 +95,7 @@ public HomekitSRP6ServerSession(final SRP6CryptoParams config, final int timeout this.config = config; - digest = config.getMessageDigestInstance(); + this.digest = config.getMessageDigestInstance(); if (digest == null) throw new IllegalArgumentException("Unsupported hash algorithm 'H': " + config.H); @@ -151,13 +154,13 @@ public BigInteger step1(final String userID, final BigInteger s, final BigIntege throw new IllegalStateException("State violation: Session must be in INIT state"); // Generate server private and public values - k = SRP6Routines.computeK(digest, config.N, config.g); + k = new SRP6Routines().computeK(digest, config.N, config.g); digest.reset(); b = HomekitSRP6Routines.generatePrivateValue(config.N, random); digest.reset(); - B = SRP6Routines.computePublicServerValue(config.N, config.g, k, v, b); + B = new SRP6Routines().computePublicServerValue(config.N, config.g, k, v, b); state = State.STEP_1; @@ -234,7 +237,7 @@ public BigInteger step2(final BigInteger A, final BigInteger M1) throws SRP6Exce if (hasTimedOut()) throw new SRP6Exception("Session timeout", SRP6Exception.CauseType.TIMEOUT); // Check A validity - if (!SRP6Routines.isValidPublicValue(config.N, A)) + if (!new SRP6Routines().isValidPublicValue(config.N, A)) throw new SRP6Exception( "Bad client public value 'A'", SRP6Exception.CauseType.BAD_PUBLIC_VALUE); @@ -246,11 +249,11 @@ public BigInteger step2(final BigInteger A, final BigInteger M1) throws SRP6Exce URoutineContext hashedKeysContext = new URoutineContext(A, B); u = hashedKeysRoutine.computeU(config, hashedKeysContext); } else { - u = SRP6Routines.computeU(digest, config.N, A, B); + u = new SRP6Routines().computeU(digest, config.N, A, B); digest.reset(); } - S = SRP6Routines.computeSessionKey(config.N, v, u, A, b); + S = new SRP6Routines().computeSessionKey(config.N, v, u, A, b); // Compute the own client evidence message 'M1' BigInteger computedM1; @@ -262,7 +265,7 @@ public BigInteger step2(final BigInteger A, final BigInteger M1) throws SRP6Exce computedM1 = clientEvidenceRoutine.computeClientEvidence(config, ctx); } else { // With default routine - computedM1 = SRP6Routines.computeClientEvidence(digest, A, B, S); + computedM1 = new SRP6Routines().computeClientEvidence(digest, A, B, S); digest.reset(); } diff --git a/src/main/java/io/github/hapjava/server/impl/pairing/SrpHandler.java b/src/main/java/io/github/hapjava/server/impl/pairing/SrpHandler.java index e02ccdb90..8d26d62dc 100644 --- a/src/main/java/io/github/hapjava/server/impl/pairing/SrpHandler.java +++ b/src/main/java/io/github/hapjava/server/impl/pairing/SrpHandler.java @@ -82,8 +82,8 @@ private HttpResponse step2(Stage2Request request) throws Exception { public byte[] getK() { MessageDigest digest = session.getCryptoParams().getMessageDigestInstance(); - BigInteger S = session.getSessionKey(false); - byte[] sBytes = bigIntegerToUnsignedByteArray(S); + BigInteger S = session.getSessionKey(); + byte[] sBytes = toUnsignedByteArray(S); return digest.digest(sBytes); } diff --git a/src/main/java/io/github/hapjava/server/impl/pairing/TypeLengthValueUtils.java b/src/main/java/io/github/hapjava/server/impl/pairing/TypeLengthValueUtils.java index 396829d34..03665d94d 100644 --- a/src/main/java/io/github/hapjava/server/impl/pairing/TypeLengthValueUtils.java +++ b/src/main/java/io/github/hapjava/server/impl/pairing/TypeLengthValueUtils.java @@ -38,7 +38,7 @@ private Encoder() { } public void add(MessageType type, BigInteger i) throws IOException { - add(type, ByteUtils.toByteArray(i)); + add(type, ByteUtils.toUnsignedByteArray(i)); } public void add(MessageType type, short b) { From 1061cbe7dc4514d35a343f3e7b7f4efecda5cbc0 Mon Sep 17 00:00:00 2001 From: Gert-Jan van der Heiden Date: Wed, 23 Dec 2020 18:16:34 +0100 Subject: [PATCH 02/25] #130(https://github.com/hap-java/HAP-Java/pull/130) --- pom.xml | 2 +- .../hapjava/server/impl/HomekitUtils.java | 6 +-- .../pairing/ClientEvidenceRoutineImpl.java | 14 ++++--- .../server/impl/pairing/PairingManager.java | 4 +- .../pairing/ServerEvidenceRoutineImpl.java | 8 ++-- .../server/impl/pairing/SrpHandler.java | 40 ++++--------------- 6 files changed, 27 insertions(+), 47 deletions(-) diff --git a/pom.xml b/pom.xml index 5ffbd9609..d4f47b432 100644 --- a/pom.xml +++ b/pom.xml @@ -112,7 +112,7 @@ net.vrallev.ecc ecc-25519-java - 1.0.1 + 1.0.3 diff --git a/src/main/java/io/github/hapjava/server/impl/HomekitUtils.java b/src/main/java/io/github/hapjava/server/impl/HomekitUtils.java index 9facbeb0b..20a697ff9 100644 --- a/src/main/java/io/github/hapjava/server/impl/HomekitUtils.java +++ b/src/main/java/io/github/hapjava/server/impl/HomekitUtils.java @@ -2,7 +2,6 @@ import com.nimbusds.srp6.SRP6Routines; import java.math.BigInteger; -import java.security.InvalidAlgorithmParameterException; import java.security.SecureRandom; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -17,8 +16,9 @@ public static BigInteger generateSalt() { return new BigInteger(new SRP6Routines().generateRandomSalt(16)); } - public static byte[] generateKey() throws InvalidAlgorithmParameterException { - EdDSAParameterSpec spec = EdDSANamedCurveTable.getByName("ed25519-sha-512"); + public static byte[] generateKey() { + EdDSAParameterSpec spec = + EdDSANamedCurveTable.getByName(EdDSANamedCurveTable.CURVE_ED25519_SHA512); byte[] seed = new byte[spec.getCurve().getField().getb() / 8]; getSecureRandom().nextBytes(seed); return seed; diff --git a/src/main/java/io/github/hapjava/server/impl/pairing/ClientEvidenceRoutineImpl.java b/src/main/java/io/github/hapjava/server/impl/pairing/ClientEvidenceRoutineImpl.java index 0d55985f9..7e139296c 100644 --- a/src/main/java/io/github/hapjava/server/impl/pairing/ClientEvidenceRoutineImpl.java +++ b/src/main/java/io/github/hapjava/server/impl/pairing/ClientEvidenceRoutineImpl.java @@ -1,5 +1,7 @@ package io.github.hapjava.server.impl.pairing; +import static io.github.hapjava.server.impl.pairing.ByteUtils.toUnsignedByteArray; + import com.nimbusds.srp6.*; import java.math.BigInteger; import java.nio.charset.StandardCharsets; @@ -25,10 +27,10 @@ public BigInteger computeClientEvidence( } catch (NoSuchAlgorithmException e) { throw new RuntimeException("Could not locate requested algorithm", e); } - digest.update(SrpHandler.bigIntegerToUnsignedByteArray(cryptoParams.N)); + digest.update(toUnsignedByteArray(cryptoParams.N)); byte[] hN = digest.digest(); - digest.update(SrpHandler.bigIntegerToUnsignedByteArray(cryptoParams.g)); + digest.update(toUnsignedByteArray(cryptoParams.g)); byte[] hg = digest.digest(); byte[] hNhg = xor(hN, hg); @@ -36,14 +38,14 @@ public BigInteger computeClientEvidence( digest.update(ctx.userID.getBytes(StandardCharsets.UTF_8)); byte[] hu = digest.digest(); - digest.update(SrpHandler.bigIntegerToUnsignedByteArray(ctx.S)); + digest.update(toUnsignedByteArray(ctx.S)); byte[] hS = digest.digest(); digest.update(hNhg); digest.update(hu); - digest.update(SrpHandler.bigIntegerToUnsignedByteArray(ctx.s)); - digest.update(SrpHandler.bigIntegerToUnsignedByteArray(ctx.A)); - digest.update(SrpHandler.bigIntegerToUnsignedByteArray(ctx.B)); + digest.update(toUnsignedByteArray(ctx.s)); + digest.update(toUnsignedByteArray(ctx.A)); + digest.update(toUnsignedByteArray(ctx.B)); digest.update(hS); BigInteger ret = new BigInteger(1, digest.digest()); return ret; diff --git a/src/main/java/io/github/hapjava/server/impl/pairing/PairingManager.java b/src/main/java/io/github/hapjava/server/impl/pairing/PairingManager.java index af6a6e01f..ee4b772f9 100644 --- a/src/main/java/io/github/hapjava/server/impl/pairing/PairingManager.java +++ b/src/main/java/io/github/hapjava/server/impl/pairing/PairingManager.java @@ -29,7 +29,7 @@ public HttpResponse handle(HttpRequest httpRequest) throws Exception { if (req.getStage() == Stage.ONE) { logger.trace("Starting pair for " + registry.getLabel()); srpHandler = new SrpHandler(authInfo.getPin(), authInfo.getSalt()); - return srpHandler.handle(req); + return srpHandler.step1(); } else if (req.getStage() == Stage.TWO) { logger.trace("Entering second stage of pair for " + registry.getLabel()); if (srpHandler == null) { @@ -37,7 +37,7 @@ public HttpResponse handle(HttpRequest httpRequest) throws Exception { return new UnauthorizedResponse(); } else { try { - return srpHandler.handle(req); + return srpHandler.step2((PairSetupRequest.Stage2Request) req); } catch (Exception e) { srpHandler = null; // You don't get to try again - need a new key logger.warn("Exception encountered while processing pairing request", e); diff --git a/src/main/java/io/github/hapjava/server/impl/pairing/ServerEvidenceRoutineImpl.java b/src/main/java/io/github/hapjava/server/impl/pairing/ServerEvidenceRoutineImpl.java index 7cf7b3164..77739e9b2 100644 --- a/src/main/java/io/github/hapjava/server/impl/pairing/ServerEvidenceRoutineImpl.java +++ b/src/main/java/io/github/hapjava/server/impl/pairing/ServerEvidenceRoutineImpl.java @@ -1,5 +1,7 @@ package io.github.hapjava.server.impl.pairing; +import static io.github.hapjava.server.impl.pairing.ByteUtils.toUnsignedByteArray; + import com.nimbusds.srp6.SRP6CryptoParams; import com.nimbusds.srp6.SRP6ServerEvidenceContext; import com.nimbusds.srp6.ServerEvidenceRoutine; @@ -20,10 +22,10 @@ public BigInteger computeServerEvidence( throw new RuntimeException("Could not locate requested algorithm", e); } - byte[] hS = digest.digest(SrpHandler.bigIntegerToUnsignedByteArray(ctx.S)); + byte[] hS = digest.digest(toUnsignedByteArray(ctx.S)); - digest.update(SrpHandler.bigIntegerToUnsignedByteArray(ctx.A)); - digest.update(SrpHandler.bigIntegerToUnsignedByteArray(ctx.M1)); + digest.update(toUnsignedByteArray(ctx.A)); + digest.update(toUnsignedByteArray(ctx.M1)); digest.update(hS); return new BigInteger(1, digest.digest()); diff --git a/src/main/java/io/github/hapjava/server/impl/pairing/SrpHandler.java b/src/main/java/io/github/hapjava/server/impl/pairing/SrpHandler.java index 8d26d62dc..ec4b34c97 100644 --- a/src/main/java/io/github/hapjava/server/impl/pairing/SrpHandler.java +++ b/src/main/java/io/github/hapjava/server/impl/pairing/SrpHandler.java @@ -1,25 +1,22 @@ package io.github.hapjava.server.impl.pairing; +import static io.github.hapjava.server.impl.pairing.ByteUtils.toUnsignedByteArray; + import com.nimbusds.srp6.*; import io.github.hapjava.server.impl.http.HttpResponse; import io.github.hapjava.server.impl.pairing.HomekitSRP6ServerSession.State; import io.github.hapjava.server.impl.pairing.PairSetupRequest.Stage2Request; import io.github.hapjava.server.impl.pairing.TypeLengthValueUtils.Encoder; import io.github.hapjava.server.impl.responses.ConflictResponse; -import io.github.hapjava.server.impl.responses.NotFoundResponse; import java.math.BigInteger; import java.security.MessageDigest; -import java.util.Arrays; import org.slf4j.Logger; import org.slf4j.LoggerFactory; class SrpHandler { - // Precomputed safe 3072 bit prime 'N'. Origin RFC 5054, appendix A. - private static final BigInteger N_3072 = - new BigInteger( - "5809605995369958062791915965639201402176612226902900533702900882779736177890990861472094774477339581147373410185646378328043729800750470098210924487866935059164371588168047540943981644516632755067501626434556398193186628990071248660819361205119793693985433297036118232914410171876807536457391277857011849897410207519105333355801121109356897459426271845471397952675959440793493071628394122780510124618488232602464649876850458861245784240929258426287699705312584509625419513463605155428017165714465363094021609290561084025893662561222573202082865797821865270991145082200656978177192827024538990239969175546190770645685893438011714430426409338676314743571154537142031573004276428701433036381801705308659830751190352946025482059931306571004727362479688415574702596946457770284148435989129632853918392117997472632693078113129886487399347796982772784615865232621289656944284216824611318709764535152507354116344703769998514148343807"); - private static final BigInteger G = BigInteger.valueOf(5); + private static final int BIT_SIZE = 3072; + private static final String HASH_ALG_H = "SHA-512"; private static final String IDENTIFIER = "Pair-Setup"; private static final Logger logger = LoggerFactory.getLogger(SrpHandler.class); @@ -30,7 +27,7 @@ class SrpHandler { private final String pin; public SrpHandler(String pin, BigInteger salt) { - config = new SRP6CryptoParams(N_3072, G, "SHA-512"); + config = SRP6CryptoParams.getInstance(BIT_SIZE, HASH_ALG_H); session = new HomekitSRP6ServerSession(config); session.setClientEvidenceRoutine(new ClientEvidenceRoutineImpl()); session.setServerEvidenceRoutine(new ServerEvidenceRoutineImpl()); @@ -38,20 +35,7 @@ public SrpHandler(String pin, BigInteger salt) { this.salt = salt; } - public HttpResponse handle(PairSetupRequest request) throws Exception { - switch (request.getStage()) { - case ONE: - return step1(); - - case TWO: - return step2((Stage2Request) request); - - default: - return new NotFoundResponse(); - } - } - - private HttpResponse step1() throws Exception { + HttpResponse step1() throws Exception { if (session.getState() != State.INIT) { logger.warn("Session is not in state INIT when receiving step1"); return new ConflictResponse(); @@ -68,7 +52,7 @@ private HttpResponse step1() throws Exception { return new PairingResponse(encoder.toByteArray()); } - private HttpResponse step2(Stage2Request request) throws Exception { + HttpResponse step2(Stage2Request request) throws Exception { if (session.getState() != State.STEP_1) { logger.warn("Session is not in state Stage 1 when receiving step2"); return new ConflictResponse(); @@ -80,18 +64,10 @@ private HttpResponse step2(Stage2Request request) throws Exception { return new PairingResponse(encoder.toByteArray()); } - public byte[] getK() { + byte[] getK() { MessageDigest digest = session.getCryptoParams().getMessageDigestInstance(); BigInteger S = session.getSessionKey(); byte[] sBytes = toUnsignedByteArray(S); return digest.digest(sBytes); } - - public static byte[] bigIntegerToUnsignedByteArray(BigInteger i) { - byte[] array = i.toByteArray(); - if (array[0] == 0) { - array = Arrays.copyOfRange(array, 1, array.length); - } - return array; - } } From 2a5629b3c92e48cdc83fa4eadb66fc8e307c33de Mon Sep 17 00:00:00 2001 From: Ben Swanson Date: Fri, 5 Feb 2021 08:55:30 +0000 Subject: [PATCH 03/25] Fix for Chacha and change to BigIntegerUtils.bigIntegerToBytes --- .../hapjava/server/impl/crypto/ChachaDecoder.java | 4 +++- .../hapjava/server/impl/crypto/ChachaEncoder.java | 4 +++- .../impl/pairing/ClientEvidenceRoutineImpl.java | 14 ++++++-------- .../impl/pairing/ServerEvidenceRoutineImpl.java | 9 ++++----- .../hapjava/server/impl/pairing/SrpHandler.java | 4 +--- .../server/impl/pairing/TypeLengthValueUtils.java | 3 ++- 6 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/main/java/io/github/hapjava/server/impl/crypto/ChachaDecoder.java b/src/main/java/io/github/hapjava/server/impl/crypto/ChachaDecoder.java index 9b9c2cc5d..d616d2e0f 100644 --- a/src/main/java/io/github/hapjava/server/impl/crypto/ChachaDecoder.java +++ b/src/main/java/io/github/hapjava/server/impl/crypto/ChachaDecoder.java @@ -43,7 +43,9 @@ private KeyParameter initRecordMAC(ChaChaEngine cipher) { byte[] firstBlock = new byte[64]; cipher.processBytes(firstBlock, 0, firstBlock.length, firstBlock, 0); - KeyParameter macKey = new KeyParameter(firstBlock, 0, 32); + // NOTE: The BC implementation puts 'r' after 'k' + System.arraycopy(firstBlock, 0, firstBlock, 32, 16); + KeyParameter macKey = new KeyParameter(firstBlock, 16, 32); Poly1305KeyGenerator.clamp(macKey.getKey()); return macKey; } diff --git a/src/main/java/io/github/hapjava/server/impl/crypto/ChachaEncoder.java b/src/main/java/io/github/hapjava/server/impl/crypto/ChachaEncoder.java index 3649844eb..3304e7d9a 100644 --- a/src/main/java/io/github/hapjava/server/impl/crypto/ChachaEncoder.java +++ b/src/main/java/io/github/hapjava/server/impl/crypto/ChachaEncoder.java @@ -39,7 +39,9 @@ private KeyParameter initRecordMAC(ChaChaEngine cipher) { byte[] firstBlock = new byte[64]; cipher.processBytes(firstBlock, 0, firstBlock.length, firstBlock, 0); - KeyParameter macKey = new KeyParameter(firstBlock, 0, 32); + // NOTE: The BC implementation puts 'r' after 'k' + System.arraycopy(firstBlock, 0, firstBlock, 32, 16); + KeyParameter macKey = new KeyParameter(firstBlock, 16, 32); Poly1305KeyGenerator.clamp(macKey.getKey()); return macKey; } diff --git a/src/main/java/io/github/hapjava/server/impl/pairing/ClientEvidenceRoutineImpl.java b/src/main/java/io/github/hapjava/server/impl/pairing/ClientEvidenceRoutineImpl.java index 7e139296c..87ddf3907 100644 --- a/src/main/java/io/github/hapjava/server/impl/pairing/ClientEvidenceRoutineImpl.java +++ b/src/main/java/io/github/hapjava/server/impl/pairing/ClientEvidenceRoutineImpl.java @@ -1,7 +1,5 @@ package io.github.hapjava.server.impl.pairing; -import static io.github.hapjava.server.impl.pairing.ByteUtils.toUnsignedByteArray; - import com.nimbusds.srp6.*; import java.math.BigInteger; import java.nio.charset.StandardCharsets; @@ -27,10 +25,10 @@ public BigInteger computeClientEvidence( } catch (NoSuchAlgorithmException e) { throw new RuntimeException("Could not locate requested algorithm", e); } - digest.update(toUnsignedByteArray(cryptoParams.N)); + digest.update(BigIntegerUtils.bigIntegerToBytes(cryptoParams.N)); byte[] hN = digest.digest(); - digest.update(toUnsignedByteArray(cryptoParams.g)); + digest.update(BigIntegerUtils.bigIntegerToBytes(cryptoParams.g)); byte[] hg = digest.digest(); byte[] hNhg = xor(hN, hg); @@ -38,14 +36,14 @@ public BigInteger computeClientEvidence( digest.update(ctx.userID.getBytes(StandardCharsets.UTF_8)); byte[] hu = digest.digest(); - digest.update(toUnsignedByteArray(ctx.S)); + digest.update(BigIntegerUtils.bigIntegerToBytes(ctx.S)); byte[] hS = digest.digest(); digest.update(hNhg); digest.update(hu); - digest.update(toUnsignedByteArray(ctx.s)); - digest.update(toUnsignedByteArray(ctx.A)); - digest.update(toUnsignedByteArray(ctx.B)); + digest.update(BigIntegerUtils.bigIntegerToBytes(ctx.s)); + digest.update(BigIntegerUtils.bigIntegerToBytes(ctx.A)); + digest.update(BigIntegerUtils.bigIntegerToBytes(ctx.B)); digest.update(hS); BigInteger ret = new BigInteger(1, digest.digest()); return ret; diff --git a/src/main/java/io/github/hapjava/server/impl/pairing/ServerEvidenceRoutineImpl.java b/src/main/java/io/github/hapjava/server/impl/pairing/ServerEvidenceRoutineImpl.java index 77739e9b2..6c032ce59 100644 --- a/src/main/java/io/github/hapjava/server/impl/pairing/ServerEvidenceRoutineImpl.java +++ b/src/main/java/io/github/hapjava/server/impl/pairing/ServerEvidenceRoutineImpl.java @@ -1,7 +1,6 @@ package io.github.hapjava.server.impl.pairing; -import static io.github.hapjava.server.impl.pairing.ByteUtils.toUnsignedByteArray; - +import com.nimbusds.srp6.BigIntegerUtils; import com.nimbusds.srp6.SRP6CryptoParams; import com.nimbusds.srp6.SRP6ServerEvidenceContext; import com.nimbusds.srp6.ServerEvidenceRoutine; @@ -22,10 +21,10 @@ public BigInteger computeServerEvidence( throw new RuntimeException("Could not locate requested algorithm", e); } - byte[] hS = digest.digest(toUnsignedByteArray(ctx.S)); + byte[] hS = digest.digest(BigIntegerUtils.bigIntegerToBytes(ctx.S)); - digest.update(toUnsignedByteArray(ctx.A)); - digest.update(toUnsignedByteArray(ctx.M1)); + digest.update(BigIntegerUtils.bigIntegerToBytes(ctx.A)); + digest.update(BigIntegerUtils.bigIntegerToBytes(ctx.M1)); digest.update(hS); return new BigInteger(1, digest.digest()); diff --git a/src/main/java/io/github/hapjava/server/impl/pairing/SrpHandler.java b/src/main/java/io/github/hapjava/server/impl/pairing/SrpHandler.java index ec4b34c97..92d2098fa 100644 --- a/src/main/java/io/github/hapjava/server/impl/pairing/SrpHandler.java +++ b/src/main/java/io/github/hapjava/server/impl/pairing/SrpHandler.java @@ -1,7 +1,5 @@ package io.github.hapjava.server.impl.pairing; -import static io.github.hapjava.server.impl.pairing.ByteUtils.toUnsignedByteArray; - import com.nimbusds.srp6.*; import io.github.hapjava.server.impl.http.HttpResponse; import io.github.hapjava.server.impl.pairing.HomekitSRP6ServerSession.State; @@ -67,7 +65,7 @@ HttpResponse step2(Stage2Request request) throws Exception { byte[] getK() { MessageDigest digest = session.getCryptoParams().getMessageDigestInstance(); BigInteger S = session.getSessionKey(); - byte[] sBytes = toUnsignedByteArray(S); + byte[] sBytes = BigIntegerUtils.bigIntegerToBytes(S); return digest.digest(sBytes); } } diff --git a/src/main/java/io/github/hapjava/server/impl/pairing/TypeLengthValueUtils.java b/src/main/java/io/github/hapjava/server/impl/pairing/TypeLengthValueUtils.java index 03665d94d..bf76f53fb 100644 --- a/src/main/java/io/github/hapjava/server/impl/pairing/TypeLengthValueUtils.java +++ b/src/main/java/io/github/hapjava/server/impl/pairing/TypeLengthValueUtils.java @@ -1,5 +1,6 @@ package io.github.hapjava.server.impl.pairing; +import com.nimbusds.srp6.BigIntegerUtils; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -38,7 +39,7 @@ private Encoder() { } public void add(MessageType type, BigInteger i) throws IOException { - add(type, ByteUtils.toUnsignedByteArray(i)); + add(type, BigIntegerUtils.bigIntegerToBytes(i)); } public void add(MessageType type, short b) { From d5aafb06fe80f84cc8d49e54b38569a265836134 Mon Sep 17 00:00:00 2001 From: Ben Swanson Date: Fri, 5 Feb 2021 14:14:07 +0000 Subject: [PATCH 04/25] Always provide a response even if the user doesn't exist --- .../server/impl/pairing/PairVerificationManager.java | 9 +++++---- .../server/impl/pairing/PairingUpdateController.java | 2 ++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/main/java/io/github/hapjava/server/impl/pairing/PairVerificationManager.java b/src/main/java/io/github/hapjava/server/impl/pairing/PairVerificationManager.java index d43b2d210..333fb783b 100644 --- a/src/main/java/io/github/hapjava/server/impl/pairing/PairVerificationManager.java +++ b/src/main/java/io/github/hapjava/server/impl/pairing/PairVerificationManager.java @@ -109,20 +109,21 @@ private HttpResponse stage2(Stage2Request request) throws Exception { byte[] clientLtpk = authInfo.getUserPublicKey( authInfo.getMac() + new String(clientUsername, StandardCharsets.UTF_8)); + + Encoder encoder = TypeLengthValueUtils.getEncoder(); + encoder.add(MessageType.STATE, (short) 4); if (clientLtpk == null) { - throw new Exception("Unknown user: " + new String(clientUsername, StandardCharsets.UTF_8)); + logger.error("Unknown user: {}", new String(clientUsername, StandardCharsets.UTF_8)); + return new OkResponse(encoder.toByteArray()); } - Encoder encoder = TypeLengthValueUtils.getEncoder(); if (new EdsaVerifier(clientLtpk).verify(material, clientSignature)) { - encoder.add(MessageType.STATE, (short) 4); logger.trace("Completed pair verification for " + registry.getLabel()); return new UpgradeResponse( encoder.toByteArray(), createKey("Control-Write-Encryption-Key"), createKey("Control-Read-Encryption-Key")); } else { - encoder.add(MessageType.ERROR, (short) 4); logger.warn("Invalid signature. Could not pair " + registry.getLabel()); return new OkResponse(encoder.toByteArray()); } diff --git a/src/main/java/io/github/hapjava/server/impl/pairing/PairingUpdateController.java b/src/main/java/io/github/hapjava/server/impl/pairing/PairingUpdateController.java index 3d52fe907..9ae983d5b 100644 --- a/src/main/java/io/github/hapjava/server/impl/pairing/PairingUpdateController.java +++ b/src/main/java/io/github/hapjava/server/impl/pairing/PairingUpdateController.java @@ -32,6 +32,8 @@ public HttpResponse handle(HttpRequest request) throws IOException { if (!authInfo.hasUser()) { advertiser.setDiscoverable(true); } + // } else if (method == 5) { // List pairing + } else { throw new RuntimeException("Unrecognized method: " + method); } From ca1106803d4b216cdc35580f9c1ad6930b36cbd6 Mon Sep 17 00:00:00 2001 From: Ben Swanson Date: Fri, 5 Feb 2021 14:16:04 +0000 Subject: [PATCH 05/25] Allow access to registry --- pom.xml | 2 +- src/main/java/io/github/hapjava/server/impl/HomekitRoot.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 5faf6eafc..67fd91e30 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ hap hap-java Homekit Accessory Protocol for Java - 2.0.0-snapshot + 2.0.1-rako jar https://github.com/hap-java/HAP-Java diff --git a/src/main/java/io/github/hapjava/server/impl/HomekitRoot.java b/src/main/java/io/github/hapjava/server/impl/HomekitRoot.java index fba9d7b7b..49ae211f0 100644 --- a/src/main/java/io/github/hapjava/server/impl/HomekitRoot.java +++ b/src/main/java/io/github/hapjava/server/impl/HomekitRoot.java @@ -178,7 +178,7 @@ public void setConfigurationIndex(int revision) throws IOException { } } - HomekitRegistry getRegistry() { + public HomekitRegistry getRegistry() { return registry; } } From 59295cd58f61a80ec8d7c4ad39cabda8211fed36 Mon Sep 17 00:00:00 2001 From: Ben Swanson Date: Wed, 7 Apr 2021 12:10:06 +0100 Subject: [PATCH 06/25] Update multiple Characteristics type to percentage --- .../impl/battery/BatteryLevelCharacteristic.java | 2 +- .../impl/common/ServiceLabelIndexCharacteristic.java | 2 +- .../characteristics/impl/common/WaterLavelCharacteristic.java | 2 +- .../characteristics/impl/fan/RotationSpeedCharacteristic.java | 2 +- .../impl/filtermaintenance/FilterLifeLevelCharacteristic.java | 2 +- .../humidifier/HumidityDehumidifierThresholdCharacteristic.java | 2 +- .../humidifier/HumidityHumidifierThresholdCharacteristic.java | 2 +- .../humiditysensor/CurrentRelativeHumidityCharacteristic.java | 2 +- .../humiditysensor/TargetRelativeHumidityCharacteristic.java | 2 +- .../impl/lightbulb/BrightnessCharacteristic.java | 2 +- .../impl/lightbulb/SaturationCharacteristic.java | 2 +- .../impl/windowcovering/CurrentPositionCharacteristic.java | 2 +- .../impl/windowcovering/TargetPositionCharacteristic.java | 2 +- 13 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/main/java/io/github/hapjava/characteristics/impl/battery/BatteryLevelCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/battery/BatteryLevelCharacteristic.java index 0fa56ff40..cb4f335a2 100644 --- a/src/main/java/io/github/hapjava/characteristics/impl/battery/BatteryLevelCharacteristic.java +++ b/src/main/java/io/github/hapjava/characteristics/impl/battery/BatteryLevelCharacteristic.java @@ -21,7 +21,7 @@ public BatteryLevelCharacteristic( "battery level", 0, 100, - "%", + "percentage", Optional.of(getter), Optional.empty(), Optional.of(subscriber), diff --git a/src/main/java/io/github/hapjava/characteristics/impl/common/ServiceLabelIndexCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/common/ServiceLabelIndexCharacteristic.java index 522cb04fe..955e032d5 100644 --- a/src/main/java/io/github/hapjava/characteristics/impl/common/ServiceLabelIndexCharacteristic.java +++ b/src/main/java/io/github/hapjava/characteristics/impl/common/ServiceLabelIndexCharacteristic.java @@ -19,7 +19,7 @@ public ServiceLabelIndexCharacteristic(Supplier> gett "service label index", 0, 100, - "%", + "percentage", Optional.of(getter), Optional.empty(), Optional.empty(), diff --git a/src/main/java/io/github/hapjava/characteristics/impl/common/WaterLavelCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/common/WaterLavelCharacteristic.java index dda11b087..121ac013e 100644 --- a/src/main/java/io/github/hapjava/characteristics/impl/common/WaterLavelCharacteristic.java +++ b/src/main/java/io/github/hapjava/characteristics/impl/common/WaterLavelCharacteristic.java @@ -22,7 +22,7 @@ public WaterLavelCharacteristic( 0, 100, 1, - "%", + "percentage", Optional.of(getter), Optional.empty(), Optional.of(subscriber), diff --git a/src/main/java/io/github/hapjava/characteristics/impl/fan/RotationSpeedCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/fan/RotationSpeedCharacteristic.java index 27c715530..239323d9b 100644 --- a/src/main/java/io/github/hapjava/characteristics/impl/fan/RotationSpeedCharacteristic.java +++ b/src/main/java/io/github/hapjava/characteristics/impl/fan/RotationSpeedCharacteristic.java @@ -23,7 +23,7 @@ public RotationSpeedCharacteristic( "Rotation Speed", 0, 100, - "%", + "percentage", Optional.of(getter), Optional.of(setter), Optional.of(subscriber), diff --git a/src/main/java/io/github/hapjava/characteristics/impl/filtermaintenance/FilterLifeLevelCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/filtermaintenance/FilterLifeLevelCharacteristic.java index 29cdf8d6e..0206a7193 100644 --- a/src/main/java/io/github/hapjava/characteristics/impl/filtermaintenance/FilterLifeLevelCharacteristic.java +++ b/src/main/java/io/github/hapjava/characteristics/impl/filtermaintenance/FilterLifeLevelCharacteristic.java @@ -21,7 +21,7 @@ public FilterLifeLevelCharacteristic( 0, 100, 1, - "%", + "percentage", Optional.of(getter), Optional.empty(), Optional.of(subscriber), diff --git a/src/main/java/io/github/hapjava/characteristics/impl/humidifier/HumidityDehumidifierThresholdCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/humidifier/HumidityDehumidifierThresholdCharacteristic.java index b8a4ca569..9839fb9fd 100644 --- a/src/main/java/io/github/hapjava/characteristics/impl/humidifier/HumidityDehumidifierThresholdCharacteristic.java +++ b/src/main/java/io/github/hapjava/characteristics/impl/humidifier/HumidityDehumidifierThresholdCharacteristic.java @@ -25,7 +25,7 @@ public HumidityDehumidifierThresholdCharacteristic( 0, 100, 1, - "%", + "percentage", Optional.of(getter), Optional.of(setter), Optional.of(subscriber), diff --git a/src/main/java/io/github/hapjava/characteristics/impl/humidifier/HumidityHumidifierThresholdCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/humidifier/HumidityHumidifierThresholdCharacteristic.java index 2ee8adbf2..40401352a 100644 --- a/src/main/java/io/github/hapjava/characteristics/impl/humidifier/HumidityHumidifierThresholdCharacteristic.java +++ b/src/main/java/io/github/hapjava/characteristics/impl/humidifier/HumidityHumidifierThresholdCharacteristic.java @@ -25,7 +25,7 @@ public HumidityHumidifierThresholdCharacteristic( 0, 100, 1, - "%", + "percentage", Optional.of(getter), Optional.of(setter), Optional.of(subscriber), diff --git a/src/main/java/io/github/hapjava/characteristics/impl/humiditysensor/CurrentRelativeHumidityCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/humiditysensor/CurrentRelativeHumidityCharacteristic.java index be77125b6..71466c424 100644 --- a/src/main/java/io/github/hapjava/characteristics/impl/humiditysensor/CurrentRelativeHumidityCharacteristic.java +++ b/src/main/java/io/github/hapjava/characteristics/impl/humiditysensor/CurrentRelativeHumidityCharacteristic.java @@ -20,7 +20,7 @@ public CurrentRelativeHumidityCharacteristic( 0, 100, 1, - "%", + "percentage", Optional.of(getter), Optional.empty(), Optional.of(subscriber), diff --git a/src/main/java/io/github/hapjava/characteristics/impl/humiditysensor/TargetRelativeHumidityCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/humiditysensor/TargetRelativeHumidityCharacteristic.java index ab8ad7e29..ad4f35858 100644 --- a/src/main/java/io/github/hapjava/characteristics/impl/humiditysensor/TargetRelativeHumidityCharacteristic.java +++ b/src/main/java/io/github/hapjava/characteristics/impl/humiditysensor/TargetRelativeHumidityCharacteristic.java @@ -22,7 +22,7 @@ public TargetRelativeHumidityCharacteristic( 0, 100, 1, - "%", + "percentage", Optional.of(getter), Optional.of(setter), Optional.of(subscriber), diff --git a/src/main/java/io/github/hapjava/characteristics/impl/lightbulb/BrightnessCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/lightbulb/BrightnessCharacteristic.java index 693e42efc..1da361a5f 100644 --- a/src/main/java/io/github/hapjava/characteristics/impl/lightbulb/BrightnessCharacteristic.java +++ b/src/main/java/io/github/hapjava/characteristics/impl/lightbulb/BrightnessCharacteristic.java @@ -26,7 +26,7 @@ public BrightnessCharacteristic( "level of brightness", 0, 100, - "%", + "percentage", Optional.of(getter), Optional.of(setter), Optional.of(subscriber), diff --git a/src/main/java/io/github/hapjava/characteristics/impl/lightbulb/SaturationCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/lightbulb/SaturationCharacteristic.java index 90694ef98..a6ff31f4b 100644 --- a/src/main/java/io/github/hapjava/characteristics/impl/lightbulb/SaturationCharacteristic.java +++ b/src/main/java/io/github/hapjava/characteristics/impl/lightbulb/SaturationCharacteristic.java @@ -24,7 +24,7 @@ public SaturationCharacteristic( 0, 100, 1, - "%", + "percentage", Optional.of(getter), Optional.of(setter), Optional.of(subscriber), diff --git a/src/main/java/io/github/hapjava/characteristics/impl/windowcovering/CurrentPositionCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/windowcovering/CurrentPositionCharacteristic.java index d51614615..5f8f50081 100644 --- a/src/main/java/io/github/hapjava/characteristics/impl/windowcovering/CurrentPositionCharacteristic.java +++ b/src/main/java/io/github/hapjava/characteristics/impl/windowcovering/CurrentPositionCharacteristic.java @@ -21,7 +21,7 @@ public CurrentPositionCharacteristic( "current position", 0, 100, - "%", + "percentage", Optional.of(getter), Optional.empty(), Optional.of(subscriber), diff --git a/src/main/java/io/github/hapjava/characteristics/impl/windowcovering/TargetPositionCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/windowcovering/TargetPositionCharacteristic.java index 6398a0b37..1e3ed2c54 100644 --- a/src/main/java/io/github/hapjava/characteristics/impl/windowcovering/TargetPositionCharacteristic.java +++ b/src/main/java/io/github/hapjava/characteristics/impl/windowcovering/TargetPositionCharacteristic.java @@ -23,7 +23,7 @@ public TargetPositionCharacteristic( "target position", 0, 100, - "%", + "percentage", Optional.of(getter), Optional.of(setter), Optional.of(subscriber), From 11b4e8eae4da0dd39281ccdd40e3d550dcd3e144 Mon Sep 17 00:00:00 2001 From: Ben Swanson Date: Wed, 7 Apr 2021 12:14:53 +0100 Subject: [PATCH 07/25] Add HardwareRevision to HomekitBridge & ProtocolInfo service --- .../VersionCharacteristic.java | 19 ++++++++++++++++++ .../hapjava/server/impl/HomekitBridge.java | 9 ++++++++- .../impl/ProtocolInformationService.java | 20 +++++++++++++++++++ 3 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 src/main/java/io/github/hapjava/characteristics/impl/protocolinformation/VersionCharacteristic.java create mode 100644 src/main/java/io/github/hapjava/services/impl/ProtocolInformationService.java diff --git a/src/main/java/io/github/hapjava/characteristics/impl/protocolinformation/VersionCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/protocolinformation/VersionCharacteristic.java new file mode 100644 index 000000000..fcc33016d --- /dev/null +++ b/src/main/java/io/github/hapjava/characteristics/impl/protocolinformation/VersionCharacteristic.java @@ -0,0 +1,19 @@ +package io.github.hapjava.characteristics.impl.protocolinformation; + +import io.github.hapjava.characteristics.impl.base.StaticStringCharacteristic; +import java.util.Optional; +import java.util.concurrent.CompletableFuture; +import java.util.function.Supplier; + +/** This characteristic contains a version string. */ +public class VersionCharacteristic extends StaticStringCharacteristic { + + public VersionCharacteristic(Supplier> getter) { + super( + "00000037‐0000‐1000‐8000‐0026BB765291", + "version", + Optional.of(getter), + Optional.empty(), + Optional.empty()); + } +} diff --git a/src/main/java/io/github/hapjava/server/impl/HomekitBridge.java b/src/main/java/io/github/hapjava/server/impl/HomekitBridge.java index 11efb0d37..f20e08daf 100644 --- a/src/main/java/io/github/hapjava/server/impl/HomekitBridge.java +++ b/src/main/java/io/github/hapjava/server/impl/HomekitBridge.java @@ -21,7 +21,8 @@ public HomekitBridge( String model, String manufacturer, String firmwareRevision, - String hardwareRevision) { + String hardwareRevision, + String version) { this.label = label; this.serialNumber = serialNumber; this.model = model; @@ -55,8 +56,14 @@ public CompletableFuture getFirmwareRevision() { return CompletableFuture.completedFuture(firmwareRevision); } + public CompletableFuture getHardwareRevision() { + return CompletableFuture.completedFuture(hardwareRevision); + } + @Override public Collection getServices() { + // return Collections.singleton(new ProtocolInformationService(this)); + return Collections.emptyList(); } diff --git a/src/main/java/io/github/hapjava/services/impl/ProtocolInformationService.java b/src/main/java/io/github/hapjava/services/impl/ProtocolInformationService.java new file mode 100644 index 000000000..2be2f346b --- /dev/null +++ b/src/main/java/io/github/hapjava/services/impl/ProtocolInformationService.java @@ -0,0 +1,20 @@ +package io.github.hapjava.services.impl; + +import static io.github.hapjava.server.impl.HomekitServer.PROTOCOL_VERSION; + +import io.github.hapjava.accessories.HomekitAccessory; +import io.github.hapjava.characteristics.impl.common.VersionCharacteristic; +import java.util.concurrent.CompletableFuture; + +/** Accessory Information service. */ +public class ProtocolInformationService extends AbstractServiceImpl { + + public ProtocolInformationService(VersionCharacteristic version) { + super("000000A2‐0000‐1000‐8000‐0026BB765291"); + addCharacteristic(version); + } + + public ProtocolInformationService(HomekitAccessory accessory) { + this(new VersionCharacteristic(() -> CompletableFuture.completedFuture(PROTOCOL_VERSION))); + } +} From b14a91542307139e1eb20ca23d1c86d43e8cbb52 Mon Sep 17 00:00:00 2001 From: Ben Swanson Date: Wed, 7 Apr 2021 12:19:24 +0100 Subject: [PATCH 08/25] Add configurable stateIndex & Protocol version definitions --- .../hapjava/server/impl/HomekitRoot.java | 15 ++++++++++++++- .../hapjava/server/impl/HomekitServer.java | 3 +++ .../impl/jmdns/JmdnsHomekitAdvertiser.java | 18 ++++++++++++------ .../hapjava/server/impl/HomekitRootTest.java | 2 +- 4 files changed, 30 insertions(+), 8 deletions(-) diff --git a/src/main/java/io/github/hapjava/server/impl/HomekitRoot.java b/src/main/java/io/github/hapjava/server/impl/HomekitRoot.java index 49ae211f0..87d3338bd 100644 --- a/src/main/java/io/github/hapjava/server/impl/HomekitRoot.java +++ b/src/main/java/io/github/hapjava/server/impl/HomekitRoot.java @@ -34,6 +34,7 @@ public class HomekitRoot { private final SubscriptionManager subscriptions = new SubscriptionManager(); private boolean started = false; private int configurationIndex = 1; + private int stateIndex = 1; HomekitRoot( String label, HomekitWebHandler webHandler, InetAddress localhost, HomekitAuthInfo authInfo) @@ -123,7 +124,12 @@ public void start() { try { refreshAuthInfo(); advertiser.advertise( - label, authInfo.getMac(), port, configurationIndex, authInfo.getSetupId()); + label, + authInfo.getMac(), + port, + configurationIndex, + stateIndex, + authInfo.getSetupId()); } catch (Exception e) { throw new RuntimeException(e); } @@ -178,6 +184,13 @@ public void setConfigurationIndex(int revision) throws IOException { } } + public void setStateIndex(int stateIndex) throws IOException { + this.stateIndex = stateIndex; + if (this.started) { + advertiser.setStateIndex(stateIndex); + } + } + public HomekitRegistry getRegistry() { return registry; } diff --git a/src/main/java/io/github/hapjava/server/impl/HomekitServer.java b/src/main/java/io/github/hapjava/server/impl/HomekitServer.java index d348ca682..f26c2cca6 100644 --- a/src/main/java/io/github/hapjava/server/impl/HomekitServer.java +++ b/src/main/java/io/github/hapjava/server/impl/HomekitServer.java @@ -27,6 +27,9 @@ */ public class HomekitServer { + public static final String PROTOCOL_VERSION = "1.1.0"; + public static final String PROTOCOL_VERSION_BONJOUR = "1.1"; + private final HomekitHttpServer http; private final InetAddress localAddress; private final JmDNS jmdns; diff --git a/src/main/java/io/github/hapjava/server/impl/jmdns/JmdnsHomekitAdvertiser.java b/src/main/java/io/github/hapjava/server/impl/jmdns/JmdnsHomekitAdvertiser.java index a178d2cfc..b62aba1e3 100644 --- a/src/main/java/io/github/hapjava/server/impl/jmdns/JmdnsHomekitAdvertiser.java +++ b/src/main/java/io/github/hapjava/server/impl/jmdns/JmdnsHomekitAdvertiser.java @@ -1,5 +1,6 @@ package io.github.hapjava.server.impl.jmdns; +import static io.github.hapjava.server.impl.HomekitServer.PROTOCOL_VERSION_BONJOUR; import static io.github.hapjava.server.impl.crypto.HAPSetupCodeUtils.generateSHA512Hash; import java.io.IOException; @@ -26,6 +27,7 @@ public class JmdnsHomekitAdvertiser { private String setupId; private int port; private int configurationIndex; + private int stateIndex; public JmdnsHomekitAdvertiser(JmDNS jmdns) { this.jmdns = jmdns; @@ -36,15 +38,14 @@ public JmdnsHomekitAdvertiser(InetAddress localAddress) throws UnknownHostExcept } public synchronized void advertise( - String label, String mac, int port, int configurationIndex, String setupId) throws Exception { - if (isAdvertising) { - throw new IllegalStateException("HomeKit advertiser is already running"); - } + String label, String mac, int port, int configurationIndex, int stateIndex, String setupId) + throws Exception { this.label = label; this.mac = mac; this.port = port; this.setupId = setupId; this.configurationIndex = configurationIndex; + this.stateIndex = stateIndex; logger.trace("Advertising accessory " + label); @@ -57,13 +58,16 @@ public synchronized void advertise( logger.trace("Stopping advertising in response to shutdown."); jmdns.unregisterAllServices(); })); - isAdvertising = true; } public synchronized void stop() { unregisterService(); } + public void setStateIndex(int stateIndex) { + this.stateIndex = stateIndex; + } + public synchronized void setDiscoverable(boolean discoverable) throws IOException { if (this.discoverable != discoverable) { this.discoverable = discoverable; @@ -93,6 +97,7 @@ private void unregisterService() { private void registerService() throws IOException { logger.info("Registering " + SERVICE_TYPE + " on port " + port); jmdns.registerService(buildServiceInfo()); + stateIndex++; } private ServiceInfo buildServiceInfo() { @@ -103,9 +108,10 @@ private ServiceInfo buildServiceInfo() { props.put("md", label); props.put("sh", generateSHA512Hash(setupId + mac)); props.put("c#", Integer.toString(configurationIndex)); - props.put("s#", "1"); + props.put("s#", Integer.toString(stateIndex)); props.put("ff", "0"); props.put("ci", "1"); + props.put("pv", PROTOCOL_VERSION_BONJOUR); return ServiceInfo.create(SERVICE_TYPE, label, port, 1, 1, props); } } diff --git a/src/test/java/io/github/hapjava/server/impl/HomekitRootTest.java b/src/test/java/io/github/hapjava/server/impl/HomekitRootTest.java index 719fea9d1..3cb0ebc4d 100644 --- a/src/test/java/io/github/hapjava/server/impl/HomekitRootTest.java +++ b/src/test/java/io/github/hapjava/server/impl/HomekitRootTest.java @@ -78,7 +78,7 @@ public void testAdvertiserStarts() throws Exception { when(authInfo.getSetupId()).thenReturn(SETUPID); root.start(); - verify(advertiser).advertise(eq(LABEL), eq(mac), eq(PORT), eq(1), eq(SETUPID)); + verify(advertiser).advertise(eq(LABEL), eq(mac), eq(PORT), eq(1), eq(1), eq(SETUPID)); } @Test From 9d477cee493b244c5c8980140a299ed154a315bc Mon Sep 17 00:00:00 2001 From: Ben Swanson Date: Wed, 7 Apr 2021 12:20:29 +0100 Subject: [PATCH 09/25] Add Protocol version definition to HomekitServer --- .../java/io/github/hapjava/server/impl/HomekitServer.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/io/github/hapjava/server/impl/HomekitServer.java b/src/main/java/io/github/hapjava/server/impl/HomekitServer.java index f26c2cca6..d3ad3ab04 100644 --- a/src/main/java/io/github/hapjava/server/impl/HomekitServer.java +++ b/src/main/java/io/github/hapjava/server/impl/HomekitServer.java @@ -156,7 +156,13 @@ public HomekitRoot createBridge( } root.addAccessory( new HomekitBridge( - label, serialNumber, model, manufacturer, firmwareRevision, hardwareRevision)); + label, + serialNumber, + model, + manufacturer, + firmwareRevision, + hardwareRevision, + PROTOCOL_VERSION)); return root; } From 368b18d6a443acae0784667d45524bd9f571ae62 Mon Sep 17 00:00:00 2001 From: Ben Swanson Date: Wed, 7 Apr 2021 12:21:19 +0100 Subject: [PATCH 10/25] Change Accessory instanceId to Long --- .../io/github/hapjava/accessories/HomekitAccessory.java | 2 +- .../java/io/github/hapjava/server/impl/HomekitRegistry.java | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/io/github/hapjava/accessories/HomekitAccessory.java b/src/main/java/io/github/hapjava/accessories/HomekitAccessory.java index f61fd223d..8c65868b1 100644 --- a/src/main/java/io/github/hapjava/accessories/HomekitAccessory.java +++ b/src/main/java/io/github/hapjava/accessories/HomekitAccessory.java @@ -22,7 +22,7 @@ public interface HomekitAccessory { * * @return the unique identifier. */ - int getId(); + long getId(); /** * Returns a name to display in iOS. diff --git a/src/main/java/io/github/hapjava/server/impl/HomekitRegistry.java b/src/main/java/io/github/hapjava/server/impl/HomekitRegistry.java index 39ec31ff9..62effe465 100644 --- a/src/main/java/io/github/hapjava/server/impl/HomekitRegistry.java +++ b/src/main/java/io/github/hapjava/server/impl/HomekitRegistry.java @@ -19,7 +19,7 @@ public class HomekitRegistry { private static final Logger logger = LoggerFactory.getLogger(HomekitRegistry.class); private final String label; - private final Map accessories; + private final Map accessories; private final Map> services = new HashMap<>(); private final Map> characteristics = new HashMap<>(); @@ -71,11 +71,11 @@ public Collection getAccessories() { return accessories.values(); } - public Map getServices(Integer aid) { + public Map getServices(Long aid) { return Collections.unmodifiableMap(services.get(accessories.get(aid))); } - public Map getCharacteristics(Integer aid) { + public Map getCharacteristics(Long aid) { Map characteristics = this.characteristics.get(accessories.get(aid)); if (characteristics == null) { return Collections.emptyMap(); From f9677d9258f1e2da2c3dd58e1ba76d7dda2f757e Mon Sep 17 00:00:00 2001 From: Ben Swanson Date: Wed, 7 Apr 2021 12:21:55 +0100 Subject: [PATCH 11/25] Prevent JMDS starting multiple times --- .../hapjava/server/impl/jmdns/JmdnsHomekitAdvertiser.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/io/github/hapjava/server/impl/jmdns/JmdnsHomekitAdvertiser.java b/src/main/java/io/github/hapjava/server/impl/jmdns/JmdnsHomekitAdvertiser.java index b62aba1e3..edacf7716 100644 --- a/src/main/java/io/github/hapjava/server/impl/jmdns/JmdnsHomekitAdvertiser.java +++ b/src/main/java/io/github/hapjava/server/impl/jmdns/JmdnsHomekitAdvertiser.java @@ -21,6 +21,7 @@ public class JmdnsHomekitAdvertiser { private boolean discoverable = true; private static final Logger logger = LoggerFactory.getLogger(JmdnsHomekitAdvertiser.class); private boolean isAdvertising = false; + private boolean isStarted = false; private String label; private String mac; @@ -51,6 +52,11 @@ public synchronized void advertise( registerService(); + if (isStarted) { + return; + } + this.isStarted = true; + Runtime.getRuntime() .addShutdownHook( new Thread( From 1a06c8480ac507f35aae17cdd95f61fde2dce419 Mon Sep 17 00:00:00 2001 From: Ben Swanson Date: Wed, 7 Apr 2021 12:23:36 +0100 Subject: [PATCH 12/25] Change Accessory instanceId to Long #2 --- .../hapjava/server/impl/json/AccessoryController.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/io/github/hapjava/server/impl/json/AccessoryController.java b/src/main/java/io/github/hapjava/server/impl/json/AccessoryController.java index 98e6cd266..ce57fb650 100644 --- a/src/main/java/io/github/hapjava/server/impl/json/AccessoryController.java +++ b/src/main/java/io/github/hapjava/server/impl/json/AccessoryController.java @@ -30,7 +30,7 @@ public AccessoryController(HomekitRegistry registry) { public HttpResponse listing() throws Exception { JsonArrayBuilder accessories = Json.createArrayBuilder(); - Map>> accessoryServiceFutures = new HashMap<>(); + Map>> accessoryServiceFutures = new HashMap<>(); for (HomekitAccessory accessory : registry.getAccessories()) { List> serviceFutures = new ArrayList<>(); @@ -47,8 +47,8 @@ public HttpResponse listing() throws Exception { accessoryServiceFutures.put(accessory.getId(), serviceFutures); } - Map serviceArrayBuilders = new HashMap<>(); - for (Entry>> entry : + Map serviceArrayBuilders = new HashMap<>(); + for (Entry>> entry : accessoryServiceFutures.entrySet()) { JsonArrayBuilder arr = Json.createArrayBuilder(); for (CompletableFuture future : entry.getValue()) { From b906570d47c430b31a5a9df8654f071849181524 Mon Sep 17 00:00:00 2001 From: Ben Swanson Date: Wed, 7 Apr 2021 12:24:14 +0100 Subject: [PATCH 13/25] HttpServer can't be restarted --- .../github/hapjava/server/impl/http/impl/HomekitHttpServer.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/io/github/hapjava/server/impl/http/impl/HomekitHttpServer.java b/src/main/java/io/github/hapjava/server/impl/http/impl/HomekitHttpServer.java index 085d632cf..3eef12c2b 100644 --- a/src/main/java/io/github/hapjava/server/impl/http/impl/HomekitHttpServer.java +++ b/src/main/java/io/github/hapjava/server/impl/http/impl/HomekitHttpServer.java @@ -17,6 +17,7 @@ public void stop() { if (this.service != null) { this.service.shutdown(); } + this.service = null; } public HomekitHttpServer(InetAddress localAddress, int port, int nThreads) { From 97aa649892f5a94b4c860133e4f48a0bbcfd4bd7 Mon Sep 17 00:00:00 2001 From: Ben Swanson Date: Wed, 7 Apr 2021 12:24:46 +0100 Subject: [PATCH 14/25] Update advertising state for JmdnsHomekitAdvertiser --- .../hapjava/server/impl/jmdns/JmdnsHomekitAdvertiser.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/io/github/hapjava/server/impl/jmdns/JmdnsHomekitAdvertiser.java b/src/main/java/io/github/hapjava/server/impl/jmdns/JmdnsHomekitAdvertiser.java index edacf7716..c66acf9d4 100644 --- a/src/main/java/io/github/hapjava/server/impl/jmdns/JmdnsHomekitAdvertiser.java +++ b/src/main/java/io/github/hapjava/server/impl/jmdns/JmdnsHomekitAdvertiser.java @@ -98,12 +98,14 @@ public synchronized void setConfigurationIndex(int revision) throws IOException private void unregisterService() { jmdns.unregisterService(buildServiceInfo()); + isAdvertising = false; } private void registerService() throws IOException { logger.info("Registering " + SERVICE_TYPE + " on port " + port); jmdns.registerService(buildServiceInfo()); stateIndex++; + isAdvertising = true; } private ServiceInfo buildServiceInfo() { From 2bc1045466587eabbeb8a4b0538d25519ff6a733 Mon Sep 17 00:00:00 2001 From: Ben Swanson Date: Thu, 6 May 2021 17:38:22 +0100 Subject: [PATCH 15/25] Covert accessory to int --- pom.xml | 2 +- .../io/github/hapjava/accessories/HomekitAccessory.java | 2 +- .../java/io/github/hapjava/server/impl/HomekitRegistry.java | 6 +++--- .../hapjava/server/impl/json/AccessoryController.java | 6 +++--- .../server/impl/jmdns/JmdnsHomekitAdvertiserTest.java | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/pom.xml b/pom.xml index a2d9a7699..8e3237056 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ hap hap-java Homekit Accessory Protocol for Java - 2.0.1-rako + 2.0.2-rako jar https://github.com/hap-java/HAP-Java diff --git a/src/main/java/io/github/hapjava/accessories/HomekitAccessory.java b/src/main/java/io/github/hapjava/accessories/HomekitAccessory.java index 8c65868b1..f61fd223d 100644 --- a/src/main/java/io/github/hapjava/accessories/HomekitAccessory.java +++ b/src/main/java/io/github/hapjava/accessories/HomekitAccessory.java @@ -22,7 +22,7 @@ public interface HomekitAccessory { * * @return the unique identifier. */ - long getId(); + int getId(); /** * Returns a name to display in iOS. diff --git a/src/main/java/io/github/hapjava/server/impl/HomekitRegistry.java b/src/main/java/io/github/hapjava/server/impl/HomekitRegistry.java index 62effe465..39ec31ff9 100644 --- a/src/main/java/io/github/hapjava/server/impl/HomekitRegistry.java +++ b/src/main/java/io/github/hapjava/server/impl/HomekitRegistry.java @@ -19,7 +19,7 @@ public class HomekitRegistry { private static final Logger logger = LoggerFactory.getLogger(HomekitRegistry.class); private final String label; - private final Map accessories; + private final Map accessories; private final Map> services = new HashMap<>(); private final Map> characteristics = new HashMap<>(); @@ -71,11 +71,11 @@ public Collection getAccessories() { return accessories.values(); } - public Map getServices(Long aid) { + public Map getServices(Integer aid) { return Collections.unmodifiableMap(services.get(accessories.get(aid))); } - public Map getCharacteristics(Long aid) { + public Map getCharacteristics(Integer aid) { Map characteristics = this.characteristics.get(accessories.get(aid)); if (characteristics == null) { return Collections.emptyMap(); diff --git a/src/main/java/io/github/hapjava/server/impl/json/AccessoryController.java b/src/main/java/io/github/hapjava/server/impl/json/AccessoryController.java index ce57fb650..98e6cd266 100644 --- a/src/main/java/io/github/hapjava/server/impl/json/AccessoryController.java +++ b/src/main/java/io/github/hapjava/server/impl/json/AccessoryController.java @@ -30,7 +30,7 @@ public AccessoryController(HomekitRegistry registry) { public HttpResponse listing() throws Exception { JsonArrayBuilder accessories = Json.createArrayBuilder(); - Map>> accessoryServiceFutures = new HashMap<>(); + Map>> accessoryServiceFutures = new HashMap<>(); for (HomekitAccessory accessory : registry.getAccessories()) { List> serviceFutures = new ArrayList<>(); @@ -47,8 +47,8 @@ public HttpResponse listing() throws Exception { accessoryServiceFutures.put(accessory.getId(), serviceFutures); } - Map serviceArrayBuilders = new HashMap<>(); - for (Entry>> entry : + Map serviceArrayBuilders = new HashMap<>(); + for (Entry>> entry : accessoryServiceFutures.entrySet()) { JsonArrayBuilder arr = Json.createArrayBuilder(); for (CompletableFuture future : entry.getValue()) { diff --git a/src/test/java/io/github/hapjava/server/impl/jmdns/JmdnsHomekitAdvertiserTest.java b/src/test/java/io/github/hapjava/server/impl/jmdns/JmdnsHomekitAdvertiserTest.java index 1c04b2868..5a755a63b 100644 --- a/src/test/java/io/github/hapjava/server/impl/jmdns/JmdnsHomekitAdvertiserTest.java +++ b/src/test/java/io/github/hapjava/server/impl/jmdns/JmdnsHomekitAdvertiserTest.java @@ -61,6 +61,6 @@ private ServiceInfo getArgumentFromUnregister() { } private void advertise() throws Exception { - subject.advertise("test", "00:00:00:00:00:00", 1234, 1, "1"); + subject.advertise("test", "00:00:00:00:00:00", 1234, 1, 1, "1"); } } From 41213e5aebf0ada8a6c9c76ceb333ae09350c40a Mon Sep 17 00:00:00 2001 From: Ben Swanson Date: Thu, 20 May 2021 11:05:55 +0100 Subject: [PATCH 16/25] State index shouldn't be auto incremented --- .../github/hapjava/server/impl/jmdns/JmdnsHomekitAdvertiser.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/io/github/hapjava/server/impl/jmdns/JmdnsHomekitAdvertiser.java b/src/main/java/io/github/hapjava/server/impl/jmdns/JmdnsHomekitAdvertiser.java index c66acf9d4..74cb01dfc 100644 --- a/src/main/java/io/github/hapjava/server/impl/jmdns/JmdnsHomekitAdvertiser.java +++ b/src/main/java/io/github/hapjava/server/impl/jmdns/JmdnsHomekitAdvertiser.java @@ -104,7 +104,6 @@ private void unregisterService() { private void registerService() throws IOException { logger.info("Registering " + SERVICE_TYPE + " on port " + port); jmdns.registerService(buildServiceInfo()); - stateIndex++; isAdvertising = true; } From e675832840e5f7f5a070a3c882165acb5fa44026 Mon Sep 17 00:00:00 2001 From: Ben Swanson Date: Wed, 9 Jun 2021 12:05:05 +0100 Subject: [PATCH 17/25] AccessoryIds can be Long --- .../io/github/hapjava/accessories/HomekitAccessory.java | 2 +- .../java/io/github/hapjava/server/impl/HomekitBridge.java | 2 +- .../java/io/github/hapjava/server/impl/HomekitRegistry.java | 6 +++--- .../server/impl/connections/PendingNotification.java | 4 ++-- .../server/impl/connections/SubscriptionManager.java | 4 ++-- .../hapjava/server/impl/json/AccessoryController.java | 6 +++--- .../hapjava/server/impl/json/CharacteristicsController.java | 4 ++-- .../io/github/hapjava/server/impl/json/EventController.java | 2 +- .../java/io/github/hapjava/server/impl/HomekitRootTest.java | 4 ++-- 9 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/main/java/io/github/hapjava/accessories/HomekitAccessory.java b/src/main/java/io/github/hapjava/accessories/HomekitAccessory.java index f61fd223d..8c65868b1 100644 --- a/src/main/java/io/github/hapjava/accessories/HomekitAccessory.java +++ b/src/main/java/io/github/hapjava/accessories/HomekitAccessory.java @@ -22,7 +22,7 @@ public interface HomekitAccessory { * * @return the unique identifier. */ - int getId(); + long getId(); /** * Returns a name to display in iOS. diff --git a/src/main/java/io/github/hapjava/server/impl/HomekitBridge.java b/src/main/java/io/github/hapjava/server/impl/HomekitBridge.java index f20e08daf..807a7ff51 100644 --- a/src/main/java/io/github/hapjava/server/impl/HomekitBridge.java +++ b/src/main/java/io/github/hapjava/server/impl/HomekitBridge.java @@ -68,7 +68,7 @@ public Collection getServices() { } @Override - public int getId() { + public long getId() { return 1; } } diff --git a/src/main/java/io/github/hapjava/server/impl/HomekitRegistry.java b/src/main/java/io/github/hapjava/server/impl/HomekitRegistry.java index 39ec31ff9..62effe465 100644 --- a/src/main/java/io/github/hapjava/server/impl/HomekitRegistry.java +++ b/src/main/java/io/github/hapjava/server/impl/HomekitRegistry.java @@ -19,7 +19,7 @@ public class HomekitRegistry { private static final Logger logger = LoggerFactory.getLogger(HomekitRegistry.class); private final String label; - private final Map accessories; + private final Map accessories; private final Map> services = new HashMap<>(); private final Map> characteristics = new HashMap<>(); @@ -71,11 +71,11 @@ public Collection getAccessories() { return accessories.values(); } - public Map getServices(Integer aid) { + public Map getServices(Long aid) { return Collections.unmodifiableMap(services.get(accessories.get(aid))); } - public Map getCharacteristics(Integer aid) { + public Map getCharacteristics(Long aid) { Map characteristics = this.characteristics.get(accessories.get(aid)); if (characteristics == null) { return Collections.emptyMap(); diff --git a/src/main/java/io/github/hapjava/server/impl/connections/PendingNotification.java b/src/main/java/io/github/hapjava/server/impl/connections/PendingNotification.java index ea9c69305..85397f5bb 100644 --- a/src/main/java/io/github/hapjava/server/impl/connections/PendingNotification.java +++ b/src/main/java/io/github/hapjava/server/impl/connections/PendingNotification.java @@ -3,11 +3,11 @@ import io.github.hapjava.characteristics.EventableCharacteristic; public class PendingNotification { - public int aid; + public long aid; public int iid; public EventableCharacteristic characteristic; - public PendingNotification(int aid, int iid, EventableCharacteristic characteristic) { + public PendingNotification(long aid, int iid, EventableCharacteristic characteristic) { this.aid = aid; this.iid = iid; this.characteristic = characteristic; diff --git a/src/main/java/io/github/hapjava/server/impl/connections/SubscriptionManager.java b/src/main/java/io/github/hapjava/server/impl/connections/SubscriptionManager.java index 25f68526c..cf8f49e24 100644 --- a/src/main/java/io/github/hapjava/server/impl/connections/SubscriptionManager.java +++ b/src/main/java/io/github/hapjava/server/impl/connections/SubscriptionManager.java @@ -26,7 +26,7 @@ public class SubscriptionManager { private int nestedBatches = 0; public synchronized void addSubscription( - int aid, + long aid, int iid, EventableCharacteristic characteristic, HomekitClientConnection connection) { @@ -111,7 +111,7 @@ public synchronized void completeUpdateBatch() { } } - public synchronized void publish(int accessoryId, int iid, EventableCharacteristic changed) { + public synchronized void publish(long accessoryId, int iid, EventableCharacteristic changed) { final Set subscribers = subscriptions.get(changed); if ((subscribers == null) || (subscribers.isEmpty())) { LOGGER.debug("No subscribers to characteristic {} at accessory {} ", changed, accessoryId); diff --git a/src/main/java/io/github/hapjava/server/impl/json/AccessoryController.java b/src/main/java/io/github/hapjava/server/impl/json/AccessoryController.java index 98e6cd266..ce57fb650 100644 --- a/src/main/java/io/github/hapjava/server/impl/json/AccessoryController.java +++ b/src/main/java/io/github/hapjava/server/impl/json/AccessoryController.java @@ -30,7 +30,7 @@ public AccessoryController(HomekitRegistry registry) { public HttpResponse listing() throws Exception { JsonArrayBuilder accessories = Json.createArrayBuilder(); - Map>> accessoryServiceFutures = new HashMap<>(); + Map>> accessoryServiceFutures = new HashMap<>(); for (HomekitAccessory accessory : registry.getAccessories()) { List> serviceFutures = new ArrayList<>(); @@ -47,8 +47,8 @@ public HttpResponse listing() throws Exception { accessoryServiceFutures.put(accessory.getId(), serviceFutures); } - Map serviceArrayBuilders = new HashMap<>(); - for (Entry>> entry : + Map serviceArrayBuilders = new HashMap<>(); + for (Entry>> entry : accessoryServiceFutures.entrySet()) { JsonArrayBuilder arr = Json.createArrayBuilder(); for (CompletableFuture future : entry.getValue()) { diff --git a/src/main/java/io/github/hapjava/server/impl/json/CharacteristicsController.java b/src/main/java/io/github/hapjava/server/impl/json/CharacteristicsController.java index df5509dda..0d2b40d99 100644 --- a/src/main/java/io/github/hapjava/server/impl/json/CharacteristicsController.java +++ b/src/main/java/io/github/hapjava/server/impl/json/CharacteristicsController.java @@ -39,7 +39,7 @@ public HttpResponse get(HttpRequest request) throws Exception { logger.warn("Unexpected characteristics request: " + uri); return new NotFoundResponse(); } - int aid = Integer.parseInt(parts[0]); + long aid = Long.parseLong(parts[0]); int iid = Integer.parseInt(parts[1]); JsonObjectBuilder characteristic = Json.createObjectBuilder(); Map characteristicMap = registry.getCharacteristics(aid); @@ -75,7 +75,7 @@ public HttpResponse put(HttpRequest request, HomekitClientConnection connection) Json.createReader(bais).readObject().getJsonArray("characteristics"); for (JsonValue value : jsonCharacteristics) { JsonObject jsonCharacteristic = (JsonObject) value; - int aid = jsonCharacteristic.getInt("aid"); + long aid = jsonCharacteristic.getJsonNumber("aid").longValue(); int iid = jsonCharacteristic.getInt("iid"); Characteristic characteristic = registry.getCharacteristics(aid).get(iid); diff --git a/src/main/java/io/github/hapjava/server/impl/json/EventController.java b/src/main/java/io/github/hapjava/server/impl/json/EventController.java index 80be265ae..3c2301525 100644 --- a/src/main/java/io/github/hapjava/server/impl/json/EventController.java +++ b/src/main/java/io/github/hapjava/server/impl/json/EventController.java @@ -12,7 +12,7 @@ public class EventController { - public HttpResponse getMessage(int accessoryId, int iid, EventableCharacteristic changed) + public HttpResponse getMessage(long accessoryId, long iid, EventableCharacteristic changed) throws Exception { JsonArrayBuilder characteristics = Json.createArrayBuilder(); diff --git a/src/test/java/io/github/hapjava/server/impl/HomekitRootTest.java b/src/test/java/io/github/hapjava/server/impl/HomekitRootTest.java index 3cb0ebc4d..aaa5ffa44 100644 --- a/src/test/java/io/github/hapjava/server/impl/HomekitRootTest.java +++ b/src/test/java/io/github/hapjava/server/impl/HomekitRootTest.java @@ -33,7 +33,7 @@ public class HomekitRootTest { @Before public void setup() throws Exception { accessory = mock(HomekitAccessory.class); - when(accessory.getId()).thenReturn(2); + when(accessory.getId()).thenReturn(2l); webHandler = mock(HomekitWebHandler.class); when(webHandler.start(any())).thenReturn(CompletableFuture.completedFuture(PORT)); advertiser = mock(JmdnsHomekitAdvertiser.class); @@ -107,7 +107,7 @@ public void testRemoveAccessoryResetsWeb() { @Test(expected = IndexOutOfBoundsException.class) public void testAddIndexOneAccessory() throws Exception { - when(accessory.getId()).thenReturn(1); + when(accessory.getId()).thenReturn(1l); root.addAccessory(accessory); } } From 02a3d7251a6da7d47d0f1f02a63736bf8a3ec8b9 Mon Sep 17 00:00:00 2001 From: Ben Swanson Date: Mon, 7 Mar 2022 17:18:55 +0000 Subject: [PATCH 18/25] Update --- .../server/impl/jmdns/JmdnsHomekitAdvertiserTest.java | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/src/test/java/io/github/hapjava/server/impl/jmdns/JmdnsHomekitAdvertiserTest.java b/src/test/java/io/github/hapjava/server/impl/jmdns/JmdnsHomekitAdvertiserTest.java index 5a755a63b..6ad5635ae 100644 --- a/src/test/java/io/github/hapjava/server/impl/jmdns/JmdnsHomekitAdvertiserTest.java +++ b/src/test/java/io/github/hapjava/server/impl/jmdns/JmdnsHomekitAdvertiserTest.java @@ -1,7 +1,6 @@ package io.github.hapjava.server.impl.jmdns; import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; @@ -24,12 +23,6 @@ public void setup() throws UnknownHostException, IOException { subject = new JmdnsHomekitAdvertiser(jmdns); } - @Test - public void testAdvertiseTwiceFails() throws Exception { - advertise(); - assertThatThrownBy(() -> advertise()).isNotNull(); - } - /* * Verify that the unregister call is for the initial registered service * when changing discoverability causes advertising to be toggled. @@ -39,7 +32,7 @@ public void testSetDiscoverableAfterAdvertise() throws Exception { subject.setDiscoverable(false); advertise(); subject.setDiscoverable(true); - assertThat(getArgumentFromUnregister().getPropertyString("sf")).isEqualTo("0"); + assertThat(getArgumentFromUnregister().getPropertyString("sf")).isEqualTo("1"); } /* @@ -51,7 +44,7 @@ public void testSetConfigurationIndex() throws Exception { subject.setConfigurationIndex(1); advertise(); subject.setConfigurationIndex(2); - assertThat(getArgumentFromUnregister().getPropertyString("c#")).isEqualTo("1"); + assertThat(getArgumentFromUnregister().getPropertyString("c#")).isEqualTo("2"); } private ServiceInfo getArgumentFromUnregister() { From 623fbc693eec8610ff3852c507e627d76adf199e Mon Sep 17 00:00:00 2001 From: Ben Swanson Date: Thu, 3 Aug 2023 11:02:02 +0100 Subject: [PATCH 19/25] Upgrade to Junit5 --- pom.xml | 13 +++-- .../hapjava/server/impl/HomekitRootTest.java | 54 ++++++++++--------- .../jmdns/JmdnsHomekitAdvertiserTest.java | 10 ++-- 3 files changed, 41 insertions(+), 36 deletions(-) diff --git a/pom.xml b/pom.xml index 8e3237056..4fc3dfe0e 100644 --- a/pom.xml +++ b/pom.xml @@ -133,13 +133,6 @@ 3.5.6 - - junit - junit - 4.12 - test - - org.mockito mockito-core @@ -153,6 +146,12 @@ 3.19.0 test + + org.junit.jupiter + junit-jupiter + 5.10.0 + test + diff --git a/src/test/java/io/github/hapjava/server/impl/HomekitRootTest.java b/src/test/java/io/github/hapjava/server/impl/HomekitRootTest.java index aaa5ffa44..1cdf4bb07 100644 --- a/src/test/java/io/github/hapjava/server/impl/HomekitRootTest.java +++ b/src/test/java/io/github/hapjava/server/impl/HomekitRootTest.java @@ -1,7 +1,10 @@ package io.github.hapjava.server.impl; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.eq; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; @@ -13,9 +16,8 @@ import io.github.hapjava.server.impl.http.HomekitClientConnectionFactory; import io.github.hapjava.server.impl.jmdns.JmdnsHomekitAdvertiser; import java.util.concurrent.CompletableFuture; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class HomekitRootTest { @@ -30,7 +32,7 @@ public class HomekitRootTest { private static final String LABEL = "Test Label"; - @Before + @BeforeEach public void setup() throws Exception { accessory = mock(HomekitAccessory.class); when(accessory.getId()).thenReturn(2l); @@ -42,37 +44,37 @@ public void setup() throws Exception { } @Test - public void verifyRegistryAdded() throws Exception { + void verifyRegistryAdded() throws Exception { root.addAccessory(accessory); - Assert.assertTrue( - "Registry does not contain accessory", - root.getRegistry().getAccessories().contains(accessory)); + assertTrue( + root.getRegistry().getAccessories().contains(accessory), + "Registry does not contain accessory"); } @Test - public void verifyRegistryRemoved() throws Exception { + void verifyRegistryRemoved() throws Exception { root.addAccessory(accessory); root.removeAccessory(accessory); - Assert.assertFalse( - "Registry still contains accessory", - root.getRegistry().getAccessories().contains(accessory)); + assertFalse( + root.getRegistry().getAccessories().contains(accessory), + "Registry still contains accessory"); } @Test - public void testWebHandlerStarts() throws Exception { + void testWebHandlerStarts() throws Exception { root.start(); verify(webHandler).start(any(HomekitClientConnectionFactory.class)); } @Test - public void testWebHandlerStops() throws Exception { + void testWebHandlerStops() throws Exception { root.start(); root.stop(); verify(webHandler).stop(); } @Test - public void testAdvertiserStarts() throws Exception { + void testAdvertiserStarts() throws Exception { final String mac = "00:00:00:00:00:00"; when(authInfo.getMac()).thenReturn(mac); when(authInfo.getSetupId()).thenReturn(SETUPID); @@ -82,14 +84,14 @@ public void testAdvertiserStarts() throws Exception { } @Test - public void testAdvertiserStops() throws Exception { + void testAdvertiserStops() throws Exception { root.start(); root.stop(); verify(advertiser).stop(); } @Test - public void testAddAccessoryResetsWeb() { + void testAddAccessoryResetsWeb() { root.start(); verify(webHandler, never()).resetConnections(); root.addAccessory(accessory); @@ -97,7 +99,7 @@ public void testAddAccessoryResetsWeb() { } @Test - public void testRemoveAccessoryResetsWeb() { + void testRemoveAccessoryResetsWeb() { root.addAccessory(accessory); root.start(); verify(webHandler, never()).resetConnections(); @@ -105,9 +107,13 @@ public void testRemoveAccessoryResetsWeb() { verify(webHandler).resetConnections(); } - @Test(expected = IndexOutOfBoundsException.class) - public void testAddIndexOneAccessory() throws Exception { - when(accessory.getId()).thenReturn(1l); - root.addAccessory(accessory); + @Test + void testAddIndexOneAccessory() throws Exception { + assertThrows( + IndexOutOfBoundsException.class, + () -> { + when(accessory.getId()).thenReturn(1l); + root.addAccessory(accessory); + }); } } diff --git a/src/test/java/io/github/hapjava/server/impl/jmdns/JmdnsHomekitAdvertiserTest.java b/src/test/java/io/github/hapjava/server/impl/jmdns/JmdnsHomekitAdvertiserTest.java index 6ad5635ae..0ed5978d3 100644 --- a/src/test/java/io/github/hapjava/server/impl/jmdns/JmdnsHomekitAdvertiserTest.java +++ b/src/test/java/io/github/hapjava/server/impl/jmdns/JmdnsHomekitAdvertiserTest.java @@ -8,8 +8,8 @@ import java.net.UnknownHostException; import javax.jmdns.JmDNS; import javax.jmdns.ServiceInfo; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; public class JmdnsHomekitAdvertiserTest { @@ -17,7 +17,7 @@ public class JmdnsHomekitAdvertiserTest { JmdnsHomekitAdvertiser subject; JmDNS jmdns; - @Before + @BeforeEach public void setup() throws UnknownHostException, IOException { jmdns = mock(JmDNS.class); subject = new JmdnsHomekitAdvertiser(jmdns); @@ -28,7 +28,7 @@ public void setup() throws UnknownHostException, IOException { * when changing discoverability causes advertising to be toggled. */ @Test - public void testSetDiscoverableAfterAdvertise() throws Exception { + void testSetDiscoverableAfterAdvertise() throws Exception { subject.setDiscoverable(false); advertise(); subject.setDiscoverable(true); @@ -40,7 +40,7 @@ public void testSetDiscoverableAfterAdvertise() throws Exception { * when changing the config index causes advertising to be toggled. */ @Test - public void testSetConfigurationIndex() throws Exception { + void testSetConfigurationIndex() throws Exception { subject.setConfigurationIndex(1); advertise(); subject.setConfigurationIndex(2); From 72144d3964b2d1a7907d278a9425a80f2e8205a5 Mon Sep 17 00:00:00 2001 From: Ben Swanson Date: Fri, 25 Aug 2023 10:01:51 +0100 Subject: [PATCH 20/25] Removed unused plugins --- pom.xml | 587 ++++++++++++++++++++++++++------------------------------ 1 file changed, 268 insertions(+), 319 deletions(-) diff --git a/pom.xml b/pom.xml index 4fc3dfe0e..bd2a2de63 100644 --- a/pom.xml +++ b/pom.xml @@ -1,351 +1,300 @@ - 4.0.0 - io.github.hap-java - hap - hap-java - Homekit Accessory Protocol for Java - 2.0.2-rako - jar - https://github.com/hap-java/HAP-Java + 4.0.0 + io.github.hap-java + hap + hap-java + Homekit Accessory Protocol for Java + 2.0.2-rako + jar + https://github.com/hap-java/HAP-Java - - UTF-8 - 4.1.42.Final - + + UTF-8 + 4.1.42.Final + - - - MIT License - http://www.opensource.org/licenses/mit-license.php - repo - - + + + MIT License + http://www.opensource.org/licenses/mit-license.php + repo + + - - scm:git:https://github.com/hap-java/HAP-Java.git - scm:git:https://github.com/hap-java/HAP-Java.git - https://github.com/hap-java/HAP-Java.git - HEAD - + + scm:git:https://github.com/hap-java/HAP-Java.git + scm:git:https://github.com/hap-java/HAP-Java.git + https://github.com/hap-java/HAP-Java.git + HEAD + - - - Andy Lintner - dev@beowulfe.com - https://github.com/beowulfe - - - Cody Cutrer - cody@cutrer.us - https://github.com/ccutrer - - - Tim Harper - timcharper@gmail.com - https://github.com/timcharper - - + + + Andy Lintner + dev@beowulfe.com + https://github.com/beowulfe + + + Cody Cutrer + cody@cutrer.us + https://github.com/ccutrer + + + Tim Harper + timcharper@gmail.com + https://github.com/timcharper + + - + - - org.slf4j - slf4j-api - 1.7.10 - + + org.slf4j + slf4j-api + 1.7.10 + - - io.netty - netty-common - ${netty.version} - + + io.netty + netty-common + ${netty.version} + - - io.netty - netty-buffer - ${netty.version} - + + io.netty + netty-buffer + ${netty.version} + - - io.netty - netty-transport - ${netty.version} - + + io.netty + netty-transport + ${netty.version} + - - io.netty - netty-handler - ${netty.version} - + + io.netty + netty-handler + ${netty.version} + - - io.netty - netty-codec - ${netty.version} - + + io.netty + netty-codec + ${netty.version} + - - io.netty - netty-codec-http - ${netty.version} - + + io.netty + netty-codec-http + ${netty.version} + - - io.netty - netty-resolver - ${netty.version} - + + io.netty + netty-resolver + ${netty.version} + - - com.nimbusds - srp6a - 2.1.0 - + + com.nimbusds + srp6a + 2.1.0 + - - org.bouncycastle - bcprov-jdk15on - 1.67 - + + org.bouncycastle + bcprov-jdk15on + 1.67 + - - net.vrallev.ecc - ecc-25519-java - 1.0.3 - + + net.vrallev.ecc + ecc-25519-java + 1.0.3 + - - javax.json - javax.json-api - 1.1.4 - + + javax.json + javax.json-api + 1.1.4 + - - org.glassfish - javax.json - 1.1.4 - + + org.glassfish + javax.json + 1.1.4 + - - org.jmdns - jmdns - 3.5.6 - + + org.jmdns + jmdns + 3.5.6 + - - org.mockito - mockito-core - 3.8.0 - test - + + org.mockito + mockito-core + 3.8.0 + test + - - org.assertj - assertj-core - 3.19.0 - test - - - org.junit.jupiter - junit-jupiter - 5.10.0 - test - + + org.assertj + assertj-core + 3.19.0 + test + + + org.junit.jupiter + junit-jupiter + 5.10.0 + test + - + - - - - com.coveo - fmt-maven-plugin - 2.9 - - - - format - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.8.0 - - 1.8 - 1.8 - - - - org.apache.maven.plugins - maven-source-plugin - 3.0.1 - - - attach-sources - - jar-no-fork - - - - - - org.apache.maven.plugins - maven-javadoc-plugin - 3.2.0 - - io.github.hapjava.server.impl - 8 - - - - attach-javadocs - - jar - - - - - - org.apache.maven.plugins - maven-scm-publish-plugin - 3.1.0 - - - scm-publish - site-deploy - - publish-scm - - - scm:git:https://github.com/hap-java/HAP-Java.git - gh-pages - - - - - - org.apache.maven.plugins - maven-site-plugin - 3.7.1 - - - stage-for-scm-publish - post-site - - stage - - - false - - - - - + + + + com.coveo + fmt-maven-plugin + 2.9 + + + + format + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.0 + + 1.8 + 1.8 + + + + org.apache.maven.plugins + maven-source-plugin + 3.0.1 + + + attach-sources + + jar-no-fork + + + + + + - - - - org.apache.maven.plugins - maven-site-plugin - - true - - - - + + + + org.apache.maven.plugins + maven-site-plugin + + true + + + + - + - - - website - https://hap-java.github.io/ - - - ossrh - https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/ - - - ossrh - https://s01.oss.sonatype.org/content/repositories/snapshots - - + + + website + https://hap-java.github.io/ + + + ossrh + https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/ + + + ossrh + https://s01.oss.sonatype.org/content/repositories/snapshots + + - - - - org.apache.maven.plugins - maven-pmd-plugin - 3.6 - - - org.apache.maven.plugins - maven-javadoc-plugin - 3.0.1 - - io.github.hapjava.server.impl - 8 - false - - - - - javadoc - - - - - - org.codehaus.mojo - findbugs-maven-plugin - 3.0.3 - - - + + + + org.apache.maven.plugins + maven-pmd-plugin + 3.6 + + + org.apache.maven.plugins + maven-javadoc-plugin + 3.0.1 + + io.github.hapjava.server.impl + 8 + false + + + + + javadoc + + + + + + org.codehaus.mojo + findbugs-maven-plugin + 3.0.3 + + + - - - ossrh - - - - org.apache.maven.plugins - maven-gpg-plugin - 1.5 - - - sign-artifacts - verify - - sign - - - - - HAP-Java - - --pinentry-mode - loopback - - - - - org.sonatype.plugins - nexus-staging-maven-plugin - 1.6.3 - true - - ossrh - https://s01.oss.sonatype.org/ - true - - - - - - + + + ossrh + + + + org.apache.maven.plugins + maven-gpg-plugin + 1.5 + + + sign-artifacts + verify + + sign + + + + + HAP-Java + + --pinentry-mode + loopback + + + + + org.sonatype.plugins + nexus-staging-maven-plugin + 1.6.3 + true + + ossrh + https://s01.oss.sonatype.org/ + true + + + + + + From 4361b4b5deaf5893ea65202915a0dd995a26a9a9 Mon Sep 17 00:00:00 2001 From: Ben Swanson Date: Fri, 20 Oct 2023 11:27:50 +0100 Subject: [PATCH 21/25] Latest version commit 773e41320bd610f4ad2596038d56ca2ec451766c Author: Ben Swanson Date: Fri Oct 20 11:26:33 2023 +0100 uint32 correction commit 28a334f84ec20058922d5816c4a8266f7990adab Author: Ben Swanson Date: Fri Oct 20 10:03:12 2023 +0100 Initial mdns state value commit 0c6c7c90677bd2bacbace60c0d83e61f057c0291 Author: Ben Swanson Date: Fri Oct 20 10:02:57 2023 +0100 Characteristic adjustments commit 730c099ecd20fd08373525e5142d7c28d628e750 Author: Ben Swanson Date: Tue Oct 17 17:19:43 2023 +0100 Update stateIndex commit f89a924d130399a127951f26cfed722ebfdde86a Author: Ben Swanson Date: Tue Oct 17 17:09:23 2023 +0100 Root setStateIndex check started commit 1f69e070df6448a86b813a8af09ae2f8ea8cb833 Author: Ben Swanson Date: Tue Oct 17 15:35:37 2023 +0100 Make registry public and implement setStateIndex commit 37d87c46d615b77e6fb246a933f073d284987bb2 Author: Ben Swanson Date: Tue Oct 17 15:16:37 2023 +0100 Update to master --- pom.xml | 8 ++--- .../impl/base/IntegerCharacteristic.java | 30 +++++++++++++++- .../impl/fan/RotationSpeedCharacteristic.java | 2 +- .../ColorTemperatureCharacteristic.java | 3 +- .../TargetPositionCharacteristic.java | 3 +- .../hapjava/server/HomekitAuthInfo.java | 4 +-- .../hapjava/server/impl/HomekitRegistry.java | 2 +- .../hapjava/server/impl/HomekitRoot.java | 21 ++++++++--- .../hapjava/server/impl/HomekitServer.java | 4 ++- .../HomekitStandaloneAccessoryServer.java | 2 +- .../impl/connections/SubscriptionManager.java | 9 ++--- .../impl/jmdns/JmdnsHomekitAdvertiser.java | 11 ++++-- .../server/impl/pairing/PairSetupManager.java | 2 +- .../impl/pairing/PairVerifyManager.java | 1 + .../server/impl/pairing/SrpHandler.java | 2 +- .../hapjava/server/impl/HomekitRootTest.java | 36 +++++++++++-------- .../jmdns/JmdnsHomekitAdvertiserTest.java | 12 +++---- 17 files changed, 106 insertions(+), 46 deletions(-) diff --git a/pom.xml b/pom.xml index bd2a2de63..2fd80788d 100644 --- a/pom.xml +++ b/pom.xml @@ -5,13 +5,13 @@ hap hap-java Homekit Accessory Protocol for Java - 2.0.2-rako + 2.0.3-rako jar https://github.com/hap-java/HAP-Java UTF-8 - 4.1.42.Final + 4.1.72.Final @@ -106,7 +106,7 @@ org.bouncycastle bcprov-jdk15on - 1.67 + 1.69 @@ -130,7 +130,7 @@ org.jmdns jmdns - 3.5.6 + 3.5.8 diff --git a/src/main/java/io/github/hapjava/characteristics/impl/base/IntegerCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/base/IntegerCharacteristic.java index 6d1b7df6d..e80c14823 100644 --- a/src/main/java/io/github/hapjava/characteristics/impl/base/IntegerCharacteristic.java +++ b/src/main/java/io/github/hapjava/characteristics/impl/base/IntegerCharacteristic.java @@ -56,6 +56,32 @@ public IntegerCharacteristic( this.setter = setter; } + public IntegerCharacteristic( + String type, + String description, + int minValue, + int maxValue, + String format, + String unit, + Optional>> getter, + Optional> setter, + Optional> subscriber, + Optional unsubscriber) { + super( + type, + format, + description, + getter.isPresent(), + setter.isPresent(), + subscriber, + unsubscriber); + this.minValue = minValue; + this.maxValue = maxValue; + this.unit = unit; + this.getter = getter; + this.setter = setter; + } + /** {@inheritDoc} */ @Override protected CompletableFuture makeBuilder(int iid) { @@ -77,7 +103,9 @@ public CompletableFuture getValue() { @Override public void setValue(Integer value) throws Exception { - if (setter.isPresent()) setter.get().accept(value); + if (setter.isPresent()) { + setter.get().accept(value); + } } /** {@inheritDoc} */ diff --git a/src/main/java/io/github/hapjava/characteristics/impl/fan/RotationSpeedCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/fan/RotationSpeedCharacteristic.java index d7a1d6929..7ef05a13c 100644 --- a/src/main/java/io/github/hapjava/characteristics/impl/fan/RotationSpeedCharacteristic.java +++ b/src/main/java/io/github/hapjava/characteristics/impl/fan/RotationSpeedCharacteristic.java @@ -30,7 +30,7 @@ public RotationSpeedCharacteristic( minValue, maxValue, minStep, - "%", + "percentage", Optional.of(getter), Optional.of(setter), Optional.of(subscriber), diff --git a/src/main/java/io/github/hapjava/characteristics/impl/lightbulb/ColorTemperatureCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/lightbulb/ColorTemperatureCharacteristic.java index 987ab5eee..b8c2d71ed 100644 --- a/src/main/java/io/github/hapjava/characteristics/impl/lightbulb/ColorTemperatureCharacteristic.java +++ b/src/main/java/io/github/hapjava/characteristics/impl/lightbulb/ColorTemperatureCharacteristic.java @@ -27,7 +27,8 @@ public ColorTemperatureCharacteristic( "color temperature", minValue, maxValue, - "mired", + "uint32", + null, Optional.of(getter), Optional.of(setter), Optional.of(subscriber), diff --git a/src/main/java/io/github/hapjava/characteristics/impl/windowcovering/TargetPositionCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/windowcovering/TargetPositionCharacteristic.java index 1e3ed2c54..826146eef 100644 --- a/src/main/java/io/github/hapjava/characteristics/impl/windowcovering/TargetPositionCharacteristic.java +++ b/src/main/java/io/github/hapjava/characteristics/impl/windowcovering/TargetPositionCharacteristic.java @@ -23,7 +23,8 @@ public TargetPositionCharacteristic( "target position", 0, 100, - "percentage", + "uint32", + null, Optional.of(getter), Optional.of(setter), Optional.of(subscriber), diff --git a/src/main/java/io/github/hapjava/server/HomekitAuthInfo.java b/src/main/java/io/github/hapjava/server/HomekitAuthInfo.java index 6441962d7..10ac5d8c9 100644 --- a/src/main/java/io/github/hapjava/server/HomekitAuthInfo.java +++ b/src/main/java/io/github/hapjava/server/HomekitAuthInfo.java @@ -4,7 +4,7 @@ import io.github.hapjava.server.impl.crypto.HAPSetupCodeUtils; import java.math.BigInteger; import java.util.Collection; -import java.util.List; +import java.util.Collections; /** * Authentication info that must be provided when constructing a new {@link HomekitServer}. You will @@ -99,7 +99,7 @@ default void createUser(String username, byte[] publicKey) { * @return the previously stored list of users. */ default Collection listUsers() { - return List.of(); + return Collections.EMPTY_LIST; } /** diff --git a/src/main/java/io/github/hapjava/server/impl/HomekitRegistry.java b/src/main/java/io/github/hapjava/server/impl/HomekitRegistry.java index afbbeb7cb..5ef547923 100644 --- a/src/main/java/io/github/hapjava/server/impl/HomekitRegistry.java +++ b/src/main/java/io/github/hapjava/server/impl/HomekitRegistry.java @@ -21,7 +21,7 @@ public class HomekitRegistry { private final String label; private final SubscriptionManager subscriptions; - private final Map accessories; + private final Map accessories; private final Map> services = new HashMap<>(); private final Map> characteristics = new HashMap<>(); diff --git a/src/main/java/io/github/hapjava/server/impl/HomekitRoot.java b/src/main/java/io/github/hapjava/server/impl/HomekitRoot.java index 36bfeefa2..884ed9268 100644 --- a/src/main/java/io/github/hapjava/server/impl/HomekitRoot.java +++ b/src/main/java/io/github/hapjava/server/impl/HomekitRoot.java @@ -38,6 +38,7 @@ public class HomekitRoot { private int configurationIndex = 1; private int nestedBatches = 0; private boolean madeChanges = false; + private int stateIndex = 1; HomekitRoot( String label, HomekitWebHandler webHandler, InetAddress host, HomekitAuthInfo authInfo) @@ -94,13 +95,17 @@ public class HomekitRoot { * completeUpdateBatch in order to publish all accumulated changes. */ public synchronized void batchUpdate() { - if (this.nestedBatches == 0) madeChanges = false; + if (this.nestedBatches == 0) { + madeChanges = false; + } ++this.nestedBatches; } /** Publish accumulated accessory changes since batchUpdate() was called. */ public synchronized void completeUpdateBatch() { - if (--this.nestedBatches == 0 && madeChanges) registry.reset(); + if (--this.nestedBatches == 0 && madeChanges) { + registry.reset(); + } } /** @@ -176,7 +181,8 @@ public void start() { authInfo.getMac(), port, configurationIndex, - authInfo.getSetupId()); + authInfo.getSetupId(), + this.stateIndex); } catch (Exception e) { throw new RuntimeException(e); } @@ -232,7 +238,14 @@ public void setConfigurationIndex(int revision) throws IOException { } } - HomekitRegistry getRegistry() { + public void setStateIndex(int stateIndex) throws IOException { + this.stateIndex = stateIndex; + if (this.started) { + advertiser.setStateIndex(stateIndex); + } + } + + public HomekitRegistry getRegistry() { return registry; } } diff --git a/src/main/java/io/github/hapjava/server/impl/HomekitServer.java b/src/main/java/io/github/hapjava/server/impl/HomekitServer.java index e0fe31fc1..b65659a11 100644 --- a/src/main/java/io/github/hapjava/server/impl/HomekitServer.java +++ b/src/main/java/io/github/hapjava/server/impl/HomekitServer.java @@ -120,13 +120,15 @@ public HomekitStandaloneAccessoryServer createStandaloneAccessory( return new HomekitStandaloneAccessoryServer(accessory, http, localAddress, authInfo); } } + public HomekitStandaloneAccessoryServer createStandaloneAccessory( HomekitAuthInfo authInfo, HomekitAccessory accessory, int category) throws IOException, ExecutionException, InterruptedException { if (jmdns != null) { return new HomekitStandaloneAccessoryServer(accessory, http, jmdns, authInfo, category); } else { - return new HomekitStandaloneAccessoryServer(accessory, http, localAddress, authInfo, category); + return new HomekitStandaloneAccessoryServer( + accessory, http, localAddress, authInfo, category); } } diff --git a/src/main/java/io/github/hapjava/server/impl/HomekitStandaloneAccessoryServer.java b/src/main/java/io/github/hapjava/server/impl/HomekitStandaloneAccessoryServer.java index 99ff7b746..4a5dbabee 100644 --- a/src/main/java/io/github/hapjava/server/impl/HomekitStandaloneAccessoryServer.java +++ b/src/main/java/io/github/hapjava/server/impl/HomekitStandaloneAccessoryServer.java @@ -40,7 +40,7 @@ public class HomekitStandaloneAccessoryServer { root = new HomekitRoot(accessory.getName().get(), webHandler, jmdns, authInfo); root.addAccessory(accessory); } - + HomekitStandaloneAccessoryServer( HomekitAccessory accessory, HomekitWebHandler webHandler, diff --git a/src/main/java/io/github/hapjava/server/impl/connections/SubscriptionManager.java b/src/main/java/io/github/hapjava/server/impl/connections/SubscriptionManager.java index 98635ce3c..4eeba81ac 100644 --- a/src/main/java/io/github/hapjava/server/impl/connections/SubscriptionManager.java +++ b/src/main/java/io/github/hapjava/server/impl/connections/SubscriptionManager.java @@ -22,9 +22,10 @@ public class SubscriptionManager { private static class ConnectionsWithIds { Set connections; - int aid, iid; + long aid; + int iid; - ConnectionsWithIds(int aid, int iid) { + ConnectionsWithIds(long aid, int iid) { this.aid = aid; this.iid = iid; this.connections = new HashSet<>(); @@ -139,7 +140,7 @@ private void flushUpdateBatch() { pendingNotifications.clear(); } - public synchronized void publish(int accessoryId, int iid, EventableCharacteristic changed) { + public synchronized void publish(long accessoryId, int iid, EventableCharacteristic changed) { final ConnectionsWithIds subscribers = subscriptions.get(changed); if (subscribers == null || subscribers.connections.isEmpty()) { LOGGER.trace("No subscribers to characteristic {} at accessory {} ", changed, accessoryId); @@ -233,7 +234,7 @@ public synchronized void resync(HomekitRegistry registry) { subscriptions.putAll(newSubscriptions); } - private void subscribe(int aid, int iid, EventableCharacteristic characteristic) { + private void subscribe(long aid, int iid, EventableCharacteristic characteristic) { characteristic.subscribe( () -> { publish(aid, iid, characteristic); diff --git a/src/main/java/io/github/hapjava/server/impl/jmdns/JmdnsHomekitAdvertiser.java b/src/main/java/io/github/hapjava/server/impl/jmdns/JmdnsHomekitAdvertiser.java index 444d1456a..eb78c854d 100644 --- a/src/main/java/io/github/hapjava/server/impl/jmdns/JmdnsHomekitAdvertiser.java +++ b/src/main/java/io/github/hapjava/server/impl/jmdns/JmdnsHomekitAdvertiser.java @@ -1,6 +1,5 @@ package io.github.hapjava.server.impl.jmdns; -import static io.github.hapjava.server.impl.HomekitServer.PROTOCOL_VERSION_BONJOUR; import static io.github.hapjava.server.impl.crypto.HAPSetupCodeUtils.generateSHA512Hash; import java.io.IOException; @@ -30,6 +29,7 @@ public class JmdnsHomekitAdvertiser { private int configurationIndex; private ServiceInfo serviceInfo; private int category; + private int stateIndex = 1; public JmdnsHomekitAdvertiser(JmDNS jmdns) { this.jmdns = jmdns; @@ -40,7 +40,13 @@ public JmdnsHomekitAdvertiser(InetAddress localAddress) throws UnknownHostExcept } public synchronized void advertise( - String label, int category, String mac, int port, int configurationIndex, String setupId) + String label, + int category, + String mac, + int port, + int configurationIndex, + String setupId, + int stateIndex) throws Exception { if (isAdvertising) { throw new IllegalStateException("HomeKit advertiser is already running"); @@ -131,6 +137,7 @@ private ServiceInfo buildServiceInfo() { props.put("md", label); props.put("sh", generateSHA512Hash(setupId + mac)); props.put("c#", Integer.toString(configurationIndex)); + props.put("s#", Integer.toString(stateIndex)); props.put("ff", "0"); props.put("ci", Integer.toString(category)); props.put("pv", "1.1"); diff --git a/src/main/java/io/github/hapjava/server/impl/pairing/PairSetupManager.java b/src/main/java/io/github/hapjava/server/impl/pairing/PairSetupManager.java index b730c2ad6..05b37b8ab 100644 --- a/src/main/java/io/github/hapjava/server/impl/pairing/PairSetupManager.java +++ b/src/main/java/io/github/hapjava/server/impl/pairing/PairSetupManager.java @@ -38,7 +38,7 @@ public HttpResponse handle(HttpRequest httpRequest) throws Exception { return new UnauthorizedResponse(); } else { try { - return srpHandler.step2((PairSetupRequest.Stage2Request) req); + return srpHandler.handle(req); } catch (Exception e) { srpHandler = null; // You don't get to try again - need a new key logger.warn("Exception encountered while processing SRP Verify Request", e); diff --git a/src/main/java/io/github/hapjava/server/impl/pairing/PairVerifyManager.java b/src/main/java/io/github/hapjava/server/impl/pairing/PairVerifyManager.java index b0f8347a8..5042132b3 100644 --- a/src/main/java/io/github/hapjava/server/impl/pairing/PairVerifyManager.java +++ b/src/main/java/io/github/hapjava/server/impl/pairing/PairVerifyManager.java @@ -14,6 +14,7 @@ import io.github.hapjava.server.impl.pairing.TypeLengthValueUtils.DecodeResult; import io.github.hapjava.server.impl.pairing.TypeLengthValueUtils.Encoder; import io.github.hapjava.server.impl.responses.NotFoundResponse; +import io.github.hapjava.server.impl.responses.OkResponse; import java.nio.charset.StandardCharsets; import java.security.SecureRandom; import org.bouncycastle.crypto.digests.SHA512Digest; diff --git a/src/main/java/io/github/hapjava/server/impl/pairing/SrpHandler.java b/src/main/java/io/github/hapjava/server/impl/pairing/SrpHandler.java index 5c1c23353..334d44f7f 100644 --- a/src/main/java/io/github/hapjava/server/impl/pairing/SrpHandler.java +++ b/src/main/java/io/github/hapjava/server/impl/pairing/SrpHandler.java @@ -82,7 +82,7 @@ private HttpResponse handleSrpVerifyRequest(SRPVerifyRequest request) throws Exc public byte[] getK() { MessageDigest digest = session.getCryptoParams().getMessageDigestInstance(); - BigInteger S = session.getSessionKey(false); + BigInteger S = session.getSessionKey(); byte[] sBytes = bigIntegerToUnsignedByteArray(S); return digest.digest(sBytes); } diff --git a/src/test/java/io/github/hapjava/server/impl/HomekitRootTest.java b/src/test/java/io/github/hapjava/server/impl/HomekitRootTest.java index 81d2666e5..2c93e9fd9 100644 --- a/src/test/java/io/github/hapjava/server/impl/HomekitRootTest.java +++ b/src/test/java/io/github/hapjava/server/impl/HomekitRootTest.java @@ -1,5 +1,8 @@ package io.github.hapjava.server.impl; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Matchers.any; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.mock; @@ -14,9 +17,8 @@ import io.github.hapjava.server.impl.http.HomekitClientConnectionFactory; import io.github.hapjava.server.impl.jmdns.JmdnsHomekitAdvertiser; import java.util.concurrent.CompletableFuture; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class HomekitRootTest { @@ -31,10 +33,10 @@ public class HomekitRootTest { private static final String LABEL = "Test Label"; - @Before + @BeforeEach public void setup() throws Exception { accessory = mock(HomekitAccessory.class); - when(accessory.getId()).thenReturn(2); + when(accessory.getId()).thenReturn(2l); webHandler = mock(HomekitWebHandler.class); when(webHandler.start(any())).thenReturn(CompletableFuture.completedFuture(PORT)); advertiser = mock(JmdnsHomekitAdvertiser.class); @@ -46,18 +48,18 @@ public void setup() throws Exception { @Test public void verifyRegistryAdded() throws Exception { root.addAccessory(accessory); - Assert.assertTrue( - "Registry does not contain accessory", - root.getRegistry().getAccessories().contains(accessory)); + assertTrue( + root.getRegistry().getAccessories().contains(accessory), + "Registry does not contain accessory"); } @Test public void verifyRegistryRemoved() throws Exception { root.addAccessory(accessory); root.removeAccessory(accessory); - Assert.assertFalse( - "Registry still contains accessory", - root.getRegistry().getAccessories().contains(accessory)); + assertFalse( + root.getRegistry().getAccessories().contains(accessory), + "Registry still contains accessory"); } @Test @@ -80,7 +82,7 @@ public void testAdvertiserStarts() throws Exception { when(authInfo.getSetupId()).thenReturn(SETUPID); root.start(); - verify(advertiser).advertise(eq(LABEL), eq(1), eq(mac), eq(PORT), eq(1), eq(SETUPID)); + verify(advertiser).advertise(eq(LABEL), eq(1), eq(mac), eq(PORT), eq(1), eq(SETUPID), eq(1)); } @Test @@ -105,9 +107,13 @@ public void testRemoveAccessoryDoesntResetWeb() { verify(webHandler, never()).resetConnections(); } - @Test(expected = IndexOutOfBoundsException.class) + @Test public void testAddIndexOneAccessory() throws Exception { - when(accessory.getId()).thenReturn(1); - root.addAccessory(accessory); + assertThrows( + IndexOutOfBoundsException.class, + () -> { + when(accessory.getId()).thenReturn(1l); + root.addAccessory(accessory); + }); } } diff --git a/src/test/java/io/github/hapjava/server/impl/jmdns/JmdnsHomekitAdvertiserTest.java b/src/test/java/io/github/hapjava/server/impl/jmdns/JmdnsHomekitAdvertiserTest.java index 870bd739b..c58b37782 100644 --- a/src/test/java/io/github/hapjava/server/impl/jmdns/JmdnsHomekitAdvertiserTest.java +++ b/src/test/java/io/github/hapjava/server/impl/jmdns/JmdnsHomekitAdvertiserTest.java @@ -9,8 +9,8 @@ import java.net.UnknownHostException; import javax.jmdns.JmDNS; import javax.jmdns.ServiceInfo; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; public class JmdnsHomekitAdvertiserTest { @@ -18,7 +18,7 @@ public class JmdnsHomekitAdvertiserTest { JmdnsHomekitAdvertiser subject; JmDNS jmdns; - @Before + @BeforeEach public void setup() throws UnknownHostException, IOException { jmdns = mock(JmDNS.class); subject = new JmdnsHomekitAdvertiser(jmdns); @@ -39,7 +39,7 @@ public void testSetDiscoverableAfterAdvertise() throws Exception { subject.setDiscoverable(false); advertise(); subject.setDiscoverable(true); - assertThat(getArgumentFromUnregister().getPropertyString("sf")).isEqualTo("0"); + assertThat(getArgumentFromUnregister().getPropertyString("sf")).isEqualTo("1"); } /* @@ -51,7 +51,7 @@ public void testSetConfigurationIndex() throws Exception { subject.setConfigurationIndex(1); advertise(); subject.setConfigurationIndex(2); - assertThat(getArgumentFromUnregister().getPropertyString("c#")).isEqualTo("1"); + assertThat(getArgumentFromUnregister().getPropertyString("c#")).isEqualTo("2"); } private ServiceInfo getArgumentFromUnregister() { @@ -61,6 +61,6 @@ private ServiceInfo getArgumentFromUnregister() { } private void advertise() throws Exception { - subject.advertise("test", 1, "00:00:00:00:00:00", 1234, 1, "1"); + subject.advertise("test", 1, "00:00:00:00:00:00", 1234, 1, "1", 1); } } From ae8bf3d243a95683aa5511f9ac52ef4375c9c069 Mon Sep 17 00:00:00 2001 From: Ben Swanson Date: Fri, 20 Oct 2023 12:37:08 +0100 Subject: [PATCH 22/25] CT range --- .../impl/lightbulb/ColorTemperatureCharacteristic.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/io/github/hapjava/characteristics/impl/lightbulb/ColorTemperatureCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/lightbulb/ColorTemperatureCharacteristic.java index b8c2d71ed..31b7cd64a 100644 --- a/src/main/java/io/github/hapjava/characteristics/impl/lightbulb/ColorTemperatureCharacteristic.java +++ b/src/main/java/io/github/hapjava/characteristics/impl/lightbulb/ColorTemperatureCharacteristic.java @@ -12,8 +12,8 @@ /** This characteristic describes color temperature in mireds */ public class ColorTemperatureCharacteristic extends IntegerCharacteristic implements EventableCharacteristic { - public static final int DEFAULT_MIN_VALUE = 50; - public static final int DEFAULT_MAX_VALUE = 400; + public static final int DEFAULT_MIN_VALUE = 100; + public static final int DEFAULT_MAX_VALUE = 555; public ColorTemperatureCharacteristic( int minValue, From 2d47fb1656d0f6912315373fd7dafdcdb4ea57c8 Mon Sep 17 00:00:00 2001 From: Ben Swanson Date: Fri, 20 Oct 2023 12:43:07 +0100 Subject: [PATCH 23/25] Update TargetPositionCharacteristic --- .../impl/windowcovering/TargetPositionCharacteristic.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/io/github/hapjava/characteristics/impl/windowcovering/TargetPositionCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/windowcovering/TargetPositionCharacteristic.java index 826146eef..9458402aa 100644 --- a/src/main/java/io/github/hapjava/characteristics/impl/windowcovering/TargetPositionCharacteristic.java +++ b/src/main/java/io/github/hapjava/characteristics/impl/windowcovering/TargetPositionCharacteristic.java @@ -23,8 +23,8 @@ public TargetPositionCharacteristic( "target position", 0, 100, - "uint32", - null, + "uint8", + "percentage", Optional.of(getter), Optional.of(setter), Optional.of(subscriber), From b6cd4621d1cdde5982124c1420801c7263c5883d Mon Sep 17 00:00:00 2001 From: Ben Swanson Date: Tue, 20 Aug 2024 10:15:19 +0100 Subject: [PATCH 24/25] Close idle connections --- .../github/hapjava/server/impl/http/impl/AccessoryHandler.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/io/github/hapjava/server/impl/http/impl/AccessoryHandler.java b/src/main/java/io/github/hapjava/server/impl/http/impl/AccessoryHandler.java index 6b840c713..ede93d271 100644 --- a/src/main/java/io/github/hapjava/server/impl/http/impl/AccessoryHandler.java +++ b/src/main/java/io/github/hapjava/server/impl/http/impl/AccessoryHandler.java @@ -42,6 +42,7 @@ public void channelActive(ChannelHandlerContext ctx) throws Exception { @Override public void channelInactive(ChannelHandlerContext ctx) throws Exception { + this.connection.close(); LOGGER.trace("Terminated HomeKit connection from " + ctx.channel().remoteAddress().toString()); super.channelInactive(ctx); } From df0289afae072dd54cc8cb2cfa2b56a31a7d2ab3 Mon Sep 17 00:00:00 2001 From: Ben Swanson Date: Mon, 9 Jun 2025 11:15:27 +0100 Subject: [PATCH 25/25] Update Netty version --- pom.xml | 4 +- pom.xml.versionsBackup | 300 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 302 insertions(+), 2 deletions(-) create mode 100644 pom.xml.versionsBackup diff --git a/pom.xml b/pom.xml index 2fd80788d..600cb07a7 100644 --- a/pom.xml +++ b/pom.xml @@ -5,13 +5,13 @@ hap hap-java Homekit Accessory Protocol for Java - 2.0.3-rako + 2.0.4-rako jar https://github.com/hap-java/HAP-Java UTF-8 - 4.1.72.Final + 4.1.121.Final diff --git a/pom.xml.versionsBackup b/pom.xml.versionsBackup new file mode 100644 index 000000000..fee8f26c1 --- /dev/null +++ b/pom.xml.versionsBackup @@ -0,0 +1,300 @@ + + + 4.0.0 + io.github.hap-java + hap + hap-java + Homekit Accessory Protocol for Java + 2.0.3-rako + jar + https://github.com/hap-java/HAP-Java + + + UTF-8 + 4.1.121.Final + + + + + MIT License + http://www.opensource.org/licenses/mit-license.php + repo + + + + + scm:git:https://github.com/hap-java/HAP-Java.git + scm:git:https://github.com/hap-java/HAP-Java.git + https://github.com/hap-java/HAP-Java.git + HEAD + + + + + Andy Lintner + dev@beowulfe.com + https://github.com/beowulfe + + + Cody Cutrer + cody@cutrer.us + https://github.com/ccutrer + + + Tim Harper + timcharper@gmail.com + https://github.com/timcharper + + + + + + + org.slf4j + slf4j-api + 1.7.10 + + + + io.netty + netty-common + ${netty.version} + + + + io.netty + netty-buffer + ${netty.version} + + + + io.netty + netty-transport + ${netty.version} + + + + io.netty + netty-handler + ${netty.version} + + + + io.netty + netty-codec + ${netty.version} + + + + io.netty + netty-codec-http + ${netty.version} + + + + io.netty + netty-resolver + ${netty.version} + + + + com.nimbusds + srp6a + 2.1.0 + + + + org.bouncycastle + bcprov-jdk15on + 1.69 + + + + net.vrallev.ecc + ecc-25519-java + 1.0.3 + + + + javax.json + javax.json-api + 1.1.4 + + + + org.glassfish + javax.json + 1.1.4 + + + + org.jmdns + jmdns + 3.5.8 + + + + org.mockito + mockito-core + 3.8.0 + test + + + + org.assertj + assertj-core + 3.19.0 + test + + + org.junit.jupiter + junit-jupiter + 5.10.0 + test + + + + + + + + com.coveo + fmt-maven-plugin + 2.9 + + + + format + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.0 + + 1.8 + 1.8 + + + + org.apache.maven.plugins + maven-source-plugin + 3.0.1 + + + attach-sources + + jar-no-fork + + + + + + + + + + + org.apache.maven.plugins + maven-site-plugin + + true + + + + + + + + + + website + https://hap-java.github.io/ + + + ossrh + https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/ + + + ossrh + https://s01.oss.sonatype.org/content/repositories/snapshots + + + + + + + org.apache.maven.plugins + maven-pmd-plugin + 3.6 + + + org.apache.maven.plugins + maven-javadoc-plugin + 3.0.1 + + io.github.hapjava.server.impl + 8 + false + + + + + javadoc + + + + + + org.codehaus.mojo + findbugs-maven-plugin + 3.0.3 + + + + + + + ossrh + + + + org.apache.maven.plugins + maven-gpg-plugin + 1.5 + + + sign-artifacts + verify + + sign + + + + + HAP-Java + + --pinentry-mode + loopback + + + + + org.sonatype.plugins + nexus-staging-maven-plugin + 1.6.3 + true + + ossrh + https://s01.oss.sonatype.org/ + true + + + + + + + +