diff options
| -rw-r--r-- | pica-registrar/PICA_registrar.cpp | 46 |
1 files changed, 43 insertions, 3 deletions
diff --git a/pica-registrar/PICA_registrar.cpp b/pica-registrar/PICA_registrar.cpp index 465c9de..9ffba7b 100644 --- a/pica-registrar/PICA_registrar.cpp +++ b/pica-registrar/PICA_registrar.cpp @@ -10,8 +10,11 @@ #include <unistd.h> #include <sys/errno.h> +#include <cstring> #include <map> +using namespace std; + #define PICA_REGISTRAR_PORT 2299 #define READ_BUF_SIZE 4096 char read_buf[READ_BUF_SIZE]; @@ -43,9 +46,10 @@ while (1) if (client_socket >= 0) { pos = 0; + disconnect_flag = 0; do { - ret = recv(client_socket, read_buf + pos, READ_BUF_SIZE - pos, 0); + ret = recv(client_socket, read_buf + pos, READ_BUF_SIZE - 1 - pos, 0); if (ret > 0) pos += ret; @@ -55,10 +59,46 @@ while (1) if (ret < 0) perror("recv"); } - + read_buf[pos + 1] = '\0'; + } + while(pos < READ_BUF_SIZE && !disconnect_flag && !std::strstr(read_buf, "-----END CERTIFICATE REQUEST-----")); + + if (disconnect_flag) + continue; + + { + FILE *csr_temp; + + std::string filename = (string("/tmp/CSR-") + inet_ntoa(sc.sin_addr) ); + + csr_temp = fopen(filename.c_str, "w"); + + if (!csr_temp) + { + perror("fopen"); + continue; } - while(); + + ret = fwrite(read_buf, pos, 1, csr_temp); + + if (ret != 1) + { + perror("fwrite"); + fclose(csr_temp); + remove(filename.c_str); + continue; + } + + fclose(csr_temp); + + //system(openssl ca) + + remove(filename.c_str); + } + } + else + perror("accept"); } |
