Back to index

nordugrid-arc-nox  1.1.0~rc6
test_xmlsecnode.cpp
Go to the documentation of this file.
00001 #ifdef HAVE_CONFIG_H
00002 #include <config.h>
00003 #endif
00004 
00005 #include <arc/XMLNode.h>
00006 #include "XMLSecNode.h"
00007 #include "XmlSecUtils.h"
00008 #include <iostream>
00009 #include <fstream>
00010 #include <string>
00011 #include <list>
00012 #include <map>
00013 
00014 
00015 int main(void)
00016 {
00017     std::string xml_str = "";
00018     std::string str;
00019     std::ifstream f("testxmlsec.xml");
00020 
00021     // load content of file
00022     while (f >> str) {
00023         xml_str.append(str);
00024         xml_str.append(" ");
00025     }
00026     f.close();
00027     
00028     Arc::XMLNode node(xml_str);
00029     node.GetXML(str);
00030     std::cout<<"Original node: "<<std::endl<<str<<std::endl;
00031 
00032     Arc::XMLSecNode secnode(node);
00033 
00034     Arc::init_xmlsec();
00035 
00036     //Sign the node
00037     std::string idname("ID");
00038     secnode.AddSignatureTemplate(idname, Arc::XMLSecNode::RSA_SHA1);  
00039     std::string privkey("../../../tests/echo/testkey-nopass.pem");
00040     std::string cert("../../../tests/echo/testcert.pem");  
00041     if(secnode.SignNode(privkey,cert)) {
00042       std::cout<<"Succeed to sign the signature under the node"<<std::endl;
00043       secnode.GetXML(str);
00044       std::cout<<"Signed node: "<<std::endl<<str<<std::endl;
00045     }
00046     else { Arc::final_xmlsec(); return 0; }
00047    
00048     //Verify the signature
00049     std::string cafile("../../../tests/echo/testcacert.pem");
00050     std::string capath("");
00051     if(secnode.VerifyNode(idname, cafile, capath)) {
00052       std::cout<<"Succeed to verify the signature under the node"<<std::endl;
00053     }
00054 
00055     Arc::final_xmlsec();
00056     return 0;
00057 }
00058