From cecb87de299ff1a8d8c1bec8d3bd9d40f50cb3a2 Mon Sep 17 00:00:00 2001 From: "Andrew Coates (REDMOND)" Date: Wed, 25 Mar 2020 15:46:31 -0700 Subject: [PATCH 1/4] Fix hang on react-native-init when run from a non-elevated prompt --- vnext/local-cli/generator-windows/index.js | 20 ++++++------------ .../templates/cpp/keys/MyApp_TemporaryKey.pfx | Bin 0 -> 2454 bytes 2 files changed, 7 insertions(+), 13 deletions(-) create mode 100644 vnext/local-cli/generator-windows/templates/cpp/keys/MyApp_TemporaryKey.pfx diff --git a/vnext/local-cli/generator-windows/index.js b/vnext/local-cli/generator-windows/index.js index 6b66a15a385..3a8e9ad70e1 100644 --- a/vnext/local-cli/generator-windows/index.js +++ b/vnext/local-cli/generator-windows/index.js @@ -20,20 +20,14 @@ function generateCertificate(srcPath, destPath, newProjectName, currentUser) { console.log('Generating self-signed certificate...'); let toCopyTempKey = false; if (os.platform() === 'win32') { - const certGenCommand = [ - `$cert = New-SelfSignedCertificate -KeyUsage DigitalSignature -KeyExportPolicy Exportable -Subject "CN=${currentUser}" -TextExtension @("2.5.29.37={text}1.3.6.1.5.5.7.3.3", "2.5.29.19={text}Subject Type:End Entity") -CertStoreLocation "Cert:\\CurrentUser\\My"`, - '$pwd = ConvertTo-SecureString -String password -Force -AsPlainText', - `New-Item -ErrorAction Ignore -ItemType directory -Path ${path.join(windowsDir, newProjectName)}`, - `Export-PfxCertificate -Cert "cert:\\CurrentUser\\My\\$($cert.Thumbprint)" -FilePath ${path.join(windowsDir, newProjectName, newProjectName)}_TemporaryKey.pfx -Password $pwd`, - '$cert.Thumbprint', - ]; - const certGenProcess = childProcess.spawnSync('powershell', ['-command', certGenCommand.join(';')]); - - if (certGenProcess.status === 0) { - const certGenProcessOutput = certGenProcess.stdout.toString().trim().split('\n'); + try { + const thumbprint = childProcess.execSync(`powershell -command "Write-Output (New-SelfSignedCertificate -KeyUsage DigitalSignature -KeyExportPolicy Exportable -Subject 'CN=${currentUser}' -TextExtension @('2.5.29.37={text}1.3.6.1.5.5.7.3.3', '2.5.29.19={text}Subject Type:End Entity') -CertStoreLocation 'Cert:\\CurrentUser\\My').Thumbprint"`); + const password = childProcess.execSync('powershell -command "Write-Output (ConvertTo-SecureString -String password -Force -AsPlainText).Thumbprint"'); + childProcess.execSync(`powershell -command "New-Item -ErrorAction Ignore -ItemType directory -Path ${path.join(windowsDir, newProjectName)}"`); + childProcess.execSync(`powershell -command "Export-PfxCertificate -Cert 'cert:\\CurrentUser\\My\\$(${thumbprint})' -FilePath ${path.join(windowsDir, newProjectName, newProjectName)}_TemporaryKey.pfx -Password ${password}"`); console.log(chalk.green('Self-signed certificate generated successfully.')); - return certGenProcessOutput[certGenProcessOutput.length - 1]; - } else { + return thumbprint; + } catch (err) { console.log(chalk.yellow('Failed to generate Self-signed certificate. Using Default Certificate. Use Visual Studio to renew it.')); toCopyTempKey = true; } diff --git a/vnext/local-cli/generator-windows/templates/cpp/keys/MyApp_TemporaryKey.pfx b/vnext/local-cli/generator-windows/templates/cpp/keys/MyApp_TemporaryKey.pfx new file mode 100644 index 0000000000000000000000000000000000000000..08328fc151890556883c49831ec0828a15428fd3 GIT binary patch literal 2454 zcmZuzc|25Y8$M??Mz%5`Tb3-*a%LJ^i0Bm&ib!^uv6g)aQO8!V<&~^SQ4z_QtP@i9 z@3Sw32qRmKQ1piB#dq|3zrMcT@BQOG=en-vxt{y^-RC*?IS`CbL4jxp#+%^qim?W< zt2`hFm^ug>&LQ#?5)-%`f4jK3KvXV_*@R#W8xq5D{Z~d7 z=f!Z^ABMW~qXD2`qXj2RyJ_Ff=3!Er<1s!Ft&TJ%yz&~56gQ^aS&eATB#JEo%S^~J+%3tYB3@3$cW^; zj&1fkoO!U^BkfkLEUDMNd7JmuygX#QxP}Bs|4tcYH`EoaBt*$52dDN;TdQOHJ9S(H ztE(fu6iwp}oac1;m)xu^K{b}hJxO6V1UC;SE@-!vVl7~lac$h2pk7JTv<8Lox ztfhLq6Q1Th9&fXQ2;N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mjo7SnOXBK9JCl@R&+PJ zTRBBK|K?@uac=hd1N}3ZP5QMOH2=z}X#D2jb3gUZhL_~olZC$SZ%WkOBql#PH{V8G zi@H7Zr&N2~c+V00CeiR)<{5)qd;0BESLr95P(C2;aH+S{<4*Az;nsnNbq4<8`8qbA z8hXN*nNzRt-cR?==|->n@N2zmtavdjzpE+YPf{T&R^4t!*Lb;kPpJ3!71?z5nXO`; z8;)HzC;N1JM4v}kd{Qf=;@_-nq}O7CBW3IzvJKS3=@K6m**;Y%=I5LBIV)pGS@C0x zM}lJKus#RAI-*;^1s2d>YfHB;ao4jW?*8W&UIW?-ap15@yl9jNhTz23wd!@OYgr)& nNPCnSM4V?T6k`a3;-OhqjT_LVqQ5eE$7EPLEF49)|B(IzfpaF1 literal 0 HcmV?d00001 From 70ef6b0c1ca8f3a8929739756f1983465bd4b53a Mon Sep 17 00:00:00 2001 From: "Andrew Coates (REDMOND)" Date: Wed, 25 Mar 2020 15:49:47 -0700 Subject: [PATCH 2/4] Change files --- ...ct-native-windows-2020-03-25-15-49-46-noadmininit.json | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 change/react-native-windows-2020-03-25-15-49-46-noadmininit.json diff --git a/change/react-native-windows-2020-03-25-15-49-46-noadmininit.json b/change/react-native-windows-2020-03-25-15-49-46-noadmininit.json new file mode 100644 index 00000000000..a837dc311dd --- /dev/null +++ b/change/react-native-windows-2020-03-25-15-49-46-noadmininit.json @@ -0,0 +1,8 @@ +{ + "type": "prerelease", + "comment": "Fix hang on react-native-init when run from a non-elevated prompt", + "packageName": "react-native-windows", + "email": "acoates@microsoft.com", + "dependentChangeType": "patch", + "date": "2020-03-25T22:49:46.943Z" +} \ No newline at end of file From f8e80cd996c26eba0c16c4b53e39e21b1b1d9ac8 Mon Sep 17 00:00:00 2001 From: "Andrew Coates (REDMOND)" Date: Wed, 25 Mar 2020 21:43:18 -0700 Subject: [PATCH 3/4] Fix cert creation --- vnext/.eslintignore | 1 - vnext/local-cli/generator-windows/index.js | 19 ++++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/vnext/.eslintignore b/vnext/.eslintignore index fe4ae497b63..e8f78012d7b 100644 --- a/vnext/.eslintignore +++ b/vnext/.eslintignore @@ -2,7 +2,6 @@ /flow /lib /Libraries -/local-cli/generator-windows/templates/index.windows.js **/node_modules /packages /ReactCopies diff --git a/vnext/local-cli/generator-windows/index.js b/vnext/local-cli/generator-windows/index.js index 3a8e9ad70e1..d1fe9b871e5 100644 --- a/vnext/local-cli/generator-windows/index.js +++ b/vnext/local-cli/generator-windows/index.js @@ -21,17 +21,18 @@ function generateCertificate(srcPath, destPath, newProjectName, currentUser) { let toCopyTempKey = false; if (os.platform() === 'win32') { try { - const thumbprint = childProcess.execSync(`powershell -command "Write-Output (New-SelfSignedCertificate -KeyUsage DigitalSignature -KeyExportPolicy Exportable -Subject 'CN=${currentUser}' -TextExtension @('2.5.29.37={text}1.3.6.1.5.5.7.3.3', '2.5.29.19={text}Subject Type:End Entity') -CertStoreLocation 'Cert:\\CurrentUser\\My').Thumbprint"`); - const password = childProcess.execSync('powershell -command "Write-Output (ConvertTo-SecureString -String password -Force -AsPlainText).Thumbprint"'); - childProcess.execSync(`powershell -command "New-Item -ErrorAction Ignore -ItemType directory -Path ${path.join(windowsDir, newProjectName)}"`); - childProcess.execSync(`powershell -command "Export-PfxCertificate -Cert 'cert:\\CurrentUser\\My\\$(${thumbprint})' -FilePath ${path.join(windowsDir, newProjectName, newProjectName)}_TemporaryKey.pfx -Password ${password}"`); + const thumbprint = childProcess.execSync(`powershell -command "Write-Output (New-SelfSignedCertificate -KeyUsage DigitalSignature -KeyExportPolicy Exportable -Subject 'CN=${currentUser}' -TextExtension @('2.5.29.37={text}1.3.6.1.5.5.7.3.3', '2.5.29.19={text}Subject Type:End Entity') -CertStoreLocation 'Cert:\\CurrentUser\\My').Thumbprint"`).toString().trim(); + if (!fs.existsSync(path.join(windowsDir, newProjectName))) { + fs.createDir(path.join(windowsDir, newProjectName)); + } + childProcess.execSync(`powershell -command "$pwd = (ConvertTo-SecureString -String password -Force -AsPlainText); Export-PfxCertificate -Cert 'cert:\\CurrentUser\\My\\${thumbprint}' -FilePath ${path.join(windowsDir, newProjectName, newProjectName)}_TemporaryKey.pfx -Password $pwd"`); console.log(chalk.green('Self-signed certificate generated successfully.')); return thumbprint; - } catch (err) { - console.log(chalk.yellow('Failed to generate Self-signed certificate. Using Default Certificate. Use Visual Studio to renew it.')); - toCopyTempKey = true; - } - } else { + } catch (err) { + console.log(chalk.yellow('Failed to generate Self-signed certificate. Using Default Certificate. Use Visual Studio to renew it.')); + toCopyTempKey = true; + } + } else { console.log(chalk.yellow('Using Default Certificate. Use Visual Studio to renew it.')); toCopyTempKey = true; } From a98380b4397338dc22a4a4a252de33883cfe36a5 Mon Sep 17 00:00:00 2001 From: "Andrew Coates (REDMOND)" Date: Wed, 25 Mar 2020 21:44:40 -0700 Subject: [PATCH 4/4] Add temp key for cs project --- .../templates/cs/keys/MyApp_TemporaryKey.pfx | Bin 0 -> 2454 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 vnext/local-cli/generator-windows/templates/cs/keys/MyApp_TemporaryKey.pfx diff --git a/vnext/local-cli/generator-windows/templates/cs/keys/MyApp_TemporaryKey.pfx b/vnext/local-cli/generator-windows/templates/cs/keys/MyApp_TemporaryKey.pfx new file mode 100644 index 0000000000000000000000000000000000000000..08328fc151890556883c49831ec0828a15428fd3 GIT binary patch literal 2454 zcmZuzc|25Y8$M??Mz%5`Tb3-*a%LJ^i0Bm&ib!^uv6g)aQO8!V<&~^SQ4z_QtP@i9 z@3Sw32qRmKQ1piB#dq|3zrMcT@BQOG=en-vxt{y^-RC*?IS`CbL4jxp#+%^qim?W< zt2`hFm^ug>&LQ#?5)-%`f4jK3KvXV_*@R#W8xq5D{Z~d7 z=f!Z^ABMW~qXD2`qXj2RyJ_Ff=3!Er<1s!Ft&TJ%yz&~56gQ^aS&eATB#JEo%S^~J+%3t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