Main Page | Modules | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

DSIGConstants.hpp

Go to the documentation of this file.
00001 /*
00002  * Copyright 2002-2005 The Apache Software Foundation.
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00017 /*
00018  * XSEC
00019  *
00020  * DSIGConstants := Definitions of varius DSIG constants (mainly strings)
00021  *
00022  * Author(s): Berin Lautenbach
00023  *
00024  * $Id: DSIGConstants.hpp,v 1.24 2005/02/20 10:35:51 blautenb Exp $
00025  *
00026  */
00027 
00028 #ifndef DSIGCONSTANTS_HEADER
00029 #define DSIGCONSTANTS_HEADER
00030 
00031 #include <xsec/utils/XSECSafeBuffer.hpp>
00032 
00033 // Xerces
00034 #include <xercesc/util/XMLString.hpp>
00035 
00036 XSEC_USING_XERCES(XMLString);
00037 
00038 // Name Spaces
00039 
00040 #define URI_ID_DSIG     "http://www.w3.org/2000/09/xmldsig#"
00041 #define URI_ID_EC       "http://www.w3.org/2001/10/xml-exc-c14n#"
00042 // Also used as algorithm ID for XPATH_FILTER
00043 #define URI_ID_XPF      "http://www.w3.org/2002/06/xmldsig-filter2"
00044 #define URI_ID_XENC     "http://www.w3.org/2001/04/xmlenc#"
00045 
00046 // Hashing Algorithms
00047 
00048 #define URI_ID_SHA1         "http://www.w3.org/2000/09/xmldsig#sha1"
00049 #define URI_ID_MD5          "http://www.w3.org/2001/04/xmldsig-more#md5"
00050 #define URI_ID_SHA224       "http://www.w3.org/2001/04/xmldsig-more#sha224"
00051 #define URI_ID_SHA256       "http://www.w3.org/2001/04/xmlenc#sha256"
00052 #define URI_ID_SHA384       "http://www.w3.org/2001/04/xmldsig-more#sha384"
00053 #define URI_ID_SHA512       "http://www.w3.org/2001/04/xmlenc#sha512"
00054 
00055 // Encryption Algorithms
00056 #define URI_ID_3DES_CBC     "http://www.w3.org/2001/04/xmlenc#tripledes-cbc"
00057 #define URI_ID_AES128_CBC   "http://www.w3.org/2001/04/xmlenc#aes128-cbc"
00058 #define URI_ID_AES192_CBC   "http://www.w3.org/2001/04/xmlenc#aes192-cbc"
00059 #define URI_ID_AES256_CBC   "http://www.w3.org/2001/04/xmlenc#aes256-cbc"
00060 
00061 // Key Wrap Algorithm
00062 #define URI_ID_KW_AES128    "http://www.w3.org/2001/04/xmlenc#kw-aes128"
00063 #define URI_ID_KW_AES192    "http://www.w3.org/2001/04/xmlenc#kw-aes192"
00064 #define URI_ID_KW_AES256    "http://www.w3.org/2001/04/xmlenc#kw-aes256"
00065 #define URI_ID_KW_3DES      "http://www.w3.org/2001/04/xmlenc#kw-tripledes"
00066 
00067 // Key Transport algorithms
00068 #define URI_ID_RSA_1_5          "http://www.w3.org/2001/04/xmlenc#rsa-1_5"
00069 #define URI_ID_RSA_OAEP_MGFP1   "http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p"
00070 
00071 // Transforms
00072 
00073 #define URI_ID_BASE64           "http://www.w3.org/2000/09/xmldsig#base64"
00074 #define URI_ID_XPATH            "http://www.w3.org/TR/1999/REC-xpath-19991116"
00075 #define URI_ID_XSLT             "http://www.w3.org/TR/1999/REC-xslt-19991116"
00076 #define URI_ID_ENVELOPE         "http://www.w3.org/2000/09/xmldsig#enveloped-signature"
00077 #define URI_ID_C14N_NOC         "http://www.w3.org/TR/2001/REC-xml-c14n-20010315"
00078 #define URI_ID_C14N_COM         "http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments"
00079 #define URI_ID_EXC_C14N_NOC     "http://www.w3.org/2001/10/xml-exc-c14n#"
00080 #define URI_ID_EXC_C14N_COM     "http://www.w3.org/2001/10/xml-exc-c14n#WithComments"
00081 #define XPATH_EXPR_ENVELOPE     "count(ancestor-or-self::dsig:Signature | \
00082                                  here()/ancestor::dsig:Signature[1]) > \
00083                                  count(ancestor-or-self::dsig:Signature)"
00084 
00085 // Signature Algorithms
00086 
00087 #define URI_ID_SIG_BASE     "http://www.w3.org/2000/09/xmldsig#"
00088 #define URI_ID_SIG_BASEMORE "http://www.w3.org/2001/04/xmldsig-more#"
00089 #define URI_ID_SIG_DSA      "dsa"
00090 #define URI_ID_SIG_HMAC     "hmac"
00091 #define URI_ID_SIG_SHA1     "sha1"
00092 #define URI_ID_SIG_SHA224   "sha224"
00093 #define URI_ID_SIG_SHA256   "sha256"
00094 #define URI_ID_SIG_SHA384   "sha384"
00095 #define URI_ID_SIG_SHA512   "sha512"
00096 #define URI_ID_SIG_RSA      "rsa"
00097 #define URI_ID_SIG_MD5      "md5"
00098 
00099 #define URI_ID_DSA_SHA1     "http://www.w3.org/2000/09/xmldsig#dsa-sha1"
00100 #define URI_ID_HMAC_SHA1    "http://www.w3.org/2000/09/xmldsig#hmac-sha1"
00101 #define URI_ID_HMAC_SHA224  "http://www.w3.org/2001/04/xmldsig-more#hmac-sha224"
00102 #define URI_ID_HMAC_SHA256  "http://www.w3.org/2001/04/xmldsig-more#hmac-sha256"
00103 #define URI_ID_HMAC_SHA384  "http://www.w3.org/2001/04/xmldsig-more#hmac-sha384"
00104 #define URI_ID_HMAC_SHA512  "http://www.w3.org/2001/04/xmldsig-more#hmac-sha512"
00105 #define URI_ID_RSA_SHA1     "http://www.w3.org/2000/09/xmldsig#rsa-sha1"
00106 #define URI_ID_RSA_SHA224   "http://www.w3.org/2001/04/xmldsig-more#rsa-sha224"
00107 #define URI_ID_RSA_SHA256   "http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"
00108 #define URI_ID_RSA_SHA384   "http://www.w3.org/2001/04/xmldsig-more#rsa-sha384"
00109 #define URI_ID_RSA_SHA512   "http://www.w3.org/2001/04/xmldsig-more#rsa-sha512"
00110 #define URI_ID_RSA_MD5      "http://www.w3.org/2000/09/xmldsig#rsa-md5"
00111 
00112 // Encryption defines
00113 #define URI_ID_XENC_ELEMENT "http://www.w3.org/2001/04/xmlenc#Element"
00114 #define URI_ID_XENC_CONTENT "http://www.w3.org/2001/04/xmlenc#Content"
00115 
00116 // General
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 #define URI_ID_RAWX509  "http://www.w3.org/2000/09/xmldsig#rawX509Certificate"
00121 
00122 // Internal Crypto Providers
00123 
00124 #define PROV_OPENSSL    "OpenSSL Provider"
00125 #define PROV_WINCAPI    "WinCAPI Provider"
00126 
00127 // Enumerated Types
00128 
00129 enum canonicalizationMethod {
00130 
00131     CANON_NONE                  = 0,            // No method defined
00132     CANON_C14N_NOC              = 1,            // C14n without comments
00133     CANON_C14N_COM              = 2,            // C14n with comments
00134     CANON_C14NE_NOC             = 3,            // C14n Exclusive (without comments)
00135     CANON_C14NE_COM             = 4             // C14n Exlusive (with Comments
00136 };
00137 
00138 enum signatureMethod {
00139 
00140     SIGNATURE_NONE              = 0,            // No method defined
00141     SIGNATURE_DSA               = 1,            // DSA
00142     SIGNATURE_HMAC              = 2,            // Hash MAC
00143     SIGNATURE_RSA               = 3             // RSA
00144 };
00145 
00146 
00147 enum hashMethod {
00148 
00149     HASH_NONE                   = 0,            // No method defined
00150     HASH_SHA1                   = 1,            // SHA1
00151     HASH_MD5                    = 2,
00152     HASH_SHA224                 = 3,
00153     HASH_SHA256                 = 4,
00154     HASH_SHA384                 = 5,
00155     HASH_SHA512                 = 6
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 enum encryptionMethod {
00179 
00180     ENCRYPT_NONE            = 0,                // No method defined
00181     ENCRYPT_3DES_CBC        = 1,                // Use 3DES
00182     ENCRYPT_AES128_CBC      = 2,                // 128 bit AES in CBC mode
00183     ENCRYPT_AES192_CBC      = 3,                // 192 bit AES in CBC mode
00184     ENCRYPT_AES256_CBC      = 4,                // 256 bit AES in CBC mode
00185     ENCRYPT_KW_AES128       = 5,                // KeyWrap - AES128
00186     ENCRYPT_KW_AES192       = 6,                // KeyWrap - AES192
00187     ENCRYPT_KW_AES256       = 7,                // KeyWrap - AES256
00188     ENCRYPT_KW_3DES         = 8,
00189     ENCRYPT_RSA_15          = 9,                // RSA with PKCS 1.5 padding
00190     ENCRYPT_RSA_OAEP_MGFP1  = 10                // RSA with OAEP
00191 
00192 };
00193 
00194 
00195 // --------------------------------------------------------------------------------
00196 //           Some utility functions
00197 // --------------------------------------------------------------------------------
00198 
00199 inline
00200 bool canonicalizationMethod2URI(safeBuffer &uri, canonicalizationMethod cm) {
00201 
00202     switch (cm) {
00203 
00204     case (CANON_C14N_NOC) :
00205 
00206         uri = URI_ID_C14N_NOC;
00207         break;
00208 
00209     case (CANON_C14N_COM) :
00210 
00211         uri = URI_ID_C14N_COM;
00212         break;
00213 
00214     case (CANON_C14NE_NOC) :
00215 
00216         uri = URI_ID_EXC_C14N_NOC;
00217         break;
00218 
00219     case (CANON_C14NE_COM) :
00220 
00221         uri = URI_ID_EXC_C14N_COM;
00222         break;
00223 
00224     default :
00225         return false;       // Unknown type
00226 
00227     }
00228 
00229     return true;
00230 
00231 }
00232 
00233 inline
00234 bool signatureHashMethod2URI(safeBuffer &uri, signatureMethod sm, hashMethod hm) {
00235 
00236     if (hm < HASH_MD5)
00237         uri = URI_ID_SIG_BASE;
00238     else
00239         uri = URI_ID_SIG_BASEMORE;
00240 
00241     switch (sm) {
00242 
00243     case (SIGNATURE_DSA) :
00244 
00245         uri.sbStrcatIn(URI_ID_SIG_DSA);
00246         break;
00247 
00248     case (SIGNATURE_HMAC) :
00249 
00250         uri.sbStrcatIn(URI_ID_SIG_HMAC);
00251         break;
00252 
00253     case (SIGNATURE_RSA) :
00254 
00255         uri.sbStrcatIn(URI_ID_SIG_RSA);
00256         break;
00257 
00258     default :
00259 
00260         return false;
00261 
00262     }
00263 
00264     uri.sbStrcatIn("-");
00265 
00266     switch (hm) {
00267 
00268     case (HASH_SHA1) :
00269 
00270         uri.sbStrcatIn(URI_ID_SIG_SHA1);
00271         break;
00272 
00273     case (HASH_MD5) :
00274 
00275         uri.sbStrcatIn(URI_ID_SIG_MD5);
00276         break;
00277 
00278     case (HASH_SHA224) :
00279 
00280         uri.sbStrcatIn(URI_ID_SIG_SHA224);
00281         break;
00282 
00283     case (HASH_SHA256) :
00284 
00285         uri.sbStrcatIn(URI_ID_SIG_SHA256);
00286         break;
00287 
00288     case (HASH_SHA384) :
00289 
00290         uri.sbStrcatIn(URI_ID_SIG_SHA384);
00291         break;
00292 
00293     case (HASH_SHA512) :
00294 
00295         uri.sbStrcatIn(URI_ID_SIG_SHA512);
00296         break;
00297 
00298     default:
00299 
00300         return false;
00301 
00302     }
00303 
00304     return true;
00305 
00306 }
00307 
00308 inline
00309 bool hashMethod2URI(safeBuffer &uri, hashMethod hm) {
00310 
00311     switch (hm) {
00312 
00313     case (HASH_SHA1) :
00314 
00315         uri = URI_ID_SHA1;
00316         break;
00317 
00318     case (HASH_MD5) :
00319 
00320         uri = URI_ID_MD5;
00321         break;
00322 
00323     case (HASH_SHA224) :
00324 
00325         uri = URI_ID_SHA224;
00326         break;
00327 
00328     case (HASH_SHA256) :
00329 
00330         uri = URI_ID_SHA256;
00331         break;
00332 
00333     case (HASH_SHA384) :
00334 
00335         uri = URI_ID_SHA384;
00336         break;
00337 
00338     case (HASH_SHA512) :
00339 
00340         uri = URI_ID_SHA512;
00341         break;
00342 
00343     default:
00344         return false;
00345 
00346     }
00347 
00348     return true;
00349 
00350 }
00351 
00352 inline
00353 bool encryptionMethod2URI(safeBuffer &uri, encryptionMethod em) {
00354 
00355     switch (em) {
00356 
00357     case (ENCRYPT_3DES_CBC) :
00358 
00359         uri = URI_ID_3DES_CBC;
00360         break;
00361 
00362     case (ENCRYPT_AES128_CBC) :
00363 
00364         uri = URI_ID_AES128_CBC;
00365         break;
00366 
00367     case (ENCRYPT_AES192_CBC) :
00368 
00369         uri = URI_ID_AES192_CBC;
00370         break;
00371 
00372     case (ENCRYPT_AES256_CBC) :
00373 
00374         uri = URI_ID_AES256_CBC;
00375         break;
00376 
00377     case (ENCRYPT_KW_AES128) :
00378 
00379         uri = URI_ID_KW_AES128;
00380         break;
00381 
00382     case (ENCRYPT_KW_AES192) :
00383 
00384         uri = URI_ID_KW_AES192;
00385         break;
00386 
00387     case (ENCRYPT_KW_AES256) :
00388 
00389         uri = URI_ID_KW_AES256;
00390         break;
00391 
00392     case (ENCRYPT_KW_3DES) :
00393 
00394         uri = URI_ID_KW_3DES;
00395         break;
00396 
00397     case (ENCRYPT_RSA_15) :
00398 
00399         uri = URI_ID_RSA_1_5;
00400         break;
00401         
00402     case (ENCRYPT_RSA_OAEP_MGFP1) :
00403 
00404         uri = URI_ID_RSA_OAEP_MGFP1;
00405         break;
00406     
00407     default:
00408 
00409         return false;
00410 
00411     }
00412 
00413     return true;
00414 
00415 }
00416 
00417 // --------------------------------------------------------------------------------
00418 //           Constant Strings Class
00419 // --------------------------------------------------------------------------------
00420 
00421 class DSIG_EXPORT DSIGConstants {
00422 
00423 public:
00424 
00425     // General strings
00426 
00427     static const XMLCh * s_unicodeStrEmpty;     // ""
00428     static const XMLCh * s_unicodeStrNL;            // "\n"
00429     static const XMLCh * s_unicodeStrXmlns;     // "xmlns"
00430     static const XMLCh * s_unicodeStrURI;       // "URI"
00431 
00432     // DSIG Element Strings
00433     static const XMLCh * s_unicodeStrAlgorithm;
00434 
00435     // URI_IDs
00436     static const XMLCh * s_unicodeStrURIDSIG;
00437     static const XMLCh * s_unicodeStrURIEC;
00438     static const XMLCh * s_unicodeStrURIXPF;
00439     static const XMLCh * s_unicodeStrURIXENC;
00440 
00441     static const XMLCh * s_unicodeStrURIRawX509;
00442     static const XMLCh * s_unicodeStrURISHA1;
00443     static const XMLCh * s_unicodeStrURISHA224;
00444     static const XMLCh * s_unicodeStrURISHA256;
00445     static const XMLCh * s_unicodeStrURISHA384;
00446     static const XMLCh * s_unicodeStrURISHA512;
00447     static const XMLCh * s_unicodeStrURIMD5;        // Not recommended
00448     static const XMLCh * s_unicodeStrURIBASE64;
00449     static const XMLCh * s_unicodeStrURIXPATH;
00450     static const XMLCh * s_unicodeStrURIXSLT;
00451     static const XMLCh * s_unicodeStrURIENVELOPE;
00452     static const XMLCh * s_unicodeStrURIC14N_NOC;
00453     static const XMLCh * s_unicodeStrURIC14N_COM;
00454     static const XMLCh * s_unicodeStrURIEXC_C14N_NOC;
00455     static const XMLCh * s_unicodeStrURIEXC_C14N_COM;
00456     static const XMLCh * s_unicodeStrURIDSA_SHA1;
00457     static const XMLCh * s_unicodeStrURIRSA_SHA1;
00458     static const XMLCh * s_unicodeStrURIHMAC_SHA1;
00459     static const XMLCh * s_unicodeStrURIXMLNS;
00460     static const XMLCh * s_unicodeStrURIMANIFEST;
00461 
00462     // URIs for Encryption
00463     static const XMLCh * s_unicodeStrURI3DES_CBC;
00464     static const XMLCh * s_unicodeStrURIAES128_CBC; 
00465     static const XMLCh * s_unicodeStrURIAES192_CBC; 
00466     static const XMLCh * s_unicodeStrURIAES256_CBC; 
00467     static const XMLCh * s_unicodeStrURIKW_AES128;
00468     static const XMLCh * s_unicodeStrURIKW_AES192;
00469     static const XMLCh * s_unicodeStrURIKW_AES256;
00470     static const XMLCh * s_unicodeStrURIKW_3DES;
00471     static const XMLCh * s_unicodeStrURIRSA_1_5;
00472     static const XMLCh * s_unicodeStrURIRSA_OAEP_MGFP1;
00473 
00474     static const XMLCh * s_unicodeStrURIXENC_ELEMENT;
00475     static const XMLCh * s_unicodeStrURIXENC_CONTENT;
00476 
00477     // Internal Crypto Providers
00478     static const XMLCh * s_unicodeStrPROVOpenSSL;
00479     static const XMLCh * s_unicodeStrPROVWinCAPI;
00480 
00481 
00482     DSIGConstants();
00483 
00484     static void create();
00485     static void destroy();
00486 
00487 };
00488 
00489 
00490 
00491 
00492 inline
00493 const XMLCh * canonicalizationMethod2UNICODEURI(canonicalizationMethod cm) {
00494 
00495     switch (cm) {
00496 
00497     case (CANON_C14N_NOC) :
00498 
00499         return DSIGConstants::s_unicodeStrURIC14N_NOC;
00500         break;
00501 
00502     case (CANON_C14N_COM) :
00503 
00504         return DSIGConstants::s_unicodeStrURIC14N_COM;
00505         break;
00506 
00507     case (CANON_C14NE_NOC) :
00508 
00509         return DSIGConstants::s_unicodeStrURIEXC_C14N_NOC;
00510         break;
00511 
00512     case (CANON_C14NE_COM) :
00513 
00514         return DSIGConstants::s_unicodeStrURIEXC_C14N_COM;
00515         break;
00516 
00517     default :
00518         break;
00519 
00520     }
00521 
00522     return DSIGConstants::s_unicodeStrEmpty;
00523 
00524 }
00525 
00526 #endif /* DSIGCONSTANTS_HEADER */
00527 

Generated on Sun Jul 3 17:37:25 2005 for XML-Security-C by  doxygen 1.4.2