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/PathUtils.hpp>
00010 #include <limal/Exception.hpp>
00011 #include <limal/ByteBuffer.hpp>
00012 #include <limal/ca-mgm/CA.hpp>
00013 #include <limal/ca-mgm/LocalManagement.hpp>
00014
00015 #include <iostream>
00016 #include <fstream>
00017 #include <unistd.h>
00018
00019 using namespace blocxx;
00020 using namespace limal;
00021 using namespace limal::ca_mgm;
00022 using namespace std;
00023
00024 int main()
00025 {
00026 try
00027 {
00028 blocxx::StringArray cat;
00029 cat.push_back("FATAL");
00030 cat.push_back("ERROR");
00031 cat.push_back("INFO");
00032
00033
00034
00035 LoggerRef l = limal::Logger::createCerrLogger(
00036 "Export",
00037 LogAppender::ALL_COMPONENTS,
00038 cat,
00039 "%-5p %c - %m"
00040 );
00041 limal::Logger::setDefaultLogger(l);
00042
00043 CA ca("MyRootCA", "system");
00044
00045
00046
00047
00048 ByteBuffer ba = ca.exportCACert(E_PEM);
00049
00050
00051
00052
00053 ba = ca.exportCACert(E_DER);
00054
00055
00056
00057
00058 ba = ca.exportCAKeyAsPEM("");
00059
00060 LocalManagement::writeFile(ba, "./CAKey.key");
00061
00062
00063
00064
00065 ba = ca.exportCAKeyAsPEM("tralla");
00066
00067 LocalManagement::writeFile(ba, "./CAKey2.key");
00068
00069
00070
00071
00072 ba = ca.exportCAKeyAsDER();
00073
00074 LocalManagement::writeFile(ba, "./CAKeyDER.key");
00075
00076
00077
00078
00079 ba = ca.exportCAasPKCS12("tralla", false);
00080
00081 LocalManagement::writeFile(ba, "./CA.p12");
00082
00083
00084
00085
00086 ba = ca.exportCAasPKCS12("tralla", true);
00087
00088 LocalManagement::writeFile(ba, "./TestRepos3/testCAChain.p12");
00089
00090
00091
00092 CA ca2("MyUserCA", "system");
00093
00094
00095
00096 ba = ca2.exportCertificate("01:9528e1d8783f83b662fca6085a8c1467-1111161258",
00097 E_PEM);
00098
00099
00100
00101
00102 ba = ca2.exportCertificate("01:9528e1d8783f83b662fca6085a8c1467-1111161258",
00103 E_DER);
00104
00105
00106
00107
00108 ba = ca2.exportCertificateKeyAsPEM("01:9528e1d8783f83b662fca6085a8c1467-1111161258",
00109 "system", "");
00110
00111 LocalManagement::writeFile(ba, "./Key.key");
00112
00113
00114
00115
00116 ba = ca2.exportCertificateKeyAsPEM("01:9528e1d8783f83b662fca6085a8c1467-1111161258",
00117 "system", "tralla");
00118
00119 LocalManagement::writeFile(ba, "./Key2.key");
00120
00121
00122
00123
00124 ba = ca2.exportCertificateKeyAsDER("01:9528e1d8783f83b662fca6085a8c1467-1111161258",
00125 "system");
00126
00127 LocalManagement::writeFile(ba, "./TestRepos3/KeyDER.key");
00128
00129
00130
00131
00132 ba = ca2.exportCertificateAsPKCS12("01:9528e1d8783f83b662fca6085a8c1467-1111161258",
00133 "system", "tralla", false);
00134
00135 LocalManagement::writeFile(ba, "./Cert.p12");
00136
00137
00138
00139
00140 ba = ca2.exportCertificateAsPKCS12("01:9528e1d8783f83b662fca6085a8c1467-1111161258",
00141 "system", "tralla", true);
00142
00143 LocalManagement::writeFile(ba, "./TestRepos3/CertChain.p12");
00144
00145
00146
00147
00148 ba = ca2.exportCRL(E_PEM);
00149
00150
00151
00152
00153 ba = ca2.exportCRL(E_DER);
00154
00155 }
00156 catch(Exception& e)
00157 {
00158 cerr << e << endl;
00159 }
00160
00161 return 0;
00162 }
00163
00164