海运的博客

openssl验证ocsp及haproxy配置ocsp

发布时间:January 8, 2020 // 分类: // No Comments

获取网站公钥:

openssl s_client -connect www.haiyun.me:443 2>&1 < /dev/null | sed -n '/-----BEGIN/,/-----END/p' > www.haiyun.me.cer

获取签发者公钥,第一个为网站公钥,和上面获取的一样,等同于acme申请的免费ssl证书www.haiyun.me.cer,第二个为签发者公钥,两者合并等同于acme生成的fullchain.cer文件。

openssl s_client -connect www.haiyun.me:443 -showcerts 2>&1 < /dev/null | awk '/BEGIN/,/END/{ if(/BEGIN/){num++}; out="haiyun.me."num".cer"; print > out}'
#openssl s_client -showcerts -connect www.wikipedia.org:443 < /dev/null 2>&1 |  sed -n '/-----BEGIN/,/-----END/p' | sed -n '/^-----END CERTIFICATE-----/,$ p' | sed 1d > chain.pem

查看网站证书验证ocsp的网址:

openssl x509 -noout -ocsp_uri -in haiyun.me.1.cer 

ocsp验证:

openssl ocsp -noverify -no_nonce -issuer haiyun.me.2.cer -cert haiyun.me.1.cer -url http://ocsp.int-x3.letsencrypt.org --text

生成haproxy可用的ocsp文件:

openssl ocsp -noverify -no_nonce -issuer haiyun.me.2.cer -cert haiyun.me.1.cer -url http://ocsp.int-x3.letsencrypt.org -respout haproxy.ocsp

通过haproxy管理sock更新ocsp:

echo "set ssl ocsp-response `base64 -w 0 haproxy.ocsp`"|socat stdio /var/run/haproxy.sock  

如果提示以下错误:

OCSP single response: Certificate ID does not match any certificate or issuer.

因为haproxy有配置多个域名ssl证书,需先让haproxy加载ocsp文件再使用sock更新,将ocsp文件保存到haproxy配置的证书目录,名字更改为证书名ocsp,重新启动haproxy则自动加载ocsp文件。
如haproxy使用acme申请的Let’s Encrypt ecc免费证书:

cat fullchain.cer www.haiyun.me.key > www.haiyun.me.pem
mv haproxy.ocsp www.haiyun.me.pem.ocsp

haproxy配置:

bind :443 allow-0rtt ssl crt www.haiyun.me_ecc/www.haiyun.pem alpn http/1.1,h2

使用openssl验证网站配置的ocsp是否生效:

openssl s_client -connect www.haiyun.me:443 -status -tlsextdebug < /dev/null 2>&1 | sed -n '/OCSP Response Data:/,/======/p'

https://github.com/pierky/haproxy-ocsp-stapling-updater
https://icicimov.github.io/blog/server/HAProxy-OCSP-stapling/
https://raymii.org/s/articles/OpenSSL_Manually_Verify_a_certificate_against_an_OCSP.html
https://imququ.com/post/why-can-not-turn-on-ocsp-stapling.html

linux开启tcp fast open/tfo并测试

发布时间:January 6, 2020 // 分类: // No Comments

首先服务器和客户端都开启tcp fast open:

net.ipv4.tcp_fastopen = 3

使用curl开启tfo测试:

curl --tcp-fastopen https://www.haiyun.me/
#httping -F https://www.haiyun.me/

nginx开启tfo:

listen 80 fastopen=256

使用tcpdump监听数据发现:
第一次请求时客户端syn携带cookiereq,服务器如果支持tfo则返回tfo cookie:

Flags [S], options [mss 1460,sackOK,TS val 4250936141 ecr 0,nop,wscale 6,exp-tfo cookiereq], length 0
Flags [S.], options [mss 1460,sackOK,TS val 2764503812 ecr 4250936141,nop,wscale 11,exp-tfo cookie f6aecea49990ea33], length 0

后续再请求时会在syn带上tfo cookie和请求数据:

Flags [S], options [mss 1460,sackOK,TS val 4250944477 ecr 0,nop,wscale 6,exp-tfo cookie f6aecea49990ea33], length 77: HTTP: GET / HTTP/1.1

以上都配置了如果客户端syn数据包未带tfo cookiereq,则可能因为丢包或防火墙原因返回了正常模式,修改以下再测试:

net.ipv4.tcp_fastopen_blackhole_timeout_sec = 0

haproxy admin unix sock使用

发布时间:January 6, 2020 // 分类: // No Comments

配置文件开启:

stats socket /var/run/haproxy.sock mode 600 level admin 
stats timeout 2m

使用socat:

echo "help" | socat stdio /var/run/haproxy.sock

使用php:

<?php
$fp = stream_socket_client("unix:///var/run/haproxy.sock", $errno, $errstr);
if (!$fp) {
  echo "$errstr \n";
}
fwrite($fp, 'help'."\r\n");
$res = "";
while (!feof($fp)) {
  $res .= fgets($fp, 1024);
}
var_dump($res);

master sock,haproxy启动参数:

-S /var/run/haproxy-master.sock
echo "reload" | socat stdio /var/run/haproxy-master.sock

smartdns修改/删除cname ttl

发布时间:January 5, 2020 // 分类: // No Comments

diff -uN s.c dns_server.c
--- s.c 2020-01-05 18:15:46.288965975 +0800
+++ dns_server.c        2020-01-05 16:57:02.891166416 +0800
@@ -352,10 +352,13 @@
        }
 
        /* add CNAME record */
+        /*
        if (request->has_cname) {
+                //request->ttl_cname = request->has_ipv4 ?  request->ttl_v4 : request->ttl_v6;
                ret |= dns_add_CNAME(packet, DNS_RRS_AN, request->domain, request->ttl_cname, request->cname);
                domain = request->cname;
        }
+        */
 
        /* add A record */
        if (request->has_ipv4 && request->qtype == DNS_T_A) {

一些函数:
进入查询处理:_dns_server_recv _dns_server_do_query _dns_server_process_cache
转发查询结果处理:dns_server_resolve_callback
返回客户端:_dns_server_request_complete _dns_reply _dns_add_rrs

dnsstamps解析和创建sdns DNS Stamp

发布时间:December 24, 2019 // 分类: // No Comments

安装dnsstamps:

apt-get install python3-pip
python3 -m pip install --user dnsstamps
export PATH=$PATH:~/.local/bin/ 

查看使用方法:

dnsstamp.py -h
dnsstamp.py dot -h

cloudflare-dns.com dns over tls构建sdns示例:

dnsstamp.py dot -a 1.1.1.1 -n cloudflare-dns.com -l -f
DoT DNS stamp
=============

DNSSEC: no
No logs: yes
No filter: yes
IP Address: 1.1.1.1
Hostname: cloudflare-dns.com
Hashes: []
Bootstrap IPs: []

sdns://AwYAAAAAAAAABzEuMS4xLjEAEmNsb3VkZmxhcmUtZG5zLmNvbQ

解析sdns:

dnsstamp.py parse sdns://AwYAAAAAAAAABzEuMS4xLjEAEmNsb3VkZmxhcmUtZG5zLmNvbQ

https://github.com/chrisss404/python-dnsstamps

分类
最新文章
最近回复
  • opnfense: 谢谢博主!!!解决问题了!!!我之前一直以为内置的odhcp6就是唯一管理ipv6的方式
  • liyk: 这个方法获取的IPv6大概20分钟之后就会失效,默认路由先消失,然后Global IPV6再消失
  • 海运: 不好意思,没有。
  • zongboa: 您好,請問一下有immortalwrt設定guest Wi-Fi的GUI教學嗎?感謝您。
  • 海运: 恩山有很多。
  • swsend: 大佬可以分享一下固件吗,谢谢。
  • Jimmy: 方法一 nghtp3步骤需要改成如下才能编译成功: git clone https://git...
  • 海运: 地址格式和udpxy一样,udpxy和msd_lite能用这个就能用。
  • 1: 怎么用 编译后的程序在家里路由器内任意一台设备上运行就可以吗?比如笔记本电脑 m参数是笔记本的...
  • 孤狼: ups_status_set: seems that UPS [BK650M2-CH] is ...
归档