From: Mohamad Al-Jaf mohamadaljaf@gmail.com
Needed by Lenovo USBRecoveryCreator. --- dlls/cryptxml/Makefile.in | 3 + dlls/cryptxml/cryptxml.c | 114 ++++++++++++++++++++++++++++++++++++ dlls/cryptxml/cryptxml.spec | 2 +- include/cryptxml.h | 22 +++++++ 4 files changed, 140 insertions(+), 1 deletion(-) create mode 100644 dlls/cryptxml/cryptxml.c
diff --git a/dlls/cryptxml/Makefile.in b/dlls/cryptxml/Makefile.in index f5e925499c2..1fe91fe7019 100644 --- a/dlls/cryptxml/Makefile.in +++ b/dlls/cryptxml/Makefile.in @@ -1 +1,4 @@ MODULE = cryptxml.dll + +SOURCES = \ + cryptxml.c diff --git a/dlls/cryptxml/cryptxml.c b/dlls/cryptxml/cryptxml.c new file mode 100644 index 00000000000..d79e3895705 --- /dev/null +++ b/dlls/cryptxml/cryptxml.c @@ -0,0 +1,114 @@ +/* CryptXML Implementation + * + * Copyright (C) 2025 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 <stdarg.h> + +#include "windef.h" +#include "winbase.h" +#include "cryptxml.h" + +#include "wine/debug.h" + +WINE_DEFAULT_DEBUG_CHANNEL(cryptxml); + +#define DOC_MAGIC 0x584d4c44 +#define SIG_MAGIC 0x5349474e + +struct object +{ + ULONG magic; + CRYPT_XML_STATUS status; +}; + +struct xmldoc +{ + struct object hdr; + CRYPT_XML_DOC_CTXT ctx; +}; + +struct signature +{ + struct object hdr; + CRYPT_XML_SIGNATURE sig; + CRYPT_XML_KEY_INFO key_info; + struct xmldoc *doc; +}; + +struct xmldoc *alloc_doc( void ) +{ + struct xmldoc *doc; + + if (!(doc = calloc( 1, sizeof( *doc ) + sizeof( *doc->ctx.rgpSignature ) ))) return NULL; + + doc->hdr.magic = DOC_MAGIC; + doc->hdr.status.cbSize = sizeof( doc->hdr.status ); + doc->hdr.status.dwErrorStatus = CRYPT_XML_STATUS_ERROR_NOT_RESOLVED; + + doc->ctx.cbSize = sizeof( doc->ctx ); + doc->ctx.hDocCtxt = (HCRYPTXML)doc; + doc->ctx.rgpSignature = (CRYPT_XML_SIGNATURE **)(doc + 1); + return doc; +} + +struct signature *alloc_sig( const CRYPT_XML_BLOB *blob ) +{ + struct signature *sig; + + if (!(sig = calloc( 1, sizeof( *sig ) + blob->cbData ))) return NULL; + + sig->hdr.magic = SIG_MAGIC; + sig->hdr.status.cbSize = sizeof( sig->hdr.status ); + sig->hdr.status.dwErrorStatus = CRYPT_XML_STATUS_ERROR_NOT_RESOLVED; + + sig->sig.cbSize = sizeof( *sig ); + sig->sig.hSignature = (HCRYPTXML)sig; + sig->sig.SignatureValue.pbData = (BYTE *)(sig + 1); + memcpy( sig->sig.SignatureValue.pbData, blob->pbData, blob->cbData ); + sig->sig.SignatureValue.cbData = blob->cbData; + + sig->sig.pKeyInfo = &sig->key_info; + return sig; +} + +HRESULT WINAPI CryptXmlOpenToDecode( const CRYPT_XML_TRANSFORM_CHAIN_CONFIG *config, DWORD flags, + const CRYPT_XML_PROPERTY *property, ULONG property_count, + const CRYPT_XML_BLOB *blob, HCRYPTXML *handle ) +{ + struct xmldoc *doc; + struct signature *sig; + + FIXME( "config %p, flags %lx, property %p, property_count %lu, blob %p, handle %p stub!\n", + config, flags, property, property_count, blob, handle ); + + if (!blob || !handle) return E_INVALIDARG; + + if (!(sig = alloc_sig( blob ))) return E_OUTOFMEMORY; + if (!(doc = alloc_doc())) + { + free( sig ); + return E_OUTOFMEMORY; + } + + doc->ctx.cSignature = 1; + doc->ctx.rgpSignature[0] = &sig->sig; + sig->doc = doc; + + *handle = (HCRYPTXML)doc; + return S_OK; +} diff --git a/dlls/cryptxml/cryptxml.spec b/dlls/cryptxml/cryptxml.spec index 326f5d56b32..6e9847770a3 100644 --- a/dlls/cryptxml/cryptxml.spec +++ b/dlls/cryptxml/cryptxml.spec @@ -12,7 +12,7 @@ @ stub CryptXmlGetStatus @ stub CryptXmlGetTransforms @ stub CryptXmlImportPublicKey -@ stub CryptXmlOpenToDecode +@ stdcall CryptXmlOpenToDecode(ptr long ptr long ptr ptr) @ stub CryptXmlOpenToEncode @ stub CryptXmlSetHMACSecret @ stub CryptXmlSign diff --git a/include/cryptxml.h b/include/cryptxml.h index 1a531f9739d..b11c33a37c4 100644 --- a/include/cryptxml.h +++ b/include/cryptxml.h @@ -273,6 +273,28 @@ typedef struct _CRYPT_XML_DOC_CTXT PCRYPT_XML_SIGNATURE *rgpSignature; } CRYPT_XML_DOC_CTXT, *PCRYPT_XML_DOC_CTXT;
+typedef struct _CRYPT_XML_STATUS +{ + ULONG cbSize; + DWORD dwErrorStatus; + DWORD dwInfoStatus; +} CRYPT_XML_STATUS, *PCRYPT_XML_STATUS; + +#define CRYPT_XML_STATUS_NO_ERROR 0x00000000 +#define CRYPT_XML_STATUS_ERROR_NOT_RESOLVED 0x00000001 +#define CRYPT_XML_STATUS_ERROR_DIGEST_INVALID 0x00000002 +#define CRYPT_XML_STATUS_ERROR_NOT_SUPPORTED_ALGORITHM 0x00000004 +#define CRYPT_XML_STATUS_ERROR_NOT_SUPPORTED_TRANSFORM 0x00000008 +#define CRYPT_XML_STATUS_ERROR_SIGNATURE_INVALID 0x00010000 +#define CRYPT_XML_STATUS_ERROR_KEYINFO_NOT_PARSED 0x00020000 + +#define CRYPT_XML_STATUS_INTERNAL_REFERENCE 0x00000001 +#define CRYPT_XML_STATUS_KEY_AVAILABLE 0x00000002 +#define CRYPT_XML_STATUS_DIGESTING 0x00000004 +#define CRYPT_XML_STATUS_DIGEST_VALID 0x00000008 +#define CRYPT_XML_STATUS_SIGNATURE_VALID 0x00010000 +#define CRYPT_XML_STATUS_OPENED_TO_ENCODE 0x80000000 + HRESULT WINAPI CryptXmlOpenToDecode(const CRYPT_XML_TRANSFORM_CHAIN_CONFIG *config, DWORD flags, const CRYPT_XML_PROPERTY *property, ULONG property_count, const CRYPT_XML_BLOB *blob, HCRYPTXML *handle);