Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(certs): support detecting apple certs #93

Merged
merged 2 commits into from
Aug 29, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
39 changes: 23 additions & 16 deletions lib/certs.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ const
magik = require('./utilities').magik,
__ = appc.i18n(__dirname).__;

const certRegExp = /^(?:((?:Apple|iOS) Development)|((?:iOS|Apple|iPhone) Distribution)): (.+)$/;

var cache = null,
watchers = {},
watchResults = null,
Expand Down Expand Up @@ -74,7 +76,7 @@ function detect(options, callback) {
return cb(results);
}

function parseCerts(src, dest, name) {
function parseCerts(src, dest, prefix) {
var p = 0,
q = src.indexOf('-----END'),
pem, cert, validity, expired, invalid, commonName;
Expand All @@ -85,11 +87,26 @@ function detect(options, callback) {
expired = cert.validity.notAfter < now,
invalid = expired || cert.validity.notBefore > now;
commonName = cert.subject.getField('CN').value;
let certName;

if (!prefix) {
const fullname = appc.encoding.decodeOctalUTF8(commonName);
if (fullname === 'Apple Worldwide Developer Relations Certification Authority') {
certName = commonName;
} else {
const match = fullname.match(certRegExp);
if (match) {
certName = match[3]
}
}
} else {
certName = appc.encoding.decodeOctalUTF8(commonName.substring(prefix.length)).trim();
}

if (!validOnly || !invalid) {
const teamId = cert.subject.attributes.find(attr => attr.name === 'organizationalUnitName');
dest.push({
name: appc.encoding.decodeOctalUTF8(name ? commonName.substring(name.length) : commonName).trim(),
name: certName,
fullname: appc.encoding.decodeOctalUTF8(commonName).trim(),
pem: pem,
before: cert.validity.notBefore,
Expand Down Expand Up @@ -131,29 +148,19 @@ function detect(options, callback) {

// find all the developer certificates in this keychain
tasks.push(function (next) {
appc.subprocess.run(env.executables.security, ['find-certificate', '-c', 'iOS Development:', '-a', '-p', keychain], function (code, out, err) {
if (!code) {
parseCerts(out, dest.developer, 'iOS Development:');
}
next();
});
});

// find all the distribution certificates in this keychain
tasks.push(function (next) {
appc.subprocess.run(env.executables.security, ['find-certificate', '-c', 'iPhone Distribution:', '-a', '-p', keychain], function (code, out, err) {
appc.subprocess.run(env.executables.security, ['find-certificate', '-c', 'Development:', '-a', '-p', keychain], function (code, out, err) {
if (!code) {
parseCerts(out, dest.distribution, 'iPhone Distribution:');
parseCerts(out, dest.developer);
}
next();
});
});

// find all the distribution certificates in this keychain
tasks.push(function (next) {
appc.subprocess.run(env.executables.security, ['find-certificate', '-c', 'iOS Distribution:', '-a', '-p', keychain], function (code, out, err) {
appc.subprocess.run(env.executables.security, ['find-certificate', '-c', 'Distribution:', '-a', '-p', keychain], function (code, out, err) {
if (!code) {
parseCerts(out, dest.distribution, 'iOS Distribution:');
parseCerts(out, dest.distribution);
}
next();
});
Expand Down