From c8cb9959374de68c912932edd43cf9ce76337963 Mon Sep 17 00:00:00 2001 From: vnugent Date: Thu, 23 Nov 2023 13:02:08 -0500 Subject: package updates --- Module.Taskfile.yaml | 6 +++++ src/HardwareAuthenticator.cs | 10 ++++---- src/PkiAuthenticator.csproj | 10 ++++---- src/ProcessArguments.cs | 54 -------------------------------------------- src/Program.cs | 12 +++++----- src/SoftwareAuthenticator.cs | 10 ++++---- src/Statics.cs | 14 ++++++------ 7 files changed, 34 insertions(+), 82 deletions(-) delete mode 100644 src/ProcessArguments.cs diff --git a/Module.Taskfile.yaml b/Module.Taskfile.yaml index e2865c0..45f63ac 100644 --- a/Module.Taskfile.yaml +++ b/Module.Taskfile.yaml @@ -28,6 +28,12 @@ tasks: #build debug mode first - task: build_debug - task: build_release + + postbuild_success: + cmds: + #git archive in the module directory + - git archive --format {{.ARCHIVE_FILE_FORMAT}} --output {{.ARCHIVE_FILE_NAME}} HEAD + #called by build pipeline to clean module clean: diff --git a/src/HardwareAuthenticator.cs b/src/HardwareAuthenticator.cs index a630957..ec8d74b 100644 --- a/src/HardwareAuthenticator.cs +++ b/src/HardwareAuthenticator.cs @@ -55,7 +55,7 @@ namespace PkiAuthenticator get { //Check for slot cli flag - string? slotArg = CliArgs.GetArg("--piv-slot"); + string? slotArg = CliArgs.GetArgument("--piv-slot"); //Try hase from hex, otherwise default to the authentication slot return byte.TryParse(slotArg, NumberStyles.HexNumber, null, out byte slotNum) ? slotNum : Yubico.YubiKey.Piv.PivSlot.Authentication; } @@ -76,7 +76,7 @@ namespace PkiAuthenticator Log.Debug("Using hardware authenticator"); //User may select the serial of the specific key to use - if (CliArgs.HasArg("--key") && int.TryParse(CliArgs.GetArg("--key"), out int serial)) + if (CliArgs.HasArgument("--key") && int.TryParse(CliArgs.GetArgument("--key"), out int serial)) { Log.Debug("Loading device {d}", serial); @@ -167,7 +167,7 @@ namespace PkiAuthenticator string? input; //Check if the user issued the pin as cli arg - if (CliArgs.HasArg("--pin")) + if (CliArgs.HasArgument("--pin")) { //No retires allowed during cli, we dont want the device to lock out if (keyData.IsRetry) @@ -175,7 +175,7 @@ namespace PkiAuthenticator return false; } - input = CliArgs.GetArg("--pin"); + input = CliArgs.GetArgument("--pin"); } //Check for environment variable else if (Environment.GetEnvironmentVariable(Program.YUBIKEY_PIN_ENV_VAR_NAME) != null) @@ -188,7 +188,7 @@ namespace PkiAuthenticator input = Environment.GetEnvironmentVariable(Program.YUBIKEY_PIN_ENV_VAR_NAME); } //If the silent flag is set, a pin cli or env must be set, since we cannot write to STDOUT - else if (CliArgs.Silent) + else if (CliArgs.HasArgument("--silent") || CliArgs.HasArgument("-s")) { return false; } diff --git a/src/PkiAuthenticator.csproj b/src/PkiAuthenticator.csproj index 01d1024..576b466 100644 --- a/src/PkiAuthenticator.csproj +++ b/src/PkiAuthenticator.csproj @@ -36,11 +36,11 @@ - - - - - + + + + + diff --git a/src/ProcessArguments.cs b/src/ProcessArguments.cs deleted file mode 100644 index 4d1febd..0000000 --- a/src/ProcessArguments.cs +++ /dev/null @@ -1,54 +0,0 @@ -/* -* Copyright (c) 2023 Vaughn Nugent -* -* Package: PkiAuthenticator -* File: ProcessArguments.cs -* -* PkiAuthenticator is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published -* by the Free Software Foundation, either version 2 of the License, -* or (at your option) any later version. -* -* PkiAuthenticator is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -* General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with PkiAuthenticator. If not, see http://www.gnu.org/licenses/. -*/ - -using System; -using System.Linq; -using System.Collections.Generic; - -namespace PkiAuthenticator -{ - internal class ProcessArguments - { - private readonly List _args; - - public ProcessArguments(string[] args) => _args = args.ToList(); - - public bool HasArg(string arg) => _args.Contains(arg, StringComparer.OrdinalIgnoreCase); - - public bool Verbose => HasArg("-v") || HasArg("--verbose"); - public bool Debug => HasArg("-d") || HasArg("--debug"); - public bool Silent => HasArg("-s") || HasArg("--silent"); - public bool DoubleVerbose => Verbose && HasArg("-vv"); - - public bool LogHttp => HasArg("--log-http"); - - /// - /// Gets the value following the specified argument, or - /// null no value follows the specified argument - /// - /// - /// - public string? GetArg(string arg) - { - int index = _args.IndexOf(arg); - return index == -1 || index + 1 >= _args.Count ? null : _args[index + 1]; - } - } -} diff --git a/src/Program.cs b/src/Program.cs index 09bb867..d2fd034 100644 --- a/src/Program.cs +++ b/src/Program.cs @@ -36,7 +36,7 @@ namespace PkiAuthenticator public const string PEM_EXPORT_TEMPLATE = "You may copy your public key\n\n{cert}\n"; const string HELP_MESSAGE = @$" - vauth Copyright © Vaughn Nugent https://www.vaughnnugent.com/resources/software + vauth Copyright (c) Vaughn Nugent https://www.vaughnnugent.com/resources/software This program comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute it under certain conditions. See the license.txt file for more details. @@ -160,7 +160,7 @@ namespace PkiAuthenticator static int Main(string[] args) { - if (CliArgs.HasArg("-h") || CliArgs.HasArg("--help")) + if (CliArgs.HasArgument("-h") || CliArgs.HasArgument("--help")) { Console.WriteLine(HELP_MESSAGE); return 0; @@ -172,25 +172,25 @@ namespace PkiAuthenticator try { //Get software or hardware authenticator - using IAuthenticator authenticator = CliArgs.HasArg("--software") ? new SoftwareAuthenticator() : new HardwareAuthenticator(); + using IAuthenticator authenticator = CliArgs.HasArgument("--software") ? new SoftwareAuthenticator() : new HardwareAuthenticator(); //initialze the authenticator if (authenticator.Initialize()) { //Only continue if authenticator successfully initialized - if (CliArgs.HasArg("--list-devices")) + if (CliArgs.HasArgument("--list-devices")) { Log.Verbose("Gathering device information"); //List devices flag exitCode = authenticator.ListDevices(); } - else if (CliArgs.HasArg("-e") || CliArgs.HasArg("--export")) + else if (CliArgs.HasArgument("-e") || CliArgs.HasArgument("--export")) { Log.Verbose("Exporting public key"); //Check for pem encoding flag - if (CliArgs.HasArg("pem")) + if (CliArgs.HasArgument("pem")) { string pem = authenticator.ExportPem(); Log.Information(PEM_EXPORT_TEMPLATE, pem); diff --git a/src/SoftwareAuthenticator.cs b/src/SoftwareAuthenticator.cs index f147113..27eb47c 100644 --- a/src/SoftwareAuthenticator.cs +++ b/src/SoftwareAuthenticator.cs @@ -64,7 +64,7 @@ namespace PkiAuthenticator Log.Debug("Using software authenticator"); //try to import the certificate file - string? cerFilePath = CliArgs.GetArg("--software"); + string? cerFilePath = CliArgs.GetArgument("--software"); if(cerFilePath == null) { Log.Error("You must specify a file path following the --software flag"); @@ -78,7 +78,7 @@ namespace PkiAuthenticator return false; } - string? privateKeyFile = CliArgs.GetArg("--private-key"); + string? privateKeyFile = CliArgs.GetArgument("--private-key"); if(privateKeyFile == null) { @@ -96,15 +96,15 @@ namespace PkiAuthenticator ReadOnlySpan password = null; //See if password is required - if (CliArgs.HasArg("--password")) + if (CliArgs.HasArgument("--password")) { //encryption is required, get from arg, or from env var - string? pass = CliArgs.GetArg("--password") ?? Environment.GetEnvironmentVariable(Program.SOFTWARE_PASSWORD_VAR_NAME); + string? pass = CliArgs.GetArgument("--password") ?? Environment.GetEnvironmentVariable(Program.SOFTWARE_PASSWORD_VAR_NAME); if (pass == null) { //if silent, we cant read the key, so we need to bail; - if (CliArgs.Silent) + if (CliArgs.HasArgument("--silent") || CliArgs.HasArgument("-s")) { return false; } diff --git a/src/Statics.cs b/src/Statics.cs index c27b27a..0978abf 100644 --- a/src/Statics.cs +++ b/src/Statics.cs @@ -47,7 +47,7 @@ namespace PkiAuthenticator internal static class Statics { - public static ProcessArguments CliArgs { get; } = new(Environment.GetCommandLineArgs()); + public static ArgumentList CliArgs { get; } = new ArgumentList(Environment.GetCommandLineArgs()); public static ILogProvider Log { get; } = GetLog(); @@ -56,11 +56,11 @@ namespace PkiAuthenticator LoggerConfiguration config = new(); //Set min level from cli flags - if(CliArgs.Verbose) + if(CliArgs.HasArgument("--verbose") || CliArgs.HasArgument("-v")) { config.MinimumLevel.Verbose(); } - else if (CliArgs.Debug) + else if (CliArgs.HasArgument("--verbose") || CliArgs.HasArgument("-v")) { config.MinimumLevel.Debug(); } @@ -70,7 +70,7 @@ namespace PkiAuthenticator } //Make sure the silent flag is not set - if(!CliArgs.Silent) + if(!CliArgs.HasArgument("--silent") || CliArgs.HasArgument("-s")) { //Write to console for now config.WriteTo.Console(); @@ -87,8 +87,8 @@ namespace PkiAuthenticator /// The process exit code returning the status of the operation. public static int GenerateOtp(this IAuthenticator authenticator) { - string? uid = CliArgs.GetArg("-u"); - uid ??= CliArgs.GetArg("--user"); + string? uid = CliArgs.GetArgument("-u"); + uid ??= CliArgs.GetArgument("--user"); HashAlg digest; @@ -157,7 +157,7 @@ namespace PkiAuthenticator Log.Information(Program.TOKEN_PRINT_TEMPLATE, jwt.Compile()); //If silent mode is enabled, write credential directly to stdout - if (CliArgs.Silent) + if (CliArgs.HasArgument("--silent") || CliArgs.HasArgument("-s")) { Console.Write(jwt.Compile()); } -- cgit