# Client-side OPAQUE auth-mode driver over SSH.
#
# Parallel to opaque-register: same dlopen + libssh pattern, but pins
# mode = OPAQUE_MODE_AUTH (0) so the plug-in routes the three-message
# AKE against the server's stored record instead of running the
# 5-token register flow. Authenticates and exits — no shell.
#
# See GSSAPI_IMPLEMENTATION_PLAN.md §5.2 / §5.3 (070-auth-mode.sh).

pkg_check_modules(LIBSSH REQUIRED IMPORTED_TARGET libssh)

add_executable(opaque-ssh opaque-ssh.c)

# Same dlopen-via-mechglue pattern as opaque-register: we do NOT link
# gssopaque_obj directly. mechglue's dlopen of gssopaque.so and our own
# dlopen yield the same image (Linux dedup), so the pending credential
# slot set by gssspi_opaque_set_password is visible to the plug-in
# instance mechglue dispatches into.
target_link_libraries(opaque-ssh PRIVATE
    PkgConfig::LIBSSH
    PkgConfig::GSSAPI
    PkgConfig::SODIUM
    ${CMAKE_DL_LIBS})

target_compile_definitions(opaque-ssh PRIVATE
    _POSIX_C_SOURCE=200809L
    OPAQUE_PLUGIN_DEFAULT_PATH="${CMAKE_INSTALL_FULL_LIBDIR}/gssopaque/gssopaque.so")

install(TARGETS opaque-ssh
    RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
