]> WPIA git - cassiopeia.git/blobdiff - src/config.cpp
add: Full CRL tranfer (non-chunked)
[cassiopeia.git] / src / config.cpp
index f11edb112838386c74fb970db374397ebd8fe20b..b746bad11a88049338853537be38250c1297bb6a 100644 (file)
@@ -4,10 +4,11 @@
 #include <dirent.h>
 #include <unordered_map>
 
-#include "sslUtil.h"
+#include "crypto/sslUtil.h"
 
 std::string keyDir;
 std::unordered_map<std::string, Profile> profiles;
+std::unordered_map<std::string, std::shared_ptr<CAConfig>> CAs;
 std::string sqlHost, sqlUser, sqlPass, sqlDB;
 std::string serialPath;
 
@@ -45,18 +46,8 @@ std::shared_ptr<std::unordered_map<std::string, std::string>> parseConf( std::st
     return map;
 }
 
-int parseConfig( std::string path ) {
-
-    auto masterConf = parseConf( path );
-
-    keyDir = masterConf->at( "key.directory" );
-    sqlHost = masterConf->at( "sql.host" );
-    sqlUser = masterConf->at( "sql.user" );
-    sqlPass = masterConf->at( "sql.password" );
-    sqlDB = masterConf->at( "sql.database" );
-    serialPath = masterConf->at( "serialPath" );
-
-    std::shared_ptr<std::unordered_map<std::string, std::shared_ptr<CAConfig>>> CAs( new std::unordered_map<std::string, std::shared_ptr<CAConfig>>() );
+int parseProfiles() {
+    CAs = std::unordered_map<std::string, std::shared_ptr<CAConfig>>();
 
     DIR* dp;
     struct dirent* ep;
@@ -97,12 +88,12 @@ int parseConfig( std::string path ) {
         prof.eku = map->at( "eku" );
         prof.ku = map->at( "ku" );
 
-        if( CAs->find( map->at( "ca" ) ) == CAs->end() ) {
-            std::shared_ptr<CAConfig> ca( new CAConfig( "ca/" + map->at( "ca" ) ) );
-            CAs->emplace( map->at( "ca" ), ca );
+        if( CAs.find( map->at( "ca" ) ) == CAs.end() ) {
+            std::shared_ptr<CAConfig> ca( new CAConfig( map->at( "ca" ) ) );
+            CAs.emplace( map->at( "ca" ), ca );
         }
 
-        prof.ca = CAs->at( map->at( "ca" ) );
+        prof.ca = CAs.at( map->at( "ca" ) );
 
         profiles.emplace( profileName, prof );
         std::cout << "Profile: " << profileName << " up and running." << std::endl;
@@ -113,10 +104,28 @@ int parseConfig( std::string path ) {
 
     std::cout << profiles.size() << " profiles loaded." << std::endl;
 
+    return 0;
+}
+
+int parseConfig( std::string path ) {
+
+    auto masterConf = parseConf( path );
+
+    keyDir = masterConf->at( "key.directory" );
+    sqlHost = masterConf->at( "sql.host" );
+    sqlUser = masterConf->at( "sql.user" );
+    sqlPass = masterConf->at( "sql.password" );
+    sqlDB = masterConf->at( "sql.database" );
+    serialPath = masterConf->at( "serialPath" );
+
     if( keyDir == "" ) {
         std::cerr << "Missing config property key.directory" << std::endl;
         return -1;
     }
 
+    if( parseProfiles() != 0 ) {
+        return -1;
+    }
+
     return 0;
 }