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
5701a0f0
Commit
5701a0f0
authored
Jul 07, 2005
by
Juan Lang
Committed by
Alexandre Julliard
Jul 07, 2005
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement a few utility functions, with tests.
parent
47fbe042
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
244 additions
and
4 deletions
+244
-4
cert.c
dlls/crypt32/cert.c
+89
-0
crypt32.spec
dlls/crypt32/crypt32.spec
+4
-4
main.c
dlls/crypt32/tests/main.c
+151
-0
No files found.
dlls/crypt32/cert.c
View file @
5701a0f0
...
...
@@ -178,3 +178,92 @@ PCCERT_CONTEXT WINAPI CertFindCertificateInStore(HCERTSTORE hCertStore,
SetLastError
(
CRYPT_E_NOT_FOUND
);
return
NULL
;
}
PCRYPT_ATTRIBUTE
WINAPI
CertFindAttribute
(
LPCSTR
pszObjId
,
DWORD
cAttr
,
CRYPT_ATTRIBUTE
rgAttr
[])
{
PCRYPT_ATTRIBUTE
ret
=
NULL
;
DWORD
i
;
TRACE
(
"%s %ld %p
\n
"
,
debugstr_a
(
pszObjId
),
cAttr
,
rgAttr
);
if
(
!
cAttr
)
return
NULL
;
if
(
!
pszObjId
)
{
SetLastError
(
ERROR_INVALID_PARAMETER
);
return
NULL
;
}
for
(
i
=
0
;
!
ret
&&
i
<
cAttr
;
i
++
)
if
(
rgAttr
[
i
].
pszObjId
&&
!
strcmp
(
pszObjId
,
rgAttr
[
i
].
pszObjId
))
ret
=
&
rgAttr
[
i
];
return
ret
;
}
PCERT_EXTENSION
WINAPI
CertFindExtension
(
LPCSTR
pszObjId
,
DWORD
cExtensions
,
CERT_EXTENSION
rgExtensions
[])
{
PCERT_EXTENSION
ret
=
NULL
;
DWORD
i
;
TRACE
(
"%s %ld %p
\n
"
,
debugstr_a
(
pszObjId
),
cExtensions
,
rgExtensions
);
if
(
!
cExtensions
)
return
NULL
;
if
(
!
pszObjId
)
{
SetLastError
(
ERROR_INVALID_PARAMETER
);
return
NULL
;
}
for
(
i
=
0
;
!
ret
&&
i
<
cExtensions
;
i
++
)
if
(
rgExtensions
[
i
].
pszObjId
&&
!
strcmp
(
pszObjId
,
rgExtensions
[
i
].
pszObjId
))
ret
=
&
rgExtensions
[
i
];
return
ret
;
}
PCERT_RDN_ATTR
WINAPI
CertFindRDNAttr
(
LPCSTR
pszObjId
,
PCERT_NAME_INFO
pName
)
{
PCERT_RDN_ATTR
ret
=
NULL
;
DWORD
i
,
j
;
TRACE
(
"%s %p
\n
"
,
debugstr_a
(
pszObjId
),
pName
);
if
(
!
pszObjId
)
{
SetLastError
(
ERROR_INVALID_PARAMETER
);
return
NULL
;
}
for
(
i
=
0
;
!
ret
&&
i
<
pName
->
cRDN
;
i
++
)
for
(
j
=
0
;
!
ret
&&
j
<
pName
->
rgRDN
[
i
].
cRDNAttr
;
j
++
)
if
(
pName
->
rgRDN
[
i
].
rgRDNAttr
[
j
].
pszObjId
&&
!
strcmp
(
pszObjId
,
pName
->
rgRDN
[
i
].
rgRDNAttr
[
j
].
pszObjId
))
ret
=
&
pName
->
rgRDN
[
i
].
rgRDNAttr
[
j
];
return
ret
;
}
LONG
WINAPI
CertVerifyTimeValidity
(
LPFILETIME
pTimeToVerify
,
PCERT_INFO
pCertInfo
)
{
FILETIME
fileTime
;
LONG
ret
;
if
(
!
pTimeToVerify
)
{
SYSTEMTIME
sysTime
;
GetSystemTime
(
&
sysTime
);
SystemTimeToFileTime
(
&
sysTime
,
&
fileTime
);
pTimeToVerify
=
&
fileTime
;
}
if
((
ret
=
CompareFileTime
(
pTimeToVerify
,
&
pCertInfo
->
NotBefore
))
>=
0
)
{
ret
=
CompareFileTime
(
pTimeToVerify
,
&
pCertInfo
->
NotAfter
);
if
(
ret
<
0
)
ret
=
0
;
}
return
ret
;
}
dlls/crypt32/crypt32.spec
View file @
5701a0f0
...
...
@@ -32,11 +32,11 @@
@ stub CertEnumCTLsInStore
@ stub CertEnumCertificateContextProperties
@ stdcall CertEnumCertificatesInStore(long ptr)
@ st
ub CertFindAttribute
@ st
dcall CertFindAttribute(str long ptr)
@ stub CertFindCTLInStore
@ stdcall CertFindCertificateInStore(long long long long ptr ptr)
@ st
ub CertFindExtension
@ st
ub CertFindRDNAttr
@ st
dcall CertFindExtension(str long ptr)
@ st
dcall CertFindRDNAttr(str ptr)
@ stub CertFindSubjectInCTL
@ stdcall CertFreeCRLContext(ptr)
@ stub CertFreeCTLContext
...
...
@@ -78,7 +78,7 @@
@ stub CertVerifyCTLUsage
@ stub CertVerifyRevocation
@ stub CertVerifySubjectCertificateContext
@ st
ub CertVerifyTimeValidity
@ st
dcall CertVerifyTimeValidity(ptr ptr)
@ stub CertVerifyValidityNesting
@ stub CreateFileU
@ stub CryptAcquireContextU
...
...
dlls/crypt32/tests/main.c
View file @
5701a0f0
...
...
@@ -113,8 +113,159 @@ static void testAlgIDToOID(void)
}
}
static
void
test_findAttribute
(
void
)
{
PCRYPT_ATTRIBUTE
ret
;
CRYPT_ATTR_BLOB
blobs
[]
=
{
{
3
,
"
\x02\x01\x01
"
},
};
CRYPT_ATTRIBUTE
attr
=
{
"1.2.3"
,
sizeof
(
blobs
)
/
sizeof
(
blobs
[
0
]),
blobs
};
/* returns NULL, last error not set */
SetLastError
(
0xdeadbeef
);
ret
=
CertFindAttribute
(
NULL
,
0
,
NULL
);
ok
(
ret
==
NULL
,
"Expected failure
\n
"
);
ok
(
GetLastError
()
==
0xdeadbeef
,
"Last error was set to %08lx
\n
"
,
GetLastError
());
/* crashes
SetLastError(0xdeadbeef);
ret = CertFindAttribute(NULL, 1, NULL);
*/
/* returns NULL, last error is ERROR_INVALID_PARAMETER */
SetLastError
(
0xdeadbeef
);
ret
=
CertFindAttribute
(
NULL
,
1
,
&
attr
);
ok
(
!
ret
&&
GetLastError
()
==
ERROR_INVALID_PARAMETER
,
"Expected ERROR_INVALID_PARAMETER, got %ld (%08lx)
\n
"
,
GetLastError
(),
GetLastError
());
/* returns NULL, last error not set */
SetLastError
(
0xdeadbeef
);
ret
=
CertFindAttribute
(
"bogus"
,
1
,
&
attr
);
ok
(
ret
==
NULL
,
"Expected failure
\n
"
);
ok
(
GetLastError
()
==
0xdeadbeef
,
"Last error was set to %08lx
\n
"
,
GetLastError
());
/* returns NULL, last error not set */
SetLastError
(
0xdeadbeef
);
ret
=
CertFindAttribute
(
"1.2.4"
,
1
,
&
attr
);
ok
(
ret
==
NULL
,
"Expected failure
\n
"
);
ok
(
GetLastError
()
==
0xdeadbeef
,
"Last error was set to %08lx
\n
"
,
GetLastError
());
/* succeeds, last error not set */
SetLastError
(
0xdeadbeef
);
ret
=
CertFindAttribute
(
"1.2.3"
,
1
,
&
attr
);
ok
(
ret
!=
NULL
,
"CertFindAttribute failed: %08lx
\n
"
,
GetLastError
());
}
static
void
test_findExtension
(
void
)
{
PCERT_EXTENSION
ret
;
CERT_EXTENSION
ext
=
{
"1.2.3"
,
TRUE
,
{
3
,
"
\x02\x01\x01
"
}
};
/* returns NULL, last error not set */
SetLastError
(
0xdeadbeef
);
ret
=
CertFindExtension
(
NULL
,
0
,
NULL
);
ok
(
ret
==
NULL
,
"Expected failure
\n
"
);
ok
(
GetLastError
()
==
0xdeadbeef
,
"Last error was set to %08lx
\n
"
,
GetLastError
());
/* crashes
SetLastError(0xdeadbeef);
ret = CertFindExtension(NULL, 1, NULL);
*/
/* returns NULL, last error is ERROR_INVALID_PARAMETER */
SetLastError
(
0xdeadbeef
);
ret
=
CertFindExtension
(
NULL
,
1
,
&
ext
);
ok
(
!
ret
&&
GetLastError
()
==
ERROR_INVALID_PARAMETER
,
"Expected ERROR_INVALID_PARAMETER, got %ld (%08lx)
\n
"
,
GetLastError
(),
GetLastError
());
/* returns NULL, last error not set */
SetLastError
(
0xdeadbeef
);
ret
=
CertFindExtension
(
"bogus"
,
1
,
&
ext
);
ok
(
ret
==
NULL
,
"Expected failure
\n
"
);
ok
(
GetLastError
()
==
0xdeadbeef
,
"Last error was set to %08lx
\n
"
,
GetLastError
());
/* returns NULL, last error not set */
SetLastError
(
0xdeadbeef
);
ret
=
CertFindExtension
(
"1.2.4"
,
1
,
&
ext
);
ok
(
ret
==
NULL
,
"Expected failure
\n
"
);
ok
(
GetLastError
()
==
0xdeadbeef
,
"Last error was set to %08lx
\n
"
,
GetLastError
());
/* succeeds, last error not set */
SetLastError
(
0xdeadbeef
);
ret
=
CertFindExtension
(
"1.2.3"
,
1
,
&
ext
);
ok
(
ret
!=
NULL
,
"CertFindExtension failed: %08lx
\n
"
,
GetLastError
());
}
static
void
test_findRDNAttr
(
void
)
{
PCERT_RDN_ATTR
ret
;
CERT_RDN_ATTR
attrs
[]
=
{
{
"1.2.3"
,
CERT_RDN_IA5_STRING
,
{
11
,
"
\x16\x09
Juan Lang"
}
},
};
CERT_RDN
rdns
[]
=
{
{
sizeof
(
attrs
)
/
sizeof
(
attrs
[
0
]),
attrs
},
};
CERT_NAME_INFO
nameInfo
=
{
sizeof
(
rdns
)
/
sizeof
(
rdns
[
0
]),
rdns
};
/* crashes
SetLastError(0xdeadbeef);
ret = CertFindRDNAttr(NULL, NULL);
*/
/* returns NULL, last error is ERROR_INVALID_PARAMETER */
SetLastError
(
0xdeadbeef
);
ret
=
CertFindRDNAttr
(
NULL
,
&
nameInfo
);
ok
(
!
ret
&&
GetLastError
()
==
ERROR_INVALID_PARAMETER
,
"Expected ERROR_INVALID_PARAMETER, got %ld (%08lx)
\n
"
,
GetLastError
(),
GetLastError
());
/* returns NULL, last error not set */
SetLastError
(
0xdeadbeef
);
ret
=
CertFindRDNAttr
(
"bogus"
,
&
nameInfo
);
ok
(
ret
==
NULL
,
"Expected failure
\n
"
);
ok
(
GetLastError
()
==
0xdeadbeef
,
"Last error was set to %08lx
\n
"
,
GetLastError
());
/* returns NULL, last error not set */
SetLastError
(
0xdeadbeef
);
ret
=
CertFindRDNAttr
(
"1.2.4"
,
&
nameInfo
);
ok
(
ret
==
NULL
,
"Expected failure
\n
"
);
ok
(
GetLastError
()
==
0xdeadbeef
,
"Last error was set to %08lx
\n
"
,
GetLastError
());
/* succeeds, last error not set */
SetLastError
(
0xdeadbeef
);
ret
=
CertFindRDNAttr
(
"1.2.3"
,
&
nameInfo
);
ok
(
ret
!=
NULL
,
"CertFindRDNAttr failed: %08lx
\n
"
,
GetLastError
());
}
static
void
test_verifyTimeValidity
(
void
)
{
SYSTEMTIME
sysTime
;
FILETIME
fileTime
;
CERT_INFO
info
=
{
0
};
LONG
ret
;
GetSystemTime
(
&
sysTime
);
SystemTimeToFileTime
(
&
sysTime
,
&
fileTime
);
/* crashes
ret = CertVerifyTimeValidity(NULL, NULL);
ret = CertVerifyTimeValidity(&fileTime, NULL);
*/
/* Check with 0 NotBefore and NotAfter */
ret
=
CertVerifyTimeValidity
(
&
fileTime
,
&
info
);
ok
(
ret
==
1
,
"Expected 1, got %ld
\n
"
,
ret
);
memcpy
(
&
info
.
NotAfter
,
&
fileTime
,
sizeof
(
info
.
NotAfter
));
/* Check with NotAfter equal to comparison time */
ret
=
CertVerifyTimeValidity
(
&
fileTime
,
&
info
);
ok
(
ret
==
0
,
"Expected 0, got %ld
\n
"
,
ret
);
/* Check with NotBefore after comparison time */
memcpy
(
&
info
.
NotBefore
,
&
fileTime
,
sizeof
(
info
.
NotBefore
));
info
.
NotBefore
.
dwLowDateTime
+=
5000
;
ret
=
CertVerifyTimeValidity
(
&
fileTime
,
&
info
);
ok
(
ret
==
-
1
,
"Expected -1, got %ld
\n
"
,
ret
);
}
START_TEST
(
main
)
{
testOIDToAlgID
();
testAlgIDToOID
();
test_findAttribute
();
test_findExtension
();
test_findRDNAttr
();
test_verifyTimeValidity
();
}
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