This example shows how to export CAs, keys, certificates and CRLs from the repository
#include <blocxx/Logger.hpp>
#include <blocxx/AppenderLogger.hpp>
#include <blocxx/CerrLogger.hpp>
#include <blocxx/CerrAppender.hpp>
#include <blocxx/String.hpp>
#include <blocxx/PerlRegEx.hpp>
#include <limal/Logger.hpp>
#include <limal/PathInfo.hpp>
#include <limal/PathUtils.hpp>
#include <limal/Exception.hpp>
#include <limal/ByteBuffer.hpp>
#include <limal/ca-mgm/CA.hpp>
#include <limal/ca-mgm/LocalManagement.hpp>
#include <iostream>
#include <fstream>
#include <unistd.h>
using namespace blocxx;
using namespace limal;
using namespace limal::ca_mgm;
using namespace std;
int main()
{
try
{
blocxx::StringArray cat;
cat.push_back("FATAL");
cat.push_back("ERROR");
cat.push_back("INFO");
LoggerRef l = limal::Logger::createCerrLogger(
"Export",
LogAppender::ALL_COMPONENTS,
cat,
"%-5p %c - %m"
);
limal::Logger::setDefaultLogger(l);
CA ca("MyRootCA", "system");
ByteBuffer ba = ca.exportCACert(
E_PEM);
ba = ca.exportCACert(
E_DER);
ba = ca.exportCAKeyAsPEM("");
LocalManagement::writeFile(ba, "./CAKey.key");
ba = ca.exportCAKeyAsPEM("tralla");
LocalManagement::writeFile(ba, "./CAKey2.key");
ba = ca.exportCAKeyAsDER();
LocalManagement::writeFile(ba, "./CAKeyDER.key");
ba = ca.exportCAasPKCS12("tralla", false);
LocalManagement::writeFile(ba, "./CA.p12");
ba = ca.exportCAasPKCS12("tralla", true);
LocalManagement::writeFile(ba, "./TestRepos3/testCAChain.p12");
CA ca2("MyUserCA", "system");
ba = ca2.exportCertificate("01:9528e1d8783f83b662fca6085a8c1467-1111161258",
ba = ca2.exportCertificate("01:9528e1d8783f83b662fca6085a8c1467-1111161258",
ba = ca2.exportCertificateKeyAsPEM("01:9528e1d8783f83b662fca6085a8c1467-1111161258",
"system", "");
LocalManagement::writeFile(ba, "./Key.key");
ba = ca2.exportCertificateKeyAsPEM("01:9528e1d8783f83b662fca6085a8c1467-1111161258",
"system", "tralla");
LocalManagement::writeFile(ba, "./Key2.key");
ba = ca2.exportCertificateKeyAsDER("01:9528e1d8783f83b662fca6085a8c1467-1111161258",
"system");
LocalManagement::writeFile(ba, "./TestRepos3/KeyDER.key");
ba = ca2.exportCertificateAsPKCS12("01:9528e1d8783f83b662fca6085a8c1467-1111161258",
"system", "tralla", false);
LocalManagement::writeFile(ba, "./Cert.p12");
ba = ca2.exportCertificateAsPKCS12("01:9528e1d8783f83b662fca6085a8c1467-1111161258",
"system", "tralla", true);
LocalManagement::writeFile(ba, "./TestRepos3/CertChain.p12");
ba = ca2.exportCRL(
E_PEM);
ba = ca2.exportCRL(
E_DER);
}
catch(Exception& e)
{
cerr << e << endl;
}
return 0;
}