wow i hope my database password doesn't show up

woomy
This commit is contained in:
Malloc of Kuzkycyziklistan 2017-08-18 16:01:11 -05:00
parent 8867c3051a
commit 22f4a8f702
17 changed files with 273 additions and 73 deletions

1
.gitignore vendored
View file

@ -304,3 +304,4 @@ $RECYCLE.BIN/
# Windows shortcuts
*.lnk
server/config.ini

View file

@ -36,6 +36,8 @@ All numbers, unless otherwise specified, are the string representation of a base
A packet ID may have a specific "direction" of communication, in that an endpoint may either act as a _requester_ or a _responder_. A _requester_ is an endpoint that drives all of the communication on that specific packet ID, while the _responder_ is responsible for providing a timely response to the requests it receives. A _responder_ for a specific packet ID should never send that packet ID unsolicited; either the packet will be ignored or the other endpoint will close the connection. Any packet ID marked as bidirectional may be initiated by either endpoint at any time.
A _blind requester_ is an endpoint that sends out a packet of a certain ID and either does not expect a response or expects a response on a different packet ID.
#### Server to Client
TODO: populate
@ -59,7 +61,80 @@ Communication between the master server and clients will be done over a WebSocke
<table style="margin-right: 8px; margin-bottom: 8px;">
<thead>
<th colspan="100" class="center">
ID 0: Key Exchange<br />
ID 1: Key Exchange<br />
Requester (resp. StM ID 0)
</th>
</thead>
<thead>
<th>#</th>
<th>Region</th>
<th>Type</th>
</thead>
<tr>
<td>1</td>
<td>Generator</td>
<td>Big Int</td>
</tr>
<tr>
<td>2</td>
<td>Modulus</td>
<td>Big Int</td>
</tr>
<tr>
<td>3</td>
<td>Server Key</td>
<td>Big Int</td>
</tr>
</table>
#### Slave to Master
<table style="margin-right: 8px; margin-bottom: 8px;">
<thead>
<th colspan="100" class="center">
ID 0: Initiation Attempt<br />
Blind Requester
</th>
</thead>
<thead>
<th>#</th>
<th>Region</th>
<th>Type</th>
</thead>
<tr>
<td class="center">1</td>
<td>Secret</td>
<td>String</td>
</tr>
</table>
<table style="margin-right: 8px; margin-bottom: 8px;">
<thead>
<th colspan="100" class="center">
ID 1: Key Exchange<br />
Responder
</th>
</thead>
<thead>
<th>#</th>
<th>Region</th>
<th>Type</th>
</thead>
<tr>
<td class="center">1</td>
<td>Client Key</td>
<td>Big Int</td>
</tr>
</table>
### Master/Client Packet IDs
#### Master to Client
<table style="margin-right: 8px; margin-bottom: 8px;">
<thead>
<th colspan="100" class="center">
ID 1: Key Exchange<br />
Requester
</th>
</thead>
@ -88,7 +163,7 @@ Communication between the master server and clients will be done over a WebSocke
<table style="margin-right: 8px; margin-bottom: 8px;">
<thead>
<th colspan="100" class="center">
ID 1: Login Attempt<br />
ID 2: Login Attempt<br />
[Encrypted] Responder
</th>
</thead>
@ -112,7 +187,7 @@ Communication between the master server and clients will be done over a WebSocke
<table style="margin-right: 8px; margin-bottom: 8px;">
<thead>
<th colspan="100" class="center">
ID 2: Registration Attempt<br />
ID 3: Registration Attempt<br />
[Encrypted] Responder
</th>
</thead>
@ -133,12 +208,12 @@ Communication between the master server and clients will be done over a WebSocke
</tr>
</table>
#### Slave to Master
#### Client to Master
<table style="margin-right: 8px; margin-bottom: 8px;">
<thead>
<th colspan="100" class="center">
ID 0: Key Exchange<br />
ID 1: Key Exchange<br />
Responder
</th>
</thead>
@ -149,15 +224,15 @@ Communication between the master server and clients will be done over a WebSocke
</thead>
<tr>
<td class="center">1</td>
<td>Client Key</td>
<td>Big Int</td>
<td>Secret</td>
<td>String</td>
</tr>
</table>
<table style="margin-right: 8px; margin-bottom: 8px;">
<thead>
<th colspan="100" class="center">
ID 1: Login Attempt<br />
ID 2: Login Attempt<br />
[Encrypted] Requester
</th>
</thead>
@ -181,7 +256,7 @@ Communication between the master server and clients will be done over a WebSocke
<table style="margin-right: 8px; margin-bottom: 8px;">
<thead>
<th colspan="100" class="center">
ID 2: Registration Attempt<br />
ID 3: Registration Attempt<br />
[Encrypted] Requester
</th>
</thead>
@ -207,12 +282,6 @@ Communication between the master server and clients will be done over a WebSocke
</tr>
</table>
### Master/Client Packet IDs
#### Master to Client
#### Client to Master
## Sockstamps
Because epoch time is not standardized across systems, an intermediate layer of date/time transmission must be used between the client and server so as to handle time dependent interactions. Therefore, a "sockstamp" will be used in place of the context-dependent implementations of epoch time.

34
server/2config.ini Normal file
View file

@ -0,0 +1,34 @@
[General]
; determines if this server instance should run the master server
Run Master = false
; address and port of the master server
;; if master server is in this instance, addr should be localhost
;; and port determines what port the master server runs on
Master Addr = localhost
Master Port = 16670
; this value used if the max users isn't specified in a server instance
Max Users = 100
; url to a web page that prints out the public ip address of the requester
Ip Checker = http://aroltd.com/ip.php
[Database]
Server = aroltd.com
Username = alec
Password = Buddyman5
Database = scape
[Server]
Id = 1
Port = 6770
Max Users = 300
[Server]
Id = 2
Port = 6780
[Server]
Id = 3
Port = 6790

View file

@ -17,7 +17,6 @@
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
<provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6, Version=6.9.9.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"></provider></providers>
</entityFramework>
<connectionStrings configSource="connectionStrings.config" />
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
</assemblyBinding>

View file

@ -24,6 +24,17 @@ namespace SockScape {
}
},
new SectionRules {
Name = "Database",
Required = true,
RequiredFields = new string[] {
"Server",
"Username",
"Password",
"Database"
}
},
new SectionRules {
Name = "Server",
AllowMultiple = true,
@ -47,6 +58,12 @@ namespace SockScape {
}
}
public static Instance Database {
get {
return Settings["Database"][0];
}
}
public static Section Servers {
get {
return Settings["Server"];

View file

@ -1,9 +1,10 @@
namespace SockScape.DAL {
using System;
using System.Data.Entity;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System;
using System.Data.Entity;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using Config = SockScape.Configuration;
namespace SockScape.DAL {
[DbConfigurationType(typeof(MySql.Data.Entity.MySqlEFConfiguration))]
public partial class ScapeDb : DbContext {
static ScapeDb() {
@ -11,7 +12,11 @@ namespace SockScape.DAL {
}
public ScapeDb()
: base("name=ScapeDbDebug")
: base("server="+ Config.Database["Server"]
+";user id="+ Config.Database["Username"]
+";password="+ Config.Database["Password"]
+";persistsecurityinfo=True;"
+"database="+ Config.Database["Database"])
{
}

View file

@ -23,21 +23,43 @@ namespace SockScape.Encryption {
public Packet GenerateRequestPacket() {
return new Packet(
Packet.kId.KeyExchange,
1,
Generator.ToHexString(),
Modulus.ToHexString(),
BigInteger.ModPow(Generator, Secret, Modulus).ToHexString()
);
}
public Packet ParseRequestPacket(Packet packet) {
if(packet.Id != 1 || packet.RegionCount != 3)
return null;
bool check = BigInteger.TryParse(packet[0], NumberStyles.HexNumber,
NumberFormatInfo.InvariantInfo, out BigInteger generator);
check &= BigInteger.TryParse(packet[1], NumberStyles.HexNumber,
NumberFormatInfo.InvariantInfo, out BigInteger modulus);
check &= BigInteger.TryParse(packet[2], NumberStyles.HexNumber,
NumberFormatInfo.InvariantInfo, out BigInteger serverKey);
if(!check)
return null;
var clientKey = BigInteger.ModPow(generator, Secret, modulus);
PrivateKey = BigInteger.ModPow(serverKey, Secret, modulus);
return new Packet(
1,
clientKey.ToHexString()
);
}
public BigInteger ParseResponsePacket(Packet packet) {
if(packet.Id != Packet.kId.KeyExchange || packet.RegionCount != 1)
if(packet.Id != 1 || packet.RegionCount != 1)
return -1;
if(!BigInteger.TryParse(packet[0], NumberStyles.HexNumber, NumberFormatInfo.InvariantInfo, out BigInteger ClientKey))
if(!BigInteger.TryParse(packet[0], NumberStyles.HexNumber, NumberFormatInfo.InvariantInfo, out BigInteger clientKey))
return -1;
return (PrivateKey = BigInteger.ModPow(ClientKey, Secret, Modulus));
return (PrivateKey = BigInteger.ModPow(clientKey, Secret, Modulus));
}
}
}

View file

@ -31,8 +31,6 @@ namespace SockScape {
servers.Add(server["Id"], new Server<PlayerConnection>((ushort)server["Port"], pool, server));
}
//var server = new Server<PlayerConnection>(6770, PoolManager.Pending);
//server.Start();

View file

@ -7,7 +7,7 @@
<ProjectGuid>{438DBAC1-BA37-40BB-9CCE-0FE1F23C6DC5}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>CircleScape</RootNamespace>
<RootNamespace>SockScape</RootNamespace>
<AssemblyName>server</AssemblyName>
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
@ -87,7 +87,10 @@
<Compile Include="Socks\MasterConnection.cs" />
<Compile Include="Socks\MasterUdpClient.cs" />
<Compile Include="Socks\MasterUdpServer.cs" />
<Compile Include="Socks\Packet.cs" />
<Compile Include="Socks\Protocols\ClientServerIds.cs" />
<Compile Include="Socks\Protocols\InterMasterIds.cs" />
<Compile Include="Socks\Protocols\IntraMasterIds.cs" />
<Compile Include="Socks\Protocols\Packet.cs" />
<Compile Include="Entrypoint.cs" />
<Compile Include="Socks\PlayerConnection.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
@ -96,10 +99,6 @@
<None Include="App.config">
<SubType>Designer</SubType>
</None>
<None Include="connectionStrings.config">
<DependentUpon>App.config</DependentUpon>
<SubType>Designer</SubType>
</None>
<None Include="packages.config">
<SubType>Designer</SubType>
<DependentUpon>App.config</DependentUpon>

View file

@ -5,9 +5,54 @@ using System.Text;
using System.Threading.Tasks;
using Kneesocks;
using Glove;
using SockScape.Encryption;
namespace SockScape.Socks {
namespace SockScape {
class MasterConnection : Connection {
private Key Key;
public Cipher Encryptor { get; private set; } = null;
protected override void OnOpen() {
Key = new Key();
Send(Key.GenerateRequestPacket().GetBytes());
}
protected override void OnParse() {
}
protected override void OnReceive(byte[] data) {
Packet packet =
Encryptor == null ? Packet.FromBytes(data)
: Packet.FromBytes(Encryptor.Parse(data));
if(packet == null) {
Disconnect(Frame.kClosingReason.ProtocolError, "Packet received was not legal.");
return;
}
switch((kInterMasterId)packet.Id) {
case kInterMasterId.KeyExchange:
Key.ParseResponsePacket(packet);
if(!Key.Succeeded) {
Disconnect(Frame.kClosingReason.ProtocolError, "Could not exchange keys.");
return;
}
Encryptor = new Cipher(Key.PrivateKey);
break;
case kInterMasterId.LoginAttempt:
break;
case kInterMasterId.RegistrationAttempt:
break;
default:
Disconnect(Frame.kClosingReason.ProtocolError, "Packet ID could not be understood at this time.");
break;
}
Console.WriteLine(Id + " says " + data.GetString());
}
}
}

View file

@ -11,14 +11,9 @@ using SockScape.Encryption;
namespace SockScape {
class PlayerConnection : Connection {
private DateTime ConnectionOpened;
private Key Key;
public Cipher Encryptor { get; private set; } = null;
protected override void OnOpen() {
ConnectionOpened = DateTime.UtcNow;
Key = new Key();
Send(Key.GenerateRequestPacket().GetBytes());
}
protected override void OnParse() {
@ -28,28 +23,14 @@ namespace SockScape {
}
protected override void OnReceive(byte[] data) {
Packet packet =
Encryptor == null ? Packet.FromBytes(data)
: Packet.FromBytes(Encryptor.Parse(data));
Packet packet = Packet.FromBytes(data);
if(packet == null) {
Disconnect(Frame.kClosingReason.ProtocolError, "Packet received was not legal.");
return;
}
switch(packet.Id) {
case Packet.kId.KeyExchange:
Key.ParseResponsePacket(packet);
if(!Key.Succeeded) {
Disconnect(Frame.kClosingReason.ProtocolError, "Could not exchange keys.");
return;
}
Encryptor = new Cipher(Key.PrivateKey);
break;
case Packet.kId.LoginAttempt:
break;
switch((kClientServerId)packet.Id) {
default:
Disconnect(Frame.kClosingReason.ProtocolError, "Packet ID could not be understood at this time.");
break;

View file

@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SockScape {
public enum kClientServerId {
}
}

View file

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SockScape {
public enum kInterMasterId {
KeyExchange = 1,
LoginAttempt,
RegistrationAttempt
}
}

View file

@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SockScape {
public enum kIntraMasterId {
InitiationAttempt = 0,
KeyExchange
}
}

View file

@ -9,24 +9,16 @@ namespace SockScape {
class Packet {
private static readonly byte[] MagicNumber = { 0xF0, 0x9F, 0xA6, 0x91 };
public enum kId {
KeyExchange = 0,
LoginAttempt,
RegistrationAttempt
}
public static Packet FromBytes(byte[] raw) {
if(raw.Length < 7)
return null;
Packet packet = new Packet();
if(!Enum.IsDefined(typeof(kId), (int)raw[4]))
return null;
if(!raw.Subset(0, 4).SequenceEqual(MagicNumber))
return null;
packet.Id = (kId)raw[4];
packet.Id = raw[4];
var regionCount = raw[5];
var regionLengths = new List<uint>();
var headerPtr = 6;
@ -66,15 +58,14 @@ namespace SockScape {
}
private List<byte[]> Regions = new List<byte[]>();
public kId Id { get; private set; } = kId.KeyExchange;
public bool IsLegal { get; private set; } = true;
public int Id { get; private set; }
public int RegionCount {
get => Regions.Count;
}
private Packet() { }
protected Packet() { }
public Packet(kId id, params object[] regions) {
public Packet(int id, params object[] regions) {
Id = id;
foreach(var region in regions)
@ -95,9 +86,6 @@ namespace SockScape {
}
public byte[] GetBytes() {
if(!IsLegal)
return null;
var header = new List<byte>();
header.AddRange(MagicNumber);
header.Add((byte)Id);

View file

@ -14,6 +14,12 @@ Master Port = 16670
; url to a web page that prints out the public ip address of the requester
Ip Checker = http://aroltd.com/ip.php
[Database]
Server = aroltd.com
Username = alec
Password = Buddyman5
Database = scape
[Server]
Id = 1
Port = 6770