server icon indicating copy to clipboard operation
server copied to clipboard

Self-Hosted unable to access admin portal or register new user

Open scharri opened this issue 6 years ago • 9 comments

Hello Guys, since .NET Core update of bitwarden server i am unable to access admin portal or register new user because as you can see i get an exception when mailkit tries to send a mail. My SMPT settings are: globalSettings__mail__replyToEmail= globalSettings__mail__smtp__host= globalSettings__mail__smtp__port=587 globalSettings__mail__smtp__ssl=true

Theses settings did work. I also tried to change smtp port to 465 which my provider also support but same error. I also tried to downgrade Debian's OpenSSL Security Level from 2 to 1 in /etc/ssl/openssl.cnf but same result.

2020-04-13 19:59:24.882 +00:00 [Information] Migrating database.
2020-04-13 19:59:25.281 +00:00 [Information] Beginning transaction
2020-04-13 19:59:25.284 +00:00 [Information] Beginning database upgrade
2020-04-13 19:59:25.286 +00:00 [Information] Checking whether journal table exists..
2020-04-13 19:59:25.304 +00:00 [Information] Fetching list of already executed scripts.
2020-04-13 19:59:25.309 +00:00 [Information] No new scripts need to be executed - completing.
2020-04-13 19:59:25.310 +00:00 [Information] Migration successful.
2020-04-13 19:59:29.790 +00:00 [Error] An error occurred while attempting to establish an SSL or TLS connection.

This usually means that the SSL certificate presented by the server is not trusted by the system for one or more of
the following reasons:

1. The server is using a self-signed certificate which cannot be verified.
2. The local system is missing a Root or Intermediate certificate needed to verify the server's certificate.
3. A Certificate Authority CRL server for one or more of the certificates in the chain is temporarily unavailable.
4. The certificate presented by the server is expired or invalid.

Another possibility is that you are trying to connect to a port which does not support SSL/TLS.

It is also possible that the set of SSL/TLS protocols supported by the client and server do not match.

See https://github.com/jstedfast/MailKit/blob/master/FAQ.md#SslHandshakeException for possible solutions.

MailKit.Security.SslHandshakeException: An error occurred while attempting to establish an SSL or TLS connection.

This usually means that the SSL certificate presented by the server is not trusted by the system for one or more of
the following reasons:

1. The server is using a self-signed certificate which cannot be verified.
2. The local system is missing a Root or Intermediate certificate needed to verify the server's certificate.
3. A Certificate Authority CRL server for one or more of the certificates in the chain is temporarily unavailable.
4. The certificate presented by the server is expired or invalid.

Another possibility is that you are trying to connect to a port which does not support SSL/TLS.

It is also possible that the set of SSL/TLS protocols supported by the client and server do not match.

See https://github.com/jstedfast/MailKit/blob/master/FAQ.md#SslHandshakeException for possible solutions.

 ---> System.Security.Authentication.AuthenticationException: Authentication failed, see inner exception.
 ---> Interop+OpenSsl+SslException: SSL Handshake failed with OpenSSL error - SSL_ERROR_SSL.
 ---> Interop+Crypto+OpenSslCryptographicException: error:141A318A:SSL routines:tls_process_ske_dhe:dh key too small
   --- End of inner exception stack trace ---
   at Interop.OpenSsl.DoSslHandshake(SafeSslHandle context, Byte[] recvBuf, Int32 recvOffset, Int32 recvCount, Byte[]& sendBuf, Int32& sendCount)
   at System.Net.Security.SslStreamPal.HandshakeInternal(SafeFreeCredentials credential, SafeDeleteContext& context, ArraySegment`1 inputBuffer, Byte[]& outputBuffer, SslAuthenticationOptions sslAuthenticationOptions)
   --- End of inner exception stack trace ---
   at System.Net.Security.SslStream.StartSendAuthResetSignal(ProtocolToken message, AsyncProtocolRequest asyncRequest, ExceptionDispatchInfo exception)
   at System.Net.Security.SslStream.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslStream.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslStream.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslStream.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslStream.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslStream.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslStream.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslStream.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslStream.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslStream.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslStream.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslStream.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslStream.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslStream.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslStream.PartialFrameCallback(AsyncProtocolRequest asyncRequest)
--- End of stack trace from previous location where exception was thrown ---
   at System.Net.Security.SslStream.ThrowIfExceptional()
   at System.Net.Security.SslStream.InternalEndProcessAuthentication(LazyAsyncResult lazyResult)
   at System.Net.Security.SslStream.EndProcessAuthentication(IAsyncResult result)
   at System.Net.Security.SslStream.EndAuthenticateAsClient(IAsyncResult asyncResult)
   at System.Net.Security.SslStream.<>c.<AuthenticateAsClientAsync>b__64_2(IAsyncResult iar)
   at System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, Action`1 endAction, Task`1 promise, Boolean requiresSynchronization)
--- End of stack trace from previous location where exception was thrown ---
   at MailKit.Net.Smtp.SmtpClient.ConnectAsync(String host, Int32 port, SecureSocketOptions options, Boolean doAsync, CancellationToken cancellationToken)
   --- End of inner exception stack trace ---
   at MailKit.Net.Smtp.SmtpClient.ConnectAsync(String host, Int32 port, SecureSocketOptions options, Boolean doAsync, CancellationToken cancellationToken)
   at Bit.Core.Services.MailKitSmtpMailDeliveryService.SendEmailAsync(MailMessage message) in /home/appveyor/projects/server/src/Core/Services/Implementations/MailKitSmtpMailDeliveryService.cs:line 84
   at Bit.Core.Services.HandlebarsMailService.SendPasswordlessSignInAsync(String returnUrl, String token, String email) in /home/appveyor/projects/server/src/Core/Services/Implementations/HandlebarsMailService.cs:line 232
   at Bit.Core.Identity.PasswordlessSignInManager`1.PasswordlessSignInAsync(String email, String returnUrl) in /home/appveyor/projects/server/src/Core/Identity/PasswordlessSignInManager.cs:line 43
   at Bit.Admin.Controllers.LoginController.Index(LoginModel model) in /home/appveyor/projects/server/src/Admin/Controllers/LoginController.cs:line 42
   at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.TaskOfIActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Awaited|12_0(ControllerActionInvoker invoker, ValueTask`1 actionResultValueTask)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeInnerFilterAsync>g__Awaited|13_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextExceptionFilterAsync>g__Awaited|25_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)

scharri avatar Apr 13 '20 20:04 scharri

Who is your SMTP mail provider?

kspearrin avatar Apr 14 '20 18:04 kspearrin

scharri , thanks for opening up this issue.

I am having same issues. the mailing (via Mailkit) and admin page were working before. my upgrade procedure missed the steps of verifying admin page login and ask for password hint. So I can't tell which version upgrade causing these two issues.

":dh key too small" look like the hint of the problem after the .net core version upgrade.


 ---> System.Security.Authentication.AuthenticationException: Authentication failed, see inner exception.
 ---> Interop+OpenSsl+SslException: SSL Handshake failed with OpenSSL error - SSL_ERROR_SSL.
 ---> Interop+Crypto+OpenSslCryptographicException: error:141A318A:SSL routines:tls_process_ske_dhe:dh key too small
   --- End of inner exception stack trace ---

@kspearrin I am on centos 7 and was able to run following command to verify mailing path from centos 7 to my SMTP server. But following is not what bitwarden (MailKit ?) used to send out email.

echo "Testing out postfix mail agent(MTA)" | mailx -r "[email protected]" -s "Dummy mail sending from `hostname`" "[email protected]"
  • here is the version info.
[bitwarden@server05~]$  docker ps --format 'table {{.Names}}\t{{.Image}}\t{{.Status}}';date
NAMES                     IMAGE                            STATUS
bitwarden-nginx           bitwarden/nginx:1.33.0           Up 48 minutes (healthy)
bitwarden-admin           bitwarden/admin:1.33.0           Up 48 minutes (healthy)
bitwarden-identity        bitwarden/identity:1.33.0        Up 48 minutes (healthy)
bitwarden-notifications   bitwarden/notifications:1.33.0   Up 48 minutes (healthy)
bitwarden-mssql           bitwarden/mssql:1.33.0           Up 48 minutes (healthy)
bitwarden-events          bitwarden/events:1.33.0          Up 48 minutes (healthy)
bitwarden-api             bitwarden/api:1.33.0             Up 48 minutes (healthy)
bitwarden-attachments     bitwarden/attachments:1.33.0     Up 48 minutes (healthy)
bitwarden-icons           bitwarden/icons:1.33.0           Up 48 minutes (healthy)
bitwarden-web             bitwarden/web:2.13.1             Up 48 minutes (healthy)
Sat Apr 25 07:59:38 EDT 2020
[bitwarden@server05 ~]$

tjyang avatar Apr 25 '20 11:04 tjyang

Switching back to my previous VMWare snapshot (version 1.32) fixed the issue.

tjyang avatar Apr 25 '20 21:04 tjyang

What mail provider is being used here? I can try opening an issue with MailKit, but I will need more information about the configuration.

kspearrin avatar Jun 11 '20 15:06 kspearrin

The issue seems to be covered here: https://github.com/dotnet/runtime/issues/30667#issuecomment-566482876

It seems the latest .NET images are based on Debian Buster which has SECLEVEL=2, requiring a dh key of size 2048 or greater. Is your mail server using a smaller dh key? Is it possible to upgrade to a larger key?

kspearrin avatar Jun 11 '20 15:06 kspearrin

@kspearrin Thanks for tracing down the root cause. Sorry, Upgrading internal mail relay server is my control. I don't know about .Net at all, Is it possible to set SECLEVEL=1 in global.override.env ?

tjyang avatar Jun 11 '20 15:06 tjyang

@kspearrin Also thanks from me. In my case my mail provider is using only a 1024 bit key which cause the problem mentioned above. It would be great to set SECLEVEL=1 via global.override.env or inside .NET image. In my opinion a downgrade is no option for me.

scharri avatar Jun 11 '20 18:06 scharri

  • This issue can be closed, IMO.
  • This one-liner can be used to report back remote mail server's key strength. ( should be 2048 or above).
echo | openssl s_client -connect mail-really.test.com:25 -starttls smtp -cipher kEDH |egrep "Server Temp Key"

tjyang avatar Jun 17 '20 14:06 tjyang

For any users experiencing this issue after updating to 1.33 or above. The recommended fix is to update the mail server certificate to use a 2048 bit key at a minimum.

If you need to make an exception and override the key strength check then you can use a Docker Compose override. This override will lower the SECLEVEL requirement to a 1 in the relevant containers (Admin, Api, and Identity). You can add the override file (docker-compose.override.yml) to your ./bwdata/docker/ directory and restart the Bitwarden Server.

version: '3'

services:
  api:
    entrypoint:
      - /bin/sh
      - -c
      - |
        sed -i 's|DEFAULT@SECLEVEL=2|DEFAULT@SECLEVEL=1|g' /etc/ssl/openssl.cnf
        /entrypoint.sh
  identity:
    entrypoint:
      - /bin/sh
      - -c
      - |
        sed -i 's|DEFAULT@SECLEVEL=2|DEFAULT@SECLEVEL=1|g' /etc/ssl/openssl.cnf
        /entrypoint.sh
  admin:
    entrypoint:
      - /bin/sh
      - -c
      - |
        sed -i 's|DEFAULT@SECLEVEL=2|DEFAULT@SECLEVEL=1|g' /etc/ssl/openssl.cnf
        /entrypoint.sh

sevensixseven avatar Jun 17 '20 16:06 sevensixseven