25#include <xmlsec/xmlsec.h>
26#include <xmlsec/keys.h>
27#include <xmlsec/keysmngr.h>
28#include <xmlsec/transforms.h>
29#include <xmlsec/errors.h>
31#include <xmlsec/mscng/crypto.h>
32#include <xmlsec/mscng/keysstore.h>
33#include <xmlsec/mscng/x509.h>
48 xmlSecKeysMngrPtr keyMngr = nullptr ;
49 xmlSecKeyStorePtr keyStore = nullptr ;
51 keyStore = xmlSecKeyStoreCreate(xmlSecMSCngKeysStoreId);
52 if (keyStore ==
nullptr)
54 xmlSecError(XMLSEC_ERRORS_HERE,
56 "xmlSecKeyStoreCreate",
57 XMLSEC_ERRORS_R_XMLSEC_FAILED,
58 XMLSEC_ERRORS_NO_MESSAGE) ;
62 keyMngr = xmlSecKeysMngrCreate() ;
63 if (keyMngr ==
nullptr)
65 xmlSecError(XMLSEC_ERRORS_HERE,
67 "xmlSecKeysMngrCreate",
68 XMLSEC_ERRORS_R_XMLSEC_FAILED,
69 XMLSEC_ERRORS_NO_MESSAGE) ;
71 xmlSecKeyStoreDestroy(keyStore) ;
79 if (xmlSecKeysMngrAdoptKeysStore(keyMngr, keyStore) < 0)
81 xmlSecError(XMLSEC_ERRORS_HERE,
82 xmlSecErrorsSafeString(xmlSecKeyStoreGetName(keyStore)),
83 "xmlSecKeysMngrAdoptKeyStore",
84 XMLSEC_ERRORS_R_XMLSEC_FAILED,
85 XMLSEC_ERRORS_NO_MESSAGE) ;
87 xmlSecKeyStoreDestroy(keyStore) ;
88 xmlSecKeysMngrDestroy(keyMngr) ;
95 if (xmlSecMSCngKeysMngrInit(keyMngr) < 0)
97 xmlSecError(XMLSEC_ERRORS_HERE,
99 "xmlSecMSCngKeysMngrInit",
100 XMLSEC_ERRORS_R_XMLSEC_FAILED,
101 XMLSEC_ERRORS_NO_MESSAGE);
103 xmlSecKeysMngrDestroy(keyMngr);
117 keyMngr->getKey = xmlSecKeysMngrGetKey ;
124 xmlSecKeysMngrPtr mngr,
128 xmlSecKeyDataStorePtr x509Store ;
130 xmlSecAssert2(mngr !=
nullptr, -1) ;
131 xmlSecAssert2(keyStore !=
nullptr, -1) ;
133 x509Store = xmlSecKeysMngrGetDataStore(mngr, xmlSecMSCngX509StoreId);
134 if (x509Store ==
nullptr)
136 xmlSecError(XMLSEC_ERRORS_HERE,
138 "xmlSecKeysMngrGetDataStore",
139 XMLSEC_ERRORS_R_XMLSEC_FAILED,
140 XMLSEC_ERRORS_NO_MESSAGE) ;
144 if (xmlSecMSCngX509StoreAdoptKeyStore(x509Store, keyStore) < 0)
146 xmlSecError(XMLSEC_ERRORS_HERE,
147 xmlSecErrorsSafeString(xmlSecKeyDataStoreGetName(x509Store)),
148 "xmlSecMSCngX509StoreAdoptKeyStore",
149 XMLSEC_ERRORS_R_XMLSEC_FAILED,
150 XMLSEC_ERRORS_NO_MESSAGE);
159 xmlSecKeysMngrPtr mngr,
160 HCERTSTORE trustedStore
163 xmlSecKeyDataStorePtr x509Store ;
165 xmlSecAssert2(mngr !=
nullptr, -1) ;
166 xmlSecAssert2(trustedStore !=
nullptr, -1) ;
168 x509Store = xmlSecKeysMngrGetDataStore(mngr, xmlSecMSCngX509StoreId);
169 if (x509Store ==
nullptr)
171 xmlSecError(XMLSEC_ERRORS_HERE,
173 "xmlSecKeysMngrGetDataStore",
174 XMLSEC_ERRORS_R_XMLSEC_FAILED,
175 XMLSEC_ERRORS_NO_MESSAGE) ;
179 if (xmlSecMSCngX509StoreAdoptTrustedStore(x509Store, trustedStore) < 0)
181 xmlSecError(XMLSEC_ERRORS_HERE,
182 xmlSecErrorsSafeString(xmlSecKeyDataStoreGetName(x509Store)),
183 "xmlSecMSCngX509StoreAdoptKeyStore",
184 XMLSEC_ERRORS_R_XMLSEC_FAILED,
185 XMLSEC_ERRORS_NO_MESSAGE);
194 xmlSecKeysMngrPtr mngr,
195 HCERTSTORE untrustedStore
198 xmlSecKeyDataStorePtr x509Store ;
200 xmlSecAssert2(mngr !=
nullptr, -1) ;
201 xmlSecAssert2(untrustedStore !=
nullptr, -1) ;
203 x509Store = xmlSecKeysMngrGetDataStore(mngr, xmlSecMSCngX509StoreId);
204 if (x509Store ==
nullptr)
206 xmlSecError(XMLSEC_ERRORS_HERE,
208 "xmlSecKeysMngrGetDataStore",
209 XMLSEC_ERRORS_R_XMLSEC_FAILED,
210 XMLSEC_ERRORS_NO_MESSAGE) ;
214 if (xmlSecMSCngX509StoreAdoptUntrustedStore(x509Store, untrustedStore) < 0)
216 xmlSecError(XMLSEC_ERRORS_HERE,
217 xmlSecErrorsSafeString(xmlSecKeyDataStoreGetName(x509Store)),
218 "xmlSecMSCngX509StoreAdoptKeyStore",
219 XMLSEC_ERRORS_R_XMLSEC_FAILED,
220 XMLSEC_ERRORS_NO_MESSAGE);
xmlSecKeysMngrPtr MSCryptoAppliedKeysMngrCreate()
MSCryptoAppliedKeysMngrCreate:
int MSCryptoAppliedKeysMngrAdoptKeyStore(xmlSecKeysMngrPtr mngr, HCERTSTORE keyStore)
int MSCryptoAppliedKeysMngrAdoptUntrustedStore(xmlSecKeysMngrPtr mngr, HCERTSTORE untrustedStore)
int MSCryptoAppliedKeysMngrAdoptTrustedStore(xmlSecKeysMngrPtr mngr, HCERTSTORE trustedStore)