【发布时间】: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