Skip to content

Commit

Permalink
auth: shorten token selection frame
Browse files Browse the repository at this point in the history
client: update windows cli to use status codes
  • Loading branch information
Netdex committed May 1, 2018
1 parent 158128a commit d2a929b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
11 changes: 6 additions & 5 deletions Seppuku.Client.Windows.CLI/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Quartz.Impl;
using Seppuku.Module;
using Seppuku.Module.Config;
using Seppuku.Module.Standard;

namespace Seppuku.Client.Windows.CLI
{
Expand Down Expand Up @@ -113,15 +114,15 @@ public static void UpdateLastReset(JObject data)
{
L.Info("response received from seppuku server");
L.Info("{0}", data.ToString());
switch ((int)data["status"])
switch ((StatusCode)(int)data["status"])
{
case 0:
case StatusCode.Success:
NotificationIcon.ShowBalloonTip(5000, "Seppuku Reset", "Deadman's switch has been reset!", ToolTipIcon.Info);
break;
case -1:
NotificationIcon.ShowBalloonTip(5000, "Seppuku Failure", "Deadman's switch has activated!", ToolTipIcon.Error);
case StatusCode.Expired:
NotificationIcon.ShowBalloonTip(5000, "Seppuku Failure", "Deadman's switch is already expired!", ToolTipIcon.Error);
break;
case -999:
case StatusCode.Unauthorized:
NotificationIcon.ShowBalloonTip(5000, "Seppuku Failure", "The authorization token is invalid!", ToolTipIcon.Error);
break;
}
Expand Down
3 changes: 2 additions & 1 deletion Seppuku.Module/SeppukuModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public abstract class SeppukuModule
private static readonly NLog.Logger L = NLog.LogManager.GetCurrentClassLogger();

public const string ModuleConfigDirectory = "Configuration";
public const int TokenDivision = 60 * 60;

public string Name { get; set; }
public string Description { get; set; }
Expand Down Expand Up @@ -47,7 +48,7 @@ public virtual void OnStop() { }

public static string GetCurrentToken(string secret)
{
byte[] byteArray = Encoding.ASCII.GetBytes(DateTime.UtcNow.Date.ToLongDateString());
byte[] byteArray = BitConverter.GetBytes((long)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds / TokenDivision));
using (HMACSHA1 hmacsha1 = new HMACSHA1(Encoding.ASCII.GetBytes(secret)))
{
return hmacsha1.ComputeHash(byteArray).Aggregate("", (s, e) => s + $"{e:x2}", s => s);
Expand Down
2 changes: 1 addition & 1 deletion Seppuku/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ private static void Main(string[] args)
Configuration.ConfigurationFileName);
L.Info("Secret key is {0}",
Configuration.Get<string>("Secret"));
L.Info("Today's auth token is {0}", SeppukuModule.GetCurrentToken(Configuration.Get<string>("Secret")));
L.Info("Auth token is {0} for the next {1} second(s)", SeppukuModule.GetCurrentToken(Configuration.Get<string>("Secret")), SeppukuModule.TokenDivision);

// load scheduling information from global configuration
Sched.Initialize();
Expand Down

0 comments on commit d2a929b

Please sign in to comment.