Skip to content

Instantly share code, notes, and snippets.

@marcsolanadal
Created January 14, 2016 09:41
Show Gist options
  • Save marcsolanadal/ea4b80ecc6866e482e18 to your computer and use it in GitHub Desktop.
Save marcsolanadal/ea4b80ecc6866e482e18 to your computer and use it in GitHub Desktop.
utils.validateKeystore = function (path, keystore, passwd, alias) {
if (typeof path === 'undefined') {
path = ".";
}
var deferred = Q.defer();
// check file extension
if (keystore.indexOf(".keystore") == -1) {
keystore += ".keystore";
}
// check if file exists
if (!fs.existsSync(path + '/' + keystore)) {
console.error("Keystore " + keystore + " not found");
deferred.reject("Keystore " + keystore + " not found");
}
var proc = spawn('keytool', [
'-list',
'-keystore',
path + '/' + keystore,
'-alias',
alias,
'-storepass',
passwd,
'-v'
]);
var grepCommand = spawn('egrep', ['Alias|Valid|Válido']);
var result = "";
proc.stdout.pipe(grepCommand.stdin);
grepCommand.stdout.on('data', function (data) {
//console.log('' + data);
result += data;
});
grepCommand.stderr.on('data', function (data) {
console.log('grep stderr: ' + data);
});
grepCommand.on('close', function (code) {
if (code === 0) {
var dateFinish = result.replace(/([^]*)(hasta: )([^\n]*)(\n)([^]*)/gm, "$3");
console.log("DATE: " + dateFinish);
console.log("keystore is valid");
deferred.resolve();
} else {
console.error("Error validating keystore");
deferred.reject("Error validating keystore");
}
});
grepCommand.on('error', function (error) {
console.log("ERROR:" + error);
deferred.reject("ERROR:" + error);
});
return deferred.promise;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment