服务器上的 Cordova 指纹认证
Cordova fingerprint authentication on server
我正在尝试在我的 (cordova) 应用程序中为 android 创建一个身份验证机制,允许我的用户使用密码和用户名登录,或者允许他们扫描手指以进行签名英寸
如何验证在客户端、服务器端注册的指纹?这甚至有可能使用 Cordova 吗?我尝试将手指扫描的结果传输到我的服务器:这看起来像:
FingerprintAuth.isAvailable(function(result) {
if (result.isAvailable) {
if(result.hasEnrolledFingerprints){
FingerprintAuth.show({
clientId: client_id,
clientSecret: client_secret
}, function (result) {
alert(JSON.stringify(result));
$http.post('http://192.168.149.33:3000/authorize', result).then(
function(response) {}
);
if (result.withFingerprint) {
$scope.$parent.loggedIn = true;
alert("Successfully authenticated using a fingerprint");
$location.path( "/home" );
} else if (result.withPassword) {
alert("Authenticated with backup password");
}
}, function(error) {
console.log(error); // "Fingerprint authentication not available"
});
} else {
alert("Fingerprint auth available, but no fingerprint registered on the device");
}
}
}, function(message) {
alert("Cannot detect fingerprint device : "+ message);
});
服务器端我收到以下数据(3 次单独扫描):
{ withFingerprint: 't8haYq36fmBPUEPbVjiWOaBLjMPBeUNP/BTOkoVtZ2ZiX20eBVzZAs3dn6PW/R4E\n' }
{ withFingerprint: 'rA9H+MIoQR3au9pqgLAi/EOCRA9b0Wx1AvzC/taGIUc8cCeDfzfiDZkxNy5U4joB\n' }
{ withFingerprint: 'MMyJm46O8MTxsa9aofKUS9fZW3OZVG7ojD+XspO71LWVy4TZh2FtvPtfjJFnj7Sy\n' }
模式似乎每次都不同,有没有办法可以 link 指纹到例如数据库中用户下保存的模式?
使用 cordova-plugin-fingerprint-aio 进行指纹认证。
有关更多信息,您可以参考 https://www.npmjs.com/package/cordova-plugin-fingerprint-aio。
您无法在服务器上验证指纹,指纹是使用 Live Scan/Biometric template
存储或验证的。通过将当前扫描模板与以前存储的模板进行比较来完成身份验证
首先,您无权访问这些存储的模板(OS providers/Phone 制造商不提供),如果我们假设您可以访问这些模板,那么一个高效的算法(Image based / Pattern based )需要将当前模板与以前存储的模板进行比较。您不能简单地通过字符串比较来验证它。
简答
这个API返回的字符串不是"fingerprint patterns"。所以你将无法验证你的想法......
长答案
让我们先看看您正在使用的 API 的 source code。
查看 this file 我们看到这些方法:
public static void onAuthenticated(boolean withFingerprint) {
JSONObject resultJson = new JSONObject();
String errorMessage = "";
boolean createdResultJson = false;
try {
if (withFingerprint) {
// If the user has authenticated with fingerprint, verify that using cryptography and
// then return the encrypted token
byte[] encrypted = tryEncrypt();
resultJson.put("withFingerprint", Base64.encodeToString(encrypted, 0 /* flags */));
} else {
// Authentication happened with backup password.
resultJson.put("withPassword", true);
// if failed to init cipher because of InvalidKeyException, create new key
if (!initCipher()) {
createKey();
}
}
createdResultJson = true;
// ...
/**
* Tries to encrypt some data with the generated key in {@link #createKey} which is
* only works if the user has just authenticated via fingerprint.
*/
private static byte[] tryEncrypt() throws BadPaddingException, IllegalBlockSizeException {
return mCipher.doFinal(mClientSecret.getBytes());
}
看看 "withFingerprint"
上放了什么。它是加密客户端机密的 Base64 编码。从技术上讲,这 是 您的身份验证。您将使用此令牌对请求进行身份验证,而您的服务器将解密并验证客户端机密。
总结
指纹识别增加了一层安全性,但它不是唯一的安全手段。需要事先与设备和服务器建立关系。
我发现这张图有助于理解 android 指纹认证的意图(参考:http://android-developers.blogspot.com/2015/10/new-in-android-samples-authenticating.html)
我正在尝试在我的 (cordova) 应用程序中为 android 创建一个身份验证机制,允许我的用户使用密码和用户名登录,或者允许他们扫描手指以进行签名英寸
如何验证在客户端、服务器端注册的指纹?这甚至有可能使用 Cordova 吗?我尝试将手指扫描的结果传输到我的服务器:这看起来像:
FingerprintAuth.isAvailable(function(result) {
if (result.isAvailable) {
if(result.hasEnrolledFingerprints){
FingerprintAuth.show({
clientId: client_id,
clientSecret: client_secret
}, function (result) {
alert(JSON.stringify(result));
$http.post('http://192.168.149.33:3000/authorize', result).then(
function(response) {}
);
if (result.withFingerprint) {
$scope.$parent.loggedIn = true;
alert("Successfully authenticated using a fingerprint");
$location.path( "/home" );
} else if (result.withPassword) {
alert("Authenticated with backup password");
}
}, function(error) {
console.log(error); // "Fingerprint authentication not available"
});
} else {
alert("Fingerprint auth available, but no fingerprint registered on the device");
}
}
}, function(message) {
alert("Cannot detect fingerprint device : "+ message);
});
服务器端我收到以下数据(3 次单独扫描):
{ withFingerprint: 't8haYq36fmBPUEPbVjiWOaBLjMPBeUNP/BTOkoVtZ2ZiX20eBVzZAs3dn6PW/R4E\n' }
{ withFingerprint: 'rA9H+MIoQR3au9pqgLAi/EOCRA9b0Wx1AvzC/taGIUc8cCeDfzfiDZkxNy5U4joB\n' }
{ withFingerprint: 'MMyJm46O8MTxsa9aofKUS9fZW3OZVG7ojD+XspO71LWVy4TZh2FtvPtfjJFnj7Sy\n' }
模式似乎每次都不同,有没有办法可以 link 指纹到例如数据库中用户下保存的模式?
使用 cordova-plugin-fingerprint-aio 进行指纹认证。
有关更多信息,您可以参考 https://www.npmjs.com/package/cordova-plugin-fingerprint-aio。
您无法在服务器上验证指纹,指纹是使用 Live Scan/Biometric template
存储或验证的。通过将当前扫描模板与以前存储的模板进行比较来完成身份验证
首先,您无权访问这些存储的模板(OS providers/Phone 制造商不提供),如果我们假设您可以访问这些模板,那么一个高效的算法(Image based / Pattern based )需要将当前模板与以前存储的模板进行比较。您不能简单地通过字符串比较来验证它。
简答
这个API返回的字符串不是"fingerprint patterns"。所以你将无法验证你的想法......
长答案
让我们先看看您正在使用的 API 的 source code。
查看 this file 我们看到这些方法:
public static void onAuthenticated(boolean withFingerprint) {
JSONObject resultJson = new JSONObject();
String errorMessage = "";
boolean createdResultJson = false;
try {
if (withFingerprint) {
// If the user has authenticated with fingerprint, verify that using cryptography and
// then return the encrypted token
byte[] encrypted = tryEncrypt();
resultJson.put("withFingerprint", Base64.encodeToString(encrypted, 0 /* flags */));
} else {
// Authentication happened with backup password.
resultJson.put("withPassword", true);
// if failed to init cipher because of InvalidKeyException, create new key
if (!initCipher()) {
createKey();
}
}
createdResultJson = true;
// ...
/**
* Tries to encrypt some data with the generated key in {@link #createKey} which is
* only works if the user has just authenticated via fingerprint.
*/
private static byte[] tryEncrypt() throws BadPaddingException, IllegalBlockSizeException {
return mCipher.doFinal(mClientSecret.getBytes());
}
看看 "withFingerprint"
上放了什么。它是加密客户端机密的 Base64 编码。从技术上讲,这 是 您的身份验证。您将使用此令牌对请求进行身份验证,而您的服务器将解密并验证客户端机密。
总结
指纹识别增加了一层安全性,但它不是唯一的安全手段。需要事先与设备和服务器建立关系。
我发现这张图有助于理解 android 指纹认证的意图(参考:http://android-developers.blogspot.com/2015/10/new-in-android-samples-authenticating.html)