CRM-16757 - Use customized CertificateValidator
authorTim Otten <totten@civicrm.org>
Tue, 30 Jun 2015 23:21:10 +0000 (16:21 -0700)
committerTim Otten <totten@civicrm.org>
Tue, 14 Jul 2015 04:00:09 +0000 (21:00 -0700)
CRM/Cxn/BAO/Cxn.php
api/v3/CxnApp.php

index f41cb576c01c319723fb2fe95e9cd9e733db633c..4e8a690f6d32795fb6fbc83f1825648e0f132a0c 100644 (file)
@@ -161,8 +161,9 @@ class CRM_Cxn_BAO_Cxn extends CRM_Cxn_DAO_Cxn {
    */
   public static function createRegistrationClient() {
     $cxnStore = new \CRM_Cxn_CiviCxnStore();
-    $client = new \Civi\Cxn\Rpc\RegistrationClient(self::getCACert(), $cxnStore, \CRM_Cxn_BAO_Cxn::getSiteCallbackUrl());
+    $client = new \Civi\Cxn\Rpc\RegistrationClient($cxnStore, \CRM_Cxn_BAO_Cxn::getSiteCallbackUrl());
     $client->setLog(new \CRM_Utils_SystemLogger());
+    $client->setCertValidator(self::createCertificateValidator());
     return $client;
   }
 
@@ -175,8 +176,22 @@ class CRM_Cxn_BAO_Cxn extends CRM_Cxn_DAO_Cxn {
     $cxnStore = new CRM_Cxn_CiviCxnStore();
     $apiServer = new \Civi\Cxn\Rpc\ApiServer($cxnStore);
     $apiServer->setLog(new CRM_Utils_SystemLogger());
+    $apiServer->setCertValidator(self::createCertificateValidator());
     $apiServer->setRouter(array('CRM_Cxn_ApiRouter', 'route'));
     return $apiServer;
   }
 
+  /**
+   * @return \Civi\Cxn\Rpc\CertificateValidatorInterface
+   * @throws CRM_Core_Exception
+   */
+  public static function createCertificateValidator() {
+    $caCert = self::getCACert();
+    if ($caCert === NULL) {
+      return new \Civi\Cxn\Rpc\DefaultCertificateValidator(NULL, NULL, NULL);
+    }
+    else {
+      return new \Civi\Cxn\Rpc\DefaultCertificateValidator($caCert);
+    }
+  }
 }
index be10d3b82e3f1fd62c7e72151ca58c1f6ac2add7..5f7afd6a413084fe66db7424e84e2df7895b9342 100644 (file)
@@ -104,7 +104,8 @@ function civicrm_api3_cxn_app_get($params) {
     throw new API_Exception("Failed to download application list.");
   }
 
-  $agent = new \Civi\Cxn\Rpc\Agent(CRM_Cxn_BAO_Cxn::getCACert(), NULL, NULL);
+  $agent = new \Civi\Cxn\Rpc\Agent(NULL, NULL);
+  $agent->setCertValidator(CRM_Cxn_BAO_Cxn::createCertificateValidator());
   $message = $agent->decode(array(AppMetasMessage::NAME, GarbledMessage::NAME), $blob);
 
   if ($message instanceof AppMetasMessage) {