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 2004/06/09 06:06:23 UTC
cvs commit: xml-security/c/src/tools/xklient xklient.cpp
blautenb 2004/06/08 21:06:23
Modified: c/src/tools/xklient xklient.cpp
Log:
Xklient will now create a request and process the result
Revision Changes Path
1.4 +215 -51 xml-security/c/src/tools/xklient/xklient.cpp
Index: xklient.cpp
===================================================================
RCS file: /home/cvs/xml-security/c/src/tools/xklient/xklient.cpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- xklient.cpp 20 Apr 2004 12:28:29 -0000 1.3
+++ xklient.cpp 9 Jun 2004 04:06:23 -0000 1.4
@@ -30,6 +30,7 @@
#include <xsec/canon/XSECC14n20010315.hpp>
#include <xsec/dsig/DSIGSignature.hpp>
#include <xsec/dsig/DSIGKeyInfoX509.hpp>
+#include <xsec/dsig/DSIGKeyInfoValue.hpp>
#include <xsec/framework/XSECException.hpp>
#include <xsec/enc/XSECCryptoException.hpp>
#include <xsec/utils/XSECDOMUtils.hpp>
@@ -37,7 +38,9 @@
#include <xsec/xkms/XKMSMessageAbstractType.hpp>
#include <xsec/xkms/XKMSLocateRequest.hpp>
+#include <xsec/xkms/XKMSLocateResult.hpp>
#include <xsec/xkms/XKMSQueryKeyBinding.hpp>
+#include <xsec/xkms/XKMSConstants.hpp>
#include <xsec/utils/XSECSOAPRequestorSimple.hpp>
@@ -108,6 +111,8 @@
char * g_certFile = NULL;
bool g_txtOut = false;
+int doParsedMsgDump(DOMDocument * doc);
+
// --------------------------------------------------------------------------------
// General functions
// --------------------------------------------------------------------------------
@@ -281,13 +286,29 @@
}
XSECSOAPRequestorSimple req(MAKE_UNICODE_STRING(g_serviceURI));
- req.doRequest(doc);
+ DOMDocument * responseDoc = req.doRequest(doc);
+ // Cleanup request stuff
delete msg;
doc->release();
- return 0;
+ // Now lets process the result
+ int ret;
+
+ try {
+ if (g_txtOut) {
+ outputDoc(responseDoc);
+ }
+ ret = doParsedMsgDump(responseDoc);
+ }
+ catch (...) {
+ responseDoc->release();
+ throw;
+ }
+
+ responseDoc->release();
+ return ret;
}
// --------------------------------------------------------------------------------
@@ -364,18 +385,111 @@
}
-void doKeyBindingDump(XKMSKeyBindingAbstractType * msg, int level) {
+void doResultTypeDump(XKMSResultType *msg, int level) {
+
+ const XMLCh * rid = msg->getRequestId();
+ char * s;
+
+ if (rid != NULL) {
+ levelSet(level);
+ cout << "Result is in response to MsgID : ";
+ s = XMLString::transcode(rid);
+ cout << s << endl;
+ XMLString::release(&s);
+ }
- cout << endl;
levelSet(level);
- cout << "Key Binding found." << endl;
+ cout << "Result Major code = ";
+ s = XMLString::transcode(XKMSConstants::s_tagResultMajorCodes[msg->getResultMajor()]);
+ cout << s << endl;
+ XMLString::release(&s);
+
+ XKMSResultType::ResultMinor rm = msg->getResultMinor();
+ if (rm != XKMSResultType::NoneMinor) {
+ levelSet(level);
+ cout << "Result Minor code = ";
+ char * s = XMLString::transcode(XKMSConstants::s_tagResultMinorCodes[rm]);
+ cout << s << endl;
+ XMLString::release(&s);
+ }
+
+}
+
+void doKeyInfoDump(DSIGKeyInfoList * l, int level) {
+
+
+ int size = l->getSize();
+
+ for (int i = 0 ; i < size ; ++ i) {
+
+ DSIGKeyInfoValue * kiv;
+ char * b;
+
+ DSIGKeyInfo * ki = l->item(i);
+
+ switch (ki->getKeyInfoType()) {
+
+ case DSIGKeyInfo::KEYINFO_VALUE_RSA :
+
+ kiv = (DSIGKeyInfoValue *) ki;
+ levelSet(level);
+ cout << "RSA Key Value" << endl;
+
+ levelSet(level+1);
+ b = XMLString::transcode(kiv->getRSAExponent());
+ cout << "Base64 encoded exponent = " << b << endl;
+ delete[] b;
+
+ levelSet(level+1);
+ b = XMLString::transcode(kiv->getRSAModulus());
+ cout << "Base64 encoded modulus = " << b << endl;
+ delete[] b;
+
+ break;
+
+ case DSIGKeyInfo::KEYINFO_VALUE_DSA :
+
+ kiv = (DSIGKeyInfoValue *) ki;
+ levelSet(level);
+ cout << "DSA Key Value" << endl;
+
+ levelSet(level+1);
+ b = XMLString::transcode(kiv->getDSAG());
+ cout << "G = " << b << endl;
+ delete[] b;
+
+ levelSet(level+1);
+ b = XMLString::transcode(kiv->getDSAP());
+ cout << "P = " << b << endl;
+ delete[] b;
+
+ levelSet(level+1);
+ b = XMLString::transcode(kiv->getDSAQ());
+ cout << "Q = " << b << endl;
+ delete[] b;
+
+ levelSet(level+1);
+ b = XMLString::transcode(kiv->getDSAY());
+ cout << "Y = " << b << endl;
+ delete[] b;
+
+ break;
+
+ default:
- if (msg->getKeyInfoList() != NULL) {
+ levelSet(level);
+ cout << "Unknown KeyInfo type" << endl;
- levelSet(level+1);
- cout << "Has KeyInfo element" << endl;
+ }
}
+}
+
+
+void doKeyBindingDump(XKMSKeyBindingAbstractType * msg, int level) {
+
+ levelSet(level);
+ cout << "Key Binding found." << endl;
levelSet(level+1);
cout << "KeyUsage Encryption : ";
@@ -398,8 +512,21 @@
else
cout << "no" << endl;
+ // Now dump any KeyInfo
+ levelSet(level+1);
+ cout << "KeyInfo information:" << endl << endl;
+
+ doKeyInfoDump(msg->getKeyInfoList(), level + 2);
+
}
+void doUnverifiedKeyBindingDump(XKMSUnverifiedKeyBinding * ukb, int level) {
+
+ doKeyBindingDump((XKMSKeyBindingAbstractType *) ukb, level);
+
+}
+
+
int doLocateRequestDump(XKMSLocateRequest *msg) {
cout << endl << "This is a LocateRequest Message" << endl;
@@ -415,65 +542,40 @@
return 0;
}
+int doLocateResultDump(XKMSLocateResult *msg) {
-int doMsgDump(void) {
-
- // Dump the details of an XKMS message to the console
- cout << "Decoding XKMS Message contained in " << g_inputFile << endl;
+ cout << endl << "This is a LocateResult Message" << endl;
+ int level = 1;
- // Create and set up the parser
+ doMessageAbstractTypeDump(msg, level);
+ doResultTypeDump(msg, level);
- XercesDOMParser * parser = new XercesDOMParser;
- Janitor<XercesDOMParser> j_parser(parser);
+ int j;
- parser->setDoNamespaces(true);
- parser->setCreateEntityReferenceNodes(true);
+ if ((j = msg->getUnverifiedKeyBindingSize()) > 0) {
- // Now parse out file
+ cout << endl;
+ levelSet(level);
+ cout << "Unverified Key Bindings" << endl << endl;
- bool errorsOccured = false;
- int errorCount = 0;
- try
- {
- parser->parse(g_inputFile);
- errorCount = parser->getErrorCount();
- }
-
- catch (const XMLException& e)
- {
- char * msg = XMLString::transcode(e.getMessage());
- cerr << "An error occured during parsing\n Message: "
- << msg << endl;
- XMLString::release(&msg);
- errorsOccured = true;
- }
+ for (int i = 0; i < j ; ++i) {
+ doUnverifiedKeyBindingDump(msg->getUnverifiedKeyBindingItem(i), level + 1);
- catch (const DOMException& e)
- {
- cerr << "A DOM error occured during parsing\n DOMException code: "
- << e.code << endl;
- errorsOccured = true;
- }
-
- if (errorCount > 0 || errorsOccured) {
-
- cout << "Errors during parse" << endl;
- return (2);
+ }
}
- /*
+ return 0;
+}
- Now that we have the parsed file, get the DOM document and start looking at it
- */
-
- DOMDocument *doc = parser->getDocument();
+int doParsedMsgDump(DOMDocument * doc) {
// Get an XKMS Message Factory
XSECProvider prov;
XKMSMessageFactory * factory = prov.getXKMSMessageFactory();
+ int errorsOccured;
try {
@@ -517,6 +619,11 @@
doLocateRequestDump(dynamic_cast<XKMSLocateRequest *>(msg));
break;
+ case XKMSMessageAbstractType::LocateResult :
+
+ doLocateResultDump(dynamic_cast<XKMSLocateResult *>(msg));
+ break;
+
default :
cout << "Unknown message type!" << endl;
@@ -560,7 +667,64 @@
// Clean up
return 0;
+}
+
+int doMsgDump(void) {
+
+ // Dump the details of an XKMS message to the console
+ cout << "Decoding XKMS Message contained in " << g_inputFile << endl;
+
+ // Create and set up the parser
+
+ XercesDOMParser * parser = new XercesDOMParser;
+ Janitor<XercesDOMParser> j_parser(parser);
+
+ parser->setDoNamespaces(true);
+ parser->setCreateEntityReferenceNodes(true);
+
+ // Now parse out file
+
+ bool errorsOccured = false;
+ int errorCount = 0;
+ try
+ {
+ parser->parse(g_inputFile);
+ errorCount = parser->getErrorCount();
+ }
+
+ catch (const XMLException& e)
+ {
+ char * msg = XMLString::transcode(e.getMessage());
+ cerr << "An error occured during parsing\n Message: "
+ << msg << endl;
+ XMLString::release(&msg);
+ errorsOccured = true;
+ }
+
+
+ catch (const DOMException& e)
+ {
+ cerr << "A DOM error occured during parsing\n DOMException code: "
+ << e.code << endl;
+ errorsOccured = true;
+ }
+
+ if (errorCount > 0 || errorsOccured) {
+
+ cout << "Errors during parse" << endl;
+ return (2);
+
+ }
+
+ /*
+
+ Now that we have the parsed file, get the DOM document and start looking at it
+
+ */
+
+ DOMDocument *doc = parser->getDocument();
+ return doParsedMsgDump(doc);
}