private function _setCA(Cert &$cert, $insertMode = FALSE)
 {
     $method = "PUT";
     $url = E3_PROV_URL_TRUSTSTORE . "/certs/" . rawurlencode($cert->getId());
     if ($insertMode) {
         $method = "POST";
         $url = E3_PROV_URL_TRUSTSTORE . "/certs";
     }
     /**
      * Send the XML payload the the Provisioning Backend
      */
     LoggerInterface::log(($insertMode ? "Creating" : "Updating") . " Cert: {$cert->toXML()}\nEndpoint: ({$method}) {$url}", LoggerInterface::INFO);
     $reply = $this->restClient->makeCall($url, $method, $cert->toXML());
     $xml = simplexml_load_string($reply->getPayload());
     if ($reply->getHTTPCode() === "200") {
         if ($insertMode) {
             if ($cert->getId() == NULL) {
                 $cert->setId((string) $xml->id);
             }
         }
         return $cert;
     } else {
         throw new Exception(!empty($xml->error) ? $xml->error->errorText : UNDEFINED_ERROR_TEXT);
     }
 }
 private function validateFormAndGetCA(&$validationErrors)
 {
     $registry = Zend_Registry::getInstance();
     $translate = $registry->get("Zend_Translate");
     $validationErrors = array();
     $ca = new Cert();
     $validate_alnum_wspace = new Zend_Validate_Alnum(array('allowWhiteSpace' => true));
     // TODO: validate id field?
     $id = $_POST['ca_id'];
     $ca->setId($id);
     $name = $_POST['ca_name'];
     if (!$validate_alnum_wspace->isValid($name)) {
         $validationErrors['ca_name'] = $translate->translate("The CA name must be only alpha-numeric characters");
     }
     $ca->setDisplayName($_POST['ca_name']);
     if (isset($_FILES['ca_file']) && !empty($_FILES['ca_file']['name'])) {
         if (!$_FILES['ca_file']['error']) {
             $contents = file_get_contents($_FILES['ca_file']['tmp_name']);
             if ($contents !== false) {
                 $ca->setContent($contents);
             } else {
                 $validationErrors['ca_file'] = $translate->translate("There was an error getting contents of CA file.");
             }
         } else {
             $validationErrors['ca_file'] = $translate->translate("There was an error uploading file: ") . $_FILES['content']['error'];
         }
     } else {
         if (empty($id)) {
             $validationErrors['ca_file'] = $translate->translate("Please upload a CA file.");
         }
     }
     return $ca;
 }