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
00087
00088 #define URI_ID_SHA1 "http://www.w3.org/2000/09/xmldsig#sha1"
00089 #define URI_ID_MD5 "http://www.w3.org/2001/04/xmldsig-more#md5"
00090
00091
00092
00093 #define URI_ID_BASE64 "http://www.w3.org/2000/09/xmldsig#base64"
00094 #define URI_ID_XPATH "http://www.w3.org/TR/1999/REC-xpath-19991116"
00095 #define URI_ID_XSLT "http://www.w3.org/TR/1999/REC-xslt-19991116"
00096 #define URI_ID_ENVELOPE "http://www.w3.org/2000/09/xmldsig#enveloped-signature"
00097 #define URI_ID_C14N_NOC "http://www.w3.org/TR/2001/REC-xml-c14n-20010315"
00098 #define URI_ID_C14N_COM "http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments"
00099 #define URI_ID_EXC_C14N_NOC "http://www.w3.org/2001/10/xml-exc-c14n#"
00100 #define URI_ID_EXC_C14N_COM "http://www.w3.org/2001/10/xml-exc-c14n#WithComments"
00101 #define XPATH_EXPR_ENVELOPE "count(ancestor-or-self::dsig:Signature | \
00102 here()/ancestor::dsig:Signature[1]) > \
00103 count(ancestor-or-self::dsig:Signature)"
00104
00105
00106
00107 #define URI_ID_SIG_BASE "http://www.w3.org/2000/09/xmldsig#"
00108 #define URI_ID_SIG_DSA "dsa"
00109 #define URI_ID_SIG_HMAC "hmac"
00110 #define URI_ID_SIG_SHA1 "sha1"
00111 #define URI_ID_SIG_RSA "rsa"
00112
00113 #define URI_ID_DSA_SHA1 "http://www.w3.org/2000/09/xmldsig#dsa-sha1"
00114 #define URI_ID_HMAC_SHA1 "http://www.w3.org/2000/09/xmldsig#hmac-sha1"
00115 #define URI_ID_RSA_SHA1 "http://www.w3.org/2000/09/xmldsig#rsa-sha1"
00116
00117
00118
00119 #define URI_ID_XMLNS "http://www.w3.org/2000/xmlns/"
00120 #define URI_ID_MANIFEST "http://www.w3.org/2000/09/xmldsig#Manifest"
00121
00122
00123
00124 #define PROV_OPENSSL "OpenSSL Provider"
00125 #define PROV_WINCAPI "WinCAPI Provider"
00126
00127
00128
00129
00130 enum canonicalizationMethod {
00131
00132 CANON_NONE = 0,
00133 CANON_C14N_NOC = 1,
00134 CANON_C14N_COM = 2,
00135 CANON_C14NE_NOC = 3,
00136 CANON_C14NE_COM = 4
00137 };
00138
00139 enum signatureMethod {
00140
00141 SIGNATURE_NONE = 0,
00142 SIGNATURE_DSA = 1,
00143 SIGNATURE_HMAC = 2,
00144 SIGNATURE_RSA = 3
00145 };
00146
00147
00148 enum hashMethod {
00149
00150 HASH_NONE = 0,
00151 HASH_SHA1 = 1,
00152 HASH_MD5 = 2
00153 };
00154
00155 enum transformType {
00156
00157 TRANSFORM_BASE64,
00158 TRANSFORM_C14N,
00159 TRANSFORM_EXC_C14N,
00160 TRANSFORM_ENVELOPED_SIGNATURE,
00161 TRANSFORM_XPATH,
00162 TRANSFORM_XSLT
00163
00164 };
00165
00166
00167
00168
00169
00170 inline
00171 bool canonicalizationMethod2URI(safeBuffer &uri, canonicalizationMethod cm) {
00172
00173 switch (cm) {
00174
00175 case (CANON_C14N_NOC) :
00176
00177 uri = URI_ID_C14N_NOC;
00178 break;
00179
00180 case (CANON_C14N_COM) :
00181
00182 uri = URI_ID_C14N_COM;
00183 break;
00184
00185 case (CANON_C14NE_NOC) :
00186
00187 uri = URI_ID_EXC_C14N_NOC;
00188 break;
00189
00190 case (CANON_C14NE_COM) :
00191
00192 uri = URI_ID_EXC_C14N_COM;
00193 break;
00194
00195 default :
00196 return false;
00197
00198 }
00199
00200 return true;
00201
00202 }
00203
00204 inline
00205 bool signatureHashMethod2URI(safeBuffer &uri, signatureMethod sm, hashMethod hm) {
00206
00207 uri = URI_ID_SIG_BASE;
00208
00209 switch (sm) {
00210
00211 case (SIGNATURE_DSA) :
00212
00213 uri.sbStrcatIn(URI_ID_SIG_DSA);
00214 break;
00215
00216 case (SIGNATURE_HMAC) :
00217
00218 uri.sbStrcatIn(URI_ID_SIG_HMAC);
00219 break;
00220
00221 case (SIGNATURE_RSA) :
00222
00223 uri.sbStrcatIn(URI_ID_SIG_RSA);
00224 break;
00225
00226 default :
00227
00228 return false;
00229
00230 }
00231
00232 uri.sbStrcatIn("-");
00233
00234 switch (hm) {
00235
00236 case (HASH_SHA1) :
00237
00238 uri.sbStrcatIn(URI_ID_SIG_SHA1);
00239 break;
00240
00241 default:
00242
00243 return false;
00244
00245 }
00246
00247 return true;
00248
00249 }
00250
00251 inline
00252 bool hashMethod2URI(safeBuffer &uri, hashMethod hm) {
00253
00254 switch (hm) {
00255
00256 case (HASH_SHA1) :
00257
00258 uri = URI_ID_SHA1;
00259 break;
00260
00261 case (HASH_MD5) :
00262
00263 uri = URI_ID_MD5;
00264 break;
00265
00266 default:
00267 return false;
00268
00269 }
00270
00271 return true;
00272
00273 }
00274
00275
00276
00277
00278
00279 class DSIG_EXPORT DSIGConstants {
00280
00281 public:
00282
00283
00284
00285 static const XMLCh * const & s_unicodeStrEmpty;
00286 static const XMLCh * const & s_unicodeStrNL;
00287 static const XMLCh * const & s_unicodeStrXmlns;
00288
00289
00290 static const XMLCh * const & s_unicodeStrAlgorithm;
00291
00292
00293 static const XMLCh * const & s_unicodeStrURIDSIG;
00294 static const XMLCh * const & s_unicodeStrURIEC;
00295 static const XMLCh * const & s_unicodeStrURISHA1;
00296 static const XMLCh * const & s_unicodeStrURIMD5;
00297 static const XMLCh * const & s_unicodeStrURIBASE64;
00298 static const XMLCh * const & s_unicodeStrURIXPATH;
00299 static const XMLCh * const & s_unicodeStrURIXSLT;
00300 static const XMLCh * const & s_unicodeStrURIENVELOPE;
00301 static const XMLCh * const & s_unicodeStrURIC14N_NOC;
00302 static const XMLCh * const & s_unicodeStrURIC14N_COM;
00303 static const XMLCh * const & s_unicodeStrURIEXC_C14N_NOC;
00304 static const XMLCh * const & s_unicodeStrURIEXC_C14N_COM;
00305 static const XMLCh * const & s_unicodeStrURIDSA_SHA1;
00306 static const XMLCh * const & s_unicodeStrURIRSA_SHA1;
00307 static const XMLCh * const & s_unicodeStrURIHMAC_SHA1;
00308 static const XMLCh * const & s_unicodeStrURIXMLNS;
00309 static const XMLCh * const & s_unicodeStrURIMANIFEST;
00310
00311
00312 static const XMLCh * const & s_unicodeStrPROVOpenSSL;
00313 static const XMLCh * const & s_unicodeStrPROVWinCAPI;
00314
00315
00316 DSIGConstants();
00317
00318 static void create();
00319 static void destroy();
00320
00321 };
00322
00323
00324
00325
00326 inline
00327 const XMLCh * canonicalizationMethod2UNICODEURI(canonicalizationMethod cm) {
00328
00329 switch (cm) {
00330
00331 case (CANON_C14N_NOC) :
00332
00333 return DSIGConstants::s_unicodeStrURIC14N_NOC;
00334 break;
00335
00336 case (CANON_C14N_COM) :
00337
00338 return DSIGConstants::s_unicodeStrURIC14N_COM;
00339 break;
00340
00341 case (CANON_C14NE_NOC) :
00342
00343 return DSIGConstants::s_unicodeStrURIEXC_C14N_NOC;
00344 break;
00345
00346 case (CANON_C14NE_COM) :
00347
00348 return DSIGConstants::s_unicodeStrURIEXC_C14N_COM;
00349 break;
00350
00351 default :
00352 break;
00353
00354 }
00355
00356 return DSIGConstants::s_unicodeStrEmpty;
00357
00358 }
00359
00360 #endif
00361