Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What to do if the file has multiple digital signatures? #211

Open
send010 opened this issue Oct 22, 2021 · 2 comments
Open

What to do if the file has multiple digital signatures? #211

send010 opened this issue Oct 22, 2021 · 2 comments

Comments

@send010
Copy link

send010 commented Oct 22, 2021

What to do if the file has multiple digital signatures?

@secana
Copy link
Owner

secana commented Oct 29, 2021

Hi @send010, do you have an example binary? If so, I can have a look at what options PeNet offers, or what is needed to the information you need.

@send010
Copy link
Author

send010 commented Nov 1, 2021

File

mycode:

    public static List<X509Certificate2> GetSigningCertificates(this PeFile pefile)
    {
        var data = DecodeCertificateData(pefile.WinCertificate?.BCertificate.ToArray());
        var result = new List<X509Certificate2>();
        result.Add(pefile.Authenticode.SigningCertificate);
        foreach (var cert in data)
        {
            result.AddRange(GetNestedAuthenticodeDetails(cert));
        }
        return result;
    }

    public static IEnumerable<SignerInfo> DecodeCertificateData(byte[] rawData)
    {
        var orgCms = new SignedCms();
        orgCms.Decode(rawData);
        
        return orgCms.SignerInfos.Cast<SignerInfo>();
    }

    public static List<X509Certificate2> GetNestedAuthenticodeDetails(SignerInfo cert)
    {
        var result = new List<X509Certificate2>();
        List<CryptographicAttributeObject> data = new List<CryptographicAttributeObject>();
        foreach (var item in cert.UnsignedAttributes)
        {
            if (item.Oid.Value == "1.3.6.1.4.1.311.2.4.1")
            {
                data.Add(item);
            }
        }

        foreach (var item in data)
        {
            var CertificateList = DecodeCertificateData(item.Values[0].RawData);
            foreach (var item1 in CertificateList)
            {
                result.Add(item1.Certificate);
            }
        }
        return result;
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants