Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wine-winehq
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-winehq
Commits
b633d6a3
Commit
b633d6a3
authored
Aug 14, 2006
by
Juan Lang
Committed by
Alexandre Julliard
Aug 15, 2006
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
crypt32: Implement CertCreateCertificateChainEngine and CertFreeCertificateChainEngine.
parent
fd3fcc0b
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
284 additions
and
2 deletions
+284
-2
Makefile.in
dlls/crypt32/Makefile.in
+1
-0
chain.c
dlls/crypt32/chain.c
+172
-0
crypt32.spec
dlls/crypt32/crypt32.spec
+2
-2
Makefile.in
dlls/crypt32/tests/Makefile.in
+1
-0
chain.c
dlls/crypt32/tests/chain.c
+108
-0
No files found.
dlls/crypt32/Makefile.in
View file @
b633d6a3
...
@@ -10,6 +10,7 @@ IMPORTS = user32 advapi32 kernel32 ntdll
...
@@ -10,6 +10,7 @@ IMPORTS = user32 advapi32 kernel32 ntdll
C_SRCS
=
\
C_SRCS
=
\
base64.c
\
base64.c
\
cert.c
\
cert.c
\
chain.c
\
crl.c
\
crl.c
\
context.c
\
context.c
\
decode.c
\
decode.c
\
...
...
dlls/crypt32/chain.c
0 → 100644
View file @
b633d6a3
/*
* Copyright 2006 Juan Lang
*
* 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 "wincrypt.h"
#include "wine/debug.h"
#include "crypt32_private.h"
WINE_DEFAULT_DEBUG_CHANNEL
(
crypt
);
/* This represents a subset of a certificate chain engine: it doesn't include
* the "hOther" store described by MSDN, because I'm not sure how that's used.
* It also doesn't include the "hTrust" store, because I don't yet implement
* CTLs or complex certificate chains.
*/
typedef
struct
_CertificateChainEngine
{
LONG
ref
;
HCERTSTORE
hRoot
;
HCERTSTORE
hWorld
;
DWORD
dwFlags
;
DWORD
dwUrlRetrievalTimeout
;
DWORD
MaximumCachedCertificates
;
DWORD
CycleDetectionModulus
;
}
CertificateChainEngine
,
*
PCertificateChainEngine
;
static
inline
void
CRYPT_AddStoresToCollection
(
HCERTSTORE
collection
,
DWORD
cStores
,
HCERTSTORE
*
stores
)
{
DWORD
i
;
for
(
i
=
0
;
i
<
cStores
;
i
++
)
CertAddStoreToCollection
(
collection
,
stores
[
i
],
0
,
0
);
}
static
inline
void
CRYPT_CloseStores
(
DWORD
cStores
,
HCERTSTORE
*
stores
)
{
DWORD
i
;
for
(
i
=
0
;
i
<
cStores
;
i
++
)
CertCloseStore
(
stores
[
i
],
0
);
}
static
const
WCHAR
rootW
[]
=
{
'R'
,
'o'
,
'o'
,
't'
,
0
};
BOOL
CRYPT_CheckRestrictedRoot
(
HCERTSTORE
store
)
{
BOOL
ret
=
TRUE
;
if
(
store
)
{
HCERTSTORE
rootStore
=
CertOpenSystemStoreW
(
0
,
rootW
);
PCCERT_CONTEXT
cert
=
NULL
,
check
;
BYTE
hash
[
20
];
DWORD
size
;
do
{
cert
=
CertEnumCertificatesInStore
(
store
,
cert
);
if
(
cert
)
{
size
=
sizeof
(
hash
);
ret
=
CertGetCertificateContextProperty
(
cert
,
CERT_HASH_PROP_ID
,
hash
,
&
size
);
if
(
ret
)
{
CRYPT_HASH_BLOB
blob
=
{
sizeof
(
hash
),
hash
};
check
=
CertFindCertificateInStore
(
rootStore
,
cert
->
dwCertEncodingType
,
0
,
CERT_FIND_SHA1_HASH
,
&
blob
,
NULL
);
if
(
!
check
)
ret
=
FALSE
;
else
CertFreeCertificateContext
(
check
);
}
}
}
while
(
ret
&&
cert
);
if
(
cert
)
CertFreeCertificateContext
(
cert
);
CertCloseStore
(
rootStore
,
0
);
}
return
ret
;
}
BOOL
WINAPI
CertCreateCertificateChainEngine
(
PCERT_CHAIN_ENGINE_CONFIG
pConfig
,
HCERTCHAINENGINE
*
phChainEngine
)
{
static
const
WCHAR
caW
[]
=
{
'C'
,
'A'
,
0
};
static
const
WCHAR
myW
[]
=
{
'M'
,
'y'
,
0
};
static
const
WCHAR
trustW
[]
=
{
'T'
,
'r'
,
'u'
,
's'
,
't'
,
0
};
BOOL
ret
;
TRACE
(
"(%p, %p)
\n
"
,
pConfig
,
phChainEngine
);
if
(
pConfig
->
cbSize
!=
sizeof
(
*
pConfig
))
{
SetLastError
(
E_INVALIDARG
);
return
FALSE
;
}
*
phChainEngine
=
NULL
;
ret
=
CRYPT_CheckRestrictedRoot
(
pConfig
->
hRestrictedRoot
);
if
(
ret
)
{
PCertificateChainEngine
engine
=
CryptMemAlloc
(
sizeof
(
CertificateChainEngine
));
if
(
engine
)
{
HCERTSTORE
worldStores
[
4
];
engine
->
ref
=
1
;
if
(
pConfig
->
hRestrictedRoot
)
engine
->
hRoot
=
CertDuplicateStore
(
pConfig
->
hRestrictedRoot
);
else
engine
->
hRoot
=
CertOpenSystemStoreW
(
0
,
rootW
);
engine
->
hWorld
=
CertOpenStore
(
CERT_STORE_PROV_COLLECTION
,
0
,
0
,
CERT_STORE_CREATE_NEW_FLAG
,
NULL
);
worldStores
[
0
]
=
CertDuplicateStore
(
engine
->
hRoot
);
worldStores
[
1
]
=
CertOpenSystemStoreW
(
0
,
caW
);
worldStores
[
2
]
=
CertOpenSystemStoreW
(
0
,
myW
);
worldStores
[
3
]
=
CertOpenSystemStoreW
(
0
,
trustW
);
CRYPT_AddStoresToCollection
(
engine
->
hWorld
,
sizeof
(
worldStores
)
/
sizeof
(
worldStores
[
0
]),
worldStores
);
CRYPT_AddStoresToCollection
(
engine
->
hWorld
,
pConfig
->
cAdditionalStore
,
pConfig
->
rghAdditionalStore
);
CRYPT_CloseStores
(
sizeof
(
worldStores
)
/
sizeof
(
worldStores
[
0
]),
worldStores
);
engine
->
dwFlags
=
pConfig
->
dwFlags
;
engine
->
dwUrlRetrievalTimeout
=
pConfig
->
dwUrlRetrievalTimeout
;
engine
->
MaximumCachedCertificates
=
pConfig
->
MaximumCachedCertificates
;
engine
->
CycleDetectionModulus
=
pConfig
->
CycleDetectionModulus
;
*
phChainEngine
=
(
HCERTCHAINENGINE
)
engine
;
ret
=
TRUE
;
}
else
ret
=
FALSE
;
}
return
ret
;
}
void
WINAPI
CertFreeCertificateChainEngine
(
HCERTCHAINENGINE
hChainEngine
)
{
PCertificateChainEngine
engine
=
(
PCertificateChainEngine
)
hChainEngine
;
TRACE
(
"(%p)
\n
"
,
hChainEngine
);
if
(
InterlockedDecrement
(
&
engine
->
ref
)
==
0
)
{
CertCloseStore
(
engine
->
hWorld
,
0
);
CertCloseStore
(
engine
->
hRoot
,
0
);
CryptMemFree
(
engine
);
}
}
dlls/crypt32/crypt32.spec
View file @
b633d6a3
...
@@ -18,7 +18,7 @@
...
@@ -18,7 +18,7 @@
@ stdcall CertControlStore(long long long ptr)
@ stdcall CertControlStore(long long long ptr)
@ stdcall CertCreateCRLContext(long ptr long)
@ stdcall CertCreateCRLContext(long ptr long)
@ stdcall CertCreateCTLContext(long ptr long)
@ stdcall CertCreateCTLContext(long ptr long)
@ st
ub CertCreateCertificateChainEngine
@ st
dcall CertCreateCertificateChainEngine(ptr ptr)
@ stdcall CertCreateCertificateContext(long ptr long)
@ stdcall CertCreateCertificateContext(long ptr long)
@ stdcall CertCreateSelfSignCertificate(long ptr long ptr ptr ptr ptr ptr)
@ stdcall CertCreateSelfSignCertificate(long ptr long ptr ptr ptr ptr ptr)
@ stdcall CertDeleteCRLFromStore(ptr)
@ stdcall CertDeleteCRLFromStore(ptr)
...
@@ -45,7 +45,7 @@
...
@@ -45,7 +45,7 @@
@ stdcall CertFreeCRLContext(ptr)
@ stdcall CertFreeCRLContext(ptr)
@ stdcall CertFreeCTLContext(ptr)
@ stdcall CertFreeCTLContext(ptr)
@ stub CertFreeCertificateChain
@ stub CertFreeCertificateChain
@ st
ub CertFreeCertificateChainEngine
@ st
dcall CertFreeCertificateChainEngine(ptr)
@ stdcall CertFreeCertificateContext(ptr)
@ stdcall CertFreeCertificateContext(ptr)
@ stdcall CertGetCRLContextProperty(ptr long ptr ptr)
@ stdcall CertGetCRLContextProperty(ptr long ptr ptr)
@ stdcall CertGetCRLFromStore(ptr ptr ptr ptr)
@ stdcall CertGetCRLFromStore(ptr ptr ptr ptr)
...
...
dlls/crypt32/tests/Makefile.in
View file @
b633d6a3
...
@@ -8,6 +8,7 @@ IMPORTS = crypt32 advapi32 kernel32
...
@@ -8,6 +8,7 @@ IMPORTS = crypt32 advapi32 kernel32
CTESTS
=
\
CTESTS
=
\
base64.c
\
base64.c
\
cert.c
\
cert.c
\
chain.c
\
crl.c
\
crl.c
\
encode.c
\
encode.c
\
main.c
\
main.c
\
...
...
dlls/crypt32/tests/chain.c
0 → 100644
View file @
b633d6a3
/*
* crypt32 certificate chain functions tests
*
* Copyright 2006 Juan Lang
*
* 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 <assert.h>
#include <stdio.h>
#include <stdarg.h>
#include <windef.h>
#include <winbase.h>
#include <winerror.h>
#include <wincrypt.h>
#include "wine/test.h"
static
const
BYTE
selfSignedCert
[]
=
{
0x30
,
0x82
,
0x01
,
0x1f
,
0x30
,
0x81
,
0xce
,
0xa0
,
0x03
,
0x02
,
0x01
,
0x02
,
0x02
,
0x10
,
0xeb
,
0x0d
,
0x57
,
0x2a
,
0x9c
,
0x09
,
0xba
,
0xa4
,
0x4a
,
0xb7
,
0x25
,
0x49
,
0xd9
,
0x3e
,
0xb5
,
0x73
,
0x30
,
0x09
,
0x06
,
0x05
,
0x2b
,
0x0e
,
0x03
,
0x02
,
0x1d
,
0x05
,
0x00
,
0x30
,
0x15
,
0x31
,
0x13
,
0x30
,
0x11
,
0x06
,
0x03
,
0x55
,
0x04
,
0x03
,
0x13
,
0x0a
,
0x4a
,
0x75
,
0x61
,
0x6e
,
0x20
,
0x4c
,
0x61
,
0x6e
,
0x67
,
0x00
,
0x30
,
0x1e
,
0x17
,
0x0d
,
0x30
,
0x36
,
0x30
,
0x36
,
0x32
,
0x39
,
0x30
,
0x35
,
0x30
,
0x30
,
0x34
,
0x36
,
0x5a
,
0x17
,
0x0d
,
0x30
,
0x37
,
0x30
,
0x36
,
0x32
,
0x39
,
0x31
,
0x31
,
0x30
,
0x30
,
0x34
,
0x36
,
0x5a
,
0x30
,
0x15
,
0x31
,
0x13
,
0x30
,
0x11
,
0x06
,
0x03
,
0x55
,
0x04
,
0x03
,
0x13
,
0x0a
,
0x4a
,
0x75
,
0x61
,
0x6e
,
0x20
,
0x4c
,
0x61
,
0x6e
,
0x67
,
0x00
,
0x30
,
0x5c
,
0x30
,
0x0d
,
0x06
,
0x09
,
0x2a
,
0x86
,
0x48
,
0x86
,
0xf7
,
0x0d
,
0x01
,
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static
void
testCreateCertChainEngine
(
void
)
{
BOOL
ret
;
CERT_CHAIN_ENGINE_CONFIG
config
=
{
0
};
HCERTCHAINENGINE
engine
;
HCERTSTORE
store
;
/* Crash
ret = CertCreateCertificateChainEngine(NULL, NULL);
ret = CertCreateCertificateChainEngine(NULL, &engine);
*/
ret
=
CertCreateCertificateChainEngine
(
&
config
,
NULL
);
ok
(
!
ret
&&
GetLastError
()
==
E_INVALIDARG
,
"Expected E_INVALIDARG, got %08lx
\n
"
,
GetLastError
());
ret
=
CertCreateCertificateChainEngine
(
&
config
,
&
engine
);
ok
(
!
ret
&&
GetLastError
()
==
E_INVALIDARG
,
"Expected E_INVALIDARG, got %08lx
\n
"
,
GetLastError
());
/* Crashes
config.cbSize = sizeof(config);
ret = CertCreateCertificateChainEngine(&config, NULL);
*/
config
.
cbSize
=
sizeof
(
config
);
ret
=
CertCreateCertificateChainEngine
(
&
config
,
&
engine
);
ok
(
ret
,
"CertCreateCertificateChainEngine failed: %08lx
\n
"
,
GetLastError
());
CertFreeCertificateChainEngine
(
engine
);
config
.
dwFlags
=
0xff000000
;
ret
=
CertCreateCertificateChainEngine
(
&
config
,
&
engine
);
ok
(
ret
,
"CertCreateCertificateChainEngine failed: %08lx
\n
"
,
GetLastError
());
CertFreeCertificateChainEngine
(
engine
);
/* Creating a cert with no root certs at all is allowed.. */
store
=
CertOpenStore
(
CERT_STORE_PROV_MEMORY
,
0
,
0
,
CERT_STORE_CREATE_NEW_FLAG
,
NULL
);
config
.
hRestrictedRoot
=
store
;
ret
=
CertCreateCertificateChainEngine
(
&
config
,
&
engine
);
ok
(
ret
,
"CertCreateCertificateChainEngine failed: %08lx
\n
"
,
GetLastError
());
CertFreeCertificateChainEngine
(
engine
);
/* but creating one with a restricted root with a cert that isn't a member
* of the Root store isn't allowed.
*/
CertAddEncodedCertificateToStore
(
store
,
X509_ASN_ENCODING
,
selfSignedCert
,
sizeof
(
selfSignedCert
),
CERT_STORE_ADD_ALWAYS
,
NULL
);
ret
=
CertCreateCertificateChainEngine
(
&
config
,
&
engine
);
ok
(
!
ret
&&
GetLastError
()
==
CRYPT_E_NOT_FOUND
,
"Expected CRYPT_E_NOT_FOUND, got %08lx
\n
"
,
GetLastError
());
CertCloseStore
(
store
,
0
);
}
START_TEST
(
chain
)
{
testCreateCertChainEngine
();
}
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