Back to index

nordugrid-arc-nox  1.1.0~rc6
testproxy.cpp
Go to the documentation of this file.
00001 #ifdef HAVE_CONFIG_H
00002 #include <config.h>
00003 #endif
00004 
00005 #include <string>
00006 #include <iostream>
00007 #include <fstream>
00008 #include <arc/Logger.h>
00009 #include "VOMSUtil.h"
00010 #include "Credential.h"
00011 
00012 
00013 int main(void) {
00014   Arc::LogStream cdest(std::cerr);
00015   Arc::Logger::getRootLogger().addDestination(cdest);
00016   Arc::Logger::getRootLogger().setThreshold(Arc::VERBOSE);
00017 
00018   std::string cert("../../../tests/echo/testcert.pem"); 
00019   std::string key("../../../tests/echo/testkey-nopass.pem");
00020   std::string cafile("../../../tests/echo/testcacert.pem"); 
00021   std::string cadir("../../../tests/echo/certificates");
00022 
00023   int keybits = 1024;
00024   int proxydepth = 10;
00025 
00026   Arc::Time t;
00027 
00032   //Request side
00033   BIO* req;
00034   req = BIO_new(BIO_s_mem());
00035   //Arc::Credential request(t, Arc::Period(24*3600), keybits,  "rfc", "independent");
00036   Arc::Credential request(t,0,keybits);
00037   request.GenerateRequest(req);
00038 
00039   //Signing side
00040   BIO* out; 
00041   out = BIO_new(BIO_s_mem());
00042   Arc::Credential proxy;
00043 
00044   Arc::Credential signer(cert, key, cadir, cafile); 
00045   std::string dn_name = signer.GetDN();
00046   std::cout<<"DN:--"<<dn_name<<std::endl;
00047 
00048   proxy.InquireRequest(req);
00049   proxy.SetProxyPolicy("rfc","independent","",-1);
00050   proxy.SetLifeTime(Arc::Period(24*3600));
00051   signer.SignRequest(&proxy, out);
00052 
00053   BIO_free_all(req);
00054   BIO_free_all(out);
00055 
00056 
00058   //Request side
00059   std::string req_string;
00060   std::string out_string;
00061   Arc::Credential request1(t,0, keybits);
00062   request1.GenerateRequest(req_string);
00063   std::cout<<"Certificate request: "<<req_string<<std::endl;
00064 
00065   //Signing side
00066   Arc::Credential proxy1;
00067   proxy1.InquireRequest(req_string);
00068   proxy1.SetProxyPolicy("rfc","independent","",-1);
00069   proxy1.SetLifeTime(Arc::Period(12*3600));
00070   signer.SignRequest(&proxy1, out_string);
00071   
00072   std::string signing_cert1;
00073   signer.OutputCertificate(signing_cert1);
00074 
00075   //Back to request side, compose the signed proxy certificate, local private key, 
00076   //and signing certificate into one file.
00077   std::string private_key1;
00078   request1.OutputPrivatekey(private_key1);
00079   out_string.append(private_key1);
00080   out_string.append(signing_cert1);
00081   std::cout<<"Final proxy certificate: " <<out_string<<std::endl;
00082 
00083 
00085   //Request side
00086   std::string req_file("./request.pem");
00087   std::string out_file("./out.pem");
00088   //Arc::Credential request2(t, Arc::Period(168*3600), keybits, "rfc", "inheritAll", "policy.txt", proxydepth);
00089   Arc::Credential request2(t,0, keybits);
00090   request2.GenerateRequest(req_file.c_str());
00091 
00092   //Signing side
00093   Arc::Credential proxy2;
00094   proxy2.InquireRequest(req_file.c_str());
00095   proxy2.SetProxyPolicy("rfc", "inheritall", "policy.txt", proxydepth);
00096   proxy2.SetLifeTime(Arc::Period(168*3600));
00097   signer.SignRequest(&proxy2, out_file.c_str());
00098 
00099   //Back to request side, compose the signed proxy certificate, local private key,
00100   //and signing certificate into one file.
00101   std::string private_key2, signing_cert2, signing_cert2_chain;
00102   request2.OutputPrivatekey(private_key2);
00103   signer.OutputCertificate(signing_cert2);
00104   signer.OutputCertificateChain(signing_cert2_chain);
00105   std::ofstream out_f(out_file.c_str(), std::ofstream::app);
00106   out_f.write(private_key2.c_str(), private_key2.size());
00107   out_f.write(signing_cert2.c_str(), signing_cert2.size());
00108   out_f.write(signing_cert2_chain.c_str(), signing_cert2_chain.size());
00109   out_f.close();
00110 
00111   return 0;
00112 }