Skip to content

Instantly share code, notes, and snippets.

View lukpueh's full-sized avatar
👶
OOO until 2/25

Lukas Pühringer lukpueh

👶
OOO until 2/25
View GitHub Profile
@lukpueh
lukpueh / bin_numbers.py
Last active December 18, 2023 12:28
TUF hash bin delegation (optimal bin numbers)
"""TUF hash bin delegation (optimal bin numbers)
Calculate the optimal number of bins for given number of target files.
Problem description
===================
Given 'targets_count', 'bin_meta_size' and 'target_meta_size', I want to know
the optimal 'bin_count', for which 'snapshot_size' plus 'bin_size' are minimal.
Constraints
@lukpueh
lukpueh / serve_simple_dsse_repo.py
Last active October 12, 2023 10:49
Serve simple static TUF repo with DSSE metadata (client demo)
"""Serve simple static TUF repo with DSSE metadata (client demo).
Serves ad-hoc generated top-level metadata and single target file from
localhost to demo client-side DSSE support.
Usage:
- Install python-tuf (with DSSE support -- theupdateframework/python-tuf#2385)
- Start this script (quit with ctrl+z)
- Download target with python-tuf example client
@lukpueh
lukpueh / 1.root.json
Last active November 4, 2022 17:19
Update root with unrecognized fields
{
"signatures": [
{
"keyid": "bb3de7c557a82e1f8b2867dd3e457e51c7f01bd262c4c812eb5818600776f0ad",
"sig": "e7ae9d3cd1c9818bff2a8d2a80a350acc802397f9db0a37a8540656501e42b92daeb3802245ed41ce79c062c18b1619a8af2a139b1147cf4831251d23e8ff104"
}
],
"signed": {
"_type": "root",
"consistent_snapshot": true,
@lukpueh
lukpueh / inline_disable_pylint.py
Created October 18, 2022 11:57
Inline-disable pylint based on logged messages.
"""Inline-disable pylint based on logged messages.
Parses pylint log and adds "# pylint: disable=<msg>, <msg>, .." inline to all flagged
lines, unless the pylint message is of type ERROR or FATAL.
This is useful, to enable a linter on a legacy code base, without the need to address
all warnings right away.
Issues:
- Messages about empty files, e.g. __init__.py are ignored
@lukpueh
lukpueh / python-tuf_sec_audit_example.md
Last active March 8, 2023 10:00
Example python-tuf usage for security assessment

python-tuf security assessment

There are 2 classes of interesting TUF repository compromise scenarios and corresponding audit questions:

  1. Repository hosting compromised and/or MITM, signing keys safe --> "Can the attacker affect the client in any way?"

  2. Repository hosting compromised and/or MITM, signing keys compromised --> "Can the attacker affect the client beyond the capability of the compromised key in

@lukpueh
lukpueh / scrape_box.py
Created March 23, 2022 13:45
Scrape app.box.com pseudo PDFs
import os
import base64
import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
TIMEOUT = 10000
@lukpueh
lukpueh / gh_org_info.py
Last active January 14, 2021 14:50
Query GitHub REST API to get org permission for people and teams.
#!/usr/bin/env python
"""Query GitHub REST API to get org permission for people and teams
Usage:
./gh_org_info.py <GitHub user name> <AuthToken> <organization name>
Note: To create an authentication token see
https://docs.github.com/en/free-pro-team@latest/github/authenticating-to-github/creating-a-personal-access-token
Result:
{
"people": {
@lukpueh
lukpueh / tuf_with_unicode.py
Created March 20, 2020 14:46
Minimal tuf repo <-> client unicode example
# coding: utf-8
"""Minimal tuf repo <-> client example, with unicode
- delegated targets role name, and
- target file name
"""
import os, tempfile, shutil, six
from tuf.repository_tool import *
from securesystemslib.process import subprocess, run_duplicate_streams
@lukpueh
lukpueh / profile_tuf_bins.py
Last active March 19, 2020 17:51
Script to generate and write a basic TUF repo for profiling purposes
"""
Script to generate and write a basic TUF repo with keys, top-level roles, a
delegated targets role, and BIN_N_COUNT delegated targets roles, for profiling
purposes.
<Usage>
pip install securesystemslib[crypto,pynacl] tuf
curl https://gist.githubusercontent.com/lukpueh/724bd1d7b477f201a9f199b037d85747/raw/profile_tuf_bins.py -o profile_tuf_bins.py
python -m cProfile -o stats profile_tuf_bins.py
@lukpueh
lukpueh / recursive_nested_to_upper.go
Created April 10, 2019 11:29
Self-educational go snippet to learn about the empty interface{} type.
// Self-educational go snippet to learn about the empty interface{} type.
// Based on @hvoecking's arbitrary structures traversal gist
// https://gist.github.com/hvoecking/10772475
package main
import (
"fmt"
"reflect"