34 const std::string SecurityCertificateManager::TAG =
"SecurityCertificateManager";
37 : _initialized(false), _cert(NULL), _privateKey(NULL)
61 return _trustedCAPath;
76 fp = fopen(certificate.
getPath().c_str(),
"r");
77 if(!fp || !PEM_read_X509(fp, &cert, NULL, NULL)){
87 fp = fopen(privateKey.
getPath().c_str(),
"r");
88 if(!fp || !PEM_read_PrivateKey(fp, &key, NULL, NULL)){
105 _trustedCAPath = trustedCAPath;
138 return SecurityCertificateManager::TAG;
144 if(!certificate || cn.empty()){
148 X509_NAME *cert_name;
149 X509_NAME_ENTRY *name_entry;
150 ASN1_STRING *eid_string;
152 unsigned char *utf8_eid;
156 if(!(cert_name = X509_get_subject_name(certificate))){
161 eid_string = ASN1_STRING_type_new(V_ASN1_PRINTABLESTRING);
167 ASN1_STRING_set(eid_string, cn.c_str(), -1);
169 utf8_eid_len = ASN1_STRING_to_UTF8(&utf8_eid, eid_string);
170 if(utf8_eid_len <= 0){
171 std::stringstream ss; ss <<
"ASN1_STRING_to_UTF8() returned " << utf8_eid_len <<
".";
177 lastpos = X509_NAME_get_index_by_NID(cert_name, NID_commonName, lastpos);
183 name_entry = X509_NAME_get_entry(cert_name, lastpos);
190 ASN1_STRING *asn1 = X509_NAME_ENTRY_get_data(name_entry);
196 unsigned char *utf8_cert_name;
198 utf8_cert_len = ASN1_STRING_to_UTF8(&utf8_cert_name, asn1);
199 if(utf8_cert_len <= 0){
205 if(utf8_cert_len != utf8_eid_len){
208 if(memcmp(utf8_eid, utf8_cert_name, utf8_eid_len) == 0){
209 OPENSSL_free(utf8_cert_name);
210 OPENSSL_free(utf8_eid);
213 OPENSSL_free(utf8_cert_name);
216 OPENSSL_free(utf8_eid);
218 char *subject_line = X509_NAME_oneline(cert_name, NULL, 0);
219 std::stringstream ss;
222 ss <<
"Certificate does not fit. Expected: " << cn <<
", Certificate Subject: " << subject_line <<
".";