Git Product home page Git Product logo

hap's Introduction

Homekit Accessory Protocol, implemented in Swift

The goal of this package is to provide a complete implementation of the Homekit Accessory Protocol, enabling you to build your DIY accessories, and connect your non-HAP devices.

Build Status Maintainability Rating

Features

  • Persistent configuration across reboots.
  • Homekit pairing by scanning QR code (shipped in iOS 11).
  • Speakers and Remote Control accessories (shipped in iOS 12 / macOS Mojave).
  • Television accessories (shipped in iOS 12.2 / macOS 10.14.3).
  • Extensibility through custom services and characteristics.
  • Runs on Linux / Raspbian (Raspberry Pi).

Communication

Remember that this is not a commercial product, but the result of free labor.

  • If you need help using this library, open an issue here on GitHub. The more detail the better!
  • If you found a bug, open an issue here on GitHub. The more detail the better!
  • If you want to contribute, submit a pull request.

Contents

Credits

This library was written by Bouke Haarsma and contributors.

hap's People

Contributors

bouke avatar gbrooker avatar kyleleneau avatar makleso6 avatar mayerhofer-dev avatar mdaxter avatar moflo avatar piotr-sekara avatar tgu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

hap's Issues

Possible dependency error in Package.swift

I don't build on linux, but spotted this in the linux section of Package.swift
package.targets[0].dependencies.append("NetService")
Shouldn't that be
package.targets[1].dependencies.append("NetService")
now that CQRCode is the first (i.e [0]) target ?

Correctly unsubscribe when closing connection

Currently when a connection is closed, the subscriptions on characteristics remain. These subscriptions should be removed when the connection is closed. I feel this should be resolved while also tackling #5.

Remove all pairings if no admins remain

When the last admin pairing is removed, all other non-admin pairings should be removed as well. Per HAP specification (page 54):

If the last remaining admin controller pairing is removed, all pairings on the accessory must be removed.

Linux error since last commit

Hi,

Since the last issue there is some compiling issues.

1st issue (Solved)

./HAP/.build/checkouts/Cdns_sd.git--79080462313159224/shim.h:1:10: error: 'dns_sd.h' file not found
#include <dns_sd.h>
^
./HAP/.build/checkouts/NetService.git-3665721673043840872/Sources/NetService/NetService.swift:13:8: error: could not build C module 'Cdns_sd'
import Cdns_sd

I solved that issue with sudo apt-get install libavahi-compat-libdnssd-dev

Second issue:

./HAP/Sources/HAP/Server/Server.swift:67:41: error: cannot convert value of type '[String : String]' to expected argument type 'Data?'
service.setTXTRecord(device.config)
~~~~~~~^~~~~~

Same issue on both x86 and arm platform

Cannot add bridge if the name contains a space

Hi,

I found an odd issue where if the Device's .bridgeInfo contains a space, it will fail to get added correctly in the Home app (iOS11). Looking at the actual network requests, it appears that the Host header from the iOS device trying to add the bridge is not being processed correctly: it contains the literal string \032 in the header: Host: hk\032test._hap._tcp.local\r\n, and (presumably) the HTTP processing library isn't handling this correctly. I have no idea if this is actually legal in the HTTP spec, but it appears to not cause problems with other devices/libraries (e.g. my Ikea TRADFRI does this without issue).

The easiest fix here is probably to just disallow spaces in the bridge name; I think the ideal solution is correctly handling such a header in the HTTP library but that's probably an upstream issue.

Use Swift-NIO for HTTP parsing

It looks like swift-nio implements an HTTP parser. Using this, we can replace our outdated fork of Kitura-net and update other dependencies (e.g. BlueSocket).

NIO Precondition fails on first pairing

I am trying to pair with the home app, but i am facing a little snag.
Just finished following the steps to build the project on my mac, created an xcode project for debugging, this is what happens when i run hap-server

➜  hap-server git:(master) ✗ swift run hap-server
'CLibSodium' /Users/btg/Documents/GitHub/HAP/.build/checkouts/CLibSodium: warning: system packages are deprecated; use system library targets instead
[hap.device|ERROR] Error reading configuration data: ENOENT, using default configuration instead
[hap.http|DEBUG] binding listening port...
[hap.http|DEBUG] bound, listening on 8000
Initializing the server...

Scan the following QR code using your iPhone to pair this device:

▄▄▄▄▄▄▄ ▄▄▄▄▄ ▄▄▄▄▄▄▄
█ ▄▄▄ █ ██ █▄ █ ▄▄▄ █
█ ███ █ ▄ ███ █ ███ █
█▄▄▄▄▄█ ▄ ▄▀█ █▄▄▄▄▄█
▄  ▄▄▄▄▄▄▄  ▀▄  ▄ ▄▄▄
  ▄▀▄▄▄█ ▀█ ▄▄▀█▀█▀▄▄
▀ ▀█▀▄▄ ▄▀ ▄ █▀▄▄█▀▀▀
▄▄▄▄▄▄▄ █ ▀▄▄ █▄▄█▀ ▀
█ ▄▄▄ █ ██▄▄▀▄█▄█▀   
█ ███ █ ▀▄▀▄███▀▄▀▄▄▄
█▄▄▄▄▄█ ▄ ▄█▀▀▀  █ █ 

i take my phone out, point to the screen.

[hap.nio|INFO] Controller [IPv6]::ffff:10.11.175.194/::ffff:10.11.175.194:60975 connected, 1 controllers total
[hap.device|INFO] State change from: notPaired to pairing
[hap.controllers.pair-setup|INFO] Pair setup started
[hap.controllers.pair-setup|DEBUG] <-- s bf2affeee21fe81523abbd824161c8bf
[hap.controllers.pair-setup|DEBUG] <-- B f09a3b04b742df5cdb6ace0dbae1b5b94d2d3f3e97bedaccb63511b0720cd1186e852bd6301701f112fcf9190a36cae440df89281551ce24d4fbba900df0766e483f05e5b0d1ab709946860aa6ec8b534e85f038bf20ecfb027ce550def8ff5dfd722c09f98bdb1286b5465a049e40e6aff200f82ac79fa208a4988179b764b8924bdee87d18005a6430b55d46dd8d6158d3aadc0f804b3b204209519607baa33d9edcd992c5055d002be2d0e3a709bcc0dfdb947d5d221f56e802f7051eada44d4debf8b556abd42f0b776e0777f8396965464abb80473f73383dc9991886f6172c90422f250e64ae5e5fd9b2c73c637254cdc389c17bb1908ecd5926e2a9dcf560c62944c93174f8839f3b4458f0dec4681a7f43cb0b10a5ca28105241a6c42ad40945216cc07c2af8973f9d6abad6954f657a034f7261c758c849b92cfe6a07d3bcd5bde99a4b9027b22245885423b0f22e4b7b580210dcbbf48d2afd80a7a2c4afaa3a324cf30710b61577cebde2a37fa994037b795029219de791f3f842

Ok, seems to be pairing, then this happens:

Precondition failed: file /Users/btg/Documents/GitHub/HAP/.build/checkouts/swift-nio/Sources/NIO/ChannelPipeline.swift, line 153
[hap.endpoints|INFO] [IPv6]::ffff:10.11.175.194/::ffff:10.11.175.194:60975 POST /pair-setup 200 409
[hap.endpoints|DEBUG] Response Message: -

i am not sure if i am missing some key configuration not covered in the instalation process, what should i do?

Print QR code in terminal on startup

Now that we have auto-setup using QR codes, it would be nice to print QR codes in the terminal, or at least a clickable URL to generate a QR code online.

Stop using Box<> / ObjectIdentifier for subscribers

I don't like the way this is implemented as a result of Characteristic being a protocol, therefore not being able to participate in heterogeneous collections. Possible alternatives:

  • Store subscribers on the characteristic themselves -- however I don't like having the characteristics keeping a reference to the connections
  • Some other way of identifying characteristics, we must know which connections subscribed to which characteristics

Linux support

Status:

  • No CommonCrypto on Linux, use BlueCryptor to abstract over CommonCrypto/OpenSSL
  • NSNetService, see https://github.com/Bouke/NetService for an implementation Swift
  • JSONSerialization works with different base types
  • Use BlueSocket instead of InputStream/OutputStream

Linux running issue

Hi,

I'm trying to run the project on ubuntu 16.10.0 without success, I already got the message "Illegal instruction (core dumped)"

How to add HAP as a dependency in Swift Package Manager?

I'm new to this and the Readme file doesn't really show. Could you explain how I'm supposed to add HAP as a library to my dependencies list in Swift's Package Manager? Maybe add the instructions to the Readme for other people that are as noob as I am? :)

Thanks!

Improve documentation

Some work has been done in this regard. According to jazzy, currently 2% is documented.

Delete pairings when requested

It logs a deletion, however nothing is deleted...

[hap.endpoints.pairings|DEBUG] Updating pairings data: [HAP.PairTag.state: 1 bytes, HAP.PairTag.pairingMethod: 1 bytes, HAP.PairTag.identifier: 36 bytes], method: removePairing
[hap.endpoints.pairings|INFO] Removed pairing for ...
[hap.endpoints|INFO] 10.0.1.33 POST /pairings - 200 3
[hap.endpoints.pairings|DEBUG] Updating pairings data: [HAP.PairTag.state: 1 bytes, HAP.PairTag.pairingMethod: 1 bytes, HAP.PairTag.identifier: 36 bytes], method: removePairing
[hap.endpoints.pairings|INFO] Removed pairing for ...
[hap.endpoints|INFO] 10.0.1.33 POST /pairings - 200 3
[hap.endpoints.pairings|DEBUG] Updating pairings data: [HAP.PairTag.state: 1 bytes, HAP.PairTag.pairingMethod: 1 bytes, HAP.PairTag.identifier: 36 bytes], method: removePairing
[hap.endpoints.pairings|INFO] Removed pairing for ...
[hap.endpoints|INFO] 10.0.1.33 POST /pairings - 200 3

Extending CharacteristicType

I am implementing a custom outlet accessory that measures both power and energy. For that reason CharacteristicType is extended with .watt and . kiloWattHour. Since there is no way to extend an enum this has to be done in the HAP library. It would however be desirable if you could avoid creating custom versions of the library, especially since I am using the proprietary characteristics and their UUIDs used by Elgato Eve, partly documented by gomfunkel. This way the energy sensor shows up in their app.

extension Accessory {
   open class Energy: Accessory {
       public let energy = Service.Energy()
       
       public init(info: Service.Info) {
           super.init(info: info, type: .outlet, services: [energy])
       }
   }
}

extension Service {
   open class Energy: Service {
       public let on = GenericCharacteristic<Bool>(type: .on, value: false)
       public let inUse = GenericCharacteristic<Bool>(type: .outletInUse, value: true, permissions: [.read, .events])
       public let watt = GenericCharacteristic<Double>(type: .watt, value: 0, permissions: [.read, .events])
       public let kiloWattHour = GenericCharacteristic<Double>(type: .kiloWattHour, value: 0, permissions: [.read, .events])
       
       public init() {
           super.init(type: .outlet, characteristics: [on, inUse, watt, kiloWattHour])
       }
   }
}

Another problem is that Accessory.init seems to be internal and cannot be called outside the library, changing the permission opens a can of worms.

Persist device config

See also the specs for c# and other mDNS fields. Also; should we serialize the instance IDs so we can re-assign them? Should we support adding/removing accessories dynamically?

Building on High Sierra

Hi there,

Just as a note (maybe include this in the readme?), to build on High Sierra, you need to include some compiler/linker flags:

swift build -Xswiftc -I/usr/local/opt/libsodium/include -Xlinker -L/usr/local/opt/libsodium/lib

To generate an Xcode project:

swift package -Xswiftc -I/usr/local/opt/libsodium/include -Xlinker -L/usr/local/opt/libsodium/lib generate-xcodeproj

Upgrade NIO to v2

NIO released a new major version (v2), which includes some breaking API changes affecting us. This issue tracks the progress of upgrading to v2.

Question: Why JSONSerializable vs Codable?

How come you have a seemingly custom JSONSerializable interface over using Codable? Is it due to the type support and what have you found as a limitation:

extension Array: JSONValueType { }
extension Dictionary: JSONValueType { }
extension String: JSONValueType { }
extension Bool: JSONValueType { }
extension Int: JSONValueType { }
extension UInt8: JSONValueType { }
extension UInt16: JSONValueType { }
extension UInt32: JSONValueType { }
extension Float: JSONValueType { }
extension Double: JSONValueType { }
extension NSNull: JSONValueType { }

Maintain instance ids assignments between restarts

From the HAP specification 2.6.1.2:

After a firmware update services and characteristics types that remain unchanged must retain their previous instance ids, newly added services and characteristics must not reuse instance ids from services and characteristics that were removed in the firmware update.

We currently reassign instance ids.

NIO stack - decryption failing

I'm moving my project over to the new master, but am seeing issues with the NIO stack. I am able to pair with a controller, but HAP gets into an infinite loop reverifying connections over and over, preceded by the following message:

[hap.nio|WARNING] Could not decrypt message from [IPv6]::ffff:10.0.8.144/::ffff:10.0.8.144:62546, closing connection.

Here is a log extract after pairing. The bridge worked fine in the same HomeKit network and config with the previous network stack. Any pointers on where to look in the NIO code for what is causing this problem ?

[hap.controllers.pair-verify|DEBUG] startRequest result: [(HAP.PairTag.identifier, 17 bytes), (HAP.PairTag.signature, 64 bytes)]
[hap.controllers.pair-verify|DEBUG] startRequest result: [(HAP.PairTag.identifier, 17 bytes), (HAP.PairTag.signature, 64 bytes)]
[hap.controllers.pair-verify|DEBUG] startRequest encrypted result: [(HAP.PairTag.state, 1 bytes), (HAP.PairTag.publicKey, 32 bytes), (HAP.PairTag.encryptedData, 101 bytes)]
[hap.controllers.pair-verify|DEBUG] startRequest encrypted result: [(HAP.PairTag.state, 1 bytes), (HAP.PairTag.publicKey, 32 bytes), (HAP.PairTag.encryptedData, 101 bytes)]
[hap.endpoints|INFO] [IPv6]::ffff:10.0.8.8/::ffff:10.0.8.8:50174 POST /pair-verify 200 140
[hap.endpoints|INFO] [IPv6]::ffff:10.0.8.129/::ffff:10.0.8.129:61615 POST /pair-verify 200 140
[hap.controllers.pair-verify|DEBUG] --> username EC48906B-6BEB-4265-97E7-08ADD3E17285
[hap.controllers.pair-verify|DEBUG] --> signature bce6131ba373bc8398c55959d3ca62380975a39a58839d0b1b7023f1b46562e7089039e31d9afd897105d3dbee294715d942fe90455e0f869e2a94b86f8b470d
[hap.controllers.pair-verify|DEBUG] --> public key effeff36f977b12c5ecf7cc536d3bcf9eabc41295768fa88815f4249d205c042
[hap.controllers.pair-verify|INFO] Pair verify completed
[hap.endpoints|INFO] [IPv6]::ffff:10.0.8.8/::ffff:10.0.8.8:50174 POST /pair-verify 200 3
[hap.encryption|INFO] Decrypt message #0, length: 95
[hap.endpoints|INFO] [IPv6]::ffff:10.0.8.8/::ffff:10.0.8.8:50174 GET /accessories 200 11414
[hap.encryption|INFO] Encrypt message #0, length: 139
[hap.encryption|INFO] Encrypt message #1, length: 11414
[hap.encryption|INFO] Encrypt message #13, length: 0
[hap.controllers.pair-verify|DEBUG] --> username EC48906B-6BEB-4265-97E7-08ADD3E17285
[hap.controllers.pair-verify|DEBUG] --> signature c65026bf90f4de0ffb1bac0b449b21587710731c7fb2383139848ed9b37d23e5c830ec9d967f8c4fe9f60025078927098c7e7c1b4e9a6c0c007163e86e76fc0e
[hap.controllers.pair-verify|DEBUG] --> public key effeff36f977b12c5ecf7cc536d3bcf9eabc41295768fa88815f4249d205c042
[hap.controllers.pair-verify|INFO] Pair verify completed
[hap.endpoints|INFO] [IPv6]::ffff:10.0.8.129/::ffff:10.0.8.129:61615 POST /pair-verify 200 3
[hap.encryption|INFO] Decrypt message #0, length: 95
[hap.endpoints|INFO] [IPv6]::ffff:10.0.8.129/::ffff:10.0.8.129:61615 GET /accessories 200 11414
[hap.encryption|INFO] Encrypt message #0, length: 139
[hap.encryption|INFO] Encrypt message #1, length: 11414
[hap.encryption|INFO] Encrypt message #13, length: 0
[hap.controllers.pair-verify|DEBUG] startRequest result: [(HAP.PairTag.identifier, 17 bytes), (HAP.PairTag.signature, 64 bytes)]
[hap.controllers.pair-verify|DEBUG] startRequest encrypted result: [(HAP.PairTag.state, 1 bytes), (HAP.PairTag.publicKey, 32 bytes), (HAP.PairTag.encryptedData, 101 bytes)]
[hap.endpoints|INFO] [IPv6]::ffff:10.0.8.121/::ffff:10.0.8.121:54402 POST /pair-verify 200 140
[hap.controllers.pair-verify|DEBUG] startRequest result: [(HAP.PairTag.identifier, 17 bytes), (HAP.PairTag.signature, 64 bytes)]
[hap.controllers.pair-verify|DEBUG] startRequest encrypted result: [(HAP.PairTag.state, 1 bytes), (HAP.PairTag.publicKey, 32 bytes), (HAP.PairTag.encryptedData, 101 bytes)]
[hap.endpoints|INFO] [IPv6]::ffff:10.0.8.144/::ffff:10.0.8.144:62546 POST /pair-verify 200 140
[hap.controllers.pair-verify|DEBUG] --> username EC48906B-6BEB-4265-97E7-08ADD3E17285
[hap.controllers.pair-verify|DEBUG] --> signature e3997b59368143de8abdb984cbe40b55d06d275f6330f110b12106cf216193d0fb1bb263bad0ba5a15c5f36186e0735d46a5c3f5b4180bc4931703583f28c100
[hap.controllers.pair-verify|DEBUG] --> public key effeff36f977b12c5ecf7cc536d3bcf9eabc41295768fa88815f4249d205c042
[hap.controllers.pair-verify|INFO] Pair verify completed
[hap.endpoints|INFO] [IPv6]::ffff:10.0.8.121/::ffff:10.0.8.121:54402 POST /pair-verify 200 3
[hap.encryption|INFO] Decrypt message #0, length: 95
[hap.endpoints|INFO] [IPv6]::ffff:10.0.8.121/::ffff:10.0.8.121:54402 GET /accessories 200 11414
[hap.encryption|INFO] Encrypt message #0, length: 139
[hap.encryption|INFO] Encrypt message #1, length: 11414
[hap.encryption|INFO] Encrypt message #13, length: 0
[hap.controllers.pair-verify|DEBUG] --> username EC48906B-6BEB-4265-97E7-08ADD3E17285
[hap.controllers.pair-verify|DEBUG] --> signature 9e2e43882e426689271e54e3c42ccef78d9e098e812673ea643ac11be8f25cfa27c98a152bb0884b22615aa941ba1525270c05e7773d3072f9127acb1d029802
[hap.controllers.pair-verify|DEBUG] --> public key effeff36f977b12c5ecf7cc536d3bcf9eabc41295768fa88815f4249d205c042
[hap.controllers.pair-verify|INFO] Pair verify completed
[hap.endpoints|INFO] [IPv6]::ffff:10.0.8.144/::ffff:10.0.8.144:62546 POST /pair-verify 200 3
[hap.encryption|INFO] Decrypt message #0, length: 95
[hap.endpoints|INFO] [IPv6]::ffff:10.0.8.144/::ffff:10.0.8.144:62546 GET /accessories 200 11414
[hap.encryption|INFO] Encrypt message #0, length: 139
[hap.encryption|INFO] Encrypt message #1, length: 11414
[hap.encryption|INFO] Encrypt message #13, length: 0
[hap.controllers.pair-verify|DEBUG] startRequest result: [(HAP.PairTag.identifier, 17 bytes), (HAP.PairTag.signature, 64 bytes)]
[hap.controllers.pair-verify|DEBUG] startRequest encrypted result: [(HAP.PairTag.state, 1 bytes), (HAP.PairTag.publicKey, 32 bytes), (HAP.PairTag.encryptedData, 101 bytes)]
[hap.endpoints|INFO] [IPv6]::ffff:10.0.8.116/::ffff:10.0.8.116:55837 POST /pair-verify 200 140
[hap.controllers.pair-verify|DEBUG] --> username EC48906B-6BEB-4265-97E7-08ADD3E17285
[hap.controllers.pair-verify|DEBUG] --> signature 6a1a766e5e355f7ae1a3ac0b0d84c17908a3207951c1a1c2156c6b7240b46999b0aaa4742428042899c68959358937211745be15e0aa766c4330847ca839a70e
[hap.controllers.pair-verify|DEBUG] --> public key effeff36f977b12c5ecf7cc536d3bcf9eabc41295768fa88815f4249d205c042
[hap.controllers.pair-verify|INFO] Pair verify completed
[hap.endpoints|INFO] [IPv6]::ffff:10.0.8.116/::ffff:10.0.8.116:55837 POST /pair-verify 200 3
[hap.encryption|INFO] Decrypt message #0, length: 95
[hap.endpoints|INFO] [IPv6]::ffff:10.0.8.116/::ffff:10.0.8.116:55837 GET /accessories 200 11414
[hap.encryption|INFO] Encrypt message #0, length: 139
[hap.encryption|INFO] Encrypt message #1, length: 11414
[hap.encryption|INFO] Encrypt message #13, length: 0
[hap.encryption|INFO] Decrypt message #1, length: 205
[hap.endpoints.characteristics|DEBUG] PUT data: Optional("{\"characteristics\":[{\"aid\":25,\"iid\":9,\"ev\":true}]}")
[hap.endpoints.characteristics|DEBUG] Added listener for HAP.GenericCharacteristic<Swift.Bool>
[hap.endpoints|INFO] [IPv6]::ffff:10.0.8.144/::ffff:10.0.8.144:62546 PUT /characteristics 204 0
[hap.encryption|INFO] Encrypt message #14, length: 88
[hap.encryption|INFO] Decrypt message #1, length: 205
[hap.endpoints.characteristics|DEBUG] PUT data: Optional("{\"characteristics\":[{\"aid\":25,\"iid\":9,\"ev\":true}]}")
[hap.endpoints.characteristics|DEBUG] Added listener for HAP.GenericCharacteristic<Swift.Bool>
[hap.endpoints|INFO] [IPv6]::ffff:10.0.8.121/::ffff:10.0.8.121:54402 PUT /characteristics 204 0
[hap.encryption|INFO] Encrypt message #14, length: 88
[hap.encryption|INFO] Decrypt message #1, length: 205
[hap.endpoints.characteristics|DEBUG] PUT data: Optional("{\"characteristics\":[{\"aid\":25,\"iid\":9,\"ev\":true}]}")
[hap.endpoints.characteristics|DEBUG] Added listener for HAP.GenericCharacteristic<Swift.Bool>
[hap.endpoints|INFO] [IPv6]::ffff:10.0.8.116/::ffff:10.0.8.116:55837 PUT /characteristics 204 0
[hap.encryption|INFO] Encrypt message #14, length: 88
[hap.encryption|INFO] Decrypt message #1, length: 236
[hap.endpoints.characteristics|DEBUG] PUT data: Optional("{\"characteristics\":[{\"aid\":24,\"iid\":13,\"ev\":true},{\"aid\":24,\"iid\":23,\"ev\":true}]}")
[hap.endpoints.characteristics|DEBUG] Added listener for HAP.GenericCharacteristic<Swift.String>
[hap.endpoints.characteristics|DEBUG] Added listener for HAP.GenericCharacteristic<Swift.String>
[hap.endpoints|INFO] [IPv6]::ffff:10.0.8.8/::ffff:10.0.8.8:50174 PUT /characteristics 204 0
[hap.encryption|INFO] Encrypt message #14, length: 88
[hap.encryption|INFO] Decrypt message #2, length: 387
[hap.endpoints.characteristics|DEBUG] PUT data: Optional("{\"characteristics\":[{\"aid\":23,\"iid\":30,\"ev\":true},{\"aid\":23,\"iid\":37,\"ev\":true},{\"aid\":23,\"iid\":51,\"ev\":true},{\"aid\":23,\"iid\":23,\"ev\":true},{\"aid\":23,\"iid\":13,\"ev\":true},{\"aid\":23,\"iid\":44,\"ev\":true},{\"aid\":23,\"iid\":58,\"ev\":true}]}")
[hap.endpoints.characteristics|DEBUG] Added listener for HAP.GenericCharacteristic<Swift.String>
[hap.endpoints.characteristics|DEBUG] Added listener for HAP.GenericCharacteristic<Swift.String>
[hap.endpoints.characteristics|DEBUG] Added listener for HAP.GenericCharacteristic<Swift.String>
[hap.endpoints.characteristics|DEBUG] Added listener for HAP.GenericCharacteristic<Swift.String>
[hap.endpoints.characteristics|DEBUG] Added listener for HAP.GenericCharacteristic<Swift.String>
[hap.endpoints.characteristics|DEBUG] Added listener for HAP.GenericCharacteristic<Swift.String>
[hap.endpoints.characteristics|DEBUG] Added listener for HAP.GenericCharacteristic<Swift.String>
[hap.endpoints|INFO] [IPv6]::ffff:10.0.8.8/::ffff:10.0.8.8:50174 PUT /characteristics 204 0
[hap.encryption|INFO] Encrypt message #15, length: 88
[hap.encryption|INFO] Decrypt message #1, length: 236
[hap.endpoints.characteristics|DEBUG] PUT data: Optional("{\"characteristics\":[{\"aid\":24,\"iid\":13,\"ev\":true},{\"aid\":24,\"iid\":23,\"ev\":true}]}")
[hap.endpoints.characteristics|DEBUG] Added listener for HAP.GenericCharacteristic<Swift.String>
[hap.endpoints.characteristics|DEBUG] Added listener for HAP.GenericCharacteristic<Swift.String>
[hap.endpoints|INFO] [IPv6]::ffff:10.0.8.129/::ffff:10.0.8.129:61615 PUT /characteristics 204 0
[hap.encryption|INFO] Encrypt message #14, length: 88
[hap.encryption|INFO] Decrypt message #2, length: 387
[hap.endpoints.characteristics|DEBUG] PUT data: Optional("{\"characteristics\":[{\"aid\":23,\"iid\":30,\"ev\":true},{\"aid\":23,\"iid\":37,\"ev\":true},{\"aid\":23,\"iid\":51,\"ev\":true},{\"aid\":23,\"iid\":23,\"ev\":true},{\"aid\":23,\"iid\":13,\"ev\":true},{\"aid\":23,\"iid\":44,\"ev\":true},{\"aid\":23,\"iid\":58,\"ev\":true}]}")
[hap.endpoints.characteristics|DEBUG] Added listener for HAP.GenericCharacteristic<Swift.String>
[hap.endpoints.characteristics|DEBUG] Added listener for HAP.GenericCharacteristic<Swift.String>
[hap.endpoints.characteristics|DEBUG] Added listener for HAP.GenericCharacteristic<Swift.String>
[hap.endpoints.characteristics|DEBUG] Added listener for HAP.GenericCharacteristic<Swift.String>
[hap.endpoints.characteristics|DEBUG] Added listener for HAP.GenericCharacteristic<Swift.String>
[hap.endpoints.characteristics|DEBUG] Added listener for HAP.GenericCharacteristic<Swift.String>
[hap.endpoints.characteristics|DEBUG] Added listener for HAP.GenericCharacteristic<Swift.String>
[hap.endpoints|INFO] [IPv6]::ffff:10.0.8.129/::ffff:10.0.8.129:61615 PUT /characteristics 204 0
[hap.encryption|INFO] Encrypt message #15, length: 88
[hap.encryption|INFO] Decrypt message #2, length: 512
[hap.nio|WARNING] Could not decrypt message from [IPv6]::ffff:10.0.8.121/::ffff:10.0.8.121:54402, closing connection.
[hap.encryption|INFO] Decrypt message #2, length: 512
[hap.nio|WARNING] Could not decrypt message from [IPv6]::ffff:10.0.8.116/::ffff:10.0.8.116:55837, closing connection.
[hap.controllers.pair-verify|DEBUG] startRequest result: [(HAP.PairTag.identifier, 17 bytes), (HAP.PairTag.signature, 64 bytes)]
[hap.controllers.pair-verify|DEBUG] startRequest encrypted result: [(HAP.PairTag.state, 1 bytes), (HAP.PairTag.publicKey, 32 bytes), (HAP.PairTag.encryptedData, 101 bytes)]
[hap.endpoints|INFO] [IPv6]::ffff:10.0.8.121/::ffff:10.0.8.121:54403 POST /pair-verify 200 140
[hap.controllers.pair-verify|DEBUG] --> username EC48906B-6BEB-4265-97E7-08ADD3E17285
[hap.controllers.pair-verify|DEBUG] --> signature f96008d1df597290d63430834496983dad66d3834add4da45da8aac175de7aa801357c77ccebf594071d9d9ee42664809da6d5a3988f530dfb9b0fd6be6edc00
[hap.controllers.pair-verify|DEBUG] --> public key effeff36f977b12c5ecf7cc536d3bcf9eabc41295768fa88815f4249d205c042
[hap.controllers.pair-verify|INFO] Pair verify completed
[hap.endpoints|INFO] [IPv6]::ffff:10.0.8.121/::ffff:10.0.8.121:54403 POST /pair-verify 200 3
[hap.encryption|INFO] Decrypt message #0, length: 95
[hap.endpoints|INFO] [IPv6]::ffff:10.0.8.121/::ffff:10.0.8.121:54403 GET /accessories 200 11414
[hap.encryption|INFO] Encrypt message #0, length: 139
[hap.encryption|INFO] Encrypt message #1, length: 11414
[hap.encryption|INFO] Encrypt message #13, length: 0
[hap.encryption|INFO] Decrypt message #2, length: 512
[hap.nio|WARNING] Could not decrypt message from [IPv6]::ffff:10.0.8.144/::ffff:10.0.8.144:62546, closing connection.
[hap.controllers.pair-verify|DEBUG] startRequest result: [(HAP.PairTag.identifier, 17 bytes), (HAP.PairTag.signature, 64 bytes)]
[hap.controllers.pair-verify|DEBUG] startRequest encrypted result: [(HAP.PairTag.state, 1 bytes), (HAP.PairTag.publicKey, 32 bytes), (HAP.PairTag.encryptedData, 101 bytes)]
[hap.endpoints|INFO] [IPv6]::ffff:10.0.8.116/::ffff:10.0.8.116:55838 POST /pair-verify 200 140
[hap.controllers.pair-verify|DEBUG] --> username EC48906B-6BEB-4265-97E7-08ADD3E17285
[hap.controllers.pair-verify|DEBUG] --> signature 9733b51120793c97bd6ee3b211cafca7ea48558291467633a41ba6dc38ed8f9167f4553aa0e6ad7270d296e6d64f2573666bb205cab5beaf3f2c0a7623a5ed0f
[hap.controllers.pair-verify|DEBUG] --> public key effeff36f977b12c5ecf7cc536d3bcf9eabc41295768fa88815f4249d205c042
[hap.controllers.pair-verify|INFO] Pair verify completed
[hap.endpoints|INFO] [IPv6]::ffff:10.0.8.116/::ffff:10.0.8.116:55838 POST /pair-verify 200 3
[hap.encryption|INFO] Decrypt message #0, length: 95
[hap.encryption|INFO] Decrypt message #1, length: 512
[hap.nio|WARNING] Could not decrypt message from [IPv6]::ffff:10.0.8.121/::ffff:10.0.8.121:54403, closing connection.
[hap.endpoints|INFO] [IPv6]::ffff:10.0.8.116/::ffff:10.0.8.116:55838 GET /accessories 200 11414
[hap.encryption|INFO] Encrypt message #0, length: 139
[hap.encryption|INFO] Encrypt message #1, length: 11414
[hap.encryption|INFO] Encrypt message #13, length: 0
[hap.controllers.pair-verify|DEBUG] startRequest result: [(HAP.PairTag.identifier, 17 bytes), (HAP.PairTag.signature, 64 bytes)]
[hap.controllers.pair-verify|DEBUG] startRequest encrypted result: [(HAP.PairTag.state, 1 bytes), (HAP.PairTag.publicKey, 32 bytes), (HAP.PairTag.encryptedData, 101 bytes)]
[hap.endpoints|INFO] [IPv6]::ffff:10.0.8.144/::ffff:10.0.8.144:62547 POST /pair-verify 200 140
[hap.encryption|INFO] Decrypt message #1, length: 512
[hap.nio|WARNING] Could not decrypt message from [IPv6]::ffff:10.0.8.116/::ffff:10.0.8.116:55838, closing connection.
[hap.controllers.pair-verify|DEBUG] --> username EC48906B-6BEB-4265-97E7-08ADD3E17285
[hap.controllers.pair-verify|DEBUG] --> signature 18579c95af5dc4bd115bc86b9fc2a4467e3361a66aa9e7f69a7ce83fa58ccc7b7029a84714472449be219442fbdfe28a83b2607a276b709b065bae00889b1e08
[hap.controllers.pair-verify|DEBUG] --> public key effeff36f977b12c5ecf7cc536d3bcf9eabc41295768fa88815f4249d205c042
[hap.controllers.pair-verify|INFO] Pair verify completed
[hap.endpoints|INFO] [IPv6]::ffff:10.0.8.144/::ffff:10.0.8.144:62547 POST /pair-verify 200 3
[hap.encryption|INFO] Decrypt message #0, length: 95
[hap.endpoints|INFO] [IPv6]::ffff:10.0.8.144/::ffff:10.0.8.144:62547 GET /accessories 200 11414
[hap.encryption|INFO] Encrypt message #0, length: 139
[hap.encryption|INFO] Encrypt message #1, length: 11414
[hap.encryption|INFO] Encrypt message #13, length: 0
[hap.encryption|INFO] Decrypt message #1, length: 387
[hap.endpoints.characteristics|DEBUG] PUT data: Optional("{\"characteristics\":[{\"aid\":23,\"iid\":30,\"ev\":true},{\"aid\":23,\"iid\":37,\"ev\":true},{\"aid\":23,\"iid\":51,\"ev\":true},{\"aid\":23,\"iid\":23,\"ev\":true},{\"aid\":23,\"iid\":13,\"ev\":true},{\"aid\":23,\"iid\":44,\"ev\":true},{\"aid\":23,\"iid\":58,\"ev\":true}]}")
[hap.endpoints.characteristics|DEBUG] Added listener for HAP.GenericCharacteristic<Swift.String>
[hap.endpoints.characteristics|DEBUG] Added listener for HAP.GenericCharacteristic<Swift.String>
[hap.endpoints.characteristics|DEBUG] Added listener for HAP.GenericCharacteristic<Swift.String>
[hap.endpoints.characteristics|DEBUG] Added listener for HAP.GenericCharacteristic<Swift.String>
[hap.endpoints.characteristics|DEBUG] Added listener for HAP.GenericCharacteristic<Swift.String>
[hap.endpoints.characteristics|DEBUG] Added listener for HAP.GenericCharacteristic<Swift.String>
[hap.endpoints.characteristics|DEBUG] Added listener for HAP.GenericCharacteristic<Swift.String>
[hap.endpoints|INFO] [IPv6]::ffff:10.0.8.144/::ffff:10.0.8.144:62547 PUT /characteristics 204 0
[hap.encryption|INFO] Encrypt message #14, length: 88
[hap.controllers.pair-verify|DEBUG] startRequest result: [(HAP.PairTag.identifier, 17 bytes), (HAP.PairTag.signature, 64 bytes)]
[hap.controllers.pair-verify|DEBUG] startRequest encrypted result: [(HAP.PairTag.state, 1 bytes), (HAP.PairTag.publicKey, 32 bytes), (HAP.PairTag.encryptedData, 101 bytes)]
[hap.endpoints|INFO] [IPv6]::ffff:10.0.8.124/::ffff:10.0.8.124:49704 POST /pair-verify 200 140
[hap.controllers.pair-verify|DEBUG] --> username EC48906B-6BEB-4265-97E7-08ADD3E17285
[hap.controllers.pair-verify|DEBUG] --> signature 4ba24928162a30657228897d8266831401ba17fef0870cf127278292af33c9e90df2d0f90a098eda1a00a2d0ecf142bb4e0795df57099d2ae76ada204e0f0d0e
[hap.controllers.pair-verify|DEBUG] --> public key effeff36f977b12c5ecf7cc536d3bcf9eabc41295768fa88815f4249d205c042
[hap.controllers.pair-verify|INFO] Pair verify completed
[hap.endpoints|INFO] [IPv6]::ffff:10.0.8.124/::ffff:10.0.8.124:49704 POST /pair-verify 200 3
[hap.encryption|INFO] Decrypt message #0, length: 95
[hap.endpoints|INFO] [IPv6]::ffff:10.0.8.124/::ffff:10.0.8.124:49704 GET /accessories 200 11414
[hap.encryption|INFO] Encrypt message #0, length: 139
[hap.encryption|INFO] Encrypt message #1, length: 11414
[hap.encryption|INFO] Encrypt message #13, length: 0
[hap.encryption|INFO] Decrypt message #1, length: 205
[hap.endpoints.characteristics|DEBUG] PUT data: Optional("{\"characteristics\":[{\"aid\":25,\"iid\":9,\"ev\":true}]}")
[hap.endpoints.characteristics|DEBUG] Added listener for HAP.GenericCharacteristic<Swift.Bool>
[hap.endpoints|INFO] [IPv6]::ffff:10.0.8.124/::ffff:10.0.8.124:49704 PUT /characteristics 204 0
[hap.encryption|INFO] Encrypt message #14, length: 88
[hap.encryption|INFO] Decrypt message #2, length: 205
[hap.endpoints.characteristics|DEBUG] PUT data: Optional("{\"characteristics\":[{\"aid\":25,\"iid\":9,\"ev\":true}]}")
[hap.endpoints.characteristics|DEBUG] Added listener for HAP.GenericCharacteristic<Swift.Bool>
[hap.endpoints|INFO] [IPv6]::ffff:10.0.8.144/::ffff:10.0.8.144:62547 PUT /characteristics 204 0
[hap.encryption|INFO] Encrypt message #15, length: 88
[hap.controllers.pair-verify|DEBUG] startRequest result: [(HAP.PairTag.identifier, 17 bytes), (HAP.PairTag.signature, 64 bytes)]
[hap.controllers.pair-verify|DEBUG] startRequest encrypted result: [(HAP.PairTag.state, 1 bytes), (HAP.PairTag.publicKey, 32 bytes), (HAP.PairTag.encryptedData, 101 bytes)]
[hap.endpoints|INFO] [IPv6]::ffff:10.0.8.116/::ffff:10.0.8.116:55839 POST /pair-verify 200 140
[hap.controllers.pair-verify|DEBUG] --> username EC48906B-6BEB-4265-97E7-08ADD3E17285
[hap.controllers.pair-verify|DEBUG] --> signature 89d33ce1df75982fa2e0873762fcc8d00286868936cfe49748151d299d62106a3528d814432c9f896f00996f9ee6d15014967617fc9c5d9bc2ea7f593ff4210f
[hap.controllers.pair-verify|DEBUG] --> public key effeff36f977b12c5ecf7cc536d3bcf9eabc41295768fa88815f4249d205c042
[hap.controllers.pair-verify|INFO] Pair verify completed
[hap.endpoints|INFO] [IPv6]::ffff:10.0.8.116/::ffff:10.0.8.116:55839 POST /pair-verify 200 3
[hap.encryption|INFO] Decrypt message #0, length: 95
[hap.endpoints|INFO] [IPv6]::ffff:10.0.8.116/::ffff:10.0.8.116:55839 GET /accessories 200 11414
[hap.encryption|INFO] Encrypt message #0, length: 139
[hap.encryption|INFO] Encrypt message #1, length: 11414
[hap.encryption|INFO] Encrypt message #13, length: 0
[hap.encryption|INFO] Decrypt message #1, length: 512
[hap.nio|WARNING] Could not decrypt message from [IPv6]::ffff:10.0.8.116/::ffff:10.0.8.116:55839, closing connection.
[hap.encryption|INFO] Decrypt message #2, length: 512
[hap.nio|WARNING] Could not decrypt message from [IPv6]::ffff:10.0.8.124/::ffff:10.0.8.124:49704, closing connection.

Only allow admin users to manage pairings

From the HAP specification (page 36):

4.4 Admins
Admins are pairings that have the 'admin bit' set. Admins are exclusively authorized to add, remove, and list pairings.

Can't build on macOS Sierra with Xcode 8 Beta 6

I've been trying to build this repo for several days now and even with your updates to support Xcode 8 Beta 6, I'm still getting a lot of build errors.

The first thing I get is a problem with OpenSSL:

Linking ./.build/debug/http-demo
ld: library not found for -lssl
<unknown>:0: error: link command failed with exit code 1 (use -v to see invocation)

Then I get hundreds (literally hundreds!) of "redefinition" errors like this:

/Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/module.modulemap:1:8: error: redefinition of module 'AppleTextureEncoder'
module AppleTextureEncoder [system] [extern_c] {
       ^
/usr/include/module.modulemap:1:8: note: previously defined here
module AppleTextureEncoder [system] [extern_c] {
       ^
/Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/module.modulemap:7:8: error: redefinition of module 'Compression'
module Compression [system] [extern_c] {
       ^
/usr/include/module.modulemap:7:8: note: previously defined here
module Compression [system] [extern_c] {
       ^

Are you building this on macOS Sierra? That's the only reason I can think of that could be drastically different between our environments that could be causing this issue.

How to handle optional characteristics?

Take for example the Info service, described in 9.1 of the HAP specifications:

9.1 Accessory Information
Every accessory must expose a single instance of the Accessory Information service with the following definition. The values of Manufacturer, Model, Name and Serial Number must be persistent through the lifetime of the accessory.
Any other Apple-defined characteristics added to this service must only contain one or more of the following permissions: Paired Read or Notify. Custom characteristics added to this service must only contain one or more of the following permissions: Paired Read, Notify, or Broadcast. All other permissions are not permitted.

Currently it's not worked out how to add custom characteristics. Off course one could create a custom Service, but we need to test that this actually works and is documented.

Cannot add >23 accessories to bridge

Danny reached out to me by e-mail with an issue not being able to add >23 accessories, which I confirmed on my end as well.

The one with 23 items, the size is: 15,744 bytes

[hap.endpoints|INFO] 192.168.1.214 GET /accessories - 200 15744

The one with 24 items, the size is: 16,344 bytes

[hap.endpoints|INFO] 192.168.1.214 GET /accessories - 200 16344

The error showing up in the server's logs is:

[hap.http|ERROR] Error while reading from socket [ERROR: Error code: -9971(0x-26F3), Connection reset by peer]

Build Failed on swift 4.2

Hi,

I installed swift on an odroid C2 SBC and I'm only able to install swift 4.2.
Building HAP failed on building BlueSignals

.build/checkouts/BlueSignals.git-8826455067652766894/Sources/Signals/Signals.swift:111:36:

error: converting non-escaping value to 'T' may allow it to escape
sigAction.__sigaction_handler = unsafeBitCast(action, to: sigaction.__Unnamed_union___sigaction_handler.self)

The bug seems to be fixed since BlueSIgnals 1.02 but Kitura-net still use 1.0.0.

After updated BlueSignals to the last release building HAP on my odroid C2 SBC succes

IPCamera

Could you create an IPCamera type accessory? I didn't understand how to do it

How to find plugins?

Hi! Thanks for great project! I really love it.
I'll want write a plugin, but how distribute it and how can people find it?
maybe use prefix HAPplugin_name? Or make Plugins.MD with urls?

Crash in ChaCha20Poly1305.encrypt

There is a crashing bug in the packet encryption code, if the buffer length is 495 or 496 bytes long.

The crash can be demonstrated by adding the following test case to CryptographerTests

    func testCrash() {

        let crashMessage = "6174223a22737472696e67222c2274797065223a223230222c227065726d73223a5b227072225d7d2c7b2274797065223a223231222c22696964223a352c2276616c7565223a224861726d6f6e7920487562204163746976697479222c226465736372697074696f6e223a224d6f64656c222c227065726d73223a5b227072225d2c22666f726d6174223a22737472696e67227d2c7b2274797065223a223532222c22696964223a362c226465736372697074696f6e223a224669726d77617265205265766973696f6e222c22666f726d6174223a22737472696e67222c227065726d73223a5b227072225d2c2276616c7565223a22342e31352e323530227d2c7b226465736372697074696f6e223a224964656e74696679222c227065726d73223a5b227077225d2c22666f726d6174223a22626f6f6c222c2274797065223a223134222c22696964223a377d5d2c22696964223a317d2c7b22636861726163746572697374696373223a5b7b2276616c7565223a66616c73652c227065726d73223a5b227072222c227077222c226576225d2c226465736372697074696f6e223a22506f776572205374617465222c22696964223a392c22666f726d6174223a22626f6f6c222c2274797065223a223235227d5d2c22696964223a382c2274797065223a223439227d5d7d5d7d"

        let shorterMessage = String(crashMessage.dropFirst(2))
        let longerMessage = "6161\(crashMessage)"
        let alsoCrashMessage = "61\(crashMessage)"

        var data = Data(hex: shorterMessage)!
        var plaintextBuffer = channel.allocator.buffer(capacity: 512)
        plaintextBuffer.write(bytes: data)
        handler.write(ctx: context, data: NIOAny(plaintextBuffer), promise: nil)

        print("Passed for \(data.count) bytes\n")

        data = Data(hex: longerMessage)!
        plaintextBuffer = channel.allocator.buffer(capacity: 512)
        plaintextBuffer.write(bytes: data)
        handler.write(ctx: context, data: NIOAny(plaintextBuffer), promise: nil)

        print("Passed for \(data.count) bytes\n")

        data = Data(hex: crashMessage)!
        plaintextBuffer = channel.allocator.buffer(capacity: 512)
        plaintextBuffer.write(bytes: data)
        handler.write(ctx: context, data: NIOAny(plaintextBuffer), promise: nil)

        print("Passed for \(data.count) bytes\n")

        data = Data(hex: alsoCrashMessage)!
        plaintextBuffer = channel.allocator.buffer(capacity: 512)
        plaintextBuffer.write(bytes: data)
        handler.write(ctx: context, data: NIOAny(plaintextBuffer), promise: nil)

        print("Passed for \(data.count) bytes\n")

    }

The last two tests cause a precondition failure in ByteBuffer.moveWriterIndex

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.