Skip to content

Commit cf9f9a0

Browse files
committed
LGTM for xamarin-android should be done
1 parent 7348c7c commit cf9f9a0

File tree

10 files changed

+39
-164
lines changed

10 files changed

+39
-164
lines changed

.lgtm.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
queries:
2+
- exclude: cs/campaign/constantine

build-tools/xa-prep-tasks/Xamarin.Android.BuildTools.PrepTasks/DownloadUri.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,17 @@ public override bool Execute ()
4343

4444
var source = cancellationTokenSource = new CancellationTokenSource ();
4545
var tasks = new Task<ITaskItem> [SourceUris.Length];
46-
using (var client = new HttpClient ()) {
46+
47+
// LGTM recommendation
48+
//
49+
// Using HttpClient without providing a platform specific handler (WinHttpHandler or CurlHandler) where the CheckCertificateRevocationList property is set
50+
// to true, will allow revoked certificates to be accepted by the HttpClient as valid.
51+
//
52+
var handler = new HttpClientHandler {
53+
CheckCertificateRevocationList = true,
54+
};
55+
56+
using (var client = new HttpClient (handler)) {
4757
client.Timeout = TimeSpan.FromHours (3);
4858
for (int i = 0; i < SourceUris.Length; ++i) {
4959
tasks [i] = DownloadFile (client, source, SourceUris [i], DestinationFiles [i]);

build-tools/xaprepare/xaprepare/Application/Utilities.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -471,12 +471,21 @@ static decimal SignificantDigits (decimal number, int maxDigitCount)
471471
return (success, size);
472472
}
473473

474+
public static HttpClient CreateHttpClient ()
475+
{
476+
var handler = new HttpClientHandler {
477+
CheckCertificateRevocationList = true,
478+
};
479+
480+
return new HttpClient (handler);
481+
}
482+
474483
public static async Task<(bool success, ulong size, HttpStatusCode status)> GetDownloadSizeWithStatus (Uri url)
475484
{
476485
TimeSpan delay = ExceptionRetryInitialDelay;
477486
for (int i = 0; i < ExceptionRetries; i++) {
478487
try {
479-
using (var httpClient = new HttpClient ()) {
488+
using (HttpClient httpClient = CreateHttpClient ()) {
480489
httpClient.Timeout = WebRequestTimeout;
481490
var req = new HttpRequestMessage (HttpMethod.Head, url);
482491
req.Headers.ConnectionClose = true;
@@ -524,7 +533,7 @@ public static async Task<bool> Download (Uri url, string targetFile, DownloadSta
524533

525534
static async Task DoDownload (Uri url, string targetFile, DownloadStatus status)
526535
{
527-
using (var httpClient = new HttpClient ()) {
536+
using (HttpClient httpClient = CreateHttpClient ()) {
528537
httpClient.Timeout = WebRequestTimeout;
529538
Log.DebugLine ("Calling GetAsync");
530539
HttpResponseMessage resp = await httpClient.GetAsync (url, HttpCompletionOption.ResponseHeadersRead);
@@ -820,7 +829,7 @@ public static string GetStringFromStdout (ProcessRunner runner, bool throwOnErro
820829
LogError ($"failed with exit code {runner.ExitCode}");
821830
return String.Empty;
822831
}
823-
832+
824833
string ret = sw.ToString ();
825834
if (trimTrailingWhitespace)
826835
return ret.TrimEnd ();

build-tools/xaprepare/xaprepare/Steps/Step_Get_Windows_Binutils.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ string GetStampFile (string file, string destinationDirectory, string ndkVersion
157157
async Task<bool> FetchFiles (Dictionary<string, string> neededFiles, string destinationDirectory, Uri url)
158158
{
159159
Utilities.CreateDirectory (destinationDirectory);
160-
using (var httpClient = new HttpClient ()) {
160+
using (HttpClient httpClient = Utilities.CreateHttpClient ()) {
161161
bool success;
162162
long size;
163163

src-ThirdParty/NUnitLite/Constraints/BinarySerializableConstraint.cs

Lines changed: 0 additions & 104 deletions
This file was deleted.

src-ThirdParty/NUnitLite/Constraints/ConstraintExpression.cs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -350,20 +350,6 @@ public UniqueItemsConstraint Unique
350350

351351
#endregion
352352

353-
#region BinarySerializable
354-
355-
#if !NETCF && !SILVERLIGHT
356-
/// <summary>
357-
/// Returns a constraint that tests whether an object graph is serializable in binary format.
358-
/// </summary>
359-
public BinarySerializableConstraint BinarySerializable
360-
{
361-
get { return (BinarySerializableConstraint)this.Append(new BinarySerializableConstraint()); }
362-
}
363-
#endif
364-
365-
#endregion
366-
367353
#region XmlSerializable
368354

369355
#if !SILVERLIGHT

src-ThirdParty/NUnitLite/Constraints/ConstraintFactory.cs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -297,20 +297,6 @@ public UniqueItemsConstraint Unique
297297

298298
#endregion
299299

300-
#region BinarySerializable
301-
302-
#if !NETCF && !SILVERLIGHT
303-
/// <summary>
304-
/// Returns a constraint that tests whether an object graph is serializable in binary format.
305-
/// </summary>
306-
public BinarySerializableConstraint BinarySerializable
307-
{
308-
get { return new BinarySerializableConstraint(); }
309-
}
310-
#endif
311-
312-
#endregion
313-
314300
#region XmlSerializable
315301

316302
#if !SILVERLIGHT

src-ThirdParty/NUnitLite/Is.cs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -157,20 +157,6 @@ public static UniqueItemsConstraint Unique
157157

158158
#endregion
159159

160-
#region BinarySerializable
161-
162-
#if !NETCF && !SILVERLIGHT
163-
/// <summary>
164-
/// Returns a constraint that tests whether an object graph is serializable in binary format.
165-
/// </summary>
166-
public static BinarySerializableConstraint BinarySerializable
167-
{
168-
get { return new BinarySerializableConstraint(); }
169-
}
170-
#endif
171-
172-
#endregion
173-
174160
#region XmlSerializable
175161

176162
#if !SILVERLIGHT

src/Mono.Android/Xamarin.Android.Net/AuthDigestSession.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Adapted from:
33
//
44
// System.Net.DigestClient.cs
5-
//
5+
//
66
// Authors:
77
// Greg Reinacker (gregr@rassoc.com)
88
// Sebastien Pouliot (spouliot@motus.com)
@@ -55,7 +55,7 @@ public string? QOP {
5555
}
5656

5757
public string CNonce {
58-
get {
58+
get {
5959
if (_cnonce == null) {
6060
// 15 is a multiple of 3 which is better for base64 because it
6161
// wont end with '=' and risk messing up the server parsing
@@ -73,20 +73,20 @@ public DateTime LastUse {
7373
}
7474

7575
[System.Diagnostics.CodeAnalysis.SuppressMessage ("Security", "CA5351:Do Not Use Broken Cryptographic Algorithms", Justification = "Only supported algorithm by RFC2617.")]
76-
public bool Parse (string challenge)
76+
public bool Parse (string challenge)
7777
{
7878
parser = new AuthDigestHeaderParser (challenge);
7979
if (!parser.Parse ())
8080
return false;
8181

8282
// build the hash object (only MD5 is defined in RFC2617)
8383
if ((parser.Algorithm == null) || (parser.Algorithm.StartsWith ("MD5", StringComparison.OrdinalIgnoreCase)))
84-
hash = MD5.Create ();
84+
hash = MD5.Create (); // lgtm [cs/weak-crypto] This is part of RFC2617 and we cannot change the algorithm here.
8585

8686
return true;
8787
}
8888

89-
string? HashToHexString (string toBeHashed)
89+
string? HashToHexString (string toBeHashed)
9090
{
9191
if (hash == null)
9292
return null;
@@ -100,26 +100,26 @@ public bool Parse (string challenge)
100100
return sb.ToString ();
101101
}
102102

103-
string? HA1 (string username, string password)
103+
string? HA1 (string username, string password)
104104
{
105105
string ha1 = $"{username}:{Realm}:{password}";
106106
if (String.Compare (Algorithm, "md5-sess", StringComparison.OrdinalIgnoreCase) == 0)
107107
ha1 = $"{HashToHexString (ha1)}:{Nonce}:{CNonce}";
108108
return HashToHexString (ha1);
109109
}
110110

111-
string? HA2 (HttpURLConnection webRequest)
111+
string? HA2 (HttpURLConnection webRequest)
112112
{
113113
var uri = new Uri (webRequest.URL?.ToString ()!);
114114
string ha2 = $"{webRequest.RequestMethod}:{uri.PathAndQuery}";
115115
if (QOP == "auth-int") {
116116
// TODO
117117
// ha2 += String.Format (":{0}", hentity);
118-
}
118+
}
119119
return HashToHexString (ha2);
120120
}
121121

122-
string? Response (string username, string password, HttpURLConnection webRequest)
122+
string? Response (string username, string password, HttpURLConnection webRequest)
123123
{
124124
string response = $"{HA1 (username, password)}:{Nonce}:";
125125
if (QOP != null)
@@ -128,13 +128,13 @@ public bool Parse (string challenge)
128128
return HashToHexString (response);
129129
}
130130

131-
public Authorization? Authenticate (HttpURLConnection request, ICredentials credentials)
131+
public Authorization? Authenticate (HttpURLConnection request, ICredentials credentials)
132132
{
133133
if (parser == null)
134134
throw new InvalidOperationException ();
135135
if (request == null)
136136
return null;
137-
137+
138138
lastUse = DateTime.Now;
139139
var uri = new Uri (request.URL?.ToString ()!);
140140
NetworkCredential cred = credentials.GetCredential (uri, "digest");

src/Xamarin.Android.Build.Tasks/Tasks/Aapt2.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ static string GetErrorCode (string message)
314314
Tuple.Create ("APT2097", "failed to open directory"),
315315
Tuple.Create ("APT2098", "failed to open file"),
316316
Tuple.Create ("APT2099", "failed to open resources.arsc"),
317-
Tuple.Create ("APT2100", "failed to open resources.pb"),
317+
Tuple.Create ("APT2100", "failed to open resources.pb"), // lgtm [csharp/responsible-ai/ml-training-and-serialization-files-referenced] These are not the droids you are looking for. Not ML data training files.
318318
Tuple.Create ("APT2101", "failed to open"),
319319
Tuple.Create ("APT2102", "failed to parse binary XML"),
320320
Tuple.Create ("APT2103", "failed to parse binary"),
@@ -367,7 +367,7 @@ static string GetErrorCode (string message)
367367
Tuple.Create ("APT2150", "invalid preferred density"),
368368
Tuple.Create ("APT2151", "invalid resource ID"),
369369
Tuple.Create ("APT2152", "invalid resource name"),
370-
Tuple.Create ("APT2153", "invalid resources.pb"),
370+
Tuple.Create ("APT2153", "invalid resources.pb"), // lgtm [csharp/responsible-ai/ml-training-and-serialization-files-referenced] These are not the droids you are looking for. Not ML data training files.
371371
Tuple.Create ("APT2154", "invalid split name"),
372372
Tuple.Create ("APT2155", "invalid split parameter"),
373373
Tuple.Create ("APT2156", "invalid static library"),

0 commit comments

Comments
 (0)