SignTool ตรวจสอบว่าเทียบเท่ากับไฟล์ .application และ .manifest หรือไม่

ฉันใช้ signtool.exe v6.2.9200.20527 สำหรับการรองรับสวิตช์ /tr และ /td ในตัวอย่างต่อไปนี้ 0961...35d2 คือรหัสประจำตัว SHA1 ของใบรับรองการลงนามโค้ด SHA256 ในส่วนตัวของผู้ใช้ปัจจุบัน > ที่เก็บใบรับรอง

ตัวอย่างที่ 1: การลงนามโค้ดด้วยไดเจสต์ SHA256 ไม่มีการประทับเวลา

c:signtool.exe sign /fd sha256 /sha1 0961...35d2 CertificateCheck.exe
c:signtool.exe verify /all /pa CertificateCheck.exe

File: CertificateCheck.exe
Index  Algorithm  Timestamp
========================================
0      sha256     None

Successfully verified: CertificateCheck.exe

ตัวอย่างที่ 2: การลงนามโค้ดด้วยไดเจสต์ SHA1 ไม่มีการประทับเวลา

c:signtool.exe sign /fd sha1 /sha1 0961...35d2 CertificateCheck.exe
c:signtool.exe verify /all /pa CertificateCheck.exe

File: CertificateCheck.exe
Index  Algorithm  Timestamp
========================================
0      sha1       None

Successfully verified: CertificateCheck.exe

ตัวอย่างที่ 3: การลงนามสองครั้งด้วยไดเจสต์ SHA256 และไดเจสต์ SHA1 และการประทับเวลา

c:signtool.exe sign /fd sha256 /sha1 0961...35d2 /tr http://timestamp.globalsign.com/scripts/timstamp.dll /td sha256 CertificateCheck.exe
c:signtool.exe sign /as /fd sha1 /sha1 0961...35d2 /tr http://timestamp.globalsign.com/scripts/timstamp.dll /td sha1  CertificateCheck.exe
c:signtool.exe verify /all /pa CertificateCheck.exe

File: CertificateCheck.exe
Index  Algorithm  Timestamp
========================================
0      sha256     RFC3161
1      sha1       RFC3161

การใช้ signtool Verify /v ฉันสามารถดูรายละเอียดใบรับรองและห่วงโซ่ความน่าเชื่อถือของใบรับรองได้...

c:signtool.exe verify /all /pa /v CertificateCheck.exe

Verifying: CertificateCheck.exe
Signature Index: 0 (Primary Signature)
Hash of file (sha256): 6774...B2D1

Signing Certificate Chain:
    Issued to: GlobalSign
    Issued by: GlobalSign
    Expires:   Sun Mar 18 20:00:00 2029
    SHA1 hash: D69B...76AD

        Issued to: GlobalSign CodeSigning CA - SHA256 - G2
        Issued by: GlobalSign
        Expires:   Fri Aug 02 20:00:00 2019
        SHA1 hash: 4E34...36FF

            Issued to: Example Company Pty Ltd
            Issued by: GlobalSign CodeSigning CA - SHA256 - G2
            Expires:   Fri May 11 02:17:24 2018
            SHA1 hash: 0961...35D2

The signature is timestamped: Wed May 06 13:51:05 2015
Timestamp Verified by:
    Issued to: GlobalSign Root CA
    Issued by: GlobalSign Root CA
    Expires:   Fri Jan 28 22:00:00 2028
    SHA1 hash: B1BC...829C

        Issued to: GlobalSign Timestamping CA - G2
        Issued by: GlobalSign Root CA
        Expires:   Fri Jan 28 22:00:00 2028
        SHA1 hash: C0E4...5B71

            Issued to: GlobalSign TSA for Standard - G2
            Issued by: GlobalSign Timestamping CA - G2
            Expires:   Tue Mar 03 10:00:00 2026
            SHA1 hash: 19E1...65B6

Signature Index: 1
Hash of file (sha1): CFA4...7863

Signing Certificate Chain:
    Issued to: GlobalSign
    Issued by: GlobalSign
    Expires:   Sun Mar 18 20:00:00 2029
    SHA1 hash: D69B...76AD

        Issued to: GlobalSign CodeSigning CA - SHA256 - G2
        Issued by: GlobalSign
        Expires:   Fri Aug 02 20:00:00 2019
        SHA1 hash: 4E34...36FF

            Issued to: Example Company Pty Ltd
            Issued by: GlobalSign CodeSigning CA - SHA256 - G2
            Expires:   Fri May 11 02:17:24 2018
            SHA1 hash: 0961...35D2

The signature is timestamped: Wed May 06 13:51:06 2015
Timestamp Verified by:
    Issued to: GlobalSign Root CA
    Issued by: GlobalSign Root CA
    Expires:   Fri Jan 28 22:00:00 2028
    SHA1 hash: B1BC...829C

        Issued to: GlobalSign Timestamping CA - G2
        Issued by: GlobalSign Root CA
        Expires:   Fri Jan 28 22:00:00 2028
        SHA1 hash: C0E4...5B71

            Issued to: GlobalSign TSA for Standard - G2
            Issued by: GlobalSign Timestamping CA - G2
            Expires:   Tue Mar 03 10:00:00 2026
            SHA1 hash: 19E1...65B6


Successfully verified: CertificateCheck.exe

Number of signatures successfully Verified: 2
Number of warnings: 0
Number of errors: 0

นอกจากนี้เรายังลงนามไฟล์ ClickOnce .application และ .manifest สองครั้งโดยใช้ Mage.exe และ SignTool.exe ร่วมกัน แต่ SignTool Verify ดูเหมือนจะใช้งานไม่ได้กับไฟล์ .application และ .manifest:

c:signtool.exe verify /all /pa /v CertificateCheck.application

Verifying: CertificateCheck.application
SignTool Error: This file format cannot be verified because it is not recognized.

Number of signatures successfully Verified: 0
Number of warnings: 0
Number of errors: 1

c:signtool.exe verify /all /pa /v CertificateCheck.exe.manifest

Verifying: CertificateCheck.exe.manifest
SignTool Error: This file format cannot be verified because it is not recognized.

Number of signatures successfully Verified: 0
Number of warnings: 0
Number of errors: 1

เราสามารถเปิดไฟล์ .manifest และ .application ในตัวแก้ไขที่รองรับ XML เพื่อดูว่ามีการเพิ่มลายเซ็นที่เข้ารหัส base64 จริงหรือไม่ แต่จะเทียบเท่ากับ SignTool Verify ที่ช่วยให้ฉันเห็นลายเซ็นและ/หรือสายโซ่ความน่าเชื่อถือของใบรับรองที่แนบมาด้วย จากบรรทัดคำสั่งเหรอ? หรือฉันแค่ขับรถผิด? ฉันต้องการทำเช่นนี้เพื่อให้เราสามารถเพิ่มขั้นตอนการทดสอบลงในสคริปต์การสร้างของเราได้

ข้อมูลเพิ่มเติม...

ตกลง ดูเหมือนว่าจะเป็นปัญหาเกี่ยวกับเวอร์ชัน

ฉันได้รวบรวม SignTool เวอร์ชันต่างๆ ไว้สองสามเวอร์ชันเพื่อลองทำสิ่งต่างๆ ซีรีส์ v5 มีสวิตช์ Verify /manifest ต่างๆ ในขณะที่ไม่มีซีรีส์ v6 ใดที่ฉันพบ ในทางกลับกัน ซีรีส์ v6 รองรับใบรับรองและอัลกอริธึม SHA2 ในขณะที่ซีรีส์ v5 ไม่ชอบมันมากนัก

การใช้ signtool.exe v5.2.3790.2568 ฉันสามารถตรวจสอบชื่อที่รัดกุม (ข้อมูลระบุตัวตนของแอปพลิเคชัน) ด้วยสิ่งนี้:

signtool verify /manifest /snonly /v CertificateChecker.application
Successfully verified: CertificateChecker.application

Number of files successfully Verified: 1
Number of warnings: 0
Number of errors: 0

แต่ถ้าฉันพยายามแสดงห่วงโซ่ความน่าเชื่อถือของใบรับรอง (และมีใบรับรอง SHA256 อยู่ในนั้น) มันจะเกิดข้อผิดพลาด:

signtool verify /manifest /pa /v CertificateChecker.application
SignTool Error: CryptVerifyManifestFile returned error: 0x800B0004
        The subject is not trusted for the specified action.
Signing Certificate Chain:
    Issued to: GlobalSign
    Issued by: GlobalSign
    Expires:   2029-03-18 8:00:00 PM
    SHA1 hash: D69B...76AD

        Issued to: GlobalSign CodeSigning CA - SHA256 - G2
        Issued by: GlobalSign
        Expires:   2019-08-02 8:00:00 PM
        SHA1 hash: 4E34...A36FF

            Issued to: Example Pty Ltd
            Issued by: GlobalSign CodeSigning CA - SHA256 - G2
            Expires:   2018-05-11 2:17:24 AM
            SHA1 hash: 0961...A35D2

File is not timestamped.
SignTool Error: File not valid: CertificateChecker.application

Number of files successfully Verified: 0
Number of warnings: 0
Number of errors: 1

ดังนั้นฉันจึงเหลือคำถามเดิมอีกข้อหนึ่ง: มีการแทนที่ SignTool Verify สำหรับไฟล์ ClickOnce .application และ .manifest... และรองรับ SHA256 หรือไม่


person AlwaysLearning    schedule 06.05.2015    source แหล่งที่มา


คำตอบ (3)


mage.exe เครื่องมือสร้างและแก้ไขไฟล์ Manifest

mage -s CertificateCheck.application

ฉันยังไม่ทราบวิธีการยืนยันจาก CLI

person Remus Rusanu    schedule 05.04.2016

ใช้รหัสนี้เพื่อตรวจสอบรายการ ClickOnce:

// based on tip from http://www.pcreview.co.uk/threads/tool-for-clickonce-maifest-and-application-signature-validation.3308405/#post-11299058
private static ManifestSignatureInformationCollection GetClickOnceManifestSignature(string manifestPath)
{
    bool isApplicationManifest;
    if (manifestPath.EndsWith(".exe.manifest"))
    {
        isApplicationManifest = true;
    }
    else if (manifestPath.EndsWith(".application"))
    {
        isApplicationManifest = false;
    }
    else
    {
        throw new InvalidOperationException("Unrecognized manifest type, expected either application manifest (.exe.manifest) or deployment manifest (.application)");
    }

    XmlNamespaceManager namespaceManager = new XmlNamespaceManager(new NameTable());
    namespaceManager.AddNamespace("asmv1", "urn:schemas-microsoft-com:asm.v1");

    XElement assemblyIdentityXml = XDocument.Load(manifestPath).XPathSelectElement("/asmv1:assembly/asmv1:assemblyIdentity", namespaceManager);

    string applicationIdentityPart = string.Format(
        "{0}, Version={1}, Culture={2}, PublicKeyToken={3}, processorArchitecture={4}",
        assemblyIdentityXml.Attribute("name").Value,
        assemblyIdentityXml.Attribute("version").Value,
        assemblyIdentityXml.Attribute("language").Value,
        assemblyIdentityXml.Attribute("publicKeyToken").Value,
        assemblyIdentityXml.Attribute("processorArchitecture").Value);
    if (isApplicationManifest)
    {
        applicationIdentityPart += ", type=" + assemblyIdentityXml.Attribute("type").Value;
    }

    return ManifestSignatureInformation.VerifySignature(
        ActivationContext.CreatePartialActivationContext(new ApplicationIdentity(applicationIdentityPart + "/" + applicationIdentityPart),
            new[] { manifestPath, manifestPath }),
        isApplicationManifest ? ManifestKinds.Application : ManifestKinds.Deployment);
}


private static void Main(string[] args)
{
    ManifestSignatureInformationCollection resultDeployment = GetClickOnceManifestSignature(@"path\to\DeploymentManifest.application");
    ManifestSignatureInformationCollection resultApplication = GetClickOnceManifestSignature(@"path\to\ApplicationManifest.exe.manifest");

    Console.WriteLine("Deployment manifest is trusted: ");
    Console.WriteLine(resultDeployment[0].AuthenticodeSignature.TrustStatus == TrustStatus.KnownIdentity || resultDeployment[0].AuthenticodeSignature.TrustStatus == TrustStatus.Trusted);

    Console.WriteLine("Application manifest is trusted: ");
    Console.WriteLine(resultApplication[0].AuthenticodeSignature.TrustStatus == TrustStatus.KnownIdentity || resultApplication[0].AuthenticodeSignature.TrustStatus == TrustStatus.Trusted);
}
person Rafał Kłys    schedule 26.04.2016

ไม่ใช่ว่าฉันรู้ ความโง่เขลาของ Microsoft ยังคงทำให้ฉันประหลาดใจในบางครั้ง

signtool.exes เก่าไม่รองรับ SHA256 เวอร์ชันใหม่ทำ แต่ไม่รองรับการลงนามรายการ (ทำไม M$ ถึงลบฟังก์ชันนั้นออกไป!) mage.exe ไม่รองรับเซิร์ฟเวอร์ใบรับรอง HSM เว้นแต่คุณจะทราบรหัสส่วนตัว (ซึ่งเป็นจุดรวมของการใช้เซิร์ฟเวอร์ดังกล่าวเพื่อรักษาความปลอดภัยใบรับรอง) มันน่าทึ่งจริงๆ

person Joe Coder    schedule 27.01.2016
comment
ดังนั้นหากฉันเข้าใจถูกต้อง เป็นไปไม่ได้ที่จะสร้างตัวติดตั้งแอปพลิเคชัน ClickOnce ที่ลงนามด้วยโมดูลความปลอดภัยฮาร์ดแวร์ (HSM) - person Eric Hewitt; 04.04.2017