我想验证证书的格式是否有效,所以我写了这段代码,但似乎有错误
if (validConfigFile()) {
INIReader reader(CONFIG_FILE);
string certFile= reader.Get("Server", "cert-file", "None");
if (certFile == "None") {
syslog(LOG_ERR, "cert-file in configuration file is not properly adjusted");
exit(EXIT_FAILURE); }
else {
std::string fileName(certFile);
ifstream fin(fileName.c_str());
if(fin.fail()) {
syslog(LOG_ERR, "cert-file not found in its file path");
exit(EXIT_FAILURE); }
else {
OpenSSL_add_all_digests();
SSL_CTX *sslctx = SSL_CTX_new(SSLv23_server_method());
SSL_CTX_use_certificate_file(sslctx, certFile, SSL_FILETYPE_PEM);
SSL *ssl = SSL_new(sslctx);
X509 *CERT = SSL_get_certificate(ssl);
if (X509_verify(CERT,X509_get_pubkey(CERT)) == -1) {
syslog(LOG_ERR, "cert-file not valid");
exit(EXIT_FAILURE); }
}
}
}
编译时出现此错误
/main.cpp:68: error: cannot convert ‘std::string’ to ‘const char*’ for argument ‘2’ to ‘int SSL_CTX_use_certificate_file(SSL_CTX*, const char*, int)’
并且
main.cpp:70: error: expected unqualified-id before ‘char’ for that line : X509 *CERT = SSL_get_certificate(ssl);