设备具有wifi AP的功能, 手机可以通过wifi进行连接和控制
设备是具有web server(webservd)的功能,提供http(80)和https(443)服务
手机连接设备后使用http连接, 可以访问如下连接:(external/libweave/src/privet/privet_handler.cc@brillo-m8-dev):
- /privet/info (scope: kNone)
- /privet/v3/pairing/start (scope: kNone)
- /privet/v3/pairing/confirm (scope: kNone)
- /privet/v3/pairing/cancel (scope: kNone)
如果使用https连接,还可以访问如下连接:
- /privet/v3/auth (scope: kNone)
- /privet/v3/setup/start (scope: kOwner)
- /privet/v3/setup/status (scope: kOwner)
- /privet/v3/state (scope: kViewer)
- /privet/v3/commandDefs (scope: kViewer)
- /privet/v3/commands/execute (scope: kViewer)
- /privet/v3/commands/status (scope: kViewer)
- /privet/v3/commands/cancel (scope: kViewer)
- /privet/v3/commands/list (scope: kViewer)
- /privet/v3/commands/checkForUpdates (scope: kViewer)
- /privet/v3/traits (scope: kViewer)
- /privet/v3/components (scope: kViewer)
准备工作(下载,编译代码,运行模似器):
$ brilloemulator-x86 -m 256
forward设备的80和443端口(实际上只需要443端口):
$ adb forward tcp:8000 tcp:80 $ adb forward tcp:8001 tcp:443
查看设备的基本信息:
$ curl -H "Authorization: Privet anonymous" https://localhost:8001/privet/info
可以知道服务器使用的是自签名证书, 使用 -k 参数关闭证书验证
$ curl -H "Authorization: Privet anonymous" -k https://localhost:8001/privet/info
可以得到包含authentication, basicModelManifest, description, endpoints, gcd, id, modelManifestId, name, services, uptime, version, wifi
关于anonymous, 是一个特珠的scope (kNone), weave定义了四种类型的scope: kNone(0), kViewer(1), kUser(2), kOwer(3), 具备的权限也是逐渐增大(external/libweave/include/weave/settings.h)
paring start:
$ curl -H "Authorization: Privet anonymous" -H "Content-Type: application/json" -X POST --data '{ "pairing": "embeddedCode", "crypto": "p224_spake2" }' -k https://localhost:8001/privet/v3/pairing/start
可以得到sessionId和deviceCommitment (clientCommitment)
pairing confirm(传入由paring start得到的sessionId和deviceCommitment):
$ curl -H "Authorization: Privet anonymous" -H "Content-Type: application/json" -X POST --data '{ "sessionId": "0588E45C-C759-4F2A-8F15-0D34EA212D10", "clientCommitment": "m9wluyfSJP4AoX1JOH+bUMJJOEErF1i5yveHZbGPhnfef04JpvWMuL9Tckk8gHPVpm7D9t/kVw4=" }' -k https://localhost:8001/privet/v3/pairing/confirm
就可以得到certFingerprint和certSignature