Example #1
0
 public function setUp()
 {
     parent::setUp();
     $person = new Person();
     $person->last_name = 'Doe';
     $person->first_name = 'John';
     $person->middle_name = 'Dee';
     $person->active = 1;
     $person->persist();
     $this->_objects['person'] = $person;
     $username = '******';
     $password = '******';
     $user = new User();
     $user->userId = $person->personId;
     $user->personId = $person->personId;
     $user->username = $username;
     $user->password = $password;
     $user->persist();
     $this->_objects['user'] = $user;
     $userKey = new UserKey();
     $userKey->userId = $user->userId;
     $userKey->generateKeys($password);
     $userKey->persist();
     $this->_objects['userKey'] = $userKey;
 }
Example #2
0
 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;
 }
Example #3
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getUserKeys()
 {
     return $this->hasMany(UserKey::className(), ['user_id' => 'id']);
 }
 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 generateUsersKeysAction()
 {
     exit;
     //$f = fopen('/tmp/newusers.csv','r');
     //$counter = 0;
     //while (($data = fgetcsv($f)) !== FALSE) {
     //if ($counter == 0) { $counter++; continue; }
     echo $data[4] . "<br />";
     flush();
     $user = new User();
     $user->username = '******';
     $user->populateWithUsername();
     $userKey = new UserKey();
     $userKey->userId = $user->userId;
     //field 2 is passphrase
     $userKey->generateKeys('test passphrase');
     echo $user->toString();
     echo $data[0] . "\n";
     flush();
     $userKey->persist();
     $counter++;
     //}
     //fclose($f);
     exit;
 }
Example #6
0
 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.');
 }