asn1 go (client side cert auth)

huangapple go评论92阅读模式
英文:

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
}

huangapple
  • 本文由 发表于 2015年1月17日 04:46:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/27992496.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定