Skip to content

Commit 7dd0868

Browse files
yfreandylintner
authored andcommitted
#93 Fix discoverability & pairing with ios13 (#95)
Switch discoverable to false once client is authenticated
1 parent 58d068a commit 7dd0868

File tree

4 files changed

+7
-14
lines changed

4 files changed

+7
-14
lines changed

src/main/java/io/github/hapjava/impl/connections/HttpSession.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ public HttpResponse handleRequest(HttpRequest request) throws IOException {
6666
}
6767

6868
public HttpResponse handleAuthenticatedRequest(HttpRequest request) throws IOException {
69+
advertiser.setDiscoverable(
70+
false); // brigde is already bound and should not be discoverable anymore
6971
try {
7072
switch (request.getUri()) {
7173
case "/accessories":
@@ -101,7 +103,7 @@ private HttpResponse handlePairSetup(HttpRequest request) {
101103
if (pairingManager == null) {
102104
synchronized (HttpSession.class) {
103105
if (pairingManager == null) {
104-
pairingManager = new PairingManager(authInfo, registry, advertiser);
106+
pairingManager = new PairingManager(authInfo, registry);
105107
}
106108
}
107109
}

src/main/java/io/github/hapjava/impl/json/AccessoryController.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,7 @@ private CompletableFuture<JsonObject> toJson(Service service, int interfaceId) t
8181
.thenApply(
8282
v -> {
8383
JsonArrayBuilder jsonCharacteristics = Json.createArrayBuilder();
84-
characteristicFutures
85-
.stream()
84+
characteristicFutures.stream()
8685
.map(future -> future.join())
8786
.forEach(c -> jsonCharacteristics.add(c));
8887
builder.add("characteristics", jsonCharacteristics);

src/main/java/io/github/hapjava/impl/pairing/FinalPairHandler.java

+1-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import io.github.hapjava.HomekitAuthInfo;
44
import io.github.hapjava.impl.crypto.*;
55
import io.github.hapjava.impl.http.HttpResponse;
6-
import io.github.hapjava.impl.jmdns.JmdnsHomekitAdvertiser;
76
import io.github.hapjava.impl.pairing.PairSetupRequest.Stage3Request;
87
import io.github.hapjava.impl.pairing.TypeLengthValueUtils.DecodeResult;
98
import io.github.hapjava.impl.pairing.TypeLengthValueUtils.Encoder;
@@ -16,14 +15,12 @@ class FinalPairHandler {
1615

1716
private final byte[] k;
1817
private final HomekitAuthInfo authInfo;
19-
private final JmdnsHomekitAdvertiser advertiser;
2018

2119
private byte[] hkdf_enc_key;
2220

23-
public FinalPairHandler(byte[] k, HomekitAuthInfo authInfo, JmdnsHomekitAdvertiser advertiser) {
21+
public FinalPairHandler(byte[] k, HomekitAuthInfo authInfo) {
2422
this.k = k;
2523
this.authInfo = authInfo;
26-
this.advertiser = advertiser;
2724
}
2825

2926
public HttpResponse handle(PairSetupRequest req) throws Exception {
@@ -66,7 +63,6 @@ private HttpResponse createUser(byte[] username, byte[] ltpk, byte[] proof) thro
6663
throw new Exception("Invalid signature");
6764
}
6865
authInfo.createUser(authInfo.getMac() + new String(username, StandardCharsets.UTF_8), ltpk);
69-
advertiser.setDiscoverable(false);
7066
return createResponse();
7167
}
7268

src/main/java/io/github/hapjava/impl/pairing/PairingManager.java

+2-6
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import io.github.hapjava.impl.HomekitRegistry;
55
import io.github.hapjava.impl.http.HttpRequest;
66
import io.github.hapjava.impl.http.HttpResponse;
7-
import io.github.hapjava.impl.jmdns.JmdnsHomekitAdvertiser;
87
import io.github.hapjava.impl.responses.NotFoundResponse;
98
import io.github.hapjava.impl.responses.UnauthorizedResponse;
109
import org.slf4j.Logger;
@@ -16,15 +15,12 @@ public class PairingManager {
1615

1716
private final HomekitAuthInfo authInfo;
1817
private final HomekitRegistry registry;
19-
private final JmdnsHomekitAdvertiser advertiser;
2018

2119
private SrpHandler srpHandler;
2220

23-
public PairingManager(
24-
HomekitAuthInfo authInfo, HomekitRegistry registry, JmdnsHomekitAdvertiser advertiser) {
21+
public PairingManager(HomekitAuthInfo authInfo, HomekitRegistry registry) {
2522
this.authInfo = authInfo;
2623
this.registry = registry;
27-
this.advertiser = advertiser;
2824
}
2925

3026
public HttpResponse handle(HttpRequest httpRequest) throws Exception {
@@ -54,7 +50,7 @@ public HttpResponse handle(HttpRequest httpRequest) throws Exception {
5450
logger.warn("Received unexpected stage 3 request for " + registry.getLabel());
5551
return new UnauthorizedResponse();
5652
} else {
57-
FinalPairHandler handler = new FinalPairHandler(srpHandler.getK(), authInfo, advertiser);
53+
FinalPairHandler handler = new FinalPairHandler(srpHandler.getK(), authInfo);
5854
try {
5955
return handler.handle(req);
6056
} catch (Exception e) {

0 commit comments

Comments
 (0)