Ironbin


  • 首页

  • 关于

  • 标签

  • 分类

  • 归档

  • 搜索

使用 vs2015 编译 OpenSSL

发表于 2017-01-16 | 分类于 openssl | | 阅读次数:

OpenSSL 版本

openssl-1.0.2j

必需的工具

  • Visual Studio 2015
  • ActivePerl
  • Nasm (The Netwide Assembler)

nasm 需要根据需要下载32位或64位版本:

  • 32位
  • 64位

编译32位版本

1. 初始化命令行环境

1
2
3
4
5
6

cd C:\build\src\openssl-1.0.2j

set PATH=%PATH%;C:\nasm

"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat"

2. 初始化编译配置

1
2
3
perl Configure VC-WIN32 no-asm

ms\do_nasm

3. 编译

1
2
3
4
5
6
7
8
// 静态库
nmake /f ms\nt.mak
nmake /f ms\nt.mak test
nmake /f ms\nt.mak install

// 动态库
nmake -f ms\ntdll.mak
nmake -f ms\ntdll.mak install

编译64位版本

1. 初始化命令行环境

1
2
3
4
5
6

cd C:\build\src\openssl-1.0.2j

set PATH=%PATH%;C:\nasm

"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" amd64

2. 初始化编译配置

1
2
3
perl Configure VC-WIN64A no-asm

ms\do_win64a

3. 编译

1
2
3
4
5
6
7
8
// 静态库
nmake /f ms\nt.mak
nmake /f ms\nt.mak test
nmake /f ms\nt.mak install

// 动态库
nmake -f ms\ntdll.mak
nmake -f ms\ntdll.mak install

遇到的错误

1
2
3
4
5
Assembling: tmp32\sha1-586.asm
tmp32\sha1-586.asm(1427) : error A2070: invalid instruction operands
tmp32\sha1-586.asm(1571) : error A2070: invalid instruction operands
NMAKE : fatal error U1077: 'ml' : return code '0x1'
Stop.

解决: perl Configure VC-WIN32 no-asm 加上 no-asm

关于证书类型

发表于 2016-12-20 | 分类于 crypto | | 阅读次数:

证书的编码(encoding)分类

首先,ASN.1 定义了几个编码格式,成为了 X.690 标准,它们是:

  • Basic Encoding Rules (BER)
  • Canonical Encoding Rules (CER)
  • Distinguished Encoding Rules (DER)

然后证书采用了 DER 作为 二进制 编码格式;但是为了便于阅读和传送,也可以将二进制转换为 base64 形式,又引入了 PEM 格式,如下所示:

  • Privacy-enhanced Electronic Mail (PEM) :将 DER 的做 base64 编码,并在开头和结尾加入标识:"-----BEGIN CERTIFICATE-----" 和 "-----END CERTIFICATE-----"

证书的存储格式

  • .pem
  • .cer, .crt, .der
  • .p7b, .p7c
  • .p12
  • .pfx
  • .key

.pem

存储的是 base64 格式,也就是 PEM 格式

.cer, .crt, .der

通常存储的是 DER 编码的二进制格式

.p7b, .p7c

不包含数据的 PKCS#7 签名格式, 只包含证书或CRL
开头和结尾是:"-----BEGIN PKCS7-----" 和 "-----END PKCS7-----"

.pfx

personal information exchange (PFX) 也是 PKCS#12 格式,这是微软提出的格式

.p12

PKCS#12 格式,包含了证书和私钥,私钥有密码保护,Netscape 提出的格式

.key

用于 PKCS#8 的公钥或私钥,编码支持 DER 或 PEM 2种格式

查看证书

查看 DER 证书

1
openssl x509 -in certificate.der -inform der -text -noout

查看 PEM 证书

1
2
3
openssl x509 -in cert.pem -text -noout
openssl x509 -in cert.cer -text -noout
openssl x509 -in cert.crt -text -noout

编码转换

DER -> PEM

1
openssl x509 -in cert.crt -inform der -outform pem -out cert.pem

PEM -> DER

1
openssl x509 -in cert.crt -outform der -out cert.der

PEM -> P7B

1
openssl crl2pkcs7 -nocrl -certfile certificate.cer -out certificate.p7b -certfile CACert.cer

PEM -> PFX

1
openssl pkcs12 -export -out certificate.pfx -inkey privateKey.key -in certificate.crt -certfile CACert.crt

PFX -> PEM

1
openssl pkcs12 -in certificate.pfx -out certificate.cer -nodes

P7B -> PEM

1
openssl pkcs7 -print_certs -in certificate.p7b -out certificate.cer

P7B -> PFX

1
2
3
openssl pkcs7 -print_certs -in certificate.p7b -out certificate.cer

openssl pkcs12 -export -in certificate.cer -inkey privateKey.key -out certificate.pfx -certfile CACert.cer

MySQL升级到5.7

发表于 2016-08-28 | 分类于 mysql | | 阅读次数:

Step 1: Uninstall MySQL Packages
First uninstall all the MySQL packages installed on your server

1
2
3
4
5
6

> yum remove mysql mysql-server

> yum list installed | grep mysql

> yum remove mysql-client mysql-server mysql-common mysql-devel
1
2
3
4

> rm -rf /var/lib/mysql/

> rm -rf /etc/my.cnf

Step 2: Romove MySQL Directory
Now we need to remove MySQL data directory from system which by default exists at /var/lib/mysql. If you didn’t find this, It may be changed to some other place, which you can find in my.cnf file with variable datadir. Delete the /var/lib/mysql directory from system but we prefer to rename it to keep a backup of existing files.

1
> mv /var/lib/mysql /var/lib/mysql_old_backup

Step 3: Install MySQL Packages Again
After removing MySQL completely, install it again using yum package manager, It will re create mysql directory under /var/lib/.

1
> yum install mysql mysql-server
1
2
3
4
5
6
7
8
9
> mysql_upgrade -uroot -p

> grep 'temporary password' /var/log/mysqld.log

> mysql_secure_installation

> we can set it in my.cnf file
> [mysqld]
> validate_password_policy=LOW

参考

How to Install Latest MySQL 5.7.9 on RHEL/CentOS 7/6/5 and Fedora

CentOS6 安装 nginx, MySQL, PHP

发表于 2016-08-28 | 分类于 linux | | 阅读次数:

参考

How To Install Linux, nginx, MySQL, PHP (LEMP) stack on CentOS 6

Linux 查看磁盘空间使用

发表于 2016-08-18 | 分类于 linux | | 阅读次数:

df

du

fdisk

参考

df、du、fdisk:Linux磁盘管理三板斧的使用心得

IntelliJ,Tomcat,Maven,Spring

发表于 2016-08-16 | 分类于 java | | 阅读次数:

常见问题

1)IntelliJ 部署目录是不是 Tomcat webapps 目录?

IntelliJ 默认发布到 ${dir.to.idea.project}\YourWebApp\out\artifacts,而不是 Tomcat webapps 目录。但是可以通过配置,将配置文件发现到 Tomcat 目录:

配置发布tomcat

1
2


Supervisor 使用小结

发表于 2016-06-03 | 分类于 linux | | 阅读次数:

安装

通过 pip 来安装

1
> pip install supervisor

如果还没有 pip,运行下面的命令:

1
2
3
4
> curl -O http://python-distribute.org/distribute_setup.py
> python distribute_setup.py
> sudo easy_install pip
> sudo pip install supervisor

在 Mac OS 下,还可能通过 homebrew 安装:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
> brew install distribute
> sudo easy_install pip
> sudo pip install supervisor
```

### 创建配置文件

一旦安装完成,运行 `echo_supervisord_conf` 将打印一个标准的配置模板,可将其保存到下列配置路径中:

```shell
/usr/local/share/etc/supervisord.conf
/usr/local/share/supervisord.conf
./supervisord.conf
./etc/supervisord.conf
/etc/supervisord.conf

将标准配置输出到某个路径下的命令是:

1
> echo_supervisord_conf > /etc/supervisord.conf

运行 supervisor

supervisor 提供了2个运行程序:守护程序 supervisord 和客户端程序 supervisorctl。守护程序在后台运行,管理其它进程;客户端程序用于操作supervisor。

启动守护进程:

1
2
> supervisord 
> supervisord -c /path/to/supervisord.conf # 或指定配置文件

Mac OS 配置 launchd

添加文件 /Library/LaunchDaemons/com.agendaless.supervisord.plist

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">
<plist version=\"1.0\">
<dict>
<key>KeepAlive</key>
<dict>
<key>SuccessfulExit</key>
<false/>
</dict>
<key>Label</key>
<string>com.agendaless.supervisord</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/share/python/supervisord</string>
<string>-n</string>
<string>-c</string>
<string>/usr/local/share/supervisor/supervisord.conf</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>

注册 plist

1
> launchctl load /Library/LaunchDaemons/com.agendaless.supervisord.plist

使用 supervisorctl

1
2
3
4
5
6
7
8
9
10
11
> supervisorctl -c /etc/supervisord.conf

> status # 查看程序状态
> stop foo # 关闭 foo 程序
> start foo # 启动 foo 程序
> restart foo # 重启 foo 程序
> reread # 读取有更新(增加)的配置文件,不会启动新添加的程序
> update # 重启配置文件修改过的程序
> tail foo stdout
> tail -f foo
> tail -f foo stderr

通过命令行直接运行:

1
> sudo supervisorctl start foo

修改配置文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
[unix_http_server]
file=/tmp/supervisor.sock ; UNIX socket 文件,supervisorctl 会使用
;chmod=0700 ; socket 文件的 mode,默认是 0700
;chown=nobody:nogroup ; socket 文件的 owner,格式: uid:gid

[inet_http_server] ; HTTP 服务器,提供 web 管理界面
port=127.0.0.1:9001 ; Web 管理后台运行的 IP 和端口,如果开放到公网,需要注意安全性
;username=user ; 登录管理后台的用户名
;password=123 ; 登录管理后台的密码

[supervisord]
logfile=/tmp/supervisord.log ; 日志文件,默认是 $CWD/supervisord.log
logfile_maxbytes=50MB ; 日志文件大小,超出会 rotate,默认 50MB
logfile_backups=10 ; 日志文件保留备份数量默认 10
loglevel=info ; 日志级别,默认 info,其它: debug,warn,trace
pidfile=/tmp/supervisord.pid ; pid 文件
nodaemon=false ; 是否在前台启动,默认是 false,即以 daemon 的方式启动
minfds=1024 ; 可以打开的文件描述符的最小值,默认 1024
minprocs=200 ; 可以打开的进程数的最小值,默认 200

; the below section must remain in the config file for RPC
; (supervisorctl/web interface) to work, additional interfaces may be
; added by defining them in separate rpcinterface: sections
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface

[supervisorctl]
serverurl=unix:///tmp/supervisor.sock ; 通过 UNIX socket 连接 supervisord,路径与 unix_http_server 部分的 file 一致
;serverurl=http://127.0.0.1:9001 ; 通过 HTTP 的方式连接 supervisord

; 包含其他的配置文件
[include]
files = relative/directory/*.ini ; 可以是 *.conf 或 *.ini

当更新配置文件后,重新启动守护进程:

1
supervisord -c /etc/supervisord.conf

常用程序

nginx

1
2
3
4
[program:nginx]
command=sudo /usr/local/sbin/nginx
autostart=false
autorestart=true

laravel queue

1
2
3
4
5
6
7
8
9
[program:laravel-worker]
process_name=%(program_name)s_%(process_num)02d
command=php /home/forge/app.com/artisan queue:work sqs --sleep=3 --tries=3 --daemon
autostart=true
autorestart=true
user=forge
numprocs=8
redirect_stderr=true
stdout_logfile=/home/forge/app.com/worker.log

可能遇到的问题:

问题:

* Starting Supervisor daemon manager...
Error: Another program is already listening on a port that one of our HTTP servers is configured to use.  Shut this program down first before starting supervisord.
For help, use /usr/bin/supervisord -h
   ...fail!

解决办法:
删除 supervisor.sock

PHP 使用小结

发表于 2016-05-28 | 分类于 php | | 阅读次数:

PHP 环境信息

1
php -i
  • 查看配置文件位置:php -i | grep php.ini
  • 根据关键字查询配置:php -i | grep memory

###

COM 组件 AddRef/Release 用法

发表于 2016-05-24 | 分类于 C++ | | 阅读次数:

AddRef/Release 是 COM 组件的垃圾回收机制。当请求一个接口时,调用AddRef增加引用计数;当使用完该接口时,调用Release减少计数,计数为0时,释放接口(释放接口对应的对象,内存如何操作?)。

IUnknown

QueryInterface VS QueryControl

CoCreateInstance

CComQIPtr VS CComPtr

附录:

  • COM组件的AddRef和Release()方法使用
  • Reference Counting Rules
  • COM :IUnknown接口QueryInterface函数介绍
  • COM编程——引用计数(1)
  • COM编程——引用计数(2)
  • COM编程——QueryInterface函数(1)
  • COM编程——QueryInterface函数(2)

Amazon EC2 启用 root 登录

发表于 2016-03-06 | 分类于 php | | 阅读次数:

在亚马逊安装完 EC2 云主机实例,当使用 root 账号登录时,会收到下面的信息:

“Please login as the user “centos” rather than the user “root”.” Then the connection will close.

如果你想启用root账号 SSH 登录,可以按下面的步骤:

  • 第一步:先登录云主机
1
# ssh -i privateKey.pem  root@ip-address
  • 第二步:切换到 root 模式
1
# sudo -s
  • 第三步:修改密钥验证文件
    打开 authorized_keys,删除从开头到 sh-rsa 之前的内容。
1
# vi /root/.ssh/authorized_keys
  • 第四步:修改ssh配置文件

打开 sshd_config,注释掉 PermitRootLogin yes

1
# vi /etc/ssh/sshd_config
  • 第五步:重启 SSH 守护进程(demand)
1
# systemctl restart sshd

现在,你可以重新以 root 用户登录实例了。

1…8910…12
程学彬

程学彬

117 日志
48 分类
99 标签
Creative Commons
Links
  • ShinySky
0%
© 2014 — 2020 程学彬