Skip to content

Commit

Permalink
PM-9126: Add AddAuthenticator fn call
Browse files Browse the repository at this point in the history
  • Loading branch information
coltonhurst committed Feb 13, 2025
1 parent 4087c86 commit 00e69f7
Show file tree
Hide file tree
Showing 4 changed files with 142 additions and 5 deletions.
44 changes: 44 additions & 0 deletions apps/desktop/desktop_native/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ bindgen = "0.71.1"
[target.'cfg(windows)'.dependencies]
windows = { version = "0.59.0", features = ["Win32_Foundation", "Win32_Security", "Win32_System_Com" ] }
windows-core = "0.59.0"
ciborium = "0.2.2"
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,15 @@
mod pa;

use pa::{
EXPERIMENTAL_WebAuthNPluginAddAuthenticator, DWORD,
EXPERIMENTAL_PCWEBAUTHN_PLUGIN_CANCEL_OPERATION_REQUEST,
EXPERIMENTAL_PCWEBAUTHN_PLUGIN_OPERATION_REQUEST,
EXPERIMENTAL_PWEBAUTHN_PLUGIN_ADD_AUTHENTICATOR_RESPONSE,
EXPERIMENTAL_PWEBAUTHN_PLUGIN_OPERATION_RESPONSE,
EXPERIMENTAL_WEBAUTHN_PLUGIN_ADD_AUTHENTICATOR_RESPONSE, LPCWSTR, PBYTE, WCHAR,
_EXPERIMENTAL_WEBAUTHN_PLUGIN_ADD_AUTHENTICATOR_OPTIONS,
};
use std::ffi::c_uchar;
use std::ptr;
use windows::Win32::Foundation::*;
use windows::Win32::System::Com::*;
Expand Down Expand Up @@ -38,7 +43,6 @@ pub fn register() -> i32 {
}

static FACTORY: windows_core::StaticComObject<Factory> = Factory().into_static();

let random_plugin_guid_ptr: *const GUID = &GUID::from_u128(0xa98925d161f640de9327dc418fcb2ff4);
let result: u32 = match unsafe {
CoRegisterClassObject(
Expand All @@ -58,15 +62,102 @@ pub fn register() -> i32 {
}
};

// build the request
let authenticator_name: HSTRING = "Bitwarden Desktop Authenticator".into();
let authenticator_name_ptr = PCWSTR(authenticator_name.as_ptr()).as_ptr();

let clsid: HSTRING = "0f7dc5d9-69ce-4652-8572-6877fd695062".into();
let clsid_ptr = PCWSTR(clsid.as_ptr()).as_ptr();

let aaguid: HSTRING = "d548826e-79b4-db40-a3d8-11116f7e8349".into();
let aaguid_ptr = PCWSTR(aaguid.as_ptr()).as_ptr();

let relying_party_id: HSTRING = "bitwarden.com".into();
let relying_party_id_ptr = PCWSTR(relying_party_id.as_ptr()).as_ptr();

let mut pbPluginIdKey: u8 = 0;

let mut add_options = _EXPERIMENTAL_WEBAUTHN_PLUGIN_ADD_AUTHENTICATOR_OPTIONS {
pwszAuthenticatorName: authenticator_name_ptr,
pwszPluginClsId: clsid_ptr,
pwszAaguid: aaguid_ptr,
pwszPluginRpId: relying_party_id_ptr,
pwszLogo: ptr::null_mut(),
cbPluginIdKey: 0 as u32,
pbPluginIdKey: &mut pbPluginIdKey,
};

// build the response
let cbUvPubKey: DWORD = 0;
let mut pbUvPubKey: c_uchar = 0;
let pbUvPubKey_ptr: PBYTE = &mut pbUvPubKey;

let mut add_response = EXPERIMENTAL_WEBAUTHN_PLUGIN_ADD_AUTHENTICATOR_RESPONSE {
cbUvPubKey: cbUvPubKey,
pbUvPubKey: pbUvPubKey_ptr,
};

let mut add_response_ptr: *mut EXPERIMENTAL_WEBAUTHN_PLUGIN_ADD_AUTHENTICATOR_RESPONSE = &mut add_response;

// Add the authenticator
let r: i32 = unsafe { EXPERIMENTAL_WebAuthNPluginAddAuthenticator(&mut add_options, &mut add_response_ptr) };

println!("AddAuthenticator() -> {:?}/n{:?}", r, HRESULT(r).message());

8
}

pub fn get_test_number() -> i32 {
-1
}

pub fn get_version_number() -> u64 {
unsafe { pa::WebAuthNGetApiVersionNumber() }.into()
pub fn get_version_number() -> u32 {
unsafe { pa::WebAuthNGetApiVersionNumber() }
}

/*
pub type WCHAR = u16;
pub type LPCWSTR = *const WCHAR;
pub type DWORD = ::std::os::raw::c_ulong;
pub type BYTE = ::std::os::raw::c_uchar;
pub type PBYTE = *mut BYTE;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct _EXPERIMENTAL_WEBAUTHN_PLUGIN_ADD_AUTHENTICATOR_OPTIONS {
pub pwszAuthenticatorName: LPCWSTR,
pub pwszPluginClsId: LPCWSTR,
pub pwszAaguid: LPCWSTR,
pub pwszPluginRpId: LPCWSTR,
pub pwszLogo: LPCWSTR,
pub cbPluginIdKey: DWORD,
pub pbPluginIdKey: PBYTE,
}
pub type EXPERIMENTAL_PWEBAUTHN_PLUGIN_ADD_AUTHENTICATOR_RESPONSE =
*mut _EXPERIMENTAL_WEBAUTHN_PLUGIN_ADD_AUTHENTICATOR_RESPONSE;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct _EXPERIMENTAL_WEBAUTHN_PLUGIN_ADD_AUTHENTICATOR_RESPONSE {
pub cbUvPubKey: DWORD,
pub pbUvPubKey: PBYTE,
}
unsafe extern "C" {
pub fn EXPERIMENTAL_WebAuthNPluginAddAuthenticator(
pPluginAddAuthenticatorOptions: EXPERIMENTAL_PCWEBAUTHN_PLUGIN_ADD_AUTHENTICATOR_OPTIONS,
ppPluginAddAuthenticatorResponse : * mut EXPERIMENTAL_PWEBAUTHN_PLUGIN_ADD_AUTHENTICATOR_RESPONSE,
) -> HRESULT;
}
*/
pub fn add_authenticator(
add_authenticator_options: _EXPERIMENTAL_WEBAUTHN_PLUGIN_ADD_AUTHENTICATOR_OPTIONS,
add_authenticator_response: EXPERIMENTAL_PWEBAUTHN_PLUGIN_ADD_AUTHENTICATOR_RESPONSE,
) -> i32 {
0
}

#[interface("e6466e9a-b2f3-47c5-b88d-89bc14a8d998")]
Expand Down
5 changes: 3 additions & 2 deletions apps/desktop/src/entry.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { spawn } from "child_process";
import * as path from "path";

import { app } from "electron";

import { passkey_authenticator } from "@bitwarden/desktop-napi";

Check warning on line 6 in apps/desktop/src/entry.ts

View check run for this annotation

Codecov / codecov/patch

apps/desktop/src/entry.ts#L6

Added line #L6 was not covered by tests

import { app } from "electron";

if (
process.platform === "darwin" &&
Expand Down Expand Up @@ -42,7 +43,7 @@ if (
// eslint-disable-next-line
const Main = require("./main").Main;

let value = passkey_authenticator.register();
passkey_authenticator.register();

Check warning on line 46 in apps/desktop/src/entry.ts

View check run for this annotation

Codecov / codecov/patch

apps/desktop/src/entry.ts#L46

Added line #L46 was not covered by tests

const main = new Main();
main.bootstrap();
Expand Down

0 comments on commit 00e69f7

Please sign in to comment.