Back to index

nordugrid-arc-nox  1.1.0~rc6
testeec.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 "Credential.h"
00010 
00011 int main(void) {
00012   Arc::LogStream cdest(std::cerr);
00013   Arc::Logger::getRootLogger().addDestination(cdest);
00014   Arc::Logger::getRootLogger().setThreshold(Arc::VERBOSE);
00015 
00016   std::string CAcert("./CAcert.pem"); 
00017   std::string CAkey("./CAkey.pem");
00018   std::string CAserial("./CAserial");
00019 
00020   int keybits = 1024;
00021   Arc::Time t;
00022 
00026   //Request side
00027   std::string req_file("./eec_request.pem");
00028   std::string out_certfile("./eec_cert.pem");
00029   std::string out_keyfile("./eec_key.pem");
00030   Arc::Credential request(t, Arc::Period(168*3600), keybits, "EEC");
00031   request.GenerateRequest(req_file.c_str());
00032 
00033   //Signing side
00034   Arc::Credential eec;
00035   eec.InquireRequest(req_file.c_str(), true);
00036   //Add extension: a simple string
00037   std::string ext_data("test extension data");
00038   if(!(eec.AddExtension("1.2.3.4", ext_data))) {
00039     std::cout<<"Failed to add an extension to certificate"<<std::endl;
00040   }
00041   
00042   std::string ca_passphrase = "aa1122";
00043   Arc::Credential signer(CAcert, CAkey, CAserial, 0, "", "", ca_passphrase);
00044   std::string identity_name = signer.GetIdentityName();
00045   std::cout<<"Identity Name: "<<identity_name<<std::endl;
00046 
00047   std::string dn("/O=KnowARC/OU=UIO/CN=Test001");
00048   signer.SignEECRequest(&eec, dn, out_certfile.c_str());
00049 
00050   //Request side, output private key
00051   std::string private_key;
00052   std::string passphrase("12345");
00053   request.OutputPrivatekey(private_key, true, passphrase);
00054   std::ofstream out_f(out_keyfile.c_str());
00055   out_f.write(private_key.c_str(), private_key.size());
00056   out_f.close();
00057 
00058   return 0;
00059 }