Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wine-cw
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wine
wine-cw
Commits
300c10a3
Commit
300c10a3
authored
Sep 08, 2005
by
Juan Lang
Committed by
Alexandre Julliard
Sep 08, 2005
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- implement system stores
- remove an intermittently failing registry test
parent
09d9f429
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
222 additions
and
46 deletions
+222
-46
cert.c
dlls/crypt32/cert.c
+123
-45
cert.c
dlls/crypt32/tests/cert.c
+99
-1
No files found.
dlls/crypt32/cert.c
View file @
300c10a3
...
...
@@ -1405,7 +1405,7 @@ static PWINECRYPT_CERTSTORE CRYPT_SysRegOpenStoreW(HCRYPTPROV hCryptProv,
DWORD
dwFlags
,
const
void
*
pvPara
)
{
static
const
WCHAR
fmt
[]
=
{
'%'
,
's'
,
'\\'
,
'%'
,
's'
,
0
};
LP
WSTR
storeName
=
(
LP
WSTR
)
pvPara
;
LP
CWSTR
storeName
=
(
LPC
WSTR
)
pvPara
;
LPWSTR
storePath
;
PWINECRYPT_CERTSTORE
store
=
NULL
;
HKEY
root
;
...
...
@@ -1535,60 +1535,89 @@ static PWINECRYPT_CERTSTORE CRYPT_SysRegOpenStoreA(HCRYPTPROV hCryptProv,
return
ret
;
}
static
void
WINAPI
CRYPT_DummyCloseStore
(
HCERTSTORE
hCertStore
,
DWORD
dwFlags
)
static
PWINECRYPT_CERTSTORE
CRYPT_SysOpenStoreW
(
HCRYPTPROV
hCryptProv
,
DWORD
dwFlags
,
const
void
*
pvPara
)
{
H
eapFree
(
GetProcessHeap
(),
0
,
(
PWINECRYPT_CERTSTORE
)
hCertStore
)
;
}
H
CERTSTORE
store
=
0
;
BOOL
ret
;
static
BOOL
WINAPI
CRYPT_DummyAddCert
(
HCERTSTORE
store
,
PCCERT_CONTEXT
pCert
,
DWORD
dwAddDisposition
)
{
return
FALSE
;
}
TRACE
(
"(%ld, %08lx, %s)
\n
"
,
hCryptProv
,
dwFlags
,
debugstr_w
((
LPCWSTR
)
pvPara
));
static
PWINE_CERT_CONTEXT_REF
CRYPT_DummyEnumCert
(
PWINECRYPT_CERTSTORE
store
,
PWINE_CERT_CONTEXT_REF
pPrev
)
{
return
NULL
;
}
if
(
!
pvPara
)
{
SetLastError
(
ERROR_FILE_NOT_FOUND
);
return
NULL
;
}
/* This returns a different error than system registry stores if the
* location is invalid.
*/
switch
(
dwFlags
&
CERT_SYSTEM_STORE_LOCATION_MASK
)
{
case
CERT_SYSTEM_STORE_LOCAL_MACHINE
:
case
CERT_SYSTEM_STORE_CURRENT_USER
:
case
CERT_SYSTEM_STORE_CURRENT_SERVICE
:
case
CERT_SYSTEM_STORE_SERVICES
:
case
CERT_SYSTEM_STORE_USERS
:
case
CERT_SYSTEM_STORE_CURRENT_USER_GROUP_POLICY
:
case
CERT_SYSTEM_STORE_LOCAL_MACHINE_GROUP_POLICY
:
case
CERT_SYSTEM_STORE_LOCAL_MACHINE_ENTERPRISE
:
ret
=
TRUE
;
break
;
default:
SetLastError
(
ERROR_FILE_NOT_FOUND
);
ret
=
FALSE
;
}
if
(
ret
)
{
HCERTSTORE
regStore
=
CertOpenStore
(
CERT_STORE_PROV_SYSTEM_REGISTRY_W
,
0
,
hCryptProv
,
dwFlags
,
pvPara
);
static
BOOL
WINAPI
CRYPT_DummyDeleteCert
(
HCERTSTORE
hCertStore
,
PCCERT_CONTEXT
pCertContext
,
DWORD
dwFlags
)
{
return
TRUE
;
if
(
regStore
)
{
store
=
CertOpenStore
(
CERT_STORE_PROV_COLLECTION
,
0
,
0
,
CERT_STORE_CREATE_NEW_FLAG
,
NULL
);
if
(
store
)
{
CertAddStoreToCollection
(
store
,
regStore
,
dwFlags
&
CERT_STORE_READONLY_FLAG
?
0
:
CERT_PHYSICAL_STORE_ADD_ENABLE_FLAG
,
0
);
CertCloseStore
(
regStore
,
0
);
}
}
}
return
(
PWINECRYPT_CERTSTORE
)
store
;
}
static
WINECRYPT_CERTSTORE
*
CRYPT_DummyOpenStore
(
HCRYPTPROV
hCryptProv
,
static
PWINECRYPT_CERTSTORE
CRYPT_SysOpenStoreA
(
HCRYPTPROV
hCryptProv
,
DWORD
dwFlags
,
const
void
*
pvPara
)
{
PWINECRYPT_CERTSTORE
store
;
int
len
;
PWINECRYPT_CERTSTORE
ret
=
NULL
;
TRACE
(
"(%ld, %08lx, %p)
\n
"
,
hCryptProv
,
dwFlags
,
pvPara
);
TRACE
(
"(%ld, %08lx, %s)
\n
"
,
hCryptProv
,
dwFlags
,
debugstr_a
((
LPCSTR
)
pvPara
));
if
(
dwFlags
&
CERT_STORE_DELETE_FLAG
)
if
(
!
pvPara
)
{
SetLastError
(
ERROR_
CALL_NOT_IMPLEMENTE
D
);
store
=
NULL
;
SetLastError
(
ERROR_
FILE_NOT_FOUN
D
);
return
NULL
;
}
else
len
=
MultiByteToWideChar
(
CP_ACP
,
0
,
(
LPCSTR
)
pvPara
,
-
1
,
NULL
,
0
);
if
(
len
)
{
store
=
HeapAlloc
(
GetProcessHeap
(),
HEAP_ZERO_MEMORY
,
sizeof
(
WINECRYPT_CERTSTORE
));
if
(
store
)
LPWSTR
storeName
=
HeapAlloc
(
GetProcessHeap
(),
0
,
len
*
sizeof
(
WCHAR
));
if
(
store
Name
)
{
CRYPT_InitStore
(
store
,
hCryptProv
,
dwFlags
,
StoreTypeDummy
);
store
->
closeStore
=
CRYPT_DummyCloseStore
;
store
->
addCert
=
CRYPT_DummyAddCert
;
store
->
createCertRef
=
CRYPT_CreateCertRef
;
store
->
enumCert
=
CRYPT_DummyEnumCert
;
store
->
deleteCert
=
CRYPT_DummyDeleteCert
;
store
->
freeCert
=
NULL
;
MultiByteToWideChar
(
CP_ACP
,
0
,
(
LPCSTR
)
pvPara
,
-
1
,
storeName
,
len
);
ret
=
CRYPT_SysOpenStoreW
(
hCryptProv
,
dwFlags
,
storeName
);
HeapFree
(
GetProcessHeap
(),
0
,
storeName
);
}
}
return
(
PWINECRYPT_CERTSTORE
)
store
;
return
ret
;
}
HCERTSTORE
WINAPI
CertOpenStore
(
LPCSTR
lpszStoreProvider
,
DWORD
dwMsgAndCertEncodingType
,
HCRYPTPROV
hCryptProv
,
DWORD
dwFlags
,
const
void
*
pvPara
)
...
...
@@ -1613,8 +1642,10 @@ HCERTSTORE WINAPI CertOpenStore(LPCSTR lpszStoreProvider,
openFunc
=
CRYPT_CollectionOpenStore
;
break
;
case
(
int
)
CERT_STORE_PROV_SYSTEM_A
:
openFunc
=
CRYPT_SysOpenStoreA
;
break
;
case
(
int
)
CERT_STORE_PROV_SYSTEM_W
:
openFunc
=
CRYPT_
DummyOpenStore
;
openFunc
=
CRYPT_
SysOpenStoreW
;
break
;
case
(
int
)
CERT_STORE_PROV_SYSTEM_REGISTRY_A
:
openFunc
=
CRYPT_SysRegOpenStoreA
;
...
...
@@ -1630,7 +1661,7 @@ HCERTSTORE WINAPI CertOpenStore(LPCSTR lpszStoreProvider,
else
if
(
!
strcasecmp
(
lpszStoreProvider
,
sz_CERT_STORE_PROV_MEMORY
))
openFunc
=
CRYPT_MemOpenStore
;
else
if
(
!
strcasecmp
(
lpszStoreProvider
,
sz_CERT_STORE_PROV_SYSTEM
))
openFunc
=
CRYPT_
DummyOpenStore
;
openFunc
=
CRYPT_
SysOpenStoreW
;
else
if
(
!
strcasecmp
(
lpszStoreProvider
,
sz_CERT_STORE_PROV_COLLECTION
))
openFunc
=
CRYPT_CollectionOpenStore
;
else
if
(
!
strcasecmp
(
lpszStoreProvider
,
sz_CERT_STORE_PROV_SYSTEM_REGISTRY
))
...
...
@@ -1655,17 +1686,64 @@ HCERTSTORE WINAPI CertOpenStore(LPCSTR lpszStoreProvider,
HCERTSTORE
WINAPI
CertOpenSystemStoreA
(
HCRYPTPROV
hProv
,
LPCSTR
szSubSystemProtocol
)
{
return
CertOpenStore
(
CERT_STORE_PROV_SYSTEM_A
,
0
,
0
,
CERT_SYSTEM_STORE_CURRENT_USER
|
CERT_SYSTEM_STORE_LOCAL_MACHINE
|
CERT_SYSTEM_STORE_USERS
,
szSubSystemProtocol
);
HCERTSTORE
ret
=
0
;
if
(
szSubSystemProtocol
)
{
int
len
=
MultiByteToWideChar
(
CP_ACP
,
0
,
szSubSystemProtocol
,
-
1
,
NULL
,
0
);
LPWSTR
param
=
HeapAlloc
(
GetProcessHeap
(),
0
,
len
*
sizeof
(
WCHAR
));
if
(
param
)
{
MultiByteToWideChar
(
CP_ACP
,
0
,
szSubSystemProtocol
,
-
1
,
param
,
len
);
ret
=
CertOpenSystemStoreW
(
hProv
,
param
);
HeapFree
(
GetProcessHeap
(),
0
,
param
);
}
}
else
SetLastError
(
HRESULT_FROM_WIN32
(
ERROR_INVALID_PARAMETER
));
return
ret
;
}
HCERTSTORE
WINAPI
CertOpenSystemStoreW
(
HCRYPTPROV
hProv
,
LPCWSTR
szSubSystemProtocol
)
{
return
CertOpenStore
(
CERT_STORE_PROV_SYSTEM_W
,
0
,
0
,
CERT_SYSTEM_STORE_CURRENT_USER
|
CERT_SYSTEM_STORE_LOCAL_MACHINE
|
CERT_SYSTEM_STORE_USERS
,
szSubSystemProtocol
);
HCERTSTORE
ret
;
if
(
!
szSubSystemProtocol
)
{
SetLastError
(
HRESULT_FROM_WIN32
(
ERROR_INVALID_PARAMETER
));
return
0
;
}
/* FIXME: needs some tests. It seems to open both HKEY_LOCAL_MACHINE and
* HKEY_CURRENT_USER stores, but I'm not sure under what conditions, if any,
* it fails.
*/
ret
=
CertOpenStore
(
CERT_STORE_PROV_COLLECTION
,
0
,
hProv
,
CERT_STORE_CREATE_NEW_FLAG
,
NULL
);
if
(
ret
)
{
HCERTSTORE
store
=
CertOpenStore
(
CERT_STORE_PROV_SYSTEM_REGISTRY_W
,
0
,
hProv
,
CERT_SYSTEM_STORE_LOCAL_MACHINE
,
szSubSystemProtocol
);
if
(
store
)
{
CertAddStoreToCollection
(
ret
,
store
,
CERT_PHYSICAL_STORE_ADD_ENABLE_FLAG
,
0
);
CertCloseStore
(
store
,
0
);
}
store
=
CertOpenStore
(
CERT_STORE_PROV_SYSTEM_REGISTRY_W
,
0
,
hProv
,
CERT_SYSTEM_STORE_CURRENT_USER
,
szSubSystemProtocol
);
if
(
store
)
{
CertAddStoreToCollection
(
ret
,
store
,
CERT_PHYSICAL_STORE_ADD_ENABLE_FLAG
,
0
);
CertCloseStore
(
store
,
0
);
}
}
return
ret
;
}
BOOL
WINAPI
CertSaveStore
(
HCERTSTORE
hCertStore
,
DWORD
dwMsgAndCertEncodingType
,
...
...
dlls/crypt32/tests/cert.c
View file @
300c10a3
...
...
@@ -883,7 +883,6 @@ static void testRegStore(void)
{
RegCloseKey
(
key
);
rc
=
RegDeleteKeyA
(
HKEY_CURRENT_USER
,
tempKey
);
ok
(
!
rc
,
"RegDeleteKeyA failed: %ld
\n
"
,
rc
);
if
(
rc
)
{
HMODULE
shlwapi
=
LoadLibraryA
(
"shlwapi"
);
...
...
@@ -975,6 +974,102 @@ static void testSystemRegStore(void)
"Expected ERROR_FILE_NOT_FOUND, got %08lx
\n
"
,
GetLastError
());
}
static
void
testSystemStore
(
void
)
{
static
const
WCHAR
baskslashW
[]
=
{
'\\'
,
0
};
HCERTSTORE
store
;
WCHAR
keyName
[
MAX_PATH
];
HKEY
key
;
LONG
rc
;
store
=
CertOpenStore
(
CERT_STORE_PROV_SYSTEM
,
0
,
0
,
0
,
NULL
);
ok
(
!
store
&&
GetLastError
()
==
ERROR_FILE_NOT_FOUND
,
"Expected ERROR_FILE_NOT_FOUND, got %08lx
\n
"
,
GetLastError
());
store
=
CertOpenStore
(
CERT_STORE_PROV_SYSTEM
,
0
,
0
,
CERT_SYSTEM_STORE_LOCAL_MACHINE
|
CERT_SYSTEM_STORE_CURRENT_USER
,
MyA
);
ok
(
!
store
&&
GetLastError
()
==
ERROR_FILE_NOT_FOUND
,
"Expected ERROR_FILE_NOT_FOUND, got %08lx
\n
"
,
GetLastError
());
store
=
CertOpenStore
(
CERT_STORE_PROV_SYSTEM
,
0
,
0
,
CERT_SYSTEM_STORE_LOCAL_MACHINE
|
CERT_SYSTEM_STORE_CURRENT_USER
,
MyW
);
ok
(
!
store
&&
GetLastError
()
==
ERROR_FILE_NOT_FOUND
,
"Expected ERROR_FILE_NOT_FOUND, got %08lx
\n
"
,
GetLastError
());
/* The name is expected to be UNICODE, first check with an ASCII name */
store
=
CertOpenStore
(
CERT_STORE_PROV_SYSTEM
,
0
,
0
,
CERT_SYSTEM_STORE_CURRENT_USER
|
CERT_STORE_OPEN_EXISTING_FLAG
,
MyA
);
ok
(
!
store
&&
GetLastError
()
==
ERROR_FILE_NOT_FOUND
,
"Expected ERROR_FILE_NOT_FOUND, got %08lx
\n
"
,
GetLastError
());
/* Create the expected key */
lstrcpyW
(
keyName
,
CERT_LOCAL_MACHINE_SYSTEM_STORE_REGPATH
);
lstrcatW
(
keyName
,
baskslashW
);
lstrcatW
(
keyName
,
MyW
);
rc
=
RegCreateKeyExW
(
HKEY_CURRENT_USER
,
keyName
,
0
,
NULL
,
0
,
KEY_READ
,
NULL
,
&
key
,
NULL
);
ok
(
!
rc
,
"RegCreateKeyEx failed: %ld
\n
"
,
rc
);
if
(
!
rc
)
RegCloseKey
(
key
);
/* Check opening with a UNICODE name, specifying the create new flag */
store
=
CertOpenStore
(
CERT_STORE_PROV_SYSTEM
,
0
,
0
,
CERT_SYSTEM_STORE_CURRENT_USER
|
CERT_STORE_CREATE_NEW_FLAG
,
MyW
);
ok
(
!
store
&&
GetLastError
()
==
ERROR_FILE_EXISTS
,
"Expected ERROR_FILE_EXISTS, got %08lx
\n
"
,
GetLastError
());
/* Now check opening with a UNICODE name, this time opening existing */
store
=
CertOpenStore
(
CERT_STORE_PROV_SYSTEM
,
0
,
0
,
CERT_SYSTEM_STORE_CURRENT_USER
|
CERT_STORE_OPEN_EXISTING_FLAG
,
MyW
);
ok
(
store
!=
0
,
"CertOpenStore failed: %08lx
\n
"
,
GetLastError
());
if
(
store
)
{
HCERTSTORE
memStore
=
CertOpenStore
(
CERT_STORE_PROV_MEMORY
,
0
,
0
,
CERT_STORE_CREATE_NEW_FLAG
,
NULL
);
/* Check that it's a collection store */
if
(
memStore
)
{
BOOL
ret
=
CertAddStoreToCollection
(
store
,
memStore
,
0
,
0
);
/* FIXME: this'll fail on NT4, but what error will it give? */
ok
(
ret
,
"CertAddStoreToCollection failed: %08lx
\n
"
,
GetLastError
());
CertCloseStore
(
memStore
,
0
);
}
CertCloseStore
(
store
,
0
);
}
/* Check opening a bogus store */
store
=
CertOpenStore
(
CERT_STORE_PROV_SYSTEM
,
0
,
0
,
CERT_SYSTEM_STORE_CURRENT_USER
|
CERT_STORE_OPEN_EXISTING_FLAG
,
BogusW
);
ok
(
!
store
&&
GetLastError
()
==
ERROR_FILE_NOT_FOUND
,
"Expected ERROR_FILE_NOT_FOUND, got %08lx
\n
"
,
GetLastError
());
store
=
CertOpenStore
(
CERT_STORE_PROV_SYSTEM
,
0
,
0
,
CERT_SYSTEM_STORE_CURRENT_USER
,
BogusW
);
ok
(
store
!=
0
,
"CertOpenStore failed: %08lx
\n
"
,
GetLastError
());
if
(
store
)
CertCloseStore
(
store
,
0
);
/* Now check whether deleting is allowed */
store
=
CertOpenStore
(
CERT_STORE_PROV_SYSTEM
,
0
,
0
,
CERT_SYSTEM_STORE_CURRENT_USER
|
CERT_STORE_DELETE_FLAG
,
BogusW
);
RegDeleteKeyW
(
HKEY_CURRENT_USER
,
BogusPathW
);
}
static
void
testCertOpenSystemStore
(
void
)
{
HCERTSTORE
store
;
store
=
CertOpenSystemStoreW
(
0
,
NULL
);
ok
(
!
store
&&
GetLastError
()
==
HRESULT_FROM_WIN32
(
ERROR_INVALID_PARAMETER
),
"Expected HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER), got %08lx
\n
"
,
GetLastError
());
/* This succeeds, and on WinXP at least, the Bogus key is created under
* HKCU (but not under HKLM, even when run as an administrator.)
*/
store
=
CertOpenSystemStoreW
(
0
,
BogusW
);
ok
(
store
!=
0
,
"CertOpenSystemStore failed: %08lx
\n
"
,
GetLastError
());
if
(
store
)
CertCloseStore
(
store
,
0
);
/* Delete it so other tests succeed next time around */
store
=
CertOpenStore
(
CERT_STORE_PROV_SYSTEM
,
0
,
0
,
CERT_SYSTEM_STORE_CURRENT_USER
|
CERT_STORE_DELETE_FLAG
,
BogusW
);
RegDeleteKeyW
(
HKEY_CURRENT_USER
,
BogusPathW
);
}
static
void
testCertProperties
(
void
)
{
PCCERT_CONTEXT
context
=
CertCreateCertificateContext
(
X509_ASN_ENCODING
,
...
...
@@ -1254,6 +1349,9 @@ START_TEST(cert)
testCollectionStore
();
testRegStore
();
testSystemRegStore
();
testSystemStore
();
testCertOpenSystemStore
();
testCertProperties
();
testAddSerialized
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment