Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2024-2025 Yubico.
* Copyright (C) 2024-2026 Yubico.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -24,6 +24,8 @@
import com.yubico.yubikit.openpgp.OpenPgpTests;
import com.yubico.yubikit.piv.PivTests;
import com.yubico.yubikit.sd.SecurityDomainTests;
import com.yubico.yubikit.yubiotp.YubiOtpOverCcidTests;
import com.yubico.yubikit.yubiotp.YubiOtpTests;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;

Expand All @@ -41,6 +43,8 @@
MultiProtocolResetTests.class,
FidoTests.class,
FidoOverCcidTests.class,
YubiOtpTests.class,
YubiOtpOverCcidTests.class,
SmartCardProtocolTests.class
})
public class DeviceTests {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright (C) 2026 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.yubiotp;

import com.yubico.yubikit.SmokeTest;
import com.yubico.yubikit.core.otp.OtpConnection;
import com.yubico.yubikit.core.smartcard.SmartCardConnection;
import com.yubico.yubikit.framework.YubiOtpInstrumentedTests;
import java.util.Collections;
import org.junit.Before;
import org.junit.Test;
import org.junit.experimental.categories.Category;

public class YubiOtpOverCcidTests extends YubiOtpInstrumentedTests {

@Before
public void setupCcidOnly() {
connectionTypes = Collections.singletonList(SmartCardConnection.class);
}

@Test
public void testSlotTouchTriggered() throws Throwable {
withYubiOtpSession(
(otp, state) -> {
YubiOtpDeviceTests.testSlotTouchTriggered(otp, state, Slot.ONE);
YubiOtpDeviceTests.testSlotTouchTriggered(otp, state, Slot.TWO);
});
}

@Test
@Category(SmokeTest.class)
public void testSwitchTransports() throws Throwable {
withYubiOtpSession(YubiOtpDeviceTests::testSlotConfigured);
connectionTypes = Collections.singletonList(OtpConnection.class);
withYubiOtpSession(YubiOtpDeviceTests::testSlotConfigured);
connectionTypes = Collections.singletonList(SmartCardConnection.class);
withYubiOtpSession(YubiOtpDeviceTests::testSlotConfigured);
connectionTypes = Collections.singletonList(OtpConnection.class);
withYubiOtpSession(YubiOtpDeviceTests::testCalculateHmacSha1);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright (C) 2026 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.yubiotp;

import com.yubico.yubikit.SmokeTest;
import com.yubico.yubikit.framework.YubiOtpInstrumentedTests;
import org.junit.Test;
import org.junit.experimental.categories.Category;

public class YubiOtpTests extends YubiOtpInstrumentedTests {
@Test
@Category(SmokeTest.class)
public void testSlotConfiguration() throws Throwable {
withYubiOtpSession(YubiOtpDeviceTests::testSlotConfigured);
}

@Test
public void testSlotTouchTriggered() throws Throwable {
withYubiOtpSession(
(otp, state) -> {
YubiOtpDeviceTests.testSlotTouchTriggered(otp, state, Slot.ONE);
YubiOtpDeviceTests.testSlotTouchTriggered(otp, state, Slot.TWO);
});
}

@Test
public void testConfigureNdef() throws Throwable {
withYubiOtpSession(YubiOtpDeviceTests::testConfigureNdef);
}

@Test
@Category(SmokeTest.class)
public void testCalculateHmacSha1() throws Throwable {
withYubiOtpSession(YubiOtpDeviceTests::testCalculateHmacSha1);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright (C) 2026 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.framework;

import com.yubico.yubikit.TestState;
import com.yubico.yubikit.core.YubiKeyConnection;
import com.yubico.yubikit.core.otp.OtpConnection;
import com.yubico.yubikit.core.smartcard.SmartCardConnection;
import com.yubico.yubikit.yubiotp.YubiOtpSession;
import com.yubico.yubikit.yubiotp.YubiOtpTestState;
import java.util.Arrays;
import java.util.List;

public class YubiOtpInstrumentedTests extends YkInstrumentedTests {

public static List<Class<? extends YubiKeyConnection>> connectionTypes =
Arrays.asList(OtpConnection.class, SmartCardConnection.class);

protected void withYubiOtpSession(
TestState.StatefulSessionCallback<YubiOtpSession, YubiOtpTestState> callback)
throws Throwable {
final YubiOtpTestState state =
new YubiOtpTestState.Builder(device, connectionTypes, usbPid).scpKid(getScpKid()).build();
state.withYubiOtp(callback);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2024-2025 Yubico.
* Copyright (C) 2024-2026 Yubico.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -23,6 +23,8 @@
import com.yubico.yubikit.openpgp.OpenPgpTests;
import com.yubico.yubikit.piv.PivTests;
import com.yubico.yubikit.sd.SecurityDomainTests;
import com.yubico.yubikit.yubiotp.YubiOtpOverCcidTests;
import com.yubico.yubikit.yubiotp.YubiOtpTests;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;

Expand All @@ -42,6 +44,8 @@
MultiProtocolResetTests.class,
FidoTests.class,
FidoOverCcidTests.class,
YubiOtpTests.class,
YubiOtpOverCcidTests.class,
SmartCardProtocolTests.class
})
public class DeviceTests {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright (C) 2026 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.yubiotp;

import com.yubico.yubikit.SmokeTest;
import com.yubico.yubikit.core.otp.OtpConnection;
import com.yubico.yubikit.core.smartcard.SmartCardConnection;
import com.yubico.yubikit.framework.YubiOtpInstrumentedTests;
import java.util.Collections;
import org.junit.Before;
import org.junit.Test;
import org.junit.experimental.categories.Category;

public class YubiOtpOverCcidTests extends YubiOtpInstrumentedTests {

@Before
public void setupCcidOnly() {
connectionTypes = Collections.singletonList(SmartCardConnection.class);
}

@Test
public void testSlotTouchTriggered() throws Throwable {
withYubiOtpSession(
(otp, state) -> {
YubiOtpDeviceTests.testSlotTouchTriggered(otp, state, Slot.ONE);
YubiOtpDeviceTests.testSlotTouchTriggered(otp, state, Slot.TWO);
});
}

@Test
@Category(SmokeTest.class)
public void testSwitchTransports() throws Throwable {
withYubiOtpSession(YubiOtpDeviceTests::testSlotConfigured);
connectionTypes = Collections.singletonList(OtpConnection.class);
withYubiOtpSession(YubiOtpDeviceTests::testSlotConfigured);
connectionTypes = Collections.singletonList(SmartCardConnection.class);
withYubiOtpSession(YubiOtpDeviceTests::testSlotConfigured);
connectionTypes = Collections.singletonList(OtpConnection.class);
withYubiOtpSession(YubiOtpDeviceTests::testCalculateHmacSha1);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright (C) 2026 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.yubiotp;

import com.yubico.yubikit.SmokeTest;
import com.yubico.yubikit.framework.YubiOtpInstrumentedTests;
import org.junit.Test;
import org.junit.experimental.categories.Category;

public class YubiOtpTests extends YubiOtpInstrumentedTests {
@Test
@Category(SmokeTest.class)
public void testSlotConfiguration() throws Throwable {
withYubiOtpSession(YubiOtpDeviceTests::testSlotConfigured);
}

@Test
public void testSlotTouchTriggered() throws Throwable {
withYubiOtpSession(
(otp, state) -> {
YubiOtpDeviceTests.testSlotTouchTriggered(otp, state, Slot.ONE);
YubiOtpDeviceTests.testSlotTouchTriggered(otp, state, Slot.TWO);
});
}

@Test
public void testConfigureNdef() throws Throwable {
withYubiOtpSession(YubiOtpDeviceTests::testConfigureNdef);
}

@Test
@Category(SmokeTest.class)
public void testCalculateHmacSha1() throws Throwable {
withYubiOtpSession(YubiOtpDeviceTests::testCalculateHmacSha1);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright (C) 2026 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.framework;

import com.yubico.yubikit.TestState;
import com.yubico.yubikit.core.YubiKeyConnection;
import com.yubico.yubikit.core.otp.OtpConnection;
import com.yubico.yubikit.core.smartcard.SmartCardConnection;
import com.yubico.yubikit.yubiotp.YubiOtpSession;
import com.yubico.yubikit.yubiotp.YubiOtpTestState;
import java.util.Arrays;
import java.util.List;

public class YubiOtpInstrumentedTests extends YkInstrumentedTests {

public static List<Class<? extends YubiKeyConnection>> connectionTypes =
Arrays.asList(OtpConnection.class, SmartCardConnection.class);

protected void withYubiOtpSession(
TestState.StatefulSessionCallback<YubiOtpSession, YubiOtpTestState> callback)
throws Throwable {
final YubiOtpTestState state =
new YubiOtpTestState.Builder(device, connectionTypes, usbPid).scpKid(getScpKid()).build();
state.withYubiOtp(callback);
}
}
11 changes: 10 additions & 1 deletion testing/src/main/java/com/yubico/yubikit/AllowList.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2025 Yubico.
* Copyright (C) 2025-2026 Yubico.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -21,6 +21,7 @@
import com.yubico.yubikit.core.YubiKeyConnection;
import com.yubico.yubikit.core.YubiKeyDevice;
import com.yubico.yubikit.core.fido.FidoConnection;
import com.yubico.yubikit.core.otp.OtpConnection;
import com.yubico.yubikit.core.smartcard.SmartCardConnection;
import com.yubico.yubikit.management.DeviceInfo;
import com.yubico.yubikit.support.DeviceUtil;
Expand Down Expand Up @@ -87,6 +88,14 @@ private Integer getDeviceSerialNumber(YubiKeyDevice device, @Nullable UsbPid pid
}
}

if (device.supportsConnection(OtpConnection.class)) {
try (OtpConnection connection = device.openConnection(OtpConnection.class)) {
return getDeviceSerialNumber(connection, pid);
} catch (Exception e) {
logger.error("Error opening OTP connection", e);
}
}

if (device.supportsConnection(FidoConnection.class)) {
try (FidoConnection connection = device.openConnection(FidoConnection.class)) {
return getDeviceSerialNumber(connection, pid);
Expand Down
Loading
Loading