File tree Expand file tree Collapse file tree 3 files changed +25
-1
lines changed
src/main/java/io/github/hapjava/server Expand file tree Collapse file tree 3 files changed +25
-1
lines changed Original file line number Diff line number Diff line change 11package io .github .hapjava .server ;
22
33import io .github .hapjava .server .impl .HomekitServer ;
4+ import io .github .hapjava .server .impl .crypto .HAPSetupCodeUtils ;
45import java .math .BigInteger ;
56
67/**
@@ -27,7 +28,9 @@ public interface HomekitAuthInfo {
2728 *
2829 * @return setup id
2930 */
30- String getSetupId ();
31+ default String getSetupId () {
32+ return HAPSetupCodeUtils .generateSetupId ();
33+ }
3134
3235 /**
3336 * A unique MAC address to be advertised with the HomeKit information. This does not have to be
Original file line number Diff line number Diff line change 55import org .bouncycastle .crypto .digests .SHA512Digest ;
66
77public class HAPSetupCodeUtils {
8+ private static final String ALPHA_NUMERIC_STRING = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" ;
9+
10+ public static String randomAlphaNumeric (int count ) {
11+ StringBuilder builder = new StringBuilder ();
12+ while (count -- != 0 ) {
13+ int character = (int ) (Math .random () * ALPHA_NUMERIC_STRING .length ());
14+ builder .append (ALPHA_NUMERIC_STRING .charAt (character ));
15+ }
16+ return builder .toString ();
17+ }
18+
19+ public static String generateSetupId () {
20+ String setupId =
21+ ""
22+ + ALPHA_NUMERIC_STRING .charAt ((int ) (Math .random () * ALPHA_NUMERIC_STRING .length ()))
23+ + ALPHA_NUMERIC_STRING .charAt ((int ) (Math .random () * ALPHA_NUMERIC_STRING .length ()))
24+ + ALPHA_NUMERIC_STRING .charAt ((int ) (Math .random () * ALPHA_NUMERIC_STRING .length ()))
25+ + ALPHA_NUMERIC_STRING .charAt ((int ) (Math .random () * ALPHA_NUMERIC_STRING .length ()));
26+ return setupId ;
27+ }
828
929 private static byte [] calculateHash (final String input , final Digest digest ) {
1030 byte [] inputAsBytes = input .getBytes ();
Original file line number Diff line number Diff line change @@ -84,6 +84,7 @@ public synchronized void setConfigurationIndex(int revision) throws IOException
8484
8585 private void registerService () throws IOException {
8686 logger .info ("Registering " + SERVICE_TYPE + " on port " + port );
87+ logger .trace ("MAC:" + mac + " Setup Id:" + setupId );
8788 Map <String , String > props = new HashMap <>();
8889 props .put ("sf" , discoverable ? "1" : "0" );
8990 props .put ("id" , mac );
You can’t perform that action at this time.
0 commit comments