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

DSIGConstants.hpp

Go to the documentation of this file.
00001 /*
00002  * Copyright 2002-2004 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  * imitations 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.21 2004/02/08 10:20: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 
00051 // Encryption Algorithms
00052 #define URI_ID_3DES_CBC     "http://www.w3.org/2001/04/xmlenc#tripledes-cbc"
00053 #define URI_ID_AES128_CBC   "http://www.w3.org/2001/04/xmlenc#aes128-cbc"
00054 #define URI_ID_AES192_CBC   "http://www.w3.org/2001/04/xmlenc#aes192-cbc"
00055 #define URI_ID_AES256_CBC   "http://www.w3.org/2001/04/xmlenc#aes256-cbc"
00056 
00057 // Key Wrap Algorithm
00058 #define URI_ID_KW_AES128    "http://www.w3.org/2001/04/xmlenc#kw-aes128"
00059 #define URI_ID_KW_AES192    "http://www.w3.org/2001/04/xmlenc#kw-aes192"
00060 #define URI_ID_KW_AES256    "http://www.w3.org/2001/04/xmlenc#kw-aes256"
00061 #define URI_ID_KW_3DES      "http://www.w3.org/2001/04/xmlenc#kw-tripledes"
00062 
00063 // Key Transport algorithms
00064 #define URI_ID_RSA_1_5          "http://www.w3.org/2001/04/xmlenc#rsa-1_5"
00065 #define URI_ID_RSA_OAEP_MGFP1   "http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p"
00066 
00067 // Transforms
00068 
00069 #define URI_ID_BASE64           "http://www.w3.org/2000/09/xmldsig#base64"
00070 #define URI_ID_XPATH            "http://www.w3.org/TR/1999/REC-xpath-19991116"
00071 #define URI_ID_XSLT             "http://www.w3.org/TR/1999/REC-xslt-19991116"
00072 #define URI_ID_ENVELOPE         "http://www.w3.org/2000/09/xmldsig#enveloped-signature"
00073 #define URI_ID_C14N_NOC         "http://www.w3.org/TR/2001/REC-xml-c14n-20010315"
00074 #define URI_ID_C14N_COM         "http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments"
00075 #define URI_ID_EXC_C14N_NOC     "http://www.w3.org/2001/10/xml-exc-c14n#"
00076 #define URI_ID_EXC_C14N_COM     "http://www.w3.org/2001/10/xml-exc-c14n#WithComments"
00077 #define XPATH_EXPR_ENVELOPE     "count(ancestor-or-self::dsig:Signature | \
00078                                  here()/ancestor::dsig:Signature[1]) > \
00079                                  count(ancestor-or-self::dsig:Signature)"
00080 
00081 // Signature Algorithms
00082 
00083 #define URI_ID_SIG_BASE     "http://www.w3.org/2000/09/xmldsig#"
00084 #define URI_ID_SIG_DSA      "dsa"
00085 #define URI_ID_SIG_HMAC     "hmac"
00086 #define URI_ID_SIG_SHA1     "sha1"
00087 #define URI_ID_SIG_RSA      "rsa"
00088 
00089 #define URI_ID_DSA_SHA1     "http://www.w3.org/2000/09/xmldsig#dsa-sha1"
00090 #define URI_ID_HMAC_SHA1    "http://www.w3.org/2000/09/xmldsig#hmac-sha1"
00091 #define URI_ID_RSA_SHA1     "http://www.w3.org/2000/09/xmldsig#rsa-sha1"
00092 
00093 // Encryption defines
00094 #define URI_ID_XENC_ELEMENT "http://www.w3.org/2001/04/xmlenc#Element"
00095 #define URI_ID_XENC_CONTENT "http://www.w3.org/2001/04/xmlenc#Content"
00096 
00097 // General
00098 
00099 #define URI_ID_XMLNS    "http://www.w3.org/2000/xmlns/"
00100 #define URI_ID_MANIFEST "http://www.w3.org/2000/09/xmldsig#Manifest"
00101 #define URI_ID_RAWX509  "http://www.w3.org/2000/09/xmldsig#rawX509Certificate"
00102 
00103 // Internal Crypto Providers
00104 
00105 #define PROV_OPENSSL    "OpenSSL Provider"
00106 #define PROV_WINCAPI    "WinCAPI Provider"
00107 
00108 // Enumerated Types
00109 
00110 enum canonicalizationMethod {
00111 
00112     CANON_NONE                  = 0,            // No method defined
00113     CANON_C14N_NOC              = 1,            // C14n without comments
00114     CANON_C14N_COM              = 2,            // C14n with comments
00115     CANON_C14NE_NOC             = 3,            // C14n Exclusive (without comments)
00116     CANON_C14NE_COM             = 4             // C14n Exlusive (with Comments
00117 };
00118 
00119 enum signatureMethod {
00120 
00121     SIGNATURE_NONE              = 0,            // No method defined
00122     SIGNATURE_DSA               = 1,            // DSA
00123     SIGNATURE_HMAC              = 2,            // Hash MAC
00124     SIGNATURE_RSA               = 3             // RSA
00125 };
00126 
00127 
00128 enum hashMethod {
00129 
00130     HASH_NONE                   = 0,            // No method defined
00131     HASH_SHA1                   = 1,            // SHA1
00132     HASH_MD5                    = 2
00133 };
00134 
00135 enum transformType {
00136 
00137     TRANSFORM_BASE64,
00138     TRANSFORM_C14N,
00139     TRANSFORM_EXC_C14N,
00140     TRANSFORM_ENVELOPED_SIGNATURE,
00141     TRANSFORM_XPATH,
00142     TRANSFORM_XSLT,
00143     TRANSFORM_XPATH_FILTER
00144 
00145 };
00146 
00147 enum xpathFilterType {
00148 
00149     FILTER_UNION            = 0,    
00150     FILTER_INTERSECT        = 1,    
00151     FILTER_SUBTRACT         = 2     
00153 };
00154 
00155 enum encryptionMethod {
00156 
00157     ENCRYPT_NONE            = 0,                // No method defined
00158     ENCRYPT_3DES_CBC        = 1,                // Use 3DES
00159     ENCRYPT_AES128_CBC      = 2,                // 128 bit AES in CBC mode
00160     ENCRYPT_AES192_CBC      = 3,                // 192 bit AES in CBC mode
00161     ENCRYPT_AES256_CBC      = 4,                // 256 bit AES in CBC mode
00162     ENCRYPT_KW_AES128       = 5,                // KeyWrap - AES128
00163     ENCRYPT_KW_AES192       = 6,                // KeyWrap - AES192
00164     ENCRYPT_KW_AES256       = 7,                // KeyWrap - AES256
00165     ENCRYPT_KW_3DES         = 8,
00166     ENCRYPT_RSA_15          = 9,                // RSA with PKCS 1.5 padding
00167     ENCRYPT_RSA_OAEP_MGFP1  = 10                // RSA with OAEP
00168 
00169 };
00170 
00171 
00172 // --------------------------------------------------------------------------------
00173 //           Some utility functions
00174 // --------------------------------------------------------------------------------
00175 
00176 inline
00177 bool canonicalizationMethod2URI(safeBuffer &uri, canonicalizationMethod cm) {
00178 
00179     switch (cm) {
00180 
00181     case (CANON_C14N_NOC) :
00182 
00183         uri = URI_ID_C14N_NOC;
00184         break;
00185 
00186     case (CANON_C14N_COM) :
00187 
00188         uri = URI_ID_C14N_COM;
00189         break;
00190 
00191     case (CANON_C14NE_NOC) :
00192 
00193         uri = URI_ID_EXC_C14N_NOC;
00194         break;
00195 
00196     case (CANON_C14NE_COM) :
00197 
00198         uri = URI_ID_EXC_C14N_COM;
00199         break;
00200 
00201     default :
00202         return false;       // Unknown type
00203 
00204     }
00205 
00206     return true;
00207 
00208 }
00209 
00210 inline
00211 bool signatureHashMethod2URI(safeBuffer &uri, signatureMethod sm, hashMethod hm) {
00212 
00213     uri = URI_ID_SIG_BASE;
00214 
00215     switch (sm) {
00216 
00217     case (SIGNATURE_DSA) :
00218 
00219         uri.sbStrcatIn(URI_ID_SIG_DSA);
00220         break;
00221 
00222     case (SIGNATURE_HMAC) :
00223 
00224         uri.sbStrcatIn(URI_ID_SIG_HMAC);
00225         break;
00226 
00227     case (SIGNATURE_RSA) :
00228 
00229         uri.sbStrcatIn(URI_ID_SIG_RSA);
00230         break;
00231 
00232     default :
00233 
00234         return false;
00235 
00236     }
00237 
00238     uri.sbStrcatIn("-");
00239 
00240     switch (hm) {
00241 
00242     case (HASH_SHA1) :
00243 
00244         uri.sbStrcatIn(URI_ID_SIG_SHA1);
00245         break;
00246 
00247     default:
00248 
00249         return false;
00250 
00251     }
00252 
00253     return true;
00254 
00255 }
00256 
00257 inline
00258 bool hashMethod2URI(safeBuffer &uri, hashMethod hm) {
00259 
00260     switch (hm) {
00261 
00262     case (HASH_SHA1) :
00263 
00264         uri = URI_ID_SHA1;
00265         break;
00266 
00267     case (HASH_MD5) :
00268 
00269         uri = URI_ID_MD5;
00270         break;
00271 
00272     default:
00273         return false;
00274 
00275     }
00276 
00277     return true;
00278 
00279 }
00280 
00281 inline
00282 bool encryptionMethod2URI(safeBuffer &uri, encryptionMethod em) {
00283 
00284     switch (em) {
00285 
00286     case (ENCRYPT_3DES_CBC) :
00287 
00288         uri = URI_ID_3DES_CBC;
00289         break;
00290 
00291     case (ENCRYPT_AES128_CBC) :
00292 
00293         uri = URI_ID_AES128_CBC;
00294         break;
00295 
00296     case (ENCRYPT_AES192_CBC) :
00297 
00298         uri = URI_ID_AES192_CBC;
00299         break;
00300 
00301     case (ENCRYPT_AES256_CBC) :
00302 
00303         uri = URI_ID_AES256_CBC;
00304         break;
00305 
00306     case (ENCRYPT_KW_AES128) :
00307 
00308         uri = URI_ID_KW_AES128;
00309         break;
00310 
00311     case (ENCRYPT_KW_AES192) :
00312 
00313         uri = URI_ID_KW_AES192;
00314         break;
00315 
00316     case (ENCRYPT_KW_AES256) :
00317 
00318         uri = URI_ID_KW_AES256;
00319         break;
00320 
00321     case (ENCRYPT_KW_3DES) :
00322 
00323         uri = URI_ID_KW_3DES;
00324         break;
00325 
00326     case (ENCRYPT_RSA_15) :
00327 
00328         uri = URI_ID_RSA_1_5;
00329         break;
00330         
00331     case (ENCRYPT_RSA_OAEP_MGFP1) :
00332 
00333         uri = URI_ID_RSA_OAEP_MGFP1;
00334         break;
00335     
00336     default:
00337 
00338         return false;
00339 
00340     }
00341 
00342     return true;
00343 
00344 }
00345 
00346 // --------------------------------------------------------------------------------
00347 //           Constant Strings Class
00348 // --------------------------------------------------------------------------------
00349 
00350 class DSIG_EXPORT DSIGConstants {
00351 
00352 public:
00353 
00354     // General strings
00355 
00356     static const XMLCh * s_unicodeStrEmpty;     // ""
00357     static const XMLCh * s_unicodeStrNL;            // "\n"
00358     static const XMLCh * s_unicodeStrXmlns;     // "xmlns"
00359     static const XMLCh * s_unicodeStrURI;       // "URI"
00360 
00361     // DSIG Element Strings
00362     static const XMLCh * s_unicodeStrAlgorithm;
00363 
00364     // URI_IDs
00365     static const XMLCh * s_unicodeStrURIDSIG;
00366     static const XMLCh * s_unicodeStrURIEC;
00367     static const XMLCh * s_unicodeStrURIXPF;
00368     static const XMLCh * s_unicodeStrURIXENC;
00369 
00370     static const XMLCh * s_unicodeStrURIRawX509;
00371     static const XMLCh * s_unicodeStrURISHA1;
00372     static const XMLCh * s_unicodeStrURIMD5;        // Not recommended
00373     static const XMLCh * s_unicodeStrURIBASE64;
00374     static const XMLCh * s_unicodeStrURIXPATH;
00375     static const XMLCh * s_unicodeStrURIXSLT;
00376     static const XMLCh * s_unicodeStrURIENVELOPE;
00377     static const XMLCh * s_unicodeStrURIC14N_NOC;
00378     static const XMLCh * s_unicodeStrURIC14N_COM;
00379     static const XMLCh * s_unicodeStrURIEXC_C14N_NOC;
00380     static const XMLCh * s_unicodeStrURIEXC_C14N_COM;
00381     static const XMLCh * s_unicodeStrURIDSA_SHA1;
00382     static const XMLCh * s_unicodeStrURIRSA_SHA1;
00383     static const XMLCh * s_unicodeStrURIHMAC_SHA1;
00384     static const XMLCh * s_unicodeStrURIXMLNS;
00385     static const XMLCh * s_unicodeStrURIMANIFEST;
00386 
00387     // URIs for Encryption
00388     static const XMLCh * s_unicodeStrURI3DES_CBC;
00389     static const XMLCh * s_unicodeStrURIAES128_CBC; 
00390     static const XMLCh * s_unicodeStrURIAES192_CBC; 
00391     static const XMLCh * s_unicodeStrURIAES256_CBC; 
00392     static const XMLCh * s_unicodeStrURIKW_AES128;
00393     static const XMLCh * s_unicodeStrURIKW_AES192;
00394     static const XMLCh * s_unicodeStrURIKW_AES256;
00395     static const XMLCh * s_unicodeStrURIKW_3DES;
00396     static const XMLCh * s_unicodeStrURIRSA_1_5;
00397     static const XMLCh * s_unicodeStrURIRSA_OAEP_MGFP1;
00398 
00399     static const XMLCh * s_unicodeStrURIXENC_ELEMENT;
00400     static const XMLCh * s_unicodeStrURIXENC_CONTENT;
00401 
00402     // Internal Crypto Providers
00403     static const XMLCh * s_unicodeStrPROVOpenSSL;
00404     static const XMLCh * s_unicodeStrPROVWinCAPI;
00405 
00406 
00407     DSIGConstants();
00408 
00409     static void create();
00410     static void destroy();
00411 
00412 };
00413 
00414 
00415 
00416 
00417 inline
00418 const XMLCh * canonicalizationMethod2UNICODEURI(canonicalizationMethod cm) {
00419 
00420     switch (cm) {
00421 
00422     case (CANON_C14N_NOC) :
00423 
00424         return DSIGConstants::s_unicodeStrURIC14N_NOC;
00425         break;
00426 
00427     case (CANON_C14N_COM) :
00428 
00429         return DSIGConstants::s_unicodeStrURIC14N_COM;
00430         break;
00431 
00432     case (CANON_C14NE_NOC) :
00433 
00434         return DSIGConstants::s_unicodeStrURIEXC_C14N_NOC;
00435         break;
00436 
00437     case (CANON_C14NE_COM) :
00438 
00439         return DSIGConstants::s_unicodeStrURIEXC_C14N_COM;
00440         break;
00441 
00442     default :
00443         break;
00444 
00445     }
00446 
00447     return DSIGConstants::s_unicodeStrEmpty;
00448 
00449 }
00450 
00451 #endif /* DSIGCONSTANTS_HEADER */
00452 

Generated on Sun Mar 14 20:20:34 2004 for XML-Security-C by doxygen 1.3.2