Problem verifying a X509Certificate's signature

From: Ricardo Pereira (pereira.ric_at_mail.telepac.pt)
Date: 09/17/04

  • Next message: Sebastien Pouliot: "Re: Problem verifying a X509Certificate's signature"
    Date: 16 Sep 2004 16:54:32 -0700
    
    

    Hello all,
    I'm implementing a class that extends the .NET 1.1 framework
    X509Certificate class. The purpose is to end up with a class that has
    the (inhereted) functionalities of the X509Certificate class plus some
    more.
    One of the methods I am implementing is the Verify method.

    Let's call my class, the X509CertificateEnhanced class. The Verify
    method is declared as such:

    bool Verify(byte[] publicKey)

    This method will verify if a given X509Certificate (in this case, a
    X509CertificateEnhanced) is signed by the public key (of another
    certificate) passed as a parameter.

    To help implementing this method (and others) I use the BouncyCastle
    C# Port (a lightweight version of the Java BouncyCastle API,
    www.bouncycastle.org/csharp/) and the X509KeyParser (found on the
    Internet, I'll post the link where I found it as soon as I get to my
    computer at work).

    I use the .NET VerifyHash method, of the class
    RSACryptoServiceProvider, to verify if the certificate's hash
    validates with its signature, given the other certificate's public
    key.

    public bool VerifyHash(byte[] rgbHash, string str, byte[]
    rgbSignature)

    I'm trying to do this validation this way:
    - Initialize the RSACryptoServiceProvider class with the the
    RSAParameters (returned by a static method of the class X509KeyParser,
    that accepts a public key byte[], which in turn was got using the
    method X509Certificate.GetPublicKey) that correspond to the other
    certificate's public key.
    - Use the method X509Certificate.GetCertHash to get the X509
    certificate's hash that will be passed as the parameter "rgbHash".
    - The "str" parameter will be the return value of
    CryptoConfig.MapNameToOID("SHA1").
    - Use the method (from the BouncyCastle API)
    X509CertificateStructure.GetSignature().GetBytes() to get the X509
    certificate's signature, to be used in the "rgbSignature" parameter.

    The problem is that I am getting a "false" return result when I do all
    this with the public key of a certificate that did sign the other
    certificate that I am verifying.
    I am using the public key of the certificate that is in the upper
    position (in the chain with the 2 certificates) and the hash and
    signature of the certificate in the lower position.

    I'm almost sure that I have the correct RSAParameters (public key) to
    initialize the RSACryptoServiceProvider as I got the same
    RSAParameters using the Web Service Enhancements 2.0
    X509Certificate.PublicKey property (which returns an instance of a
    RSACryptoServiceProvider class, already initialized with the puclic
    key of that certificate), so the problem would either be in the hash
    or in the signature.

    On one hand, I'm not that sure that the X509Certificate.GetCertHash
    method returns the hash of the X509 certificate part that was used to
    generate its signature.
    On the other hand, I'm not also 100% sure that the method
    X509CertificateStructure.GetSignature().GetBytes() (documentation in
    http://www.bouncycastle.org/docs/docs1.4/index.html) returns the
    certificate's signature the way that it is needed in the VerifyHash
    method.

    p.s.:(don't mind that the BouncyCastle API is in javadoc, the API is
    the same as the Java one but with fewer classes. ex: there is no
    X509CertificateObject in the C# version, that's why I have to use The
    X509CertificateStructure class)

    Any help will be glad,
      thanks in advance

        Ricardo Pereira


  • Next message: Sebastien Pouliot: "Re: Problem verifying a X509Certificate's signature"

    Relevant Pages

    • Re: Soft signatures
      ... now, digital signature, typically just represents that you (in ... For some time there were arguments that if a certificate contained the ... certificate with your public key and the non-repudiation flag in it. ... for a number of different business purposes. ...
      (sci.crypt)
    • Re: Are ++ and -- operators really more efficient
      ... But you still need a way to verify that it's the right key. ... the signature contains a URL indicating ... where the certificate can be found. ... (This idea that public keys represent principals -- ...
      (comp.lang.c)
    • Re: how can we restrict what certificate WSE will use?
      ... > X509SecurityTokenManager to verify the request is from a trusted client. ... > certificate to build a valid signature and encrypted data section. ...
      (microsoft.public.dotnet.framework.webservices.enhancements)
    • Re: Certificates and Cryptography (Please HELP!)
      ... signedMessage1.txt is the DSA 40-byte Base64-Encoded signature which I ... should be able to verify with the certificate's public key. ... The certificate store that I installed the certificate into ... >> I've read through the CryptoAPI documentation, ...
      (microsoft.public.dotnet.framework.aspnet.security)
    • Re: Problem verifying a X509Certificates signature
      ... hash they use to verify the signature is calculated from the ... ASN1 part of the X509 certificate structure that does not include the ... X509Certificate.GetCertHash() did not return the hash of the ... >> One of the methods I am implementing is the Verify method. ...
      (microsoft.public.dotnet.security)