Ejemplo 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;
 }
Ejemplo n.º 2
0
 /**
  * Tries to find a child node named $name in the given array $array of nodes
  * (assumed to be returned by the method $xml->readInnerXML()), and returns
  * true in case of success, or false otherwise. If the node is found,
  * $result will contain what is inside :
  *  - either null if the nodes contains nothing
  *  - either a string if the node contains a text node
  *  - either the subtree (as an array) of the node
  * @param array $array
  * @param string $name
  * @param mixed $result
  * @return boolean
  */
 private function tryReadTextValueFromArray($array, $name, &$result)
 {
     if (XMLStackReader::tryGetChild($array, $name, $result)) {
         if ($result[XMLStackReader::INNER] == null) {
             $result = null;
         } elseif (is_string($result[XMLStackReader::INNER])) {
             $a = $result[XMLStackReader::ATTRIBUTES];
             if ($a != null && array_key_exists(self::XML_PROTECTED, $a) && $a[self::XML_PROTECTED] == self::XML_PROTECTED_TRUE) {
                 $v = base64_decode($result[XMLStackReader::INNER]);
                 $result = $this->randomStream->dencrypt($v);
             } else {
                 $result = $result[XMLStackReader::INNER];
             }
         }
         return true;
     }
     return false;
 }