📄 caservice.h
字号:
#ifndef __CASERVICE_H_ #define __CASERVICE_H_#include <openssl/evp.h>#include <openssl/bio.h>#include <openssl/x509.h>#include <openssl/x509v3.h>#include <openssl/pkcs12.h>#include <openssl/rand.h>#include <openssl/pem.h>#include <openssl/pkcs7.h>#include <openssl/safestack.h>#include <assert.h>#include <stdlib.h>#include <stdio.h>#include <string.h>#include <stdarg.h>#include <iostream>#include <stddef.h>#include <time.h>#include <sys/types.h>#include <sys/stat.h>#include <unistd.h>#include <sys/types.h>#include <dirent.h>#include "NggObject.h"#include "Communicate.h"#include "CertDB.h"using namespace std;#define writelog(str) \ cout<< "\n" << str <<"--->"<<__FILE__<<" : "<<__LINE__<<"\n"<<endl;#define successlog(str) \ cout<< str << endl;#define Debug() cout<<"----------> Debug "<< __FILE__<< " : " <<__LINE__<<endl;#define UCHAR unsigned char#define DAY 60*60*24#define CA_CONFIG_PATH "./CA.xml"#define K 1024#define YEAR 365#define DER 1#define PEM 3 #define NET 4#define P12 5#define USER_CERTIFICATE 1000#define GW_CERTIFICATE 1001 struct stuSUBJECT{ char countryName[4]; char province[4]; char localityName[12]; char organizationName[48]; char organizationalUnitName[24]; char commonName[12]; char mail[24]; char title[12];// char description[12]; char name[12]; char surname[12]; stuSUBJECT() { memset(this,0,sizeof(stuSUBJECT)); }};struct stuKEYUSAGE{ bool DS;//Digital Signature bool NR;//Non-Repudiation bool KE;//Key Encipherment bool DE;//Data Encipherment bool KA;//keyAgreement bool KC;//keyCertSign bool CS;//cRLSign bool EO;//Encipher Only bool DO;//Decipher Only stuKEYUSAGE() { memset(this,0,sizeof(stuKEYUSAGE)); }};struct stuEKEYUSAGE//增强型密钥用途{ bool SA;//服务器验证 bool CA;//客户端验证 bool CS;//代码签名 bool EP;//安全电子邮件 bool TS;//时间戳 bool msCC;//代码完整 bool msCTLS;//可签名信任列表 bool msSGC;//联机事务处理 bool msEFS;//加密磁盘上的数据 bool msSC;//智能卡登录 bool IP;//Internet stuEKEYUSAGE() { memset(this,0,sizeof(stuEKEYUSAGE)); }};class CAService{public: CAService(); ~CAService(); string importThirdCRL(char* crl, string issuer); bool locateFile(char* filepath); bool initializeConnect(); string exportCRLToUser(string type="local"); bool shutdownConnect(); bool deleteCertFromCRL(string serialNumber, char* result=NULL); string removeUserCertificate(char* serialNumber); void showInformation(); bool issueRootCertificate(char*outMsg, stuSUBJECT *rootinfo, int bits, int days, const char* certFile, const char* privFile, int type=1); bool issueTerminalCertificate(char* outfile="./usercert.cer", char *reqfile=NULL, int type=USER_CERTIFICATE, char* outlist=NULL, int len=0); void sendMessage(); void exportCertificateFromCertList(char* infile=NULL); bool exportCertToUser(string dn="", string name="", string action=""); void initializeEnvironment(); void insertCRL(char* req); void updateCRL(char* req, string action="del"); void print(char* filepath); string verifyCertificate(string data); string getCRL(); private: string exportCertIssuer(); void createCAConfigFile(); void initItem(); bool checkInitialResult(); bool makeRootCert(stuSUBJECT *rootInfo, X509** x, EVP_PKEY** key, int bits, int days, char* outmsg); bool setInfo(X509_NAME* x509name, int type, char* iput); bool makeUserCert(char* outfile="./usercert.cer", char* reqfile=NULL, int type=USER_CERTIFICATE, char* outlist=NULL, int filelen=0); bool checkParameter(char* first, ...); bool checkWhetherUserHaveExisted(const char* DN); bool toBeHandle(string id); bool importCertToDB(X509* cert, string type="user", EVP_PKEY* key=NULL); bool importCertListToDB(string dn, string certlist, string type="user"); bool importCRLToDB(); bool findCertInDB(X509* cert, string type="user"); bool updateCertToDB(X509* cert, string type="user"); string makeCertRevocateList(string serialNumber); string updateUserCert(); void handleMessage(MSG msg); void backup(string src, string dst, string action="cp"); string packMessage(string msg, string result); bool unpackMessage(string msg); X509* load_cert(char * outMsg, BIO *cert, int format, char * pwd); string createCertList(char* outlist=NULL, X509* x509=NULL); string getDN(X509* cert); string getRequestSubject(X509_NAME* name); string m_swap; long m_id; long m_action; int m_type; unsigned long m_serialNumber ; CertDB *m_db; string m_distingishName, m_serial; string m_sn; string m_ObjectUpdated, m_ObjectType, m_CommonName, m_CertReq, m_SerialNumber; string m_Issuer, m_importObject; string analyzeString(string& third); public : Communicate *com; CONTENT getMessageCA(); void freeComm(); EVP_PKEY* loadRootPriv(char * key, int keylen=0, int format=PEM); X509* LoadCert(char * cert,int certlen=0,char * outMsg=NULL); string toString(long value); string readCAconfig(string keyword, string objectName=""); string getIssuer(const char* dn); void setCAConfigItem(string keyword, string object="", string value=""); void setCAConfigSet(string keyword, string object, string value); void printCert(X509* x509); void sendMessageCA(CONTENT msg); void getCurrentTime(int& year, int& month, int& day); char* m_rootCertPath; char* m_rootPrivKeyPath; string m_caPath; string m_rootPath; string m_crlPath; string m_exportPath; string m_usersPath; string m_importPath; string m_reqPath;};#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -