00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071 #ifndef DSIGCONSTANTS_HEADER
00072 #define DSIGCONSTANTS_HEADER
00073
00074 #include <xsec/utils/XSECSafeBuffer.hpp>
00075
00076
00077 #include <xercesc/util/XMLString.hpp>
00078
00079 XSEC_USING_XERCES(XMLString);
00080
00081
00082
00083 #define URI_ID_DSIG "http://www.w3.org/2000/09/xmldsig#"
00084 #define URI_ID_EC "http://www.w3.org/2001/10/xml-exc-c14n#"
00085
00086 #define URI_ID_XPF "http://www.w3.org/2002/06/xmldsig-filter2"
00087
00088
00089
00090 #define URI_ID_SHA1 "http://www.w3.org/2000/09/xmldsig#sha1"
00091 #define URI_ID_MD5 "http://www.w3.org/2001/04/xmldsig-more#md5"
00092
00093
00094
00095 #define URI_ID_BASE64 "http://www.w3.org/2000/09/xmldsig#base64"
00096 #define URI_ID_XPATH "http://www.w3.org/TR/1999/REC-xpath-19991116"
00097 #define URI_ID_XSLT "http://www.w3.org/TR/1999/REC-xslt-19991116"
00098 #define URI_ID_ENVELOPE "http://www.w3.org/2000/09/xmldsig#enveloped-signature"
00099 #define URI_ID_C14N_NOC "http://www.w3.org/TR/2001/REC-xml-c14n-20010315"
00100 #define URI_ID_C14N_COM "http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments"
00101 #define URI_ID_EXC_C14N_NOC "http://www.w3.org/2001/10/xml-exc-c14n#"
00102 #define URI_ID_EXC_C14N_COM "http://www.w3.org/2001/10/xml-exc-c14n#WithComments"
00103 #define XPATH_EXPR_ENVELOPE "count(ancestor-or-self::dsig:Signature | \
00104 here()/ancestor::dsig:Signature[1]) > \
00105 count(ancestor-or-self::dsig:Signature)"
00106
00107
00108
00109 #define URI_ID_SIG_BASE "http://www.w3.org/2000/09/xmldsig#"
00110 #define URI_ID_SIG_DSA "dsa"
00111 #define URI_ID_SIG_HMAC "hmac"
00112 #define URI_ID_SIG_SHA1 "sha1"
00113 #define URI_ID_SIG_RSA "rsa"
00114
00115 #define URI_ID_DSA_SHA1 "http://www.w3.org/2000/09/xmldsig#dsa-sha1"
00116 #define URI_ID_HMAC_SHA1 "http://www.w3.org/2000/09/xmldsig#hmac-sha1"
00117 #define URI_ID_RSA_SHA1 "http://www.w3.org/2000/09/xmldsig#rsa-sha1"
00118
00119
00120
00121 #define URI_ID_XMLNS "http://www.w3.org/2000/xmlns/"
00122 #define URI_ID_MANIFEST "http://www.w3.org/2000/09/xmldsig#Manifest"
00123 #define URI_ID_RAWX509 "http://www.w3.org/2000/09/xmldsig#rawX509Certificate"
00124
00125
00126
00127 #define PROV_OPENSSL "OpenSSL Provider"
00128 #define PROV_WINCAPI "WinCAPI Provider"
00129
00130
00131
00132
00133 enum canonicalizationMethod {
00134
00135 CANON_NONE = 0,
00136 CANON_C14N_NOC = 1,
00137 CANON_C14N_COM = 2,
00138 CANON_C14NE_NOC = 3,
00139 CANON_C14NE_COM = 4
00140 };
00141
00142 enum signatureMethod {
00143
00144 SIGNATURE_NONE = 0,
00145 SIGNATURE_DSA = 1,
00146 SIGNATURE_HMAC = 2,
00147 SIGNATURE_RSA = 3
00148 };
00149
00150
00151 enum hashMethod {
00152
00153 HASH_NONE = 0,
00154 HASH_SHA1 = 1,
00155 HASH_MD5 = 2
00156 };
00157
00158 enum transformType {
00159
00160 TRANSFORM_BASE64,
00161 TRANSFORM_C14N,
00162 TRANSFORM_EXC_C14N,
00163 TRANSFORM_ENVELOPED_SIGNATURE,
00164 TRANSFORM_XPATH,
00165 TRANSFORM_XSLT,
00166 TRANSFORM_XPATH_FILTER
00167
00168 };
00169
00170 enum xpathFilterType {
00171
00172 FILTER_UNION = 0,
00173 FILTER_INTERSECT = 1,
00174 FILTER_SUBTRACT = 2
00176 };
00177
00178
00179
00180
00181
00182
00183 inline
00184 bool canonicalizationMethod2URI(safeBuffer &uri, canonicalizationMethod cm) {
00185
00186 switch (cm) {
00187
00188 case (CANON_C14N_NOC) :
00189
00190 uri = URI_ID_C14N_NOC;
00191 break;
00192
00193 case (CANON_C14N_COM) :
00194
00195 uri = URI_ID_C14N_COM;
00196 break;
00197
00198 case (CANON_C14NE_NOC) :
00199
00200 uri = URI_ID_EXC_C14N_NOC;
00201 break;
00202
00203 case (CANON_C14NE_COM) :
00204
00205 uri = URI_ID_EXC_C14N_COM;
00206 break;
00207
00208 default :
00209 return false;
00210
00211 }
00212
00213 return true;
00214
00215 }
00216
00217 inline
00218 bool signatureHashMethod2URI(safeBuffer &uri, signatureMethod sm, hashMethod hm) {
00219
00220 uri = URI_ID_SIG_BASE;
00221
00222 switch (sm) {
00223
00224 case (SIGNATURE_DSA) :
00225
00226 uri.sbStrcatIn(URI_ID_SIG_DSA);
00227 break;
00228
00229 case (SIGNATURE_HMAC) :
00230
00231 uri.sbStrcatIn(URI_ID_SIG_HMAC);
00232 break;
00233
00234 case (SIGNATURE_RSA) :
00235
00236 uri.sbStrcatIn(URI_ID_SIG_RSA);
00237 break;
00238
00239 default :
00240
00241 return false;
00242
00243 }
00244
00245 uri.sbStrcatIn("-");
00246
00247 switch (hm) {
00248
00249 case (HASH_SHA1) :
00250
00251 uri.sbStrcatIn(URI_ID_SIG_SHA1);
00252 break;
00253
00254 default:
00255
00256 return false;
00257
00258 }
00259
00260 return true;
00261
00262 }
00263
00264 inline
00265 bool hashMethod2URI(safeBuffer &uri, hashMethod hm) {
00266
00267 switch (hm) {
00268
00269 case (HASH_SHA1) :
00270
00271 uri = URI_ID_SHA1;
00272 break;
00273
00274 case (HASH_MD5) :
00275
00276 uri = URI_ID_MD5;
00277 break;
00278
00279 default:
00280 return false;
00281
00282 }
00283
00284 return true;
00285
00286 }
00287
00288
00289
00290
00291
00292 class DSIG_EXPORT DSIGConstants {
00293
00294 public:
00295
00296
00297
00298 static const XMLCh * s_unicodeStrEmpty;
00299 static const XMLCh * s_unicodeStrNL;
00300 static const XMLCh * s_unicodeStrXmlns;
00301
00302
00303 static const XMLCh * s_unicodeStrAlgorithm;
00304
00305
00306 static const XMLCh * s_unicodeStrURIDSIG;
00307 static const XMLCh * s_unicodeStrURIEC;
00308 static const XMLCh * s_unicodeStrURIXPF;
00309
00310 static const XMLCh * s_unicodeStrURIRawX509;
00311 static const XMLCh * s_unicodeStrURISHA1;
00312 static const XMLCh * s_unicodeStrURIMD5;
00313 static const XMLCh * s_unicodeStrURIBASE64;
00314 static const XMLCh * s_unicodeStrURIXPATH;
00315 static const XMLCh * s_unicodeStrURIXSLT;
00316 static const XMLCh * s_unicodeStrURIENVELOPE;
00317 static const XMLCh * s_unicodeStrURIC14N_NOC;
00318 static const XMLCh * s_unicodeStrURIC14N_COM;
00319 static const XMLCh * s_unicodeStrURIEXC_C14N_NOC;
00320 static const XMLCh * s_unicodeStrURIEXC_C14N_COM;
00321 static const XMLCh * s_unicodeStrURIDSA_SHA1;
00322 static const XMLCh * s_unicodeStrURIRSA_SHA1;
00323 static const XMLCh * s_unicodeStrURIHMAC_SHA1;
00324 static const XMLCh * s_unicodeStrURIXMLNS;
00325 static const XMLCh * s_unicodeStrURIMANIFEST;
00326
00327
00328 static const XMLCh * s_unicodeStrPROVOpenSSL;
00329 static const XMLCh * s_unicodeStrPROVWinCAPI;
00330
00331
00332 DSIGConstants();
00333
00334 static void create();
00335 static void destroy();
00336
00337 };
00338
00339
00340
00341
00342 inline
00343 const XMLCh * canonicalizationMethod2UNICODEURI(canonicalizationMethod cm) {
00344
00345 switch (cm) {
00346
00347 case (CANON_C14N_NOC) :
00348
00349 return DSIGConstants::s_unicodeStrURIC14N_NOC;
00350 break;
00351
00352 case (CANON_C14N_COM) :
00353
00354 return DSIGConstants::s_unicodeStrURIC14N_COM;
00355 break;
00356
00357 case (CANON_C14NE_NOC) :
00358
00359 return DSIGConstants::s_unicodeStrURIEXC_C14N_NOC;
00360 break;
00361
00362 case (CANON_C14NE_COM) :
00363
00364 return DSIGConstants::s_unicodeStrURIEXC_C14N_COM;
00365 break;
00366
00367 default :
00368 break;
00369
00370 }
00371
00372 return DSIGConstants::s_unicodeStrEmpty;
00373
00374 }
00375
00376 #endif
00377