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

报告相同问题?

悬赏问题

  • ¥15 蓝桥oj3931,请问我错在哪里
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染