diff options
author | Matt Ward <matt.ward@microsoft.com> | 2018-02-22 16:42:02 +0300 |
---|---|---|
committer | Matt Ward <matt.ward@microsoft.com> | 2018-02-22 16:42:02 +0300 |
commit | e9a2e2a60561de7d6ba5edd6245856d678486075 (patch) | |
tree | 7ed9313ced850b6aa90d337fb9ddd1ea9f6611b1 /main/src | |
parent | 3d236595dfad92c4a2dbe9665047e4b30c362fb8 (diff) |
[AspNetCore] Remove dev-certs helper console app
Use a single console app to request credentials and then call itself
with a different argument so it then runs dotnet dev-certs after
changing the user id to 0.
Diffstat (limited to 'main/src')
5 files changed, 31 insertions, 176 deletions
diff --git a/main/src/addins/MonoDevelop.AspNetCore/MonoDevelop.AspNetCore.DevCertInstaller/Program.cs b/main/src/addins/MonoDevelop.AspNetCore/MonoDevelop.AspNetCore.DevCertInstaller/Program.cs index afab88da95..2fd5bae955 100644 --- a/main/src/addins/MonoDevelop.AspNetCore/MonoDevelop.AspNetCore.DevCertInstaller/Program.cs +++ b/main/src/addins/MonoDevelop.AspNetCore/MonoDevelop.AspNetCore.DevCertInstaller/Program.cs @@ -25,6 +25,7 @@ // THE SOFTWARE. using System; +using System.Diagnostics; using System.IO; using Mono.Unix.Native; using Security; @@ -36,17 +37,17 @@ namespace MonoDevelop.AspNetCore.DevCertInstaller public static int Main (string[] args) { try { - string dotNetCorePath = null; - string monoPath = null; - if (args.Length > 1) { - dotNetCorePath = args [0]; - monoPath = args [1]; - } else { + if (args.Length < 2) { Console.WriteLine ("Arguments missing."); return -4; } - return Run (monoPath, dotNetCorePath); + if (args [0] == "--setuid") { + return RunDotNetDevCerts (args [1]); + } else { + return Run (args [0], args [1]); + } + } catch (Exception ex) { Console.WriteLine (ex.Message); return -2; @@ -61,11 +62,10 @@ namespace MonoDevelop.AspNetCore.DevCertInstaller /// console application is run which calls setuid to change the user id to 0 /// and then runs the dotnet dev-certs. /// </summary> - static int Run (string monoPath, string dotNetCorePath) + static int Run (string dotNetCorePath, string monoPath) { - var directory = Path.GetDirectoryName (typeof (MainClass).Assembly.Location); - var fileName = Path.Combine (directory, "MonoDevelop.AspNetCore.DevCertWrapper.exe"); - var args = new [] { fileName, dotNetCorePath }; + var fileName = typeof (MainClass).Assembly.Location; + var args = new [] { fileName, "--setuid", dotNetCorePath }; var flags = AuthorizationFlags.ExtendRights | AuthorizationFlags.InteractionAllowed | @@ -105,5 +105,19 @@ namespace MonoDevelop.AspNetCore.DevCertInstaller return exitCode; } } + + static int RunDotNetDevCerts (string dotNetCorePath) + { + int result = Syscall.setuid (0); + if (result != 0) { + Console.WriteLine ("Unable to set user id to root."); + return -3; + } + + using (var process = Process.Start (dotNetCorePath, "dev-certs https --trust")) { + process.WaitForExit (); + return process.ExitCode; + } + } } } diff --git a/main/src/addins/MonoDevelop.AspNetCore/MonoDevelop.AspNetCore.DevCertWrapper/MonoDevelop.AspNetCore.DevCertWrapper.csproj b/main/src/addins/MonoDevelop.AspNetCore/MonoDevelop.AspNetCore.DevCertWrapper/MonoDevelop.AspNetCore.DevCertWrapper.csproj deleted file mode 100644 index b0497f2761..0000000000 --- a/main/src/addins/MonoDevelop.AspNetCore/MonoDevelop.AspNetCore.DevCertWrapper/MonoDevelop.AspNetCore.DevCertWrapper.csproj +++ /dev/null @@ -1,40 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> - <PropertyGroup> - <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> - <Platform Condition=" '$(Platform)' == '' ">x64</Platform> - <ProjectGuid>{4DB8621C-B80A-468D-839A-1647D631C693}</ProjectGuid> - <OutputType>Exe</OutputType> - <RootNamespace>MonoDevelop.AspNetCore.DevCertWrapper</RootNamespace> - <AssemblyName>MonoDevelop.AspNetCore.DevCertWrapper</AssemblyName> - <TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion> - </PropertyGroup> - <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' "> - <DebugSymbols>true</DebugSymbols> - <DebugType>full</DebugType> - <Optimize>false</Optimize> - <OutputPath>..\..\..\..\build\bin</OutputPath> - <DefineConstants>DEBUG;</DefineConstants> - <ErrorReport>prompt</ErrorReport> - <WarningLevel>4</WarningLevel> - <ExternalConsole>true</ExternalConsole> - <PlatformTarget>x64</PlatformTarget> - </PropertyGroup> - <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' "> - <Optimize>true</Optimize> - <OutputPath>..\..\..\..\build\bin</OutputPath> - <ErrorReport>prompt</ErrorReport> - <WarningLevel>4</WarningLevel> - <ExternalConsole>true</ExternalConsole> - <PlatformTarget>x64</PlatformTarget> - </PropertyGroup> - <ItemGroup> - <Reference Include="System" /> - <Reference Include="Mono.Posix" /> - </ItemGroup> - <ItemGroup> - <Compile Include="Program.cs" /> - <Compile Include="Properties\AssemblyInfo.cs" /> - </ItemGroup> - <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> -</Project>
\ No newline at end of file diff --git a/main/src/addins/MonoDevelop.AspNetCore/MonoDevelop.AspNetCore.DevCertWrapper/Program.cs b/main/src/addins/MonoDevelop.AspNetCore/MonoDevelop.AspNetCore.DevCertWrapper/Program.cs deleted file mode 100644 index 3be9b5d518..0000000000 --- a/main/src/addins/MonoDevelop.AspNetCore/MonoDevelop.AspNetCore.DevCertWrapper/Program.cs +++ /dev/null @@ -1,68 +0,0 @@ -// -// Program.cs -// -// Author: -// Matt Ward <matt.ward@microsoft.com> -// -// Copyright (c) 2018 Microsoft -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - -using System; -using Mono.Unix.Native; -using System.Diagnostics; - -namespace MonoDevelop.AspNetCore.DevCertWrapper -{ - class MainClass - { - public static int Main (string[] args) - { - try { - string dotNetCorePath = ParseArguments (args); - return Run (dotNetCorePath); - } catch (Exception ex) { - Console.WriteLine (ex.Message); - return -2; - } - } - - static string ParseArguments (string[] args) - { - if (args.Length > 0) { - return args [0]; - } - throw new InvalidOperationException ("Argument missing: Path to .NET Core runtime"); - } - - static int Run (string dotNetCorePath) - { - int result = Syscall.setuid (0); - if (result != 0) { - Console.WriteLine ("Unable to set user id to root."); - return -3; - } - - using (var process = Process.Start (dotNetCorePath, "dev-certs https --trust")) { - process.WaitForExit (); - return process.ExitCode; - } - } - } -} diff --git a/main/src/addins/MonoDevelop.AspNetCore/MonoDevelop.AspNetCore.DevCertWrapper/Properties/AssemblyInfo.cs b/main/src/addins/MonoDevelop.AspNetCore/MonoDevelop.AspNetCore.DevCertWrapper/Properties/AssemblyInfo.cs deleted file mode 100644 index 7965f2c54e..0000000000 --- a/main/src/addins/MonoDevelop.AspNetCore/MonoDevelop.AspNetCore.DevCertWrapper/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,51 +0,0 @@ -// -// AssemblyInfo.cs -// -// Author: -// Matt Ward <matt.ward@microsoft.com> -// -// Copyright (c) 2018 Microsoft -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. -using System.Reflection; -using System.Runtime.CompilerServices; - -// Information about this assembly is defined by the following attributes. -// Change them to the values specific to your project. - -[assembly: AssemblyTitle ("MonoDevelop.AspNetCore.DevCertWrapper")] -[assembly: AssemblyDescription ("")] -[assembly: AssemblyConfiguration ("")] -[assembly: AssemblyCompany ("")] -[assembly: AssemblyProduct ("")] -[assembly: AssemblyCopyright ("Microsoft")] -[assembly: AssemblyTrademark ("")] -[assembly: AssemblyCulture ("")] - -// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". -// The form "{Major}.{Minor}.*" will automatically update the build and revision, -// and "{Major}.{Minor}.{Build}.*" will update just the revision. - -[assembly: AssemblyVersion ("1.0.0")] - -// The following attributes are used to specify the signing key for the assembly, -// if desired. See the Mono documentation for more information about signing. - -//[assembly: AssemblyDelaySign(false)] -//[assembly: AssemblyKeyFile("")] diff --git a/main/src/addins/MonoDevelop.AspNetCore/MonoDevelop.AspNetCore/DotNetCoreDevCertsTool.cs b/main/src/addins/MonoDevelop.AspNetCore/MonoDevelop.AspNetCore/DotNetCoreDevCertsTool.cs index 22128e7c1d..a7a2122033 100644 --- a/main/src/addins/MonoDevelop.AspNetCore/MonoDevelop.AspNetCore/DotNetCoreDevCertsTool.cs +++ b/main/src/addins/MonoDevelop.AspNetCore/MonoDevelop.AspNetCore/DotNetCoreDevCertsTool.cs @@ -198,12 +198,12 @@ namespace MonoDevelop.AspNetCore var monoRuntime = Runtime.SystemAssemblyService.DefaultRuntime as MonoTargetRuntime; string monoPath = monoRuntime.GetMonoExecutableForAssembly (installerPath); - string arguments = $"\"{installerPath}\" \"{DotNetCoreRuntime.FileName}\" \"{monoPath}\""; - var command = new NativeExecutionCommand (monoPath, arguments); - - var executionHandler = Runtime.ProcessService.GetDefaultExecutionHandler (command); - - var process = executionHandler.Execute (command, progressMonitor.Console); + var process = Runtime.ProcessService.StartConsoleProcess ( + monoPath, + $"\"{installerPath}\" \"{DotNetCoreRuntime.FileName}\" \"{monoPath}\"", + null, + progressMonitor.Console + ); using (var customCancelToken = cancellationToken.Register (process.Cancel)) { await process.Task; |