bump product version to 4.1.6.2
[LibreOffice.git] / libxmlsec / src / akmngr_mscrypto.c
blobaf9eef4ecfb686c3c945a87815c5b8fbe5747e02
1 /**
2 * XMLSec library
4 * This is free software; see Copyright file in the source
5 * distribution for preciese wording.
7 * Copyright.........................
8 */
9 #include "globals.h"
11 #include <xmlsec/xmlsec.h>
12 #include <xmlsec/keys.h>
13 #include <xmlsec/keysmngr.h>
14 #include <xmlsec/transforms.h>
15 #include <xmlsec/errors.h>
17 #include <xmlsec/mscrypto/crypto.h>
18 #include <xmlsec/mscrypto/keysstore.h>
19 #include <xmlsec/mscrypto/akmngr.h>
20 #include <xmlsec/mscrypto/x509.h>
22 /**
23 * xmlSecMSCryptoAppliedKeysMngrCreate:
24 * @hKeyStore: the pointer to key store.
25 * @hCertStore: the pointer to certificate database.
27 * Create and load key store and certificate database into keys manager
29 * Returns keys manager pointer on success or NULL otherwise.
31 xmlSecKeysMngrPtr
32 xmlSecMSCryptoAppliedKeysMngrCreate(
33 HCERTSTORE hKeyStore ,
34 HCERTSTORE hCertStore
35 ) {
36 xmlSecKeyDataStorePtr certStore = NULL ;
37 xmlSecKeysMngrPtr keyMngr = NULL ;
38 xmlSecKeyStorePtr keyStore = NULL ;
40 keyStore = xmlSecKeyStoreCreate( xmlSecMSCryptoKeysStoreId ) ;
41 if( keyStore == NULL ) {
42 xmlSecError( XMLSEC_ERRORS_HERE ,
43 NULL ,
44 "xmlSecKeyStoreCreate" ,
45 XMLSEC_ERRORS_R_XMLSEC_FAILED ,
46 XMLSEC_ERRORS_NO_MESSAGE ) ;
47 return NULL ;
50 /*-
51 * At present, MS Crypto engine do not provide a way to setup a key store.
53 if( keyStore != NULL ) {
54 /*TODO: binding key store.*/
57 keyMngr = xmlSecKeysMngrCreate() ;
58 if( keyMngr == NULL ) {
59 xmlSecError( XMLSEC_ERRORS_HERE ,
60 NULL ,
61 "xmlSecKeysMngrCreate" ,
62 XMLSEC_ERRORS_R_XMLSEC_FAILED ,
63 XMLSEC_ERRORS_NO_MESSAGE ) ;
65 xmlSecKeyStoreDestroy( keyStore ) ;
66 return NULL ;
69 /*-
70 * Add key store to manager, from now on keys manager destroys the store if
71 * needed
73 if( xmlSecKeysMngrAdoptKeysStore( keyMngr, keyStore ) < 0 ) {
74 xmlSecError( XMLSEC_ERRORS_HERE ,
75 xmlSecErrorsSafeString( xmlSecKeyStoreGetName( keyStore ) ) ,
76 "xmlSecKeysMngrAdoptKeyStore" ,
77 XMLSEC_ERRORS_R_XMLSEC_FAILED ,
78 XMLSEC_ERRORS_NO_MESSAGE ) ;
80 xmlSecKeyStoreDestroy( keyStore ) ;
81 xmlSecKeysMngrDestroy( keyMngr ) ;
82 return NULL ;
85 /*-
86 * Initialize crypto library specific data in keys manager
88 if( xmlSecMSCryptoKeysMngrInit( keyMngr ) < 0 ) {
89 xmlSecError( XMLSEC_ERRORS_HERE ,
90 NULL ,
91 "xmlSecMSCryptoKeysMngrInit" ,
92 XMLSEC_ERRORS_R_XMLSEC_FAILED ,
93 XMLSEC_ERRORS_NO_MESSAGE ) ;
95 xmlSecKeysMngrDestroy( keyMngr ) ;
96 return NULL ;
99 /*-
100 * Set certificate databse to X509 key data store
103 * At present, MS Crypto engine do not provide a way to setup a cert store.
107 * Set the getKey callback
109 keyMngr->getKey = xmlSecKeysMngrGetKey ;
111 return keyMngr ;
115 xmlSecMSCryptoAppliedKeysMngrSymKeyLoad(
116 xmlSecKeysMngrPtr mngr ,
117 HCRYPTKEY symKey
119 /*TODO: import the key into keys manager.*/
120 return(0) ;
124 xmlSecMSCryptoAppliedKeysMngrPubKeyLoad(
125 xmlSecKeysMngrPtr mngr ,
126 HCRYPTKEY pubKey
128 /*TODO: import the key into keys manager.*/
129 return(0) ;
133 xmlSecMSCryptoAppliedKeysMngrPriKeyLoad(
134 xmlSecKeysMngrPtr mngr ,
135 HCRYPTKEY priKey
137 /*TODO: import the key into keys manager.*/
138 return(0) ;
142 xmlSecMSCryptoAppliedKeysMngrAdoptKeyStore (
143 xmlSecKeysMngrPtr mngr ,
144 HCERTSTORE keyStore
146 xmlSecKeyDataStorePtr x509Store ;
148 xmlSecAssert2( mngr != NULL, -1 ) ;
149 xmlSecAssert2( keyStore != NULL, -1 ) ;
151 x509Store = xmlSecKeysMngrGetDataStore( mngr, xmlSecMSCryptoX509StoreId ) ;
152 if( x509Store == NULL ) {
153 xmlSecError( XMLSEC_ERRORS_HERE ,
154 NULL ,
155 "xmlSecKeysMngrGetDataStore" ,
156 XMLSEC_ERRORS_R_XMLSEC_FAILED ,
157 XMLSEC_ERRORS_NO_MESSAGE ) ;
158 return( -1 ) ;
161 if( xmlSecMSCryptoX509StoreAdoptKeyStore( x509Store, keyStore ) < 0 ) {
162 xmlSecError( XMLSEC_ERRORS_HERE ,
163 xmlSecErrorsSafeString( xmlSecKeyDataStoreGetName( x509Store ) ) ,
164 "xmlSecMSCryptoX509StoreAdoptKeyStore" ,
165 XMLSEC_ERRORS_R_XMLSEC_FAILED ,
166 XMLSEC_ERRORS_NO_MESSAGE ) ;
167 return( -1 ) ;
170 return( 0 ) ;
174 xmlSecMSCryptoAppliedKeysMngrAdoptTrustedStore (
175 xmlSecKeysMngrPtr mngr ,
176 HCERTSTORE trustedStore
178 xmlSecKeyDataStorePtr x509Store ;
180 xmlSecAssert2( mngr != NULL, -1 ) ;
181 xmlSecAssert2( trustedStore != NULL, -1 ) ;
183 x509Store = xmlSecKeysMngrGetDataStore( mngr, xmlSecMSCryptoX509StoreId ) ;
184 if( x509Store == NULL ) {
185 xmlSecError( XMLSEC_ERRORS_HERE ,
186 NULL ,
187 "xmlSecKeysMngrGetDataStore" ,
188 XMLSEC_ERRORS_R_XMLSEC_FAILED ,
189 XMLSEC_ERRORS_NO_MESSAGE ) ;
190 return( -1 ) ;
193 if( xmlSecMSCryptoX509StoreAdoptTrustedStore( x509Store, trustedStore ) < 0 ) {
194 xmlSecError( XMLSEC_ERRORS_HERE ,
195 xmlSecErrorsSafeString( xmlSecKeyDataStoreGetName( x509Store ) ) ,
196 "xmlSecMSCryptoX509StoreAdoptKeyStore" ,
197 XMLSEC_ERRORS_R_XMLSEC_FAILED ,
198 XMLSEC_ERRORS_NO_MESSAGE ) ;
199 return( -1 ) ;
202 return( 0 ) ;
206 xmlSecMSCryptoAppliedKeysMngrAdoptUntrustedStore (
207 xmlSecKeysMngrPtr mngr ,
208 HCERTSTORE untrustedStore
210 xmlSecKeyDataStorePtr x509Store ;
212 xmlSecAssert2( mngr != NULL, -1 ) ;
213 xmlSecAssert2( untrustedStore != NULL, -1 ) ;
215 x509Store = xmlSecKeysMngrGetDataStore( mngr, xmlSecMSCryptoX509StoreId ) ;
216 if( x509Store == NULL ) {
217 xmlSecError( XMLSEC_ERRORS_HERE ,
218 NULL ,
219 "xmlSecKeysMngrGetDataStore" ,
220 XMLSEC_ERRORS_R_XMLSEC_FAILED ,
221 XMLSEC_ERRORS_NO_MESSAGE ) ;
222 return( -1 ) ;
225 if( xmlSecMSCryptoX509StoreAdoptUntrustedStore( x509Store, untrustedStore ) < 0 ) {
226 xmlSecError( XMLSEC_ERRORS_HERE ,
227 xmlSecErrorsSafeString( xmlSecKeyDataStoreGetName( x509Store ) ) ,
228 "xmlSecMSCryptoX509StoreAdoptKeyStore" ,
229 XMLSEC_ERRORS_R_XMLSEC_FAILED ,
230 XMLSEC_ERRORS_NO_MESSAGE ) ;
231 return( -1 ) ;
234 return( 0 ) ;