Skip to content

Commit

Permalink
Added additional switches
Browse files Browse the repository at this point in the history
  • Loading branch information
bytewizer committed Sep 10, 2022
1 parent e5d2eb7 commit 9b2df6c
Show file tree
Hide file tree
Showing 18 changed files with 687 additions and 48 deletions.
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
This is a simple command line utility for download and exporting the chain root certificates required for [TinyCLR OS](https://www.ghielectronics.com/) to access secure sites. Certificate can be exported in Security Certificate File Format (crt) commonly embedded as a binary project resource or a csharp source code array easly added to a project as source code.

```
Usage: cert2src url [options]
Usage: cert2src.exe url [options]
Download and export root certificates required for TinyCLR OS to access secure sites.
Expand All @@ -14,6 +14,8 @@ options:
--path Output chain root certificate as base-64 encoded PEM format to file.
--code Set output format as csharp source code array.
--width Width of the source code array output (default 18).
--namespace Namespace used when creating code array output.
--classname Class name structure used when creating code array output.
```
Note: you can included the --path flag without a path and it will default to the executable path location.

Expand Down Expand Up @@ -41,7 +43,7 @@ Root certificate downloaded from 'https://www.google.com/'
```

```
C:\project>cert2src.exe https://www.google.com --path -code -width 10
C:\project>cert2src.exe https://www.google.com --path --code --width 10
private static readonly byte[] Certificate =
{
Expand All @@ -58,6 +60,14 @@ Root certificate successfully exported to 'C:\project\certificate.cs'
Root certificate downloaded from 'https://www.google.com/'
```

## Project Files
Automate the updating of project resources by adding a command target to the bottom of your project <c>.csproj</c> file.
```
<Target Name="GetSSLCert" BeforeTargets="PrepareForBuild">
<Exec Command="$(SolutionDir)tools\cert2src.exe https://api.host.com --path $(ProjectDir)Resources" />
</Target>
```

## Contributions

Contributions to this project are always welcome. Please consider forking this project on GitHub and sending a pull request to get your improvements added to the original project.
Expand Down
27 changes: 27 additions & 0 deletions sample/src/Bytewizer.TlsClient.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.3.32825.248
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bytewizer.TlsClient", "Bytewizer.TlsClient\Bytewizer.TlsClient.csproj", "{F4D86B90-CA9A-485E-B0E7-53CFCB4366F4}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{F4D86B90-CA9A-485E-B0E7-53CFCB4366F4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F4D86B90-CA9A-485E-B0E7-53CFCB4366F4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F4D86B90-CA9A-485E-B0E7-53CFCB4366F4}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
{F4D86B90-CA9A-485E-B0E7-53CFCB4366F4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F4D86B90-CA9A-485E-B0E7-53CFCB4366F4}.Release|Any CPU.Build.0 = Release|Any CPU
{F4D86B90-CA9A-485E-B0E7-53CFCB4366F4}.Release|Any CPU.Deploy.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {9117BF18-73E8-4583-9462-AD292A7BCFB3}
EndGlobalSection
EndGlobal
95 changes: 95 additions & 0 deletions sample/src/Bytewizer.TlsClient/Bytewizer.TlsClient.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\GHIElectronics.TinyCLR.Core.2.2.0.4200\build\net452\GHIElectronics.TinyCLR.Core.props" Condition="Exists('..\packages\GHIElectronics.TinyCLR.Core.2.2.0.4200\build\net452\GHIElectronics.TinyCLR.Core.props')" />
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{F4D86B90-CA9A-485E-B0E7-53CFCB4366F4}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>Bytewizer.TlsClient</RootNamespace>
<AssemblyName>Bytewizer.TlsClient</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<ProjectTypeGuids>{A1948822-69DD-4150-919B-F3F42EFB71CC};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<LangVersion>9</LangVersion>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Include="TlsClient.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
<None Include="Resources\certificate.crt" />
</ItemGroup>
<ItemGroup>
<Reference Include="GHIElectronics.TinyCLR.Devices.Gpio, Version=2.2.0.4200, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\GHIElectronics.TinyCLR.Devices.Gpio.2.2.0.4200\lib\net452\GHIElectronics.TinyCLR.Devices.Gpio.dll</HintPath>
</Reference>
<Reference Include="GHIElectronics.TinyCLR.Devices.Network, Version=2.2.0.4200, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\GHIElectronics.TinyCLR.Devices.Network.2.2.0.4200\lib\net452\GHIElectronics.TinyCLR.Devices.Network.dll</HintPath>
</Reference>
<Reference Include="GHIElectronics.TinyCLR.Devices.Spi, Version=2.2.0.4200, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\GHIElectronics.TinyCLR.Devices.Spi.2.2.0.4200\lib\net452\GHIElectronics.TinyCLR.Devices.Spi.dll</HintPath>
</Reference>
<Reference Include="GHIElectronics.TinyCLR.Devices.Uart, Version=2.2.0.4200, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\GHIElectronics.TinyCLR.Devices.Uart.2.2.0.4200\lib\net452\GHIElectronics.TinyCLR.Devices.Uart.dll</HintPath>
</Reference>
<Reference Include="GHIElectronics.TinyCLR.Native, Version=2.2.0.4200, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\GHIElectronics.TinyCLR.Native.2.2.0.4200\lib\net452\GHIElectronics.TinyCLR.Native.dll</HintPath>
</Reference>
<Reference Include="GHIElectronics.TinyCLR.Networking, Version=2.2.0.4200, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\GHIElectronics.TinyCLR.Networking.2.2.0.4200\lib\net452\GHIElectronics.TinyCLR.Networking.dll</HintPath>
</Reference>
<Reference Include="GHIElectronics.TinyCLR.Networking.Http, Version=2.2.0.4200, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\GHIElectronics.TinyCLR.Networking.Http.2.2.0.4200\lib\net452\GHIElectronics.TinyCLR.Networking.Http.dll</HintPath>
</Reference>
<Reference Include="GHIElectronics.TinyCLR.Pins, Version=2.2.0.4200, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\GHIElectronics.TinyCLR.Pins.2.2.0.4200\lib\net452\GHIElectronics.TinyCLR.Pins.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\GHIElectronics.TinyCLR.Core.2.2.0.4200\build\net452\GHIElectronics.TinyCLR.Core.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\GHIElectronics.TinyCLR.Core.2.2.0.4200\build\net452\GHIElectronics.TinyCLR.Core.props'))" />
</Target>
<Target Name="GetSSLCert" BeforeTargets="PrepareForBuild">
<Exec Command="$(SolutionDir)tools\cert2src.exe https://api.coindesk.com --path $(ProjectDir)Resources" />
</Target>
</Project>
27 changes: 27 additions & 0 deletions sample/src/Bytewizer.TlsClient/Bytewizer.TlsClient.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.3.32825.248
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bytewizer.TlsClient", "Bytewizer.TlsClient\Bytewizer.TlsClient.csproj", "{F4D86B90-CA9A-485E-B0E7-53CFCB4366F4}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{F4D86B90-CA9A-485E-B0E7-53CFCB4366F4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F4D86B90-CA9A-485E-B0E7-53CFCB4366F4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F4D86B90-CA9A-485E-B0E7-53CFCB4366F4}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
{F4D86B90-CA9A-485E-B0E7-53CFCB4366F4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F4D86B90-CA9A-485E-B0E7-53CFCB4366F4}.Release|Any CPU.Build.0 = Release|Any CPU
{F4D86B90-CA9A-485E-B0E7-53CFCB4366F4}.Release|Any CPU.Deploy.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {9117BF18-73E8-4583-9462-AD292A7BCFB3}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\GHIElectronics.TinyCLR.Core.2.2.0.4200\build\net452\GHIElectronics.TinyCLR.Core.props" Condition="Exists('..\packages\GHIElectronics.TinyCLR.Core.2.2.0.4200\build\net452\GHIElectronics.TinyCLR.Core.props')" />
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{F4D86B90-CA9A-485E-B0E7-53CFCB4366F4}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>Bytewizer.TlsClient</RootNamespace>
<AssemblyName>Bytewizer.TlsClient</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<ProjectTypeGuids>{A1948822-69DD-4150-919B-F3F42EFB71CC};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<LangVersion>9</LangVersion>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\GHIElectronics.TinyCLR.Core.2.2.0.4200\build\net452\GHIElectronics.TinyCLR.Core.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\GHIElectronics.TinyCLR.Core.2.2.0.4200\build\net452\GHIElectronics.TinyCLR.Core.props'))" />
</Target>
</Project>
15 changes: 15 additions & 0 deletions sample/src/Bytewizer.TlsClient/Bytewizer.TlsClient/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;
using System.Collections;
using System.Diagnostics;
using System.Text;
using System.Threading;

namespace Bytewizer.TlsClient
{
internal class Program
{
static void Main()
{
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Bytewizer.TlsClient")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Bytewizer.TlsClient")]
[assembly: AssemblyCopyright("Copyright © 2022")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("f4d86b90-ca9a-485e-b0e7-53cfcb4366f4")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="GHIElectronics.TinyCLR.Core" version="2.2.0.4200" targetFramework="net48" />
</packages>
57 changes: 57 additions & 0 deletions sample/src/Bytewizer.TlsClient/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using System;
using System.Collections;
using System.Threading;
using System.Diagnostics;

using GHIElectronics.TinyCLR.Pins;
using GHIElectronics.TinyCLR.Devices.Gpio;
using GHIElectronics.TinyCLR.Devices.Network;

namespace Bytewizer.TlsClient
{
internal class Program
{
static bool _linkReady = false;

public static NetworkController Controller { get; private set; }

static void Main()
{
var resetPin = GpioController.GetDefault().OpenPin(SC20260.GpioPin.PG3);
resetPin.SetDriveMode(GpioPinDriveMode.Output);

resetPin.Write(GpioPinValue.Low);
Thread.Sleep(100);

resetPin.Write(GpioPinValue.High);
Thread.Sleep(100);

Controller = NetworkController.FromName(SC20260.NetworkController.EthernetEmac);
Controller.SetCommunicationInterfaceSettings(new BuiltInNetworkCommunicationInterfaceSettings());
Controller.SetInterfaceSettings(new EthernetNetworkInterfaceSettings()
{
DhcpEnable = true,
DynamicDnsEnable = true,
MacAddress = new byte[6] { 0x00, 0x8D, 0xB4, 0x49, 0xAD, 0xBD }
});
Controller.SetAsDefaultController();
Controller.NetworkAddressChanged += NetworkController_NetworkAddressChanged;
Controller.Enable();

while (_linkReady == false);

var tlsClient = new TlsClient();
tlsClient.Connect("https://api.coindesk.com/v1/bpi/currentprice.json");
}

private static void NetworkController_NetworkAddressChanged
(NetworkController sender, NetworkAddressChangedEventArgs e)
{
var ipProperties = sender.GetIPProperties();
var address = ipProperties.Address.GetAddressBytes();

_linkReady = address[0] != 0;
Debug.WriteLine("IP: " + address[0] + "." + address[1] + "." + address[2] + "." + address[3]);
}
}
}
Loading

0 comments on commit 9b2df6c

Please sign in to comment.