Wojtek – IT guy

IT, Security, IAM, PKI, Software, Tools, Games, Scripts etc…

New web browser extension – Keep Awake

Simple but my own. I was looking for such extension to prevent my computer to go to sleep when I step away for a bit, but was not happy with others I found so I decided to write it. Very simple, yet fulfils my needs. Check it out – Keep Awake. It’s already published on Google Web Store.

It uses Chrome power API display setting, so not so powerful, but suitable for me. I already have some ideas for enhancements, so definitely there will be next version/s but not much to upgrade in such a simple tool.

Generate number of self-signed certificates

I had a requirement to test Yubikey 5 with PIV for Windows smartcard authentication. There’s four slots for certificates 9a, 9c, 9d and 9e and by default a, d and e work for user authentication, while 9c requires minidriver to work. I wanted to deploy 4 certificates, with iterated names to confirm if slots work and if in fact 9c doesn’t work without minidriver. I used PowerShell to generate certificates:

$baseName = "wojciechjakubowski"
$certPath = "Cert:\CurrentUser\My"

for ($i = 1; $i -le 4; $i++) {
    $subject = "CN=$baseName$i"
    $cert = New-SelfSignedCertificate -Subject $subject `
        -KeyUsage DigitalSignature `
        -Type Custom `
        -TextExtension @("2.5.29.37={text}1.3.6.1.4.1.311.20.2.2") `
        -CertStoreLocation $certPath

    $pwd = ConvertTo-SecureString -String "123" -Force -AsPlainText
    $file = "$baseName$i.pfx"
    Export-PfxCertificate -Cert $cert -FilePath "C:\temp\$file" -Password $pwd
}

1.3.6.1.4.1.311.20.2.2 is an OID for smart card logon, which was something I wanted to test, but you can replace or add EKUs using below common OIDs to test against other purposes:

1.3.6.1.5.5.7.3.2 – Client Authentication
1.3.6.1.5.5.7.3.1 – Server Authentication
1.3.6.1.5.5.7.3.3 – Code Signing
1.3.6.1.4.1.311.20.2.2 – Smart Card Logon
1.3.6.1.4.1.311.10.3.12 – Document Signing

For what it’s worth, I confirmed that 9c is not showing up without minidriver and it does show up with minidriver installed.

Eurojackpot Generator update #4

It took me a while but it’s the biggest update so far, at least code wise. Version 1.4.0 allows to set notifications of upcoming Eurojackpot draws. You can mark default values of 24h, 6h and 2h or specify custom value. It can be number of hours to draw, for example 4h, or exact time on the day of the draw, for example 16:35. Extension is using system notifications and on Windows it looks like that:

This is first version that requires permissions. Check Eurojackpot Generator for version control.

Merge PDFs and send to remote computer

I had a need to automate the process of merging PDF files and sending them over to remote computer. It started with just few lines, but it grew in time to cover different scenarios. I also added comments and colors. I thought I will share it. I am using Ghostscript to merge PDFs. Access to remote computer granted through windows share to local account ‘wojtek’. Script goes like this:

Write-Host "SCRIPT STARTED" -ForegroundColor Green
# Define paths
Write-Host "Configuring variables"
$localpath = "C:\Temp\SCAN"
$remotepath = "\\192.168.0.248\share"
$outputFile = "$localpath\scan.pdf"
$gs = 'C:\Program Files\gs\gs10.04.0\bin\gswin64c.exe'

# Check for file existence
$agrEXIST = Test-Path "$localpath\agreements.pdf"
$part1EXIST = Test-Path "$localpath\part1.pdf"
$anyPDFExist = Test-Path "$localpath\*.pdf"

Write-Host "Configuring variables DONE" -ForegroundColor DarkGreen

# Exit if there is nothing to process
If (-not ($agrEXIST -or $part1EXIST -or $anyPDFExist)) {
    Write-Host "Nothing to process... Exiting..."
    exit
}

# Warn if only non-standard PDFs exist
If (-not ($agrEXIST -or $part1EXIST) -and $anyPDFExist) {
    Write-Host "Nothing to process... But I found PDF files in the folder. Check if their names are correct - agreements.pdf and part1.pdf, part2.pdf etc."
    exit
}

# Map network drive
Write-Host "Mapping kitchen computer as drive Z"
net use z: $remotepath /user:wojtek PASSWORD | Out-Null
Write-Host "Mapping kitchen computer as drive Z DONE" -ForegroundColor DarkGreen

# Process PDF files if part1.pdf exists
If ($part1EXIST) {
Write-Host "Defining settings for PDF merge"
    $pdfFiles = Get-ChildItem -Path $localpath -Filter "part*.pdf" | ForEach-Object { "`"$($_.FullName)`"" }
    $args = @("-dBATCH", "-dNOPAUSE", "-q", "-sDEVICE=pdfwrite", "-sOutputFile=$outputFile") + $pdfFiles
    Write-Host "Defining settings for PDF merge DONE" -ForegroundColor DarkGreen
    # Run Ghostscript to merge PDFs
    Write-Host "Merging PDFs"
    & $gs @args
    Write-Host "Merging PDFs DONE" -ForegroundColor DarkGreen

    # Copy files based on existence
    Write-Host "Copying Scan"
    Copy-Item $outputFile -Destination z:\
    Write-Host "Copying Scan DONE" -ForegroundColor DarkGreen

    If ($agrEXIST) {
        Write-Host "Copying Agreements"
        Copy-Item "$localpath\agreements.pdf" -Destination z:\
        Write-Host "Copying Agreements DONE" -ForegroundColor DarkGreen
    }
} Else {
    # Copy only agreements.pdf if part1.pdf does not exist
    Write-Host "Copying Agreements"
    Copy-Item "$localpath\agreements.pdf" -Destination z:\
    Write-Host "Copying Agreements DONE" -ForegroundColor DarkGreen
}

# Unmap network drive
Write-Host "Removing kitchen computer as drive Z"
net use z: /DELETE | Out-Null
Write-Host "Removing kitchen computer as drive Z DONE" -ForegroundColor DarkGreen
Write-Host "SCRIPT COMPLETED" -ForegroundColor Green

Simple, but pretty unusual. Perhaps you’ll find it useful.