Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

qemu: enable canokey by default #311914

Merged
merged 4 commits into from
May 22, 2024
Merged
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
1 change: 0 additions & 1 deletion nixos/tests/systemd-initrd-luks-fido2.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import ./make-test-python.nix ({ lib, pkgs, ... }: {
# Booting off the encrypted disk requires having a Nix store available for the init script
mountHostNixStore = true;
useEFIBoot = true;
qemu.package = lib.mkForce (pkgs.qemu_test.override { canokeySupport = true; });
qemu.options = [ "-device canokey,file=/tmp/canokey-file" ];
};
boot.loader.systemd-boot.enable = true;
Expand Down
41 changes: 41 additions & 0 deletions pkgs/applications/virtualization/qemu/canokey-qemu-memcpy.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
From 9e59480d941c40b868ebafa5138bbc71ca87f08e Mon Sep 17 00:00:00 2001
From: Alyssa Ross <[email protected]>
Date: Sat, 18 May 2024 09:55:17 +0200
Subject: [PATCH] Fix build where memcpy is a macro

I got the following compiler error with Clang 16 building for
x86_64-apple-darwin:

/tmp/nix-build-canokey-qemu-0-unstable-2023-06-06.drv-0/source/canokey-core/applets/oath/oath.c:44:50: error: too many arguments provided to function-like macro invocation
memcpy(RDATA, (uint8_t[]){OATH_TAG_VERSION, 3, 0x05, 0x05, 0x05, OATH_TAG_NAME, HANDLE_LEN}, 7);
^
/nix/store/vw8y07yai2pjv02s1piw3r5cyhmjbddf-Libsystem-1238.60.2/include/secure/_string.h:64:9: note: macro 'memcpy' defined here
#define memcpy(dest, src, len) \
^
/tmp/nix-build-canokey-qemu-0-unstable-2023-06-06.drv-0/source/canokey-core/applets/oath/oath.c:44:3: note: parentheses are required around macro argument containing braced initializer list
memcpy(RDATA, (uint8_t[]){OATH_TAG_VERSION, 3, 0x05, 0x05, 0x05, OATH_TAG_NAME, HANDLE_LEN}, 7);
^
( )
1 error generated.

Link: https://github.com/canokeys/canokey-core/pull/85
---
canokey-core/applets/oath/oath.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/canokey-core/applets/oath/oath.c b/canokey-core/applets/oath/oath.c
index bd8361a..2d2c0ef 100644
--- a/canokey-core/applets/oath/oath.c
+++ b/canokey-core/applets/oath/oath.c
@@ -41,7 +41,7 @@ int oath_install(uint8_t reset) {
static int oath_select(const CAPDU *capdu, RAPDU *rapdu) {
if (P2 != 0x00) EXCEPT(SW_WRONG_P1P2);

- memcpy(RDATA, (uint8_t[]){OATH_TAG_VERSION, 3, 0x05, 0x05, 0x05, OATH_TAG_NAME, HANDLE_LEN}, 7);
+ memcpy(RDATA, ((uint8_t[]){OATH_TAG_VERSION, 3, 0x05, 0x05, 0x05, OATH_TAG_NAME, HANDLE_LEN}), 7);
if (read_attr(OATH_FILE, ATTR_HANDLE, RDATA + 7, HANDLE_LEN) < 0) return -1;
LL = 7 + HANDLE_LEN;

--
2.44.0

24 changes: 21 additions & 3 deletions pkgs/applications/virtualization/qemu/canokey-qemu.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,47 @@
stdenv,
fetchFromGitHub,
cmake,
unstableGitUpdater,
}:
stdenv.mkDerivation rec {
pname = "canokey-qemu";
version = "unstable-2022-06-23";
rev = "b70af31229f1858089c3366f71b8d771de4a1e84";
version = "0-unstable-2023-06-06";
rev = "151568c34f5e92b086b7a3a62a11c43dd39f628b";

src = fetchFromGitHub {
owner = "canokeys";
repo = "canokey-qemu";
inherit rev;
fetchSubmodules = true;
hash = "sha256-VJb59K/skx+DhoJs5qGUu070hAjQZC2Z6hAMXuX0bMw=";
hash = "sha256-4V/2UOgGWgL+tFJO/k90bCDjWSVyIpxw3nYi9NU/OxA=";
};

patches = [
./canokey-qemu-memcpy.patch
];

postPatch = ''
substituteInPlace canokey-core/CMakeLists.txt \
--replace "COMMAND git describe --always --tags --long --abbrev=8 --dirty >>" "COMMAND echo '$rev' >>"
'';

preConfigure = ''
cmakeFlagsArray+=(
-DCMAKE_C_FLAGS=${lib.escapeShellArg ([
"-Wno-error=unused-but-set-parameter"
"-Wno-error=unused-but-set-variable"
] ++ lib.optionals stdenv.cc.isClang [
"-Wno-error=documentation"
])}
)
'';

outputs = [ "out" "dev" ];

nativeBuildInputs = [ cmake ];

passthru.updateScript = unstableGitUpdater { };

meta = with lib; {
homepage = "https://github.com/canokeys/canokey-qemu";
description = "CanoKey QEMU Virt Card";
Expand Down
2 changes: 1 addition & 1 deletion pkgs/applications/virtualization/qemu/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
, smbdSupport ? false, samba
, tpmSupport ? !toolsOnly
, uringSupport ? stdenv.isLinux, liburing
, canokeySupport ? false, canokey-qemu
, canokeySupport ? !toolsOnly, canokey-qemu
, capstoneSupport ? !toolsOnly, capstone
, enableDocs ? true
, hostCpuOnly ? false
Expand Down