You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
161 lines
5.2 KiB
161 lines
5.2 KiB
"use strict";
|
|
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
exports.exportCertBase64 = exportCertBase64;
|
|
exports.generateUploadKeystore = generateUploadKeystore;
|
|
exports.logKeystoreHashes = logKeystoreHashes;
|
|
function _spawnAsync() {
|
|
const data = _interopRequireDefault(require("@expo/spawn-async"));
|
|
_spawnAsync = function () {
|
|
return data;
|
|
};
|
|
return data;
|
|
}
|
|
function _crypto() {
|
|
const data = _interopRequireDefault(require("crypto"));
|
|
_crypto = function () {
|
|
return data;
|
|
};
|
|
return data;
|
|
}
|
|
function _fsExtra() {
|
|
const data = _interopRequireDefault(require("fs-extra"));
|
|
_fsExtra = function () {
|
|
return data;
|
|
};
|
|
return data;
|
|
}
|
|
function _uuid() {
|
|
const data = require("uuid");
|
|
_uuid = function () {
|
|
return data;
|
|
};
|
|
return data;
|
|
}
|
|
function _internal() {
|
|
const data = require("../internal");
|
|
_internal = function () {
|
|
return data;
|
|
};
|
|
return data;
|
|
}
|
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
const log = _internal().Logger.global;
|
|
async function exportCertBinary({
|
|
keystorePath,
|
|
keystorePassword,
|
|
keyAlias
|
|
}, certFile) {
|
|
try {
|
|
return (0, _spawnAsync().default)('keytool', ['-exportcert', '-keystore', keystorePath, '-storepass', keystorePassword, '-alias', keyAlias, '-file', certFile, '-noprompt', '-storetype', 'JKS']);
|
|
} catch (err) {
|
|
if (err.code === 'ENOENT') {
|
|
log.warn('Are you sure you have keytool installed?');
|
|
log.info('keytool is a part of OpenJDK: https://openjdk.java.net/');
|
|
log.info('Also make sure that keytool is in your PATH after installation.');
|
|
}
|
|
if (err.stdout) {
|
|
log.info(err.stdout);
|
|
}
|
|
if (err.stderr) {
|
|
log.error(err.stderr);
|
|
}
|
|
throw err;
|
|
}
|
|
}
|
|
async function exportCertBase64({
|
|
keystorePath,
|
|
keystorePassword,
|
|
keyAlias
|
|
}, certFile) {
|
|
try {
|
|
return (0, _spawnAsync().default)('keytool', ['-export', '-rfc', '-keystore', keystorePath, '-storepass', keystorePassword, '-alias', keyAlias, '-file', certFile, '-noprompt', '-storetype', 'JKS']);
|
|
} catch (err) {
|
|
if (err.code === 'ENOENT') {
|
|
log.warn('Are you sure you have keytool installed?');
|
|
log.info('keytool is a part of OpenJDK: https://openjdk.java.net/');
|
|
log.info('Also make sure that keytool is in your PATH after installation.');
|
|
}
|
|
if (err.stdout) {
|
|
log.info(err.stdout);
|
|
}
|
|
if (err.stderr) {
|
|
log.error(err.stderr);
|
|
}
|
|
throw err;
|
|
}
|
|
}
|
|
async function logKeystoreHashes(keystoreInfo, linePrefix = '') {
|
|
const {
|
|
keystorePath
|
|
} = keystoreInfo;
|
|
const certFile = `${keystorePath}.cer`;
|
|
try {
|
|
await exportCertBinary(keystoreInfo, certFile);
|
|
const data = await _fsExtra().default.readFile(certFile);
|
|
const googleHash = _crypto().default.createHash('sha1').update(data).digest('hex').toUpperCase();
|
|
const googleHash256 = _crypto().default.createHash('sha256').update(data).digest('hex').toUpperCase();
|
|
const fbHash = _crypto().default.createHash('sha1').update(data).digest('base64');
|
|
log.info(`${linePrefix}Google Certificate Fingerprint: ${googleHash.replace(/(.{2}(?!$))/g, '$1:')}`);
|
|
log.info(`${linePrefix}Google Certificate Hash (SHA-1): ${googleHash}`);
|
|
log.info(`${linePrefix}Google Certificate Hash (SHA-256): ${googleHash256}`);
|
|
log.info(`${linePrefix}Facebook Key Hash: ${fbHash}`);
|
|
} catch (err) {
|
|
if (err.code === 'ENOENT') {
|
|
log.warn('Are you sure you have keytool installed?');
|
|
log.info('keytool is a part of OpenJDK: https://openjdk.java.net/');
|
|
log.info('Also make sure that keytool is in your PATH after installation.');
|
|
}
|
|
if (err.stdout) {
|
|
log.info(err.stdout);
|
|
}
|
|
if (err.stderr) {
|
|
log.error(err.stderr);
|
|
}
|
|
throw err;
|
|
} finally {
|
|
try {
|
|
await _fsExtra().default.unlink(certFile);
|
|
} catch (err) {
|
|
if (err.code !== 'ENOENT') {
|
|
log.error(err);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
async function createKeystore({
|
|
keystorePath,
|
|
keystorePassword,
|
|
keyAlias,
|
|
keyPassword
|
|
}, androidPackage) {
|
|
try {
|
|
return await (0, _spawnAsync().default)('keytool', ['-genkey', '-v', '-storetype', 'JKS', '-storepass', keystorePassword, '-keypass', keyPassword, '-keystore', keystorePath, '-alias', keyAlias, '-keyalg', 'RSA', '-keysize', '2048', '-validity', '10000', '-dname', `CN=${androidPackage},OU=,O=,L=,S=,C=US`]);
|
|
} catch (err) {
|
|
if (err.code === 'ENOENT') {
|
|
log.warn('Are you sure you have keytool installed?');
|
|
log.info('keytool is a part of OpenJDK: https://openjdk.java.net/');
|
|
log.info('Also make sure that keytool is in your PATH after installation.');
|
|
}
|
|
if (err.stdout) {
|
|
log.info(err.stdout);
|
|
}
|
|
if (err.stderr) {
|
|
log.error(err.stderr);
|
|
}
|
|
throw err;
|
|
}
|
|
}
|
|
async function generateUploadKeystore(uploadKeystorePath, androidPackage, experienceName) {
|
|
const keystoreData = {
|
|
keystorePassword: (0, _uuid().v4)().replace(/-/g, ''),
|
|
keyPassword: (0, _uuid().v4)().replace(/-/g, ''),
|
|
keyAlias: Buffer.from(experienceName).toString('base64'),
|
|
keystorePath: uploadKeystorePath
|
|
};
|
|
await createKeystore(keystoreData, androidPackage);
|
|
return keystoreData;
|
|
}
|
|
//# sourceMappingURL=AndroidCredentials.js.map
|