BitBetter/generateKeys.ps1
Michiel Hazelhof 9bc010cb57
Update and fix unified branch (#257)
* Upstream patches

* Fix license generator according to upstream changes (#245) (#249)

* Test generating user and organization licenses during build check (#252)

* Fix ps1 script and update language

* Update class path

* Cleanup code

* Cleanup code

* Cleanup code

* Refactor and fixes

* Copy all files

* Copy files only when needed

* Make call consistent

* Simplify call

* Clarify language

* Reuse code

* Cleanup

* Cleanup

* Remove NewtonSoft.Json

* Upgrade dnlib

* Cleanup

* Fix path issue

* Fix comparator

* Cleanup circleci

* Fix type

* Fix circleci

* Properly detect previous version

* Add missing parameter

* Better detect running patched containers

* Improve naming

* Fix line endings

* Fix typo

* Add comment

* Fix tabs

* Cleanup org license

* Use proper file extension

* Add missing file

* Migrate cert.cert if exists

* Check for the correct file

* Fix character check

* Add comment

* Add more documentation

* Add proper line endings

* Add potentially correct line

* Add auto restart

* Update comment

* Improve consistency between bash and powerhell

* Update documentation

* Detect buildx

* Fix spelling mistake

* Fix check order and improve verbosity
2025-10-05 19:40:16 +01:00

25 lines
1.1 KiB
PowerShell

$ErrorActionPreference = 'Stop'
$PSNativeCommandUseErrorActionPreference = $true
# get the basic openssl binary path
$opensslbinary = "$Env:Programfiles\OpenSSL-Win64\bin\openssl.exe"
# if openssl is not installed attempt to install it
if (!(Get-Command $opensslbinary -errorAction SilentlyContinue))
{
winget install openssl
}
# if previous keys exist, remove them
if (Test-Path "$pwd\.keys")
{
Remove-Item "$pwd\.keys" -Recurse -Force
}
# create new directory
New-item -ItemType Directory -Path "$pwd\.keys"
# generate actual keys
Invoke-Expression "& '$opensslbinary' req -x509 -newkey rsa:4096 -keyout `"$pwd\.keys\key.pem`" -out `"$pwd\.keys\cert.cer`" -days 36500 -subj '/CN=www.mydom.com/O=My Company Name LTD./C=US' -outform DER -passout pass:test"
Invoke-Expression "& '$opensslbinary' x509 -inform DER -in `"$pwd\.keys\cert.cer`" -out `"$pwd\.keys\cert.pem`""
Invoke-Expression "& '$opensslbinary' pkcs12 -export -out `"$pwd\.keys\cert.pfx`" -inkey `"$pwd\.keys\key.pem`" -in `"$pwd\.keys\cert.pem`" -passin pass:test -passout pass:test"