You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@santuario.apache.org by bl...@apache.org on 2003/02/17 12:22:40 UTC
cvs commit: xml-security/c/src/tools/txfmout txfmout.cpp
blautenb 2003/02/17 03:22:39
Modified: c/src/tools/checksig checksig.cpp
c/src/tools/txfmout txfmout.cpp
Log:
Now handle relative file URIs in references
Revision Changes Path
1.5 +46 -9 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.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- checksig.cpp 12 Feb 2003 11:21:03 -0000 1.4
+++ checksig.cpp 17 Feb 2003 11:22:39 -0000 1.5
@@ -67,6 +67,9 @@
* $Id$
*
* $Log$
+ * Revision 1.5 2003/02/17 11:22:39 blautenb
+ * Now handle relative file URIs in references
+ *
* Revision 1.4 2003/02/12 11:21:03 blautenb
* UNIX generic URI resolver
*
@@ -99,6 +102,7 @@
#include <string.h>
#include <iostream.h>
#include <stdlib.h>
+#include <direct.h>
#if defined (_DEBUG) && defined (_MSC_VER)
#include <crtdbg.h>
@@ -111,11 +115,15 @@
#include <xercesc/dom/DOM.hpp>
#include <xercesc/parsers/XercesDOMParser.hpp>
#include <xercesc/util/XMLException.hpp>
+#include <xercesc/util/XMLUri.hpp>
+#include <xercesc/util/Janitor.hpp>
XSEC_USING_XERCES(XercesDOMParser);
XSEC_USING_XERCES(XMLException);
XSEC_USING_XERCES(XMLPlatformUtils);
XSEC_USING_XERCES(DOMException);
+XSEC_USING_XERCES(XMLUri);
+XSEC_USING_XERCES(Janitor);
#ifndef XSEC_NO_XALAN
@@ -210,7 +218,8 @@
// Create and set up the parser
XercesDOMParser * parser = new XercesDOMParser;
-
+ Janitor<XercesDOMParser> j_parser(parser);
+
parser->setDoNamespaces(true);
parser->setCreateEntityReferenceNodes(true);
@@ -269,7 +278,7 @@
if (sigNode == 0) {
cerr << "Could not find <Signature> node in " << argv[argc-1] << endl;
- exit(2);
+ return 2;
}
XSECProvider prov;
@@ -294,6 +303,36 @@
#endif
theResolver;
+ // Map out base path of the file
+ char path[_MAX_PATH];
+ char baseURI[(_MAX_PATH * 2) + 10];
+ getcwd(path, _MAX_PATH);
+
+ strcpy(baseURI, "file:///");
+ strcat(baseURI, path);
+ strcat(baseURI, "/");
+ strcat(baseURI, filename);
+
+ // Find any ':' and "\" characters
+ int lastSlash;
+ for (int i = 8; i < strlen(baseURI); ++i) {
+// if (path[i] == ':')
+// path[i] = '|';
+ if (baseURI[i] == '\\') {
+ lastSlash = i;
+ baseURI[i] = '/';
+ }
+ else if (baseURI[i] == '/')
+ lastSlash = i;
+ }
+
+ // The last "\\" must prefix the filename
+ baseURI[lastSlash + 1] = '\0';
+
+ XMLUri uri(MAKE_UNICODE_STRING(baseURI));
+
+ theResolver.setBaseURI(uri.getUriText());
+
sig->setURIResolver(&theResolver);
}
@@ -325,7 +364,7 @@
<< msg << endl;
delete [] msg;
errorsOccured = true;
- exit (2);
+ return 2;
}
catch (XSECCryptoException &e) {
cerr << "An error occured during signature verification\n Message: "
@@ -338,7 +377,7 @@
BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT);
ERR_print_errors(bio_err);
- exit (2);
+ return 2;
}
int retResult;
@@ -357,9 +396,7 @@
}
prov.releaseSignature(sig);
-
- delete parser;
-
+ // Janitor will clean up the parser
return retResult;
}
1.3 +49 -2 xml-security/c/src/tools/txfmout/txfmout.cpp
Index: txfmout.cpp
===================================================================
RCS file: /home/cvs/xml-security/c/src/tools/txfmout/txfmout.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- txfmout.cpp 9 Feb 2003 11:13:51 -0000 1.2
+++ txfmout.cpp 17 Feb 2003 11:22:39 -0000 1.3
@@ -65,9 +65,12 @@
*
* Author(s): Berin Lautenbach
*
- * $ID$
+ * $Id$
+ *
+ * $Log$
+ * Revision 1.3 2003/02/17 11:22:39 blautenb
+ * Now handle relative file URIs in references
*
- * $LOG$
*
*/
@@ -84,12 +87,19 @@
#include <xsec/enc/OpenSSL/OpenSSLCryptoKeyHMAC.hpp>
#include <xsec/utils/XSECBinTXFMInputStream.hpp>
+#if defined(_WIN32)
+#include <xsec/utils/winutils/XSECURIResolverGenericWin32.hpp>
+#else
+#include <xsec/utils/unixutils/XSECURIResolverGenericUnix.hpp>
+#endif
+
// General
#include <memory.h>
#include <string.h>
#include <iostream.h>
#include <stdlib.h>
+#include <direct.h>
#include <xercesc/util/PlatformUtils.hpp>
#include <xercesc/util/XMLString.hpp>
@@ -98,12 +108,14 @@
#include <xercesc/parsers/XercesDOMParser.hpp>
#include <xercesc/util/XMLException.hpp>
#include <xercesc/util/XMLNetAccessor.hpp>
+#include <xercesc/util/XMLUri.hpp>
XSEC_USING_XERCES(NetAccessorException);
XSEC_USING_XERCES(DOMException);
XSEC_USING_XERCES(XMLException);
XSEC_USING_XERCES(XercesDOMParser);
XSEC_USING_XERCES(XMLPlatformUtils);
+XSEC_USING_XERCES(XMLUri);
#ifndef XSEC_NO_XALAN
@@ -519,6 +531,44 @@
XSECProvider prov;
DSIGSignature * sig = prov.newSignatureFromDOM(theDOM, sigNode);
+
+#if defined(_WIN32)
+ XSECURIResolverGenericWin32
+#else
+ XSECURIResolverGenericUnix
+#endif
+ theResolver;
+
+ // Map out base path of the file
+ char path[_MAX_PATH];
+ char baseURI[(_MAX_PATH * 2) + 10];
+ getcwd(path, _MAX_PATH);
+
+ strcpy(baseURI, "file:///");
+ strcat(baseURI, path);
+ strcat(baseURI, "/");
+ strcat(baseURI, filename);
+
+ // Find any ':' and "\" characters
+ int lastSlash;
+ for (int i = 8; i < strlen(baseURI); ++i) {
+ if (baseURI[i] == '\\') {
+ lastSlash = i;
+ baseURI[i] = '/';
+ }
+ else if (baseURI[i] == '/')
+ lastSlash = i;
+ }
+
+ // The last "\\" must prefix the filename
+ baseURI[lastSlash + 1] = '\0';
+
+ XMLUri uri(MAKE_UNICODE_STRING(baseURI));
+
+ theResolver.setBaseURI(uri.getUriText());
+
+ sig->setURIResolver(&theResolver);
+
try {