From 390df577ae67e8693b225a68f4e0513474ba0b8f Mon Sep 17 00:00:00 2001 From: John Knox Date: Wed, 23 Sep 2020 08:37:45 -0700 Subject: [PATCH] Print out CSR mismatches when no matching one can be found Summary: We're seeing some CSR mismatches when they aren't expected. Adding logging to print out what is being found, to see if it's any OS-specific encoding issues or something like that, or completely different CSRs, etc. URL encoded in case there are differences in non printable characters. Reviewed By: nikoant Differential Revision: D23867267 fbshipit-source-id: f406a396c808687b6b84561eb1def61b565aee34 --- desktop/app/src/utils/CertificateProvider.tsx | 28 +++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/desktop/app/src/utils/CertificateProvider.tsx b/desktop/app/src/utils/CertificateProvider.tsx index 19beaf1c1..863d759eb 100644 --- a/desktop/app/src/utils/CertificateProvider.tsx +++ b/desktop/app/src/utils/CertificateProvider.tsx @@ -373,15 +373,15 @@ export default class CertificateProvider { appName, csr, ) - .then((isMatch) => { - return {id: device.id, isMatch, error: null}; + .then((result) => { + return {id: device.id, ...result, error: null}; }) .catch((e) => { console.error( `Unable to check for matching CSR in ${device.id}:${appName}`, logTag, ); - return {id: device.id, isMatch: false, error: e}; + return {id: device.id, isMatch: false, foundCsr: null, error: e}; }), ); return Promise.all(deviceMatchList).then((devices) => { @@ -391,6 +391,16 @@ export default class CertificateProvider { if (erroredDevice) { throw erroredDevice.error; } + const foundCsrs = devices + .filter((d) => d.foundCsr !== null) + .map((d) => (d.foundCsr ? encodeURI(d.foundCsr) : 'null')); + console.error(`Looking for CSR (url encoded): + + ${encodeURI(this.santitizeString(csr))} + + Found these: + + ${foundCsrs.join('\n\n')}`); throw new Error(`No matching device found for app: ${appName}`); } if (matchingIds.length > 1) { @@ -445,7 +455,7 @@ export default class CertificateProvider { deviceId: string, processName: string, csr: string, - ): Promise { + ): Promise<{isMatch: boolean; foundCsr: string}> { return this.adb .then((adbClient) => androidUtil.pull( @@ -458,10 +468,12 @@ export default class CertificateProvider { .then((deviceCsr) => { // Santitize both of the string before comparation // The csr string extraction on client side return string in both way - return ( - this.santitizeString(deviceCsr.toString()) === - this.santitizeString(csr) - ); + const [sanitizedDeviceCsr, sanitizedClientCsr] = [ + deviceCsr.toString(), + csr, + ].map((s) => this.santitizeString(s)); + const isMatch = sanitizedDeviceCsr === sanitizedClientCsr; + return {isMatch: isMatch, foundCsr: sanitizedDeviceCsr}; }); }