Skip to content

Instantly share code, notes, and snippets.

@thezim
thezim / build-tmux.sh
Created September 11, 2025 08:39
Builds tmux on macOS
#!/usr/bin/env sh
set -ex
CPU_CORES=$(sysctl -n hw.ncpu)
MAKE_JOBS=$(expr $CPU_CORES / 2)
# Set working directory.
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
cd $SCRIPT_DIR
@thezim
thezim / generate-test-certificates.sh
Last active July 9, 2025 00:48
Generates a root CA, intermediate CA, intermediate CRL, server certificate, and two user certificates.
#!/usr/bin/env sh
# Loosly based on https://openssl-ca.readthedocs.io/en/latest/index.html
set -eu
# --- Configuration ---
ROOT_CA_KEY_SIZE=4096
OTHER_KEY_SIZE=2048
@thezim
thezim / get-dod-pem.sh
Created June 22, 2025 17:41
Download DoD PEM
#!/usr/bin/env sh
URL=https://dl.dod.cyber.mil/wp-content/uploads/pki-pke/zip/unclass-certificates_pkcs7_DoD.zip
FILENAME=$(basename $URL)
DOWNLOAD_FILE=$TMPDIR$FILENAME
curl -sL -o $DOWNLOAD_FILE $URL
unzip -p $DOWNLOAD_FILE *.pem.p7b | openssl pkcs7 -print_certs -outform PEM -out $1
@thezim
thezim / pem-regex.txt
Created January 11, 2025 00:33
Regular expressions PEM file with multiple certificates
-----BEGIN CERTIFICATE REQUEST-----(?<certificate>\r?\n([A-Za-z0-9\/+]{64}\r?\n)*[A-Za-z0-9\/+]{1,64}={0,2}\r?\n)-----END CERTIFICATE REQUEST-----(\r?\n)?
@thezim
thezim / Get-Win32OpenSSL.ps1
Created August 21, 2024 00:05
Get OpenSSL from Git client distribution
$ErrorActionPreference = "Stop"
$Global:ProgressPreference = "SilentlyContinue"
$installpath = Join-Path -Path $env:ProgramFiles -ChildPath OpenSSL
$uri = [uri]"https://github.com/git-for-windows/git/releases/download/v2.45.0.windows.1/PortableGit-2.45.0-64-bit.7z.exe"
$filename = $uri.Segments | Select-Object -Last 1
$downloadpath = Join-Path -Path $env:TEMP -ChildPath $filename
Invoke-WebRequest -Uri $uri -OutFile $downloadpath
$expandpath = Join-Path -Path $env:TEMP -ChildPath (Get-Item -Path $downloadpath | Select-Object -ExpandProperty BaseName)
& $downloadpath -o"$expandpath" -y
$files = @( "openssl.exe", "libcrypto-3-x64.dll", "libssl-3-x64.dll", "zlib1.dll" )
$code = @"
using System.Text;
using System;
using System.Runtime.InteropServices;
namespace CredManager {
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct CredentialMem
{
public int flags;
@thezim
thezim / colors.reg
Created July 12, 2023 12:52
Registry entry for new console themes
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Console]
"ColorTable00"=dword:000c0c0c
"ColorTable01"=dword:00da3700
"ColorTable02"=dword:000ea113
"ColorTable03"=dword:00dd963a
"ColorTable04"=dword:001f0fc5
"ColorTable05"=dword:00981788
"ColorTable06"=dword:00009cc1
openssl rsa -in somefile.pem -out id_rsa_somefile
function Invoke-ListDirectory {
param (
[Parameter(Mandatory = $false, Position = 0, ValueFromRemainingArguments = $true)]$Remaining
)
$defaultargs = "-la"
/bin/ls $defaultargs @Remaining
}
function Get-RemoteCertificate {
param (
[uri]$Uri
)
$tcpclient = New-Object System.Net.Sockets.TcpClient($Uri.DnsSafeHost, $Uri.Port)
$rcvc = [System.Net.Security.RemoteCertificateValidationCallback]{
param(
[object]$senderd,
[System.Security.Cryptography.X509Certificates.X509Certificate]$certificate,
[System.Security.Cryptography.X509Certificates.X509Chain]$chain,