Convert from NULL macro to nullptr.
[shibboleth/cpp-xmltooling.git] / xmltooling / security / impl / AbstractPKIXTrustEngine.cpp
index 696aa97..0798115 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright 2001-2009 Internet2
+ *  Copyright 2001-2010 Internet2
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -25,6 +25,7 @@
 #include "logging.h"
 #include "security/AbstractPKIXTrustEngine.h"
 #include "signature/KeyInfo.h"
+#include "signature/Signature.h"
 
 #include <openssl/x509_vfy.h>
 #include <openssl/x509v3.h>
@@ -57,7 +58,7 @@ namespace {
         STACK_OF(X509)* untrusted,
         AbstractPKIXTrustEngine::PKIXValidationInfoIterator* pkixInfo,
         bool fullCRLChain,
-        const vector<XSECCryptoX509CRL*>* inlineCRLs=NULL
+        const vector<XSECCryptoX509CRL*>* inlineCRLs=nullptr
         )
     {
         Category& log=Category::getInstance(XMLTOOLING_LOGCAT".TrustEngine");
@@ -162,13 +163,25 @@ namespace {
     }
 };
 
+AbstractPKIXTrustEngine::PKIXValidationInfoIterator::PKIXValidationInfoIterator()
+{
+}
+
+AbstractPKIXTrustEngine::PKIXValidationInfoIterator::~PKIXValidationInfoIterator()
+{
+}
+
 AbstractPKIXTrustEngine::AbstractPKIXTrustEngine(const xercesc::DOMElement* e) : TrustEngine(e), m_fullCRLChain(false)
 {
     static XMLCh fullCRLChain[] = UNICODE_LITERAL_12(f,u,l,l,C,R,L,C,h,a,i,n);
-    const XMLCh* flag = e ? e->getAttributeNS(NULL, fullCRLChain) : NULL;
+    const XMLCh* flag = e ? e->getAttributeNS(nullptr, fullCRLChain) : nullptr;
     m_fullCRLChain = (flag && (*flag == xercesc::chLatin_t || *flag == xercesc::chDigit_1));
 }
 
+AbstractPKIXTrustEngine::~AbstractPKIXTrustEngine()
+{
+}
+
 bool AbstractPKIXTrustEngine::checkEntityNames(
     X509* certEE, const CredentialResolver& credResolver, const CredentialCriteria& criteria
     ) const
@@ -198,8 +211,8 @@ bool AbstractPKIXTrustEngine::checkEntityNames(
         X509_NAME_print_ex(b2,subject,0,XN_FLAG_RFC2253 + XN_FLAG_SEP_CPLUS_SPC - XN_FLAG_SEP_COMMA_PLUS);
         BIO_flush(b2);
 
-        BUF_MEM* bptr=NULL;
-        BUF_MEM* bptr2=NULL;
+        BUF_MEM* bptr=nullptr;
+        BUF_MEM* bptr2=nullptr;
         BIO_get_mem_ptr(b, &bptr);
         BIO_get_mem_ptr(b2, &bptr2);
 
@@ -227,7 +240,7 @@ bool AbstractPKIXTrustEngine::checkEntityNames(
         BIO_free(b2);
 
         log.debug("unable to match DN, trying TLS subjectAltName match");
-        STACK_OF(GENERAL_NAME)* altnames=(STACK_OF(GENERAL_NAME)*)X509_get_ext_d2i(certEE, NID_subject_alt_name, NULL, NULL);
+        STACK_OF(GENERAL_NAME)* altnames=(STACK_OF(GENERAL_NAME)*)X509_get_ext_d2i(certEE, NID_subject_alt_name, nullptr, nullptr);
         if (altnames) {
             int numalts = sk_GENERAL_NAME_num(altnames);
             for (int an=0; an<numalts; an++) {
@@ -255,28 +268,28 @@ bool AbstractPKIXTrustEngine::checkEntityNames(
         log.debug("unable to match subjectAltName, trying TLS CN match");
 
         // Fetch the last CN RDN.
-        char* peer_CN = NULL;\r
-        int j,i = -1;\r
-        while ((j=X509_NAME_get_index_by_NID(subject, NID_commonName, i)) >= 0)\r
-            i = j;\r
-        if (i >= 0) {\r
-            ASN1_STRING* tmp = X509_NAME_ENTRY_get_data(X509_NAME_get_entry(subject, i));\r
-            // Copied in from libcurl.\r
-            /* In OpenSSL 0.9.7d and earlier, ASN1_STRING_to_UTF8 fails if the input\r
-               is already UTF-8 encoded. We check for this case and copy the raw\r
-               string manually to avoid the problem. */\r
-            if(tmp && ASN1_STRING_type(tmp) == V_ASN1_UTF8STRING) {\r
-                j = ASN1_STRING_length(tmp);\r
-                if(j >= 0) {\r
-                    peer_CN = (char*)OPENSSL_malloc(j + 1);\r
-                    memcpy(peer_CN, ASN1_STRING_data(tmp), j);\r
-                    peer_CN[j] = '\0';\r
-                }\r
-            }\r
-            else /* not a UTF8 name */ {\r
-                j = ASN1_STRING_to_UTF8(reinterpret_cast<unsigned char**>(&peer_CN), tmp);\r
-            }\r
-\r
+        char* peer_CN = nullptr;
+        int j,i = -1;
+        while ((j=X509_NAME_get_index_by_NID(subject, NID_commonName, i)) >= 0)
+            i = j;
+        if (i >= 0) {
+            ASN1_STRING* tmp = X509_NAME_ENTRY_get_data(X509_NAME_get_entry(subject, i));
+            // Copied in from libcurl.
+            /* In OpenSSL 0.9.7d and earlier, ASN1_STRING_to_UTF8 fails if the input
+               is already UTF-8 encoded. We check for this case and copy the raw
+               string manually to avoid the problem. */
+            if(tmp && ASN1_STRING_type(tmp) == V_ASN1_UTF8STRING) {
+                j = ASN1_STRING_length(tmp);
+                if(j >= 0) {
+                    peer_CN = (char*)OPENSSL_malloc(j + 1);
+                    memcpy(peer_CN, ASN1_STRING_data(tmp), j);
+                    peer_CN[j] = '\0';
+                }
+            }
+            else /* not a UTF8 name */ {
+                j = ASN1_STRING_to_UTF8(reinterpret_cast<unsigned char**>(&peer_CN), tmp);
+            }
+
             for (set<string>::const_iterator n=trustednames.begin(); n!=trustednames.end(); n++) {
 #ifdef HAVE_STRCASECMP
                 if (n->length() == j && !strncasecmp(peer_CN, n->c_str(), j)) {
@@ -284,17 +297,17 @@ bool AbstractPKIXTrustEngine::checkEntityNames(
                 if (n->length() == j && !strnicmp(peer_CN, n->c_str(), j)) {
 #endif
                     log.debug("matched subject CN to a key name (%s)", n->c_str());
-                    if(peer_CN)\r
-                        OPENSSL_free(peer_CN);\r
+                    if(peer_CN)
+                        OPENSSL_free(peer_CN);
                     return true;
                 }
             }
-            if(peer_CN)\r
-                OPENSSL_free(peer_CN);\r
+            if(peer_CN)
+                OPENSSL_free(peer_CN);
         }
         else {
             log.warn("no common name in certificate subject");
-        }\r
+        }
     }
     else {
         log.error("certificate has no subject?!");
@@ -418,7 +431,7 @@ bool AbstractPKIXTrustEngine::validate(
 
     // Find and save off a pointer to the certificate that unlocks the object.
     // Most of the time, this will be the first one anyway.
-    XSECCryptoX509* certEE=NULL;
+    XSECCryptoX509* certEE=nullptr;
     SignatureValidator keyValidator;
     for (vector<XSECCryptoX509*>::const_iterator i=certs.begin(); !certEE && i!=certs.end(); ++i) {
         try {
@@ -496,7 +509,7 @@ bool AbstractPKIXTrustEngine::validate(
 
     // Find and save off a pointer to the certificate that unlocks the object.
     // Most of the time, this will be the first one anyway.
-    XSECCryptoX509* certEE=NULL;
+    XSECCryptoX509* certEE=nullptr;
     for (vector<XSECCryptoX509*>::const_iterator i=certs.begin(); !certEE && i!=certs.end(); ++i) {
         try {
             auto_ptr<XSECCryptoKey> key((*i)->clonePublicKey());