Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
onlyoffice_core
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boris Kocherov
onlyoffice_core
Commits
1d003863
Commit
1d003863
authored
Apr 17, 2017
by
Oleg Korshul
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
d356a305
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
279 additions
and
295 deletions
+279
-295
DesktopEditor/xmlsec/test/windows_list_serts/main.cpp
DesktopEditor/xmlsec/test/windows_list_serts/main.cpp
+279
-295
No files found.
DesktopEditor/xmlsec/test/windows_list_serts/main.cpp
View file @
1d003863
...
...
@@ -23,125 +23,122 @@ bool Verify(HCERTSTORE hStoreHandle, PCCERT_CONTEXT pCertContext, std::wstring s
void
main
(
void
)
{
//-------------------------------------------------------------------
// Copyright (C) Microsoft. All rights reserved.
// This program lists all of the certificates in a system certificate
// store and all of the property identifier numbers of those
// certificates. It also demonstrates the use of two
// UI functions. One, CryptUIDlgSelectCertificateFromStore,
// displays the certificates in a store
// and allows the user to select one of them,
// The other, CryptUIDlgViewContext,
// displays the contents of a single certificate.
//-------------------------------------------------------------------
// Declare and initialize variables.
HCERTSTORE
hCertStore
;
PCCERT_CONTEXT
pCertContext
=
NULL
;
char
pszNameString
[
256
];
char
pszStoreName
[
256
];
void
*
pvData
;
DWORD
cbData
;
DWORD
dwPropId
=
0
;
//-------------------------------------------------------------------
// Copyright (C) Microsoft. All rights reserved.
// This program lists all of the certificates in a system certificate
// store and all of the property identifier numbers of those
// certificates. It also demonstrates the use of two
// UI functions. One, CryptUIDlgSelectCertificateFromStore,
// displays the certificates in a store
// and allows the user to select one of them,
// The other, CryptUIDlgViewContext,
// displays the contents of a single certificate.
//-------------------------------------------------------------------
// Declare and initialize variables.
HCERTSTORE
hCertStore
;
PCCERT_CONTEXT
pCertContext
=
NULL
;
char
pszNameString
[
256
];
char
pszStoreName
[
256
];
void
*
pvData
;
DWORD
cbData
;
DWORD
dwPropId
=
0
;
// Zero must be used on the first
// call to the function. After that,
// the last returned property identifier is passed.
//-------------------------------------------------------------------
// Begin processing and Get the name of the system certificate store
// to be enumerated. Output here is to stderr so that the program
// can be run from the command line and stdout can be redirected
// to a file.
/*
fprintf(stderr,"Please enter the store name:");
gets_s(pszStoreName, sizeof(pszStoreName));
fprintf(stderr,"The store name is %s.\n",pszStoreName);
*/
pszStoreName
[
0
]
=
'M'
;
pszStoreName
[
1
]
=
'Y'
;
pszStoreName
[
2
]
=
'\0'
;
//-------------------------------------------------------------------
// Open a system certificate store.
if
(
hCertStore
=
CertOpenSystemStore
(
NULL
,
pszStoreName
))
{
fprintf
(
stderr
,
"The %s store has been opened.
\n
"
,
pszStoreName
);
}
else
{
// If the store was not opened, exit to an error routine.
//-------------------------------------------------------------------
// Begin processing and Get the name of the system certificate store
// to be enumerated. Output here is to stderr so that the program
// can be run from the command line and stdout can be redirected
// to a file.
/*
fprintf(stderr,"Please enter the store name:");
gets_s(pszStoreName, sizeof(pszStoreName));
fprintf(stderr,"The store name is %s.\n",pszStoreName);
*/
pszStoreName
[
0
]
=
'M'
;
pszStoreName
[
1
]
=
'Y'
;
pszStoreName
[
2
]
=
'\0'
;
//-------------------------------------------------------------------
// Open a system certificate store.
if
(
hCertStore
=
CertOpenSystemStore
(
NULL
,
pszStoreName
))
{
fprintf
(
stderr
,
"The %s store has been opened.
\n
"
,
pszStoreName
);
}
else
{
// If the store was not opened, exit to an error routine.
MyHandleError
(
"The store was not opened."
);
}
}
//-------------------------------------------------------------------
// Use CertEnumCertificatesInStore to get the certificates
// from the open store. pCertContext must be reset to
// NULL to retrieve the first certificate in the store.
//-------------------------------------------------------------------
// Use CertEnumCertificatesInStore to get the certificates
// from the open store. pCertContext must be reset to
// NULL to retrieve the first certificate in the store.
// pCertContext = NULL;
// pCertContext = NULL;
#ifdef ENUMS_CERTS
while
(
pCertContext
=
CertEnumCertificatesInStore
(
while
(
pCertContext
=
CertEnumCertificatesInStore
(
hCertStore
,
pCertContext
))
{
//-------------------------------------------------------------------
// A certificate was retrieved. Continue.
//-------------------------------------------------------------------
// Display the certificate.
{
//-------------------------------------------------------------------
// A certificate was retrieved. Continue.
//-------------------------------------------------------------------
// Display the certificate.
if
(
CryptUIDlgViewContext
(
if
(
CryptUIDlgViewContext
(
CERT_STORE_CERTIFICATE_CONTEXT
,
pCertContext
,
NULL
,
NULL
,
0
,
NULL
))
{
// printf("OK\n");
}
else
{
{
// printf("OK\n");
}
else
{
MyHandleError
(
"UI failed."
);
}
}
if
(
CertGetNameString
(
if
(
CertGetNameString
(
pCertContext
,
CERT_NAME_SIMPLE_DISPLAY_TYPE
,
0
,
NULL
,
pszNameString
,
128
))
{
{
printf
(
"
\n
Certificate for %s
\n
"
,
pszNameString
);
}
else
}
else
fprintf
(
stderr
,
"CertGetName failed.
\n
"
);
//-------------------------------------------------------------------
// Loop to find all of the property identifiers for the specified
// certificate. The loop continues until
// CertEnumCertificateContextProperties returns zero.
//-------------------------------------------------------------------
// Loop to find all of the property identifiers for the specified
// certificate. The loop continues until
// CertEnumCertificateContextProperties returns zero.
while
(
dwPropId
=
CertEnumCertificateContextProperties
(
while
(
dwPropId
=
CertEnumCertificateContextProperties
(
pCertContext
,
// The context whose properties are to be listed.
dwPropId
))
// Number of the last property found.
// This must be zero to find the first
// property identifier.
{
//-------------------------------------------------------------------
// When the loop is executed, a property identifier has been found.
// Print the property number.
{
//-------------------------------------------------------------------
// When the loop is executed, a property identifier has been found.
// Print the property number.
printf
(
"Property # %d found->"
,
dwPropId
);
//-------------------------------------------------------------------
// Indicate the kind of property found.
//-------------------------------------------------------------------
// Indicate the kind of property found.
switch
(
dwPropId
)
{
...
...
@@ -242,10 +239,10 @@ while(dwPropId = CertEnumCertificateContextProperties(
}
}
// End switch.
//-------------------------------------------------------------------
// Retrieve information on the property by first getting the
// property size.
// For more information, see CertGetCertificateContextProperty.
//-------------------------------------------------------------------
// Retrieve information on the property by first getting the
// property size.
// For more information, see CertGetCertificateContextProperty.
if
(
CertGetCertificateContextProperty
(
pCertContext
,
...
...
@@ -261,9 +258,9 @@ while(dwPropId = CertEnumCertificateContextProperties(
// exit to an error routine.
MyHandleError
(
"Call #1 to GetCertContextProperty failed."
);
}
//-------------------------------------------------------------------
// The call succeeded. Use the size to allocate memory
// for the property.
//-------------------------------------------------------------------
// The call succeeded. Use the size to allocate memory
// for the property.
if
(
pvData
=
(
void
*
)
malloc
(
cbData
))
{
...
...
@@ -301,41 +298,28 @@ while(dwPropId = CertEnumCertificateContextProperties(
free
(
pvData
);
}
// End inner while.
}
// End outer while.
}
// End outer while.
#endif
//-------------------------------------------------------------------
// Select a new certificate by using the user interface.
//-------------------------------------------------------------------
// Select a new certificate by using the user interface.
if
(
!
(
pCertContext
=
CryptUIDlgSelectCertificateFromStore
(
hCertStore
,
NULL
,
NULL
,
NULL
,
CRYPTUI_SELECT_LOCATION_COLUMN
,
0
,
NULL
)))
{
if
(
!
(
pCertContext
=
CryptUIDlgSelectCertificateFromStore
(
hCertStore
,
NULL
,
NULL
,
NULL
,
CRYPTUI_SELECT_LOCATION_COLUMN
,
0
,
NULL
)))
{
MyHandleError
(
"Select UI failed."
);
}
//-------------------------------------------------------------------
// Clean up.
/////
bool
bRes
=
true
;
bRes
=
Sign
(
hCertStore
,
pCertContext
,
NSFile
::
GetProcessDirectory
()
+
L"/document.xml"
,
NSFile
::
GetProcessDirectory
()
+
L"/result.txt"
);
bRes
=
Verify
(
hCertStore
,
pCertContext
,
NSFile
::
GetProcessDirectory
()
+
L"/document.xml"
,
NSFile
::
GetProcessDirectory
()
+
L"/result.txt"
);
///
}
CertFreeCertificateContext
(
pCertContext
);
CertCloseStore
(
hCertStore
,
0
);
printf
(
"The function completed successfully.
\n
"
);
}
// End of main.
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
bool
bRes
=
true
;
bRes
=
Sign
(
hCertStore
,
pCertContext
,
NSFile
::
GetProcessDirectory
()
+
L"/document.xml"
,
NSFile
::
GetProcessDirectory
()
+
L"/result.txt"
);
bRes
=
Verify
(
hCertStore
,
pCertContext
,
NSFile
::
GetProcessDirectory
()
+
L"/document.xml"
,
NSFile
::
GetProcessDirectory
()
+
L"/result.txt"
);
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
CertFreeCertificateContext
(
pCertContext
);
CertCloseStore
(
hCertStore
,
0
);
printf
(
"The function completed successfully.
\n
"
);
}
void
MyHandleError
(
LPTSTR
psz
)
{
...
...
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