matter-all-in-one-addon 2.3.1 → 2.3.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -8
- package/dist/camera/ai/camera-ai-detector.d.ts +0 -2
- package/dist/camera/ai/camera-ai-detector.js +52 -57
- package/dist/camera/ai/camera-ai-detector.js.map +1 -1
- package/dist/camera/browser-preview.d.ts +9 -0
- package/dist/camera/browser-preview.js +135 -0
- package/dist/camera/browser-preview.js.map +1 -0
- package/dist/camera/camera-source-resolver.js +5 -3
- package/dist/camera/camera-source-resolver.js.map +1 -1
- package/dist/camera/camera-types.d.ts +0 -2
- package/dist/camera/cameraui/cameraui-client.js +91 -30
- package/dist/camera/cameraui/cameraui-client.js.map +1 -1
- package/dist/camera/cameraui/cameraui-homekit-bridge.js +13 -4
- package/dist/camera/cameraui/cameraui-homekit-bridge.js.map +1 -1
- package/dist/camera/cameraui/cameraui-storage.js.map +1 -1
- package/dist/camera/cameraui/cameraui-types.d.ts +6 -2
- package/dist/camera/cameraui/ha-camera-entity.js +5 -2
- package/dist/camera/cameraui/ha-camera-entity.js.map +1 -1
- package/dist/camera/homekit/ffmpeg-helper.js +17 -35
- package/dist/camera/homekit/ffmpeg-helper.js.map +1 -1
- package/dist/camera/homekit/hevc/fmp4-hevc.js +3 -1
- package/dist/camera/homekit/hevc/fmp4-hevc.js.map +1 -1
- package/dist/camera/homekit/hevc/hevc-recording.d.ts +0 -2
- package/dist/camera/homekit/hevc/hevc-recording.js +28 -63
- package/dist/camera/homekit/hevc/hevc-recording.js.map +1 -1
- package/dist/camera/homekit/hevc/multi-tier-rtp.d.ts +1 -15
- package/dist/camera/homekit/hevc/multi-tier-rtp.js +70 -228
- package/dist/camera/homekit/hevc/multi-tier-rtp.js.map +1 -1
- package/dist/camera/homekit/hevc/sframe-rtp.d.ts +0 -2
- package/dist/camera/homekit/hevc/sframe-rtp.js +0 -25
- package/dist/camera/homekit/hevc/sframe-rtp.js.map +1 -1
- package/dist/camera/homekit/hevc/sframe.d.ts +1 -11
- package/dist/camera/homekit/hevc/sframe.js +18 -133
- package/dist/camera/homekit/hevc/sframe.js.map +1 -1
- package/dist/camera/homekit/hevc/types.js +81 -9
- package/dist/camera/homekit/hevc/types.js.map +1 -1
- package/dist/camera/homekit/hevc/webrtc-session.d.ts +3 -17
- package/dist/camera/homekit/hevc/webrtc-session.js +55 -229
- package/dist/camera/homekit/hevc/webrtc-session.js.map +1 -1
- package/dist/camera/homekit/homekit-camera-recording.delegate.d.ts +0 -1
- package/dist/camera/homekit/homekit-camera-recording.delegate.js +115 -43
- package/dist/camera/homekit/homekit-camera-recording.delegate.js.map +1 -1
- package/dist/camera/homekit/homekit-camera-stream.delegate.d.ts +4 -7
- package/dist/camera/homekit/homekit-camera-stream.delegate.js +388 -201
- package/dist/camera/homekit/homekit-camera-stream.delegate.js.map +1 -1
- package/dist/camera/homekit/homekit-camera.accessory.d.ts +7 -34
- package/dist/camera/homekit/homekit-camera.accessory.js +207 -169
- package/dist/camera/homekit/homekit-camera.accessory.js.map +1 -1
- package/dist/camera/homekit/live-view-telemetry.d.ts +0 -4
- package/dist/camera/homekit/live-view-telemetry.js.map +1 -1
- package/dist/camera/homekit/tuya-hap-talkback.d.ts +41 -0
- package/dist/camera/homekit/tuya-hap-talkback.js +326 -0
- package/dist/camera/homekit/tuya-hap-talkback.js.map +1 -0
- package/dist/camera/matter/camera-endpoint.builder.js +9 -7
- package/dist/camera/matter/camera-endpoint.builder.js.map +1 -1
- package/dist/camera/matter/camera-session-manager.d.ts +1 -0
- package/dist/camera/matter/camera-session-manager.js +2 -0
- package/dist/camera/matter/camera-session-manager.js.map +1 -1
- package/dist/camera/matter/camera-webrtc-adapter.js +32 -15
- package/dist/camera/matter/camera-webrtc-adapter.js.map +1 -1
- package/dist/camera/motion/ffmpeg-motion-detector.js +28 -14
- package/dist/camera/motion/ffmpeg-motion-detector.js.map +1 -1
- package/dist/camera/nest/nest-camera-adapter.js +9 -5
- package/dist/camera/nest/nest-camera-adapter.js.map +1 -1
- package/dist/camera/ptz/ptz-capabilities.js +3 -1
- package/dist/camera/ptz/ptz-capabilities.js.map +1 -1
- package/dist/camera/ptz/ptz-legacy-discovery.js.map +1 -1
- package/dist/camera/ptz/ptz-mqtt-publisher.js +50 -12
- package/dist/camera/ptz/ptz-mqtt-publisher.js.map +1 -1
- package/dist/camera/ptz/ptz-zones-manager.js +6 -1
- package/dist/camera/ptz/ptz-zones-manager.js.map +1 -1
- package/dist/camera/scrypted/scrypted-camera-card.js +3 -1
- package/dist/camera/scrypted/scrypted-camera-card.js.map +1 -1
- package/dist/camera/scrypted/scrypted-camera-discovery-adapter.js +7 -5
- package/dist/camera/scrypted/scrypted-camera-discovery-adapter.js.map +1 -1
- package/dist/camera/scrypted/scrypted-client-discovery-adapter.js.map +1 -1
- package/dist/camera/scrypted/scrypted-client.js +6 -5
- package/dist/camera/scrypted/scrypted-client.js.map +1 -1
- package/dist/camera/scrypted/scrypted-discovery-provider.js.map +1 -1
- package/dist/camera/scrypted/scrypted-homekit-bridge.js +6 -4
- package/dist/camera/scrypted/scrypted-homekit-bridge.js.map +1 -1
- package/dist/camera/scrypted/scrypted-reconnect-manager.js.map +1 -1
- package/dist/camera/scrypted/scrypted-runtime-facade.js +2 -2
- package/dist/camera/scrypted/scrypted-runtime-facade.js.map +1 -1
- package/dist/camera/scrypted/scrypted-runtime-ingest.js +3 -1
- package/dist/camera/scrypted/scrypted-runtime-ingest.js.map +1 -1
- package/dist/camera/scrypted/scrypted-storage.js +12 -6
- package/dist/camera/scrypted/scrypted-storage.js.map +1 -1
- package/dist/camera/scrypted/scrypted-stream-validator.js +25 -7
- package/dist/camera/scrypted/scrypted-stream-validator.js.map +1 -1
- package/dist/camera/tuya-webrtc-session.d.ts +53 -0
- package/dist/camera/tuya-webrtc-session.js +261 -0
- package/dist/camera/tuya-webrtc-session.js.map +1 -0
- package/dist/converters/sensor.converter.js +4 -1
- package/dist/converters/sensor.converter.js.map +1 -1
- package/dist/device-profiles.js +3 -1
- package/dist/device-profiles.js.map +1 -1
- package/dist/entities/air_quality.entity.js +3 -1
- package/dist/entities/air_quality.entity.js.map +1 -1
- package/dist/entities/base.entity.js +45 -17
- package/dist/entities/base.entity.js.map +1 -1
- package/dist/entities/camera.entity.d.ts +1 -0
- package/dist/entities/camera.entity.js +24 -2
- package/dist/entities/camera.entity.js.map +1 -1
- package/dist/entities/composite-device.entity.js +37 -13
- package/dist/entities/composite-device.entity.js.map +1 -1
- package/dist/entities/energy_tariff.entity.js.map +1 -1
- package/dist/entities/pet_feeder.entity.d.ts +1 -0
- package/dist/entities/pet_feeder.entity.js +12 -0
- package/dist/entities/pet_feeder.entity.js.map +1 -1
- package/dist/entities/vacuum.entity.js +16 -5
- package/dist/entities/vacuum.entity.js.map +1 -1
- package/dist/frontend/assets/index-1k-iTL-m.js +26 -0
- package/dist/frontend/assets/{index-NrzHqycm.css → index-CJdlkpIy.css} +1 -1
- package/dist/frontend/index.html +2 -2
- package/dist/hap/hap-generic-accessory.d.ts +4 -0
- package/dist/hap/hap-generic-accessory.js +512 -122
- package/dist/hap/hap-generic-accessory.js.map +1 -1
- package/dist/homeAssistant.d.ts +1 -0
- package/dist/homeAssistant.js +23 -5
- package/dist/homeAssistant.js.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/mqtt/mqtt-client.js.map +1 -1
- package/dist/mqtt/mqtt.entity.js +41 -17
- package/dist/mqtt/mqtt.entity.js.map +1 -1
- package/dist/platform.d.ts +1 -0
- package/dist/platform.js +83 -13
- package/dist/platform.js.map +1 -1
- package/dist/utils/atomic-json-store.js +5 -1
- package/dist/utils/atomic-json-store.js.map +1 -1
- package/dist/utils/ha-state.js +3 -1
- package/dist/utils/ha-state.js.map +1 -1
- package/dist/utils/light-color.js +3 -5
- package/dist/utils/light-color.js.map +1 -1
- package/dist/utils/matter-command-response.js.map +1 -1
- package/dist/utils/matter-firmware.js +1 -2
- package/dist/utils/matter-firmware.js.map +1 -1
- package/dist/utils/matter-protocol.d.ts +1 -0
- package/dist/utils/matter-protocol.js +30 -0
- package/dist/utils/matter-protocol.js.map +1 -0
- package/package.json +27 -19
- package/dist/camera/camera-entity-control.d.ts +0 -12
- package/dist/camera/camera-entity-control.js +0 -24
- package/dist/camera/camera-entity-control.js.map +0 -1
- package/dist/camera/homekit/hevc/bootstrap.d.ts +0 -9
- package/dist/camera/homekit/hevc/bootstrap.js +0 -47
- package/dist/camera/homekit/hevc/bootstrap.js.map +0 -1
- package/dist/camera/homekit/hevc/recording-output.d.ts +0 -2
- package/dist/camera/homekit/hevc/recording-output.js +0 -33
- package/dist/camera/homekit/hevc/recording-output.js.map +0 -1
- package/dist/camera/homekit/media-policy.d.ts +0 -25
- package/dist/camera/homekit/media-policy.js +0 -102
- package/dist/camera/homekit/media-policy.js.map +0 -1
- package/dist/camera/homekit/route-address.d.ts +0 -2
- package/dist/camera/homekit/route-address.js +0 -27
- package/dist/camera/homekit/route-address.js.map +0 -1
- package/dist/camera/homekit/rtp-relay.d.ts +0 -21
- package/dist/camera/homekit/rtp-relay.js +0 -112
- package/dist/camera/homekit/rtp-relay.js.map +0 -1
- package/dist/camera/homekit/startup-timing.d.ts +0 -8
- package/dist/camera/homekit/startup-timing.js +0 -14
- package/dist/camera/homekit/startup-timing.js.map +0 -1
- package/dist/camera/source-adapter.d.ts +0 -132
- package/dist/camera/source-adapter.js +0 -282
- package/dist/camera/source-adapter.js.map +0 -1
- package/dist/frontend/assets/index-Bka3TVAQ.js +0 -21
- package/vendor/hap-nodejs/LICENSE +0 -176
- package/vendor/hap-nodejs/MIAO.md +0 -5
- package/vendor/hap-nodejs/PATCH.md +0 -37
- package/vendor/hap-nodejs/README.md +0 -86
- package/vendor/hap-nodejs/dist/accessories/AirConditioner_accessory.d.ts +0 -2
- package/vendor/hap-nodejs/dist/accessories/AirConditioner_accessory.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/accessories/AirConditioner_accessory.js +0 -128
- package/vendor/hap-nodejs/dist/accessories/AirConditioner_accessory.js.map +0 -1
- package/vendor/hap-nodejs/dist/accessories/AppleTVRemote_accessory.d.ts +0 -2
- package/vendor/hap-nodejs/dist/accessories/AppleTVRemote_accessory.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/accessories/AppleTVRemote_accessory.js +0 -159
- package/vendor/hap-nodejs/dist/accessories/AppleTVRemote_accessory.js.map +0 -1
- package/vendor/hap-nodejs/dist/accessories/Camera_accessory.d.ts +0 -2
- package/vendor/hap-nodejs/dist/accessories/Camera_accessory.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/accessories/Camera_accessory.js +0 -545
- package/vendor/hap-nodejs/dist/accessories/Camera_accessory.js.map +0 -1
- package/vendor/hap-nodejs/dist/accessories/Fan_accessory.d.ts +0 -2
- package/vendor/hap-nodejs/dist/accessories/Fan_accessory.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/accessories/Fan_accessory.js +0 -74
- package/vendor/hap-nodejs/dist/accessories/Fan_accessory.js.map +0 -1
- package/vendor/hap-nodejs/dist/accessories/GarageDoorOpener_accessory.d.ts +0 -2
- package/vendor/hap-nodejs/dist/accessories/GarageDoorOpener_accessory.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/accessories/GarageDoorOpener_accessory.js +0 -78
- package/vendor/hap-nodejs/dist/accessories/GarageDoorOpener_accessory.js.map +0 -1
- package/vendor/hap-nodejs/dist/accessories/Light-AdaptiveLighting_accessory.d.ts +0 -2
- package/vendor/hap-nodejs/dist/accessories/Light-AdaptiveLighting_accessory.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/accessories/Light-AdaptiveLighting_accessory.js +0 -106
- package/vendor/hap-nodejs/dist/accessories/Light-AdaptiveLighting_accessory.js.map +0 -1
- package/vendor/hap-nodejs/dist/accessories/Light_accessory.d.ts +0 -2
- package/vendor/hap-nodejs/dist/accessories/Light_accessory.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/accessories/Light_accessory.js +0 -145
- package/vendor/hap-nodejs/dist/accessories/Light_accessory.js.map +0 -1
- package/vendor/hap-nodejs/dist/accessories/Lock_accessory.d.ts +0 -2
- package/vendor/hap-nodejs/dist/accessories/Lock_accessory.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/accessories/Lock_accessory.js +0 -76
- package/vendor/hap-nodejs/dist/accessories/Lock_accessory.js.map +0 -1
- package/vendor/hap-nodejs/dist/accessories/MotionSensor_accessory.d.ts +0 -2
- package/vendor/hap-nodejs/dist/accessories/MotionSensor_accessory.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/accessories/MotionSensor_accessory.js +0 -45
- package/vendor/hap-nodejs/dist/accessories/MotionSensor_accessory.js.map +0 -1
- package/vendor/hap-nodejs/dist/accessories/Outlet_accessory.d.ts +0 -2
- package/vendor/hap-nodejs/dist/accessories/Outlet_accessory.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/accessories/Outlet_accessory.js +0 -79
- package/vendor/hap-nodejs/dist/accessories/Outlet_accessory.js.map +0 -1
- package/vendor/hap-nodejs/dist/accessories/SmartSpeaker_accessory.d.ts +0 -2
- package/vendor/hap-nodejs/dist/accessories/SmartSpeaker_accessory.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/accessories/SmartSpeaker_accessory.js +0 -44
- package/vendor/hap-nodejs/dist/accessories/SmartSpeaker_accessory.js.map +0 -1
- package/vendor/hap-nodejs/dist/accessories/Sprinkler_accessory.d.ts +0 -2
- package/vendor/hap-nodejs/dist/accessories/Sprinkler_accessory.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/accessories/Sprinkler_accessory.js +0 -128
- package/vendor/hap-nodejs/dist/accessories/Sprinkler_accessory.js.map +0 -1
- package/vendor/hap-nodejs/dist/accessories/TV_accessory.d.ts +0 -2
- package/vendor/hap-nodejs/dist/accessories/TV_accessory.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/accessories/TV_accessory.js +0 -101
- package/vendor/hap-nodejs/dist/accessories/TV_accessory.js.map +0 -1
- package/vendor/hap-nodejs/dist/accessories/TemperatureSensor_accessory.d.ts +0 -2
- package/vendor/hap-nodejs/dist/accessories/TemperatureSensor_accessory.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/accessories/TemperatureSensor_accessory.js +0 -44
- package/vendor/hap-nodejs/dist/accessories/TemperatureSensor_accessory.js.map +0 -1
- package/vendor/hap-nodejs/dist/accessories/Wi-FiRouter_accessory.d.ts +0 -3
- package/vendor/hap-nodejs/dist/accessories/Wi-FiRouter_accessory.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/accessories/Wi-FiRouter_accessory.js +0 -17
- package/vendor/hap-nodejs/dist/accessories/Wi-FiRouter_accessory.js.map +0 -1
- package/vendor/hap-nodejs/dist/accessories/Wi-FiSatellite_accessory.d.ts +0 -3
- package/vendor/hap-nodejs/dist/accessories/Wi-FiSatellite_accessory.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/accessories/Wi-FiSatellite_accessory.js +0 -19
- package/vendor/hap-nodejs/dist/accessories/Wi-FiSatellite_accessory.js.map +0 -1
- package/vendor/hap-nodejs/dist/accessories/gstreamer-audioProducer.d.ts +0 -25
- package/vendor/hap-nodejs/dist/accessories/gstreamer-audioProducer.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/accessories/gstreamer-audioProducer.js +0 -145
- package/vendor/hap-nodejs/dist/accessories/gstreamer-audioProducer.js.map +0 -1
- package/vendor/hap-nodejs/dist/accessories/types.d.ts +0 -78
- package/vendor/hap-nodejs/dist/accessories/types.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/accessories/types.js +0 -88
- package/vendor/hap-nodejs/dist/accessories/types.js.map +0 -1
- package/vendor/hap-nodejs/dist/index.d.ts +0 -50
- package/vendor/hap-nodejs/dist/index.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/index.js +0 -54
- package/vendor/hap-nodejs/dist/index.js.map +0 -1
- package/vendor/hap-nodejs/dist/internal-types.d.ts +0 -76
- package/vendor/hap-nodejs/dist/internal-types.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/internal-types.js +0 -80
- package/vendor/hap-nodejs/dist/internal-types.js.map +0 -1
- package/vendor/hap-nodejs/dist/lib/Accessory.d.ts +0 -521
- package/vendor/hap-nodejs/dist/lib/Accessory.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/lib/Accessory.js +0 -1762
- package/vendor/hap-nodejs/dist/lib/Accessory.js.map +0 -1
- package/vendor/hap-nodejs/dist/lib/Advertiser.d.ts +0 -190
- package/vendor/hap-nodejs/dist/lib/Advertiser.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/lib/Advertiser.js +0 -592
- package/vendor/hap-nodejs/dist/lib/Advertiser.js.map +0 -1
- package/vendor/hap-nodejs/dist/lib/Bridge.d.ts +0 -12
- package/vendor/hap-nodejs/dist/lib/Bridge.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/lib/Bridge.js +0 -19
- package/vendor/hap-nodejs/dist/lib/Bridge.js.map +0 -1
- package/vendor/hap-nodejs/dist/lib/Characteristic.d.ts +0 -1768
- package/vendor/hap-nodejs/dist/lib/Characteristic.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/lib/Characteristic.js +0 -2532
- package/vendor/hap-nodejs/dist/lib/Characteristic.js.map +0 -1
- package/vendor/hap-nodejs/dist/lib/HAPServer.d.ts +0 -299
- package/vendor/hap-nodejs/dist/lib/HAPServer.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/lib/HAPServer.js +0 -968
- package/vendor/hap-nodejs/dist/lib/HAPServer.js.map +0 -1
- package/vendor/hap-nodejs/dist/lib/Service.d.ts +0 -598
- package/vendor/hap-nodejs/dist/lib/Service.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/lib/Service.js +0 -797
- package/vendor/hap-nodejs/dist/lib/Service.js.map +0 -1
- package/vendor/hap-nodejs/dist/lib/camera/CMAFIngest.d.ts +0 -102
- package/vendor/hap-nodejs/dist/lib/camera/CMAFIngest.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/lib/camera/CMAFIngest.js +0 -317
- package/vendor/hap-nodejs/dist/lib/camera/CMAFIngest.js.map +0 -1
- package/vendor/hap-nodejs/dist/lib/camera/HDSSnapshotTransport.d.ts +0 -38
- package/vendor/hap-nodejs/dist/lib/camera/HDSSnapshotTransport.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/lib/camera/HDSSnapshotTransport.js +0 -174
- package/vendor/hap-nodejs/dist/lib/camera/HDSSnapshotTransport.js.map +0 -1
- package/vendor/hap-nodejs/dist/lib/camera/RTPProxy.d.ts +0 -59
- package/vendor/hap-nodejs/dist/lib/camera/RTPProxy.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/lib/camera/RTPProxy.js +0 -267
- package/vendor/hap-nodejs/dist/lib/camera/RTPProxy.js.map +0 -1
- package/vendor/hap-nodejs/dist/lib/camera/RTPStreamManagement.d.ts +0 -379
- package/vendor/hap-nodejs/dist/lib/camera/RTPStreamManagement.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/lib/camera/RTPStreamManagement.js +0 -1021
- package/vendor/hap-nodejs/dist/lib/camera/RTPStreamManagement.js.map +0 -1
- package/vendor/hap-nodejs/dist/lib/camera/RecordingManagement.d.ts +0 -325
- package/vendor/hap-nodejs/dist/lib/camera/RecordingManagement.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/lib/camera/RecordingManagement.js +0 -800
- package/vendor/hap-nodejs/dist/lib/camera/RecordingManagement.js.map +0 -1
- package/vendor/hap-nodejs/dist/lib/camera/SecureVideoCredentials.d.ts +0 -20
- package/vendor/hap-nodejs/dist/lib/camera/SecureVideoCredentials.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/lib/camera/SecureVideoCredentials.js +0 -48
- package/vendor/hap-nodejs/dist/lib/camera/SecureVideoCredentials.js.map +0 -1
- package/vendor/hap-nodejs/dist/lib/camera/SecureVideoTypes.d.ts +0 -618
- package/vendor/hap-nodejs/dist/lib/camera/SecureVideoTypes.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/lib/camera/SecureVideoTypes.js +0 -911
- package/vendor/hap-nodejs/dist/lib/camera/SecureVideoTypes.js.map +0 -1
- package/vendor/hap-nodejs/dist/lib/camera/index.d.ts +0 -8
- package/vendor/hap-nodejs/dist/lib/camera/index.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/lib/camera/index.js +0 -11
- package/vendor/hap-nodejs/dist/lib/camera/index.js.map +0 -1
- package/vendor/hap-nodejs/dist/lib/controller/AdaptiveLightingController.d.ts +0 -452
- package/vendor/hap-nodejs/dist/lib/controller/AdaptiveLightingController.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/lib/controller/AdaptiveLightingController.js +0 -868
- package/vendor/hap-nodejs/dist/lib/controller/AdaptiveLightingController.js.map +0 -1
- package/vendor/hap-nodejs/dist/lib/controller/CameraController.d.ts +0 -410
- package/vendor/hap-nodejs/dist/lib/controller/CameraController.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/lib/controller/CameraController.js +0 -658
- package/vendor/hap-nodejs/dist/lib/controller/CameraController.js.map +0 -1
- package/vendor/hap-nodejs/dist/lib/controller/Controller.d.ts +0 -197
- package/vendor/hap-nodejs/dist/lib/controller/Controller.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/lib/controller/Controller.js +0 -32
- package/vendor/hap-nodejs/dist/lib/controller/Controller.js.map +0 -1
- package/vendor/hap-nodejs/dist/lib/controller/DoorbellController.d.ts +0 -59
- package/vendor/hap-nodejs/dist/lib/controller/DoorbellController.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/lib/controller/DoorbellController.js +0 -102
- package/vendor/hap-nodejs/dist/lib/controller/DoorbellController.js.map +0 -1
- package/vendor/hap-nodejs/dist/lib/controller/RemoteController.d.ts +0 -434
- package/vendor/hap-nodejs/dist/lib/controller/RemoteController.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/lib/controller/RemoteController.js +0 -1178
- package/vendor/hap-nodejs/dist/lib/controller/RemoteController.js.map +0 -1
- package/vendor/hap-nodejs/dist/lib/controller/SecureVideoController.d.ts +0 -380
- package/vendor/hap-nodejs/dist/lib/controller/SecureVideoController.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/lib/controller/SecureVideoController.js +0 -947
- package/vendor/hap-nodejs/dist/lib/controller/SecureVideoController.js.map +0 -1
- package/vendor/hap-nodejs/dist/lib/controller/index.d.ts +0 -7
- package/vendor/hap-nodejs/dist/lib/controller/index.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/lib/controller/index.js +0 -10
- package/vendor/hap-nodejs/dist/lib/controller/index.js.map +0 -1
- package/vendor/hap-nodejs/dist/lib/datastream/DataStreamManagement.d.ts +0 -73
- package/vendor/hap-nodejs/dist/lib/datastream/DataStreamManagement.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/lib/datastream/DataStreamManagement.js +0 -205
- package/vendor/hap-nodejs/dist/lib/datastream/DataStreamManagement.js.map +0 -1
- package/vendor/hap-nodejs/dist/lib/datastream/DataStreamParser.d.ts +0 -186
- package/vendor/hap-nodejs/dist/lib/datastream/DataStreamParser.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/lib/datastream/DataStreamParser.js +0 -880
- package/vendor/hap-nodejs/dist/lib/datastream/DataStreamParser.js.map +0 -1
- package/vendor/hap-nodejs/dist/lib/datastream/DataStreamServer.d.ts +0 -351
- package/vendor/hap-nodejs/dist/lib/datastream/DataStreamServer.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/lib/datastream/DataStreamServer.js +0 -878
- package/vendor/hap-nodejs/dist/lib/datastream/DataStreamServer.js.map +0 -1
- package/vendor/hap-nodejs/dist/lib/datastream/index.d.ts +0 -4
- package/vendor/hap-nodejs/dist/lib/datastream/index.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/lib/datastream/index.js +0 -7
- package/vendor/hap-nodejs/dist/lib/datastream/index.js.map +0 -1
- package/vendor/hap-nodejs/dist/lib/definitions/CharacteristicDefinitions.d.ts +0 -2245
- package/vendor/hap-nodejs/dist/lib/definitions/CharacteristicDefinitions.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/lib/definitions/CharacteristicDefinitions.js +0 -4957
- package/vendor/hap-nodejs/dist/lib/definitions/CharacteristicDefinitions.js.map +0 -1
- package/vendor/hap-nodejs/dist/lib/definitions/ServiceDefinitions.d.ts +0 -584
- package/vendor/hap-nodejs/dist/lib/definitions/ServiceDefinitions.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/lib/definitions/ServiceDefinitions.js +0 -1518
- package/vendor/hap-nodejs/dist/lib/definitions/ServiceDefinitions.js.map +0 -1
- package/vendor/hap-nodejs/dist/lib/definitions/generate-definitions.d.ts +0 -34
- package/vendor/hap-nodejs/dist/lib/definitions/generate-definitions.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/lib/definitions/generate-definitions.js +0 -624
- package/vendor/hap-nodejs/dist/lib/definitions/generate-definitions.js.map +0 -1
- package/vendor/hap-nodejs/dist/lib/definitions/generator-configuration.d.ts +0 -22
- package/vendor/hap-nodejs/dist/lib/definitions/generator-configuration.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/lib/definitions/generator-configuration.js +0 -734
- package/vendor/hap-nodejs/dist/lib/definitions/generator-configuration.js.map +0 -1
- package/vendor/hap-nodejs/dist/lib/definitions/index.d.ts +0 -3
- package/vendor/hap-nodejs/dist/lib/definitions/index.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/lib/definitions/index.js +0 -6
- package/vendor/hap-nodejs/dist/lib/definitions/index.js.map +0 -1
- package/vendor/hap-nodejs/dist/lib/gen/HomeKit.d.ts +0 -8
- package/vendor/hap-nodejs/dist/lib/gen/HomeKit.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/lib/gen/HomeKit.js +0 -9
- package/vendor/hap-nodejs/dist/lib/gen/HomeKit.js.map +0 -1
- package/vendor/hap-nodejs/dist/lib/model/AccessoryInfo.d.ts +0 -91
- package/vendor/hap-nodejs/dist/lib/model/AccessoryInfo.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/lib/model/AccessoryInfo.js +0 -311
- package/vendor/hap-nodejs/dist/lib/model/AccessoryInfo.js.map +0 -1
- package/vendor/hap-nodejs/dist/lib/model/ControllerStorage.d.ts +0 -46
- package/vendor/hap-nodejs/dist/lib/model/ControllerStorage.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/lib/model/ControllerStorage.js +0 -277
- package/vendor/hap-nodejs/dist/lib/model/ControllerStorage.js.map +0 -1
- package/vendor/hap-nodejs/dist/lib/model/HAPFileStorage.d.ts +0 -75
- package/vendor/hap-nodejs/dist/lib/model/HAPFileStorage.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/lib/model/HAPFileStorage.js +0 -190
- package/vendor/hap-nodejs/dist/lib/model/HAPFileStorage.js.map +0 -1
- package/vendor/hap-nodejs/dist/lib/model/HAPStorage.d.ts +0 -26
- package/vendor/hap-nodejs/dist/lib/model/HAPStorage.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/lib/model/HAPStorage.js +0 -79
- package/vendor/hap-nodejs/dist/lib/model/HAPStorage.js.map +0 -1
- package/vendor/hap-nodejs/dist/lib/model/IdentifierCache.d.ts +0 -33
- package/vendor/hap-nodejs/dist/lib/model/IdentifierCache.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/lib/model/IdentifierCache.js +0 -114
- package/vendor/hap-nodejs/dist/lib/model/IdentifierCache.js.map +0 -1
- package/vendor/hap-nodejs/dist/lib/tv/AccessControlManagement.d.ts +0 -83
- package/vendor/hap-nodejs/dist/lib/tv/AccessControlManagement.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/lib/tv/AccessControlManagement.js +0 -127
- package/vendor/hap-nodejs/dist/lib/tv/AccessControlManagement.js.map +0 -1
- package/vendor/hap-nodejs/dist/lib/util/checkName.d.ts +0 -8
- package/vendor/hap-nodejs/dist/lib/util/checkName.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/lib/util/checkName.js +0 -28
- package/vendor/hap-nodejs/dist/lib/util/checkName.js.map +0 -1
- package/vendor/hap-nodejs/dist/lib/util/clone.d.ts +0 -7
- package/vendor/hap-nodejs/dist/lib/util/clone.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/lib/util/clone.js +0 -22
- package/vendor/hap-nodejs/dist/lib/util/clone.js.map +0 -1
- package/vendor/hap-nodejs/dist/lib/util/color-utils.d.ts +0 -18
- package/vendor/hap-nodejs/dist/lib/util/color-utils.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/lib/util/color-utils.js +0 -442
- package/vendor/hap-nodejs/dist/lib/util/color-utils.js.map +0 -1
- package/vendor/hap-nodejs/dist/lib/util/eventedhttp.d.ts +0 -251
- package/vendor/hap-nodejs/dist/lib/util/eventedhttp.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/lib/util/eventedhttp.js +0 -714
- package/vendor/hap-nodejs/dist/lib/util/eventedhttp.js.map +0 -1
- package/vendor/hap-nodejs/dist/lib/util/hapCrypto.d.ts +0 -50
- package/vendor/hap-nodejs/dist/lib/util/hapCrypto.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/lib/util/hapCrypto.js +0 -185
- package/vendor/hap-nodejs/dist/lib/util/hapCrypto.js.map +0 -1
- package/vendor/hap-nodejs/dist/lib/util/hapStatusError.d.ts +0 -16
- package/vendor/hap-nodejs/dist/lib/util/hapStatusError.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/lib/util/hapStatusError.js +0 -29
- package/vendor/hap-nodejs/dist/lib/util/hapStatusError.js.map +0 -1
- package/vendor/hap-nodejs/dist/lib/util/net-utils.d.ts +0 -21
- package/vendor/hap-nodejs/dist/lib/util/net-utils.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/lib/util/net-utils.js +0 -79
- package/vendor/hap-nodejs/dist/lib/util/net-utils.js.map +0 -1
- package/vendor/hap-nodejs/dist/lib/util/once.d.ts +0 -7
- package/vendor/hap-nodejs/dist/lib/util/once.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/lib/util/once.js +0 -22
- package/vendor/hap-nodejs/dist/lib/util/once.js.map +0 -1
- package/vendor/hap-nodejs/dist/lib/util/promise-utils.d.ts +0 -14
- package/vendor/hap-nodejs/dist/lib/util/promise-utils.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/lib/util/promise-utils.js +0 -29
- package/vendor/hap-nodejs/dist/lib/util/promise-utils.js.map +0 -1
- package/vendor/hap-nodejs/dist/lib/util/request-util.d.ts +0 -36
- package/vendor/hap-nodejs/dist/lib/util/request-util.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/lib/util/request-util.js +0 -108
- package/vendor/hap-nodejs/dist/lib/util/request-util.js.map +0 -1
- package/vendor/hap-nodejs/dist/lib/util/time.d.ts +0 -9
- package/vendor/hap-nodejs/dist/lib/util/time.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/lib/util/time.js +0 -23
- package/vendor/hap-nodejs/dist/lib/util/time.js.map +0 -1
- package/vendor/hap-nodejs/dist/lib/util/tlv.d.ts +0 -90
- package/vendor/hap-nodejs/dist/lib/util/tlv.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/lib/util/tlv.js +0 -318
- package/vendor/hap-nodejs/dist/lib/util/tlv.js.map +0 -1
- package/vendor/hap-nodejs/dist/lib/util/uuid.d.ts +0 -23
- package/vendor/hap-nodejs/dist/lib/util/uuid.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/lib/util/uuid.js +0 -78
- package/vendor/hap-nodejs/dist/lib/util/uuid.js.map +0 -1
- package/vendor/hap-nodejs/dist/types.d.ts +0 -276
- package/vendor/hap-nodejs/dist/types.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/types.js +0 -11
- package/vendor/hap-nodejs/dist/types.js.map +0 -1
- package/vendor/hap-nodejs/package.json +0 -53
- package/vendor/hap-nodejs/src/lib/util/hapCrypto.ts +0 -208
|
@@ -1,968 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.HAPServer = exports.HAPServerEventTypes = exports.HAPPairingHTTPCode = exports.HAPHTTPCode = exports.HAPStatus = exports.TLVErrorCode = void 0;
|
|
4
|
-
exports.IsKnownHAPStatusError = IsKnownHAPStatusError;
|
|
5
|
-
const tslib_1 = require("tslib");
|
|
6
|
-
const crypto_1 = tslib_1.__importDefault(require("crypto"));
|
|
7
|
-
const debug_1 = tslib_1.__importDefault(require("debug"));
|
|
8
|
-
const events_1 = require("events");
|
|
9
|
-
const fast_srp_hap_1 = require("fast-srp-hap");
|
|
10
|
-
const tweetnacl_1 = tslib_1.__importDefault(require("tweetnacl"));
|
|
11
|
-
const url_1 = require("url");
|
|
12
|
-
const internal_types_1 = require("../internal-types");
|
|
13
|
-
const eventedhttp_1 = require("./util/eventedhttp");
|
|
14
|
-
const hapCrypto = tslib_1.__importStar(require("./util/hapCrypto"));
|
|
15
|
-
const once_1 = require("./util/once");
|
|
16
|
-
const tlv = tslib_1.__importStar(require("./util/tlv"));
|
|
17
|
-
const debug = (0, debug_1.default)("HAP-NodeJS:HAPServer");
|
|
18
|
-
/**
|
|
19
|
-
* TLV error codes for the `TLVValues.ERROR_CODE` field.
|
|
20
|
-
*
|
|
21
|
-
* @group HAP Accessory Server
|
|
22
|
-
*/
|
|
23
|
-
var TLVErrorCode;
|
|
24
|
-
(function (TLVErrorCode) {
|
|
25
|
-
// noinspection JSUnusedGlobalSymbols
|
|
26
|
-
TLVErrorCode[TLVErrorCode["UNKNOWN"] = 1] = "UNKNOWN";
|
|
27
|
-
TLVErrorCode[TLVErrorCode["INVALID_REQUEST"] = 2] = "INVALID_REQUEST";
|
|
28
|
-
// eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values
|
|
29
|
-
TLVErrorCode[TLVErrorCode["AUTHENTICATION"] = 2] = "AUTHENTICATION";
|
|
30
|
-
TLVErrorCode[TLVErrorCode["BACKOFF"] = 3] = "BACKOFF";
|
|
31
|
-
TLVErrorCode[TLVErrorCode["MAX_PEERS"] = 4] = "MAX_PEERS";
|
|
32
|
-
TLVErrorCode[TLVErrorCode["MAX_TRIES"] = 5] = "MAX_TRIES";
|
|
33
|
-
TLVErrorCode[TLVErrorCode["UNAVAILABLE"] = 6] = "UNAVAILABLE";
|
|
34
|
-
TLVErrorCode[TLVErrorCode["BUSY"] = 7] = "BUSY"; // cannot accept pairing request at this time
|
|
35
|
-
})(TLVErrorCode || (exports.TLVErrorCode = TLVErrorCode = {}));
|
|
36
|
-
/**
|
|
37
|
-
* @group HAP Accessory Server
|
|
38
|
-
*/
|
|
39
|
-
var HAPStatus;
|
|
40
|
-
(function (HAPStatus) {
|
|
41
|
-
// noinspection JSUnusedGlobalSymbols
|
|
42
|
-
/**
|
|
43
|
-
* Success of the request.
|
|
44
|
-
*/
|
|
45
|
-
HAPStatus[HAPStatus["SUCCESS"] = 0] = "SUCCESS";
|
|
46
|
-
/**
|
|
47
|
-
* The request was rejected due to insufficient privileges.
|
|
48
|
-
*/
|
|
49
|
-
HAPStatus[HAPStatus["INSUFFICIENT_PRIVILEGES"] = -70401] = "INSUFFICIENT_PRIVILEGES";
|
|
50
|
-
/**
|
|
51
|
-
* Operation failed due to some communication failure with the characteristic.
|
|
52
|
-
*/
|
|
53
|
-
HAPStatus[HAPStatus["SERVICE_COMMUNICATION_FAILURE"] = -70402] = "SERVICE_COMMUNICATION_FAILURE";
|
|
54
|
-
/**
|
|
55
|
-
* The resource is busy. Try again.
|
|
56
|
-
*/
|
|
57
|
-
HAPStatus[HAPStatus["RESOURCE_BUSY"] = -70403] = "RESOURCE_BUSY";
|
|
58
|
-
/**
|
|
59
|
-
* Cannot write a read-only characteristic ({@link Perms.PAIRED_WRITE} not defined).
|
|
60
|
-
*/
|
|
61
|
-
HAPStatus[HAPStatus["READ_ONLY_CHARACTERISTIC"] = -70404] = "READ_ONLY_CHARACTERISTIC";
|
|
62
|
-
/**
|
|
63
|
-
* Cannot read from a write-only characteristic ({@link Perms.PAIRED_READ} not defined).
|
|
64
|
-
*/
|
|
65
|
-
HAPStatus[HAPStatus["WRITE_ONLY_CHARACTERISTIC"] = -70405] = "WRITE_ONLY_CHARACTERISTIC";
|
|
66
|
-
/**
|
|
67
|
-
* Event notifications are not supported for the requested characteristic ({@link Perms.NOTIFY} not defined).
|
|
68
|
-
*/
|
|
69
|
-
HAPStatus[HAPStatus["NOTIFICATION_NOT_SUPPORTED"] = -70406] = "NOTIFICATION_NOT_SUPPORTED";
|
|
70
|
-
/**
|
|
71
|
-
* The device is out of resources to process the request.
|
|
72
|
-
*/
|
|
73
|
-
HAPStatus[HAPStatus["OUT_OF_RESOURCE"] = -70407] = "OUT_OF_RESOURCE";
|
|
74
|
-
/**
|
|
75
|
-
* The operation timed out.
|
|
76
|
-
*/
|
|
77
|
-
HAPStatus[HAPStatus["OPERATION_TIMED_OUT"] = -70408] = "OPERATION_TIMED_OUT";
|
|
78
|
-
/**
|
|
79
|
-
* The given resource does not exist.
|
|
80
|
-
*/
|
|
81
|
-
HAPStatus[HAPStatus["RESOURCE_DOES_NOT_EXIST"] = -70409] = "RESOURCE_DOES_NOT_EXIST";
|
|
82
|
-
/**
|
|
83
|
-
* Received an invalid value in the given request for the given characteristic.
|
|
84
|
-
*/
|
|
85
|
-
HAPStatus[HAPStatus["INVALID_VALUE_IN_REQUEST"] = -70410] = "INVALID_VALUE_IN_REQUEST";
|
|
86
|
-
/**
|
|
87
|
-
* Insufficient authorization.
|
|
88
|
-
*/
|
|
89
|
-
HAPStatus[HAPStatus["INSUFFICIENT_AUTHORIZATION"] = -70411] = "INSUFFICIENT_AUTHORIZATION";
|
|
90
|
-
/**
|
|
91
|
-
* Operation not allowed in the current state.
|
|
92
|
-
*/
|
|
93
|
-
HAPStatus[HAPStatus["NOT_ALLOWED_IN_CURRENT_STATE"] = -70412] = "NOT_ALLOWED_IN_CURRENT_STATE";
|
|
94
|
-
// when adding new status codes, remember to update bounds in IsKnownHAPStatusError below
|
|
95
|
-
})(HAPStatus || (exports.HAPStatus = HAPStatus = {}));
|
|
96
|
-
/**
|
|
97
|
-
* Determines if the given status code is a known {@link HAPStatus} error code.
|
|
98
|
-
*
|
|
99
|
-
* @group HAP Accessory Server
|
|
100
|
-
*/
|
|
101
|
-
function IsKnownHAPStatusError(status) {
|
|
102
|
-
return (
|
|
103
|
-
// Lower bound (most negative error code)
|
|
104
|
-
status >= -70412 /* HAPStatus.NOT_ALLOWED_IN_CURRENT_STATE */ &&
|
|
105
|
-
// Upper bound (negative error code closest to zero)
|
|
106
|
-
status <= -70401 /* HAPStatus.INSUFFICIENT_PRIVILEGES */);
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* Those status codes are the one listed as appropriate for the HAP spec!
|
|
110
|
-
*
|
|
111
|
-
* When the response is a client error 4xx or server error 5xx, the response
|
|
112
|
-
* must include a status {@link HAPStatus} property.
|
|
113
|
-
*
|
|
114
|
-
* When the response is a MULTI_STATUS EVERY entry in the characteristics property MUST include a status property (even success).
|
|
115
|
-
*
|
|
116
|
-
* @group HAP Accessory Server
|
|
117
|
-
*/
|
|
118
|
-
var HAPHTTPCode;
|
|
119
|
-
(function (HAPHTTPCode) {
|
|
120
|
-
// noinspection JSUnusedGlobalSymbols
|
|
121
|
-
HAPHTTPCode[HAPHTTPCode["OK"] = 200] = "OK";
|
|
122
|
-
HAPHTTPCode[HAPHTTPCode["NO_CONTENT"] = 204] = "NO_CONTENT";
|
|
123
|
-
HAPHTTPCode[HAPHTTPCode["MULTI_STATUS"] = 207] = "MULTI_STATUS";
|
|
124
|
-
// client error
|
|
125
|
-
HAPHTTPCode[HAPHTTPCode["BAD_REQUEST"] = 400] = "BAD_REQUEST";
|
|
126
|
-
HAPHTTPCode[HAPHTTPCode["NOT_FOUND"] = 404] = "NOT_FOUND";
|
|
127
|
-
HAPHTTPCode[HAPHTTPCode["UNPROCESSABLE_ENTITY"] = 422] = "UNPROCESSABLE_ENTITY";
|
|
128
|
-
// server error
|
|
129
|
-
HAPHTTPCode[HAPHTTPCode["INTERNAL_SERVER_ERROR"] = 500] = "INTERNAL_SERVER_ERROR";
|
|
130
|
-
HAPHTTPCode[HAPHTTPCode["SERVICE_UNAVAILABLE"] = 503] = "SERVICE_UNAVAILABLE";
|
|
131
|
-
})(HAPHTTPCode || (exports.HAPHTTPCode = HAPHTTPCode = {}));
|
|
132
|
-
/**
|
|
133
|
-
* When in a request is made to the pairing endpoints, and mime type is 'application/pairing+tlv8'
|
|
134
|
-
* one should use the below status codes.
|
|
135
|
-
*
|
|
136
|
-
* @group HAP Accessory Server
|
|
137
|
-
*/
|
|
138
|
-
var HAPPairingHTTPCode;
|
|
139
|
-
(function (HAPPairingHTTPCode) {
|
|
140
|
-
// noinspection JSUnusedGlobalSymbols
|
|
141
|
-
HAPPairingHTTPCode[HAPPairingHTTPCode["OK"] = 200] = "OK";
|
|
142
|
-
HAPPairingHTTPCode[HAPPairingHTTPCode["BAD_REQUEST"] = 400] = "BAD_REQUEST";
|
|
143
|
-
HAPPairingHTTPCode[HAPPairingHTTPCode["METHOD_NOT_ALLOWED"] = 405] = "METHOD_NOT_ALLOWED";
|
|
144
|
-
HAPPairingHTTPCode[HAPPairingHTTPCode["TOO_MANY_REQUESTS"] = 429] = "TOO_MANY_REQUESTS";
|
|
145
|
-
HAPPairingHTTPCode[HAPPairingHTTPCode["CONNECTION_AUTHORIZATION_REQUIRED"] = 470] = "CONNECTION_AUTHORIZATION_REQUIRED";
|
|
146
|
-
HAPPairingHTTPCode[HAPPairingHTTPCode["INTERNAL_SERVER_ERROR"] = 500] = "INTERNAL_SERVER_ERROR";
|
|
147
|
-
})(HAPPairingHTTPCode || (exports.HAPPairingHTTPCode = HAPPairingHTTPCode = {}));
|
|
148
|
-
/**
|
|
149
|
-
* @group HAP Accessory Server
|
|
150
|
-
*/
|
|
151
|
-
var HAPServerEventTypes;
|
|
152
|
-
(function (HAPServerEventTypes) {
|
|
153
|
-
/**
|
|
154
|
-
* Emitted when the server is fully set up and ready to receive connections.
|
|
155
|
-
*/
|
|
156
|
-
HAPServerEventTypes["LISTENING"] = "listening";
|
|
157
|
-
/**
|
|
158
|
-
* Emitted when a client wishes for this server to identify itself before pairing. You must call the
|
|
159
|
-
* callback to respond to the client with success.
|
|
160
|
-
*/
|
|
161
|
-
HAPServerEventTypes["IDENTIFY"] = "identify";
|
|
162
|
-
HAPServerEventTypes["ADD_PAIRING"] = "add-pairing";
|
|
163
|
-
HAPServerEventTypes["REMOVE_PAIRING"] = "remove-pairing";
|
|
164
|
-
HAPServerEventTypes["LIST_PAIRINGS"] = "list-pairings";
|
|
165
|
-
/**
|
|
166
|
-
* This event is emitted when a client completes the "pairing" process and exchanges encryption keys.
|
|
167
|
-
* Note that this does not mean the "Add Accessory" process in iOS has completed.
|
|
168
|
-
* You must call the callback to complete the process.
|
|
169
|
-
*/
|
|
170
|
-
HAPServerEventTypes["PAIR"] = "pair";
|
|
171
|
-
/**
|
|
172
|
-
* This event is emitted when a client requests the complete representation of Accessory data for
|
|
173
|
-
* this Accessory (for instance, what services, characteristics, etc. are supported) and any bridged
|
|
174
|
-
* Accessories in the case of a Bridge Accessory. The listener must call the provided callback function
|
|
175
|
-
* when the accessory data is ready. We will automatically JSON.stringify the data.
|
|
176
|
-
*/
|
|
177
|
-
HAPServerEventTypes["ACCESSORIES"] = "accessories";
|
|
178
|
-
/**
|
|
179
|
-
* This event is emitted when a client wishes to retrieve the current value of one or more characteristics.
|
|
180
|
-
* The listener must call the provided callback function when the values are ready. iOS clients can typically
|
|
181
|
-
* wait up to 10 seconds for this call to return. We will automatically JSON.stringify the data (which must
|
|
182
|
-
* be an array) and wrap it in an object with a top-level "characteristics" property.
|
|
183
|
-
*/
|
|
184
|
-
HAPServerEventTypes["GET_CHARACTERISTICS"] = "get-characteristics";
|
|
185
|
-
/**
|
|
186
|
-
* This event is emitted when a client wishes to set the current value of one or more characteristics and/or
|
|
187
|
-
* subscribe to one or more events. The 'events' param is an initially-empty object, associated with the current
|
|
188
|
-
* connection, on which you may store event registration keys for later processing. The listener must call
|
|
189
|
-
* the provided callback when the request has been processed.
|
|
190
|
-
*/
|
|
191
|
-
HAPServerEventTypes["SET_CHARACTERISTICS"] = "set-characteristics";
|
|
192
|
-
HAPServerEventTypes["REQUEST_RESOURCE"] = "request-resource";
|
|
193
|
-
HAPServerEventTypes["CONNECTION_CLOSED"] = "connection-closed";
|
|
194
|
-
})(HAPServerEventTypes || (exports.HAPServerEventTypes = HAPServerEventTypes = {}));
|
|
195
|
-
/**
|
|
196
|
-
* The actual HAP server that iOS devices talk to.
|
|
197
|
-
*
|
|
198
|
-
* Notes
|
|
199
|
-
* -----
|
|
200
|
-
* It turns out that the IP-based version of HomeKit's HAP protocol operates over a sort of pseudo-HTTP.
|
|
201
|
-
* Accessories are meant to host a TCP socket server that initially behaves exactly as an HTTP/1.1 server.
|
|
202
|
-
* So iOS devices will open up a long-lived connection to this server and begin issuing HTTP requests.
|
|
203
|
-
* So far, this conforms with HTTP/1.1 Keepalive. However, after the "pairing" process is complete, the
|
|
204
|
-
* connection is expected to be "upgraded" to support full-packet encryption of both HTTP headers and data.
|
|
205
|
-
* This encryption is NOT SSL. It is a customized ChaCha20+Poly1305 encryption layer.
|
|
206
|
-
*
|
|
207
|
-
* Additionally, this "HTTP Server" supports sending "event" responses at any time without warning. The iOS
|
|
208
|
-
* device simply keeps the connection open after it's finished with HTTP request/response traffic, and while
|
|
209
|
-
* the connection is open, the server can elect to issue "EVENT/1.0 200 OK" HTTP-style responses. These are
|
|
210
|
-
* typically sent to inform the iOS device of a characteristic change for the accessory (like "Door was Unlocked").
|
|
211
|
-
*
|
|
212
|
-
* See {@link EventedHTTPServer} for more detail on the implementation of this protocol.
|
|
213
|
-
*
|
|
214
|
-
* @group HAP Accessory Server
|
|
215
|
-
*/
|
|
216
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
|
|
217
|
-
class HAPServer extends events_1.EventEmitter {
|
|
218
|
-
accessoryInfo;
|
|
219
|
-
httpServer;
|
|
220
|
-
unsuccessfulPairAttempts = 0; // after 100 unsuccessful attempts the server won't accept any further attempts. Will currently be reset on a reboot
|
|
221
|
-
allowInsecureRequest;
|
|
222
|
-
constructor(accessoryInfo) {
|
|
223
|
-
super();
|
|
224
|
-
this.accessoryInfo = accessoryInfo;
|
|
225
|
-
this.allowInsecureRequest = false;
|
|
226
|
-
// internal server that does all the actual communication
|
|
227
|
-
this.httpServer = new eventedhttp_1.EventedHTTPServer();
|
|
228
|
-
this.httpServer.on("listening" /* EventedHTTPServerEvent.LISTENING */, this.onListening.bind(this));
|
|
229
|
-
this.httpServer.on("request" /* EventedHTTPServerEvent.REQUEST */, this.handleRequestOnHAPConnection.bind(this));
|
|
230
|
-
this.httpServer.on("connection-closed" /* EventedHTTPServerEvent.CONNECTION_CLOSED */, this.handleConnectionClosed.bind(this));
|
|
231
|
-
}
|
|
232
|
-
listen(port = 0, host) {
|
|
233
|
-
if (host === "::") {
|
|
234
|
-
// this will work around "EAFNOSUPPORT: address family not supported" errors
|
|
235
|
-
// on systems where IPv6 is not supported/enabled, we just use the node default then by supplying undefined
|
|
236
|
-
host = undefined;
|
|
237
|
-
}
|
|
238
|
-
this.httpServer.listen(port, host);
|
|
239
|
-
}
|
|
240
|
-
stop() {
|
|
241
|
-
this.httpServer.stop();
|
|
242
|
-
}
|
|
243
|
-
destroy() {
|
|
244
|
-
this.stop();
|
|
245
|
-
this.removeAllListeners();
|
|
246
|
-
}
|
|
247
|
-
/**
|
|
248
|
-
* Send an even notification for given characteristic and changed value to all connected clients.
|
|
249
|
-
* If `originator` is specified, the given {@link HAPConnection} will be excluded from the broadcast.
|
|
250
|
-
*
|
|
251
|
-
* @param aid - The accessory id of the updated characteristic.
|
|
252
|
-
* @param iid - The instance id of the updated characteristic.
|
|
253
|
-
* @param value - The newly set value of the characteristic.
|
|
254
|
-
* @param originator - If specified, the connection will not get an event message.
|
|
255
|
-
* @param immediateDelivery - The HAP spec requires some characteristics to be delivery immediately.
|
|
256
|
-
* Namely, for the {@link Characteristic.ButtonEvent} and the {@link Characteristic.ProgrammableSwitchEvent} characteristics.
|
|
257
|
-
*/
|
|
258
|
-
sendEventNotifications(aid, iid, value, originator, immediateDelivery) {
|
|
259
|
-
try {
|
|
260
|
-
this.httpServer.broadcastEvent(aid, iid, value, originator, immediateDelivery);
|
|
261
|
-
}
|
|
262
|
-
catch (error) {
|
|
263
|
-
console.warn("[" + this.accessoryInfo.username + "] Error when sending event notifications: " + error.message);
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
onListening(port, hostname) {
|
|
267
|
-
this.emit("listening" /* HAPServerEventTypes.LISTENING */, port, hostname);
|
|
268
|
-
}
|
|
269
|
-
// Called when an HTTP request was detected.
|
|
270
|
-
handleRequestOnHAPConnection(connection, request, response) {
|
|
271
|
-
debug("[%s] HAP Request: %s %s", this.accessoryInfo.username, request.method, request.url);
|
|
272
|
-
const requestPath = new url_1.URL(request.url, "http://hap-nodejs.local").pathname;
|
|
273
|
-
console.info("[HK4K-HAP-DIAG] request", JSON.stringify({ method: request.method, url: request.url, remote: connection.remoteAddress }));
|
|
274
|
-
response.once("finish", () => console.info("[HK4K-HAP-DIAG] response", JSON.stringify({ method: request.method, path: requestPath, status: response.statusCode, remote: connection.remoteAddress })));
|
|
275
|
-
const buffers = [];
|
|
276
|
-
request.on("data", data => buffers.push(data));
|
|
277
|
-
request.on("end", () => {
|
|
278
|
-
const url = new url_1.URL(request.url, "http://hap-nodejs.local"); // parse the url (query strings etc)
|
|
279
|
-
const handler = this.getHandler(url);
|
|
280
|
-
if (!handler) {
|
|
281
|
-
debug("[%s] WARNING: Handler for %s not implemented", this.accessoryInfo.username, request.url);
|
|
282
|
-
response.writeHead(404 /* HAPHTTPCode.NOT_FOUND */, { "Content-Type": "application/hap+json" /* HAPMimeTypes.HAP_JSON */ });
|
|
283
|
-
response.end(JSON.stringify({ status: -70409 /* HAPStatus.RESOURCE_DOES_NOT_EXIST */ }));
|
|
284
|
-
}
|
|
285
|
-
else {
|
|
286
|
-
const data = Buffer.concat(buffers);
|
|
287
|
-
try {
|
|
288
|
-
handler(connection, url, request, data, response);
|
|
289
|
-
}
|
|
290
|
-
catch (error) {
|
|
291
|
-
debug("[%s] Error executing route handler: %s", this.accessoryInfo.username, error.stack);
|
|
292
|
-
response.writeHead(500 /* HAPHTTPCode.INTERNAL_SERVER_ERROR */, { "Content-Type": "application/hap+json" /* HAPMimeTypes.HAP_JSON */ });
|
|
293
|
-
response.end(JSON.stringify({ status: -70403 /* HAPStatus.RESOURCE_BUSY */ })); // resource busy try again, does somehow fit?
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
});
|
|
297
|
-
}
|
|
298
|
-
handleConnectionClosed(connection) {
|
|
299
|
-
this.emit("connection-closed" /* HAPServerEventTypes.CONNECTION_CLOSED */, connection);
|
|
300
|
-
}
|
|
301
|
-
getHandler(url) {
|
|
302
|
-
switch (url.pathname.toLowerCase()) {
|
|
303
|
-
case "/identify":
|
|
304
|
-
return this.handleIdentifyRequest.bind(this);
|
|
305
|
-
case "/pair-setup":
|
|
306
|
-
return this.handlePairSetup.bind(this);
|
|
307
|
-
case "/pair-verify":
|
|
308
|
-
return this.handlePairVerify.bind(this);
|
|
309
|
-
case "/pairings":
|
|
310
|
-
return this.handlePairings.bind(this);
|
|
311
|
-
case "/accessories":
|
|
312
|
-
return this.handleAccessories.bind(this);
|
|
313
|
-
case "/characteristics":
|
|
314
|
-
return this.handleCharacteristics.bind(this);
|
|
315
|
-
case "/prepare":
|
|
316
|
-
return this.handlePrepareWrite.bind(this);
|
|
317
|
-
case "/resource":
|
|
318
|
-
return this.handleResource.bind(this);
|
|
319
|
-
default:
|
|
320
|
-
return undefined;
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
/**
|
|
324
|
-
* UNPAIRED Accessory identification.
|
|
325
|
-
*/
|
|
326
|
-
handleIdentifyRequest(connection, url, request, data, response) {
|
|
327
|
-
// POST body is empty
|
|
328
|
-
if (this.accessoryInfo.paired() && !this.allowInsecureRequest) {
|
|
329
|
-
response.writeHead(400 /* HAPHTTPCode.BAD_REQUEST */, { "Content-Type": "application/hap+json" /* HAPMimeTypes.HAP_JSON */ });
|
|
330
|
-
response.end(JSON.stringify({ status: -70401 /* HAPStatus.INSUFFICIENT_PRIVILEGES */ }));
|
|
331
|
-
return;
|
|
332
|
-
}
|
|
333
|
-
this.emit("identify" /* HAPServerEventTypes.IDENTIFY */, (0, once_1.once)(err => {
|
|
334
|
-
if (!err) {
|
|
335
|
-
debug("[%s] Identification success", this.accessoryInfo.username);
|
|
336
|
-
response.writeHead(204 /* HAPHTTPCode.NO_CONTENT */);
|
|
337
|
-
response.end();
|
|
338
|
-
}
|
|
339
|
-
else {
|
|
340
|
-
debug("[%s] Identification error: %s", this.accessoryInfo.username, err.message);
|
|
341
|
-
response.writeHead(500 /* HAPHTTPCode.INTERNAL_SERVER_ERROR */, { "Content-Type": "application/hap+json" /* HAPMimeTypes.HAP_JSON */ });
|
|
342
|
-
response.end(JSON.stringify({ status: -70403 /* HAPStatus.RESOURCE_BUSY */ }));
|
|
343
|
-
}
|
|
344
|
-
}));
|
|
345
|
-
}
|
|
346
|
-
handlePairSetup(connection, url, request, data, response) {
|
|
347
|
-
// Can only be directly paired with one iOS device
|
|
348
|
-
if (!this.allowInsecureRequest && this.accessoryInfo.paired()) {
|
|
349
|
-
response.writeHead(200 /* HAPPairingHTTPCode.OK */, { "Content-Type": "application/pairing+tlv8" });
|
|
350
|
-
response.end(tlv.encode(6 /* TLVValues.STATE */, 2 /* PairingStates.M2 */, 7 /* TLVValues.ERROR_CODE */, 6 /* TLVErrorCode.UNAVAILABLE */));
|
|
351
|
-
return;
|
|
352
|
-
}
|
|
353
|
-
if (this.unsuccessfulPairAttempts > 100) {
|
|
354
|
-
debug("[%s] Reached maximum amount of unsuccessful pair attempts!", this.accessoryInfo.username);
|
|
355
|
-
response.writeHead(200 /* HAPPairingHTTPCode.OK */, { "Content-Type": "application/pairing+tlv8" });
|
|
356
|
-
response.end(tlv.encode(6 /* TLVValues.STATE */, 2 /* PairingStates.M2 */, 7 /* TLVValues.ERROR_CODE */, 5 /* TLVErrorCode.MAX_TRIES */));
|
|
357
|
-
return;
|
|
358
|
-
}
|
|
359
|
-
let tlvData;
|
|
360
|
-
try {
|
|
361
|
-
tlvData = tlv.decode(data);
|
|
362
|
-
}
|
|
363
|
-
catch (error) {
|
|
364
|
-
debug("[%s] Pair-Setup: failed to decode TLV request: %s", this.accessoryInfo.username, error.message);
|
|
365
|
-
response.writeHead(400 /* HAPPairingHTTPCode.BAD_REQUEST */, { "Content-Type": "application/pairing+tlv8" });
|
|
366
|
-
response.end(tlv.encode(6 /* TLVValues.STATE */, 2 /* PairingStates.M2 */, 7 /* TLVValues.ERROR_CODE */, 1 /* TLVErrorCode.UNKNOWN */));
|
|
367
|
-
return;
|
|
368
|
-
}
|
|
369
|
-
if (!tlvData[6 /* TLVValues.SEQUENCE_NUM */]) {
|
|
370
|
-
response.writeHead(400 /* HAPPairingHTTPCode.BAD_REQUEST */, { "Content-Type": "application/pairing+tlv8" });
|
|
371
|
-
response.end(tlv.encode(6 /* TLVValues.STATE */, 2 /* PairingStates.M2 */, 7 /* TLVValues.ERROR_CODE */, 1 /* TLVErrorCode.UNKNOWN */));
|
|
372
|
-
return;
|
|
373
|
-
}
|
|
374
|
-
const sequence = tlvData[6 /* TLVValues.SEQUENCE_NUM */][0]; // value is single byte with sequence number
|
|
375
|
-
if (sequence === 1 /* PairingStates.M1 */ && !connection._pairSetupState) {
|
|
376
|
-
this.handlePairSetupM1(connection, request, response);
|
|
377
|
-
}
|
|
378
|
-
else if (sequence === 3 /* PairingStates.M3 */ && connection._pairSetupState === 2 /* PairingStates.M2 */) {
|
|
379
|
-
this.handlePairSetupM3(connection, request, response, tlvData);
|
|
380
|
-
}
|
|
381
|
-
else if (sequence === 5 /* PairingStates.M5 */ && connection._pairSetupState === 4 /* PairingStates.M4 */) {
|
|
382
|
-
this.handlePairSetupM5(connection, request, response, tlvData);
|
|
383
|
-
}
|
|
384
|
-
else {
|
|
385
|
-
// Invalid state/sequence number
|
|
386
|
-
response.writeHead(400 /* HAPPairingHTTPCode.BAD_REQUEST */, { "Content-Type": "application/pairing+tlv8" });
|
|
387
|
-
response.end(tlv.encode(6 /* TLVValues.STATE */, sequence + 1, 7 /* TLVValues.ERROR_CODE */, 1 /* TLVErrorCode.UNKNOWN */));
|
|
388
|
-
return;
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
handlePairSetupM1(connection, request, response) {
|
|
392
|
-
debug("[%s] Pair step 1/5", this.accessoryInfo.username);
|
|
393
|
-
const salt = crypto_1.default.randomBytes(16);
|
|
394
|
-
const srpParams = fast_srp_hap_1.SRP.params.hap;
|
|
395
|
-
fast_srp_hap_1.SRP.genKey(32).then(key => {
|
|
396
|
-
// create a new SRP server
|
|
397
|
-
const srpServer = new fast_srp_hap_1.SrpServer(srpParams, salt, Buffer.from("Pair-Setup"), Buffer.from(this.accessoryInfo.pincode), key);
|
|
398
|
-
const srpB = srpServer.computeB();
|
|
399
|
-
// attach it to the current TCP session
|
|
400
|
-
connection.srpServer = srpServer;
|
|
401
|
-
response.writeHead(200 /* HAPPairingHTTPCode.OK */, { "Content-Type": "application/pairing+tlv8" });
|
|
402
|
-
response.end(tlv.encode(6 /* TLVValues.SEQUENCE_NUM */, 2 /* PairingStates.M2 */, 2 /* TLVValues.SALT */, salt, 3 /* TLVValues.PUBLIC_KEY */, srpB));
|
|
403
|
-
connection._pairSetupState = 2 /* PairingStates.M2 */;
|
|
404
|
-
}).catch(error => {
|
|
405
|
-
debug("[%s] Error occurred when generating srp key: %s", this.accessoryInfo.username, error.message);
|
|
406
|
-
response.writeHead(200 /* HAPPairingHTTPCode.OK */, { "Content-Type": "application/pairing+tlv8" });
|
|
407
|
-
response.end(tlv.encode(6 /* TLVValues.STATE */, 2 /* PairingStates.M2 */, 7 /* TLVValues.ERROR_CODE */, 1 /* TLVErrorCode.UNKNOWN */));
|
|
408
|
-
return;
|
|
409
|
-
});
|
|
410
|
-
}
|
|
411
|
-
handlePairSetupM3(connection, request, response, tlvData) {
|
|
412
|
-
debug("[%s] Pair step 2/5", this.accessoryInfo.username);
|
|
413
|
-
const A = tlvData[3 /* TLVValues.PUBLIC_KEY */]; // "A is a public key that exists only for a single login session."
|
|
414
|
-
const M1 = tlvData[4 /* TLVValues.PASSWORD_PROOF */]; // "M1 is the proof that you actually know your own password."
|
|
415
|
-
// pull the SRP server we created in stepOne out of the current session
|
|
416
|
-
const srpServer = connection.srpServer;
|
|
417
|
-
srpServer.setA(A);
|
|
418
|
-
try {
|
|
419
|
-
srpServer.checkM1(M1);
|
|
420
|
-
}
|
|
421
|
-
catch (err) {
|
|
422
|
-
// most likely the client supplied an incorrect pincode.
|
|
423
|
-
this.unsuccessfulPairAttempts++;
|
|
424
|
-
debug("[%s] Error while checking pincode: %s", this.accessoryInfo.username, err.message);
|
|
425
|
-
response.writeHead(200 /* HAPPairingHTTPCode.OK */, { "Content-Type": "application/pairing+tlv8" });
|
|
426
|
-
response.end(tlv.encode(6 /* TLVValues.SEQUENCE_NUM */, 4 /* PairingStates.M4 */, 7 /* TLVValues.ERROR_CODE */, 2 /* TLVErrorCode.AUTHENTICATION */));
|
|
427
|
-
connection._pairSetupState = undefined;
|
|
428
|
-
return;
|
|
429
|
-
}
|
|
430
|
-
// "M2 is the proof that the server actually knows your password."
|
|
431
|
-
const M2 = srpServer.computeM2();
|
|
432
|
-
response.writeHead(200 /* HAPPairingHTTPCode.OK */, { "Content-Type": "application/pairing+tlv8" });
|
|
433
|
-
response.end(tlv.encode(6 /* TLVValues.SEQUENCE_NUM */, 4 /* PairingStates.M4 */, 4 /* TLVValues.PASSWORD_PROOF */, M2));
|
|
434
|
-
connection._pairSetupState = 4 /* PairingStates.M4 */;
|
|
435
|
-
}
|
|
436
|
-
handlePairSetupM5(connection, request, response, tlvData) {
|
|
437
|
-
debug("[%s] Pair step 3/5", this.accessoryInfo.username);
|
|
438
|
-
// pull the SRP server we created in stepOne out of the current session
|
|
439
|
-
const srpServer = connection.srpServer;
|
|
440
|
-
const encryptedData = tlvData[5 /* TLVValues.ENCRYPTED_DATA */];
|
|
441
|
-
if (!encryptedData || encryptedData.length < 16) {
|
|
442
|
-
debug("[%s] M5: Encrypted data missing or too short", this.accessoryInfo.username);
|
|
443
|
-
response.writeHead(200 /* HAPPairingHTTPCode.OK */, { "Content-Type": "application/pairing+tlv8" });
|
|
444
|
-
response.end(tlv.encode(6 /* TLVValues.SEQUENCE_NUM */, 4 /* PairingStates.M4 */, 7 /* TLVValues.ERROR_CODE */, 2 /* TLVErrorCode.AUTHENTICATION */));
|
|
445
|
-
connection._pairSetupState = undefined;
|
|
446
|
-
return;
|
|
447
|
-
}
|
|
448
|
-
const messageData = Buffer.alloc(encryptedData.length - 16);
|
|
449
|
-
const authTagData = Buffer.alloc(16);
|
|
450
|
-
encryptedData.copy(messageData, 0, 0, encryptedData.length - 16);
|
|
451
|
-
encryptedData.copy(authTagData, 0, encryptedData.length - 16, encryptedData.length);
|
|
452
|
-
const S_private = srpServer.computeK();
|
|
453
|
-
const encSalt = Buffer.from("Pair-Setup-Encrypt-Salt");
|
|
454
|
-
const encInfo = Buffer.from("Pair-Setup-Encrypt-Info");
|
|
455
|
-
const outputKey = hapCrypto.HKDF("sha512", encSalt, S_private, encInfo, 32);
|
|
456
|
-
let plaintext;
|
|
457
|
-
try {
|
|
458
|
-
plaintext = hapCrypto.chacha20_poly1305_decryptAndVerify(outputKey, Buffer.from("PS-Msg05"), null, messageData, authTagData);
|
|
459
|
-
}
|
|
460
|
-
catch (error) {
|
|
461
|
-
debug("[%s] Error while decrypting and verifying M5 subTlv: %s", this.accessoryInfo.username, error);
|
|
462
|
-
response.writeHead(200 /* HAPPairingHTTPCode.OK */, { "Content-Type": "application/pairing+tlv8" });
|
|
463
|
-
response.end(tlv.encode(6 /* TLVValues.SEQUENCE_NUM */, 4 /* PairingStates.M4 */, 7 /* TLVValues.ERROR_CODE */, 2 /* TLVErrorCode.AUTHENTICATION */));
|
|
464
|
-
connection._pairSetupState = undefined;
|
|
465
|
-
return;
|
|
466
|
-
}
|
|
467
|
-
// decode the client payload and pass it on to the next step
|
|
468
|
-
let M5Packet;
|
|
469
|
-
try {
|
|
470
|
-
M5Packet = tlv.decode(plaintext);
|
|
471
|
-
}
|
|
472
|
-
catch (error) {
|
|
473
|
-
debug("[%s] M5: Failed to decode decrypted TLV payload: %s", this.accessoryInfo.username, error.message);
|
|
474
|
-
response.writeHead(200 /* HAPPairingHTTPCode.OK */, { "Content-Type": "application/pairing+tlv8" });
|
|
475
|
-
response.end(tlv.encode(6 /* TLVValues.SEQUENCE_NUM */, 4 /* PairingStates.M4 */, 7 /* TLVValues.ERROR_CODE */, 1 /* TLVErrorCode.UNKNOWN */));
|
|
476
|
-
connection._pairSetupState = undefined;
|
|
477
|
-
return;
|
|
478
|
-
}
|
|
479
|
-
const clientUsername = M5Packet[1 /* TLVValues.USERNAME */];
|
|
480
|
-
const clientLTPK = M5Packet[3 /* TLVValues.PUBLIC_KEY */];
|
|
481
|
-
const clientProof = M5Packet[10 /* TLVValues.PROOF */];
|
|
482
|
-
if (!clientUsername || !clientLTPK || !clientProof) {
|
|
483
|
-
debug("[%s] M5: Missing required TLV fields in decrypted payload", this.accessoryInfo.username);
|
|
484
|
-
response.writeHead(200 /* HAPPairingHTTPCode.OK */, { "Content-Type": "application/pairing+tlv8" });
|
|
485
|
-
response.end(tlv.encode(6 /* TLVValues.SEQUENCE_NUM */, 4 /* PairingStates.M4 */, 7 /* TLVValues.ERROR_CODE */, 1 /* TLVErrorCode.UNKNOWN */));
|
|
486
|
-
connection._pairSetupState = undefined;
|
|
487
|
-
return;
|
|
488
|
-
}
|
|
489
|
-
this.handlePairSetupM5_2(connection, request, response, clientUsername, clientLTPK, clientProof, outputKey);
|
|
490
|
-
}
|
|
491
|
-
// M5-2
|
|
492
|
-
handlePairSetupM5_2(connection, request, response, clientUsername, clientLTPK, clientProof, hkdfEncKey) {
|
|
493
|
-
debug("[%s] Pair step 4/5", this.accessoryInfo.username);
|
|
494
|
-
const S_private = connection.srpServer.computeK();
|
|
495
|
-
const controllerSalt = Buffer.from("Pair-Setup-Controller-Sign-Salt");
|
|
496
|
-
const controllerInfo = Buffer.from("Pair-Setup-Controller-Sign-Info");
|
|
497
|
-
const outputKey = hapCrypto.HKDF("sha512", controllerSalt, S_private, controllerInfo, 32);
|
|
498
|
-
const completeData = Buffer.concat([outputKey, clientUsername, clientLTPK]);
|
|
499
|
-
if (!tweetnacl_1.default.sign.detached.verify(completeData, clientProof, clientLTPK)) {
|
|
500
|
-
debug("[%s] Invalid signature", this.accessoryInfo.username);
|
|
501
|
-
response.writeHead(200 /* HAPPairingHTTPCode.OK */, { "Content-Type": "application/pairing+tlv8" });
|
|
502
|
-
response.end(tlv.encode(6 /* TLVValues.SEQUENCE_NUM */, 6 /* PairingStates.M6 */, 7 /* TLVValues.ERROR_CODE */, 2 /* TLVErrorCode.AUTHENTICATION */));
|
|
503
|
-
connection._pairSetupState = undefined;
|
|
504
|
-
return;
|
|
505
|
-
}
|
|
506
|
-
this.handlePairSetupM5_3(connection, request, response, clientUsername, clientLTPK, hkdfEncKey);
|
|
507
|
-
}
|
|
508
|
-
// M5 - F + M6
|
|
509
|
-
handlePairSetupM5_3(connection, request, response, clientUsername, clientLTPK, hkdfEncKey) {
|
|
510
|
-
debug("[%s] Pair step 5/5", this.accessoryInfo.username);
|
|
511
|
-
const S_private = connection.srpServer.computeK();
|
|
512
|
-
const accessorySalt = Buffer.from("Pair-Setup-Accessory-Sign-Salt");
|
|
513
|
-
const accessoryInfo = Buffer.from("Pair-Setup-Accessory-Sign-Info");
|
|
514
|
-
const outputKey = hapCrypto.HKDF("sha512", accessorySalt, S_private, accessoryInfo, 32);
|
|
515
|
-
const serverLTPK = this.accessoryInfo.signPk;
|
|
516
|
-
const usernameData = Buffer.from(this.accessoryInfo.username);
|
|
517
|
-
const material = Buffer.concat([outputKey, usernameData, serverLTPK]);
|
|
518
|
-
const privateKey = Buffer.from(this.accessoryInfo.signSk);
|
|
519
|
-
const serverProof = tweetnacl_1.default.sign.detached(material, privateKey);
|
|
520
|
-
const message = tlv.encode(1 /* TLVValues.USERNAME */, usernameData, 3 /* TLVValues.PUBLIC_KEY */, serverLTPK, 10 /* TLVValues.PROOF */, serverProof);
|
|
521
|
-
const encrypted = hapCrypto.chacha20_poly1305_encryptAndSeal(hkdfEncKey, Buffer.from("PS-Msg06"), null, message);
|
|
522
|
-
// finally, notify listeners that we have been paired with a client
|
|
523
|
-
this.emit("pair" /* HAPServerEventTypes.PAIR */, clientUsername.toString(), clientLTPK, (0, once_1.once)(err => {
|
|
524
|
-
if (err) {
|
|
525
|
-
debug("[%s] Error adding pairing info: %s", this.accessoryInfo.username, err.message);
|
|
526
|
-
response.writeHead(200 /* HAPPairingHTTPCode.OK */, { "Content-Type": "application/pairing+tlv8" });
|
|
527
|
-
response.end(tlv.encode(6 /* TLVValues.SEQUENCE_NUM */, 6 /* PairingStates.M6 */, 7 /* TLVValues.ERROR_CODE */, 1 /* TLVErrorCode.UNKNOWN */));
|
|
528
|
-
connection._pairSetupState = undefined;
|
|
529
|
-
return;
|
|
530
|
-
}
|
|
531
|
-
// send final pairing response to client
|
|
532
|
-
response.writeHead(200 /* HAPPairingHTTPCode.OK */, { "Content-Type": "application/pairing+tlv8" });
|
|
533
|
-
response.end(tlv.encode(6 /* TLVValues.SEQUENCE_NUM */, 6 /* PairingStates.M6 */, 5 /* TLVValues.ENCRYPTED_DATA */, Buffer.concat([encrypted.ciphertext, encrypted.authTag])));
|
|
534
|
-
connection._pairSetupState = undefined;
|
|
535
|
-
}));
|
|
536
|
-
}
|
|
537
|
-
handlePairVerify(connection, url, request, data, response) {
|
|
538
|
-
let tlvData;
|
|
539
|
-
try {
|
|
540
|
-
tlvData = tlv.decode(data);
|
|
541
|
-
}
|
|
542
|
-
catch (error) {
|
|
543
|
-
debug("[%s] Pair-Verify: failed to decode TLV request: %s", this.accessoryInfo.username, error.message);
|
|
544
|
-
response.writeHead(400 /* HAPPairingHTTPCode.BAD_REQUEST */, { "Content-Type": "application/pairing+tlv8" });
|
|
545
|
-
response.end(tlv.encode(6 /* TLVValues.STATE */, 2 /* PairingStates.M2 */, 7 /* TLVValues.ERROR_CODE */, 1 /* TLVErrorCode.UNKNOWN */));
|
|
546
|
-
return;
|
|
547
|
-
}
|
|
548
|
-
if (!tlvData[6 /* TLVValues.SEQUENCE_NUM */]) {
|
|
549
|
-
response.writeHead(400 /* HAPPairingHTTPCode.BAD_REQUEST */, { "Content-Type": "application/pairing+tlv8" });
|
|
550
|
-
response.end(tlv.encode(6 /* TLVValues.STATE */, 2 /* PairingStates.M2 */, 7 /* TLVValues.ERROR_CODE */, 1 /* TLVErrorCode.UNKNOWN */));
|
|
551
|
-
return;
|
|
552
|
-
}
|
|
553
|
-
const sequence = tlvData[6 /* TLVValues.SEQUENCE_NUM */][0]; // value is single byte with sequence number
|
|
554
|
-
if (sequence === 1 /* PairingStates.M1 */) {
|
|
555
|
-
this.handlePairVerifyM1(connection, request, response, tlvData);
|
|
556
|
-
}
|
|
557
|
-
else if (sequence === 3 /* PairingStates.M3 */ && connection._pairVerifyState === 2 /* PairingStates.M2 */) {
|
|
558
|
-
this.handlePairVerifyM3(connection, request, response, tlvData);
|
|
559
|
-
}
|
|
560
|
-
else {
|
|
561
|
-
// Invalid state/sequence number
|
|
562
|
-
response.writeHead(400 /* HAPPairingHTTPCode.BAD_REQUEST */, { "Content-Type": "application/pairing+tlv8" });
|
|
563
|
-
response.end(tlv.encode(6 /* TLVValues.STATE */, sequence + 1, 7 /* TLVValues.ERROR_CODE */, 1 /* TLVErrorCode.UNKNOWN */));
|
|
564
|
-
return;
|
|
565
|
-
}
|
|
566
|
-
}
|
|
567
|
-
handlePairVerifyM1(connection, request, response, tlvData) {
|
|
568
|
-
debug("[%s] Pair verify step 1/2", this.accessoryInfo.username);
|
|
569
|
-
const clientPublicKey = tlvData[3 /* TLVValues.PUBLIC_KEY */]; // Buffer
|
|
570
|
-
// generate new encryption keys for this session
|
|
571
|
-
const keyPair = hapCrypto.generateCurve25519KeyPair();
|
|
572
|
-
const secretKey = Buffer.from(keyPair.secretKey);
|
|
573
|
-
const publicKey = Buffer.from(keyPair.publicKey);
|
|
574
|
-
const sharedSec = Buffer.from(hapCrypto.generateCurve25519SharedSecKey(secretKey, clientPublicKey));
|
|
575
|
-
const usernameData = Buffer.from(this.accessoryInfo.username);
|
|
576
|
-
const material = Buffer.concat([publicKey, usernameData, clientPublicKey]);
|
|
577
|
-
const privateKey = Buffer.from(this.accessoryInfo.signSk);
|
|
578
|
-
const serverProof = tweetnacl_1.default.sign.detached(material, privateKey);
|
|
579
|
-
const encSalt = Buffer.from("Pair-Verify-Encrypt-Salt");
|
|
580
|
-
const encInfo = Buffer.from("Pair-Verify-Encrypt-Info");
|
|
581
|
-
const outputKey = hapCrypto.HKDF("sha512", encSalt, sharedSec, encInfo, 32).subarray(0, 32);
|
|
582
|
-
connection.encryption = new eventedhttp_1.HAPEncryption(clientPublicKey, secretKey, publicKey, sharedSec, outputKey);
|
|
583
|
-
// compose the response data in TLV format
|
|
584
|
-
const message = tlv.encode(1 /* TLVValues.USERNAME */, usernameData, 10 /* TLVValues.PROOF */, serverProof);
|
|
585
|
-
const encrypted = hapCrypto.chacha20_poly1305_encryptAndSeal(outputKey, Buffer.from("PV-Msg02"), null, message);
|
|
586
|
-
response.writeHead(200 /* HAPPairingHTTPCode.OK */, { "Content-Type": "application/pairing+tlv8" });
|
|
587
|
-
response.end(tlv.encode(6 /* TLVValues.SEQUENCE_NUM */, 2 /* PairingStates.M2 */, 5 /* TLVValues.ENCRYPTED_DATA */, Buffer.concat([encrypted.ciphertext, encrypted.authTag]), 3 /* TLVValues.PUBLIC_KEY */, publicKey));
|
|
588
|
-
connection._pairVerifyState = 2 /* PairingStates.M2 */;
|
|
589
|
-
}
|
|
590
|
-
handlePairVerifyM3(connection, request, response, objects) {
|
|
591
|
-
debug("[%s] Pair verify step 2/2", this.accessoryInfo.username);
|
|
592
|
-
const encryptedData = objects[5 /* TLVValues.ENCRYPTED_DATA */];
|
|
593
|
-
if (!encryptedData || encryptedData.length < 16) {
|
|
594
|
-
debug("[%s] M3: Encrypted data missing or too short", this.accessoryInfo.username);
|
|
595
|
-
response.writeHead(200 /* HAPPairingHTTPCode.OK */, { "Content-Type": "application/pairing+tlv8" });
|
|
596
|
-
response.end(tlv.encode(6 /* TLVValues.STATE */, 4 /* PairingStates.M4 */, 7 /* TLVValues.ERROR_CODE */, 2 /* TLVErrorCode.AUTHENTICATION */));
|
|
597
|
-
connection._pairVerifyState = undefined;
|
|
598
|
-
return;
|
|
599
|
-
}
|
|
600
|
-
const messageData = Buffer.alloc(encryptedData.length - 16);
|
|
601
|
-
const authTagData = Buffer.alloc(16);
|
|
602
|
-
encryptedData.copy(messageData, 0, 0, encryptedData.length - 16);
|
|
603
|
-
encryptedData.copy(authTagData, 0, encryptedData.length - 16, encryptedData.length);
|
|
604
|
-
// instance of HAPEncryption (created in handlePairVerifyStepOne)
|
|
605
|
-
const enc = connection.encryption;
|
|
606
|
-
let plaintext;
|
|
607
|
-
try {
|
|
608
|
-
plaintext = hapCrypto.chacha20_poly1305_decryptAndVerify(enc.hkdfPairEncryptionKey, Buffer.from("PV-Msg03"), null, messageData, authTagData);
|
|
609
|
-
}
|
|
610
|
-
catch (error) {
|
|
611
|
-
debug("[%s] M3: Failed to decrypt and/or verify: %s", this.accessoryInfo.username, error);
|
|
612
|
-
response.writeHead(200 /* HAPPairingHTTPCode.OK */, { "Content-Type": "application/pairing+tlv8" });
|
|
613
|
-
response.end(tlv.encode(6 /* TLVValues.STATE */, 4 /* PairingStates.M4 */, 7 /* TLVValues.ERROR_CODE */, 2 /* TLVErrorCode.AUTHENTICATION */));
|
|
614
|
-
connection._pairVerifyState = undefined;
|
|
615
|
-
return;
|
|
616
|
-
}
|
|
617
|
-
let decoded;
|
|
618
|
-
try {
|
|
619
|
-
decoded = tlv.decode(plaintext);
|
|
620
|
-
}
|
|
621
|
-
catch (error) {
|
|
622
|
-
debug("[%s] M3: Failed to decode decrypted TLV payload: %s", this.accessoryInfo.username, error.message);
|
|
623
|
-
response.writeHead(200 /* HAPPairingHTTPCode.OK */, { "Content-Type": "application/pairing+tlv8" });
|
|
624
|
-
response.end(tlv.encode(6 /* TLVValues.STATE */, 4 /* PairingStates.M4 */, 7 /* TLVValues.ERROR_CODE */, 1 /* TLVErrorCode.UNKNOWN */));
|
|
625
|
-
connection._pairVerifyState = undefined;
|
|
626
|
-
return;
|
|
627
|
-
}
|
|
628
|
-
const clientUsername = decoded[1 /* TLVValues.USERNAME */];
|
|
629
|
-
const proof = decoded[10 /* TLVValues.PROOF */];
|
|
630
|
-
if (!clientUsername || !proof) {
|
|
631
|
-
debug("[%s] M3: Missing required TLV fields in decrypted payload", this.accessoryInfo.username);
|
|
632
|
-
response.writeHead(200 /* HAPPairingHTTPCode.OK */, { "Content-Type": "application/pairing+tlv8" });
|
|
633
|
-
response.end(tlv.encode(6 /* TLVValues.STATE */, 4 /* PairingStates.M4 */, 7 /* TLVValues.ERROR_CODE */, 1 /* TLVErrorCode.UNKNOWN */));
|
|
634
|
-
connection._pairVerifyState = undefined;
|
|
635
|
-
return;
|
|
636
|
-
}
|
|
637
|
-
const material = Buffer.concat([enc.clientPublicKey, clientUsername, enc.publicKey]);
|
|
638
|
-
// since we're paired, we should have the public key stored for this client
|
|
639
|
-
const clientPublicKey = this.accessoryInfo.getClientPublicKey(clientUsername.toString());
|
|
640
|
-
// if we're not actually paired, then there's nothing to verify - this client thinks it's paired with us, but we
|
|
641
|
-
// disagree. Respond with invalid request (seems to match HomeKit Accessory Simulator behavior)
|
|
642
|
-
if (!clientPublicKey) {
|
|
643
|
-
debug("[%s] Client %s attempting to verify, but we are not paired; rejecting client", this.accessoryInfo.username, clientUsername);
|
|
644
|
-
response.writeHead(200 /* HAPPairingHTTPCode.OK */, { "Content-Type": "application/pairing+tlv8" });
|
|
645
|
-
response.end(tlv.encode(6 /* TLVValues.STATE */, 4 /* PairingStates.M4 */, 7 /* TLVValues.ERROR_CODE */, 2 /* TLVErrorCode.AUTHENTICATION */));
|
|
646
|
-
connection._pairVerifyState = undefined;
|
|
647
|
-
return;
|
|
648
|
-
}
|
|
649
|
-
if (!tweetnacl_1.default.sign.detached.verify(material, proof, clientPublicKey)) {
|
|
650
|
-
debug("[%s] Client %s provided an invalid signature", this.accessoryInfo.username, clientUsername);
|
|
651
|
-
response.writeHead(200 /* HAPPairingHTTPCode.OK */, { "Content-Type": "application/pairing+tlv8" });
|
|
652
|
-
response.end(tlv.encode(6 /* TLVValues.STATE */, 4 /* PairingStates.M4 */, 7 /* TLVValues.ERROR_CODE */, 2 /* TLVErrorCode.AUTHENTICATION */));
|
|
653
|
-
connection._pairVerifyState = undefined;
|
|
654
|
-
return;
|
|
655
|
-
}
|
|
656
|
-
debug("[%s] Client %s verification complete", this.accessoryInfo.username, clientUsername);
|
|
657
|
-
response.writeHead(200 /* HAPPairingHTTPCode.OK */, { "Content-Type": "application/pairing+tlv8" });
|
|
658
|
-
response.end(tlv.encode(6 /* TLVValues.SEQUENCE_NUM */, 4 /* PairingStates.M4 */));
|
|
659
|
-
// now that the client has been verified, we must "upgrade" our pseudo-HTTP connection to include
|
|
660
|
-
// TCP-level encryption. We'll do this by adding some more encryption vars to the session, and using them
|
|
661
|
-
// in future calls to onEncrypt, onDecrypt.
|
|
662
|
-
const encSalt = Buffer.from("Control-Salt");
|
|
663
|
-
const infoRead = Buffer.from("Control-Read-Encryption-Key");
|
|
664
|
-
const infoWrite = Buffer.from("Control-Write-Encryption-Key");
|
|
665
|
-
enc.accessoryToControllerKey = hapCrypto.HKDF("sha512", encSalt, enc.sharedSecret, infoRead, 32);
|
|
666
|
-
enc.controllerToAccessoryKey = hapCrypto.HKDF("sha512", encSalt, enc.sharedSecret, infoWrite, 32);
|
|
667
|
-
// Our connection is now completely setup. We now want to subscribe this connection to special
|
|
668
|
-
connection.connectionAuthenticated(clientUsername.toString());
|
|
669
|
-
connection._pairVerifyState = undefined;
|
|
670
|
-
}
|
|
671
|
-
handlePairings(connection, url, request, data, response) {
|
|
672
|
-
// Only accept /pairing request if there is a secure session
|
|
673
|
-
if (!this.allowInsecureRequest && !connection.isAuthenticated()) {
|
|
674
|
-
response.writeHead(470 /* HAPPairingHTTPCode.CONNECTION_AUTHORIZATION_REQUIRED */, { "Content-Type": "application/hap+json" /* HAPMimeTypes.HAP_JSON */ });
|
|
675
|
-
response.end(JSON.stringify({ status: -70401 /* HAPStatus.INSUFFICIENT_PRIVILEGES */ }));
|
|
676
|
-
return;
|
|
677
|
-
}
|
|
678
|
-
let objects;
|
|
679
|
-
try {
|
|
680
|
-
objects = tlv.decode(data);
|
|
681
|
-
}
|
|
682
|
-
catch (error) {
|
|
683
|
-
debug("[%s] Pairings: failed to decode TLV request: %s", this.accessoryInfo.username, error.message);
|
|
684
|
-
response.writeHead(200 /* HAPPairingHTTPCode.OK */, { "Content-Type": "application/pairing+tlv8" });
|
|
685
|
-
response.end(tlv.encode(6 /* TLVValues.STATE */, 2 /* PairingStates.M2 */, 7 /* TLVValues.ERROR_CODE */, 1 /* TLVErrorCode.UNKNOWN */));
|
|
686
|
-
return;
|
|
687
|
-
}
|
|
688
|
-
if (!objects[0 /* TLVValues.METHOD */] || !objects[6 /* TLVValues.STATE */]) {
|
|
689
|
-
response.writeHead(200 /* HAPPairingHTTPCode.OK */, { "Content-Type": "application/pairing+tlv8" });
|
|
690
|
-
response.end(tlv.encode(6 /* TLVValues.STATE */, 2 /* PairingStates.M2 */, 7 /* TLVValues.ERROR_CODE */, 1 /* TLVErrorCode.UNKNOWN */));
|
|
691
|
-
return;
|
|
692
|
-
}
|
|
693
|
-
const method = objects[0 /* TLVValues.METHOD */][0]; // value is single byte with request type
|
|
694
|
-
const state = objects[6 /* TLVValues.STATE */][0];
|
|
695
|
-
if (state !== 1 /* PairingStates.M1 */) {
|
|
696
|
-
return;
|
|
697
|
-
}
|
|
698
|
-
if (method === 3 /* PairMethods.ADD_PAIRING */) {
|
|
699
|
-
if (!objects[1 /* TLVValues.IDENTIFIER */] || !objects[3 /* TLVValues.PUBLIC_KEY */] || !objects[11 /* TLVValues.PERMISSIONS */]) {
|
|
700
|
-
response.writeHead(200 /* HAPPairingHTTPCode.OK */, { "Content-Type": "application/pairing+tlv8" });
|
|
701
|
-
response.end(tlv.encode(6 /* TLVValues.STATE */, 2 /* PairingStates.M2 */, 7 /* TLVValues.ERROR_CODE */, 1 /* TLVErrorCode.UNKNOWN */));
|
|
702
|
-
return;
|
|
703
|
-
}
|
|
704
|
-
const identifier = objects[1 /* TLVValues.IDENTIFIER */].toString();
|
|
705
|
-
const publicKey = objects[3 /* TLVValues.PUBLIC_KEY */];
|
|
706
|
-
const permissions = objects[11 /* TLVValues.PERMISSIONS */][0];
|
|
707
|
-
this.emit("add-pairing" /* HAPServerEventTypes.ADD_PAIRING */, connection, identifier, publicKey, permissions, (0, once_1.once)((error) => {
|
|
708
|
-
if (error > 0) {
|
|
709
|
-
debug("[%s] Pairings: failed ADD_PAIRING with code %d", this.accessoryInfo.username, error);
|
|
710
|
-
response.writeHead(200 /* HAPPairingHTTPCode.OK */, { "Content-Type": "application/pairing+tlv8" });
|
|
711
|
-
response.end(tlv.encode(6 /* TLVValues.STATE */, 2 /* PairingStates.M2 */, 7 /* TLVValues.ERROR_CODE */, error));
|
|
712
|
-
return;
|
|
713
|
-
}
|
|
714
|
-
response.writeHead(200 /* HAPPairingHTTPCode.OK */, { "Content-Type": "application/pairing+tlv8" });
|
|
715
|
-
response.end(tlv.encode(6 /* TLVValues.STATE */, 2 /* PairingStates.M2 */));
|
|
716
|
-
debug("[%s] Pairings: successfully executed ADD_PAIRING", this.accessoryInfo.username);
|
|
717
|
-
}));
|
|
718
|
-
}
|
|
719
|
-
else if (method === 4 /* PairMethods.REMOVE_PAIRING */) {
|
|
720
|
-
if (!objects[1 /* TLVValues.IDENTIFIER */]) {
|
|
721
|
-
response.writeHead(200 /* HAPPairingHTTPCode.OK */, { "Content-Type": "application/pairing+tlv8" });
|
|
722
|
-
response.end(tlv.encode(6 /* TLVValues.STATE */, 2 /* PairingStates.M2 */, 7 /* TLVValues.ERROR_CODE */, 1 /* TLVErrorCode.UNKNOWN */));
|
|
723
|
-
return;
|
|
724
|
-
}
|
|
725
|
-
const identifier = objects[1 /* TLVValues.IDENTIFIER */].toString();
|
|
726
|
-
this.emit("remove-pairing" /* HAPServerEventTypes.REMOVE_PAIRING */, connection, identifier, (0, once_1.once)((error) => {
|
|
727
|
-
if (error > 0) {
|
|
728
|
-
debug("[%s] Pairings: failed REMOVE_PAIRING with code %d", this.accessoryInfo.username, error);
|
|
729
|
-
response.writeHead(200 /* HAPPairingHTTPCode.OK */, { "Content-Type": "application/pairing+tlv8" });
|
|
730
|
-
response.end(tlv.encode(6 /* TLVValues.STATE */, 2 /* PairingStates.M2 */, 7 /* TLVValues.ERROR_CODE */, error));
|
|
731
|
-
return;
|
|
732
|
-
}
|
|
733
|
-
response.writeHead(200 /* HAPPairingHTTPCode.OK */, { "Content-Type": "application/pairing+tlv8" });
|
|
734
|
-
response.end(tlv.encode(6 /* TLVValues.STATE */, 2 /* PairingStates.M2 */));
|
|
735
|
-
debug("[%s] Pairings: successfully executed REMOVE_PAIRING", this.accessoryInfo.username);
|
|
736
|
-
}));
|
|
737
|
-
}
|
|
738
|
-
else if (method === 5 /* PairMethods.LIST_PAIRINGS */) {
|
|
739
|
-
this.emit("list-pairings" /* HAPServerEventTypes.LIST_PAIRINGS */, connection, (0, once_1.once)((error, data) => {
|
|
740
|
-
if (error > 0) {
|
|
741
|
-
debug("[%s] Pairings: failed LIST_PAIRINGS with code %d", this.accessoryInfo.username, error);
|
|
742
|
-
response.writeHead(200 /* HAPPairingHTTPCode.OK */, { "Content-Type": "application/pairing+tlv8" });
|
|
743
|
-
response.end(tlv.encode(6 /* TLVValues.STATE */, 2 /* PairingStates.M2 */, 7 /* TLVValues.ERROR_CODE */, error));
|
|
744
|
-
return;
|
|
745
|
-
}
|
|
746
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
747
|
-
const tlvList = [];
|
|
748
|
-
data.forEach((value, index) => {
|
|
749
|
-
if (index > 0) {
|
|
750
|
-
tlvList.push(255 /* TLVValues.SEPARATOR */, Buffer.alloc(0));
|
|
751
|
-
}
|
|
752
|
-
tlvList.push(1 /* TLVValues.IDENTIFIER */, value.username, 3 /* TLVValues.PUBLIC_KEY */, value.publicKey, 11 /* TLVValues.PERMISSIONS */, value.permission);
|
|
753
|
-
});
|
|
754
|
-
const list = tlv.encode(6 /* TLVValues.STATE */, 2 /* PairingStates.M2 */, ...tlvList);
|
|
755
|
-
response.writeHead(200 /* HAPPairingHTTPCode.OK */, { "Content-Type": "application/pairing+tlv8" /* HAPMimeTypes.PAIRING_TLV8 */ });
|
|
756
|
-
response.end(list);
|
|
757
|
-
debug("[%s] Pairings: successfully executed LIST_PAIRINGS", this.accessoryInfo.username);
|
|
758
|
-
}));
|
|
759
|
-
}
|
|
760
|
-
}
|
|
761
|
-
handleAccessories(connection, url, request, data, response) {
|
|
762
|
-
if (!this.allowInsecureRequest && !connection.isAuthenticated()) {
|
|
763
|
-
response.writeHead(470 /* HAPPairingHTTPCode.CONNECTION_AUTHORIZATION_REQUIRED */, { "Content-Type": "application/hap+json" /* HAPMimeTypes.HAP_JSON */ });
|
|
764
|
-
response.end(JSON.stringify({ status: -70401 /* HAPStatus.INSUFFICIENT_PRIVILEGES */ }));
|
|
765
|
-
return;
|
|
766
|
-
}
|
|
767
|
-
// call out to listeners to retrieve the latest accessories JSON
|
|
768
|
-
this.emit("accessories" /* HAPServerEventTypes.ACCESSORIES */, connection, (0, once_1.once)((error, result) => {
|
|
769
|
-
if (error) {
|
|
770
|
-
response.writeHead(error.httpCode, { "Content-Type": "application/hap+json" /* HAPMimeTypes.HAP_JSON */ });
|
|
771
|
-
response.end(JSON.stringify({ status: error.status }));
|
|
772
|
-
}
|
|
773
|
-
else {
|
|
774
|
-
response.writeHead(200 /* HAPHTTPCode.OK */, { "Content-Type": "application/hap+json" /* HAPMimeTypes.HAP_JSON */ });
|
|
775
|
-
response.end(JSON.stringify(result));
|
|
776
|
-
}
|
|
777
|
-
}));
|
|
778
|
-
}
|
|
779
|
-
handleCharacteristics(connection, url, request, data, response) {
|
|
780
|
-
if (!this.allowInsecureRequest && !connection.isAuthenticated()) {
|
|
781
|
-
response.writeHead(470 /* HAPPairingHTTPCode.CONNECTION_AUTHORIZATION_REQUIRED */, { "Content-Type": "application/hap+json" /* HAPMimeTypes.HAP_JSON */ });
|
|
782
|
-
response.end(JSON.stringify({ status: -70401 /* HAPStatus.INSUFFICIENT_PRIVILEGES */ }));
|
|
783
|
-
return;
|
|
784
|
-
}
|
|
785
|
-
if (request.method === "GET") {
|
|
786
|
-
const searchParams = url.searchParams;
|
|
787
|
-
const idParam = searchParams.get("id");
|
|
788
|
-
if (!idParam) {
|
|
789
|
-
response.writeHead(400 /* HAPHTTPCode.BAD_REQUEST */, { "Content-Type": "application/hap+json" /* HAPMimeTypes.HAP_JSON */ });
|
|
790
|
-
response.end(JSON.stringify({ status: -70410 /* HAPStatus.INVALID_VALUE_IN_REQUEST */ }));
|
|
791
|
-
return;
|
|
792
|
-
}
|
|
793
|
-
const ids = [];
|
|
794
|
-
for (const entry of idParam.split(",")) { // ["1.9","2.14"]
|
|
795
|
-
const split = entry.split("."); // ["1","9"]
|
|
796
|
-
if (split.length !== 2 || !/^\d+$/.test(split[0]) || !/^\d+$/.test(split[1])) {
|
|
797
|
-
response.writeHead(400 /* HAPHTTPCode.BAD_REQUEST */, { "Content-Type": "application/hap+json" /* HAPMimeTypes.HAP_JSON */ });
|
|
798
|
-
response.end(JSON.stringify({ status: -70410 /* HAPStatus.INVALID_VALUE_IN_REQUEST */ }));
|
|
799
|
-
return;
|
|
800
|
-
}
|
|
801
|
-
ids.push({
|
|
802
|
-
aid: parseInt(split[0], 10), // accessory id
|
|
803
|
-
iid: parseInt(split[1], 10), // (characteristic) instance id
|
|
804
|
-
});
|
|
805
|
-
}
|
|
806
|
-
const readRequest = {
|
|
807
|
-
ids: ids,
|
|
808
|
-
includeMeta: (0, internal_types_1.consideredTrue)(searchParams.get("meta")),
|
|
809
|
-
includePerms: (0, internal_types_1.consideredTrue)(searchParams.get("perms")),
|
|
810
|
-
includeType: (0, internal_types_1.consideredTrue)(searchParams.get("type")),
|
|
811
|
-
includeEvent: (0, internal_types_1.consideredTrue)(searchParams.get("ev")),
|
|
812
|
-
};
|
|
813
|
-
this.emit("get-characteristics" /* HAPServerEventTypes.GET_CHARACTERISTICS */, connection, readRequest, (0, once_1.once)((error, readResponse) => {
|
|
814
|
-
if (error) {
|
|
815
|
-
response.writeHead(error.httpCode, { "Content-Type": "application/hap+json" /* HAPMimeTypes.HAP_JSON */ });
|
|
816
|
-
response.end(JSON.stringify({ status: error.status }));
|
|
817
|
-
return;
|
|
818
|
-
}
|
|
819
|
-
const characteristics = readResponse.characteristics;
|
|
820
|
-
let errorOccurred = false; // determine if we send a 207 Multi-Status
|
|
821
|
-
for (const data of characteristics) {
|
|
822
|
-
if (data.status) {
|
|
823
|
-
errorOccurred = true;
|
|
824
|
-
break;
|
|
825
|
-
}
|
|
826
|
-
}
|
|
827
|
-
if (errorOccurred) { // on a 207 Multi-Status EVERY characteristic MUST include a status property
|
|
828
|
-
for (const data of characteristics) {
|
|
829
|
-
if (!data.status) { // a status is undefined if the request was successful
|
|
830
|
-
data.status = 0 /* HAPStatus.SUCCESS */; // a value of zero indicates success
|
|
831
|
-
}
|
|
832
|
-
}
|
|
833
|
-
}
|
|
834
|
-
console.info("[HK4K-HAP-DIAG] get-characteristics-result", JSON.stringify({ remote: connection.remoteAddress, characteristics }));
|
|
835
|
-
// 207 "multi-status" is returned when an error occurs reading a characteristic. otherwise 200 is returned
|
|
836
|
-
response.writeHead(errorOccurred ? 207 /* HAPHTTPCode.MULTI_STATUS */ : 200 /* HAPHTTPCode.OK */, { "Content-Type": "application/hap+json" /* HAPMimeTypes.HAP_JSON */ });
|
|
837
|
-
response.end(JSON.stringify({ characteristics: characteristics }));
|
|
838
|
-
}));
|
|
839
|
-
}
|
|
840
|
-
else if (request.method === "PUT") {
|
|
841
|
-
if (!connection.isAuthenticated()) {
|
|
842
|
-
const authorization = request.headers?.authorization;
|
|
843
|
-
const authorizationBuffer = authorization ? Buffer.from(authorization) : undefined;
|
|
844
|
-
const pincodeBuffer = Buffer.from(this.accessoryInfo.pincode);
|
|
845
|
-
if (!authorizationBuffer
|
|
846
|
-
|| authorizationBuffer.length !== pincodeBuffer.length
|
|
847
|
-
|| !crypto_1.default.timingSafeEqual(authorizationBuffer, pincodeBuffer)) {
|
|
848
|
-
response.writeHead(470 /* HAPPairingHTTPCode.CONNECTION_AUTHORIZATION_REQUIRED */, { "Content-Type": "application/hap+json" /* HAPMimeTypes.HAP_JSON */ });
|
|
849
|
-
response.end(JSON.stringify({ status: -70401 /* HAPStatus.INSUFFICIENT_PRIVILEGES */ }));
|
|
850
|
-
return;
|
|
851
|
-
}
|
|
852
|
-
}
|
|
853
|
-
if (data.length === 0) {
|
|
854
|
-
response.writeHead(400 /* HAPHTTPCode.BAD_REQUEST */, { "Content-Type": "application/hap+json" /* HAPMimeTypes.HAP_JSON */ });
|
|
855
|
-
response.end(JSON.stringify({ status: -70410 /* HAPStatus.INVALID_VALUE_IN_REQUEST */ }));
|
|
856
|
-
return;
|
|
857
|
-
}
|
|
858
|
-
const writeRequest = JSON.parse(data.toString("utf8"));
|
|
859
|
-
this.emit("set-characteristics" /* HAPServerEventTypes.SET_CHARACTERISTICS */, connection, writeRequest, (0, once_1.once)((error, writeResponse) => {
|
|
860
|
-
if (error) {
|
|
861
|
-
response.writeHead(error.httpCode, { "Content-Type": "application/hap+json" /* HAPMimeTypes.HAP_JSON */ });
|
|
862
|
-
response.end(JSON.stringify({ status: error.status }));
|
|
863
|
-
return;
|
|
864
|
-
}
|
|
865
|
-
const characteristics = writeResponse.characteristics;
|
|
866
|
-
let multiStatus = false;
|
|
867
|
-
for (const data of characteristics) {
|
|
868
|
-
if (data.status || data.value !== undefined) {
|
|
869
|
-
// also send multiStatus on write response requests
|
|
870
|
-
multiStatus = true;
|
|
871
|
-
break;
|
|
872
|
-
}
|
|
873
|
-
}
|
|
874
|
-
if (multiStatus) {
|
|
875
|
-
// 207 is "multi-status" since HomeKit may be setting multiple things and any one can fail independently
|
|
876
|
-
response.writeHead(207 /* HAPHTTPCode.MULTI_STATUS */, { "Content-Type": "application/hap+json" /* HAPMimeTypes.HAP_JSON */ });
|
|
877
|
-
response.end(JSON.stringify({ characteristics: characteristics }));
|
|
878
|
-
}
|
|
879
|
-
else {
|
|
880
|
-
// if everything went fine send 204 no content response
|
|
881
|
-
response.writeHead(204 /* HAPHTTPCode.NO_CONTENT */);
|
|
882
|
-
response.end();
|
|
883
|
-
}
|
|
884
|
-
}));
|
|
885
|
-
}
|
|
886
|
-
else {
|
|
887
|
-
response.writeHead(400 /* HAPHTTPCode.BAD_REQUEST */, { "Content-Type": "application/hap+json" /* HAPMimeTypes.HAP_JSON */ }); // method not allowed
|
|
888
|
-
response.end(JSON.stringify({ status: -70410 /* HAPStatus.INVALID_VALUE_IN_REQUEST */ }));
|
|
889
|
-
}
|
|
890
|
-
}
|
|
891
|
-
handlePrepareWrite(connection, url, request, data, response) {
|
|
892
|
-
if (!this.allowInsecureRequest && !connection.isAuthenticated()) {
|
|
893
|
-
response.writeHead(470 /* HAPPairingHTTPCode.CONNECTION_AUTHORIZATION_REQUIRED */, { "Content-Type": "application/hap+json" /* HAPMimeTypes.HAP_JSON */ });
|
|
894
|
-
response.end(JSON.stringify({ status: -70401 /* HAPStatus.INSUFFICIENT_PRIVILEGES */ }));
|
|
895
|
-
return;
|
|
896
|
-
}
|
|
897
|
-
if (request.method === "PUT") {
|
|
898
|
-
if (data.length === 0) {
|
|
899
|
-
response.writeHead(400 /* HAPHTTPCode.BAD_REQUEST */, { "Content-Type": "application/hap+json" /* HAPMimeTypes.HAP_JSON */ });
|
|
900
|
-
response.end(JSON.stringify({ status: -70410 /* HAPStatus.INVALID_VALUE_IN_REQUEST */ }));
|
|
901
|
-
return;
|
|
902
|
-
}
|
|
903
|
-
const prepareRequest = JSON.parse(data.toString());
|
|
904
|
-
if (prepareRequest.pid && prepareRequest.ttl) {
|
|
905
|
-
debug("[%s] Received prepare write request with pid %d and ttl %d", this.accessoryInfo.username, prepareRequest.pid, prepareRequest.ttl);
|
|
906
|
-
if (connection.timedWriteTimeout) { // clear any currently existing timeouts
|
|
907
|
-
clearTimeout(connection.timedWriteTimeout);
|
|
908
|
-
}
|
|
909
|
-
connection.timedWritePid = prepareRequest.pid;
|
|
910
|
-
connection.timedWriteTimeout = setTimeout(() => {
|
|
911
|
-
debug("[%s] Timed write request timed out for pid %d", this.accessoryInfo.username, prepareRequest.pid);
|
|
912
|
-
connection.timedWritePid = undefined;
|
|
913
|
-
connection.timedWriteTimeout = undefined;
|
|
914
|
-
}, prepareRequest.ttl);
|
|
915
|
-
response.writeHead(200 /* HAPHTTPCode.OK */, { "Content-Type": "application/hap+json" /* HAPMimeTypes.HAP_JSON */ });
|
|
916
|
-
response.end(JSON.stringify({ status: 0 /* HAPStatus.SUCCESS */ }));
|
|
917
|
-
return;
|
|
918
|
-
}
|
|
919
|
-
else {
|
|
920
|
-
response.writeHead(400 /* HAPHTTPCode.BAD_REQUEST */, { "Content-Type": "application/hap+json" /* HAPMimeTypes.HAP_JSON */ });
|
|
921
|
-
response.end(JSON.stringify({ status: -70410 /* HAPStatus.INVALID_VALUE_IN_REQUEST */ }));
|
|
922
|
-
}
|
|
923
|
-
}
|
|
924
|
-
else {
|
|
925
|
-
response.writeHead(400 /* HAPHTTPCode.BAD_REQUEST */, { "Content-Type": "application/hap+json" /* HAPMimeTypes.HAP_JSON */ });
|
|
926
|
-
response.end(JSON.stringify({ status: -70410 /* HAPStatus.INVALID_VALUE_IN_REQUEST */ }));
|
|
927
|
-
}
|
|
928
|
-
}
|
|
929
|
-
handleResource(connection, url, request, data, response) {
|
|
930
|
-
if (!connection.isAuthenticated()) {
|
|
931
|
-
const authorization = request.headers?.authorization;
|
|
932
|
-
const authorizationBuffer = authorization ? Buffer.from(authorization) : undefined;
|
|
933
|
-
const pincodeBuffer = Buffer.from(this.accessoryInfo.pincode);
|
|
934
|
-
if (!(this.allowInsecureRequest && authorizationBuffer
|
|
935
|
-
&& authorizationBuffer.length === pincodeBuffer.length
|
|
936
|
-
&& crypto_1.default.timingSafeEqual(authorizationBuffer, pincodeBuffer))) {
|
|
937
|
-
response.writeHead(470 /* HAPPairingHTTPCode.CONNECTION_AUTHORIZATION_REQUIRED */, { "Content-Type": "application/hap+json" /* HAPMimeTypes.HAP_JSON */ });
|
|
938
|
-
response.end(JSON.stringify({ status: -70401 /* HAPStatus.INSUFFICIENT_PRIVILEGES */ }));
|
|
939
|
-
return;
|
|
940
|
-
}
|
|
941
|
-
}
|
|
942
|
-
if (request.method === "POST") {
|
|
943
|
-
if (data.length === 0) {
|
|
944
|
-
response.writeHead(400 /* HAPHTTPCode.BAD_REQUEST */, { "Content-Type": "application/hap+json" /* HAPMimeTypes.HAP_JSON */ });
|
|
945
|
-
response.end(JSON.stringify({ status: -70410 /* HAPStatus.INVALID_VALUE_IN_REQUEST */ }));
|
|
946
|
-
return;
|
|
947
|
-
}
|
|
948
|
-
const resourceRequest = JSON.parse(data.toString());
|
|
949
|
-
// call out to listeners to retrieve the resource, snapshot only right now
|
|
950
|
-
this.emit("request-resource" /* HAPServerEventTypes.REQUEST_RESOURCE */, resourceRequest, (0, once_1.once)((error, resource) => {
|
|
951
|
-
if (error) {
|
|
952
|
-
response.writeHead(error.httpCode, { "Content-Type": "application/hap+json" /* HAPMimeTypes.HAP_JSON */ });
|
|
953
|
-
response.end(JSON.stringify({ status: error.status }));
|
|
954
|
-
}
|
|
955
|
-
else {
|
|
956
|
-
response.writeHead(200 /* HAPHTTPCode.OK */, { "Content-Type": "image/jpeg" /* HAPMimeTypes.IMAGE_JPEG */ });
|
|
957
|
-
response.end(resource);
|
|
958
|
-
}
|
|
959
|
-
}));
|
|
960
|
-
}
|
|
961
|
-
else {
|
|
962
|
-
response.writeHead(400 /* HAPHTTPCode.BAD_REQUEST */, { "Content-Type": "application/hap+json" /* HAPMimeTypes.HAP_JSON */ }); // method not allowed
|
|
963
|
-
response.end(JSON.stringify({ status: -70410 /* HAPStatus.INVALID_VALUE_IN_REQUEST */ }));
|
|
964
|
-
}
|
|
965
|
-
}
|
|
966
|
-
}
|
|
967
|
-
exports.HAPServer = HAPServer;
|
|
968
|
-
//# sourceMappingURL=HAPServer.js.map
|