Skip to content

Instantly share code, notes, and snippets.

@thelastlin
Last active August 24, 2024 11:48
Show Gist options
  • Save thelastlin/c45b96cf460919e39ab5807b6d20ac2a to your computer and use it in GitHub Desktop.
Save thelastlin/c45b96cf460919e39ab5807b6d20ac2a to your computer and use it in GitHub Desktop.
Build libsk-libfido2.so from OpenSSH-portable

Tested on macOS Sonoma Developer beta 2 (23A5276g)

Build libsk-libfido2.so

Prerequisite

  1. Download openssh-portable source code, install libcrypto, libfido2;
  2. Configure openssh-portable build system by ./configure # [options].

Apply patch

Patch inworkaround-standalone-libsk.patch.

Build object files needed by libsk-libfido2.so

You may want to add -flto or other flags in CFLAGS:

  1. make libssh.a CFLAGS="-O2 -fPIC"
  2. make openbsd-compat/libopenbsd-compat.a CFLAGS="-O2 -fPIC"
  3. make sk-usbhid.o CFLAGS="-O2 -DSK_STANDALONE -fPIC"

Link object files and generate libsk-libfido2.so

  1. Export LDFLAGS, LIBFIDO2 and CC from previous generated Makefile;
  2. echo $LIBFIDO2 | xargs ${CC} -shared openbsd-compat/libopenbsd-compat.a sk-usbhid.o libssh.a -O2 -fPIC -o libsk-libfido2.so. You may want to append other flags (for example, -Wl,-dead_strip,-exported_symbol,_sk_\* in macOS).

Don't forget to copy libsk-libfido2.so into /usr/local/lib.

diff --git a/sk-usbhid.c b/sk-usbhid.c
index 7bb829aa..85c027a1 100644
--- a/sk-usbhid.c
+++ b/sk-usbhid.c
@@ -75,10 +75,10 @@
#define FIDO_CRED_PROT_UV_OPTIONAL_WITH_ID 0
#endif
+#include "misc.h"
#ifndef SK_STANDALONE
# include "log.h"
# include "xmalloc.h"
-# include "misc.h"
/*
* If building as part of OpenSSH, then rename exported functions.
* This must be done before including sk-api.h.
@murka
Copy link

murka commented Mar 27, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment