main.c 6.2 KB
Newer Older
Mike McCormack's avatar
Mike McCormack committed
1
/*
2
 * Copyright 2002 Mike McCormack for CodeWeavers
3
 * Copyright 2005 Juan Lang
Mike McCormack's avatar
Mike McCormack committed
4 5 6 7 8 9 10 11 12 13 14 15 16
 *
 * 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
17
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
Mike McCormack's avatar
Mike McCormack committed
18 19 20
 */

#include "config.h"
21
#include <stdarg.h>
22
#include <stdio.h>
23 24

#include "windef.h"
Mike McCormack's avatar
Mike McCormack committed
25
#include "winbase.h"
Mike McCormack's avatar
Mike McCormack committed
26
#include "wincrypt.h"
27
#include "winreg.h"
28
#include "winuser.h"
29
#include "i_cryptasn1tls.h"
30
#include "crypt32_private.h"
31 32 33
#include "wine/debug.h"

WINE_DEFAULT_DEBUG_CHANNEL(crypt);
Mike McCormack's avatar
Mike McCormack committed
34

35 36 37 38 39 40
static HCRYPTPROV hDefProv;

BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD fdwReason, PVOID pvReserved)
{
    switch (fdwReason)
    {
41
        case DLL_PROCESS_ATTACH:
42
            DisableThreadLibraryCalls(hInstance);
43
            crypt_oid_init(hInstance);
44
            break;
45
        case DLL_PROCESS_DETACH:
46
            crypt_oid_free();
47
            crypt_sip_free();
48
            root_store_free();
49
            default_chain_engine_free();
50 51 52 53 54 55 56 57 58 59 60 61 62 63
            if (hDefProv) CryptReleaseContext(hDefProv, 0);
            break;
    }
    return TRUE;
}

HCRYPTPROV CRYPT_GetDefaultProvider(void)
{
    if (!hDefProv)
        CryptAcquireContextW(&hDefProv, NULL, MS_ENHANCED_PROV_W,
         PROV_RSA_FULL, CRYPT_VERIFYCONTEXT);
    return hDefProv;
}

64 65 66 67 68 69 70 71 72
typedef void * HLRUCACHE;

/* this function is called by Internet Explorer when it is about to verify a
 * downloaded component.  The first parameter appears to be a pointer to an
 * unknown type, native fails unless it points to a buffer of at least 20 bytes.
 * The second parameter appears to be an out parameter, whatever it's set to is
 * passed (by cryptnet.dll) to I_CryptFlushLruCache.
 */
BOOL WINAPI I_CryptCreateLruCache(void *unknown, HLRUCACHE *out)
Mike McCormack's avatar
Mike McCormack committed
73
{
74 75 76
    FIXME("(%p, %p): stub!\n", unknown, out);
    *out = (void *)0xbaadf00d;
    return TRUE;
Mike McCormack's avatar
Mike McCormack committed
77 78
}

79 80 81 82 83 84
BOOL WINAPI I_CryptFindLruEntry(DWORD unk0, DWORD unk1)
{
    FIXME("(%08x, %08x): stub!\n", unk0, unk1);
    return FALSE;
}

85
BOOL WINAPI I_CryptFindLruEntryData(DWORD unk0, DWORD unk1, DWORD unk2)
Mike McCormack's avatar
Mike McCormack committed
86
{
87
    FIXME("(%08x, %08x, %08x): stub!\n", unk0, unk1, unk2);
Mike McCormack's avatar
Mike McCormack committed
88 89 90
    return FALSE;
}

91 92 93 94 95 96
BOOL WINAPI I_CryptCreateLruEntry(HLRUCACHE h, DWORD unk0, DWORD unk1)
{
    FIXME("(%p, %08x, %08x): stub!\n", h, unk0, unk1);
    return FALSE;
}

97
DWORD WINAPI I_CryptFlushLruCache(HLRUCACHE h, DWORD unk0, DWORD unk1)
Mike McCormack's avatar
Mike McCormack committed
98
{
99
    FIXME("(%p, %08x, %08x): stub!\n", h, unk0, unk1);
100
    return 0;
Mike McCormack's avatar
Mike McCormack committed
101 102
}

103
HLRUCACHE WINAPI I_CryptFreeLruCache(HLRUCACHE h, DWORD unk0, DWORD unk1)
Mike McCormack's avatar
Mike McCormack committed
104
{
105
    FIXME("(%p, %08x, %08x): stub!\n", h, unk0, unk1);
106
    return h;
Mike McCormack's avatar
Mike McCormack committed
107
}
Mike McCormack's avatar
Mike McCormack committed
108

109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
LPVOID WINAPI CryptMemAlloc(ULONG cbSize)
{
    return HeapAlloc(GetProcessHeap(), 0, cbSize);
}

LPVOID WINAPI CryptMemRealloc(LPVOID pv, ULONG cbSize)
{
    return HeapReAlloc(GetProcessHeap(), 0, pv, cbSize);
}

VOID WINAPI CryptMemFree(LPVOID pv)
{
    HeapFree(GetProcessHeap(), 0, pv);
}

DWORD WINAPI I_CryptAllocTls(void)
{
    return TlsAlloc();
}

LPVOID WINAPI I_CryptDetachTls(DWORD dwTlsIndex)
{
    LPVOID ret;

    ret = TlsGetValue(dwTlsIndex);
    TlsSetValue(dwTlsIndex, NULL);
    return ret;
}

LPVOID WINAPI I_CryptGetTls(DWORD dwTlsIndex)
{
    return TlsGetValue(dwTlsIndex);
}

BOOL WINAPI I_CryptSetTls(DWORD dwTlsIndex, LPVOID lpTlsValue)
{
    return TlsSetValue(dwTlsIndex, lpTlsValue);
}

BOOL WINAPI I_CryptFreeTls(DWORD dwTlsIndex, DWORD unknown)
{
150
    TRACE("(%d, %d)\n", dwTlsIndex, unknown);
151 152
    return TlsFree(dwTlsIndex);
}
153 154 155

BOOL WINAPI I_CryptGetOssGlobal(DWORD x)
{
156
    FIXME("%08x\n", x);
157 158 159
    return FALSE;
}

160
HCRYPTPROV WINAPI I_CryptGetDefaultCryptProv(DWORD reserved)
161
{
162 163
    HCRYPTPROV ret;

164
    TRACE("(%08x)\n", reserved);
165 166 167 168 169 170 171 172 173

    if (reserved)
    {
        SetLastError(E_INVALIDARG);
        return (HCRYPTPROV)0;
    }
    ret = CRYPT_GetDefaultProvider();
    CryptContextAddRef(ret, NULL, 0);
    return ret;
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190
}

BOOL WINAPI I_CryptReadTrustedPublisherDWORDValueFromRegistry(LPCWSTR name,
 DWORD *value)
{
    static const WCHAR safer[] = { 
     'S','o','f','t','w','a','r','e','\\','P','o','l','i','c','i','e','s','\\',
     'M','i','c','r','o','s','o','f','t','\\','S','y','s','t','e','m',
     'C','e','r','t','i','f','i','c','a','t','e','s','\\',
     'T','r','u','s','t','e','d','P','u','b','l','i','s','h','e','r','\\',
     'S','a','f','e','r',0 };
    HKEY key;
    LONG rc;
    BOOL ret = FALSE;

    TRACE("(%s, %p)\n", debugstr_w(name), value);

191
    *value = 0;
192 193 194 195 196 197 198 199 200 201 202 203
    rc = RegCreateKeyW(HKEY_LOCAL_MACHINE, safer, &key);
    if (rc == ERROR_SUCCESS)
    {
        DWORD size = sizeof(DWORD);

        if (!RegQueryValueExW(key, name, NULL, NULL, (LPBYTE)value, &size))
            ret = TRUE;
        RegCloseKey(key);
    }
    return ret;
}

204
DWORD WINAPI I_CryptInstallOssGlobal(DWORD x, DWORD y, DWORD z)
205
{
206 207 208 209
    static int ret = 8;
    ret++;
    FIXME("%08x %08x %08x, return value %d\n", x, y, z,ret);
    return ret;
210
}
211

212
BOOL WINAPI I_CryptInstallAsn1Module(ASN1module_t x, DWORD y, void* z)
213
{
214
    FIXME("(%p %08x %p): stub\n", x, y, z);
215 216 217
    return TRUE;
}

218
BOOL WINAPI I_CryptUninstallAsn1Module(HCRYPTASN1MODULE x)
219
{
220
    FIXME("(%08x): stub\n", x);
221 222 223
    return TRUE;
}

224
ASN1decoding_t WINAPI I_CryptGetAsn1Decoder(HCRYPTASN1MODULE x)
225
{
226 227 228 229 230 231 232
    FIXME("(%08x): stub\n", x);
    return NULL;
}

ASN1encoding_t WINAPI I_CryptGetAsn1Encoder(HCRYPTASN1MODULE x)
{
    FIXME("(%08x): stub\n", x);
233 234 235
    return NULL;
}

236 237 238 239
BOOL WINAPI CryptFormatObject(DWORD dwCertEncodingType, DWORD dwFormatType,
 DWORD dwFormatStrType, void *pFormatStruct, LPCSTR lpszStructType,
 const BYTE *pbEncoded, DWORD cbEncoded, void *pbFormat, DWORD *pcbFormat)
{
240
    FIXME("(%08x, %d, %d, %p, %s, %p, %d, %p, %p): stub\n",
241 242 243 244
     dwCertEncodingType, dwFormatType, dwFormatStrType, pFormatStruct,
     debugstr_a(lpszStructType), pbEncoded, cbEncoded, pbFormat, pcbFormat);
    return FALSE;
}