Skip to content

Commit 2a5eb6d

Browse files
Q4 integration branch 2023 (#44)
Release 2023 Q4 - 9.00.27
1 parent 34a7d38 commit 2a5eb6d

19 files changed

Lines changed: 187 additions & 91 deletions

File tree

Common/Code/Constants.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public class Constants
6161
public const string TOKEN_ENDPOINT = SAST_PREFIX + "/identity/connect/token";
6262
public const string SAVE_SAST_SCAN = "save-sast-scan";
6363
public const string MANAGE_RESULTS_COMMENT = "manage-result-comment";
64-
public const string MANAGE_RESULTS_EXPLOITABILITY = "manage-result-exploitability";
64+
public const string MANAGE_RESULTS_EXPLOITABILITY = "set-result-state-notexploitable";
6565

6666
}
6767
}

CxActionShared/CxActionShared.projitems

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@
111111
<Compile Include="$(MSBuildThisFileDirectory)Services\WinCookieHelper.cs" />
112112
<Compile Include="$(MSBuildThisFileDirectory)ValueObjects\OidcLoginResult.cs" />
113113
<Compile Include="$(MSBuildThisFileDirectory)ValueObjects\RESTApi\CxAppSecCodbashing.cs" />
114+
<Compile Include="$(MSBuildThisFileDirectory)ValueObjects\RESTApi\CxProjectDetails.cs" />
114115
<Compile Include="$(MSBuildThisFileDirectory)ValueObjects\RESTApi\CxQueryDescription.cs" />
115116
<Compile Include="$(MSBuildThisFileDirectory)ValueObjects\RESTApi\CxRESTApiLoginResponse.cs" />
116117
<Compile Include="$(MSBuildThisFileDirectory)ValueObjects\Results.cs" />

CxActionShared/Entities/LoginData.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ public class LoginData : IEntity
6464
private bool _manageResultsComment;
6565
private bool _manageResultsExploitability;
6666
private int _bindProjectCount = -1;
67+
private bool _enableTLSOrSSLServerCertificateValidation = true;
6768

6869
#endregion
6970

@@ -277,6 +278,9 @@ public bool DisableConnectionOptimizations
277278
public bool ManageResultsExploitability { get => _manageResultsExploitability; set => _manageResultsExploitability = value; }
278279

279280
public int BindProjectCount { get { return _bindProjectCount; } set { _bindProjectCount = value; } }
281+
282+
public bool EnableTLSOrSSLServerCertificateValidation { get => _enableTLSOrSSLServerCertificateValidation; set => _enableTLSOrSSLServerCertificateValidation = value; }
283+
280284
#endregion [ Properties ]
281285

282286
#region [ Public Methods ]

CxActionShared/Helpers/HttpHelper.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ public static string Get(string url)
2424
try
2525
{
2626
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
27-
ServicePointManager.ServerCertificateValidationCallback += delegate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true; };
27+
//This class is not in use. To avoid SSL_Verification_ByPass vulnarability by default SSL certificate validation enabled
28+
ServicePointManager.ServerCertificateValidationCallback += delegate (object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return false; };
2829
response = (HttpWebResponse)request.GetResponse();
2930

3031
using (StreamReader responseStream = new StreamReader(response.GetResponseStream()))

CxActionShared/Helpers/LoginHelper.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
using CxViewerAction.Views;
1515
using CxViewerAction.WebPortal;
1616
using CefSharp;
17+
using CxViewerAction.MenuLogic;
1718

1819
namespace CxViewerAction.Helpers
1920
{
@@ -469,6 +470,8 @@ internal static void DoLogout()
469470
LoginData login = LoadSaved();
470471
Logger.Create().Info("Logging out, clearing authentication data.");
471472
OidcLoginData oidcLoginData = OidcLoginData.GetOidcLoginDataInstance();
473+
BindProjectLogic _logic = new BindProjectLogic();
474+
_logic.UnBindProject(true);
472475
oidcLoginData.AccessToken = null;
473476
oidcLoginData.RefreshToken = null;
474477
oidcLoginData.AccessTokenExpiration = -1;

CxActionShared/Helpers/ScanHelper.cs

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313
using System.Threading;
1414
using CxViewerAction.CxVSWebService;
1515
using Common;
16+
using System.Net;
17+
using System.IO;
18+
using System.Text;
19+
using CxViewerAction.ValueObjects;
20+
using System.Web.Script.Serialization;
1621

1722
namespace CxViewerAction.Helpers
1823
{
@@ -27,7 +32,7 @@ internal class ScanHelper : IScanHelper
2732
static bool _cancelPressed;
2833
static Upload _uploadSettings;
2934
readonly IConfigurationHelper _configurationHelper;
30-
35+
private string _apiProjectDetails = "projects/{0}";
3136

3237
public ScanHelper(IConfigurationHelper configurationHelper)
3338
{
@@ -427,8 +432,9 @@ private void ShowScanData(ref CxWSQueryVulnerabilityData[] scanData, ref long sc
427432

428433
bindProject.BindedProjectId = scanStatus.ProjectId;
429434
CommonData.ProjectId = scanStatus.ProjectId;
430-
CommonData.IsProjectPublic = scanStatus.IsPublic;
431-
bindProject.IsPublic = scanStatus.IsPublic;
435+
bool isPublic= GetProjectDetails(scanStatus.ProjectId);
436+
CommonData.IsProjectPublic = isPublic;
437+
bindProject.IsPublic = isPublic;
432438
bindProject.IsBound = true;
433439
}
434440
bindProject.SelectedScanId = id;
@@ -471,6 +477,30 @@ private void ShowScanData(ref CxWSQueryVulnerabilityData[] scanData, ref long sc
471477
bgWork.DoWork();
472478
}
473479

480+
private bool GetProjectDetails(long projectId)
481+
{
482+
string responseText = string.Empty;
483+
484+
CxRESTApiCommon rESTApiPortalConfiguration = new CxRESTApiCommon(string.Format(_apiProjectDetails, projectId));
485+
HttpWebResponse response = rESTApiPortalConfiguration.InitPortalBaseUrl();
486+
487+
if (response != null && response.StatusCode == HttpStatusCode.OK)
488+
{
489+
using (StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8))
490+
{
491+
responseText = reader.ReadToEnd();
492+
}
493+
}
494+
495+
if (!string.IsNullOrEmpty(responseText))
496+
{
497+
CxProjectDetails projectDetails = new CxProjectDetails();
498+
JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer();
499+
projectDetails = (CxProjectDetails)javaScriptSerializer.Deserialize(responseText, typeof(CxProjectDetails));
500+
return projectDetails.isPublic;
501+
}
502+
return false;
503+
}
474504
private StatusScanResult UpdateScanStatus(ref bool bCancel, bool backgroundMode, IScanView view, BackgroundWorkerHelper bg, CxWebServiceClient client, ref bool isIISStoped)
475505
{
476506
// Get current scan status

CxActionShared/Helpers/ZipHelper.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ private static byte[] Compress(Project[] projects, string sExcludeFile, string s
135135
{
136136
foreach (string filePath in p.FilePathList) // scan only the file selected
137137
{
138-
if (Directory.Exists(p.RootPath))
138+
if (Directory.Exists(p.RootPath) && !oZip.ContainsEntry(filePath))
139139
{
140140
Logger.Create().Debug("Zip file: " + p.FilePathList);
141141
WriteEntryToZip(oZip, Path.GetFileName(filePath), filePath);
@@ -222,9 +222,12 @@ public static bool WriteDirectoryToZip(ZipOutputStream zipStream, string inputFo
222222

223223
foreach (string file in filesToZip)
224224
{
225-
WriteEntryToZip(zipStream, file.Remove(0, trimLength), file);
226-
227-
entryCounter++;
225+
bool isEntryExists = zipStream.ContainsEntry(file.Remove(0, trimLength)); // checking is entry already exists in zipoutputsteam or not
226+
if (!isEntryExists)
227+
{
228+
WriteEntryToZip(zipStream, file.Remove(0, trimLength), file);
229+
entryCounter++;
230+
}
228231

229232
// Flush every 20 entries
230233
if (entryCounter % 20 == 0)

CxActionShared/MenuLogic/BindProjectLogic.cs

Lines changed: 36 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -99,47 +99,52 @@ void DoRetrieveResults(Entities.Project project)
9999
}
100100
}
101101

102-
public CommandStatus GetStatus()
102+
public void UnBindProject(bool unBindAllData = false)
103103
{
104-
Logger.Create().Info("Bind operation getting status.");
105-
CommandStatus status = CommandStatus.CommandStatusNull;
106-
_isBinded = false;
107-
bool currentBind = false;
108-
status = (CommandStatus)CommandStatus.CommandStatusSupported |
109-
CommandStatus.CommandStatusEnabled;
110104
LoginData login = LoginHelper.LoadSaved();
111-
Logger.Create().Debug("For bind operation saved login data loaded.");
112-
///<summary>
113-
/// Changes for Plug-488 clear bound project when switching to another solution
114-
///</summary>
115-
///Start
105+
LoginData.BindProject unBindProject = null;
116106
if (login.BindedProjects != null)
117107
{
118-
Logger.Create().Info("GetSatus():Checking bound projects not empty.");
119-
Entities.Project selectedProject2 = CommonActionsInstance.getInstance().GetSelectedProject();
120-
foreach (LoginData.BindProject project in login.BindedProjects)
121-
{
122-
Logger.Create().Info("Checking for current solution bound projects.");
123-
if (selectedProject2.RootPath == project.RootPath && selectedProject2.ProjectName == project.ProjectName)
124-
{
125-
currentBind = true;
126-
}
127-
}
128-
CommonData.IsWorkingOffline = false;
129-
LoginHelper.Save(login);
130-
131-
if (!currentBind)
108+
if (unBindAllData)
132109
{
133-
Logger.Create().Info("Checking for current solution bound projects false.");
134110
login.BindedProjects.Clear();
135-
Logger.Create().Info("Clearing for current solution bound projects.");
136111
CommonData.IsProjectBound = false;
137112
LoginHelper.IsLogged = false;
138-
LoginHelper.Save(login);
139-
Logger.Create().Info("Saving data in conf file.");
113+
CommonData.IsWorkingOffline = false;
114+
Logger.Create().Info("Clearing for current solution bound projects.");
140115
}
116+
else
117+
{
118+
Logger.Create().Info("GetSatus():Checking bound projects not empty.");
119+
Entities.Project selectedProject2 = CommonActionsInstance.getInstance().GetSelectedProject();
120+
foreach (LoginData.BindProject project in login.BindedProjects)
121+
{
122+
Logger.Create().Info("Checking for current solution bound projects.");
123+
if (selectedProject2.RootPath == project.RootPath && selectedProject2.ProjectName == project.ProjectName)
124+
{
125+
unBindProject = project;
126+
}
127+
}
128+
129+
if (unBindProject != null)
130+
{
131+
login.BindedProjects.Remove(unBindProject);
132+
}
133+
}
134+
LoginHelper.Save(login);
135+
Logger.Create().Info("Saving data in conf file.");
141136
}
142-
///End
137+
}
138+
139+
public CommandStatus GetStatus()
140+
{
141+
Logger.Create().Info("Bind operation getting status.");
142+
CommandStatus status = CommandStatus.CommandStatusNull;
143+
_isBinded = false;
144+
status = (CommandStatus)CommandStatus.CommandStatusSupported |
145+
CommandStatus.CommandStatusEnabled;
146+
LoginData login = LoginHelper.LoadSaved();
147+
Logger.Create().Debug("For bind operation saved login data loaded.");
143148
Logger.Create().Info("Bind logic getting selected project.");
144149
Entities.Project selectedProject = CommonActionsInstance.getInstance().GetSelectedProject();
145150
if (selectedProject == null)

CxActionShared/Services/CxWebServiceClient.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Net.Security;
77
using CxViewerAction.CxVSWebService;
88
using CxViewerAction.Entities.WebServiceEntity;
9+
using Common;
910

1011
namespace CxViewerAction.Services
1112
{
@@ -61,7 +62,21 @@ public class CxWebServiceClient
6162
/// <param name="server">server url</param>
6263
public CxWebServiceClient(LoginData pLogin)
6364
{
64-
ServicePointManager.ServerCertificateValidationCallback += delegate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true; };
65+
ServicePointManager. ServerCertificateValidationCallback += delegate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
66+
{
67+
// No SSL policy errors, certificate is considered valid Or Certificate validation is disabled
68+
if (!pLogin.EnableTLSOrSSLServerCertificateValidation || sslPolicyErrors == SslPolicyErrors.None)
69+
return true;
70+
else
71+
{
72+
// Log or handle SSL policy errors
73+
Logger.Create().Error("Certificate error: " + sslPolicyErrors.ToString());
74+
75+
// Example: Check if the certificate is issued by a specific CA or meets specific criteria
76+
// Return false to reject the certificate
77+
return false;
78+
}
79+
};
6580

6681
CxViewerAction.Services.CxWSResolverWrapper resolver = new CxViewerAction.Services.CxWSResolverWrapper { Url = pLogin.Server };
6782
resolver.DisableConnectionOptimizations = pLogin.DisableConnectionOptimizations;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace CxViewerAction.ValueObjects
2+
{
3+
public class CxProjectDetails
4+
{
5+
public long id { get; set; }
6+
public string name { get; set; }
7+
public bool isPublic { get; set; }
8+
public long teamId { get; set; }
9+
}
10+
}

0 commit comments

Comments
 (0)