Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Xmldsig Laravel Package

greenter/xmldsig

PHP library for signing SUNAT electronic invoices in Peru. Load a PEM certificate and sign XML files or strings, adding the required ds:Signature block with transforms, digest and RSA signature to your comprobantes.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Purpose Alignment: The package (thegreenter/xmldsig) is highly specialized for SUNAT (Peruvian tax authority) electronic invoicing compliance, implementing XML-DSig (XML Digital Signatures). It remains a strong fit for Laravel applications issuing Peruvian e-invoicing (Factura Electrónica) or related fiscal documents.
  • Laravel Integration: PHP-native and Composer-compatible; no framework lock-in. Integrates cleanly via the Service Container, queues, events, and console commands.
  • v5.1.0 Impact on Fit: The release does not change the architectural surface (still raw XML string/file in, signed XML out). However, configurable signature and digest algorithms materially improve alignment with SUNAT's evolving crypto requirements (e.g., SHA-256 digest vs. legacy SHA-1), which previously would have required forking or a wrapper hack.
  • XML Processing: Still abstracts complex signature generation, but schema conformance remains the caller's responsibility (unchanged).

Integration Feasibility

  • Low Coupling: Operates on raw XML, agnostic to Eloquent, routing, or HTTP layers. Suitable for:
    • API responses (signing invoices server-side).
    • Background jobs (signing post-creation, batch processing).
    • Middleware (signing outbound payloads before SUNAT submission).
  • Dependency Risks: Still relies on XMLSecLibs (and OpenSSL/LibXML). The new GitHub Actions CI pipeline (PR #15) is a meaningful de-risking signal — it indicates the maintainers now run automated build/test checks, improving the odds that dependency or PHP-version regressions are caught before release. Verify the CI matrix covers the PHP versions your Laravel version supports (8.1+/8.2+ for current Laravel).
  • Upgrade Friction: v5.1.0 is a minor release — no documented breaking changes. If you are on v4.x or early v5.x, expect a low-risk Composer bump; if you are on a pre-5.x line, treat it as a major-line migration requiring regression testing of signature output.

Technical Risk

  • Certification Handling (UNCHANGED):
    • PFX → PEM conversion remains mandatory (CONVERT.md). Misconfiguration risk persists.
    • Private key exposure: .pem files must live in encrypted storage (e.g., Laravel storage/app/certs/ with encryption, or a secrets manager). No change.
  • XML Schema Validation (UNCHANGED): Still no built-in schema validation against SUNAT's XSDs. Callers must validate upstream.
  • Algorithm Configuration (NEW — risk reduced, but new surface):
    • The ability to configure signature and digest algorithms directly addresses the prior concern that the package would lag behind SUNAT crypto requirements. This is the single most valuable change in the release from a compliance standpoint.
    • New risk: misconfiguration. Selecting an algorithm pair (e.g., RSA-SHA1 vs. RSA-SHA256, SHA1 vs. SHA256 digest) that SUNAT does not accept will produce silently non-compliant signatures. This must be pinned explicitly in config, not left to defaults, and covered by a fixture test.
    • Open question: whether the configurable surface is exposed via setters, constructor args, or constants — confirm the API before designing the wrapper service.
  • Maintenance Signal (IMPROVED): The prior assessment flagged the package as unmaintained since 2020. v5.1.0 plus a new external contributor and CI enablement is credible evidence of revived maintenance. This downgrades — but does not eliminate — the "abandoned dependency" risk.
  • Performance (UNCHANGED): XML signing remains CPU-intensive. Algorithm choice now affects cost: SHA-256 is marginally more expensive than SHA-1 but negligible relative to RSA signing and XML canonicalization. Large invoices (100+ line items) still warrant queue offloading and timeout tuning.

Key Questions

  1. Compliance / Algorithms:
    • Which signature and digest algorithm pairs does current SUNAT guidance require, and are those the package's defaults or must they be set explicitly?
    • Can the algorithm configuration be locked at the config layer (e.g., config/sunat.php) so developers cannot accidentally diverge per call site?
  2. Compatibility:
    • Does the new CI matrix cover PHP 8.2/8.3 and the XMLSecLibs version resolved by our composer.lock?
    • Are there transitive upgrade constraints between this minor bump and our existing thegreenter/* packages (e.g., greenter/core, greenter/xml)?
  3. Breaking Changes:
    • Confirm no default algorithm change shipped silently — if defaults changed, previously valid signed output may now differ and previously stored signatures may not re-validate identically.
  4. Security: How will .pem files be stored and rotated? (Unchanged — use encrypted storage or a secrets manager; no hardcoding.)
  5. Error Handling: How will signature failures (invalid XML, expired certs, wrong algorithm) be logged and retried? The package still lacks built-in retry logic.
  6. Testing: Are there mock SUNAT validators available? Plan for golden-file signature fixtures in CI to lock algorithm behavior.

Integration Approach

Stack Fit

  • Laravel Compatibility: Verify the CI matrix against Laravel's supported PHP versions. Package remains framework-agnostic, integrating via Service Container, Events, or Console Commands.
  • Recommended Use Cases (UNCHANGED, with algorithm config added):
    1. Invoice Generation Service — a SunatSigner wrapper service that binds algorithm configuration once:
      // config/sunat.php
      return [
          'certificate' => env('SUNAT_CERT_PATH'),
          'signature_algorithm' => 'RSA-SHA256',
          'digest_algorithm' => 'SHA256',
      ];
      
      class SunatSigner {
          public function sign(string $xml): string {
              $signer = new SignedXml();
              $signer->setCertificate(Storage::disk('certs')->get(config('sunat.certificate')));
              // Apply algorithm config here per v5.1.0 API
              return $signer->signXml($xml);
          }
      }
      
    2. Middleware for Signed Responses — sign outbound XML before SUNAT submission; must delegate to the wrapper service, not instantiate the signer inline, so algorithm config is centralized.
    3. Event Listeners / Queued Jobs — trigger signing after InvoiceCreated; dispatch to a queue for batch workloads.

Migration Path

  1. Phase 0: Upgrade Triage (NEW)
    • Read the v5.1.0 changelog and diff PR #13 to confirm the exact algorithm-configuration API and whether defaults changed.
    • Bump composer.json to "thegreenter/xmldsig": "^5.1" and run composer update --dry-run to inspect transitive changes.
  2. Phase 1: Proof of Concept
    • Sign SUNAT sample XML with the target algorithm pair and validate via SUNAT's validator.
    • Add a golden-file fixture test asserting the output signature and digest method, so future minor bumps cannot silently change crypto behavior.
  3. Phase 2: Integration
    • Centralize algorithm selection in config/sunat.php; never hardcode per call site.
    • Implement certificate management (encrypted storage, rotation runbook).
    • Ensure all signing flows route through the SunatSigner wrapper.
  4. Phase 3: Compliance & CI
    • Test against SUNAT sandbox; automate signature verification in GitHub Actions (mirror the upstream pipeline so we catch breakage on their releases, not after ours).

Compatibility

  • XML Libraries: No conflicts with DOMDocument/SimpleXML.
  • PHP Extensions: Requires OpenSSL and LibXML — both standard.
  • Laravel Features: Use Storage for certs; use Queues for large payloads.
  • Version Pinning: Pin to ^5.1 and lock the resolved version; treat minor bumps as review-required given crypto-surface changes.

Sequencing

  1. Triage upstream diff (PR #13 / PR #15) and confirm algorithm defaults.
  2. Bump dependency in a branch; run full invoice regression suite.
  3. Add golden-signature fixtures to CI before enabling in production.
  4. Roll out to staging with SUNAT sandbox validation.
  5. Production rollout with monitoring on signing failures, then update the cert-rotation runbook.

Operational Impact

Maintenance

  • Package Updates (IMPROVED): The reinstated GitHub Actions pipeline and new contributor mean the package is actively maintained again. Adjust the prior "unmaintained post-2020" stance to "maintained, but monitor release cadence". Set a Dependabot/Renovate rule scoped to this package with manual approval for crypto-affecting bumps.
  • Certificate Management (UNCHANGED):
    • Rotation: manually track SUNAT certificate expiry (annual).
    • Backup: store .pem in a secure vault (e.g., AWS KMS / Secrets Manager).
  • Algorithm Governance (NEW): Treat signature/digest algorithm as configuration, not code. Document the approved pair, add a config assertion test, and require security review for changes.
  • Logging: Log signing attempts, failures, the algorithm used, and certificate metadata (expiry, thumbprint).
    try {
        $signedXml = $signer->sign($xml);
        Log::info('Invoice signed', ['invoice_id' => $id, 'alg' => config('sunat.signature_algorithm')]);
    } catch (\Exception $e) {
        Log::error('Signature failed', ['invoice_id' => $id, 'error' => $e->getMessage()]);
        throw $e;
    }
    

Support

  • Troubleshooting: The upstream CI configuration is now public — a useful reference for reproducing failures locally and for filing issues with reproducible evidence. Expect faster maintainer turnaround than during the 2020–2024 gap.
  • Escalation: Internal runbook owner for SUNAT compliance remains required; upstream maintainers will not validate our XML against SUNAT schemas.
  • Vendor Risk: Reduced but not zero. Retain the documented fallback: custom implementation over XMLSecLibs directly, or migrating to an actively maintained alternative (e.g., spomky-labs/php-xmlsecurity) if release cadence stalls again.

Scaling

  • CPU bound at signing time; scale by queue workers, not web workers. Algorithm choice has negligible throughput impact versus RSA signing and canonicalization.
  • Batch workloads: chunk large invoice runs; consider connection reuse and per-job timeouts sized to invoice line-item counts.

Failure Modes

  • Misconfigured algorithm pair → signatures rejected by SUNAT (new failure mode introduced by v5.1.0; mitigate with config pinning + fixture tests).
  • Default algorithm drift on a future minor bump → previously valid output changes; mitigate by pinning and testing signature output, not just success/failure.
  • Expired/misencoded certificate → signing exceptions; mitigate with expiry alerting at T-30/T-7 days.
  • Oversized XML → memory/timeout exhaustion; mitigate with queue jobs and payload-size guardrails.
  • Upstream abandonment (residual) → mitigate with the documented fallback path and an annual dependency health review.

Ramp-Up

  • Developer onboarding: ~half a day for the wrapper-service pattern; extend to ~1 day for a new engineer to understand the algorithm configuration and SUNAT compliance constraints (this is the new learning burden introduced by the release).
  • Ops onboarding: certificate storage, rotation, and alerting remain the dominant ramp-up cost, unchanged by this release.
  • Recommended: capture a short ADR (Architecture Decision Record) documenting the chosen algorithm pair, the reason, and the upgrade policy — this is the highest-leverage artifact given the new configurability.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
steadrun/laravel-monitor
labyrinthe/connect-laravel
elmogy/layan
drewdan/sentinel-client
dskripchenko/laravel-llm
fatryst/nuonuo
stevenay/myanfont
gmostafa/php-graphql-client
xeviant/paystack
snowsoft/faker
meditationsteps/blogetc
animalyoung/laravel-influxdb
onix-solutions/sms-telera
lonely-lights/prosetta
oxygen/data
oxygen/core
jengo/base
xiloryx/log-collector
a21ns1g4ts/filament-stripe
la-php/laravel-admin