diff --git a/src/Digipost/Signature/Client/ASiCe/Signature/CreateSignature.php b/src/Digipost/Signature/Client/ASiCe/Signature/CreateSignature.php index 4a3ffce..6dc5d26 100644 --- a/src/Digipost/Signature/Client/ASiCe/Signature/CreateSignature.php +++ b/src/Digipost/Signature/Client/ASiCe/Signature/CreateSignature.php @@ -81,7 +81,7 @@ public function createSignature( $attachedFiles, KeyStoreConfig $keyStoreConfig ) { - $xmlSignatureFactory = $this->getSignatureFactory(); + //$xmlSignatureFactory = $this->getSignatureFactory(); // $signatureMethod = $this->getSignatureMethod($xmlSignatureFactory); // $signContext = $xmlSignatureFactory->getXMLSignatureContext(); @@ -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(); diff --git a/src/Digipost/Signature/Client/ASiCe/Signature/CreateXAdESProperties.php b/src/Digipost/Signature/Client/ASiCe/Signature/CreateXAdESProperties.php index 93fe1d6..fc153ce 100644 --- a/src/Digipost/Signature/Client/ASiCe/Signature/CreateXAdESProperties.php +++ b/src/Digipost/Signature/Client/ASiCe/Signature/CreateXAdESProperties.php @@ -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; @@ -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; } diff --git a/src/Digipost/Signature/DigipostSignatureBundle.php b/src/Digipost/Signature/DigipostSignatureBundle.php index b9ed7e7..7183c0b 100644 --- a/src/Digipost/Signature/DigipostSignatureBundle.php +++ b/src/Digipost/Signature/DigipostSignatureBundle.php @@ -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); @@ -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()); } diff --git a/src/Digipost/Signature/Loader/KeyStoreFileLoader.php b/src/Digipost/Signature/Loader/KeyStoreFileLoader.php index 57ee208..5cd21e0 100644 --- a/src/Digipost/Signature/Loader/KeyStoreFileLoader.php +++ b/src/Digipost/Signature/Loader/KeyStoreFileLoader.php @@ -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)) { diff --git a/src/Digipost/Signature/XSD/SignatureApiSchemas.php b/src/Digipost/Signature/XSD/SignatureApiSchemas.php index ff50102..bbab12d 100644 --- a/src/Digipost/Signature/XSD/SignatureApiSchemas.php +++ b/src/Digipost/Signature/XSD/SignatureApiSchemas.php @@ -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) { @@ -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 */ @@ -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); } @@ -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 '' . "\n"; }, $values);