Skip to content

Commit 8450627

Browse files
Merge pull request #34 from checkmarx-ltd/q1_2023_integration_branch
Q1 2023 integration branch
2 parents f0e047f + 7cbdded commit 8450627

34 files changed

Lines changed: 1174 additions & 8149 deletions

CxActionShared/CommonActions.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public class CommonActions
4545
private bool wasInit = false;
4646
private const string vsProjectKindWeb = "{E24C65DC-7377-472b-9ABA-BC803B73C61A}";
4747
private const string vsProjectKindSolutionFolder = "{66A26720-8FB5-11D2-AA7E-00C04F688DDE}";
48+
private const string queryDescriptionHeader = "Query Description";
4849
private Dictionary<string, List<string>> fileMapping = new Dictionary<string, List<string>>(StringComparer.InvariantCultureIgnoreCase);
4950

5051
#endregion
@@ -338,8 +339,8 @@ public void NavigateToQueryDescription(object sender, EventArgs e)
338339
rESTApiPortalConfiguration.InitPortalBaseUrl();
339340
string urlToDescription = new QueryDescriptionUrlBuilder().Build(nodeData.QueryId, nodeData.QueryName, nodeData.QueryVersionCode);
340341

341-
WebBrowser webBrowser = new WebBrowser();
342-
webBrowser.Navigate(urlToDescription, "Query Description", null, "Authorization: Bearer " + OidcLoginData.GetOidcLoginDataInstance().AccessToken);
342+
QueryDescriptionForm queryDesc = new QueryDescriptionForm(urlToDescription,OidcLoginData.GetOidcLoginDataInstance().AccessToken, queryDescriptionHeader);
343+
queryDesc.Show();
343344
}
344345
catch (Exception ex)
345346
{
@@ -977,5 +978,6 @@ private void closeView(ToolWindowPane window)
977978
}
978979

979980
#endregion
981+
980982
}
981983
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
using CefSharp;
2+
using CefSharp.Handler;
3+
using Common;
4+
using System;
5+
using System.Web;
6+
using System.Windows.Forms;
7+
8+
namespace CxActionShared
9+
{
10+
public class CommonCustomResourceRequestHandler : CefSharp.Handler.ResourceRequestHandler
11+
{
12+
private readonly System.IO.MemoryStream memoryStream = new System.IO.MemoryStream();
13+
14+
protected override IResponseFilter GetResourceResponseFilter(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IRequest request, IResponse response)
15+
{
16+
return new CefSharp.ResponseFilter.StreamResponseFilter(memoryStream);
17+
}
18+
19+
public class NewCustomRequestHandler : RequestHandler
20+
{
21+
private string _token;
22+
public NewCustomRequestHandler(string token)
23+
{
24+
_token = token;
25+
}
26+
27+
public NewCustomRequestHandler() { }
28+
29+
protected override IResourceRequestHandler GetResourceRequestHandler(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame,
30+
IRequest request, bool isNavigation, bool isDownload, string requestInitiator, ref bool disableDefaultHandling)
31+
{
32+
if (!string.IsNullOrEmpty(_token))
33+
return new CustomResourceRequestHandler(_token);
34+
else
35+
return new CustomResourceRequestHandler();
36+
}
37+
}
38+
39+
public class CustomResourceRequestHandler : ResourceRequestHandler
40+
{
41+
private string _token;
42+
43+
public CustomResourceRequestHandler(string token)
44+
{
45+
_token = token;
46+
}
47+
48+
public CustomResourceRequestHandler() { }
49+
50+
protected override CefReturnValue OnBeforeResourceLoad(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IRequest request,
51+
IRequestCallback callback)
52+
{
53+
Logger.Create().Info("In on before resource load event of chrome browser page.");
54+
var Url = request.Url.ToString();
55+
Uri myUri = new Uri(request.Url);
56+
57+
if (!string.IsNullOrEmpty(_token))
58+
{
59+
var headers = request.Headers;
60+
headers["Authorization"] = $"Bearer {_token}";
61+
request.Headers = headers;
62+
}
63+
64+
if (Url.ToLower().Contains("error="))
65+
{
66+
string error = HttpUtility.ParseQueryString(myUri.Query).Get("error");
67+
MessageBox.Show(error, "Error", MessageBoxButtons.OK);
68+
Logger.Create().Error(error);
69+
browser.CloseBrowser(false);
70+
}
71+
else
72+
{
73+
Logger.Create().Debug("New url " + Url + ".");
74+
}
75+
return CefReturnValue.Continue;
76+
}
77+
}
78+
}
79+
}

CxActionShared/CxActionShared.projitems

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
</Compile>
2222
<Compile Include="$(MSBuildThisFileDirectory)Commands\CommandExecutor.cs" />
2323
<Compile Include="$(MSBuildThisFileDirectory)CommonActions.cs" />
24+
<Compile Include="$(MSBuildThisFileDirectory)CommonCustomResourceRequestHandler.cs" />
2425
<Compile Include="$(MSBuildThisFileDirectory)CommonData.cs" />
2526
<Compile Include="$(MSBuildThisFileDirectory)Connect.cs">
2627
<SubType>Code</SubType>
@@ -104,10 +105,13 @@
104105
<Compile Include="$(MSBuildThisFileDirectory)Services\CxWSResolverWrapper.cs" />
105106
<Compile Include="$(MSBuildThisFileDirectory)Services\EnvDTEConstants.cs" />
106107
<Compile Include="$(MSBuildThisFileDirectory)Services\RESTApi\CxRESTApi.cs" />
108+
<Compile Include="$(MSBuildThisFileDirectory)Services\RESTApi\CxRESTApiCommon.cs" />
107109
<Compile Include="$(MSBuildThisFileDirectory)Services\RESTApi\CxRESTApiPortalConfiguration.cs" />
108110
<Compile Include="$(MSBuildThisFileDirectory)Services\RESTApi\CxRESTApiWebRequestBase.cs" />
109111
<Compile Include="$(MSBuildThisFileDirectory)Services\WinCookieHelper.cs" />
110112
<Compile Include="$(MSBuildThisFileDirectory)ValueObjects\OidcLoginResult.cs" />
113+
<Compile Include="$(MSBuildThisFileDirectory)ValueObjects\RESTApi\CxAppSecCodbashing.cs" />
114+
<Compile Include="$(MSBuildThisFileDirectory)ValueObjects\RESTApi\CxQueryDescription.cs" />
111115
<Compile Include="$(MSBuildThisFileDirectory)ValueObjects\RESTApi\CxRESTApiLoginResponse.cs" />
112116
<Compile Include="$(MSBuildThisFileDirectory)ValueObjects\Results.cs" />
113117
<Compile Include="$(MSBuildThisFileDirectory)ValueObjects\WebPortal\Models\CxPortalConfiguration.cs" />
@@ -212,6 +216,12 @@
212216
<DependentUpon>OpenPercspectiveDialog.cs</DependentUpon>
213217
</Compile>
214218
<Compile Include="$(MSBuildThisFileDirectory)Views\ProjectListEntity.cs" />
219+
<Compile Include="$(MSBuildThisFileDirectory)Views\QueryDescriptionForm.cs">
220+
<SubType>Form</SubType>
221+
</Compile>
222+
<Compile Include="$(MSBuildThisFileDirectory)Views\QueryDescriptionForm.Designer.cs">
223+
<DependentUpon>QueryDescriptionForm.cs</DependentUpon>
224+
</Compile>
215225
<Compile Include="$(MSBuildThisFileDirectory)Views\ScanProcessFrm.cs">
216226
<SubType>Form</SubType>
217227
</Compile>
@@ -256,6 +266,7 @@
256266
</EmbeddedResource>
257267
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Views\BrowserForm.resx">
258268
<DependentUpon>BrowserForm.cs</DependentUpon>
269+
<SubType>Designer</SubType>
259270
</EmbeddedResource>
260271
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Views\DockedView\ConnectionCtrl.resx">
261272
<DependentUpon>ConnectionCtrl.cs</DependentUpon>
@@ -301,11 +312,16 @@
301312
</EmbeddedResource>
302313
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Views\OidcLoginFrm.resx">
303314
<DependentUpon>OidcLoginFrm.cs</DependentUpon>
315+
<SubType>Designer</SubType>
304316
</EmbeddedResource>
305317
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Views\OpenPercspectiveDialog.resx">
306318
<SubType>Designer</SubType>
307319
<DependentUpon>OpenPercspectiveDialog.cs</DependentUpon>
308320
</EmbeddedResource>
321+
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Views\QueryDescriptionForm.resx">
322+
<SubType>Designer</SubType>
323+
<DependentUpon>QueryDescriptionForm.cs</DependentUpon>
324+
</EmbeddedResource>
309325
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Views\ScanProcessFrm.resx">
310326
<SubType>Designer</SubType>
311327
<DependentUpon>ScanProcessFrm.cs</DependentUpon>
@@ -328,6 +344,12 @@
328344
</ItemGroup>
329345
<ItemGroup>
330346
<Content Include="$(MSBuildThisFileDirectory)Resources\1.ico" />
347+
<None Include="$(MSBuildThisFileDirectory)Resources\Checkmarx-X31.ico" />
348+
<None Include="$(MSBuildThisFileDirectory)Resources\Checkmarx-X3.ico" />
349+
<None Include="$(MSBuildThisFileDirectory)Resources\Checkmarx-X2.ico" />
350+
<None Include="$(MSBuildThisFileDirectory)Resources\Checkmarx-X1.ico" />
351+
<None Include="$(MSBuildThisFileDirectory)Resources\Checkmarx-X.ico" />
352+
<Content Include="$(MSBuildThisFileDirectory)Resources\close24.png" />
331353
<Content Include="$(MSBuildThisFileDirectory)Resources\cx.gif" />
332354
<Content Include="$(MSBuildThisFileDirectory)Resources\cx.ico" />
333355
<Content Include="$(MSBuildThisFileDirectory)Resources\Disabled.png" />

CxActionShared/Entities/LoginData.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ public class LoginData : IEntity
6363
private bool _saveSastScan;
6464
private bool _manageResultsComment;
6565
private bool _manageResultsExploitability;
66+
private int _bindProjectCount = -1;
6667

6768
#endregion
6869

@@ -275,6 +276,7 @@ public bool DisableConnectionOptimizations
275276
public bool ManageResultsComment { get => _manageResultsComment; set => _manageResultsComment = value; }
276277
public bool ManageResultsExploitability { get => _manageResultsExploitability; set => _manageResultsExploitability = value; }
277278

279+
public int BindProjectCount { get { return _bindProjectCount; } set { _bindProjectCount = value; } }
278280
#endregion [ Properties ]
279281

280282
#region [ Public Methods ]

CxActionShared/Helpers/DrawingHelper/DrawingHelper.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,14 @@ public static void SetNodeColor(Microsoft.Msagl.Drawing.Graph graph, GraphItem n
484484
SetEdgeByNodes(graph, nodeId1.UniqueID, nodeId2.UniqueID);
485485
}
486486

487+
public static Image GetResourceCloseByAssembly()
488+
{
489+
var assemName = Assembly.GetCallingAssembly().GetName();
490+
if (assemName.Name.Equals("CxViewerAction"))
491+
return global::CxViewerAction.Resources.CxViewerResources.close24;
492+
else
493+
return global::CxViewerAction.Resources.CxViewerResources2019.close24;
494+
}
487495
#endregion
488496

489497
#region Draw Nodes

CxActionShared/Helpers/ScanHelper.cs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ private ProjectScanStatuses ExecuteScan(Project project, ref CxWSQueryVulnerabil
333333

334334
if (!bCancel && !isIISStoped)
335335
{
336-
ShowScanData(ref scanData, ref scanId, client);
336+
ShowScanData(ref scanData, ref scanId, client);
337337
}
338338
else
339339
{
@@ -441,19 +441,31 @@ private void ShowScanData(ref CxWSQueryVulnerabilityData[] scanData, ref long sc
441441

442442
CommonData.SelectedScanId = id;
443443
String path = PerspectiveHelper.GetScanXML(id);
444-
ScanReportInfo scanReportInfo = new ScanReportInfo();
445-
scanReportInfo.Path = path;
446-
scanReportInfo.Id = id;
444+
447445
LoginData.BindProject projectToUpdate = _scan.LoginResult.AuthenticationData.BindedProjects.Find(delegate (LoginData.BindProject bp)
448446
{
449447
return bp.BindedProjectId == CommonData.ProjectId;
450448
}
451449
);
452450

453-
projectToUpdate.ScanReports = new List<ScanReportInfo>();
454-
projectToUpdate.ScanReports.Add(scanReportInfo);
451+
CxWSResponseScansDisplayData cxWSResponseScansDisplayData = PerspectiveHelper.GetScansDisplayData(CommonData.ProjectId);
452+
foreach (ScanDisplayData item in cxWSResponseScansDisplayData.ScanList)
453+
{
454+
455+
// Add relation to scanned project and scan report
456+
ScanReportInfo scanReportInfo = new ScanReportInfo { Id = item.ScanID };
457+
string minutes = item.QueuedDateTime.Minute.ToString().Length > 1 ? item.QueuedDateTime.Minute.ToString() : "0" + item.QueuedDateTime.Minute;
455458

459+
scanReportInfo.Name = string.Format("{0}/{1}/{2} {3}:{4}", item.QueuedDateTime.Month,
460+
item.QueuedDateTime.Day,
461+
item.QueuedDateTime.Year,
462+
item.QueuedDateTime.Hour,
463+
minutes);
464+
465+
bindProject.AddScanReport(scanReportInfo);
466+
}
456467
LoginHelper.Save(_scan.LoginResult.AuthenticationData);
468+
CommonActionsInstance.getInstance().ReportDoPrevResults();
457469
});
458470

459471
bgWork.DoWork();
7.2 KB
Binary file not shown.
7.2 KB
Binary file not shown.
7.2 KB
Binary file not shown.
7.2 KB
Binary file not shown.

0 commit comments

Comments
 (0)