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