Skip to content

Commit

Permalink
Auth-managed HWIDs (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
PJB3005 committed Sep 28, 2024
1 parent 3ba81e6 commit 3cf1c5b
Show file tree
Hide file tree
Showing 8 changed files with 2,165 additions and 9 deletions.
17 changes: 16 additions & 1 deletion SS14.Auth.Shared/Data/ApplicationDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ protected override void OnModelCreating(ModelBuilder builder)
.HasIndex(p => new {p.Hash, p.SpaceUserId})
.IsUnique();

builder.Entity<AuthHash>()
.HasOne(h => h.Hwid)
.WithMany()
.OnDelete(DeleteBehavior.SetNull);

builder.Entity<BurnerEmail>()
.HasIndex(p => new {p.Domain})
.IsUnique();
Expand All @@ -60,6 +65,14 @@ protected override void OnModelCreating(ModelBuilder builder)
.HasIndex(p => new { p.ClientId })
.IsUnique();

builder.Entity<Hwid>()
.HasIndex(h => h.ClientData)
.IsUnique();

builder.Entity<HwidUser>()
.HasIndex(h => new { h.HwidId, h.SpaceUserId })
.IsUnique();

var cfgStoreOptions = new ConfigurationStoreOptions
{
IdentityResource = new TableConfiguration("IdentityResources", "IS4"),
Expand Down Expand Up @@ -103,6 +116,8 @@ protected override void OnModelCreating(ModelBuilder builder)
public DbSet<UserOAuthClient> UserOAuthClients { get; set; }
public DbSet<PastAccountName> PastAccountNames { get; set; }
public DbSet<AccountLog> AccountLogs { get; set; }
public DbSet<Hwid> Hwids { get; set; }
public DbSet<HwidUser> HwidUsers { get; set; }

// IS4 configuration.
public DbSet<Client> Clients { get; set; }
Expand All @@ -120,4 +135,4 @@ Task<int> IPersistedGrantDbContext.SaveChangesAsync()
{
return base.SaveChangesAsync();
}
}
}
9 changes: 8 additions & 1 deletion SS14.Auth.Shared/Data/AuthHash.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.ComponentModel.DataAnnotations;
using JetBrains.Annotations;

namespace SS14.Auth.Shared.Data;

Expand All @@ -10,8 +11,14 @@ public class AuthHash
public Guid SpaceUserId { get; set; }
public SpaceUser SpaceUser { get; set; }

/// <summary>
/// The HWID for the connection attempt from the client.
/// </summary>
public long? HwidId { get; set; }
[CanBeNull] public Hwid Hwid { get; set; }

public DateTimeOffset Expires { get; set; }

[Required]
public byte[] Hash { get; set; }
}
}
64 changes: 64 additions & 0 deletions SS14.Auth.Shared/Data/Hwid.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Text.Json.Serialization;

namespace SS14.Auth.Shared.Data;

/// <summary>
/// A single HWID known to the authorization database.
/// </summary>
public sealed class Hwid
{
/// <summary>
/// Type code for <see cref="TypeCode"/>.
/// </summary>
public const int Type1 = 1;

public long Id { get; set; }

/// <summary>
/// Intended to be used for administration of the database.
/// </summary>
public int TypeCode { get; set; }

/// <summary>
/// Data returned by client.
/// </summary>
[Required] public byte[] ClientData { get; set; }

/// <summary>
/// ID value given to servers.
/// </summary>
[Required] public byte[] Value { get; set; }

/// <summary>
/// Users that have been "spotted" using this HWID.
/// </summary>
[JsonIgnore]
public List<HwidUser> Users { get; set; } = default!;
}

/// <summary>
/// A hit of a user ever having used an HWID.
/// </summary>
public sealed class HwidUser
{
public long Id { get; set; }

/// <summary>
/// ID of the <see cref="Hwid"/> that this user was seen to be using.
/// </summary>
public long HwidId { get; set; }
public Guid SpaceUserId { get; set; }

/// <summary>
/// When the user was first seen using this HWID.
/// </summary>
public DateTime FirstSeen { get; set; }

public Hwid Hwid { get; set; } = null!;

[JsonIgnore]
public SpaceUser SpaceUser { get; set; } = null!;
}
Loading

0 comments on commit 3cf1c5b

Please sign in to comment.