validar una online firma comprobar como digital-certificate

digital certificate - online - Cómo comprobar si un archivo tiene una firma digital.



como comprobar una firma digital (6)

Descarga Sigcheck y usa el siguiente comando.

sigcheck.exe -a -u -e

Un ejemplo de un dll firmado.

Un ejemplo de un dll sin firmar

Sigcheck es una utilidad de línea de comandos que muestra el número de versión del archivo. Buena suerte

Me gustaría verificar programáticamente si un archivo ha sido firmado digitalmente o no.

Por el momento, encontré un código bastante oscuro en MSDN , que no se compila ...

¿Alguna idea sobre el tema?

Una herramienta externa con línea de comando también sería genial, por cierto.


Encontré otra opción (código .Net puro) en la web here .

El código es muy simple y funciona.

using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Security.Cryptography.X509Certificates; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication1 { internal class Program { private static void Main(string[] args) { string filePath = args[0]; if (!File.Exists(filePath)) { Console.WriteLine("File not found"); return; } X509Certificate2 theCertificate; try { X509Certificate theSigner = X509Certificate.CreateFromSignedFile(filePath); theCertificate = new X509Certificate2(theSigner); } catch (Exception ex) { Console.WriteLine("No digital signature found: " + ex.Message); return; } bool chainIsValid = false; /* * * This section will check that the certificate is from a trusted authority IE * not self-signed. * */ var theCertificateChain = new X509Chain(); theCertificateChain.ChainPolicy.RevocationFlag = X509RevocationFlag.ExcludeRoot; /* * * Using .Online here means that the validation WILL CALL OUT TO THE INTERNET * to check the revocation status of the certificate. Change to .Offline if you * don''t want that to happen. */ theCertificateChain.ChainPolicy.RevocationMode = X509RevocationMode.Online; theCertificateChain.ChainPolicy.UrlRetrievalTimeout = new TimeSpan(0, 1, 0); theCertificateChain.ChainPolicy.VerificationFlags = X509VerificationFlags.NoFlag; chainIsValid = theCertificateChain.Build(theCertificate); if (chainIsValid) { Console.WriteLine("Publisher Information : " + theCertificate.SubjectName.Name); Console.WriteLine("Valid From: " + theCertificate.GetEffectiveDateString()); Console.WriteLine("Valid To: " + theCertificate.GetExpirationDateString()); Console.WriteLine("Issued By: " + theCertificate.Issuer); } else { Console.WriteLine("Chain Not Valid (certificate is self-signed)"); } } } }


La parte importante que falta en la respuesta que menciona signtool es:

Sí, con el conocido signtool.exe también puede averiguar si un archivo está firmado. No es necesario descargar otra herramienta!

Ej. Con la línea simple:

signtool verify /pa myfile.exe if %ERRORLEVEL% GEQ 1 echo This file is not signed.

(Para ver más detalles, agregue ''/ v'' después de ''/ pa''.)

Uno puede preguntar: ¿Por qué esto es importante? Acabo de firmar los archivos (de nuevo) que se firmarán y funciona.

Mi objetivo es mantener las compilaciones limpias y no firmar archivos por segunda vez, ya que no solo se cambia la fecha, sino que además es binario diferente.

Ejemplo de negocio: mi cliente tiene un proceso de compilación y publicación de compilaciones automatizadas y simplificadas "dev ops". Existen múltiples fuentes para diferentes conjuntos de archivos, y al final todo está compilado, probado y empaquetado para distribución, y para eso algunos archivos deben estar firmados. Para garantizar que algunos archivos no salgan de la unidad sin haber sido firmados, solíamos firmar todos los archivos importantes, incluso si ya estaban firmados.

Pero esto no es lo suficientemente limpio:

1) Si volvemos a firmar un archivo, que ya está firmado, la fecha del archivo y la huella digital binarias cambian, y el archivo pierde comparabilidad con sus fuentes, si simplemente se copió. (Al menos si firma con una marca de tiempo, lo que siempre hacemos y creo que es muy recomendable).

Esta es una pérdida de calidad grave, ya que este archivo ya no es comparable con sus predecesores de otro origen de archivo.

2) Si volvemos a firmar un archivo, esto también podría ser un error y es un archivo de terceros que no debe ser firmado por su unidad.

Puede evitar ambos haciendo que la firma sea condicional dependiendo del código de retorno de la llamada anterior "signtool Verify" mencionada.


Seleccione las propiedades <*>.exe clic derecho>. Si el archivo está firmado, obtendrá esta pestaña en las ventanas de propiedades de ese archivo.



También puede intentar usar el paquete sign-check npm para ese propósito.

El paquete implementa la API de WinVerifyTrust y tiene un uso simple:

npm install -g sign-check sign-check ''path/to/file''