Skip to content

Commit 2480fac

Browse files
author
Andy Lintner
committed
Initial commit.
1 parent bde3726 commit 2480fac

File tree

116 files changed

+5760
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

116 files changed

+5760
-0
lines changed

.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,14 @@
1010

1111
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
1212
hs_err_pid*
13+
14+
# Eclipse files
15+
.classpath
16+
.project
17+
.settings/
18+
19+
# Maven target folder
20+
target/
21+
22+
# Mac Files
23+
.DS_Store

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
HAP-Java
2+
=========
3+
HAP-Java is a Java implementation of the Homekit Accessory Protocol.
4+
5+
Using this library, you can create your own Homekit Accessory or Homekit Accessory Bridge.
6+
7+
Because the MFi Specification is closed to individual developers, and this implementation was made without access to that specification, it may not be complete. iOS devices do recognize and are able to interact with accessories exposed via this library however.
8+
9+
This library would not have been possible without the work done by [Tian Zhang](https://github.com/KhaosT) who did a lot of the hard work of figuring out how the protocol works in his NodeJS implementation.
10+
11+
Usage
12+
=========
13+
Read the [Javadoc](http://beowulfe.github.io/HAP-Java/apidocs/) and check out the [Sample}(https://github.com/beowulfe/HAP-Java/tree/sample).

pom.xml

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<groupId>com.beowulfe.hap</groupId>
6+
<artifactId>hap</artifactId>
7+
<name>hap-java</name>
8+
<description>Homekit Accessory Protocol for Java</description>
9+
<version>0.0.1-SNAPSHOT</version>
10+
<dependencies>
11+
12+
<dependency>
13+
<groupId>org.slf4j</groupId>
14+
<artifactId>slf4j-api</artifactId>
15+
<version>1.7.10</version>
16+
</dependency>
17+
18+
<dependency>
19+
<groupId>io.netty</groupId>
20+
<artifactId>netty-all</artifactId>
21+
<version>4.0.24.Final</version>
22+
</dependency>
23+
24+
<dependency>
25+
<groupId>com.nimbusds</groupId>
26+
<artifactId>srp6a</artifactId>
27+
<version>1.5.2</version>
28+
</dependency>
29+
30+
<dependency>
31+
<groupId>org.bouncycastle</groupId>
32+
<artifactId>bcprov-jdk15on</artifactId>
33+
<version>1.51</version>
34+
</dependency>
35+
36+
<dependency>
37+
<groupId>net.i2p.crypto</groupId>
38+
<artifactId>eddsa</artifactId>
39+
<version>0.0.1-SNAPSHOT</version>
40+
</dependency>
41+
42+
<dependency>
43+
<groupId>org.zeromq</groupId>
44+
<artifactId>curve25519-java</artifactId>
45+
<version>0.1.0</version>
46+
</dependency>
47+
48+
<dependency>
49+
<groupId>org.slf4j</groupId>
50+
<artifactId>slf4j-api</artifactId>
51+
<version>1.7.10</version>
52+
</dependency>
53+
54+
<dependency>
55+
<groupId>javax.json</groupId>
56+
<artifactId>javax.json-api</artifactId>
57+
<version>1.0</version>
58+
</dependency>
59+
60+
<dependency>
61+
<groupId>org.glassfish</groupId>
62+
<artifactId>javax.json</artifactId>
63+
<version>1.0.4</version>
64+
</dependency>
65+
66+
<dependency>
67+
<groupId>javax.jmdns</groupId>
68+
<artifactId>jmdns</artifactId>
69+
<version>3.4.2-SNAPSHOT</version>
70+
</dependency>
71+
72+
</dependencies>
73+
74+
<build>
75+
<plugins>
76+
<plugin>
77+
<groupId>org.apache.maven.plugins</groupId>
78+
<artifactId>maven-compiler-plugin</artifactId>
79+
<version>2.1</version>
80+
<configuration>
81+
<source>1.8</source>
82+
<target>1.8</target>
83+
</configuration>
84+
</plugin>
85+
<plugin>
86+
<groupId>org.apache.maven.plugins</groupId>
87+
<artifactId>maven-javadoc-plugin</artifactId>
88+
<version>2.10.1</version>
89+
<configuration>
90+
<excludePackageNames>com.beowulfe.hap.impl</excludePackageNames>
91+
</configuration>
92+
</plugin>
93+
</plugins>
94+
</build>
95+
<distributionManagement>
96+
<site>
97+
<id>website</id>
98+
<url>https://github.com/beowulfe/hap-java</url>
99+
</site>
100+
</distributionManagement>
101+
</project>
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package com.beowulfe.hap;
2+
3+
import java.util.Collection;
4+
5+
/**
6+
* Base interface for all Homekit Accessories. You can implement this interface directly, but most users will
7+
* prefer to use the more full featured interfaces in {@link com.beowulfe.hap.accessories} which include a
8+
* default implementation of {@link #getServices()}.
9+
*
10+
* @author Andy Lintner
11+
*/
12+
public interface HomekitAccessory {
13+
14+
/**
15+
* A unique identifier that must remain static across invocations to prevent errors with paired iOS devices. When used
16+
* as a child of a Bridge, this value must be greater than 1, as that ID is reserved for the Bridge itself.
17+
*
18+
* @return the unique identifier.
19+
*/
20+
int getId();
21+
22+
/**
23+
* Returns a label to display in iOS.
24+
*
25+
* @return the label.
26+
*/
27+
String getLabel();
28+
29+
/**
30+
* Performs an operation that can be used to identify the accessory. This action can be performed without
31+
* pairing.
32+
*/
33+
void identify();
34+
35+
/**
36+
* Returns a serial number to display in iOS.
37+
*
38+
* @return the serial number, or null.
39+
*/
40+
String getSerialNumber();
41+
42+
/**
43+
* Returns a model name to display in iOS.
44+
*
45+
* @return the model name, or null.
46+
*/
47+
String getModel();
48+
49+
/**
50+
* Returns a manufacturer to display in iOS.
51+
*
52+
* @return the manufacturer, or null.
53+
*/
54+
String getManufacturer();
55+
56+
/**
57+
* The collection of Services this accessory supports. Services are the primary way to interact with the accessory via
58+
* Homekit. Besides the Services offered here, the accessory will automatically include the required information service.
59+
*
60+
* This method will only be useful if you're implementing your own accessory type. For the standard accessories, use
61+
* the default implementation provided by the interfaces in {@link com.beowulfe.hap.accessories}.
62+
*
63+
* @return the collection of services.
64+
*/
65+
Collection<Service> getServices();
66+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package com.beowulfe.hap;
2+
3+
import java.math.BigInteger;
4+
5+
/**
6+
* Authentication info that must be provided when constructing a new {@link HomekitServer}. You will need to implement
7+
* this interface yourself to provide the necessary callbacks to a persistent storage mechanism. All values provided
8+
* must be constant across invocations or the accessories will require re-pairing within iOS.
9+
*
10+
* @author Andy Lintner
11+
*/
12+
public interface HomekitAuthInfo {
13+
14+
/**
15+
* A pin code used for pairing the device. This pin will be required within iOS in order to complete pairing. The numbers
16+
* cannot be sequential and should not have a repeating pattern.
17+
*
18+
* @return the pin code, in the form ###-##-###
19+
*/
20+
String getPin();
21+
22+
/**
23+
* A unique MAC address to be advertised with the Homekit information. This does not have to be the MAC address of the
24+
* network interface. You can generate this using {@link HomekitServer#generateMac()}.
25+
*
26+
* @return the unique MAC address.
27+
*/
28+
String getMac();
29+
30+
/**
31+
* The Salt that will be used when hashing the pin code to send to the client. You should generate this using
32+
* {@link HomekitServer#generateSalt()}.
33+
*
34+
* @return the Salt.
35+
*/
36+
BigInteger getSalt();
37+
38+
/**
39+
* The private key used by the server during pairing and message encryption. You should generate this using
40+
* {@link HomekitServer#generateKey()}
41+
*
42+
* @return the private key.
43+
*/
44+
byte[] getPrivateKey();
45+
46+
/**
47+
* Called during the pairing process, you should store the user and public key in a manner that the public key can later
48+
* be retrieved using {@link #getUserPublicKey(String)}. This must be stored in a persistent store as pairing will
49+
* need to be reset if the information is lost.
50+
*
51+
* @param username the iOS device's username. The value will not be meaningful to anything but iOS.
52+
* @param publicKey the iOS device's public key.
53+
*/
54+
void createUser(String username, byte[] publicKey);
55+
56+
/**
57+
* Called when an iOS device needs to remove an existing pairing. Subsequent calls to {@link #getUserPublicKey(String)} for this
58+
* username return null.
59+
*
60+
* @param username the username to delete from the persistent store.
61+
*/
62+
void removeUser(String username);
63+
64+
/**
65+
* Called when an already paired iOS device is re-connecting. The public key returned by this method will be compared
66+
* with the signature of the pair verification request to validate the device.
67+
*
68+
* @param username the username of the iOS device to retrieve the public key for.
69+
* @return the previously stored public key for this user.
70+
*/
71+
byte[] getUserPublicKey(String username);
72+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.beowulfe.hap;
2+
3+
import com.beowulfe.hap.characteristics.EventableCharacteristic;
4+
5+
/**
6+
* A callback interface for notifying subscribers that a characteristic value has changed.
7+
*
8+
* {@link EventableCharacteristic}s can be subscribed to, and in doing so, are supplied an instance of this class. Implementors
9+
* should call the {@link #changed()} method on the passed object when a subscribed characteristic changes.
10+
*
11+
* @author Andy Lintner
12+
*/
13+
@FunctionalInterface
14+
public interface HomekitCharacteristicChangeCallback {
15+
16+
/**
17+
* Call when the value of the characteristic that was subscribed to when this object was passed changes.
18+
*/
19+
public void changed();
20+
}

0 commit comments

Comments
 (0)