public function validateSigningKeyAction()
 {
     $signature = $this->_getParam('signature');
     $currentUserId = (int) Zend_Auth::getInstance()->getIdentity()->personId;
     $userKey = new UserKey();
     $userKey->userId = $currentUserId;
     $userKey->populate();
     if (strlen($userKey->privateKey) > 0) {
         try {
             $privateKeyString = $userKey->getDecryptedPrivateKey($signature);
             $ret = __('Current signature is valid.');
         } catch (Exception $e) {
             $ret = __('Current signature is invalid.' . PHP_EOL . $e->getMessage());
         }
     } else {
         $ret = __('Cannot verify, no signature exists');
     }
     $json = Zend_Controller_Action_HelperBroker::getStaticHelper('json');
     $json->suppressExit = true;
     $json->direct($ret);
 }
 public function verify($data = null)
 {
     if ($data === null) {
         $data = file_get_contents($this->getUploadFilename());
     }
     $doc = new DOMDocument();
     $doc->formatOutput = true;
     if (!$doc->loadXML($data)) {
         throw new Exception('Generated XML is invalid');
     }
     $rootNode = $doc->getElementsByTagName('mysqldump');
     if ($rootNode->length <= 0) {
         $node = $doc->createElement('mysqldump');
         $rootDoc = $doc->appendChild($node);
     } else {
         $rootDoc = $rootNode->item(0);
     }
     $nodeList = $rootDoc->getElementsByTagName('meta-data');
     if ($nodeList->length <= 0) {
         $node = $doc->createElement('meta-data');
         $elem = $rootDoc->appendChild($node);
     } else {
         $elem = $nodeList->item(0);
     }
     if ($channelId = $elem->getAttribute('channelId')) {
         $this->channelId = (int) $channelId;
     }
     if ($channel = $elem->getAttribute('channel')) {
         $this->channel = $channel;
     }
     $signature = $elem->getAttribute('signature');
     if ($version = $elem->getAttribute('version')) {
         $this->version = $version;
     }
     $elem->setAttribute('signature', '');
     if ($name = $elem->getAttribute('name')) {
         $this->name = $name;
     }
     if ($md5sum = $elem->getAttribute('md5sum')) {
         $this->md5sum = $md5sum;
     }
     if ($description = $elem->getAttribute('description')) {
         $this->description = $description;
     }
     if ($license = $elem->getAttribute('license')) {
         $this->license = $license;
     }
     $newData = $doc->saveXML();
     $hash = md5($newData);
     $userKey = new UserKey();
     $userKey->userId = $this->signingUserId;
     $userKey->populate();
     $keyFile = Zend_Registry::get('basePath');
     $keyFile .= Zend_Registry::get('config')->healthcloud->updateServerPubKeyPath;
     $serverPublicKey = file_get_contents($keyFile);
     $publicKey = openssl_get_publickey($serverPublicKey);
     openssl_public_decrypt(base64_decode($signature), $verifyHash, $publicKey);
     openssl_free_key($publicKey);
     if ($hash !== $verifyHash) {
         throw new Exception('Data verification with signature failed.');
     }
     return true;
 }
 public function verify(Document $object, $signature)
 {
     $document = $object->toDocument();
     $hash = hash('sha256', $this->signedDateTime . " " . $document);
     $userKey = new UserKey();
     $userKey->userId = $this->signingUserId;
     $userKey->populate();
     $publicKey = openssl_get_publickey($userKey->publicKey);
     openssl_public_decrypt(base64_decode($signature), $verifyHash, $publicKey);
     openssl_free_key($publicKey);
     if ($hash === $verifyHash) {
         return true;
     }
     throw new Exception('Document verification with signature failed.');
 }