首頁 > 收藏

透過人臉驗證提高應用安全性

作者:由 skysevenqi 發表于 收藏日期:2022-09-03

win7怎麼設定遊戲高效能

使用和實施人臉驗證解決方案的演練。

透過人臉驗證提高應用安全性

身份驗證是移動應用安全的主要貢獻者之一。考慮到每個人的人臉資料都是獨一無二的,它已被用於開發身份驗證的一個主要分支:人臉識別。

人臉識別已廣泛應用於我們日常使用的服務中,例如移動裝置解鎖、刷臉支付、門禁等。毫無疑問,人臉識別為上述服務提供了簡化的驗證過程。但是,這並不是說這種安全性是完全安全的。人臉識別只能檢測人臉,無法判斷人臉是否屬於真人,使得人臉識別容易受到包括列印攻擊、重放攻擊和掩碼攻擊在內的演示攻擊(PA)的攻擊。

這凸顯了對更強大的安全功能的需求,為人臉驗證鋪平了道路。雖然人臉識別和人臉驗證聽起來很相似,但實際上它們是完全不同的。例如,使用者不知道正在執行人臉識別,而他們知道人臉驗證。人臉識別不需要使用者協作,而人臉驗證通常由使用者發起。人臉識別不能保證使用者隱私,而人臉驗證可以。這些根本差異展示了面部驗證的增強安全功能。

說實話,我最近才知道這些差異,這引起了我對人臉驗證的興趣。我想知道這項技術是如何工作的,並將這個驗證功能整合到我自己的應用程式中。在嘗試了幾種解決方案後,我選擇了 HMS Core ML Kit 的互動式生物特徵驗證功能。

互動式生物特徵驗證簡介

此功能以互動方式執行驗證。在驗證過程中,它會提示使用者執行以下三個動作之一:眨眼、張嘴、左轉或右轉頭、盯著裝置攝像頭和點頭。該能力利用面部關鍵點技術和麵部跟蹤技術,計算連續幀的固定距離與變化距離的比率,並將一幀與下一幀進行比較。這有助於互動式生物特徵驗證檢查檢測到的人臉是否為真人,幫助應用抵禦 PA。整個驗證過程包含以下幾個部分: 能力檢測攝像頭流中的人臉,判斷其是否屬於真人,並將驗證結果返回給應用程式。如果驗證匹配,

不僅如此,我還注意到驗證功能在使用時提供了很多幫助,因為它會在光線不足、人臉影象模糊、人臉被口罩或太陽鏡遮擋時提示使用者進行調整。 、人臉距離裝置攝像頭太近或太遠等問題。透過這種方式,互動式生物特徵驗證有助於提高使用者互動性。

該能力提供兩種呼叫模式,即預設檢視模式和自定義檢視模式。它們之間的根本區別在於自定義檢視模式需要自定義驗證 UI。

我試過戴上口罩,看看這個能力是否能分辨出是不是我,這就是我得到的結果。

防守成功!

現在讓我們看看如何使用該能力開發驗證功能。

開發流程

準備工作

在開發應用中的驗證功能之前,您需要先做一些事情。確保您的專案中已經設定了HMS Core SDK的Maven倉庫地址,並且已經集成了互動式生物識別SDK。可以使用以下程式碼透過完整的 SDK 模式完成整合:

dependencies{ // Import the package of interactive biometric verification。 implementation ‘com。huawei。hms:ml-computer-vision-interactive-livenessdetection: 3。2。0。122’}

功能開發

使用預設檢視模式或自定義檢視模式來開發驗證功能。

預設檢視模式

1。 建立結果回撥,獲取互動式生物特徵驗證結果。

private MLInteractiveLivenessCapture。Callback callback = new MLInteractiveLivenessCapture。Callback() { @Override public void onSuccess(MLInteractiveLivenessCaptureResult result) { // Callback when the verification is successful。 The returned result indicates whether the detected face is of a real person。 swich(result。getStateCode()) { case InteractiveLivenessStateCode。ALL_ACTION_CORRECT: // Operation after verification is passed。 case InteractiveLivenessStateCode。IN_PROGRESS: // Operation when verification is in process。 … } @Override public void onFailure(int errorCode) { // Callback when verification failed。 Possible reasons include that the camera is abnormal (CAMERA_ERROR)。 Add the processing logic after the failure。 }};

2。 建立MLInteractiveLivenessConfig例項並開始驗證。

MLInteractiveLivenessConfig interactiveLivenessConfig = new MLInteractiveLivenessConfig。Builder()。build(); MLInteractiveLivenessCaptureConfig captureConfig = new MLInteractiveLivenessCaptureConfig。Builder() 。setOptions(MLInteractiveLivenessCaptureConfig。DETECT_MASK) 。setActionConfig(interactiveLivenessConfig) 。setDetectionTimeOut(TIME_OUT_THRESHOLD) 。build();MLInteractiveLivenessCapture capture = MLInteractiveLivenessCapture。getInstance();capture。startDetect(activity, callback);

自定義檢視模式

1。 建立一個

MLInteractiveLivenessDetectView

物件並將其載入到活動佈局中。

/*** i。 Bind the camera preview screen to the remote view and configure the liveness detection area。* In the camera preview stream, interactive biometric verification checks whether a face is in the middle of the face frame。 To ensure a higher verification pass rate, it is recommended that the face frame be in the middle of the screen, and the verification area be slightly larger than the area covered by the face frame。* ii。 Set whether to detect the mask。* iii。 Set the result callback。* iv。 Load MLInteractiveLivenessDetectView to the activity。*/

@Override protected void onCreate(Bundle savedInstanceState) { super。onCreate(savedInstanceState); setContentView(R。layout。activity_liveness_custom_detection); mPreviewContainer = findViewById(R。id。surface_layout); MLInteractiveLivenessConfig interactiveLivenessConfig = new MLInteractiveLivenessConfig。Builder()。build();mlInteractiveLivenessDetectView = new MLInteractiveLivenessDetectView。Builder() 。setContext(this) // Set whether detect the mask。 。setOptions(MLInteractiveLivenessCaptureConfig。DETECT_MASK) // Set the type of liveness detection。 0 indicates static biometric verification, and 1 indicates interactive biometric verification。 。setType(1) // Set the position for the camera stream。 。setFrameRect(new Rect(0, 0, 1080, 1440)) // Set the configurations for interactive biometric verification。 。setActionConfig(interactiveLivenessConfig) // Set the face frame position。 This position is relative to the camera preview view。 The coordinates of the upper left vertex and lower right vertex are determined according to an image with the dimensions of 640 x 480 px。 The face frame dimensions should comply with the ratio of a real face。 This frame checks whether a face is too close to or far from the camera, and whether a face deviates from the camera view。 。setFaceRect(new Rect(84, 122, 396, 518)) // Set the verification timeout interval。 The recommended value is about 10,000 milliseconds。 。setDetectionTimeOut(10000) // Set the result callback。 。setDetectCallback(new OnMLInteractiveLivenessDetectCallback() { @Override public void onCompleted(MLInteractiveLivenessCaptureResult result) { // Callback when verification is complete。 swich(result。getStateCode()) { case InteractiveLivenessStateCode。ALL_ACTION_CORRECT: // Operation when verification is passed。 case InteractiveLivenessStateCode。IN_PROGRESS: // Operation when verification is in process。 … } } @Override public void on​Error(int error) { // Callback when an error occurs during verification。 } })。build(); mPreviewContainer。addView(mlInteractiveLivenessDetectView); mlInteractiveLivenessDetectView。onCreate(savedInstanceState);}

2。 為

MLInteractiveLivenessDetectView

的生命週期設定監聽器。

@Overrideprotected void onDestroy() { super。onDestroy(); MLInteractiveLivenessDetectView。onDestroy();}

@Overrideprotected void onPause() { super。onPause(); MLInteractiveLivenessDetectView。onPause();}@Overrideprotected void onResume() { super。onResume(); MLInteractiveLivenessDetectView。onResume();}

@Overrideprotected void onStart() { super。onStart(); MLInteractiveLivenessDetectView。onStart();}

@Overrideprotected void onStop() { super。onStop(); MLInteractiveLivenessDetectView。onStop();}

就這樣,您已經成功地為您的應用開發了密封的人臉驗證功能。

在哪裡使用

我注意到互動式生物特徵驗證能力實際上是 ML Kit 中活體檢測的子服務之一,另一個稱為靜態生物特徵驗證。自己試過之後,發現互動式生物特徵驗證更適合人機場景。

以銀行為例。透過整合該功能,銀行應用程式將允許使用者在家中開戶,只要他們根據應用程式提示進行面部驗證。整個過程是安全的,使使用者免於親自去銀行的麻煩。

購物也是能力可以發揮關鍵作用的領域。使用者在下單前必須先驗證身份,保障賬戶資產安全。

這些只是最適合使用此功能的一些情況。你呢?您認為此功能適用於哪些情況?我期待在評論部分看到你的想法。

結論

目前,僅靠人臉識別雖然方便有效,但還不足以實現身份驗證,因為它無法驗證人臉的真實性。

人臉驗證解決方案有助於克服這個問題,而互動式生物特徵驗證能力對於實現它至關重要。此功能可以確保自拍中的人是真實的,因為它透過提示使用者執行某些操作來驗證真實性。成功完成提示將確認此人確實是真實的