From dc62629e0146c2c43015b07ade063d7dfa55dc26 Mon Sep 17 00:00:00 2001 From: Eitan Blumin Date: Fri, 15 Jul 2022 21:25:56 +0300 Subject: [PATCH 1/4] addes proxy format support for credentials URI,PORT,username:password --- ClrHttpRequest/ClrHttpRequest.jfm | Bin 16384 -> 0 bytes ClrHttpRequest/clr_http_request.cs | 28 ++++++++++++++++++++++++--- README.md | 30 +++++++++++++++++++++++++---- 3 files changed, 51 insertions(+), 7 deletions(-) delete mode 100644 ClrHttpRequest/ClrHttpRequest.jfm diff --git a/ClrHttpRequest/ClrHttpRequest.jfm b/ClrHttpRequest/ClrHttpRequest.jfm deleted file mode 100644 index 63a0db7d4aabc6ee3cf78700be60f02da2496d50..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 16384 zcmeIuF$%&^41nR+_EifCuZ!A6aI8Z?4^VLM06m10prf z_gcFM7QyuoBq1bOzUlBDJEA%)y>5ldYb=hk(>HzBjPiby 2) + { + var proxyCred = proxyValues[2].Split(':'); + if (proxyCred.Length < 2) + { + throw new FormatException("When specifying the PROXY header, please set the value in a format of URI,PORT (you can also specify credentials using the format URI,PORT,username:password)"); + } + else + { + var proxyCredPassword = proxyCred[1]; + + // if the password contains colon characters, re-stich them back into the password + for (int i = 2; i < proxyCred.Length - 1; i++) + { + proxyCredPassword += ":" + proxyCred[i]; + } + + myproxy.Credentials = new NetworkCredential(proxyCred[0], proxyCredPassword); + } + } + request.Proxy = myproxy; break; default: // other headers diff --git a/README.md b/README.md index f8dfa7b..db90633 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ My version extends the project by adding the following: * Two new authentication methods: * Authorization-Basic-Credentials (Basic authorization using Base64 credentials) * Authorization-Network-Credentials (creates a new `NetworkCredential` object and assigns it to the `Credentials` property of the request) -* Added support for using a `Proxy` with a new "Proxy" header in the form of `URI:PORT`. For example: `
https://acmeproxy:4321
` +* Added support for using a `Proxy` with a new "Proxy" header in the form of `URI,PORT[,username:password]` (credentials are optional). For example: `
https://acmeproxy,4321
` * Addition of a proper PreDeployment script which takes care of CLR assembly signing without requiring the TRUSTWORTHY database setting. * Added UTF8 encoding support instead of ASCII. * Added support for case-insensitive headers. @@ -39,18 +39,40 @@ The following code was added in line 79 to add support for special headers: request.Credentials = new NetworkCredential(netCredValues[0], netCredValues[1]); break; case "Proxy": - var proxyValues = headerValue.Split(':'); + var proxyValues = headerValue.Split(','); if (proxyValues.Length < 2) { - throw new FormatException("When specifying the PROXY header, please set the value in a format of URI:PORT"); + throw new FormatException("When specifying the PROXY header, please set the value in a format of URI,PORT (you can also specify credentials using the format URI,PORT,username:password)"); } int proxyPort; if (!int.TryParse(proxyValues[1], out proxyPort)) { - throw new FormatException("When specifying the PROXY header in the format of URI:PORT, the PORT must be numeric"); + throw new FormatException("When specifying the PROXY header in the format of URI,PORT the PORT must be numeric"); } WebProxy myproxy = new WebProxy(proxyValues[0], proxyPort); myproxy.BypassProxyOnLocal = false; + + if (proxyValues.Length > 2) + { + var proxyCred = proxyValues[2].Split(':'); + if (proxyCred.Length < 2) + { + throw new FormatException("When specifying the PROXY header, please set the value in a format of URI,PORT (you can also specify credentials using the format URI,PORT,username:password)"); + } + else + { + var proxyCredPassword = proxyCred[1]; + + // if the password contains colon characters, re-stich them back into the password + for (int i = 2; i < proxyCred.Length - 1; i++) + { + proxyCredPassword += ":" + proxyCred[i]; + } + + myproxy.Credentials = new NetworkCredential(proxyCred[0], proxyCredPassword); + } + } + request.Proxy = myproxy; break; ``` From 47b3e2a2d88484275543c64f77f6a5a93b57adb8 Mon Sep 17 00:00:00 2001 From: Eitan Blumin Date: Sat, 7 Dec 2024 09:59:51 +0200 Subject: [PATCH 2/4] added header TrustServerCertificate --- ClrHttpRequest/clr_http_request.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ClrHttpRequest/clr_http_request.cs b/ClrHttpRequest/clr_http_request.cs index 3f9d960..6c64d17 100644 --- a/ClrHttpRequest/clr_http_request.cs +++ b/ClrHttpRequest/clr_http_request.cs @@ -159,6 +159,9 @@ SqlBoolean convertResponseToBas64 request.Proxy = myproxy; break; + case "TrustServerCertificate": + ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) => true; + break; default: // other headers request.Headers.Add(headerName, headerValue); break; From 24d68f403d68201a42687cf7d15a85c345948150 Mon Sep 17 00:00:00 2001 From: Eitan Blumin Date: Sat, 7 Dec 2024 10:00:17 +0200 Subject: [PATCH 3/4] bumped to .NET framework 4.7.2 --- ClrHttpRequest/ClrHttpRequest.sqlproj | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ClrHttpRequest/ClrHttpRequest.sqlproj b/ClrHttpRequest/ClrHttpRequest.sqlproj index f458e79..5e1f031 100644 --- a/ClrHttpRequest/ClrHttpRequest.sqlproj +++ b/ClrHttpRequest/ClrHttpRequest.sqlproj @@ -17,7 +17,7 @@ 1033, CI BySchemaAndSchemaType True - v4.5 + v4.7.2 CS Properties False @@ -33,6 +33,7 @@ SIMPLE 3.0.0.0 CHECKSUM + bin\Release\ From 39a031a65830efb5eb9f31be6ec9f397c3089a75 Mon Sep 17 00:00:00 2001 From: Eitan Blumin Date: Sat, 7 Dec 2024 10:03:51 +0200 Subject: [PATCH 4/4] updated README --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index db90633..08dfe17 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,7 @@ My version extends the project by adding the following: * Addition of a proper PreDeployment script which takes care of CLR assembly signing without requiring the TRUSTWORTHY database setting. * Added UTF8 encoding support instead of ASCII. * Added support for case-insensitive headers. +* Added support for TrustServerCertificate header. For example: `
True
` The following code was added in clr_http_request.cs, line 19: ```cs