CreateRootCA.cpp

This is an example which shows how to create a root CA.

00001 #include <blocxx/Logger.hpp>
00002 #include <blocxx/AppenderLogger.hpp>
00003 #include <blocxx/CerrLogger.hpp>
00004 #include <blocxx/CerrAppender.hpp>
00005 #include <blocxx/String.hpp>
00006 #include <blocxx/PerlRegEx.hpp>
00007 #include <limal/Logger.hpp>
00008 #include <limal/PathInfo.hpp>
00009 #include <limal/ca-mgm/CA.hpp>
00010 
00011 #include <iostream>
00012 #include <fstream>
00013 #include <unistd.h>
00014 
00015 using namespace blocxx;
00016 using namespace limal;
00017 using namespace limal::ca_mgm;
00018 using namespace std;
00019 
00020 int main()
00021 {
00022     try
00023     {
00024         StringArray cat;
00025         cat.push_back("FATAL");
00026         cat.push_back("ERROR");
00027         cat.push_back("INFO");
00028         //cat.push_back("DEBUG");
00029 
00030         
00031         // Logging
00032         LoggerRef l = limal::Logger::createCerrLogger(
00033                                                       "CreateRootCA",
00034                                                       LogAppender::ALL_COMPONENTS,
00035                                                       cat,
00036                                                       "%-5p %c - %m"
00037                                                   );
00038         limal::Logger::setDefaultLogger(l);
00039         
00040         RequestGenerationData rgd = CA::getRootCARequestDefaults("./TestRepos/");
00041         CertificateIssueData  cid = CA::getRootCAIssueDefaults("./TestRepos/");
00042         
00043         List<RDNObject> dnl = rgd.getSubjectDN().getDN();
00044         List<RDNObject>::iterator dnit;
00045 
00046         for(dnit = dnl.begin(); dnit != dnl.end(); ++dnit)
00047         {
00048             if((*dnit).getType() == "countryName")
00049             {
00050                 (*dnit).setRDNValue("DE");
00051             }
00052             else if((*dnit).getType() == "commonName")
00053             {
00054                 (*dnit).setRDNValue("Test CA");
00055             }
00056             else if((*dnit).getType() == "emailAddress")
00057             {
00058                 (*dnit).setRDNValue("suse@suse.de");
00059             }
00060         }
00061         
00062         DNObject dn(dnl);
00063         rgd.setSubjectDN(dn);
00064         
00065         CA::createRootCA("Test_CA", "system", rgd, cid, "./TestRepos/");
00066 
00067         // The CA request is now available at './TestRepos/Test_CA/cacert.req'
00068         
00069         // The CA private key is now available at './TestRepos/Test_CA/cacert.key'
00070         
00071         // The CA certificate is now available at './TestRepos/Test_CA/cacert.pem'
00072     }
00073     catch(Exception& e)
00074     {
00075         cerr << e << endl;
00076     }
00077 
00078     return 0;
00079 }

Generated on Mon Nov 27 22:50:13 2006 for limal-ca-mgm by  doxygen 1.5.0