Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
adjustEntitlements (file, entMobProv, next) {
const teamId = entMobProv['com.apple.developer.team-identifier'];
const appId = entMobProv['application-identifier'];
/* TODO: check if this supports binary plist too */
let ent = machoEntitlements.parseFile(file);
if (ent === null) {
console.error('Cannot find entitlements in binary. Using defaults');
ent = defaultEntitlements(appId, teamId);
// return next();
}
let entMacho = plist.parse(ent.toString().trim());
if (this.config.selfSignedProvision) { /* */
this.emit('message', 'Using an unsigned provisioning');
const newEntitlementsFile = file + '.entitlements';
const newEntitlements = plistBuild(entMacho).toString();
fs.writeFileSync(newEntitlementsFile, newEntitlements);
this.config.entitlement = newEntitlementsFile;
return next();
}
let changed = false;
if (this.config.cloneEntitlements) {
this.emit('message', 'Cloning entitlements');
entMacho = entMobProv;
changed = true;
} else {
const k = 'com.apple.developer.icloud-container-identifiers';
if (entMacho[k]) {
return tools.getMobileProvisionPlist(this.config.mobileprovision, (err, data) => {
if (err) {
return next(err);
}
const mainBin = path.join(this.config.appdir, getExecutable(this.config.appdir));
let ent = machoEntitlements.parseFile(mainBin);
if (ent === null) {
console.error('Cannot find entitlements in binary. Using defaults');
const entMobProv = data['Entitlements'];
const teamId = entMobProv['com.apple.developer.team-identifier'];
const appId = entMobProv['application-identifier'];
ent = defaultEntitlements(appId, teamId);
}
data['Entitlements'] = plist.parse(ent.toString().trim());
fs.writeFileSync(mobileProvision, plistBuild(data).toString());
/* TODO: self-sign mobile provisioning */
next();
});
}
async function getMobileProvisionPlist (file) {
var res;
if (file === undefined) {
throw new Error('No mobile provisioning file available.');
}
if (useOpenSSL === true) {
/* portable using openssl */
const args = [ 'cms', '-in', file, '-inform', 'der', '-verify' ];
res = await execProgram(cmd.openssl, args, null);
} else {
/* OSX specific using security */
const args = [ 'cms', '-D', '-i', file ];
res = await execProgram(cmd.security, args, null);
}
return plist.parse(res.stdout);
}
adjustEntitlementsSync (file, entMobProv) {
fchk(arguments, ['string', 'object']);
const teamId = entMobProv['com.apple.developer.team-identifier'];
const appId = entMobProv['application-identifier'];
let ent = bin.entitlements(file);
if (ent === null) {
console.error('Cannot find entitlements in binary. Using defaults');
ent = defaultEntitlements(appId, teamId);
}
let entMacho = plist.parse(ent.toString().trim());
if (this.config.selfSignedProvision) {
this.emit('message', 'Using an unsigned provisioning');
const newEntitlementsFile = file + '.entitlements';
const newEntitlements = plistBuild(entMacho).toString();
fs.writeFileSync(newEntitlementsFile, newEntitlements);
this.config.entitlement = newEntitlementsFile;
return;
}
let changed = false;
if (this.config.cloneEntitlements) {
this.emit('message', 'Cloning entitlements');
entMacho = entMobProv;
changed = true;
} else {
const k = 'com.apple.developer.icloud-container-identifiers';
if (entMacho[k]) {
private getMobileProvisionData(provisionPath: string): IMobileProvisionData {
const provisionText = this.$fs.readText(path.resolve(provisionPath));
const provisionPlistText = provisionText.substring(provisionText.indexOf(constants.CRYPTO.PLIST_HEADER), provisionText.indexOf(constants.CRYPTO.PLIST_FOOTER) + constants.CRYPTO.PLIST_FOOTER.length);
return plist.parse(provisionPlistText);
}
} else {
provisionPath = provisionName;
}
let absolutePath = path.resolve(path.join(tempDir, provisionPath));
const exists = await fse.pathExists(absolutePath);
if (!exists) {
throw new ExtractError('provisioning file in filelist, but not on disk');
}
const data = await fse.readFile(absolutePath, "utf8");
provision.absolutePath = absolutePath;
await this.persistFile(provision, 'absolutePath');
provision.mobileProvisionFileContent = data;
const start = data.indexOf(Constants.PROVISION_START);
const end = data.indexOf(Constants.PROVISION_END) + Constants.PROVISION_END.length;
const goodData = data.substring(start, end);
const provisionData = plist.parse(goodData);
return provisionData;
}
private mapProvision(provision: ProvisioningProfile, provisionData: any) {
public getMobileProvisionData(provisionPath: string): IMobileProvisionData {
const provisionText = this.$fs.readText(path.resolve(provisionPath));
const provisionPlistText = provisionText.substring(provisionText.indexOf(constants.CRYPTO.PLIST_HEADER), provisionText.indexOf(constants.CRYPTO.PLIST_FOOTER) + constants.CRYPTO.PLIST_FOOTER.length);
return plist.parse(provisionPlistText);
}
function defaultEntitlements (appid, devid) {
const ent = plist.parse(entitlementTemplate.trim());
ent['application-identifier'] = appid;
ent['com.apple.developer.team-identifier'] = devid;
ent['keychain-access-groups'] = [ appid ];
ent['com.apple.developer.ubiquity-kvstore-identifier'] = appid;
delete ent['aps-environment'];
ent['com.apple.developer.icloud-container-identifiers'] = 'iCloud.' + devid;
return plistBuild(ent).toString();
}