Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse error on certificate stored in DB #87

Closed
rabol opened this issue Feb 28, 2023 · 1 comment
Closed

Parse error on certificate stored in DB #87

rabol opened this issue Feb 28, 2023 · 1 comment
Assignees
Labels
bug Something isn't working enhancement New feature or request help wanted Extra attention is needed wontfix This will not be worked on

Comments

@rabol
Copy link

rabol commented Feb 28, 2023

Describe the bug
Retrieving certificate from DB returns an parse error:

To Reproduce
Steps to reproduce the behavior:

  1. create certificate like this
    $cert = new ManageCert();
    $cert->makeDebugCertificate();

     // For MySQL
     $uc = UserCertificate::create([
         'certificate' => $cert->encryptBase64BlobString($cert->getCert()->original),
         'password'    => $cert->getEncrypter()->encryptString('123456'),
         'hash'        => base64_encode($cert->getHashKey()), // IMPORTANT
         'user_id' => Str::uuid(),
         'name' => 'auto upload',
     ]);
    
  2. get the certificate like this:
    $uc = UserCertificate::find('98937f06-c230-466f-ba71-179b385d2cac');
    dd($uc->parse());

parse method looks like this:

public function parse(): ?ManageCert
    {
        try {
            $hashKey = base64_decode($this->hash);

            return decryptCertData($hashKey, $this->certificate, $this->password, true);
        } catch (\Throwable $th) {
            Log::error('Parse certificate: '.$th->getMessage());
        }

        return null;
    }

Table migration:

Schema::create('user_certificates', function (Blueprint $table) {
            $table->uuid('id')->primary();

            $table->string('name');
            //$table->unsignedInteger('user_id');
            $table->uuid('user_id');
            $table->binary('certificate');
            $table->string('password');
            $table->string('hash');

            $table->timestamps();
        });

Error:

Process runtime error, reason: "8213037376:error:0DFFF0A8:asn1 encoding routines:CRYPTO_internal:wrong tag:/AppleInternal/Library/BuildRoots/9e200cfa-7d96-11ed-886f-a23c4f261b56/Library/Caches/com.apple.xbs/Sources/libressl/libressl-3.3/crypto/asn1/tasn_dec.c:1167:. 8213037376:error:0DFFF03A:asn1 encoding routines:CRYPTO_internal:nested asn1 error:/AppleInternal/Library/BuildRoots/9e200cfa-7d96-11ed-886f-a23c4f261b56/Library/Caches/com.apple.xbs/Sources/libressl/libressl-3.3/crypto/asn1/tasn_dec.c:337:Type=PKCS12. "

Expected behavior
That the certificate was retrieved from the DB.

Screenshots
If applicable, add screenshots to help explain your problem.

Versions involved:

  • Laravel: [e.g. 10.1.15]
  • Laravel A1 Pdf Sign [e.g. 1.0.7]
  • Composer [e.g. 2.5.3]
  • php 8.1.15

Additional context
Running on MacBook Pro M1 Max
MacOS 13.2.1 (22D68)
Laravel Valet

@rabol rabol added bug Something isn't working help wanted Extra attention is needed labels Feb 28, 2023
@lsnepomuceno
Copy link
Owner

Hello @rabol,

This issue is probably environment related.

We tried to capture the same error several times and failed.

However, we added more detailed tests on the data stored in the database, I will also include the MacOs environment in the test pipeline to identify possible problems.

@lsnepomuceno lsnepomuceno added the enhancement New feature or request label May 26, 2023
@lsnepomuceno lsnepomuceno added the wontfix This will not be worked on label Jan 25, 2024
Repository owner locked as resolved and limited conversation to collaborators Jan 25, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working enhancement New feature or request help wanted Extra attention is needed wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants