dtoka218420 2017-09-12 17:14
浏览 76

使用golang提取主题密钥标识符

I am trying to use golang crypto/tls library to extract SubjectKeyIdentifiers for all the Certificates in a Chain that a server returns.

package main

import (
    "crypto/tls"
    "fmt"
)

func main() {
    conn, err := tls.Dial("tcp", "mail.google.com:443", &tls.Config{
        InsecureSkipVerify: true,
    })
    if err != nil {
            panic("failed to connect: " + err.Error())
        }
    state := conn.ConnectionState()
        if err != nil {
                    panic("failed to get ConnState: " + err.Error())
            }
    for _, cert := range state.PeerCertificates {
        fmt.Printf("%s
", cert.Subject.CommonName)
        fmt.Printf("%X
", cert.SubjectKeyId)
    }
    conn.Close()
}

As per the docs SubjectKeyId should have already been populated with ASN1 parsed data. The problem is that I get 4E16C14EFCD46B0A09F8090F1C00278C6F992C65

while the real one is

30:A1:48:01:DB:2B:C3:EE:D3:84:54:4B:66:AF:0C:4C:66:F7:69:47

What I am doing wrongly here ?

  • 写回答

1条回答 默认 最新

  • dslpofp041310584 2017-09-13 10:53
    关注

    The problem was that I did not specify the SNI when checking with openssl. The conclusion is: Always set SNI in ClientHello

    $ echo q |openssl s_client -showcerts -connect mail.google.com:443 -servername mail.google.com -showcerts 2>/dev/null | sed -n '/-----BEGIN/,/-----END/p' | openssl x509 -text -noout | grep -P -A1 'Subject Key'
                X509v3 Subject Key Identifier: 
                    4E:16:C1:4E:FC:D4:6B:0A:09:F8:09:0F:1C:00:27:8C:6F:99:2C:65
    $ echo q |openssl s_client -showcerts -connect mail.google.com:443 -showcerts 2>/dev/null | sed -n '/-----BEGIN/,/-----END/p' | openssl x509 -text -noout | grep -P -A1 'Subject Key' 
               X509v3 Subject Key Identifier: 
                    30:A1:48:01:DB:2B:C3:EE:D3:84:54:4B:66:AF:0C:4C:66:F7:69:47
    $
    
    评论

报告相同问题?

悬赏问题

  • ¥15 python中合并修改日期相同的CSV文件并按照修改日期的名字命名文件
  • ¥15 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员