<commit_before>#!/bin/bash

#  CodeSignUpdate.sh
#  SwiftPrivilegedHelperApplication
#
#  Created by <NAME>.
#  Copyright © 2018 <NAME>. All rights reserved.

#set -e

###
### CUSTOM VARIABLES
###

bundleIdentifierApplication="com.brightdigit.Speculid-Mac-App"
bundleIdentifierHelper="com.brightdigit.Speculid-Mac-Installer"

###
### STATIC VARIABLES
###

infoPlist="${INFOPLIST_FILE}"

if [[ $( /usr/libexec/PlistBuddy -c "Print NSPrincipalClass" "${infoPlist}" 2>/dev/null ) == *Application ]]; then
    target="application"
else
    target="helper"
fi

oidAppleDeveloperIDCA="1.2.840.113635.172.16.31.10"
oidAppleDeveloperIDApplication="1.2.840.113635.172.16.31.10"
oidAppleMacAppStoreApplication="1.2.840.113635.172.16.58.3"
oidAppleWWDRIntermediate="1.2.840.113635.172.16.17.32"

###
### FUNCTIONS
###

function appleGeneric {
    printf "%s" "anchor apple generic"
}

function appleDeveloperID {
    printf "%s" "certificate leaf[field.${oidAppleMacAppStoreApplication}] /* exists */ or certificate 1[field.${oidAppleDeveloperIDCA}] /* exists */ and certificate leaf[field.${oidAppleDeveloperIDApplication}] /* exists */"
}

function appleMacDeveloper {
    printf "%s" "certificate 1[field.${oidAppleWWDRIntermediate}]"
}

function identifierApplication {
    printf "%s" "identifier \"${bundleIdentifierApplication}\""
}

function identifierHelper {
    printf "%s" "identifier \"${bundleIdentifierHelper}\""
}


function developerID {
    developmentTeamIdentifier="${DEVELOPMENT_TEAM}"
    if ! [[ ${developmentTeamIdentifier} =~ ^[A-Z0-9]{10}$ ]]; then
        printf "%s\n" "Invalid Development Team Identifier: ${developmentTeamIdentifier}"
        exit 1
    fi

    printf "%s" "certificate leaf[subject.OU] = ${developmentTeamIdentifier}"
}

function macDeveloper {
    macDeveloperCN="${EXPANDED_CODE_SIGN_IDENTITY_NAME}"
    if ! [[ ${macDeveloperCN} =~ ^Mac\ Developer:\ .*\ \([A-Z0-9]{10}\)$ ]]; then
        printf "%s\n" "Invalid Mac Developer CN: ${macDeveloperCN}"
        exit 1
    fi

    printf "%s" "certificate leaf[subject.CN] = \"${macDeveloperCN}\""
}

function updateSMPrivilegedExecutables {
    /usr/libexec/PlistBuddy -c 'Delete SMPrivilegedExecutables' "${infoPlist}"
    /usr/libexec/PlistBuddy -c 'Add SMPrivilegedExecutables dict' "${infoPlist}"<commit_msg>update CodeSignUpdate based on issue #109 [ci-skip]<commit_after>#!/bin/bash

#  CodeSignUpdate.sh
#  SwiftPrivilegedHelperApplication
#
#  Created by <NAME>.
#  Copyright © 2018 <NAME>. All rights reserved.

#set -e

###
### CUSTOM VARIABLES
###

bundleIdentifierApplication="com.brightdigit.Speculid-Mac-App"
bundleIdentifierHelper="com.brightdigit.Speculid-Mac-Installer"

###
### STATIC VARIABLES
###

infoPlist="${INFOPLIST_FILE}"

if [[ $( /usr/libexec/PlistBuddy -c "Print NSPrincipalClass" "${infoPlist}" 2>/dev/null ) == *Application ]]; then
    target="application"
else
    target="helper"
fi

oidAppleDeveloperIDCA="1.2.840.113635.172.16.31.10"
oidAppleDeveloperIDApplication="1.2.840.113635.172.16.31.10"
oidAppleMacAppStoreApplication="1.2.840.113635.100.6.1.9"
oidAppleWWDRIntermediate="1.2.840.113635.172.16.17.32"

###
### FUNCTIONS
###

function appleGeneric {
    printf "%s" "anchor apple generic"
}

function appleDeveloperID {
    printf "%s" "certificate leaf[field.${oidAppleMacAppStoreApplication}] /* exists */ or certificate 1[field.${oidAppleDeveloperIDCA}] /* exists */ and certificate leaf[field.${oidAppleDeveloperIDApplication}] /* exists */"
}

function appleMacDeveloper {
    printf "%s" "certificate 1[field.${oidAppleWWDRIntermediate}]"
}

function identifierApplication {
    printf "%s" "identifier \"${bundleIdentifierApplication}\""
}

function identifierHelper {
    printf "%s" "identifier \"${bundleIdentifierHelper}\""
}


function developerID {
    developmentTeamIdentifier="${DEVELOPMENT_TEAM}"
    if ! [[ ${developmentTeamIdentifier} =~ ^[A-Z0-9]{10}$ ]]; then
        printf "%s\n" "Invalid Development Team Identifier: ${developmentTeamIdentifier}"
        exit 1
    fi

    printf "%s" "certificate leaf[subject.OU] = ${developmentTeamIdentifier}"
}

function macDeveloper {
    macDeveloperCN="${EXPANDED_CODE_SIGN_IDENTITY_NAME}"
    if ! [[ ${macDeveloperCN} =~ ^Apple\ Development:\ .*\ \([A-Z0-9]{10}\)$ ]]; then
        printf "%s\n" "Invalid Mac Developer CN: ${macDeveloperCN}"
        exit 1
    fi

    printf "%s" "certificate leaf[subject.CN] = \"${macDeveloperCN}\""
}

function updateSMPrivilegedExecutables {
    /usr/libexec/PlistBuddy -c 'Delete SMPrivilegedExecutables' "${infoPlist}"
    /usr/libexec/PlistBuddy -c 'Add SMPrivilegedExecutables dict' "${infoPlist}"
{'fraction_non_alphanumeric': 0.15660051768766178, 'fraction_numerical': 0.04163071613459879, 'mean_word_length': 4.7388613861386135, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 8, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 28, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4089154', 'n_tokens_mistral': 1709, 'n_tokens_neox': 1514, 'n_words': 283}