From: Mohamad Al-Jaf mohamadaljaf@gmail.com
--- dlls/cryptowinrt/Makefile.in | 1 + dlls/cryptowinrt/classes.idl | 1 + dlls/cryptowinrt/credentials.c | 177 ++++++++++++++++++++++++++++++++ dlls/cryptowinrt/main.c | 9 +- dlls/cryptowinrt/private.h | 4 + dlls/cryptowinrt/tests/crypto.c | 37 +++++++ 6 files changed, 225 insertions(+), 4 deletions(-) create mode 100644 dlls/cryptowinrt/credentials.c
diff --git a/dlls/cryptowinrt/Makefile.in b/dlls/cryptowinrt/Makefile.in index 192ef49f178..39250b66b66 100644 --- a/dlls/cryptowinrt/Makefile.in +++ b/dlls/cryptowinrt/Makefile.in @@ -2,6 +2,7 @@ MODULE = cryptowinrt.dll IMPORTS = combase bcrypt uuid
C_SRCS = \ + credentials.c \ main.c
IDL_SRCS = classes.idl diff --git a/dlls/cryptowinrt/classes.idl b/dlls/cryptowinrt/classes.idl index 4352a8562e5..62272d2f93c 100644 --- a/dlls/cryptowinrt/classes.idl +++ b/dlls/cryptowinrt/classes.idl @@ -19,3 +19,4 @@ #pragma makedep register
#include "windows.security.cryptography.idl" +#include "windows.security.credentials.idl" diff --git a/dlls/cryptowinrt/credentials.c b/dlls/cryptowinrt/credentials.c new file mode 100644 index 00000000000..ba375e77e0c --- /dev/null +++ b/dlls/cryptowinrt/credentials.c @@ -0,0 +1,177 @@ +/* CryptoWinRT Credentials Implementation + * + * Copyright (C) 2022 Mohamad Al-Jaf + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#include "private.h" + +#include "wine/debug.h" + +WINE_DEFAULT_DEBUG_CHANNEL(crypto); + +struct credentials_statics +{ + IActivationFactory IActivationFactory_iface; + IKeyCredentialManagerStatics IKeyCredentialManagerStatics_iface; + LONG ref; +}; + +static inline struct credentials_statics *impl_from_IActivationFactory( IActivationFactory *iface ) +{ + return CONTAINING_RECORD( iface, struct credentials_statics, IActivationFactory_iface ); +} + +static HRESULT WINAPI credentials_QueryInterface( IActivationFactory *iface, REFIID iid, void **out ) +{ + struct credentials_statics *factory = impl_from_IActivationFactory( iface ); + + TRACE( "iface %p, iid %s, out %p.\n", iface, debugstr_guid( iid ), out ); + + if (IsEqualGUID( iid, &IID_IUnknown ) || + IsEqualGUID( iid, &IID_IInspectable ) || + IsEqualGUID( iid, &IID_IAgileObject ) || + IsEqualGUID( iid, &IID_IActivationFactory )) + { + IUnknown_AddRef( iface ); + *out = &factory->IActivationFactory_iface; + return S_OK; + } + + if (IsEqualGUID( iid, &IID_IKeyCredentialManagerStatics )) + { + IUnknown_AddRef( iface ); + *out = &factory->IKeyCredentialManagerStatics_iface; + return S_OK; + } + + FIXME( "%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid( iid ) ); + *out = NULL; + return E_NOINTERFACE; +} + +static ULONG WINAPI credentials_AddRef( IActivationFactory *iface ) +{ + struct credentials_statics *impl = impl_from_IActivationFactory( iface ); + ULONG ref = InterlockedIncrement( &impl->ref ); + TRACE( "iface %p increasing refcount to %lu.\n", iface, ref ); + return ref; +} + +static ULONG WINAPI credentials_Release( IActivationFactory *iface ) +{ + struct credentials_statics *impl = impl_from_IActivationFactory( iface ); + ULONG ref = InterlockedDecrement( &impl->ref ); + TRACE( "iface %p decreasing refcount to %lu.\n", iface, ref ); + return ref; +} + +static HRESULT WINAPI credentials_GetIids( IActivationFactory *iface, ULONG *iid_count, IID **iids ) +{ + FIXME( "iface %p, iid_count %p, iids %p stub!\n", iface, iid_count, iids ); + return E_NOTIMPL; +} + +static HRESULT WINAPI credentials_GetRuntimeClassName( IActivationFactory *iface, HSTRING *class_name ) +{ + FIXME( "iface %p, class_name %p stub!\n", iface, class_name ); + return E_NOTIMPL; +} + +static HRESULT WINAPI credentials_GetTrustLevel( IActivationFactory *iface, TrustLevel *trust_level ) +{ + FIXME( "iface %p, trust_level %p stub!\n", iface, trust_level ); + return E_NOTIMPL; +} + +static HRESULT WINAPI credentials_ActivateInstance( IActivationFactory *iface, IInspectable **instance ) +{ + FIXME( "iface %p, instance %p stub!\n", iface, instance ); + return E_NOTIMPL; +} + +static const struct IActivationFactoryVtbl factory_vtbl = +{ + credentials_QueryInterface, + credentials_AddRef, + credentials_Release, + /* IInspectable methods */ + credentials_GetIids, + credentials_GetRuntimeClassName, + credentials_GetTrustLevel, + /* IActivationFactory methods */ + credentials_ActivateInstance, +}; + +DEFINE_IINSPECTABLE( credentials_statics, IKeyCredentialManagerStatics, struct credentials_statics, IActivationFactory_iface ); + +static HRESULT WINAPI credentials_statics_IsSupportedAsync( IKeyCredentialManagerStatics *iface, IAsyncOperation_boolean **value ) +{ + FIXME( "iface %p, value %p stub!\n", iface, value ); + return E_NOTIMPL; +} + +static HRESULT WINAPI credentials_statics_RenewAttestationAsync( IKeyCredentialManagerStatics *iface, IAsyncAction **operation ) +{ + FIXME( "iface %p, operation %p stub!\n", iface, operation ); + return E_NOTIMPL; +} + +static HRESULT WINAPI credentials_statics_RequestCreateAsync( IKeyCredentialManagerStatics *iface, + HSTRING name, KeyCredentialCreationOption option, IAsyncOperation_KeyCredentialRetrievalResult **value ) +{ + FIXME( "iface %p, name %s, %d option, %p value stub!\n", iface, debugstr_hstring(name), option, value ); + return E_NOTIMPL; +} + +static HRESULT WINAPI credentials_statics_OpenAsync(IKeyCredentialManagerStatics *iface, + HSTRING name, IAsyncOperation_KeyCredentialRetrievalResult **value) +{ + FIXME( "iface %p, name %s, %p value stub!\n", iface, debugstr_hstring(name), value ); + return E_NOTIMPL; +} + +static HRESULT WINAPI credentials_statics_DeleteAsync( IKeyCredentialManagerStatics *iface, HSTRING name, IAsyncAction **operation ) +{ + FIXME( "iface %p, name %s, %p operation stub!\n", iface, debugstr_hstring(name), operation ); + return E_NOTIMPL; +} + +static const struct IKeyCredentialManagerStaticsVtbl credentials_statics_vtbl = +{ + credentials_statics_QueryInterface, + credentials_statics_AddRef, + credentials_statics_Release, + /* IInspectable methods */ + credentials_statics_GetIids, + credentials_statics_GetRuntimeClassName, + credentials_statics_GetTrustLevel, + /* IKeyCredentialManagerStatics methods */ + credentials_statics_IsSupportedAsync, + credentials_statics_RenewAttestationAsync, + credentials_statics_RequestCreateAsync, + credentials_statics_OpenAsync, + credentials_statics_DeleteAsync, +}; + +static struct credentials_statics credentials_statics = +{ + {&factory_vtbl}, + {&credentials_statics_vtbl}, + 1, +}; + +IActivationFactory *credentials_activation_factory = &credentials_statics.IActivationFactory_iface; diff --git a/dlls/cryptowinrt/main.c b/dlls/cryptowinrt/main.c index 5da2bfd3139..e86dc1c3561 100644 --- a/dlls/cryptowinrt/main.c +++ b/dlls/cryptowinrt/main.c @@ -266,6 +266,8 @@ static struct cryptobuffer_factory cryptobuffer_factory = .refcount = 1, };
+IActivationFactory *cryptobuffer_activation_factory = &cryptobuffer_factory.IActivationFactory_iface; + HRESULT WINAPI DllGetClassObject(REFCLSID clsid, REFIID riid, void **out) { FIXME("clsid %s, riid %s, out %p stub!\n", debugstr_guid(clsid), debugstr_guid(riid), out); @@ -281,10 +283,9 @@ HRESULT WINAPI DllGetActivationFactory(HSTRING classid, IActivationFactory **fac *factory = NULL;
if (!wcscmp(name, RuntimeClass_Windows_Security_Cryptography_CryptographicBuffer)) - { - *factory = &cryptobuffer_factory.IActivationFactory_iface; - IUnknown_AddRef(*factory); - } + IActivationFactory_QueryInterface(cryptobuffer_activation_factory, &IID_IActivationFactory, (void **)factory); + if (!wcscmp(name, RuntimeClass_Windows_Security_Credentials_KeyCredentialManager)) + IActivationFactory_QueryInterface(credentials_activation_factory, &IID_IActivationFactory, (void **)factory);
if (*factory) return S_OK; return CLASS_E_CLASSNOTAVAILABLE; diff --git a/dlls/cryptowinrt/private.h b/dlls/cryptowinrt/private.h index 06da75920fe..fb2e84cbfbf 100644 --- a/dlls/cryptowinrt/private.h +++ b/dlls/cryptowinrt/private.h @@ -32,9 +32,13 @@ #define WIDL_using_Windows_Foundation #define WIDL_using_Windows_Foundation_Collections #include "windows.foundation.h" +#define WIDL_using_Windows_Security_Credentials +#include "windows.security.credentials.h"
extern const char *debugstr_hstring( HSTRING hstr );
+extern IActivationFactory *credentials_activation_factory; + #define DEFINE_IINSPECTABLE_( pfx, iface_type, impl_type, impl_from, iface_mem, expr ) \ static inline impl_type *impl_from( iface_type *iface ) \ { \ diff --git a/dlls/cryptowinrt/tests/crypto.c b/dlls/cryptowinrt/tests/crypto.c index fc841b2c3c6..0ddb1de1823 100644 --- a/dlls/cryptowinrt/tests/crypto.c +++ b/dlls/cryptowinrt/tests/crypto.c @@ -32,6 +32,8 @@ #include "windows.storage.streams.h" #define WIDL_using_Windows_Security_Cryptography #include "windows.security.cryptography.h" +#define WIDL_using_Windows_Security_Credentials +#include "windows.security.credentials.h"
#include "wine/test.h"
@@ -81,6 +83,40 @@ static void test_CryptobufferStatics(void) ok( ref == 1, "got ref %ld.\n", ref ); }
+static void test_Credentials_Statics(void) +{ + static const WCHAR *credentials_statics_name = L"Windows.Security.Credentials.KeyCredentialManager"; + IKeyCredentialManagerStatics *credentials_statics; + IActivationFactory *factory; + HSTRING str; + HRESULT hr; + LONG ref; + + hr = WindowsCreateString( credentials_statics_name, wcslen( credentials_statics_name ), &str ); + ok( hr == S_OK, "got hr %#lx.\n", hr ); + + hr = RoGetActivationFactory( str, &IID_IActivationFactory, (void **)&factory ); + WindowsDeleteString( str ); + ok( hr == S_OK || broken( hr == REGDB_E_CLASSNOTREG ), "got hr %#lx.\n", hr ); + if (hr == REGDB_E_CLASSNOTREG) + { + win_skip( "%s runtimeclass not registered, skipping tests.\n", wine_dbgstr_w( credentials_statics_name ) ); + return; + } + + check_interface( factory, &IID_IUnknown ); + check_interface( factory, &IID_IInspectable ); + check_interface( factory, &IID_IAgileObject ); + + hr = IActivationFactory_QueryInterface( factory, &IID_IKeyCredentialManagerStatics, (void **)&credentials_statics ); + ok( hr == S_OK, "got hr %#lx.\n", hr ); + + ref = IKeyCredentialManagerStatics_Release( credentials_statics ); + ok( ref == 2, "got ref %ld.\n", ref ); + ref = IActivationFactory_Release( factory ); + ok( ref == 1, "got ref %ld.\n", ref ); +} + START_TEST(crypto) { HRESULT hr; @@ -89,6 +125,7 @@ START_TEST(crypto) ok( hr == S_OK, "RoInitialize failed, hr %#lx\n", hr );
test_CryptobufferStatics(); + test_Credentials_Statics();
RoUninitialize(); }