dongzhou8764 2015-01-16 20:46
浏览 61
已采纳

asn1 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条回答 默认 最新

  • doucaishou0074 2015-01-17 15:32
    关注

    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
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

    报告相同问题?

    悬赏问题

    • ¥100 webapi的部署(标签-服务器)
    • ¥20 怎么加快手机软件内部计时的时间(关键词-日期时间)
    • ¥15 C语言除0问题的检测方法
    • ¥15 为什么四分管的内径有的是16mm有的15mm,四分不应该是12.7mm吗
    • ¥15 macos13下 ios交叉编译的问题
    • ¥15 bgz压缩文件怎么打开
    • ¥15 封装dll(引入了pcl的点云设计库)
    • ¥30 关于#开发语言#的问题:我需要在抄板的基础上再抄板抄程序,根据RDA8851CM基础上开发
    • ¥15 oracle 多个括号,怎么删除指定的括号及里面的内容?
    • ¥15 小新14API2019想用bios调风扇