我正在编写 golang 代码来解析带有自定义扩展的 X509 证书:
代码如下:
func (e *PckCert) ParseValue() error {
var ext pkix.Extension
var err error
for i := 0; i < len(e.PckCertObj.Extensions); i++ {
ext = e.PckCertObj.Extensions[i]
if ExtxOid.Equal(ext.Id) == true { ///ExtOid is a constant OId is known
var asn1Extensions []asn1.RawValue
_, err := asn1.Unmarshal(ext.Value, &asn1Extensions)
if err != nil {
log.Info("err: ", err)
return errors.Wrap(err, "Asn1 Extension Unmarshal failed")
}
var sExtension pkix.Extension ///For normal OIDs
var sExtensions1 []pkix.Extension /// For TC1 SVN OID extensions under extension
for j := 0; j < len(asn1Extensions); j++ {
_, err = asn1.Unmarshal(asn1Extensions[j].FullBytes, &sExtension)
if err != nil {
log.Info("err came: ", err)
log.Info("Warning: Asn1 Extension Unmarshal failed - 2 for index:", j)
_, err = asn1.Unmarshal(asn1Extensions[j].FullBytes, &sExtensions1)
if err != nil {
log.Info("err came 2: ", err) ///**for extensions within extensions here code is failing with error: sequence tag mismatch**
}
}
}
}
}
}
上述代码仅对复合扩展序列 TC OID失败。对于复合扩展序列,我得到“asn1:结构错误:序列标签不匹配”。请在这方面提供帮助。.我能够解组除复合扩展 TC OID 之外的所有其余部分