simple-login / app

The SimpleLogin back-end and web app
https://simplelogin.io
GNU Affero General Public License v3.0
5.16k stars 438 forks source link

Error with openssl 3.0: dkim.KeyFormatError: Unparsable private key: Unexpected tag (got 30, expecting 02) #1203

Open akash07k opened 2 years ago

akash07k commented 2 years ago

Please note that this is only for bug report.

For help on your account, please reach out to us at hi[at]simplelogin.io. Please make sure to check out our FAQ that contains frequently asked questions.

For feature request, you can use our forum.

For self-hosted question/issue, please ask in self-hosted forum

Prerequisites

Bug report

Not receiving the emails from simplelogin instance.

Describe the bug A clear and concise description of what the bug is.

I'm hosting the simplelogin instance on my server and building the image it from source. Everything is fine, but whenever I'm creating an account, I'm not getting any mail on my mail address. I've created the DKIM keys via following the same instructions as readme. Openssl version is 3.0 and if I use openssl 1.X it works fine. Following are the logs on my sl-app container:

2022-07-29 19:08:15,904 - SL - WARNING - 9 - "/code/app/email_utils.py:461" - add_dkim_signature() -  - DKIM fail with [b'Message-ID', b'Date', b'Subject', b'From', b'To']
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/dkim/crypto.py", line 140, in parse_private_key
    pka = asn1_parse(ASN1_RSAPrivateKey, data)
  File "/usr/local/lib/python3.7/site-packages/dkim/asn1.py", line 85, in asn1_parse
    r.append(asn1_parse(t[1], data[i:i+length]))
  File "/usr/local/lib/python3.7/site-packages/dkim/asn1.py", line 92, in asn1_parse
    "Unexpected tag (got %02x, expecting %02x)" % (tag, t[0]))
dkim.asn1.ASN1FormatError: Unexpected tag (got 30, expecting 02)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/dkim/__init__.py", line 827, in sign
    pk = parse_pem_private_key(privkey)
  File "/usr/local/lib/python3.7/site-packages/dkim/crypto.py", line 170, in parse_pem_private_key
    return parse_private_key(pkdata)
  File "/usr/local/lib/python3.7/site-packages/dkim/crypto.py", line 142, in parse_private_key
    raise UnparsableKeyError('Unparsable private key: ' + str(e))
dkim.crypto.UnparsableKeyError: Unparsable private key: Unexpected tag (got 30, expecting 02)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/code/app/email_utils.py", line 458, in add_dkim_signature
    add_dkim_signature_with_header(msg, email_domain, dkim_headers)
  File "/code/app/email_utils.py", line 489, in add_dkim_signature_with_header
    include_headers=dkim_headers,
  File "/usr/local/lib/python3.7/site-packages/dkim/__init__.py", line 1335, in sign
    return d.sign(selector, domain, privkey, identity=identity, canonicalize=canonicalize, include_headers=include_headers, length=length)
  File "/usr/local/lib/python3.7/site-packages/dkim/__init__.py", line 829, in sign
    raise KeyFormatError(str(e))
dkim.KeyFormatError: Unparsable private key: Unexpected tag (got 30, expecting 02)
2022-07-29 19:08:15,907 - SL - WARNING - 9 - "/code/app/email_utils.py:461" - add_dkim_signature() -  - DKIM fail with [b'From', b'To']
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/dkim/crypto.py", line 140, in parse_private_key
    pka = asn1_parse(ASN1_RSAPrivateKey, data)
  File "/usr/local/lib/python3.7/site-packages/dkim/asn1.py", line 85, in asn1_parse
    r.append(asn1_parse(t[1], data[i:i+length]))
  File "/usr/local/lib/python3.7/site-packages/dkim/asn1.py", line 92, in asn1_parse
    "Unexpected tag (got %02x, expecting %02x)" % (tag, t[0]))
dkim.asn1.ASN1FormatError: Unexpected tag (got 30, expecting 02)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/dkim/__init__.py", line 827, in sign
    pk = parse_pem_private_key(privkey)
  File "/usr/local/lib/python3.7/site-packages/dkim/crypto.py", line 170, in parse_pem_private_key
    return parse_private_key(pkdata)
  File "/usr/local/lib/python3.7/site-packages/dkim/crypto.py", line 142, in parse_private_key
    raise UnparsableKeyError('Unparsable private key: ' + str(e))
dkim.crypto.UnparsableKeyError: Unparsable private key: Unexpected tag (got 30, expecting 02)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/code/app/email_utils.py", line 458, in add_dkim_signature
    add_dkim_signature_with_header(msg, email_domain, dkim_headers)
  File "/code/app/email_utils.py", line 489, in add_dkim_signature_with_header
    include_headers=dkim_headers,
  File "/usr/local/lib/python3.7/site-packages/dkim/__init__.py", line 1335, in sign
    return d.sign(selector, domain, privkey, identity=identity, canonicalize=canonicalize, include_headers=include_headers, length=length)
  File "/usr/local/lib/python3.7/site-packages/dkim/__init__.py", line 829, in sign
    raise KeyFormatError(str(e))
dkim.KeyFormatError: Unparsable private key: Unexpected tag (got 30, expecting 02)
2022-07-29 19:08:15,909 - SL - WARNING - 9 - "/code/app/email_utils.py:461" - add_dkim_signature() -  - DKIM fail with [b'Message-ID', b'Date']
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/dkim/crypto.py", line 140, in parse_private_key
    pka = asn1_parse(ASN1_RSAPrivateKey, data)
  File "/usr/local/lib/python3.7/site-packages/dkim/asn1.py", line 85, in asn1_parse
    r.append(asn1_parse(t[1], data[i:i+length]))
  File "/usr/local/lib/python3.7/site-packages/dkim/asn1.py", line 92, in asn1_parse
    "Unexpected tag (got %02x, expecting %02x)" % (tag, t[0]))
dkim.asn1.ASN1FormatError: Unexpected tag (got 30, expecting 02)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/dkim/__init__.py", line 827, in sign
    pk = parse_pem_private_key(privkey)
  File "/usr/local/lib/python3.7/site-packages/dkim/crypto.py", line 170, in parse_pem_private_key
    return parse_private_key(pkdata)
  File "/usr/local/lib/python3.7/site-packages/dkim/crypto.py", line 142, in parse_private_key
    raise UnparsableKeyError('Unparsable private key: ' + str(e))
dkim.crypto.UnparsableKeyError: Unparsable private key: Unexpected tag (got 30, expecting 02)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/code/app/email_utils.py", line 458, in add_dkim_signature
    add_dkim_signature_with_header(msg, email_domain, dkim_headers)
  File "/code/app/email_utils.py", line 489, in add_dkim_signature_with_header
    include_headers=dkim_headers,
  File "/usr/local/lib/python3.7/site-packages/dkim/__init__.py", line 1335, in sign
    return d.sign(selector, domain, privkey, identity=identity, canonicalize=canonicalize, include_headers=include_headers, length=length)
  File "/usr/local/lib/python3.7/site-packages/dkim/__init__.py", line 829, in sign
    raise KeyFormatError(str(e))
dkim.KeyFormatError: Unparsable private key: Unexpected tag (got 30, expecting 02)
2022-07-29 19:08:15,911 - SL - WARNING - 9 - "/code/app/email_utils.py:461" - add_dkim_signature() -  - DKIM fail with [b'From']
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/dkim/crypto.py", line 140, in parse_private_key
    pka = asn1_parse(ASN1_RSAPrivateKey, data)
  File "/usr/local/lib/python3.7/site-packages/dkim/asn1.py", line 85, in asn1_parse
    r.append(asn1_parse(t[1], data[i:i+length]))
  File "/usr/local/lib/python3.7/site-packages/dkim/asn1.py", line 92, in asn1_parse
    "Unexpected tag (got %02x, expecting %02x)" % (tag, t[0]))
dkim.asn1.ASN1FormatError: Unexpected tag (got 30, expecting 02)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/dkim/__init__.py", line 827, in sign
    pk = parse_pem_private_key(privkey)
  File "/usr/local/lib/python3.7/site-packages/dkim/crypto.py", line 170, in parse_pem_private_key
    return parse_private_key(pkdata)
  File "/usr/local/lib/python3.7/site-packages/dkim/crypto.py", line 142, in parse_private_key
    raise UnparsableKeyError('Unparsable private key: ' + str(e))
dkim.crypto.UnparsableKeyError: Unparsable private key: Unexpected tag (got 30, expecting 02)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/code/app/email_utils.py", line 458, in add_dkim_signature
    add_dkim_signature_with_header(msg, email_domain, dkim_headers)
  File "/code/app/email_utils.py", line 489, in add_dkim_signature_with_header
    include_headers=dkim_headers,
  File "/usr/local/lib/python3.7/site-packages/dkim/__init__.py", line 1335, in sign
    return d.sign(selector, domain, privkey, identity=identity, canonicalize=canonicalize, include_headers=include_headers, length=length)
  File "/usr/local/lib/python3.7/site-packages/dkim/__init__.py", line 829, in sign
    raise KeyFormatError(str(e))
dkim.KeyFormatError: Unparsable private key: Unexpected tag (got 30, expecting 02)
2022-07-29 19:08:15,911 - SL - ERROR - 9 - "/code/server.py:380" - error_handler() -  - Cannot create DKIM signature
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1950, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1936, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/usr/local/lib/python3.7/site-packages/flask_limiter/extension.py", line 702, in __inner
    return obj(*a, **k)
  File "/code/app/auth/views/forgot_password.py", line 37, in forgot_password
    send_reset_password_email(user)
  File "/code/app/dashboard/views/setting.py", line 433, in send_reset_password_email
    email_utils.send_reset_password_email(user.email, reset_password_link)
  File "/code/app/email_utils.py", line 163, in send_reset_password_email
    reset_password_link=reset_password_link,
  File "/code/app/email_utils.py", line 333, in send_email
    add_dkim_signature(msg, email_domain)
  File "/code/app/email_utils.py", line 473, in add_dkim_signature
    raise Exception("Cannot create DKIM signature")
Exception: Cannot create DKIM signature
2022-07-29 19:08:15,914 - SL - DEBUG - 9 - "/code/server.py:283" - after_request() -  - 10.0.0.1 POST /auth/forgot_password ImmutableMultiDict([]) 500, takes 0.03918600082397461
2022-07-29 23:59:39,513 - SL - DEBUG - 10 - "/code/server.py:283" - after_request() -  - 10.0.0.1 GET / ImmutableMultiDict([]) 302, takes 0.00030994415283203125
2022-07-29 23:59:39,610 - SL - DEBUG - 9 - "/code/server.py:283" - after_request() -  - 10.0.0.1 GET /auth/login ImmutableMultiDict([]) 200, takes 0.001558065414428711
2022-07-30 07:42:07,346 - SL - DEBUG - 9 - "/code/server.py:283" - after_request() -  - 198.235.24.11 GET / ImmutableMultiDict([]) 302, takes 0.00031948089599609375
2022-07-30 07:42:07,858 - SL - DEBUG - 10 - "/code/server.py:283" - after_request() -  - 10.0.0.1 GET /auth/login ImmutableMultiDict([]) 200, takes 0.006139278411865234

Expected behavior A clear and concise description of what you expected to happen. Mails should be received without any error. Screenshots If applicable, add screenshots to help explain your problem.

Environment (If applicable):

Additional context Add any other context about the problem here.

Spitfireap commented 2 years ago

Upstream bug has been fixed. It will be available in the next release of dkimpy. In the meantime, either use openssl1 or use -traditional argument for private key generation :)

akash07k commented 2 years ago

@Spitfireap Wow, that's wonderful to know. so, till when this fix land in SimpleLogin images? And can I replace my DKIM keys without setting up the whole instance from the scratch?

Upstream bug has been fixed. It will be available in the next release of dkimpy. In the meantime, either use openssl1 or use -traditional argument for private key generation :)

Spitfireap commented 2 years ago

Not before the fix is released on dkimpy, I have no timeline, but it should be rather quick. To replace your DKIM key you just need to replace the one you already have (don't forget to update your dns!) and restart all the docker containers (a reboot of the vps can work also).

akash07k commented 2 years ago

Wonderful.

I'll try it.

Thanks a lot.

Also, I see that SimpleLogin 4.12.0 is just released. any idea that it can be used stabally or not?

On 8/1/2022 8:09 PM, Spitfireap wrote:

Not before the fix is released on dkimpy, I have no timeline, but it should be rather quick. To replace your DKIM key you just need to replace the one you already have (don't forget to update your dns!) and restart all the docker containers (a reboot of the vps can work also).

— Reply to this email directly, view it on GitHub https://github.com/simple-login/app/issues/1203#issuecomment-1201293726, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABQWBMZHG3QIHSJKQAQB47LVW7ORDANCNFSM55DAEEPA. You are receiving this because you authored the thread.Message ID: @.***>

Spitfireap commented 2 years ago

No clue. Perhaps @nguyenkims knows more about it.

But you have to understand that most development you see here is for the commercial side of SimpleLogin and not self host environment. SimpleLogin as self hosted environment doesn't require that much more it already has. So 4.6.2 is good enough I think :)

akash07k commented 2 years ago

@Spitfireap Ah, I got it. I'll continue with 4.6 then

nguyenkims commented 2 years ago

@akash07k @Spitfireap The 4.12.0 is actually our internal version and hasn't been tested for self hosting. It usually has a lot of commercial features related to subscriptions that aren't needed for self hosting.

akash07k commented 2 years ago

@nguyenkims Any plans to make the latest builds ready for selfhosting?

MuhammadNaeem42 commented 11 months ago

i will help you to setup this application contact me https://www.fiverr.com/s/9W3PNA simple

SwapnilSoni1999 commented 1 week ago

Still facing the same issue in latest version