Example #1
0
 /**
  * @expectedException RuntimeException
  * @expectedExceptionCode 203
  */
 public function testDecryptionRuntimeException203()
 {
     $msg = new Msg();
     $msg->setVersion(1);
     $msg->setId('cafed00d-2131-4159-8e11-0b4dbadb1738');
     $msg->setSrcNodeId('cafed00d-2331-4159-8e11-0b4dbadb1738');
     $msg->setSrcSslKeyPub(static::SRC1_SSL_KEY_PUB);
     $msg->setSrcUserNickname('username1');
     $msg->setDstNodeId('cafed00d-2431-4159-8e11-0b4dbadb1738');
     $msg->setDstSslPubKey(static::DST1_SSL_KEY_PUB);
     $msg->setSubject('subj1');
     $msg->setText('text1');
     $msg->setSslKeyPrv(static::SRC1_SSL_KEY_PRV, static::SSL_KEY_PRV_PASS);
     $msg->setIgnore(false);
     $this->assertTrue($msg->encrypt());
     $body = $msg->getBody();
     $timeCreated = $msg->getTimeCreated();
     $password = $msg->getPassword();
     $checksum = $msg->getChecksum();
     $body = base64_decode($body);
     $body = gzdecode($body);
     $body = json_decode($body, true);
     $body['data'] = 'invalid';
     $body = json_encode($body);
     $body = gzencode($body, 9);
     $body = base64_encode($body);
     $msg = new Msg();
     $msg->setVersion(1);
     $msg->setId('cafed00d-2131-4159-8e11-0b4dbadb1738');
     $msg->setSrcNodeId('cafed00d-2331-4159-8e11-0b4dbadb1738');
     $msg->setBody($body);
     $msg->setSrcSslKeyPub(static::SRC1_SSL_KEY_PUB);
     $msg->setDstSslPubKey(static::DST1_SSL_KEY_PUB);
     $msg->setSslKeyPrv(static::DST1_SSL_KEY_PRV, static::SSL_KEY_PRV_PASS);
     $msg->setDstNodeId('cafed00d-2431-4159-8e11-0b4dbadb1738');
     $msg->setTimeCreated($timeCreated);
     $msg->setPassword($password);
     $msg->setChecksum($checksum);
     $msg->decrypt();
 }
Example #2
0
 public function sendMsg(Msg $msg)
 {
     $rid = (string) Uuid::uuid4();
     $this->requestAdd('msg', $rid, array('msg' => $msg));
     $data = array('rid' => $rid, 'version' => $msg->getVersion(), 'id' => $msg->getId(), 'srcNodeId' => $msg->getSrcNodeId(), 'srcSslKeyPub' => base64_encode($msg->getSrcSslKeyPub()), 'dstNodeId' => $msg->getDstNodeId(), 'body' => $msg->getBody(), 'password' => $msg->getPassword(), 'checksum' => $msg->getChecksum(), 'relayCount' => (int) $msg->getRelayCount() + 1, 'timeCreated' => (int) $msg->getTimeCreated(), 'hashcash' => $this->hashcashMint(static::HASHCASH_BITS_MAX));
     return $this->dataSend($this->msgCreate('msg', $data));
 }
Example #3
0
 public function msgUpdate(Msg $msgNew)
 {
     $rv = false;
     if (isset($this->msgs[$msgNew->getId()])) {
         $msgOld = $this->msgs[$msgNew->getId()];
         if ($msgOld->getVersion() != $msgNew->getVersion()) {
             #print __CLASS__.'->'.__FUNCTION__.': changed: version'."\n";
             $msgOld->setVersion($msgNew->getVersion());
             $this->setDataChanged(true);
             $rv = true;
         }
         /*if($msgOld->getId() != $msgNew->getId()){
         			#print __CLASS__.'->'.__FUNCTION__.': changed: id'."\n";
         			$msgOld->setId($msgNew->getId());
         			$this->setDataChanged(true);
         			$rv = true;
         		}*/
         if ($msgOld->getSrcNodeId() != $msgNew->getSrcNodeId()) {
             #print __CLASS__.'->'.__FUNCTION__.': changed srcNodeId: '.$msgOld->getSrcNodeId().' '.$msgNew->getSrcNodeId()."\n";
             $msgOld->setSrcNodeId($msgNew->getSrcNodeId());
             $this->setDataChanged(true);
             $rv = true;
         }
         if ($msgOld->getSrcSslKeyPub() != $msgNew->getSrcSslKeyPub()) {
             #print __CLASS__.'->'.__FUNCTION__.': changed: srcSslKeyPub'."\n";
             $msgOld->setSrcSslKeyPub($msgNew->getSrcSslKeyPub());
             $this->setDataChanged(true);
             $rv = true;
         }
         if ($msgOld->getDstNodeId() != $msgNew->getDstNodeId()) {
             #print __CLASS__.'->'.__FUNCTION__.': changed: dstNodeId'."\n";
             $msgOld->setDstNodeId($msgNew->getDstNodeId());
             $this->setDataChanged(true);
             $rv = true;
         }
         if ($msgOld->getDstSslPubKey() != $msgNew->getDstSslPubKey()) {
             #print __CLASS__.'->'.__FUNCTION__.': changed: dstSslPubKey'."\n";
             $msgOld->setDstSslPubKey($msgNew->getDstSslPubKey());
             $this->setDataChanged(true);
             $rv = true;
         }
         if ($msgOld->getSubject() != $msgNew->getSubject()) {
             #print __CLASS__.'->'.__FUNCTION__.': changed: subject'."\n";
             $msgOld->setSubject($msgNew->getSubject());
             $this->setDataChanged(true);
             $rv = true;
         }
         if ($msgOld->getBody() != $msgNew->getBody()) {
             #print __CLASS__.'->'.__FUNCTION__.': changed: text'."\n";
             $msgOld->setBody($msgNew->getBody());
             $this->setDataChanged(true);
             $rv = true;
         }
         if ($msgOld->getText() != $msgNew->getText()) {
             #print __CLASS__.'->'.__FUNCTION__.': changed: text'."\n";
             $msgOld->setText($msgNew->getText());
             $this->setDataChanged(true);
             $rv = true;
         }
         if ($msgOld->getPassword() != $msgNew->getPassword()) {
             #print __CLASS__.'->'.__FUNCTION__.': changed: password'."\n";
             $msgOld->setPassword($msgNew->getPassword());
             $this->setDataChanged(true);
             $rv = true;
         }
         if ($msgOld->getChecksum() != $msgNew->getChecksum()) {
             #print __CLASS__.'->'.__FUNCTION__.': changed: checksum'."\n";
             $msgOld->setChecksum($msgNew->getChecksum());
             $this->setDataChanged(true);
             $rv = true;
         }
         $msgOldSentNodes = $msgOld->getSentNodes();
         $msgNewSentNodes = $msgNew->getSentNodes();
         #if(count($msgOldSentNodes) < count($msgNewSentNodes)){
         if ($msgOldSentNodes != $msgNewSentNodes) {
             $msgOld->setSentNodes(array_unique(array_merge($msgOldSentNodes, $msgNewSentNodes)));
         }
         if ($msgOld->getRelayCount() != $msgNew->getRelayCount()) {
             #print __CLASS__.'->'.__FUNCTION__.': changed: relayCount'."\n";
             $msgOld->setRelayCount($msgNew->getRelayCount());
             $this->setDataChanged(true);
             $rv = true;
         }
         if ($msgOld->getForwardCycles() != $msgNew->getForwardCycles()) {
             #print __CLASS__.'->'.__FUNCTION__.': changed: forwardCycles'."\n";
             $msgOld->setForwardCycles($msgNew->getForwardCycles());
             $this->setDataChanged(true);
             $rv = true;
         }
         if ($msgOld->getEncryptionMode() != $msgNew->getEncryptionMode()) {
             #print __CLASS__.'->'.__FUNCTION__.': changed: encryptionMode, '.$msgOld->getEncryptionMode();
             #print ', '.$msgNew->getEncryptionMode()."\n";
             $msgOld->setEncryptionMode($msgNew->getEncryptionMode());
             $this->setDataChanged(true);
             $rv = true;
         }
         if ($msgOld->getStatus() != $msgNew->getStatus()) {
             #print __CLASS__.'->'.__FUNCTION__.': changed: status'."\n";
             $msgOld->setStatus($msgNew->getStatus());
             $this->setDataChanged(true);
             $rv = true;
         }
         if ($msgOld->getTimeCreated() != $msgNew->getTimeCreated()) {
             #print __CLASS__.'->'.__FUNCTION__.': changed: timeCreated'."\n";
             $msgOld->setTimeCreated($msgNew->getTimeCreated());
             $this->setDataChanged(true);
             $rv = true;
         }
         /*if($msgOld->getDataChanged() != $msgNew->getDataChanged()){
         			#print __CLASS__.'->'.__FUNCTION__.': changed: dataChanged'."\n";
         			$msgOld->setDataChanged($msgNew->getDataChanged());
         		}*/
     }
     return $rv;
 }
Example #4
0
 public function imapMailAdd(Msg $msg)
 {
     if ($this->getKernel() && $this->getKernel()->getIpcImapConnection()) {
         $version = $msg->getVersion();
         $id = $msg->getId();
         $srcNodeId = $msg->getSrcNodeId();
         $srcUserNickname = $msg->getSrcUserNickname();
         $dstNodeId = $msg->getDstNodeId();
         $subject = $msg->getSubject();
         $text = $msg->getText();
         $checksum = $msg->getChecksum();
         $relayCount = $msg->getRelayCount();
         $encryptionMode = $msg->getEncryptionMode();
         $status = $msg->getStatus();
         $timeCreated = $msg->getTimeCreated();
         $timeReceived = $msg->getTimeReceived();
         $args = array();
         $args[] = $version;
         $args[] = $id;
         $args[] = $srcNodeId;
         $args[] = $srcUserNickname;
         $args[] = $dstNodeId;
         $args[] = $subject;
         $args[] = $text;
         $args[] = $checksum;
         $args[] = $relayCount;
         $args[] = $encryptionMode;
         $args[] = $status;
         $args[] = $timeCreated;
         $args[] = $timeReceived;
         $this->getKernel()->getIpcImapConnection()->execAsync('mailAdd', $args);
     }
 }