Created
March 6, 2015 23:33
-
-
Save lgarner/386226ab19e7022a0e9a to your computer and use it in GitHub Desktop.
FirefoxOS, getting a certificate for an app.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
getCertificate: function getCertificate(aManifestURL) { | |
let manifestURL = "app://system.gaiamobile.org/manifest.webapp"; // change. | |
Cu.import("resource://gre/modules/FileUtils.jsm"); | |
Cu.import("resource://gre/modules/NetUtil.jsm"); | |
XPCOMUtils.defineLazyServiceGetter(this, "appsService", | |
"@mozilla.org/AppsService;1", | |
"nsIAppsService"); | |
let app = appsService.getAppByManifestURL(manifestURL); | |
if (!app) { | |
debug("ZZZ: Missing app"); | |
return false; | |
} | |
let appDir = null; | |
// Pre-installed apps (if Non-engr builds): | |
appDir = FileUtils.getDir("coreAppsDir", ["webapps", app.id], false, true); | |
if (!appDir.exists()) { | |
// Privilaged apps: | |
appDir = FileUtils.getDir("webappsDir", ["webapps", app.id], false, true); | |
} | |
// Since the app is supposed to be installed, this might work: | |
// appDir = FileUtils.initWithPath(app.basePath); | |
// appDir.append(app.id); | |
let appPackage = appDir.clone(); | |
appPackage.append("application.zip"); | |
if (appPackage.exists()) { | |
debug("ZZZ: object good."); | |
} else { | |
debug("ZZZ: object bad."); | |
} | |
let zipReader = Cc["@mozilla.org/libjar/zip-reader;1"] | |
.createInstance(Ci.nsIZipReader); | |
zipReader.open(appPackage); | |
debug('has file: ' + zipReader.hasEntry("dev_cert.cer")); | |
let devCertStream = zipReader.getInputStream("dev_cert.cer"); | |
let devCert = NetUtil.readInputStreamToString(devCertStream, devCertStream.available()); | |
devCertStream.close(); | |
debug("Dev cert: " + devCert); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment