]> apps.delaporte.us Git - dotfiles.git/commitdiff
Local user code singing utils.
authorEdward Delaporte <delaport@illinois.edu>
Mon, 8 Feb 2021 23:25:46 +0000 (17:25 -0600)
committerEdward Delaporte <delaport@illinois.edu>
Mon, 8 Feb 2021 23:25:46 +0000 (17:25 -0600)
psmodules/sign.psm1 [new file with mode: 0644]
setup/codesign.ps1 [new file with mode: 0644]

diff --git a/psmodules/sign.psm1 b/psmodules/sign.psm1
new file mode 100644 (file)
index 0000000..a5667de
--- /dev/null
@@ -0,0 +1,43 @@
+<#
+.SYNPOSIS
+
+Commands to maintain a local code singing cert.
+
+#>
+$certName = "Local Code Sign Cert"
+$codeSigning = ""
+
+function New-CodeSignCert {
+       $cert = New-SelfSignedCertificate -CertStoreLocation Cert:\CurrentUser\My -Type CodeSigningCert -Subject $certName -KeyAlgorithm RSA -KeyLength 2048 -Provider "Microsoft Enhanced RSA and AES Cryptographic Provider" -KeyUsage "DigitalSignature"
+
+}
+
+function Get-CodeSignCert {
+       $certName = "Local Code Sign Cert"
+       return Get-ChildItem -Path Cert:\CurrentUser\My | Select-Object -First 1
+#      | ? Subject -EQ "CN=$certName"
+}
+
+function Install-CodeSignCert {
+
+       $cert = Get-CodeSignCert
+       Move-Item -Path $cert.PSPath -Destination "Cert:\CurrentUser\Root"
+}
+
+function Invoke-CodeSign {
+       param(
+               [string]$Path
+       )
+       $cert = Get-CodeSignCert
+       Set-AuthenticodeSignature -FilePath $Path -Certificate $cert
+}
+
+Invoke-CodeSignProfile {
+       Invoke-CodeSign -Path $profile
+}
+
+Export-ModuleMember -Function New-CodeSignCert
+Export-ModuleMember -Function Get-CodeSignCert
+Export-ModuleMember -Function Install-CodeSignCert
+Export-ModuleMember -Function Invoke-CodeSign
+Export-ModuleMember -Function Invoke-CodeSignProfile
diff --git a/setup/codesign.ps1 b/setup/codesign.ps1
new file mode 100644 (file)
index 0000000..7f44f10
--- /dev/null
@@ -0,0 +1,35 @@
+<#
+.SYNPOSIS
+
+Commands to maintain a local code singing cert.
+
+#>
+$certName = "Local Code Sign Cert"
+
+function New-CodeSignCert {
+
+$cert = New-SelfSignedCertificate -CertStoreLocation Cert:\CurrentUser\My -Type CodeSigningCert -Subject "$certName"
+
+}
+
+function Get-CodeSignCert {
+       return Get-ChildItem -Path Cert:\CurrentUser\My | ? Subject -EQ "CN=$certName"
+}
+
+function Set-CodeSignCert {
+
+       $cert = Get-CodeSignCert
+       Move-Item -Path $cert.PSPath -Destination "Cert:\CurrentUser\Root"
+}
+
+function Invoke-SignScript {
+       param(
+               [string]$Path
+       )
+       $cert = Get-CodeSignCert
+       Set-AuthenticodeSignature -FilePath $Path -Certificate $cert
+}
+
+
+New-CodeSignCert
+Set-CodeSignCert