diff --git a/README.md b/README.md index f254260..13096e0 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ # gen-act-nvs -Generates "act-nvs.dat" from "act.dat" +Generates "act-nvs.dat" from "act.dat" (for testkit/devkit activation) \ No newline at end of file diff --git a/gen-act-nvs.sln b/gen-act-nvs.sln new file mode 100644 index 0000000..59442d8 --- /dev/null +++ b/gen-act-nvs.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.26228.76 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "gen-act-nvs", "gen-act-nvs\gen-act-nvs.csproj", "{B57FBE6F-2457-4487-9092-5901AC4ECFF2}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {B57FBE6F-2457-4487-9092-5901AC4ECFF2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B57FBE6F-2457-4487-9092-5901AC4ECFF2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B57FBE6F-2457-4487-9092-5901AC4ECFF2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B57FBE6F-2457-4487-9092-5901AC4ECFF2}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/gen-act-nvs/App.config b/gen-act-nvs/App.config new file mode 100644 index 0000000..88fa402 --- /dev/null +++ b/gen-act-nvs/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/gen-act-nvs/Program.cs b/gen-act-nvs/Program.cs new file mode 100644 index 0000000..f4bd235 --- /dev/null +++ b/gen-act-nvs/Program.cs @@ -0,0 +1,108 @@ +using Org.BouncyCastle.Crypto; +using Org.BouncyCastle.Crypto.Engines; +using Org.BouncyCastle.Crypto.Macs; +using Org.BouncyCastle.Crypto.Parameters; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace gen_act_nvs +{ + class Program + { + static byte[] ACT_NVS_KEY = new byte[] { 0x5A, 0x91, 0xFC, 0x74, 0xA8, 0x2B, 0xE3, 0xF2, 0xB8, 0xF4, 0xDB, 0x60, 0x70, 0xA0, 0x99, 0xA2, 0xBD, 0xF0, 0x0E, 0x7B, 0xF0, 0x0E, 0x7B, 0xF0, 0x8B, 0x68, 0x55, 0x34, 0xA0, 0x64, 0x6D, 0x87 }; + static void WriteString(Stream stream, string str) + { + byte[] strBytes = Encoding.UTF8.GetBytes(str); + stream.Write(strBytes, 0x00, strBytes.Length); + stream.WriteByte(0x00); + } + + static void WriteInt32(Stream stream, Int32 numb) + { + byte[] intBytes = BitConverter.GetBytes(numb); + stream.Write(intBytes, 0x00, intBytes.Length); + } + static Int32 ReadInt32(Stream stream) + { + byte[] intBytes = new byte[0x4]; + stream.Read(intBytes, 0x00, intBytes.Length); + return BitConverter.ToInt32(intBytes, 0x00); + } + + static void Main(string[] args) + { + if (args.Length >= 1) + { + string actPath = args[0]; + string actNvsPath = ""; + if (args.Length >= 2) + { + actNvsPath = args[1]; + } + else + { + actNvsPath = Path.Combine(Path.GetDirectoryName(actPath), "act-nvs.dat"); + } + + + + + if (File.Exists(actNvsPath)) + { + Console.WriteLine(actNvsPath + " Allready exists!"); + return; + } + + FileStream act = new FileStream(actPath, FileMode.OpenOrCreate, FileAccess.ReadWrite); + FileStream nvsAct = new FileStream(actNvsPath, FileMode.CreateNew, FileAccess.ReadWrite); + + act.Seek(0x8, SeekOrigin.Begin); + int IssueNo = ReadInt32(act); + int StartDate = ReadInt32(act); + int EndDate = ReadInt32(act); + + + WriteString(nvsAct, "act"); + WriteInt32(nvsAct, IssueNo); + WriteInt32(nvsAct, EndDate); + WriteInt32(nvsAct, StartDate); + + Console.WriteLine("Writing nvs-act.dat\n"); + Console.WriteLine("Issue No. " + IssueNo.ToString()); + Console.WriteLine("End Date " + EndDate.ToString()); + Console.WriteLine("Start Date " + StartDate.ToString()); + Console.WriteLine("\nCaclulating CMAC"); + + //Calculate CMAC + nvsAct.Seek(0x00, SeekOrigin.Begin); + byte[] actBuffer = new byte[0x10]; + nvsAct.Read(actBuffer, 0x00, actBuffer.Length); + + IBlockCipher cipher = new AesEngine(); + IMac mac = new CMac(cipher, 128); + KeyParameter key = new KeyParameter(ACT_NVS_KEY); + mac.Init(key); + mac.BlockUpdate(actBuffer, 0, actBuffer.Length); + byte[] outBytes = new byte[16]; + mac.DoFinal(outBytes, 0); + + nvsAct.Seek(0x10, SeekOrigin.Begin); + nvsAct.Write(outBytes,0x00,outBytes.Length); + + foreach(byte b in outBytes) + { + Console.Write(b.ToString("X") + " "); + } + Console.WriteLine("\nDone!"); + } + else + { + Console.WriteLine("gen-act-nvs [output act]"); + } + } + } +} diff --git a/gen-act-nvs/Properties/AssemblyInfo.cs b/gen-act-nvs/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..7cb058a --- /dev/null +++ b/gen-act-nvs/Properties/AssemblyInfo.cs @@ -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("gen-act-nvs")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("gen-act-nvs")] +[assembly: AssemblyCopyright("Copyright © 2019")] +[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("b57fbe6f-2457-4487-9092-5901ac4ecff2")] + +// 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")] diff --git a/gen-act-nvs/gen-act-nvs.csproj b/gen-act-nvs/gen-act-nvs.csproj new file mode 100644 index 0000000..537eb25 --- /dev/null +++ b/gen-act-nvs/gen-act-nvs.csproj @@ -0,0 +1,56 @@ + + + + + Debug + AnyCPU + {B57FBE6F-2457-4487-9092-5901AC4ECFF2} + Exe + gen_act_nvs + gen-act-nvs + v4.5.2 + 512 + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\BouncyCastle.1.8.5\lib\BouncyCastle.Crypto.dll + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/gen-act-nvs/packages.config b/gen-act-nvs/packages.config new file mode 100644 index 0000000..27ca767 --- /dev/null +++ b/gen-act-nvs/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/packages/BouncyCastle.1.8.5/.signature.p7s b/packages/BouncyCastle.1.8.5/.signature.p7s new file mode 100644 index 0000000..378adca Binary files /dev/null and b/packages/BouncyCastle.1.8.5/.signature.p7s differ diff --git a/packages/BouncyCastle.1.8.5/BouncyCastle.1.8.5.nupkg b/packages/BouncyCastle.1.8.5/BouncyCastle.1.8.5.nupkg new file mode 100644 index 0000000..f6d7c2a Binary files /dev/null and b/packages/BouncyCastle.1.8.5/BouncyCastle.1.8.5.nupkg differ diff --git a/packages/BouncyCastle.1.8.5/README.md b/packages/BouncyCastle.1.8.5/README.md new file mode 100644 index 0000000..270d9cc --- /dev/null +++ b/packages/BouncyCastle.1.8.5/README.md @@ -0,0 +1,30 @@ +# The Bouncy Castle Crypto Package For C Sharp + +The Bouncy Castle Crypto package is a C\# implementation of cryptographic algorithms and protocols, it was developed by the Legion of the Bouncy Castle, a registered Australian Charity, with a little help! The Legion, and the latest goings on with this package, can be found at [http://www.bouncycastle.org](http://www.bouncycastle.org). In addition to providing basic cryptography algorithms, the package also provides support for CMS, TSP, X.509 certificate generation and a variety of other standards such as OpenPGP. + +The Legion also gratefully acknowledges the contributions made to this package by others (see [here](http://www.bouncycastle.org/csharp/contributors.html) for the current list). If you would like to contribute to our efforts please feel free to get in touch with us or visit our [donations page](https://www.bouncycastle.org/donate), sponsor some specific work, or purchase a support contract through [Crypto Workshop](http://www.cryptoworkshop.com). + +Except where otherwise stated, this software is distributed under a license based on the MIT X Consortium license. To view the license, [see here](http://www.bouncycastle.org/licence.html). The OpenPGP library also includes a modified BZIP2 library which is licensed under the [Apache Software License, Version 2.0](http://www.apache.org/licenses/). + +**Note**: this source tree is not the FIPS version of the APIs - if you are interested in our FIPS version please contact us directly at [office@bouncycastle.org](mailto:office@bouncycastle.org). + +## Mailing Lists + +For those who are interested, there are 2 mailing lists for participation in this project. To subscribe use the links below and include the word subscribe in the message body. (To unsubscribe, replace **subscribe** with **unsubscribe** in the message body) + +* [announce-crypto-csharp-request@bouncycastle.org](mailto:announce-crypto-csharp-request@bouncycastle.org) + This mailing list is for new release announcements only, general subscribers cannot post to it. +* [dev-crypto-csharp-request@bouncycastle.org](mailto:dev-crypto-csharp-request@bouncycastle.org) + This mailing list is for discussion of development of the package. This includes bugs, comments, requests for enhancements, questions about use or operation. + +**NOTE:**You need to be subscribed to send mail to the above mailing list. + +## Feedback + +If you want to provide feedback directly to the members of **The Legion** then please use [feedback-crypto@bouncycastle.org](mailto:feedback-crypto@bouncycastle.org), if you want to help this project survive please consider [donating](https://www.bouncycastle.org/donate). + +For bug reporting/requests you can report issues here on github, via feedback-crypto if required, and we also have a [Jira issue tracker](http://www.bouncycastle.org/jira). We will accept pull requests based on this repository as well. + +## Finally + +Enjoy! diff --git a/packages/BouncyCastle.1.8.5/lib/BouncyCastle.Crypto.dll b/packages/BouncyCastle.1.8.5/lib/BouncyCastle.Crypto.dll new file mode 100644 index 0000000..05036dd Binary files /dev/null and b/packages/BouncyCastle.1.8.5/lib/BouncyCastle.Crypto.dll differ