signJarDlls.ps1 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. $certificate = 'abc'
  2. $password = 'secret'
  3. $certificateSHA1 = 5FC94CE149E5B511E621F53A060AC67CBD446B3A
  4. $description = Cryptomator
  5. $timestampUrl = 'http://timestamp.digicert.com'
  6. $folder = ".\appdir\Cryptomator"
  7. $tmpDir = ".\extract"
  8. $signtool = $(Get-ChildItem "C:/Program Files (x86)/Windows Kits/10/bin/" -Recurse -File signtool.exe | Where-Object { $_.Directory.ToString().EndsWith("x64")} | Select-Object -Last 1).FullName
  9. # preps
  10. # does this work on CI?
  11. Install-Module -Name Microsoft.PowerShell.TextUtility
  12. # import certificate
  13. $bytes = ConvertFrom-Base64 -EncodedText $certificate -AsByteArray
  14. Set-Content -Path $certificateFile -AsByteStream -Value $bytes
  15. & certutil -f -p $password -importpfx $certificateFile
  16. # create directory to extract every jar to
  17. New-Item -Path $tmpDir -ItemType Directory
  18. # iterate over all jars
  19. Get-ChildItem -Path $folder -Recurse -File *.jar | ForEach-Object {
  20. $jar = Copy-Item $_ -Destination $tmpDir -PassThru
  21. Set-Location -Path $tmpDir
  22. "Extracting jar $($jar.FullName)"
  23. jar --file=$($_.FullName) --extract
  24. Get-ChildItem -Path "." -Recurse -File "*.dll" | ForEach-Object {
  25. # sign
  26. & $signtool sign /sm /tr ${timestampUrl} /td SH256 /fd SHA256 /d $description /sha1 $certificateSHA1 $_.FullName
  27. # update jar with signed dll
  28. jar --file=$($jar.FullName) --update $(Resolve-Path -Relative -Path $_)
  29. }
  30. # replace old jar with its update
  31. Move-Item -Path $($jar.FullName) -Destination $_ -Force
  32. # clear extraction dir
  33. Remove-Item -Path ".\*" -Force -Recurse
  34. Set-Location -Path ".."
  35. }
  36. # clean up
  37. Remove-Item -Path $tmpDir