Skip to content

Instantly share code, notes, and snippets.

@pentagramz
Forked from ronsims2/README.md
Created August 12, 2023 20:59
Show Gist options
  • Save pentagramz/8ece6d0842523e6f9d8d971648edb93b to your computer and use it in GitHub Desktop.
Save pentagramz/8ece6d0842523e6f9d8d971648edb93b to your computer and use it in GitHub Desktop.

Revisions

  1. @ronsims2 ronsims2 revised this gist Mar 20, 2019. No changes.
  2. @ronsims2 ronsims2 revised this gist Mar 20, 2019. 1 changed file with 10 additions and 0 deletions.
    10 changes: 10 additions & 0 deletions ipa_cert_checker.py
    Original file line number Diff line number Diff line change
    @@ -37,10 +37,14 @@ def base64ify(fn):
    soup = bs4.BeautifulSoup(provxml, 'html.parser')

    certs = None
    exp_date = None

    for k in soup('key'):
    if k.string == 'DeveloperCertificates':
    certs = [x.string for x in k.findNext('array').findAll('data')]

    if k.string == 'ExpirationDate':
    exp_date = k.findNext('date').string


    # Decode cert and compare to specified cert
    @@ -51,4 +55,10 @@ def base64ify(fn):
    print('Certificate (' + str(i + 1) + ') beginning: ' + cer[0: 9] + '... matches the specified certificate: ' + cert)


    if exp_date is not None:
    print('This provisioning profile expires on: ' + exp_date)
    else:
    print('the provisioning profiles expiration date could not be parsed.')


    print('The cert checker has finished.')
  3. @ronsims2 ronsims2 revised this gist Mar 19, 2019. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -2,9 +2,9 @@

    Example :

    python ipa_cert_checker.py /Users/janedoe/Dcouments/Foobar.ipa /Users/janedoe/Dcouments/barfoo.cer
    python ipa_cert_checker.py /Users/janedoe/Documents/Foobar.ipa /Users/janedoe/Documents/barfoo.cer


    If any matching certs are found, the script will print something similar to:

    Certificate (1) beginning: XCVBNM... matches the specified certificate: /Users/janedoe/Dcouments/barfoo.cer
    Certificate (1) beginning: XCVBNM... matches the specified certificate: /Users/janedoe/Documents/barfoo.cer
  4. @ronsims2 ronsims2 revised this gist Mar 19, 2019. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,7 @@
    # Verify an IPA's Signing Certificate

    Example :

    python ipa_cert_checker.py /Users/janedoe/Dcouments/Foobar.ipa /Users/janedoe/Dcouments/barfoo.cer


  5. @ronsims2 ronsims2 revised this gist Mar 19, 2019. No changes.
  6. @ronsims2 ronsims2 created this gist Mar 19, 2019.
    9 changes: 9 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,9 @@
    # Verify an IPA's Signing Certificate

    Example :
    python ipa_cert_checker.py /Users/janedoe/Dcouments/Foobar.ipa /Users/janedoe/Dcouments/barfoo.cer


    If any matching certs are found, the script will print something similar to:

    Certificate (1) beginning: XCVBNM... matches the specified certificate: /Users/janedoe/Dcouments/barfoo.cer
    54 changes: 54 additions & 0 deletions ipa_cert_checker.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,54 @@
    import subprocess
    import sys
    import zipfile
    import bs4
    import base64

    if len(sys.argv) != 3:
    print('Invalid number of arguments.')
    exit(1)


    ipa = sys.argv[1]
    app_name = ipa.split('/')[-1].split('.')[0]
    cert = sys.argv[2]
    workspace = '/'.join(sys.argv[1].split('/')[0:-1])
    provfile = workspace + '/Payload/' + app_name + '.app/embedded.mobileprovision'


    # Unzip the IPA file
    with zipfile.ZipFile(ipa, 'r') as ipa_file:
    ipa_file.extractall(workspace)

    get_prov = subprocess.Popen(['security', 'cms', '-Di', provfile],
    stdout=subprocess.PIPE,
    stderr=subprocess.STDOUT)


    provxml = ''.join(map(lambda x: str(x, 'utf-8'), get_prov.stdout.readlines()))


    def base64ify(fn):
    with open(fn, 'rb') as f:
    return str(base64.b64encode(f.read()), 'utf-8')


    # Parse doc to get cert base64 string
    soup = bs4.BeautifulSoup(provxml, 'html.parser')

    certs = None

    for k in soup('key'):
    if k.string == 'DeveloperCertificates':
    certs = [x.string for x in k.findNext('array').findAll('data')]


    # Decode cert and compare to specified cert
    refcert = base64ify(cert)

    for i, cer in enumerate(certs):
    if cer == refcert:
    print('Certificate (' + str(i + 1) + ') beginning: ' + cer[0: 9] + '... matches the specified certificate: ' + cert)


    print('The cert checker has finished.')
    4 changes: 4 additions & 0 deletions requirements.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,4 @@
    beautifulsoup4==4.7.1
    certifi==2019.3.9
    chardet==3.0.4
    soupsieve==1.8