android系统中的指纹识别调用时候需要提供一个hw_auth_token_t的结构,hw_auth_token_t就是authToken数据,这个结构填充如果不对,则会导致后面的接口调用不正常。
authToken需要硬件来产生,其实关键的是hmac的计算,这个计算目前没有公开源码,大概原理是计算一个key,拿着key做hash。
在安卓系统中,调用gatekeeper的verify接口可以生成authToken数据。
下面通过例子代码演示如何调用(代码中的“hat”就是输出的authToken数据):
static bool generateHat(hw_auth_token_t& hat, int userid, uint64_t challenge, const tpassworddata* pswdata) {
if (!pswdata) {
return false;
}
memset(&hat,0,sizeof(hat));
bool result = false;
android::sp<IGatekeeper> bio = IGatekeeper::getService();
if (bio == nullptr) {
return false;
}
android::hardware::hidl_vec<uint8_t> newPwd;
newPwd.setToExternal((uint8_t*)(pswdata->pCurrentPasswordText), ::strlen(pswdata->pCurrentPasswordText));
android::hardware::hidl_vec<uint8_t> enrolledPasswordHandle;
enrolledPasswordHandle.setToExternal(const_cast<uint8_t*>(pswdata->pCurrentPasswordData), (uint32_t)pswdata->currentPasswordDataLen);
Return<void> hwRes = bio->verify(userid, challenge, enrolledPasswordHandle, newPwd,
[&hat](const GatekeeperResponse& rsp) {
if (rsp.code >= GatekeeperStatusCode::STATUS_OK) {
(int32_t)rsp.data.size());
if (rsp.data.size() == sizeof(hat)) {
memcpy(&hat, rsp.data.data(), rsp.data.size());
} else
(int32_t)rsp.data.size());
}
});
return hwRes.isOk();
}