Skip to content

Instantly share code, notes, and snippets.

View magnuswatn's full-sized avatar

Magnus Watn magnuswatn

View GitHub Profile
@magnuswatn
magnuswatn / New-CSR.ps1
Created June 23, 2022 16:46
New-CSR.ps1
<#
.Synopsis
Script som genererer en CSR for et SSL/TLS-sertifikat.
.DESCRIPTION
Scriptet genererer en nøkkel og CSR på lokal maskin, for innsendelse til en CA.
Som standard vil det genereres en RSA-nøkkel (2048 bits) som vil være eksporterbar
og legges i LocalMachine-storen, men dette kan endres med -ECDSA, -CurrentUser og -NotExportable.
Vær obs på at nøkkelen blir en såkalt "CNG-nøkkel", så noe eldre programvare kan
@magnuswatn
magnuswatn / create_ssn_ocspreq.py
Created July 7, 2021 11:02
OCSP-fødselsnummeroppslag
#!/bin/env python3
"""
Script for å lage en ocsp-forespørsel med fødselsnummer-extension.
Brukes slik: ./create_ocspreq.py cert.pem issuer.pem ocsp_request
Støtter dessverre ikke signering av requesten, men openssl kan ta den biten, slik:
./create_ocspreq.py cert.pem issuer.pem - | openssl ocsp -reqin - -signer ./signcert.pem -signkey ./signkey.pem -reqout ocsp_request
@magnuswatn
magnuswatn / Enable-AutomaticRebindOfRenewedCertificate.ps1
Created July 5, 2021 11:20
Enable-AutomaticRebindOfRenewedCertificate
<#
Script that enables automatic rebinding of a renewed certificate in IIS.
Should create a scheduled task similar to the button in the IIS Manager.
Magnus Watn <[email protected]>
#>
$existingTask = (Get-ScheduledTask -TaskPath \Microsoft\Windows\CertificateServicesClient\ -TaskName IIS-AutoCertRebind -ErrorAction SilentlyContinue)
if ($null -ne $existingTask) {
<#
Quick script to decrypt and decode a SCEP request, for debugging.
The server certificate (and it's corresponding private key) needs to be
avaiable to the user running this.
#>
Add-Type -AssemblyName System.Security
function decodeNdesRequest ($request) {
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\.pem]
@="CERFile"
"Content Type"="application/x-x509-ca-cert"
def get_ca_bundle():
"""Tries to find the platform ca bundle for the system (on linux systems)"""
ca_bundles = [
# list taken from https://golang.org/src/crypto/x509/root_linux.go
"/etc/ssl/certs/ca-certificates.crt", # Debian/Ubuntu/Gentoo etc.
"/etc/pki/tls/certs/ca-bundle.crt", # Fedora/RHEL 6
"/etc/ssl/ca-bundle.pem", # OpenSUSE
"/etc/pki/tls/cacert.pem", # OpenELEC
"/etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem", # CentOS/RHEL 7
]
<#
Quick script to dump all the issued certs from a Active Directory Certificates Services server
Magnus Watn <[email protected]>
#>
$allCerts = certutil -view -out rawCertificate
$counter = 0
For ($i=0; $i -le $allCerts.length; $i++) {
@magnuswatn
magnuswatn / sct-irule.tcl
Last active November 20, 2017 19:19
iRule to add support for the Certificate Transparency TLS extension to F5 Big-IP devices
# This iRule can be used to add support for the Certificate Transparency TLS extension to F5 Big-IP devices
# The SCT list must be generated manually, and the sct variable below updated
#
# To generate a SCT list, the Submit-CertToCT cmdlet from https://github.com/magnuswatn/Cert-Tools can be used
#
# Magnus Watn <[email protected]>
when RULE_INIT {
set sct [b64decode APAAdwBvU3asMfAxGdiZAKRRFf93FRwR2QLBACkGjbIImjfZEwAAAV5Dgt9KAAAEAwBIMEYCIQCYgk4UXnDg3B1DLvsmaJtjFLjpdpE2xfRVBiUeE5MQVgIhALkAY37w2+ydiSf2VNNaYprD/Uqw8mIyQJWz7HahYExvAHUA7ku9t3XOYLrhQmkfq+GeZqMPfl+wctiDAMR7iXqo/csAAAFTb7OoKgAABAMARjBEAiB+LIypJ4JILb0EBg0NLK1Xjpu3/N4FuyAp7UPwkRKWMQIgbbLIrfh4WPdtDq5/DZXIxUMqXheCo8WdHaMKwTsW2/g=]
# Be aware that since this is a static variable, several of these rules can't coexists on the same box withouth changing the name
"""
A script to re-sign a certificate signing request
Can be useful if it has been tampered with,
e.g. by using the excellent DER ASCII tool
(https://github.com/google/der-ascii)
Magnus Watn <[email protected]>
"""