HyperSharp.NET

拈万物化阴阳之数是为吾道。

0%

今天收到Twilio的API安全更新通知邮件,Twilio将会禁用老版本的TLS加密套件,并推荐TLS 1.2以确保安全性。
用Chrome打开我们项目中用到的Twilio页面,在Devtools中的Security标签中发现如下提示信息:

Connection – obsolete connection settings
The connection to this site uses TLS 1.0 (an obsolete protocol), ECDHE_RSA with P-256 (a strong key exchange), and AES_256_CBC with HMAC-SHA1 (an obsolete cipher).

下面将通过编辑注册表来在Windows Server 2008 R2中启用TLS 1.2安全性。

启用TLS 1.2

  1. 备份相关的注册表设置
  2. 运行regedit打开注册表编辑器,展开到[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols]
  3. 修改注册表启用TLS 1.1和TLS 1.2
    1. 在Protocols下添加TLS 1.1和TLS 1.2的Key
    2. 分别在TLS 1.1和TLS 1.2下面创建Client和Server两个Key
    3. 分别在Client和Server下添加两个DWORD值:DisabledByDefault [Value = 0]Enabled [Value = 1],最终结果如下:
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.1 ]

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.1 \Client]
"DisabledByDefault"=dword:00000000
"Enabled"=dword:00000001

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.1 \Server]
"DisabledByDefault"=dword:00000000
"Enabled"=dword:00000001

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2]

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2\Client]
"DisabledByDefault"=dword:00000000
"Enabled"=dword:00000001

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2\Server]
"DisabledByDefault"=dword:00000000
"Enabled"=dword:00000001
  1. 如果在Protocols下面发现有旧版TLS和SSL,可以像如下一样修改将DisabledByDefault和Enabled设为0
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\SSL 2.0\Client]
"DisabledByDefault"=dword:00000000
"Enabled"=dword:00000000

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\SSL 2.0\Server]
"DisabledByDefault"=dword:00000000
"Enabled"=dword:00000000
  1. 重启计算机

更新加密套件(Cipher Suites)

重启后刷新页面,这时在Devtools中的Security标签中提示加密套件过时了:

Connection – obsolete connection settings
The connection to this site uses TLS 1.2 (a strong protocol), ECDHE_RSA with P-256 (a strong key exchange), and AES_256_CBC with HMAC-SHA1 (an obsolete cipher).

在Twilio的API安全更新通知邮件中推荐使用如下的加密套件:

TLS 1.2:
TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384
TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384
TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA
TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256
TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA

TLS 1.1:
TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA
TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA

TLS-Cipher-SuiteTips: 加密套件字符串的定义

安装KB3042058即可更新Windows Server 2012 R2 中加密密码套件优先级。

参考链接

安装 Nginx

Neginx 安装比较简单,从官网 nginx for Windows 下载页面下载压缩包,解压到C:\nginx\目录下即可。

快速停止或关闭 Nginx:nginx -s stop
正常停止或关闭 Nginx:nginx -s quit
配置文件修改重装载命令:nginx -s reload

注册 Nginx 系统服务

Nginx 运行在 Windows 服务器上,系统重启后 Nginx 并不会自动启动。有时候意外重启忘记动手启动 Nginx,网站就会无法访问了,比较麻烦。如何作为一个系统服务自动启动,现在并没有官方的解决方案 。目前网上的解决方案大概有两种方式:

对比了下还是 Windows Service Wrapper 这种方式比较好。
先从 Windows service wrapper Releases 页面下载最新的 WinSW.NET2.exe 或 WinSW.NET4.exe,下载后复制并重命名到路径:C:\nginx\nginxws.exe
然后在 C:\nginx\nginxws.xml 新建配置文件,内容如下:

<configuration>
  <id>nginx</id>
  <name>Nginx</name>
  <description>Nginx for windows</description>
  <executable>C:\nginx\nginx.exe</executable>
  <logpath>‪C:\nginx\logs</logpath>
  <logmode>roll</logmode>
  <depend></depend>
  <startargument>-p</startargument>
  <startargument>C:\nginx</startargument>
  <stopargument>-p</stopargument>
  <stopargument>C:\nginx</stopargument>
  <stopargument>-s</stopargument>
  <stopargument>stop</stopargument>
</configuration>

打开 CMD,执行如下命令安装系统服务:C:\nginx\nginxws.exe install,窗口出现安装成功的消息即可。

我根据网上的文章操作的时候,在这边碰到个让人吐血的问题,按上述方式安装好服务后,无法启动 nginx,然后在错误日志中发现 executable 路径前面多个了个?

2018-01-07 21:19:44,769 INFO  - Starting ServiceWrapper in the service mode
2018-01-07 21:19:44,832 INFO  - Starting ?C:\nginx\nginx.exe  -p c:\nginx
2018-01-07 21:19:44,847 INFO  - Starting ?C:\nginx\nginx.exe  -p c:\nginx
2018-01-07 21:19:44,863 DEBUG - Completed. Exit code is 0

检查配置文件是对的,查看 Windows service wrapper 的源代码也没发现什么地方能多个?出来,最后实在没办法,从头手打一遍配置文件,重新安装服务,居然好了。才发现,原来是<executable>‪C:\nginx\nginx.exe之间多了个不可见字符(\u202A)。。。

img

参考链接

在 CentOS,RHEL 之类的系统上,安装 MariaDB 最简单的方式是使用 Yun 命令。

配置 yum 源

首先我们需要在以下位置创建 yum 源文件

vi /etc/yum.repos.d/MariaDB.repo

在文件内插入以下内容:

[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.3/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1

运行命令安装 MariaDB

yum -y install MariaDB-server MariaDB-client

成功安装后,可以通过以下命令控制 MariaDB 服务:

systemctl start mariadb         #启动服务
systemctl enable mariadb        #设置开机启动
systemctl restart mariadb       #重新启动
systemctl stop mariadb.service  #停止服务

使用 mysql_secure_installation 命令配置服务器

mysql_secure_installation   # 运行配置命令
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] y  # 设置root密码
New password:               # ***********
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y  # 是否移除匿名用户
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] Y # 是否禁止root用户远程登陆
 ... Success!

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] Y # 是否移除测试数据库
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] Y  # 是否重载权限表
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

配置 MariaDB 的字符集

查看/etc/my.cnf文件内容,其中包含一句 !includedir /etc/my.cnf.d 说明在该配置文件中引入 /etc/my.cnf.d 目录下的配置文件。

1)使用 vi server.cnf 命令编辑 server.cnf 文件,在 [mysqld] 标签下添加:

init_connect='SET collation_connection = utf8_unicode_ci' 
init_connect='SET NAMES utf8' 
character-set-server=utf8 
collation-server=utf8_unicode_ci 
skip-character-set-client-handshake

如果 /etc/my.cnf.d 目录下无 server.cnf 文件,则直接在 /etc/my.cnf 文件的 [mysqld] 标签下添加以上内容。

2)用 vi client.cnf 命令编辑 /etc/my.cnf.d/client.cnf 文件,在[client] 标签下添加:

default-character-set=utf8

3)用 vi mysql-clients.cnf 命令编辑 /etc/my.cnf.d/mysql-clients.cnf 文件,在 [mysql] 标签下添加:

default-character-set=utf8

配置完成后 systemctl restart mariadb 重启服务。进入到数据库查看字符设置。

MariaDB [(none)]> show variables like "%character%";
+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | utf8                       |
| character_set_connection | utf8                       |
| character_set_database   | utf8                       |
| character_set_filesystem | binary                     |
| character_set_results    | utf8                       |
| character_set_server     | utf8                       |
| character_set_system     | utf8                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)

MariaDB [(none)]> show variables like "%collation%";
+----------------------+-----------------+
| Variable_name        | Value           |
+----------------------+-----------------+
| collation_connection | utf8_unicode_ci |
| collation_database   | utf8_unicode_ci |
| collation_server     | utf8_unicode_ci |
+----------------------+-----------------+
3 rows in set (0.00 sec)

添加用户,设置权限

创建数据库,创建用户并授予权限:

CREATE DATABASE IF NOT EXISTS hypersharp default character set utf8mb4 COLLATE utf8mb4_unicode_ci;
create user hypersharp;
USE mysql;
update user set Password = PASSWORD("********") where user='hypersharp';
grant all privileges on hypersharp.* to hypersharp@localhost identified by '********';

授予指定用户外部访问权限:

grant all on *.* to 'hypersharp'@'10.153.176.106/255.255.255.0' identified by '********';
grant all on *.* to 'hypersharp'@'10.137.42.136/255.255.255.0' identified by '********';
flush privileges;

参考资料

VS2015 无法调试 .NET Core 项目

最近安装了 Astrill VPN 后,发现 VS2015 没法调试.NET Core 项目,但是运行没有问题,就是调试器无法启动。我尝试关闭这个软件,结束掉所有掉进程和服务,但是依然无法调试。卸载软件后,才能恢复调试。我联系了 Astrill 客服,第二天就收到了回复:

Hi Kewell,

We would request you to please uninstall the LSP from the Astrill app.
Open the Astrill app, hold Ctrl key and click on the HELP button, then click on LSP uninstall. Hopefully, that will fix the issue.

Best regards,
Astrill VPN Suppor

按客服提示操作,卸载 LSP 模块后这个问题就解决了。

Steam 客户端兼容警告

某一次 Steam 更新后,Steam 客户端启动后会弹出警告框:

An incompatible version of ASProxy.dll (related to Astril VPN) has been detected inside of the Steam process.
We suggest updating or uninstalling this software if you experience crashes or network slowdowns while running Steam or individual games.

联系客服,第二天收到回复,依然是 LSP 的问题,卸载后解决。

LSP 是啥?

分层服务提供者(英语:Layered Service Provider,缩写 LSP)是一项已被弃用的 Microsoft Windows 中 Winsock 2 服务提供者接口(SPI)的特性,它也被称为分层服务提供商或分层服务提供程序。分层服务提供者为使用 Winsock API 插入本身到 TCP/IP 协议栈的 DLL。在进入协议栈后,分层服务提供者可以拦截和修改入站和出站的互联网流量。它可以处理所有访问互联网的应用程序(例如网页浏览器、电子邮件客户端等)连接互联网的 TCP/IP 流量。

LSP 可以用来拦截网络流量,VPN 客户端使用这个接口来实现一些功能。不过 LSP 从 Windows Server 2012 起已被弃用,所以才引起了这几个问题。

dotnet core 1.0 正式版和 VS2015 update3 安装后一直无法在 VS 中正常调试。

错误提示:The debugger’s worker process (msvsmon.exe) unexpectedly exited. Debugging will be aborted.

这不是偶然现象,因为我的两台电脑都出现同样的问题。

为此我尝试过以下方式:

  1. 重新安装 DotNetCore.1.0.0-VS2015Tools.Preview2 *无效*
  2. 重新安装 DotNetCore.1.0.0-SDK.Preview2-x64 *无效*
  3. 重新安装 VS2015 升级到 Update3 并安装上面两个组件 *无效*
  4. 我在其中一台电脑上重装系统,然后安装上述组件 有效

难道除了重装系统这个没有办法的办法,就无法解决了么?为此我详细对比了两台电脑,终于发现了问题!

环境变量 PATH 中有一个路径”C:\Users{UserName}.dnx”引起了我的注意,这是 dotnet core 的前身 dnx 的安装路径,因为我之前安装过这个测试版本,而卸载后环境变量中并没有自动删除。

我手动删除了这个 PATH 中的路径,再次运行 VS 进行调试,一切正常!

然后再恢复这个 PATH 的值,重启 VS 后,问题重现。确实是这个环境变量的问题导致 VS 无法调试 dotnet core 项目。