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) 2002-2003 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.12 2003/07/05 10:30:30 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 // Also used as algorithm ID for XPATH_FILTER
00086 #define URI_ID_XPF      "http://www.w3.org/2002/06/xmldsig-filter2"
00087 
00088 // Hashing Algorithms
00089 
00090 #define URI_ID_SHA1     "http://www.w3.org/2000/09/xmldsig#sha1"
00091 #define URI_ID_MD5      "http://www.w3.org/2001/04/xmldsig-more#md5"
00092 
00093 // Transforms
00094 
00095 #define URI_ID_BASE64           "http://www.w3.org/2000/09/xmldsig#base64"
00096 #define URI_ID_XPATH            "http://www.w3.org/TR/1999/REC-xpath-19991116"
00097 #define URI_ID_XSLT             "http://www.w3.org/TR/1999/REC-xslt-19991116"
00098 #define URI_ID_ENVELOPE         "http://www.w3.org/2000/09/xmldsig#enveloped-signature"
00099 #define URI_ID_C14N_NOC         "http://www.w3.org/TR/2001/REC-xml-c14n-20010315"
00100 #define URI_ID_C14N_COM         "http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments"
00101 #define URI_ID_EXC_C14N_NOC     "http://www.w3.org/2001/10/xml-exc-c14n#"
00102 #define URI_ID_EXC_C14N_COM     "http://www.w3.org/2001/10/xml-exc-c14n#WithComments"
00103 #define XPATH_EXPR_ENVELOPE     "count(ancestor-or-self::dsig:Signature | \
00104                                  here()/ancestor::dsig:Signature[1]) > \
00105                                  count(ancestor-or-self::dsig:Signature)"
00106 
00107 // Signature Algorithms
00108 
00109 #define URI_ID_SIG_BASE     "http://www.w3.org/2000/09/xmldsig#"
00110 #define URI_ID_SIG_DSA      "dsa"
00111 #define URI_ID_SIG_HMAC     "hmac"
00112 #define URI_ID_SIG_SHA1     "sha1"
00113 #define URI_ID_SIG_RSA      "rsa"
00114 
00115 #define URI_ID_DSA_SHA1     "http://www.w3.org/2000/09/xmldsig#dsa-sha1"
00116 #define URI_ID_HMAC_SHA1    "http://www.w3.org/2000/09/xmldsig#hmac-sha1"
00117 #define URI_ID_RSA_SHA1     "http://www.w3.org/2000/09/xmldsig#rsa-sha1"
00118 
00119 // General
00120 
00121 #define URI_ID_XMLNS    "http://www.w3.org/2000/xmlns/"
00122 #define URI_ID_MANIFEST "http://www.w3.org/2000/09/xmldsig#Manifest"
00123 #define URI_ID_RAWX509  "http://www.w3.org/2000/09/xmldsig#rawX509Certificate"
00124 
00125 // Internal Crypto Providers
00126 
00127 #define PROV_OPENSSL    "OpenSSL Provider"
00128 #define PROV_WINCAPI    "WinCAPI Provider"
00129 
00130 // Enumerated Types
00131 
00132 
00133 enum canonicalizationMethod {
00134 
00135     CANON_NONE                  = 0,            // No method defined
00136     CANON_C14N_NOC              = 1,            // C14n without comments
00137     CANON_C14N_COM              = 2,            // C14n with comments
00138     CANON_C14NE_NOC             = 3,            // C14n Exclusive (without comments)
00139     CANON_C14NE_COM             = 4             // C14n Exlusive (with Comments
00140 };
00141 
00142 enum signatureMethod {
00143 
00144     SIGNATURE_NONE              = 0,            // No method defined
00145     SIGNATURE_DSA               = 1,            // DSA
00146     SIGNATURE_HMAC              = 2,            // Hash MAC
00147     SIGNATURE_RSA               = 3             // RSA
00148 };
00149 
00150 
00151 enum hashMethod {
00152 
00153     HASH_NONE                   = 0,            // No method defined
00154     HASH_SHA1                   = 1,            // SHA1
00155     HASH_MD5                    = 2
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 
00179 // --------------------------------------------------------------------------------
00180 //           Some utility functions
00181 // --------------------------------------------------------------------------------
00182 
00183 inline
00184 bool canonicalizationMethod2URI(safeBuffer &uri, canonicalizationMethod cm) {
00185 
00186     switch (cm) {
00187 
00188     case (CANON_C14N_NOC) :
00189 
00190         uri = URI_ID_C14N_NOC;
00191         break;
00192 
00193     case (CANON_C14N_COM) :
00194 
00195         uri = URI_ID_C14N_COM;
00196         break;
00197 
00198     case (CANON_C14NE_NOC) :
00199 
00200         uri = URI_ID_EXC_C14N_NOC;
00201         break;
00202 
00203     case (CANON_C14NE_COM) :
00204 
00205         uri = URI_ID_EXC_C14N_COM;
00206         break;
00207 
00208     default :
00209         return false;       // Unknown type
00210 
00211     }
00212 
00213     return true;
00214 
00215 }
00216 
00217 inline
00218 bool signatureHashMethod2URI(safeBuffer &uri, signatureMethod sm, hashMethod hm) {
00219 
00220     uri = URI_ID_SIG_BASE;
00221 
00222     switch (sm) {
00223 
00224     case (SIGNATURE_DSA) :
00225 
00226         uri.sbStrcatIn(URI_ID_SIG_DSA);
00227         break;
00228 
00229     case (SIGNATURE_HMAC) :
00230 
00231         uri.sbStrcatIn(URI_ID_SIG_HMAC);
00232         break;
00233 
00234     case (SIGNATURE_RSA) :
00235 
00236         uri.sbStrcatIn(URI_ID_SIG_RSA);
00237         break;
00238 
00239     default :
00240 
00241         return false;
00242 
00243     }
00244 
00245     uri.sbStrcatIn("-");
00246 
00247     switch (hm) {
00248 
00249     case (HASH_SHA1) :
00250 
00251         uri.sbStrcatIn(URI_ID_SIG_SHA1);
00252         break;
00253 
00254     default:
00255 
00256         return false;
00257 
00258     }
00259 
00260     return true;
00261 
00262 }
00263 
00264 inline
00265 bool hashMethod2URI(safeBuffer &uri, hashMethod hm) {
00266 
00267     switch (hm) {
00268 
00269     case (HASH_SHA1) :
00270 
00271         uri = URI_ID_SHA1;
00272         break;
00273 
00274     case (HASH_MD5) :
00275 
00276         uri = URI_ID_MD5;
00277         break;
00278 
00279     default:
00280         return false;
00281 
00282     }
00283 
00284     return true;
00285 
00286 }
00287 
00288 // --------------------------------------------------------------------------------
00289 //           Constant Strings Class
00290 // --------------------------------------------------------------------------------
00291 
00292 class DSIG_EXPORT DSIGConstants {
00293 
00294 public:
00295 
00296     // General strings
00297 
00298     static const XMLCh * s_unicodeStrEmpty;     // ""
00299     static const XMLCh * s_unicodeStrNL;            // "\n"
00300     static const XMLCh * s_unicodeStrXmlns;     // "xmlns"
00301 
00302     // DSIG Element Strings
00303     static const XMLCh * s_unicodeStrAlgorithm;
00304 
00305     // URI_IDs
00306     static const XMLCh * s_unicodeStrURIDSIG;
00307     static const XMLCh * s_unicodeStrURIEC;
00308     static const XMLCh * s_unicodeStrURIXPF;
00309 
00310     static const XMLCh * s_unicodeStrURIRawX509;
00311     static const XMLCh * s_unicodeStrURISHA1;
00312     static const XMLCh * s_unicodeStrURIMD5;        // Not recommended
00313     static const XMLCh * s_unicodeStrURIBASE64;
00314     static const XMLCh * s_unicodeStrURIXPATH;
00315     static const XMLCh * s_unicodeStrURIXSLT;
00316     static const XMLCh * s_unicodeStrURIENVELOPE;
00317     static const XMLCh * s_unicodeStrURIC14N_NOC;
00318     static const XMLCh * s_unicodeStrURIC14N_COM;
00319     static const XMLCh * s_unicodeStrURIEXC_C14N_NOC;
00320     static const XMLCh * s_unicodeStrURIEXC_C14N_COM;
00321     static const XMLCh * s_unicodeStrURIDSA_SHA1;
00322     static const XMLCh * s_unicodeStrURIRSA_SHA1;
00323     static const XMLCh * s_unicodeStrURIHMAC_SHA1;
00324     static const XMLCh * s_unicodeStrURIXMLNS;
00325     static const XMLCh * s_unicodeStrURIMANIFEST;
00326 
00327     // Internal Crypto Providers
00328     static const XMLCh * s_unicodeStrPROVOpenSSL;
00329     static const XMLCh * s_unicodeStrPROVWinCAPI;
00330 
00331 
00332     DSIGConstants();
00333 
00334     static void create();
00335     static void destroy();
00336 
00337 };
00338 
00339 
00340 
00341 
00342 inline
00343 const XMLCh * canonicalizationMethod2UNICODEURI(canonicalizationMethod cm) {
00344 
00345     switch (cm) {
00346 
00347     case (CANON_C14N_NOC) :
00348 
00349         return DSIGConstants::s_unicodeStrURIC14N_NOC;
00350         break;
00351 
00352     case (CANON_C14N_COM) :
00353 
00354         return DSIGConstants::s_unicodeStrURIC14N_COM;
00355         break;
00356 
00357     case (CANON_C14NE_NOC) :
00358 
00359         return DSIGConstants::s_unicodeStrURIEXC_C14N_NOC;
00360         break;
00361 
00362     case (CANON_C14NE_COM) :
00363 
00364         return DSIGConstants::s_unicodeStrURIEXC_C14N_COM;
00365         break;
00366 
00367     default :
00368         break;
00369 
00370     }
00371 
00372     return DSIGConstants::s_unicodeStrEmpty;
00373 
00374 }
00375 
00376 #endif /* DSIGCONSTANTS_HEADER */
00377 

Generated on Sat Aug 9 18:36:25 2003 for XML-Security-C by doxygen 1.3.2