Skip to content

Commit

Permalink
IP obfuscation
Browse files Browse the repository at this point in the history
  • Loading branch information
anierzad committed Jan 14, 2019
1 parent a9a7161 commit f74cad7
Show file tree
Hide file tree
Showing 26 changed files with 471 additions and 175 deletions.
4 changes: 2 additions & 2 deletions DeployClient/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// 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("0.9.0.0")]
[assembly: AssemblyFileVersion("0.9.0.0")]
[assembly: AssemblyVersion("0.9.1.0")]
[assembly: AssemblyFileVersion("0.9.1.0")]
2 changes: 1 addition & 1 deletion DeployClient/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "deploy-client",
"version": "0.9.0",
"version": "0.9.1",
"main": "gulpfile.js",
"license": "Apache-2.0",
"private": true,
Expand Down
2 changes: 1 addition & 1 deletion DeployClient/project.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module.exports = {
MODULE_VERSION: '00.09.00'
MODULE_VERSION: '00.09.01'
};
16 changes: 11 additions & 5 deletions PolyDeploy/Clients/Core/src/js/services/IPSpecDataService.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,20 @@

// POST
// Create a new IPSpec.
function createSpec(ipAddress) {
function createSpec(name, ipAddress) {

// Make request.
return $http.post(controllerUrl + 'Create?ip=' + ipAddress).then(
return $http.post(controllerUrl + `Create?name=${name}&ip=${ipAddress}`).then(
function (response) {

// Return unpacked data.
return response.data;
return {
err: null,
ipSpec: response.data
}
},
function (response) {
return {
err: response.data.Message
}
});
}

Expand Down
15 changes: 15 additions & 0 deletions PolyDeploy/Clients/Manage/src/css/main.less
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,21 @@

#cantarus-poly-deploy {

#menu {

ul {
list-style: none;
margin: 0;
padding: 0;

li {
list-style: inherit;
margin: 0;
padding: 0;
}
}
}

.can-pagination {
position: relative;
height: 20px;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,33 @@
// Load specs.
refreshSpecs();

$scope.newIp = {
name: '',
ipv4Address: ''
};

$scope.errorMessage = null;

// Dismiss error message.
$scope.dismissError = function () {

$scope.errorMessage = null;
};

// Create spec.
$scope.createSpec = function (ipAddress) {
$scope.createSpec = function (ipSpec) {

// Create the new spec and append it.
IPSpecDataService.createSpec(ipAddress).then(
function (createdSpec) {
IPSpecDataService.createSpec(ipSpec.name, ipSpec.ipv4Address).then(
function (resp) {

if (resp.err) {
$scope.errorMessage = resp.err;
return;
}

// Push on to specs.
$scope.specs.push(createdSpec);
$scope.specs.push(resp.ipSpec);
});
};

Expand Down
66 changes: 0 additions & 66 deletions PolyDeploy/Clients/Manage/src/js/services/APIUserDataService.js

This file was deleted.

16 changes: 10 additions & 6 deletions PolyDeploy/Clients/Manage/src/js/templates/menu.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@

<!-- Menu -->
<div class="col-sm-2">
<ul>
<li><a ui-sref="menu.welcome">Welcome</a></li>
<li><a ui-sref="menu.users">API Users</a></li>
<li><a ui-sref="menu.whitelist">IP Whitelist</a></li>
<li><a ui-sref="menu.events">Event Log</a></li>
</ul>
<div class="panel panel-default">
<div class="panel-body">
<ul>
<li><a ui-sref="menu.welcome">Welcome</a></li>
<li><a ui-sref="menu.users">API Users</a></li>
<li><a ui-sref="menu.whitelist">IP Whitelist</a></li>
<li><a ui-sref="menu.events">Event Log</a></li>
</ul>
</div>
</div>
</div>
<!-- /Menu -->

Expand Down
14 changes: 7 additions & 7 deletions PolyDeploy/Clients/Manage/src/js/templates/users.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,21 @@ <h3 class="panel-title">New API User</h3>
<div class="form-group">
<label class="col-sm-3 control-label">Name</label>
<div class="col-sm-9">
<input type="text" ng-model="newUser.name" />
<input type="text" ng-model="newUser.name" />
</div>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Bypass IP Whitelist</label>
<div class="col-sm-9">
<input type="checkbox" ng-model="newUser.bypassIPWhitelist" />
<input type="checkbox" ng-model="newUser.bypassIPWhitelist" />
</div>
</div>
</div>
<div class="form-group">
<div class="form-group">
<div class="col-sm-offset-3 col-sm-9">
<button type="button" class="btn btn-success" ng-click="createUser(newUser)">Create</button>
<button type="button" class="btn btn-success" ng-click="createUser(newUser)">Create</button>
</div>
</div>
</div>
</div>
<div class="clearfix"></div>
</div>
</div>
Expand Down
37 changes: 25 additions & 12 deletions PolyDeploy/Clients/Manage/src/js/templates/whitelist.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,36 @@
<h3 class="panel-title">New Whitelist Entry</h3>
</div>
<div class="panel-body">

<div class="form-group">
<label class="col-sm-2 control-label">IPv4 Address</label>
<div class="col-sm-10">
<input type="text" ng-model="newIpv4Address" />
</div>
<div class="alert alert-danger alert-dismissable" ng-if="errorMessage">
<button type="button" class="close" ng-click="dismissError()">&times</button>
{{ errorMessage }}
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="button" class="btn btn-success" ng-click="createSpec(newIpv4Address)">Create</button>
<div class="form-horizontal">
<div class="form-group">
<label class="col-sm-3 control-label">Name</label>
<div class="col-sm-9">
<input type="text" ng-model="newIp.name" />
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">IPv4 Address</label>
<div class="col-sm-9">
<input type="text" ng-model="newIp.ipv4Address" />
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-3 col-sm-9">
<button type="button" class="btn btn-success" ng-click="createSpec(newIp)">Create</button>
</div>
</div>
</div>
<div class="clearfix"></div>
</div>
</div>
</div>
<!-- Create User -->
<!-- Create Whitelist Entry -->

<!-- Users Table -->
<!-- Whitelist Table -->
<div class="col-xs-12">
<div class="panel panel-default">
<div class="panel-heading">
Expand All @@ -38,12 +49,14 @@ <h3 class="panel-title">Whitelist Entries</h3>
<table class="table table-striped table-bordered">
<thead>
<tr>
<th>Name</th>
<th>IPv4 Address</th>
<th></th>
</tr>
</thead>
<tbody>
<tr ng-repeat="spec in specs">
<td>{{ spec.Name }}</td>
<td>{{ spec.Address }}</td>
<td><button type="button" class="btn btn-sm btn-danger" ng-click="deleteSpec(spec)">Delete</button></td>
</tr>
Expand All @@ -52,7 +65,7 @@ <h3 class="panel-title">Whitelist Entries</h3>
</div>
</div>
</div>
<!-- /Users Table -->
<!-- /Whitelist Table -->

</div>
<!-- /Content -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,25 @@ public IPSpec Get(int ipSpecId)
}
}

public IPSpec FindByAddress(string address)
public IPSpec Get(string address)
{
using (IDataContext context = DataContext.Instance())
{
return context.ExecuteSingleOrDefault<IPSpec>(
System.Data.CommandType.StoredProcedure,
"{databaseOwner}[{objectQualifier}Cantarus_PolyDeploy_IPSpecByAddress]",
address
);
}
}

public IPSpec GetByName(string name)
{
using (IDataContext context = DataContext.Instance())
{
var repo = context.GetRepository<IPSpec>();

return repo.Find("WHERE Address = @0", address).FirstOrDefault<IPSpec>();
return repo.Find("WHERE [Name] = @0", name).FirstOrDefault<IPSpec>();
}
}

Expand Down
31 changes: 1 addition & 30 deletions PolyDeploy/Components/DataAccess/Models/APIUser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Cantarus.Modules.PolyDeploy.Components.DataAccess.Models
{
[TableName("Cantarus_PolyDeploy_APIUsers")]
[PrimaryKey("APIUserID")]
internal class APIUser
internal class APIUser : Obfuscated
{
private bool prepared;
private string apiKey;
Expand Down Expand Up @@ -151,35 +151,6 @@ public bool PrepareForUse(string apiKey)
return prepared;
}

internal static string GenerateHash(string value, string salt)
{
// Hash.
string hash = CryptoUtilities.SHA256HashString(value + salt);

// Return upper case.
return hash.ToUpper();
}

internal static string GenerateSalt()
{
// Salt length of 16 bytes should be fine for now.
int saltLength = 16;

// Generate random bytes.
byte[] bytes = CryptoUtilities.GenerateRandomBytes(saltLength);

// Convert to string.
string salt = "";

for(int i = 0; i < bytes.Length; i++)
{
salt = string.Format("{0}{1:X2}", salt, bytes[i]);
}

// Return upper case.
return salt.ToUpper();
}

private static string GenerateKey()
{
// Get new guid as string.
Expand Down
Loading

0 comments on commit f74cad7

Please sign in to comment.