File tree Expand file tree Collapse file tree 2 files changed +37
-0
lines changed
src/main/java/com/beowulfe/hap Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -149,4 +149,14 @@ public static byte[] generateKey() throws InvalidAlgorithmParameterException {
149149 public static String generateMac () {
150150 return HomekitUtils .generateMac ();
151151 }
152+
153+ /**
154+ * Generates a value to supply in {@link HomekitAuthInfo#getPin() HomekitAuthInfo.getPin()}. This
155+ * is used as the Pin a user enters into their Homekit device in order to confirm pairing.
156+ *
157+ * @return the generated Pin
158+ */
159+ public static String generatePin () {
160+ return HomekitUtils .generatePin ();
161+ }
152162}
Original file line number Diff line number Diff line change @@ -35,6 +35,33 @@ public static String generateMac() {
3535 .collect (Collectors .joining (":" ));
3636 }
3737
38+ public static String generatePin () {
39+ String pin =
40+ String .format (
41+ "%03d-%02d-%03d" ,
42+ getSecureRandom ().nextInt (1000 ),
43+ getSecureRandom ().nextInt (100 ),
44+ getSecureRandom ().nextInt (1000 ));
45+
46+ if (pin == "000-00-000"
47+ || pin == "111-11-111"
48+ || pin == "222-22-222"
49+ || pin == "333-33-333"
50+ || pin == "444-44-444"
51+ || pin == "555-55-555"
52+ || pin == "666-66-666"
53+ || pin == "777-77-777"
54+ || pin == "888-88-888"
55+ || pin == "999-99-999"
56+ || pin == "123-45-678"
57+ || pin == "876-54-321" ) {
58+ // disallowed Pin; just recurse and generate a new one
59+ return generatePin ();
60+ }
61+
62+ return pin ;
63+ }
64+
3865 private static SecureRandom getSecureRandom () {
3966 if (secureRandom == null ) {
4067 synchronized (HomekitUtils .class ) {
You can’t perform that action at this time.
0 commit comments