Skip to content

#93 Fix discoverability & pairing with ios13 #95

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ public HttpResponse handleRequest(HttpRequest request) throws IOException {
}

public HttpResponse handleAuthenticatedRequest(HttpRequest request) throws IOException {
advertiser.setDiscoverable(
false); // brigde is already bound and should not be discoverable anymore
try {
switch (request.getUri()) {
case "/accessories":
Expand Down Expand Up @@ -101,7 +103,7 @@ private HttpResponse handlePairSetup(HttpRequest request) {
if (pairingManager == null) {
synchronized (HttpSession.class) {
if (pairingManager == null) {
pairingManager = new PairingManager(authInfo, registry, advertiser);
pairingManager = new PairingManager(authInfo, registry);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ private CompletableFuture<JsonObject> toJson(Service service, int interfaceId) t
.thenApply(
v -> {
JsonArrayBuilder jsonCharacteristics = Json.createArrayBuilder();
characteristicFutures
.stream()
characteristicFutures.stream()
.map(future -> future.join())
.forEach(c -> jsonCharacteristics.add(c));
builder.add("characteristics", jsonCharacteristics);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import io.github.hapjava.HomekitAuthInfo;
import io.github.hapjava.impl.crypto.*;
import io.github.hapjava.impl.http.HttpResponse;
import io.github.hapjava.impl.jmdns.JmdnsHomekitAdvertiser;
import io.github.hapjava.impl.pairing.PairSetupRequest.Stage3Request;
import io.github.hapjava.impl.pairing.TypeLengthValueUtils.DecodeResult;
import io.github.hapjava.impl.pairing.TypeLengthValueUtils.Encoder;
Expand All @@ -16,14 +15,12 @@ class FinalPairHandler {

private final byte[] k;
private final HomekitAuthInfo authInfo;
private final JmdnsHomekitAdvertiser advertiser;

private byte[] hkdf_enc_key;

public FinalPairHandler(byte[] k, HomekitAuthInfo authInfo, JmdnsHomekitAdvertiser advertiser) {
public FinalPairHandler(byte[] k, HomekitAuthInfo authInfo) {
this.k = k;
this.authInfo = authInfo;
this.advertiser = advertiser;
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import io.github.hapjava.impl.HomekitRegistry;
import io.github.hapjava.impl.http.HttpRequest;
import io.github.hapjava.impl.http.HttpResponse;
import io.github.hapjava.impl.jmdns.JmdnsHomekitAdvertiser;
import io.github.hapjava.impl.responses.NotFoundResponse;
import io.github.hapjava.impl.responses.UnauthorizedResponse;
import org.slf4j.Logger;
Expand All @@ -16,15 +15,12 @@ public class PairingManager {

private final HomekitAuthInfo authInfo;
private final HomekitRegistry registry;
private final JmdnsHomekitAdvertiser advertiser;

private SrpHandler srpHandler;

public PairingManager(
HomekitAuthInfo authInfo, HomekitRegistry registry, JmdnsHomekitAdvertiser advertiser) {
public PairingManager(HomekitAuthInfo authInfo, HomekitRegistry registry) {
this.authInfo = authInfo;
this.registry = registry;
this.advertiser = advertiser;
}

public HttpResponse handle(HttpRequest httpRequest) throws Exception {
Expand Down Expand Up @@ -54,7 +50,7 @@ public HttpResponse handle(HttpRequest httpRequest) throws Exception {
logger.warn("Received unexpected stage 3 request for " + registry.getLabel());
return new UnauthorizedResponse();
} else {
FinalPairHandler handler = new FinalPairHandler(srpHandler.getK(), authInfo, advertiser);
FinalPairHandler handler = new FinalPairHandler(srpHandler.getK(), authInfo);
try {
return handler.handle(req);
} catch (Exception e) {
Expand Down