📄 raservice.cpp
字号:
#include <stdio.h>#include <stdlib.h>#include <string.h>#include <iostream>#include <sys/stat.h>#include <sys/types.h>#include <assert.h>#include "RAService.h"RAService::RAService(){ m_req = NULL;}RAService::~RAService(){ if(m_req != NULL) { X509_REQ_free(m_req); m_req = NULL; } }/*=================================================================== * Desc: Generate certificate request * Auth: CR * Date: 01-18-2005 * ==================================================================*/int RAService::GenerateCertReq(X509_REQ *req, CertReqInfo *pCertReqInfo, EVP_PKEY *pkey){ bool bSucc = true; long version = 0L; X509_NAME *name; // Set Version bSucc = X509_REQ_set_version(req, version); if(!bSucc) { return -1; }/* Add name entry begin */ // Check if(pCertReqInfo->CommonName == NULL) { return -1; } // Set default value if(pCertReqInfo->CountryName == NULL) { pCertReqInfo->CountryName = "CN"; } name = X509_NAME_new(); // Add Country Name if(X509_NAME_add_entry_by_txt(name, "C", MBSTRING_ASC, (unsigned char *)pCertReqInfo->CountryName, -1, -1, 0) == 0) { X509_NAME_free(name); return -1; } // Add Organization Name if(pCertReqInfo->OrganizationName != NULL) { if(X509_NAME_add_entry_by_txt(name, "O", MBSTRING_ASC, (unsigned char *)pCertReqInfo->OrganizationName, -1, -1, 0) == 0) { X509_NAME_free(name); return -1; } } // Add Organization Unit Name if(pCertReqInfo->UnitName != NULL) { if(X509_NAME_add_entry_by_txt(name, "OU", MBSTRING_ASC, (unsigned char *)pCertReqInfo->UnitName, -1, -1, 0) == 0) { X509_NAME_free(name); return -1; } } // Add State or Province Name if(pCertReqInfo->StateName != NULL) { if(X509_NAME_add_entry_by_txt(name, "ST", MBSTRING_ASC, (unsigned char *)pCertReqInfo->StateName, -1, -1, 0) == 0) { X509_NAME_free(name); return -1; } } // Add Location Name if(pCertReqInfo->CityName != NULL) { if(X509_NAME_add_entry_by_txt(name, "L", MBSTRING_ASC, (unsigned char *)pCertReqInfo->CityName, -1, -1, 0) == 0) { X509_NAME_free(name); return -1; } } // Add Common Name if(X509_NAME_add_entry_by_txt(name, "CN", MBSTRING_ASC, (unsigned char *)pCertReqInfo->CommonName, -1, -1, 0) == 0) { X509_NAME_free(name); return -1; }/* Add name entry end */ bSucc = X509_REQ_set_subject_name(req, name); if(!bSucc) { return -1; } // Add Email Attribute if(pCertReqInfo->EmailAdd != NULL) { if(X509_REQ_add1_attr_by_txt(req, "Email", MBSTRING_ASC, (unsigned char *)pCertReqInfo->EmailAdd, -1) == 0) { X509_NAME_free(name); return -1; } } // Add Public Key bSucc = X509_REQ_set_pubkey(req, pkey); if(!bSucc) { return -1; }// Comment by CR begin - 03.09.2005 - No private key, can't sign/* OpenSSL_add_all_ciphers(); OpenSSL_add_all_digests(); const EVP_MD *md = EVP_sha1(); // Sign certificate request bSucc = X509_REQ_sign(req, pkey, md); EVP_cleanup();*/ // Comment by CR end - 03.09.2005 - No private key, can't sign return 0;}/*=================================================================== * Desc: Sign certificate request * Auth: CR * Date: 01-18-2005 * ==================================================================*/int RAService::SignCertReq(X509_REQ *req){// X509_REQ_sign(); return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -