如何查找 X509 序列号

发布于 2024-10-14 22:58:44 字数 243 浏览 4 评论 0原文

我正在构建需要 wse 安全性的肥皂消息,并且出于某种原因,客户端需要 KeyInfo、主题和序列号。但 x509 显示的序列号是十六进制,不符合 X509SerialNumber 节点(整数)的 xsd 要求。我读到这需要发行者序列号,但它不是证书的一部分。这是一个自签名证书。如何确定序列号是什么?

请不要告诉我使用 WCF。如果我能使用它,我会的。我知道 WCF 会让事情变得更容易,我持有 WCF 的 MCTS。

I'm building soap message which requires wse security and for some reason, the client requires KeyInfo, subject and serial #. but the serial # displayued for the x509 is hex and doesn't fit the xsd requirements for X509SerialNumber node which is integer. I've read that this needs to the the issuer serial # but it isn't part of the cert. This is a self signed certificate. How can I determine what the serial # is?

Please DO NOT tell me to use WCF. If I could use it, I would. I know WCF would make it easier, I hold an MCTS for WCF.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

羞稚 2024-10-21 22:58:45

证书只有一个序列号字段,并且是二进制数据。发行人可以在那里放置任何东西。事实上,序列号被视为一个非常大的整数,但是如果您只检查保存该数字的字节数组,那么该数字看起来就像一个二进制文件。所以你需要将这个值视为一个巨大的数字并将其转换为“可读”的形式。例如。如果您有包含 FF 00 FF 00(4 个字节)的 4 字节长字节数组,则字符串表示形式将为“4278255360”

更新:我的上述解释适用于 XMLDSig 和 XMLEnc 标准。在其他标准中(或仅用于显示目的),可以使用其他格式(例如 base64、base16 编码等)。

There's only one serial number field of the certificate and it's is binary data. The issuer can put anything there. In fact, serial number is treated as a very large integer number, but such number will look like a binary if you just inspect the byte array that holds the number. So you need to treat this value as a huge number and convert it to "readable" form. Eg. If you have 4-byte-long byte array that contains FF 00 FF 00 (4 bytes), the string representation will be "4278255360"

Update: my above explanation applies to XMLDSig and XMLEnc standards. In other standards (or just for display purposes) other formats can be used (such as base64, base16 encoding etc.).

紫南 2024-10-21 22:58:45

我找到了我需要的东西。 http:// /www.dotnetmonster.com/Uwe/Forum.aspx/dotnet-security/2875/Manually-computing-sha1-digest-of-reference-having

只需添加一些代码。 X509ChainElement.Certificate.GetSerialNumberString() 给了我我需要的东西,我不需要计算任何东西。

这是我现在使用的代码

public static XmlElement GenerateSignature(XmlElement xmlToSign, StoreName storeName, StoreLocation storeLocation, X509Certificate2 certificate, string referenceID)
    {
        SignedXml signedXml = new SignedXml(xmlToSign);

        signedXml.SignedInfo.CanonicalizationMethod = SignedXml.XmlDsigExcC14NTransformUrl;
        signedXml.SigningKey = certificate.PrivateKey;

        Reference tRef = new Reference(referenceID);
        XmlDsigExcC14NTransform env = new XmlDsigExcC14NTransform();

        tRef.AddTransform(env);
        signedXml.AddReference(tRef);

        KeyInfo keyInfo = new KeyInfo();
        X509Chain x509Chain = new X509Chain();
        x509Chain.Build(certificate);

        foreach (X509ChainElement element in x509Chain.ChainElements)
        {
            KeyInfoX509Data x509Data = new KeyInfoX509Data(element.Certificate);
            string issuer = element.Certificate.Issuer;
            x509Data.AddIssuerSerial(issuer, element.Certificate.GetSerialNumberString());
            keyInfo.AddClause(x509Data);
        }

        signedXml.KeyInfo = keyInfo;
        signedXml.ComputeSignature();

        XmlElement xmlDsig = signedXml.GetXml();
        return xmlDsig;
    }

I found what I needed. http://www.dotnetmonster.com/Uwe/Forum.aspx/dotnet-security/2875/Manually-computing-sha1-digest-of-reference-containing

Just needed to add some code. the X509ChainElement.Certificate.GetSerialNumberString() gives me what I need and I don't have to calc anything.

Here is the code I'm now using

public static XmlElement GenerateSignature(XmlElement xmlToSign, StoreName storeName, StoreLocation storeLocation, X509Certificate2 certificate, string referenceID)
    {
        SignedXml signedXml = new SignedXml(xmlToSign);

        signedXml.SignedInfo.CanonicalizationMethod = SignedXml.XmlDsigExcC14NTransformUrl;
        signedXml.SigningKey = certificate.PrivateKey;

        Reference tRef = new Reference(referenceID);
        XmlDsigExcC14NTransform env = new XmlDsigExcC14NTransform();

        tRef.AddTransform(env);
        signedXml.AddReference(tRef);

        KeyInfo keyInfo = new KeyInfo();
        X509Chain x509Chain = new X509Chain();
        x509Chain.Build(certificate);

        foreach (X509ChainElement element in x509Chain.ChainElements)
        {
            KeyInfoX509Data x509Data = new KeyInfoX509Data(element.Certificate);
            string issuer = element.Certificate.Issuer;
            x509Data.AddIssuerSerial(issuer, element.Certificate.GetSerialNumberString());
            keyInfo.AddClause(x509Data);
        }

        signedXml.KeyInfo = keyInfo;
        signedXml.ComputeSignature();

        XmlElement xmlDsig = signedXml.GetXml();
        return xmlDsig;
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文