Skip to content

Commit

Permalink
Bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
bendikrb committed Aug 12, 2018
1 parent e494784 commit ef94d74
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public function createSignature(
$attachedFiles,
KeyStoreConfig $keyStoreConfig
) {
$xmlSignatureFactory = $this->getSignatureFactory();
//$xmlSignatureFactory = $this->getSignatureFactory();
// $signatureMethod = $this->getSignatureMethod($xmlSignatureFactory);
// $signContext = $xmlSignatureFactory->getXMLSignatureContext();

Expand Down Expand Up @@ -233,10 +233,15 @@ private function getSignatureFactory() {
* @throws SchemaException
*/
protected function validateXml(\DOMDocument $dom) {
libxml_use_internal_errors(TRUE);
libxml_use_internal_errors(FALSE);

$xsd = SignatureApiSchemas::ASICE_AND_XADES_SCHEMA()->getXSD();
$dom->schemaValidateSource($xsd, Marshalling::LIBXML_OPTIONS);
try {
$dom->schemaValidateSource($xsd, Marshalling::LIBXML_OPTIONS);
} catch (\Exception $e) {
print $e->getMessage();
}
print "OK";
if ($errors = $this->getXmlValidationErrors()) {
$error = $this->formatXmlValidationErrors();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use Digipost\Signature\Client\Core\Internal\Security\X509Certificate;
use Digipost\Signature\Client\Core\Internal\XML\Marshalling;
use DOMDocument as Document;
use RobRichards\XMLSecLibs\XMLSecurityDSig;
use Digipost\Signature\Client\Core\Internal\Security\Constants as C;
use Digipost\Signature\Client\Core\Internal\Security\Signature;

Expand Down Expand Up @@ -38,7 +37,7 @@ function __staticInit() {
*/
function __construct(\DateTime $clock) {
$this->sha1DigestMethod = new DigestMethod();
$this->sha1DigestMethod->setAlgorithm(XMLSecurityDSig::SHA1);
$this->sha1DigestMethod->setAlgorithm(C::DIGEST_SHA1);
$this->clock = $clock;
}

Expand Down
4 changes: 3 additions & 1 deletion src/Digipost/Signature/DigipostSignatureBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class DigipostSignatureBundle extends Bundle {
public function build(ContainerBuilder $container) {
parent::build($container);

define('DIGIPOST_SIGNATURE_ROOT_DIR', $container->getParameter('kernel.project_dir'));

$serializer_dir = __DIR__ . '/Resources/config/serializer';
$serializer_php_dir = __DIR__ . '/API/XML';
$container->setParameter('digipost_signature.serializer_config_dir', $serializer_dir);
Expand All @@ -25,7 +27,7 @@ public function build(ContainerBuilder $container) {
try {
$container->registerExtension(new Xsd2PhpExtension());
$container->addCompilerPass(new Xsd2PhpLoaderPass());
} catch (\Exception $e) {
} catch (\Error $e) {
$container->registerExtension(new Xsd2PhpPolyfillExtension());
}

Expand Down
2 changes: 1 addition & 1 deletion src/Digipost/Signature/Loader/KeyStoreFileLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static function loader(
) {
$kernel = $container->get('kernel');
$path = $filename;
if ($filename[0] === '@') {
if (!empty($filename) && $filename[0] === '@') {
$path = $kernel->locateResource($filename);
}
if (!file_exists($path)) {
Expand Down
40 changes: 35 additions & 5 deletions src/Digipost/Signature/XSD/SignatureApiSchemas.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,10 @@ public function __construct($value) {
$this->filename = $value;
}

// if (is_array($value)) {
// $this->filename = 'xsd://' . $this->getKey();
// }
if ($this->filename && $dir = $this->resolveVendorDir()) {
$dir .= '/digipost/signature-api-specification/schema/xsd';
$this->filename = $dir . $this->filename;
}
}

private static function create($value) {
Expand All @@ -104,6 +105,31 @@ public function getValue() {
return $this;
}

private function resolveVendorDir() {
if ($file = self::findFileInParents('vendor/autoload.php')) {
return dirname($file);
}
return FALSE;
}

private static function findFileInParents(
string $filename,
$startDir = __DIR__,
$maxIterations = 20
) {
$path = $startDir;
do {
$path = realpath($path . implode(DIRECTORY_SEPARATOR, ['', '..', '']));
$filePath = $path . DIRECTORY_SEPARATOR . $filename;
$fileFound = file_exists($filePath);
} while (--$maxIterations > 0 && !file_exists($filePath) && $path !== DIRECTORY_SEPARATOR);

if (!$fileFound) {
return FALSE;
}
return $filePath;
}

/**
* @return \GoetasWebservices\XML\XSDReader\Schema\Schema
*/
Expand All @@ -115,7 +141,7 @@ public function getSchema() {
//$schema->addSchema($reader->readFile($fileName));
//}
$schema = $reader->readFile($this->filename);
} catch (SchemaException $e) {
} catch (\Exception $e) {
throw new \RuntimeException("An error occoured during merging of schemas", 0, $e);
}

Expand All @@ -142,7 +168,11 @@ public function getXSD() {

$imports = array_map(function($schema) {
/** @var SignatureApiSchemas $schema */
$ns = $schema->getSchema()->getTargetNamespace();
try {
$ns = $schema->getSchema()->getTargetNamespace();
} catch (\Exception $e) {
return '';
}
return '<xsd:import namespace="' . $ns . '" schemaLocation="' . $schema->filename . '"/>' . "\n";
}, $values);

Expand Down

0 comments on commit ef94d74

Please sign in to comment.