-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add support for Bio metadata and verify extensions
- Loading branch information
Showing
4 changed files
with
300 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Copyright (C) 2024 Yubico. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.yubico.yubikit.piv; | ||
|
||
public class BioMetadata { | ||
final private boolean configured; | ||
final private int attemptsRemaining; | ||
final private boolean temporaryPin; | ||
|
||
public BioMetadata(boolean configured, int attemptsRemaining, boolean temporaryPin) { | ||
this.configured = configured; | ||
this.attemptsRemaining = attemptsRemaining; | ||
this.temporaryPin = temporaryPin; | ||
} | ||
|
||
/** | ||
* Indicates whether biometrics are configured or not (fingerprints enrolled or not). | ||
* <p> | ||
* A false return value indicates a YubiKey Bio without biometrics configured and hence the | ||
* client should fallback to a PIN based authentication. | ||
* | ||
* @return true if biometrics are configured or not. | ||
*/ | ||
public boolean isConfigured() { | ||
return configured; | ||
} | ||
|
||
/** | ||
* Returns value of biometric match retry counter which states how many biometric match retries | ||
* are left until a YubiKey Bio is blocked. | ||
* <p> | ||
* If this method returns 0 and {@link #isConfigured()} returns true, the device is blocked for | ||
* biometric match and the client should invoke PIN based authentication to reset the biometric | ||
* match retry counter. | ||
*/ | ||
public int getAttemptsRemaining() { | ||
return attemptsRemaining; | ||
} | ||
|
||
/** | ||
* Indicates whether a temporary PIN has been generated in the YubiKey in relation to a | ||
* successful biometric match. | ||
* | ||
* @return true if a temporary PIN has been generated. | ||
*/ | ||
public boolean hasTemporaryPin() { | ||
return temporaryPin; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
...android/src/androidTest/java/com/yubico/yubikit/testing/piv/PivBioMultiProtocolTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright (C) 2024 Yubico. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.yubico.yubikit.testing.piv; | ||
|
||
import com.yubico.yubikit.testing.framework.PivInstrumentedTests; | ||
|
||
import org.junit.Test; | ||
|
||
public class PivBioMultiProtocolTests extends PivInstrumentedTests { | ||
|
||
@Test | ||
public void testAuthenticate() throws Throwable { | ||
withPivSession(PivBioMultiProtocolDeviceTests::testAuthenticate); | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
testing/src/main/java/com/yubico/yubikit/testing/piv/PivBioMultiProtocolDeviceTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Copyright (C) 2024 Yubico. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.yubico.yubikit.testing.piv; | ||
|
||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertNotNull; | ||
import static org.junit.Assert.assertNull; | ||
import static org.junit.Assert.assertTrue; | ||
import static org.junit.Assume.assumeNoException; | ||
import static org.junit.Assume.assumeTrue; | ||
|
||
import com.yubico.yubikit.core.application.InvalidPinException; | ||
import com.yubico.yubikit.core.smartcard.ApduException; | ||
import com.yubico.yubikit.piv.BioMetadata; | ||
import com.yubico.yubikit.piv.PivSession; | ||
|
||
import java.io.IOException; | ||
|
||
public class PivBioMultiProtocolDeviceTests { | ||
|
||
/** | ||
* Verify authentication with YubiKey Bio Multi-protocol. | ||
* <p> | ||
* To run the test, create a PIN and enroll at least one fingerprint. The test will ask twice | ||
* for fingerprint authentication. | ||
*/ | ||
public static void testAuthenticate(PivSession piv) throws IOException, ApduException, InvalidPinException { | ||
try { | ||
BioMetadata bioMetadata = piv.getBioMetadata(); | ||
|
||
// we have correct key, is it configured? | ||
assumeTrue("Key has no bio multi-protocol functionality", bioMetadata.isConfigured()); | ||
assumeTrue("Key has no matches left", bioMetadata.getAttemptsRemaining() > 0); | ||
|
||
assertNull(piv.verifyUv(false, false)); | ||
assertFalse(piv.getBioMetadata().hasTemporaryPin()); | ||
|
||
// check verified state | ||
assertNull(piv.verifyUv(false, true)); | ||
|
||
byte[] pin = piv.verifyUv(true, false); | ||
assertNotNull(pin); | ||
assertTrue(piv.getBioMetadata().hasTemporaryPin()); | ||
|
||
// check verified state | ||
assertNull(piv.verifyUv(false, true)); | ||
|
||
piv.verifyTemporaryPin(pin); | ||
|
||
} catch (UnsupportedOperationException e) { | ||
assumeNoException("Key has no bio multi-protocol functionality", e); | ||
} | ||
} | ||
} |