Skip to content

Instantly share code, notes, and snippets.

View apettinen's full-sized avatar

Antti Pettinen apettinen

  • Finland
View GitHub Profile
#!/usr/bin/python
# Will loop until string contains other than strings and digits
# sets of strings and digits
# depends on your local, see locale.getlocale() and locale.setlocale()
# by default this is non-scandic, i.e. basic A-Z,a-z and 0-9
import strings
import os
strings_and_digits = string.letters+string.digits
while True:
gens=os.urandom(33).encode('base64').strip('\n')
@apettinen
apettinen / getStringEntropy.py
Created November 29, 2017 10:38
Simple entropy calculation of a string
#!/usr/bin/python
"""
Simple entropy calculation of a string
"""
from __future__ import division
from math import log
from collections import Counter
def get_entropy(s):
return -sum(i/len(s) * log(i/len(s),2) for i in Counter(s).values())
@apettinen
apettinen / keychain_password.py
Created October 3, 2017 12:27 — forked from pudquick/keychain_password.py
Storing and retrieving a generic password in the login.keychain in macOS via python and pyobjc
import objc
from ctypes import c_char
from Foundation import NSBundle
Security = NSBundle.bundleWithIdentifier_('com.apple.security')
S_functions = [
('SecKeychainGetTypeID', 'I'),
('SecKeychainItemGetTypeID', 'I'),
('SecKeychainAddGenericPassword', 'i^{OpaqueSecKeychainRef=}I*I*I*o^^{OpaqueSecKeychainItemRef}'),
('SecKeychainOpen', 'i*o^^{OpaqueSecKeychainRef}'),
#!/usr/bin/python
# As written, this requires the following:
# - OS X 10.6+ (may not work in 10.10, haven't tested)
# - python 2.6 or 2.7 (for collections.namedtuple usage, should be fine as default python in 10.6 is 2.6)
# - pyObjC (as such, recommended to be used with native OS X python install)
# Only tested and confirmed to work against 10.9.5
# Run with root
#!/usr/bin/python
# -*- coding: utf-8 -*-
# pylint: disable=C0301, C0103, W0702, W1201
# Antti Pettinen (Tampere University of Technology)
# Ilkka Vanhatalo (Helsinki University)
# Copyright: Tampere University of Technology and University of Helsinki
# License: Apache 2.0
'''
Parse CSRs for Custom Attributes and Requested Extensions with pyASN1
'''

Keybase proof

I hereby claim:

  • I am apettinen on github.
  • I am apettinen (https://keybase.io/apettinen) on keybase.
  • I have a public key ASAPWHqmLJgZShgpb5VpsctdMwANSeOR5SqlP3qXz-Qo9Qo

To claim this, I am signing this object:

@apettinen
apettinen / gist:701688cc64881a1ae1c1
Last active October 18, 2018 23:37
Getting on track with Office2016 licensing

This gist gives a short outline of how to get back on track with Office 2016 licensing if you have been using the Combo Update packages available via AutoPKG to distribute Office 2016 applications and thus copying the Office license file around.

  1. download an installer package from http://macadmins.software (e.g. Word Standalone installer)

  2. extract the LauncDaemon and PrivilegedHelperTool from the installer package (e.g. by running the installer on a VM):

  • /Library/LaunchDaemons/com.microsoft.office.licensingV2.helper.plist
  • /Library/PrivilegedHelperTools/com.microsoft.office.licensingV2.helper
  1. package the abovementioned two files
@apettinen
apettinen / DisableiCloudSetup.mobileconfig
Created October 22, 2015 14:33
DisableiCloudSetup.mobileconfig
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>PayloadIdentifier</key>
<string>YOUR IDENTIFIER HERE</string>
<key>PayloadRemovalDisallowed</key>
<false/>
<key>PayloadScope</key>
<string>System</string>
@apettinen
apettinen / disableiCloudSetup.plist
Last active August 18, 2017 10:52
plist for mcxToProfile to disable iCloud Setup
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SkipCloudSetup</key>
<true/>
</dict>
</plist>