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  * The Apache Software License, Version 1.1
00003  *
00004  *
00005  * Copyright (c) 1999 The Apache Software Foundation.  All rights 
00006  * reserved.
00007  *
00008  * Redistribution and use in source and binary forms, with or without
00009  * modification, are permitted provided that the following conditions
00010  * are met:
00011  *
00012  * 1. Redistributions of source code must retain the above copyright
00013  *    notice, this list of conditions and the following disclaimer. 
00014  *
00015  * 2. Redistributions in binary form must reproduce the above copyright
00016  *    notice, this list of conditions and the following disclaimer in
00017  *    the documentation and/or other materials provided with the
00018  *    distribution.
00019  *
00020  * 3. The end-user documentation included with the redistribution,
00021  *    if any, must include the following acknowledgment:  
00022  *       "This product includes software developed by the
00023  *        Apache Software Foundation (http://www.apache.org/)."
00024  *    Alternately, this acknowledgment may appear in the software itself,
00025  *    if and wherever such third-party acknowledgments normally appear.
00026  *
00027  * 4. The names "<WebSig>" and "Apache Software Foundation" must
00028  *    not be used to endorse or promote products derived from this
00029  *    software without prior written permission. For written 
00030  *    permission, please contact apache@apache.org.
00031  *
00032  * 5. Products derived from this software may not be called "Apache",
00033  *    nor may "Apache" appear in their name, without prior written
00034  *    permission of the Apache Software Foundation.
00035  *
00036  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
00037  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00038  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00039  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
00040  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00041  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00042  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
00043  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00044  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00045  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
00046  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00047  * SUCH DAMAGE.
00048  * ====================================================================
00049  *
00050  * This software consists of voluntary contributions made by many
00051  * individuals on behalf of the Apache Software Foundation and was
00052  * originally based on software copyright (c) 2001, Institute for
00053  * Data Communications Systems, <http://www.nue.et-inf.uni-siegen.de/>.
00054  * The development of this software was partly funded by the European 
00055  * Commission in the <WebSig> project in the ISIS Programme. 
00056  * For more information on the Apache Software Foundation, please see
00057  * <http://www.apache.org/>.
00058  */
00059 
00060 /*
00061  * XSEC
00062  *
00063  * DSIGConstants := Definitions of varius DSIG constants (mainly strings)
00064  *
00065  * Author(s): Berin Lautenbach
00066  *
00067  * $Id: DSIGConstants.hpp,v 1.8 2003/04/30 11:41:14 blautenb Exp $
00068  *
00069  */
00070 
00071 #ifndef DSIGCONSTANTS_HEADER
00072 #define DSIGCONSTANTS_HEADER
00073 
00074 #include <xsec/utils/XSECSafeBuffer.hpp>
00075 
00076 // Xerces
00077 #include <xercesc/util/XMLString.hpp>
00078 
00079 XSEC_USING_XERCES(XMLString);
00080 
00081 // Name Spaces
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 // Hashing Algorithms
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 // Transforms
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 // Signature Algorithms
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 // General
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 // Internal Crypto Providers
00123 
00124 #define PROV_OPENSSL    "OpenSSL Provider"
00125 #define PROV_WINCAPI    "WinCAPI Provider"
00126 
00127 // Enumerated Types
00128 
00129 
00130 enum canonicalizationMethod {
00131 
00132     CANON_NONE                  = 0,            // No method defined
00133     CANON_C14N_NOC              = 1,            // C14n without comments
00134     CANON_C14N_COM              = 2,            // C14n with comments
00135     CANON_C14NE_NOC             = 3,            // C14n Exclusive (without comments)
00136     CANON_C14NE_COM             = 4             // C14n Exlusive (with Comments
00137 };
00138 
00139 enum signatureMethod {
00140 
00141     SIGNATURE_NONE              = 0,            // No method defined
00142     SIGNATURE_DSA               = 1,            // DSA
00143     SIGNATURE_HMAC              = 2,            // Hash MAC
00144     SIGNATURE_RSA               = 3             // RSA
00145 };
00146 
00147 
00148 enum hashMethod {
00149 
00150     HASH_NONE                   = 0,            // No method defined
00151     HASH_SHA1                   = 1,            // SHA1
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 //           Some utility functions
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;       // Unknown type
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 //           Constant Strings Class
00277 // --------------------------------------------------------------------------------
00278 
00279 class DSIG_EXPORT DSIGConstants {
00280 
00281 public:
00282 
00283     // General strings
00284 
00285     static const XMLCh * const & s_unicodeStrEmpty;     // ""
00286     static const XMLCh * const & s_unicodeStrNL;            // "\n"
00287     static const XMLCh * const & s_unicodeStrXmlns;     // "xmlns"
00288 
00289     // DSIG Element Strings
00290     static const XMLCh * const & s_unicodeStrAlgorithm;
00291 
00292     // URI_IDs
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;        // Not recommended
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     // Internal Crypto Providers
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 /* DSIGCONSTANTS_HEADER */
00361 

Generated on Wed May 7 21:43:50 2003 for XML-Security-C by doxygen1.2.18