英文:
asn1 go (client side cert auth)
问题
我正在尝试使客户端证书认证工作,并在阅读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语言结构可能不正确,但我无法找出问题所在。
英文:
I am trying to get client side cert auth working and after reading https://developer.mozilla.org/en-US/docs/Web/HTML/Element/keygen I realised I needed to parse some asn1.
The structure I'm trying to use is this:
type PublicKeyAndChallenge struct {
Spki asn1.BitString
Challenge asn1.BitString
}
type SignedPublicKeyAndChallenge struct{
PublicKeyAndChallenge PublicKeyAndChallenge
SignitureAlgorithm asn1.BitString
Signiture asn1.BitString
}
I decode the base64 encoded asn1 into a []byte, then I try to unmarshal the asn1 into the structure.
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)
}
I am getting a structure error so I believe my structure in go must not be correct, but I am not able to figure it out.
答案1
得分: 0
我做了一些搜索,找到了RFC320,其中提供了ASN.1类的定义,并且我已经使其工作起来了!
现在的结构是:
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
}
请注意,这是一个Go语言的代码片段。
英文:
I did some duck duck going and found the rfc320 that provides the definitions of the asn.1 classes and have got it to work!
The structure is now:
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
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论