Esempio n. 1
0
 /**
  * Tries to parse the given file as a KeePass XML key file.
  * @param string $filename The name of the file to parse.
  * @return boolean Returns true in case of success, false otherwise.
  */
 private function tryParseXML($filename)
 {
     $xml = new XMLStackReader();
     if (!$xml->open($filename)) {
         return false;
     }
     $parents = array(self::XML_ROOT, self::XML_KEY, self::XML_DATA);
     if ($xml->readUntilParentsBe($parents)) {
         if ($xml->isTextInside()) {
             $this->hash = base64_decode($xml->r->value);
             $xml->close();
             return true;
         }
     }
     $xml->close();
     return false;
 }
Esempio n. 2
0
 /**
  * Tries to read the inner text of a XML node, assuming that the given
  * XMLStackReader $xml is currently at this node, and that the only child
  * of the node is a text node. Uses $this->randomStream to decode the
  * text if needed.
  * @param XMLStackReader $xml
  * @return string|\null
  */
 private function readTextValueFromXML(XMLStackReader $xml)
 {
     if ($xml->r->hasAttributes && $xml->r->moveToAttribute(self::XML_PROTECTED)) {
         if ($xml->r->value == self::XML_PROTECTED_TRUE) {
             $xml->r->moveToElement();
             if ($xml->isTextInside()) {
                 $v = base64_decode($xml->r->value);
                 return $this->randomStream->dencrypt($v);
             }
         }
     } elseif ($xml->isTextInside()) {
         return $xml->r->value;
     }
     return null;
 }