Education

MacADUK 2019

David Acland
03.18.2019
Share

Update: Here’s a copy of the slides from my talk on the 26th March: Slide deck PDF

On the 26th March 2019, I’ll be talking about digital signatures at MacADUK in London.  This is a fairly technical topic, and we’ll be going right down to a binary level with some of the underlying technologies.  

For those of you coming to the session, below you’ll find the commands used during the demos, followed by brief descriptions of each of the math concepts that will come up during the talk.

Once the presentation is over, we’ll post a copy of the slides here.

Commands used in the demos

Hashing

Hash some strings of text with sha256:
printf "macaduk" | openssl dgst -sha256
printf "MacADUK" | openssl dgst -sha256
printf "MacADUK is a 2 day conference held in London." | openssl dgst -sha256

Hash a string with sha1:
printf -n "macaduk" | openssl dgst -sha1

Hash a string with sha512:
printf -n "macaduk" | openssl dgst -sha512

Hash some files with sha256:
echo 'Hello world!' > ~/Desktop/testfile.txt
openssl dgst -sha256 ~/Desktop/testfile.txt | awk '{print $NF}'
pico ~/Desktop/testfile.txt
openssl dgst -sha256 ~/Desktop/testfile.txt | awk '{print $NF}'

Signing

Create a private key:
openssl genpkey -algorithm RSA -out ~/Desktop/private_key.pem
Create a public key:
openssl rsa -in ~/Desktop/private_key.pem -outform PEM -pubout -out ~/Desktop/public.pem
Sign your test file:
openssl dgst -sha256 -sign ~/Desktop/private_key.pem -out ~/Desktop/signature ~/Desktop/testfile.txt
Verify the signature:
openssl dgst -sha256 -verify ~/Desktop/public.pem -signature ~/Desktop/signature ~/Desktop/testfile.txt

Package Signing

Package the Calculator app:
pkgbuild --install-location /Applications --component /Applications/Calculator.app ~/Desktop/Calculator.pkg
Sign the package:
productsign --sign "your developer ID" ~/Desktop/Calculator.pkg ~/Desktop/Calculator_signed.pkg
Check the signature:
pkgutil --check-signature /Users/dave/Desktop/Calculator_signed.pkg
Expand a signed package:
pkgutil --expand ~/Desktop/Ovis\ pdf-DocPro\ Install.pkg ~/Desktop/Ovis\ pdf-DocPro\ Install_expanded.pkg

Flatten the expanded package:
pkgutil --flatten ~/Desktop/Ovis\ pdf-DocPro\ Install_expanded.pkg ~/Desktop/Ovis\ pdf-DocPro\ Install.pkg

App Signing

Create a script file:
echo '#!/bin/sh' > ~/Desktop/MyGreatScript.sh
echo 'echo "Hello world!"' >> ~/Desktop/MyGreatScript.sh
chmod 755 ~/Desktop/MyGreatScript.sh

Test the script:
~/Desktop/MyGreatScript.sh

Sign the script:
codesign -s "your developer ID" ~/Desktop/MyGreatScript.sh
codesign --verify --verbose ~/Desktop/MyGreatScript.sh
codesign -dv --verbose=2 ~/Desktop/MyGreatScript.sh

Verify the signature:
codesign -dv --verbose=2 ~/Desktop/MyGreatScript.sh

Check the code signing of the script:
codesign -dv --verbose=2 ~/Desktop/MyGreatScript.sh

Kernel Extensions

Check who signed the SoftRAID.kext kernel extension:
codesign -dvvvv --verbose=4 /Library/Extensions/SoftRAID.kext

Maths

Ahead of the talk, it will be worth attendees getting familiar with each of these math concepts:

Prime Numbers

A prime number can only be divided by itself and 1.  For example: 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197 and 199.

The list keeps growing into infinity, with the largest known prime number having 23,249,425 digits.

Factoring

Factoring is the process of finding what numbers to multiply together to get a given result. So, if you are given a value of 10, “factoring” is working out what numbers you can multiply together to get that value, i.e. “2 x 5 = 10”.

The numbers that are multiplied together to get a result are known as the “factors”. In the above example, the factors are “2” & “5”.

Numbers can have lots of factors, with 1 being a factor of all numbers (as every number is divisible by 1). For example, the factors of 16 are:

  • 1 (1 x 16 = 16)
  • 2 (2 x 8 = 16)
  • 4 (4 x 4 = 16)
  • 8 (8 x 2 = 16)
  • 16 (16 x 1 = 16)

Prime Factorisation

Prime factorisation is almost the same as factoring, but in this case, you’re looking for two prime numbers.

For example, the factors of 15 (which isn’t a prime number) are 3 & 5 (which are prime numbers):

3 * 5 = 15

Exponentiation

Exponentiation is maths shorthand describing how many times a number is multiplied by itself.  Written as be, involving two numbers, the base “b” and the exponent “e”.  When “e” is a positive Integer (a whole number greater than zero), it refers the number of times you would multiply the base “b”.  

It is often described as “b raised to the power of e”, or “b raised to the e-th power”.

Relative Prime / Coprime

Two integers are said to be relatively prime (or “coprime”) if the only positive integer that divides both of them evenly is 1.  They don’t have to be prime numbers, as long as the only common factor they share is 1.

For example, 35 and 18 are relatively prime, but they aren’t prime numbers:

  • Factors of 35 are 1, 5, 7, 35
  • Factors of 18 are 1, 2, 3, 6, 9, 18

Other than 1, none of the factors of 35 or the factors 18 are in common, so 35 and 18 are “relatively prime”

Modular Arithmetic

The modulo operation (abbreviated “mod”, or “%”) is the remainder when dividing one number with another. For example, “5 mod 3” equals “2”.  This is because “2” is the remainder when you divide 5 by 3”.

Modular Arithmetic is sometimes called “Clock Arithmetic”, because if the modulus were a clock face, the answer is the number you end up at when you “wrap” a number around it.  For example, with a mod of 3, 5 would wrap around the entire clock face of 3, and keep going, eventually stopping at 2.

Interestingly, we’ve already been using modular arithmetic for keeping time.  For example, to display 14:00 hrs, you would wrap 14 around the 12-hour clock face, giving you a remainder of 2, or 2pm.

Euler’s Totient Function ϕ(n)

Euler’s totient (sometimes called ”Euler’s Phi Function”), noted with the Greek letter phi: ϕ(n) is the value representing the number of positive integers, less than or equal to n, that are also relatively prime (coprime) to n.

A number less than or equal to and relatively prime to a given number is called a totative, with the totient being the total number of totatives of an integer.

So given any integer, Euler’s Totient Function calculates the total number of totatives of that number.

Using 24 as an example…  As a totient equation, this would be: ϕ(24)=8.  

This means that 24 has eight totatives, which are: 1, 5, 7, 11, 13, 17, 19, and 23.  Why?  Each of these numbers are relatively prime (coprime) to 24, because they don’t share any factors in common, (other than 1 which is relatively prime to all numbers).

Useful links

Here’s a few other links that help explain some of the concepts covered in this talk:

How strong is SHA256? – https://www.youtube.com/watch?v=S9JGmA5_unY

Contact Moof IT to discuss your Mac management needs

  • ISO_27001 logo
  • logo
  • Gcloud logo

Company

Address:
1st Floor, 20 Noel street, London, W1f 8GW
Company Number: 11082827