blautenb    2003/05/10 00:19:13

  Modified:    c/src/tools/checksig checksig.cpp
  Log:
  Added anonymous resolver for IAIK example
  
  Revision  Changes    Path
  1.18      +121 -5    xml-security/c/src/tools/checksig/checksig.cpp
  
  Index: checksig.cpp
  ===================================================================
  RCS file: /home/cvs/xml-security/c/src/tools/checksig/checksig.cpp,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- checksig.cpp      9 May 2003 12:07:11 -0000       1.17
  +++ checksig.cpp      10 May 2003 07:19:13 -0000      1.18
  @@ -116,6 +116,7 @@
   #include <xercesc/util/XMLException.hpp>
   #include <xercesc/util/XMLUri.hpp>
   #include <xercesc/util/Janitor.hpp>
  +#include <xercesc/framework/URLInputSource.hpp>
   
   XSEC_USING_XERCES(XercesDOMParser);
   XSEC_USING_XERCES(XMLException);
  @@ -169,6 +170,108 @@
   
   #endif
   
  +// 
----------------------------------------------------------------------------
  +//           AnonymousResolver
  +// 
----------------------------------------------------------------------------
  +
  +/*
  + * The anonymous resolver is a very simple resolver used for the IAIK 
  + * anonymousReferenceSignature.xml interop test example.
  + * It simply takes an anonymous (NULL) uri reference and links to the 
  + * relevant file in the data suite
  + */
  +
  +#define anonURI 
"../digestInputs/anonymousReferenceSignature.firstReference.txt"
  +
  +class AnonymousResolver : public XSECURIResolver {
  +
  +public:
  +
  +     AnonymousResolver() {mp_baseURI = NULL;}
  +     virtual ~AnonymousResolver() {};
  +
  +     // Interface method
  +
  +     virtual BinInputStream * resolveURI(const XMLCh * uri);
  + 
  +     // Interface method
  +
  +     virtual XSECURIResolver * clone(void);
  +
  +     // Extra methods
  +
  +     void setBaseURI(const XMLCh * uri);
  +private:
  +     XMLCh * mp_baseURI;
  +};
  +
  +XSECURIResolver * AnonymousResolver::clone(void) {
  +
  +     AnonymousResolver * ret;
  +
  +     ret = new AnonymousResolver();
  +
  +     if (this->mp_baseURI != 0)
  +             ret->mp_baseURI = XMLString::replicate(this->mp_baseURI);
  +     else
  +             ret->mp_baseURI = 0;
  +
  +     return ret;
  +
  +}
  +
  +void AnonymousResolver::setBaseURI(const XMLCh * uri) {
  +
  +     if (mp_baseURI != NULL)
  +             delete[] mp_baseURI;
  +
  +     mp_baseURI = XMLString::replicate(uri);
  +
  +}
  +
  +BinInputStream * AnonymousResolver::resolveURI(const XMLCh * uri) {
  +
  +     XSEC_USING_XERCES(URLInputSource);
  +     XSEC_USING_XERCES(XMLURL);
  +     XSEC_USING_XERCES(BinInputStream);
  +
  +     URLInputSource                  * URLS;         // Use Xerces URL Input 
source
  +     BinInputStream                  * is;           // To handle the actual 
input
  +
  +     if (uri != NULL) {
  +             throw XSECException(XSECException::ErrorOpeningURI,
  +                     "AnonymousResolver - only anonymous references 
supported");
  +     }
  +
  +     if (mp_baseURI == 0) {
  +             URLS = new URLInputSource(XMLURL(MAKE_UNICODE_STRING(anonURI)));
  +     }
  +     else {
  +             URLS = new URLInputSource(XMLURL(XMLURL(mp_baseURI), 
MAKE_UNICODE_STRING(anonURI)));
  +     }
  +
  +     // makeStream can (and is quite likely to) throw an exception
  +     Janitor<URLInputSource> j_URLS(URLS);
  +
  +     is = URLS->makeStream();
  +
  +     if (is == NULL) {
  +
  +             throw XSECException(XSECException::ErrorOpeningURI,
  +                     "An error occurred in AnonymousResolver when opening an 
URLInputStream");
  +
  +     }
  +
  +     return is;
  +}
  +
  +
  +
  +// 
----------------------------------------------------------------------------
  +//           Checksig
  +// 
----------------------------------------------------------------------------
  +
  +
   void printUsage(void) {
   
        cerr << "\nUsage: checksig [options] <input file name>\n\n";
  @@ -201,6 +304,7 @@
        char                                    * hmacKeyStr = NULL;
        XSECCryptoKey                   * key = NULL;
        bool                                    useXSECURIResolver = false;
  +     bool                    useAnonymousResolver = false;
   #if defined(_WIN32)
        HCRYPTPROV                              win32DSSCSP = 0;                
// Crypto Providers
        HCRYPTPROV                              win32RSACSP = 0;                
  @@ -231,6 +335,10 @@
                        useXSECURIResolver = true;
                        paramCount++;
                }
  +             else if (stricmp(argv[paramCount], "--anonymousresolver") == 0 
|| stricmp(argv[paramCount], "-a") ==0) {
  +                     useAnonymousResolver = true;
  +                     paramCount++;
  +             }
   #if defined (HAVE_WINCAPI)
                else if (stricmp(argv[paramCount], "--wincapi") == 0 || 
stricmp(argv[paramCount], "-w") == 0 ||
                        stricmp(argv[paramCount], "--winhmackey") == 0 || 
stricmp(argv[paramCount], "-wh") == 0) {
  @@ -441,7 +549,7 @@
        // Check whether we should use the internal resolver
   
        
  -     if (useXSECURIResolver == true) {
  +     if (useXSECURIResolver == true || useAnonymousResolver == true) {
   
   #if defined(_WIN32)
                XSECURIResolverGenericWin32 
  @@ -449,6 +557,8 @@
                XSECURIResolverGenericUnix 
   #endif
                        theResolver;
  +
  +             AnonymousResolver theAnonymousResolver;
                     
                // Map out base path of the file
                char path[_MAX_PATH];
  @@ -484,9 +594,15 @@
   
                XMLUri uri(MAKE_UNICODE_STRING(baseURI));
   
  -             theResolver.setBaseURI(uri.getUriText());
  -
  -             sig->setURIResolver(&theResolver);
  +             if (useAnonymousResolver == true) {
  +                     // AnonymousResolver takes precedence
  +                     theAnonymousResolver.setBaseURI(uri.getUriText());
  +                     sig->setURIResolver(&theAnonymousResolver);
  +             }
  +             else {
  +                     theResolver.setBaseURI(uri.getUriText());
  +                     sig->setURIResolver(&theResolver);
  +             }
        }
   
   
  
  
  

Reply via email to