Back to index

nordugrid-arc-nox  1.1.0~rc6
test_x509token.cpp
Go to the documentation of this file.
00001 #ifdef HAVE_CONFIG_H
00002 #include <config.h>
00003 #endif
00004 
00005 #include <iostream>
00006 #include <fstream>
00007 
00008 #include <arc/xmlsec/XmlSecUtils.h>
00009 #include "X509Token.h"
00010 
00011 int main(void) {
00012   std::string xml("\
00013 <S:Envelope xmlns:S=\"http://www.w3.org/2003/05/soap-envelope\"\
00014   xmlns:wsa=\"http://www.w3.org/2005/08/addressing\"\
00015   xmlns:wsu=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\">\
00016   <S:Header>\
00017   </S:Header>\
00018   <S:Body>\
00019     <f:Delete xmlns:f=\"http://example.com/fabrikam\">\
00020        <maxCount>42</maxCount>\
00021     </f:Delete>\
00022   </S:Body>\
00023 </S:Envelope>\
00024 ");
00025 
00026   Arc::init_xmlsec();
00027 
00028   std::string cert = "../../../tests/echo/testcert.pem";
00029   std::string key = "../../../tests/echo/testkey-nopass.pem";  
00030 
00031   /*Generate the signature X509 Token*/
00032   Arc::SOAPEnvelope soap1(xml);
00033   Arc::X509Token xt1(soap1, cert, key);
00034 
00035   std::string str;
00036   xt1.GetXML(str);
00037   std::cout<<"SOAP message with X509Token for signature:"<<std::endl<<str<<std::endl<<std::endl;
00038 
00039   /*Parse the X509 Token*/
00040   Arc::SOAPEnvelope soap2(str);
00041   Arc::X509Token xt2(soap2);
00042   if(!xt2) {
00043     std::cout<<"Failed parsing previously generated X509Token"<<std::endl<<std::endl;
00044   } else if(!xt2.Authenticate() || !xt2.Authenticate("../../../tests/echo/testcacert.pem", "")) {
00045     std::cout<<"Failed to authenticate to previously generated X509Token"<<std::endl<<std::endl;
00046   }
00047 
00048   /*Generate the encryption X509 Token*/
00049   Arc::SOAPEnvelope soap3(xml);
00050   Arc::X509Token xt3(soap3, cert, "", Arc::X509Token::Encryption);
00051 
00052   xt3.GetXML(str);
00053   std::cout<<"SOAP message with X509Token and encrypted body: "<<std::endl<<str<<std::endl<<std::endl;
00054 
00055   /*Parse the encryption x509 token*/
00056   Arc::SOAPEnvelope soap4(str);
00057   soap4.GetXML(str);
00058   std::cout<<"SOAP message with X509Token and encrypted body: "<<std::endl<<str<<std::endl<<std::endl;
00059 
00060   Arc::X509Token xt4(soap4, key);
00061 
00062   xt4.GetXML(str);
00063   std::cout<<"SOAP message with decrypted body: "<<std::endl<<str<<std::endl<<std::endl;
00064  
00065   Arc::final_xmlsec();
00066   return 0;
00067 }
00068