npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@xan105/win-verify-trust

v1.5.2

Published

Check the signature of a file using the WinVerifyTrust API

Downloads

44

Readme

About

Check the signature of a file using the WinVerifyTrust API. Retrieve some certificate information.

📦 Scoped @xan105 packages are for my own personal use but feel free to use them.

Example

Dead simple:

import { isSigned } from "@xan105/win-verify-trust";

const trusted = await isSigned("/path/to/file");
console.log(trusted) //boolean

Verbose:

import { verifyTrust } from "@xan105/win-verify-trust";

const { trusted, message } = await verifyTrust("/path/to/file");
console.log(trusted, message) 
//true
//"The file is signed and the signature was verified"

Once you know a file is signed and the signature was verified. You may want to check some info of the cert:

import { getCertificate } from "@xan105/win-verify-trust";

const certificate = await getCertificate("steam_api64.dll");
console.log(certificate) 
/*
{
  signer: {
    issuer: 'DigiCert SHA2 Assured ID Code Signing CA',
    subject: 'Valve',
    serialNumber: '054f466ceccbe9d6bee81f5435e64d47',
    digestAlgo: 'sha1'
  },
  timestamp: {
    issuer: 'Symantec Time Stamping Services CA - G2',
    subject: 'Symantec Time Stamping Services Signer - G4',
    serialNumber: '0ecff438c8febf356e04d86a981b1a50',
    digestAlgo: 'sha1'
  }
}
*/

💡 You can pass an optional arg to isSigned() to also check that the cert was signed for the specified signer subject:

import { isSigned } from "@xan105/win-verify-trust";

const trusted = await isSigned("steam_api64.dll", "valve");
console.log(trusted) //boolean

Installation

npm install @xan105/win-verify-trust

Force compiling:

npm install @xan105/win-verify-trust --build-from-source

You will need C/C++ build tools and Python 3.x (node-gyp) to build this module. 🚀 x86, x64 and arm64 prebuilt binary provided.

API

⚠️ This module is only available as an ECMAScript module (ESM).

Named export

verifyTrust(filePath: string): Promise<object>

Performs a trust verification action on the specified file using the WinVerifyTrust API.

Return value

Returns an object as

{
  trusted: boolean,
  message: string
}

Where trusted indicates if the file is signed and the signature was verified. And message the details of the trust status (verbose).

eg: "No signature was present in the subject"

Remarks

❌ This function will throw if the target file doesn't exist, or file ext isn't allowed, or it timeout. ⚠️ Allowed ext are: ".exe", ".cab", ".dll", ".ocx", ".msi", ".msix", ".xpi", ".ps1".

getCertificate(filePath: string): Promise<object>

Retrieve some certificate information. Once you know a file is signed and the signature was verified after having used verifyTrust() you may want to check some certificate information.

Return value

Returns an object as

{
  programName?: string,
  publisherLink?: string,
  infoLink?: string,
  signer: {
    issuer?: string,
    subject?: string,
    serialNumber?: string,
    digestAlgo?: string
  },
  timestamp?: {
    issuer?: string,
    subject?: string,
    serialNumber?: string,
    digestAlgo?: string
  }
}

Where signer contains information from the signer certificate and timestamp from the timestamp certificate.

programName is the program name, publisherLink and infoLink are publisher information.

Remarks

❌ This function will throw on error. ⚠️ Allowed ext are: ".exe", ".cab", ".dll", ".ocx", ".msi", ".msix", ".xpi", ".ps1".

💡 Invoking this function on an unsigned target will result in an ETIMEOUT error. You should use verifyTrust() first.

isSigned(filePath: string, name?: string | null): Promise<boolean>

Check if the specified file is signed and trusted. Optionally also check that the signer certificate was issued for the specified subject name (case-insensitive).

This is a shorthand of verifyTrust() and getCertificate(). This function doesn't throw.