Last active
April 13, 2020 19:42
-
-
Save fullenw1/dd7f25452914f97b8efcb1c22ebaa515 to your computer and use it in GitHub Desktop.
Code signature function #PKI #Certificates #Security
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Set-Signature { | |
[CmdletBinding()] | |
[Alias('sig')] | |
param( | |
[Parameter( | |
Mandatory, | |
Position = 0, | |
ValueFromPipeline, | |
ValueFromPipelineByPropertyName | |
)] | |
[ValidateScript( { Test-Path -Path $_ })] | |
[ValidateNotNullOrEmpty()] | |
[string[]]$FilePath | |
) | |
begin { | |
$Certificate = Get-ChildItem -Path Cert:\CurrentUser\My -CodeSigningCert | | |
Where-Object -Property NotAfter -GT (Get-Date) | | |
Sort-Object -Property NotAfter -Descending | | |
Select-Object -First 1 | |
} | |
process { | |
foreach ($Path in $FilePath) { | |
$TimeStampServer = @( | |
'http://timestamp.verisign.com/scripts/timstamp.dll' | |
'http://timestamp.globalsign.com/scripts/timstamp.dll' | |
'http://timestamp.comodoca.com/authenticode' | |
) | Get-Random | |
$Params = @{ | |
Certificate = $Certificate | |
TimestampServer = $TimeStampServer | |
HashAlgorithm = 'SHA256' | |
FilePath = $Path | |
} | |
Set-AuthenticodeSignature @Params | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment