]> WPIA git - cassiopeia.git/blobdiff - src/util.cpp
add: Initial code to implement revocation
[cassiopeia.git] / src / util.cpp
index 13443af321f7f183cb5c907e744e98740c775bfc..36f2261d62e9852477c15b2a034f091b26def049 100644 (file)
@@ -1,8 +1,10 @@
 #include "util.h"
 
+#include <sys/stat.h>
+
 #include <fstream>
 
-void writeFile( const std::string& name, const std::string& content ) {
+void writeFile( std::string name, std::string content ) {
     std::ofstream file;
 
     file.open( name );
@@ -17,3 +19,24 @@ std::string readFile( const std::string& name ) {
 
     return res;
 }
+
+std::string writeBackFile( std::string serial, std::string cert, std::string keydir ) {
+    std::string filename = keydir;
+    mkdir( filename.c_str(), 0755 );
+    filename += "/crt";
+    mkdir( filename.c_str(), 0755 );
+    std::string first;
+
+    if( serial.length() < 3 ) {
+        first = "0";
+    } else {
+        first = serial.substr( 0, serial.length() - 3 );
+    }
+
+    filename += "/" + first;
+    mkdir( filename.c_str(), 0755 );
+    filename += "/" + serial + ".crt";
+    writeFile( filename, cert );
+
+    return filename;
+}