Fix lints in CertificateProvider
Summary:
Some of them got re-introduced after rebasing D30411434 (f60429cab5).
Soz for not checking the rebase result carefully enough.
Reviewed By: mweststrate
Differential Revision: D30450602
fbshipit-source-id: 6c45422f7f9e34419949cec936ffffbdf1c652a4
This commit is contained in:
committed by
Facebook GitHub Bot
parent
e5404d2af3
commit
30d5170dee
@@ -11,8 +11,7 @@ import {Logger} from '../../fb-interfaces/Logger';
|
|||||||
import {internGraphPOSTAPIRequest} from '../../fb-stubs/user';
|
import {internGraphPOSTAPIRequest} from '../../fb-stubs/user';
|
||||||
import ServerController from '../comms/ServerController';
|
import ServerController from '../comms/ServerController';
|
||||||
import {promisify} from 'util';
|
import {promisify} from 'util';
|
||||||
import fs from 'fs';
|
import fs from 'fs-extra';
|
||||||
import fsExtra from 'fs-extra';
|
|
||||||
|
|
||||||
import {
|
import {
|
||||||
openssl,
|
openssl,
|
||||||
@@ -120,7 +119,7 @@ export default class CertificateProvider {
|
|||||||
zipPath: string,
|
zipPath: string,
|
||||||
deviceID: string,
|
deviceID: string,
|
||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
const buff = await fsExtra.readFile(zipPath);
|
const buff = await fs.readFile(zipPath);
|
||||||
const file = new File([buff], 'certs.zip');
|
const file = new File([buff], 'certs.zip');
|
||||||
return reportPlatformFailures(
|
return reportPlatformFailures(
|
||||||
timeout(
|
timeout(
|
||||||
@@ -187,7 +186,7 @@ export default class CertificateProvider {
|
|||||||
.then(async (deviceId) => {
|
.then(async (deviceId) => {
|
||||||
if (medium === 'WWW') {
|
if (medium === 'WWW') {
|
||||||
const zipPromise = new Promise((resolve, reject) => {
|
const zipPromise = new Promise((resolve, reject) => {
|
||||||
const output = fsExtra.createWriteStream(certsZipPath);
|
const output = fs.createWriteStream(certsZipPath);
|
||||||
const archive = archiver('zip', {
|
const archive = archiver('zip', {
|
||||||
zlib: {level: 9}, // Sets the compression level.
|
zlib: {level: 9}, // Sets the compression level.
|
||||||
});
|
});
|
||||||
@@ -242,15 +241,7 @@ export default class CertificateProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private getCACertificate(): Promise<string> {
|
private getCACertificate(): Promise<string> {
|
||||||
return new Promise((resolve, reject) => {
|
return fs.readFile(caCert, 'utf-8');
|
||||||
fs.readFile(caCert, (err, data) => {
|
|
||||||
if (err) {
|
|
||||||
reject(err);
|
|
||||||
} else {
|
|
||||||
resolve(data.toString());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private generateClientCertificate(csr: string): Promise<string> {
|
private generateClientCertificate(csr: string): Promise<string> {
|
||||||
@@ -288,11 +279,11 @@ export default class CertificateProvider {
|
|||||||
const appNamePromise = this.extractAppNameFromCSR(csr);
|
const appNamePromise = this.extractAppNameFromCSR(csr);
|
||||||
|
|
||||||
if (medium === 'WWW') {
|
if (medium === 'WWW') {
|
||||||
const certPathExists = await fsExtra.pathExists(certFolder);
|
const certPathExists = await fs.pathExists(certFolder);
|
||||||
if (!certPathExists) {
|
if (!certPathExists) {
|
||||||
await fsExtra.mkdir(certFolder);
|
await fs.mkdir(certFolder);
|
||||||
}
|
}
|
||||||
return fsExtra.writeFile(certFolder + filename, contents).catch((e) => {
|
return fs.writeFile(certFolder + filename, contents).catch((e) => {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Failed to write ${filename} to temporary folder. Error: ${e}`,
|
`Failed to write ${filename} to temporary folder. Error: ${e}`,
|
||||||
);
|
);
|
||||||
@@ -315,7 +306,7 @@ export default class CertificateProvider {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (os === 'iOS' || os === 'windows' || os == 'MacOS') {
|
if (os === 'iOS' || os === 'windows' || os == 'MacOS') {
|
||||||
return fsExtra
|
return fs
|
||||||
.writeFile(destination + filename, contents)
|
.writeFile(destination + filename, contents)
|
||||||
.catch(async (err) => {
|
.catch(async (err) => {
|
||||||
if (os === 'iOS') {
|
if (os === 'iOS') {
|
||||||
@@ -354,7 +345,7 @@ export default class CertificateProvider {
|
|||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const dir = await tmpDir({unsafeCleanup: true});
|
const dir = await tmpDir({unsafeCleanup: true});
|
||||||
const filePath = path.resolve(dir, filename);
|
const filePath = path.resolve(dir, filename);
|
||||||
await fsExtra.writeFile(filePath, contents);
|
await fs.writeFile(filePath, contents);
|
||||||
return await iosUtil.push(
|
return await iosUtil.push(
|
||||||
udid,
|
udid,
|
||||||
filePath,
|
filePath,
|
||||||
@@ -508,7 +499,7 @@ export default class CertificateProvider {
|
|||||||
.then(() => dir);
|
.then(() => dir);
|
||||||
})
|
})
|
||||||
.then((dir) => {
|
.then((dir) => {
|
||||||
return fsExtra
|
return fs
|
||||||
.readdir(dir)
|
.readdir(dir)
|
||||||
.then((items) => {
|
.then((items) => {
|
||||||
if (items.length > 1) {
|
if (items.length > 1) {
|
||||||
@@ -521,7 +512,7 @@ export default class CertificateProvider {
|
|||||||
})
|
})
|
||||||
.then((fileName) => {
|
.then((fileName) => {
|
||||||
const copiedFile = path.resolve(dir, fileName);
|
const copiedFile = path.resolve(dir, fileName);
|
||||||
return fsExtra
|
return fs
|
||||||
.readFile(copiedFile)
|
.readFile(copiedFile)
|
||||||
.then((data) => this.santitizeString(data.toString()));
|
.then((data) => this.santitizeString(data.toString()));
|
||||||
});
|
});
|
||||||
@@ -546,16 +537,9 @@ export default class CertificateProvider {
|
|||||||
return [path, subject];
|
return [path, subject];
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
.then(([path, subject]) => {
|
.then(async ([path, subject]) => {
|
||||||
return new Promise<string>(function (resolve, reject) {
|
await fs.unlink(path);
|
||||||
fs.unlink(path, (err) => {
|
return subject;
|
||||||
if (err) {
|
|
||||||
reject(err);
|
|
||||||
} else {
|
|
||||||
resolve(subject);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
})
|
})
|
||||||
.then((subject) => {
|
.then((subject) => {
|
||||||
const matches = subject.trim().match(x509SubjectCNRegex);
|
const matches = subject.trim().match(x509SubjectCNRegex);
|
||||||
@@ -577,16 +561,16 @@ export default class CertificateProvider {
|
|||||||
async loadSecureServerConfig(): Promise<SecureServerConfig> {
|
async loadSecureServerConfig(): Promise<SecureServerConfig> {
|
||||||
await this.certificateSetup;
|
await this.certificateSetup;
|
||||||
return {
|
return {
|
||||||
key: await fsExtra.readFile(serverKey),
|
key: await fs.readFile(serverKey),
|
||||||
cert: await fsExtra.readFile(serverCert),
|
cert: await fs.readFile(serverCert),
|
||||||
ca: await fsExtra.readFile(caCert),
|
ca: await fs.readFile(caCert),
|
||||||
requestCert: true,
|
requestCert: true,
|
||||||
rejectUnauthorized: true, // can be false if necessary as we don't strictly need to verify the client
|
rejectUnauthorized: true, // can be false if necessary as we don't strictly need to verify the client
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
async ensureCertificateAuthorityExists(): Promise<void> {
|
async ensureCertificateAuthorityExists(): Promise<void> {
|
||||||
if (!(await fsExtra.pathExists(caKey))) {
|
if (!(await fs.pathExists(caKey))) {
|
||||||
return this.generateCertificateAuthority();
|
return this.generateCertificateAuthority();
|
||||||
}
|
}
|
||||||
return this.checkCertIsValid(caCert).catch(() =>
|
return this.checkCertIsValid(caCert).catch(() =>
|
||||||
@@ -595,7 +579,7 @@ export default class CertificateProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async checkCertIsValid(filename: string): Promise<void> {
|
private async checkCertIsValid(filename: string): Promise<void> {
|
||||||
if (!(await fsExtra.pathExists(filename))) {
|
if (!(await fs.pathExists(filename))) {
|
||||||
return Promise.reject(new Error(`${filename} does not exist`));
|
return Promise.reject(new Error(`${filename} does not exist`));
|
||||||
}
|
}
|
||||||
// openssl checkend is a nice feature but it only checks for certificates
|
// openssl checkend is a nice feature but it only checks for certificates
|
||||||
@@ -652,8 +636,8 @@ export default class CertificateProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async generateCertificateAuthority(): Promise<void> {
|
private async generateCertificateAuthority(): Promise<void> {
|
||||||
if (!(await fsExtra.pathExists(getFilePath('')))) {
|
if (!(await fs.pathExists(getFilePath('')))) {
|
||||||
await fsExtra.mkdir(getFilePath(''));
|
await fs.mkdir(getFilePath(''));
|
||||||
}
|
}
|
||||||
console.log('Generating new CA', logTag);
|
console.log('Generating new CA', logTag);
|
||||||
return openssl('genrsa', {out: caKey, '2048': false})
|
return openssl('genrsa', {out: caKey, '2048': false})
|
||||||
@@ -671,9 +655,9 @@ export default class CertificateProvider {
|
|||||||
|
|
||||||
private async ensureServerCertExists(): Promise<void> {
|
private async ensureServerCertExists(): Promise<void> {
|
||||||
const allExist = Promise.all([
|
const allExist = Promise.all([
|
||||||
fsExtra.existsSync(serverKey),
|
fs.pathExists(serverKey),
|
||||||
fsExtra.existsSync(serverCert),
|
fs.pathExists(serverCert),
|
||||||
fsExtra.existsSync(caCert),
|
fs.pathExists(caCert),
|
||||||
]).then((exist) => exist.every(Boolean));
|
]).then((exist) => exist.every(Boolean));
|
||||||
if (!allExist) {
|
if (!allExist) {
|
||||||
return this.generateServerCertificate();
|
return this.generateServerCertificate();
|
||||||
@@ -714,7 +698,7 @@ export default class CertificateProvider {
|
|||||||
|
|
||||||
private writeToTempFile(content: string): Promise<string> {
|
private writeToTempFile(content: string): Promise<string> {
|
||||||
return tmpFile().then((path) =>
|
return tmpFile().then((path) =>
|
||||||
fsExtra.writeFile(path, content).then((_) => path),
|
fs.writeFile(path, content).then((_) => path),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user