Skip to content

Commit 5b91a19

Browse files
authored
Merge pull request CactuseSecurity#3447 from abarz722/develop
Several small fixes
2 parents 71f79e2 + f99c38b commit 5b91a19

File tree

14 files changed

+689
-521
lines changed

14 files changed

+689
-521
lines changed

roles/api/files/replace_metadata.json

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10480,6 +10480,17 @@
1048010480
}
1048110481
],
1048210482
"select_permissions": [
10483+
{
10484+
"role": "approver",
10485+
"permission": {
10486+
"columns": [
10487+
"ticket_id",
10488+
"owner_id"
10489+
],
10490+
"filter": {}
10491+
},
10492+
"comment": ""
10493+
},
1048310494
{
1048410495
"role": "auditor",
1048510496
"permission": {
@@ -10491,6 +10502,28 @@
1049110502
},
1049210503
"comment": ""
1049310504
},
10505+
{
10506+
"role": "fw-admin",
10507+
"permission": {
10508+
"columns": [
10509+
"ticket_id",
10510+
"owner_id"
10511+
],
10512+
"filter": {}
10513+
},
10514+
"comment": ""
10515+
},
10516+
{
10517+
"role": "implementer",
10518+
"permission": {
10519+
"columns": [
10520+
"ticket_id",
10521+
"owner_id"
10522+
],
10523+
"filter": {}
10524+
},
10525+
"comment": ""
10526+
},
1049410527
{
1049510528
"role": "modeller",
1049610529
"permission": {
@@ -10501,6 +10534,39 @@
1050110534
"filter": {}
1050210535
},
1050310536
"comment": ""
10537+
},
10538+
{
10539+
"role": "planner",
10540+
"permission": {
10541+
"columns": [
10542+
"ticket_id",
10543+
"owner_id"
10544+
],
10545+
"filter": {}
10546+
},
10547+
"comment": ""
10548+
},
10549+
{
10550+
"role": "requester",
10551+
"permission": {
10552+
"columns": [
10553+
"ticket_id",
10554+
"owner_id"
10555+
],
10556+
"filter": {}
10557+
},
10558+
"comment": ""
10559+
},
10560+
{
10561+
"role": "reviewer",
10562+
"permission": {
10563+
"columns": [
10564+
"ticket_id",
10565+
"owner_id"
10566+
],
10567+
"filter": {}
10568+
},
10569+
"comment": ""
1050410570
}
1050510571
]
1050610572
},

roles/lib/files/FWO.Data/IpProtocol.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,10 @@ public class IpProtocol
1010

1111
[JsonProperty("ip_proto_name"), JsonPropertyName("ip_proto_name")]
1212
public string Name { get; set; } = "";
13+
14+
public bool HasPorts()
15+
{
16+
return Id == 6 || Id == 17;
17+
}
1318
}
1419
}

roles/lib/files/FWO.Data/NetworkProtocol.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,17 @@ public class NetworkProtocol
1313

1414

1515
public NetworkProtocol()
16-
{}
16+
{ }
1717

1818
public NetworkProtocol(IpProtocol i)
1919
{
2020
Id = i.Id;
2121
Name = i.Name;
2222
}
23+
24+
public bool HasPorts()
25+
{
26+
return Id == 6 || Id == 17;
27+
}
2328
}
2429
}

roles/lib/files/FWO.Services/NetworkServiceComparer.cs

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,40 @@ public bool Equals(NetworkService? service1, NetworkService? service2)
1818
return false;
1919
}
2020

21+
if (CompareProtTypes(service1, service2))
22+
{
23+
return true;
24+
}
25+
2126
int destPortEnd1 = service1.DestinationPortEnd ?? service1.DestinationPort ?? 0;
2227
int destPortEnd2 = service2.DestinationPortEnd ?? service2.DestinationPort ?? 0;
2328

24-
return (!option.SvcRegardPortAndProt || service1.ProtoId == service2.ProtoId
25-
&& service1.DestinationPort == service2.DestinationPort
26-
&& destPortEnd1 == destPortEnd2)
29+
return (!option.SvcRegardPortAndProt || (service1.ProtoId == service2.ProtoId &&
30+
service1.DestinationPort == service2.DestinationPort && destPortEnd1 == destPortEnd2))
2731
&& (!option.SvcRegardName || service1.Name == service2.Name);
2832
}
2933

3034
public int GetHashCode(NetworkService service)
3135
{
36+
if (IsProtType(service.ProtoId))
37+
{
38+
return (option.SvcRegardPortAndProt ? HashCode.Combine(service.ProtoId) : 0)
39+
^ (option.SvcRegardName ? HashCode.Combine(service.Name) : 0);
40+
}
3241
int destPortEnd = service.DestinationPortEnd ?? service.DestinationPort ?? 0;
3342
return (option.SvcRegardPortAndProt ? HashCode.Combine(service.ProtoId, service.DestinationPort, destPortEnd) : 0)
3443
^ (option.SvcRegardName ? HashCode.Combine(service.Name) : 0);
3544
}
45+
46+
private static bool IsProtType(int? protoId)
47+
{
48+
return protoId != null && protoId != 1 && protoId != 6 && protoId != 17;
49+
}
50+
51+
private static bool CompareProtTypes(NetworkService service1, NetworkService service2)
52+
{
53+
return IsProtType(service1.ProtoId) && IsProtType(service2.ProtoId) && service1.ProtoId == service2.ProtoId;
54+
}
3655
}
3756

3857
public class NetworkServiceGroupComparer(RuleRecognitionOption option) : IEqualityComparer<NetworkService?>
@@ -57,18 +76,18 @@ public bool Equals(NetworkService? service1, NetworkService? service2)
5776
return false;
5877
}
5978

60-
return service1.ServiceGroupFlats.ToList().ConvertAll(g => g.Object).ToList()
79+
return service1.ServiceGroupFlats.ToList().ConvertAll(g => g.Object)
6180
.Except([.. service2.ServiceGroupFlats.ToList().ConvertAll(g => g.Object)], networkServiceComparer).ToList().Count == 0
62-
&& service2.ServiceGroupFlats.ToList().ConvertAll(g => g.Object).ToList()
81+
&& service2.ServiceGroupFlats.ToList().ConvertAll(g => g.Object)
6382
.Except([.. service1.ServiceGroupFlats.ToList().ConvertAll(g => g.Object)], networkServiceComparer).ToList().Count == 0;
6483
}
6584

6685
public int GetHashCode(NetworkService serviceGrp)
6786
{
6887
int hashCode = 0;
69-
foreach(var svc in serviceGrp.ServiceGroupFlats.Where(s => s.Object?.Type.Name != ServiceType.Group).ToList())
88+
foreach(var svc in serviceGrp.ServiceGroupFlats.Select(sg => sg.Object).Where(s => s?.Type.Name != ServiceType.Group).ToList())
7089
{
71-
hashCode ^= (svc.Object != null ? networkServiceComparer.GetHashCode(svc.Object) : 0);
90+
hashCode ^= svc != null ? networkServiceComparer.GetHashCode(svc) : 0;
7291
}
7392
return hashCode ^ (option.SvcRegardGroupName ? HashCode.Combine(serviceGrp.Name) : 0);
7493
}

roles/lib/files/FWO.Services/WfHandler.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ public async Task<bool> Init(bool fetchData = false, List<int>? ownerIds = null,
156156
}
157157
ActionHandler = new (apiConnection, this, UserGroups, usedInMwServer);
158158
await ActionHandler.Init();
159-
dbAcc = new WfDbAccess(DisplayMessageInUi, userConfig, apiConnection, ActionHandler, AuthUser == null || AuthUser.IsInRole(Roles.Admin)){};
159+
dbAcc = new WfDbAccess(DisplayMessageInUi, userConfig, apiConnection, ActionHandler, AuthUser == null || AuthUser.IsInRole(Roles.Admin) || AuthUser.IsInRole(Roles.Auditor)){};
160160
Devices = await apiConnection.SendQueryAsync<List<Device>>(DeviceQueries.getDeviceDetails);
161161
AllOwners = await apiConnection.SendQueryAsync<List<FwoOwner>>(OwnerQueries.getOwners);
162162
await stateMatrixDict.Init(Phase, apiConnection);
@@ -266,12 +266,12 @@ public void SetContinueEnv(ObjAction action)
266266

267267
// Tickets
268268

269-
public async Task<WfTicket?> ResolveTicket(long ticketId, bool checkOwner = false)
269+
public async Task<WfTicket?> ResolveTicket(long ticketId)
270270
{
271271
WfTicket? ticket = null;
272272
if(dbAcc != null)
273273
{
274-
ticket = await dbAcc.FetchTicket(ticketId, checkOwner ? AllOwners.ConvertAll(x => x.Id) : null);
274+
ticket = await dbAcc.FetchTicket(ticketId, userConfig.ReqOwnerBased ? AllOwners.ConvertAll(x => x.Id) : null);
275275
if(ticket != null)
276276
{
277277
SetTicketEnv(ticket);

0 commit comments

Comments
 (0)