【问题标题】:asn1 go (client side cert auth)asn1 go(客户端证书身份验证)
【发布时间】:2015-01-16 20:46:43
【问题描述】:

我正在尝试让客户端证书身份验证工作,在阅读 https://developer.mozilla.org/en-US/docs/Web/HTML/Element/keygen 之后,我意识到我需要解析一些 asn1。

我尝试使用的结构是这样的:

type PublicKeyAndChallenge struct {
    Spki asn1.BitString
    Challenge asn1.BitString
}

type SignedPublicKeyAndChallenge struct{
    PublicKeyAndChallenge PublicKeyAndChallenge
    SignitureAlgorithm  asn1.BitString
    Signiture asn1.BitString
}

我将 base64 编码的 asn1 解码为 []byte,然后尝试将 asn1 解组到结构中。

signeeKeySigned := make([]byte, 2048)
    _ , err = base64.StdEncoding.Decode(signeeKeySigned, signeePubKeySigned)
    if ( err != nil ){
        log.Fatal(err)
    }   
    //Parse should be asn.1 encoded
    var signee SignedPublicKeyAndChallenge
    _, err = asn1.Unmarshal(signeeKeySigned, &signee)
    if err != nil {
        log.Fatal(err)
    }  

我遇到了一个结构错误,所以我认为我在 go 中的结构一定不正确,但我无法弄清楚。

【问题讨论】:

  • 你测试过 type SignedPublicKeyAndChallenge struct{ PublicKeyAndChallenge //嵌入SignitureAlgorithm asn1.BitString Signiture asn1.BitString } //避免命名空间冲突
  • 我已经测试过嵌入的结构没有区别

标签: ssl data-structures go unmarshalling asn.1


【解决方案1】:

我做了一些鸭鸭,找到了提供 asn.1 类定义的 rfc320 并让它工作!

现在的结构是:

type SubjectPublicKeyInfo struct {
    Algorithm pkix.AlgorithmIdentifier
    SubjectPublicKey asn1.BitString
}

type PublicKeyAndChallenge struct {
    Spki SubjectPublicKeyInfo
    Challenge string
}

type SignedPublicKeyAndChallenge struct{
    PublicKeyAndChallenge PublicKeyAndChallenge
    SignitureAlgorithm pkix.AlgorithmIdentifier
    Signiture asn1.BitString
}

【讨论】:

    猜你喜欢
    • 2011-04-09
    • 2013-10-07
    • 1970-01-01
    • 2022-06-23
    • 2018-02-12
    • 2012-09-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-10
    相关资源
    最近更新 更多