2010-12-27 13 views
8

Utworzono certyfikat urządzenia. Pojawia się w folderze repozytorium certyfikatów Certyfikaty (Komputer lokalny) \ Personal \ Certificates. Teraz chcę wyodrębnić jego odcisk palca za pomocą narzędzia wiersza poleceń.Czy istnieje narzędzie wiersza polecenia do wyodrębnienia odcisku palca certyfikatu?

Niestety, najbliższa rzecz, jaką mogłem znaleźć, to this article.

Muszę być w stanie wykonać tę procedurę na każdym systemie operacyjnym Windows, począwszy od XP.

Dzięki.

+0

Skrypt w artykule robi to, co chcesz. Umieść go w pliku vbs i uruchom go. – Amnon

+0

Dobra, zrobiłem to. Ale zależy to od CAPICOM.dll, który musi zostać zarejestrowany. Zastanawiam się, czy istnieje narzędzie korzystające bezpośrednio z Crypt API, bez zależności. – mark

Odpowiedz

8

Stary, ale może to komuś pomoże. Umieść poniższe w skrypcie programu Power Shell (.ps1) i uruchom go. Wydrukuje kciuk na ekranie. obserwuj zawijanie słów w mojej wklejce.

$computerName = $Env:Computername 
$domainName = $Env:UserDnsDomain 
write-host "CN=$computername.$domainname" 
$getThumb = Get-ChildItem -path cert:\LocalMachine\My | where { $_.Subject -match "CN\=$Computername\.$DomainName" } 
$getThumb.thumbprint 
+0

To mi wystarczy. Dzięki. – mark

2

W moim przypadku nie mogłem użyć PowerShell, więc napisałem ten skrypt do uruchomienia z cscript.exe że będzie Ci kciuka za pomocą wyrażenia regularnego.

If WScript.Arguments.Count() = 0 Then 
    WScript.Echo "Domain name to search for must be specified as first parameter." 
    WScript.Quit 1 
End If 
domain = WScript.Arguments.Item(0) 

Set objShell = WScript.CreateObject ("WScript.shell") 

' Get all certificate information in store. 
Set objCert = objShell.Exec("certutil -store my") 
certOutput = "" 
Do While objCert.Status = 0 
    WScript.Sleep 10 
    Do While Not objCert.StdOut.AtEndOfStream 
    certOutput = certOutput & objCert.StdOut.ReadLine & vbNewLine 
    Loop 
Loop 

' Capture thumb for specified certificate using Regex. 
Set thumbRegex = New RegExp 
thumbRegex.Pattern = "Subject:\s+CN=" & domain & "\s*\n.*\n.*\nCert\sHash\(sha1\):\s+(.*)" 
thumbRegex.IgnoreCase = True 
thumbRegex.Global = False 

' Verify match and trim out white space. 
Set match = thumbRegex.Execute(certOutput) 
result = "" 
If match.Count > 0 Then 
    result = match.Item(0).Submatches(0) 
    result = Replace(result, " ", "") 
    WScript.Echo result 
Else 
    WScript.Echo "The certificate for """ & domain & """ was not found." 
    WScript.Quit 2 
End If 
3

Pobierz odcisk palca bezpośrednio z pliku .cer

const certpath = "\\host\res\something.cer" 
dim objStdOut 
dim strLine, resString 

set objStdOut = CreateObject("WScript.Shell").Exec("certutil " & certpath).StdOut 

while not objStdOut.AtEndOfStream 
    strLine = objStdOut.ReadLine 
    if InStr(strLine, "(sha1)") > 0 then resString = trim(split(strLine, ":")(1)) 
wend 
wscript.echo resString 
4

Bezpośrednio z wiersza polecenia do pliku cer, że nie jest zainstalowany, i usuwa spacji (mogą prawdopodobnie być poprawiona):

certutil.exe <mycert>.cer | findstr /c:"Cert Hash(sha1)" | for /f "tokens=3-22" %f in ('more') do @echo %f%g%h%i%j%k%l%m%n%o%p%q%r%s%t%u%v%w%x%y 
Powiązane problemy