Skip to content

Commit 1983e93

Browse files
committed
made the HttpSigning method public to get the signed header.
1 parent 5103355 commit 1983e93

File tree

9 files changed

+11
-83
lines changed

9 files changed

+11
-83
lines changed

modules/openapi-generator/src/main/resources/csharp/HttpSigningConfiguration.mustache

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ namespace {{packageName}}.Client
8282
/// <param name="path">Path</param>
8383
/// <param name="requestOptions">Request options</param>
8484
/// <returns>Http signed headers</returns>
85-
internal Dictionary<string, string> GetHttpSignedHeader(string basePath,string method, string path, RequestOptions requestOptions)
85+
public Dictionary<string, string> GetHttpSignedHeader(string basePath,string method, string path, RequestOptions requestOptions)
8686
{
8787
const string HEADER_REQUEST_TARGET = "(request-target)";
8888
//The time when the HTTP signature expires. The API server should reject HTTP requests

samples/client/petstore/csharp/httpclient/standard2.0/Petstore/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ private enum PrivateKeyType
9090
/// <param name="path">Path</param>
9191
/// <param name="requestOptions">Request options</param>
9292
/// <returns>Http signed headers</returns>
93-
internal Dictionary<string, string> GetHttpSignedHeader(string basePath,string method, string path, RequestOptions requestOptions)
93+
public Dictionary<string, string> GetHttpSignedHeader(string basePath,string method, string path, RequestOptions requestOptions)
9494
{
9595
const string HEADER_REQUEST_TARGET = "(request-target)";
9696
//The time when the HTTP signature expires. The API server should reject HTTP requests

samples/client/petstore/csharp/restsharp/net4.7/Petstore/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ private enum PrivateKeyType
9090
/// <param name="path">Path</param>
9191
/// <param name="requestOptions">Request options</param>
9292
/// <returns>Http signed headers</returns>
93-
internal Dictionary<string, string> GetHttpSignedHeader(string basePath,string method, string path, RequestOptions requestOptions)
93+
public Dictionary<string, string> GetHttpSignedHeader(string basePath,string method, string path, RequestOptions requestOptions)
9494
{
9595
const string HEADER_REQUEST_TARGET = "(request-target)";
9696
//The time when the HTTP signature expires. The API server should reject HTTP requests

samples/client/petstore/csharp/restsharp/net4.8/Petstore/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ private enum PrivateKeyType
9090
/// <param name="path">Path</param>
9191
/// <param name="requestOptions">Request options</param>
9292
/// <returns>Http signed headers</returns>
93-
internal Dictionary<string, string> GetHttpSignedHeader(string basePath,string method, string path, RequestOptions requestOptions)
93+
public Dictionary<string, string> GetHttpSignedHeader(string basePath,string method, string path, RequestOptions requestOptions)
9494
{
9595
const string HEADER_REQUEST_TARGET = "(request-target)";
9696
//The time when the HTTP signature expires. The API server should reject HTTP requests

samples/client/petstore/csharp/restsharp/net7/EnumMappings/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ private enum PrivateKeyType
9090
/// <param name="path">Path</param>
9191
/// <param name="requestOptions">Request options</param>
9292
/// <returns>Http signed headers</returns>
93-
internal Dictionary<string, string> GetHttpSignedHeader(string basePath,string method, string path, RequestOptions requestOptions)
93+
public Dictionary<string, string> GetHttpSignedHeader(string basePath,string method, string path, RequestOptions requestOptions)
9494
{
9595
const string HEADER_REQUEST_TARGET = "(request-target)";
9696
//The time when the HTTP signature expires. The API server should reject HTTP requests

samples/client/petstore/csharp/restsharp/net7/Petstore/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ private enum PrivateKeyType
9090
/// <param name="path">Path</param>
9191
/// <param name="requestOptions">Request options</param>
9292
/// <returns>Http signed headers</returns>
93-
internal Dictionary<string, string> GetHttpSignedHeader(string basePath,string method, string path, RequestOptions requestOptions)
93+
public Dictionary<string, string> GetHttpSignedHeader(string basePath,string method, string path, RequestOptions requestOptions)
9494
{
9595
const string HEADER_REQUEST_TARGET = "(request-target)";
9696
//The time when the HTTP signature expires. The API server should reject HTTP requests

samples/client/petstore/csharp/restsharp/standard2.0/ConditionalSerialization/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs

+2-38
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ private enum PrivateKeyType
9090
/// <param name="path">Path</param>
9191
/// <param name="requestOptions">Request options</param>
9292
/// <returns>Http signed headers</returns>
93-
internal Dictionary<string, string> GetHttpSignedHeader(string basePath,string method, string path, RequestOptions requestOptions)
93+
public Dictionary<string, string> GetHttpSignedHeader(string basePath,string method, string path, RequestOptions requestOptions)
9494
{
9595
const string HEADER_REQUEST_TARGET = "(request-target)";
9696
//The time when the HTTP signature expires. The API server should reject HTTP requests
@@ -352,43 +352,7 @@ private string GetRSASignature(byte[] stringToSign)
352352
/// <returns>ECDSA signature</returns>
353353
private string GetECDSASignature(byte[] dataToSign)
354354
{
355-
if (!File.Exists(KeyFilePath) && string.IsNullOrEmpty(KeyString))
356-
{
357-
throw new Exception("No API key has been provided.");
358-
}
359-
360-
var keyStr = KeyString;
361-
const string ecKeyHeader = "-----BEGIN EC PRIVATE KEY-----";
362-
const string ecKeyFooter = "-----END EC PRIVATE KEY-----";
363-
var ecKeyBase64String = keyStr.Replace(ecKeyHeader, "").Replace(ecKeyFooter, "").Trim();
364-
var keyBytes = System.Convert.FromBase64String(ecKeyBase64String);
365-
var ecdsa = ECDsa.Create();
366-
367-
var byteCount = 0;
368-
if (KeyPassPhrase != null)
369-
{
370-
IntPtr unmanagedString = IntPtr.Zero;
371-
try
372-
{
373-
// convert secure string to byte array
374-
unmanagedString = Marshal.SecureStringToGlobalAllocUnicode(KeyPassPhrase);
375-
ecdsa.ImportEncryptedPkcs8PrivateKey(Encoding.UTF8.GetBytes(Marshal.PtrToStringUni(unmanagedString)), keyBytes, out byteCount);
376-
}
377-
finally
378-
{
379-
if (unmanagedString != IntPtr.Zero)
380-
{
381-
Marshal.ZeroFreeBSTR(unmanagedString);
382-
}
383-
}
384-
}
385-
else
386-
ecdsa.ImportPkcs8PrivateKey(keyBytes, out byteCount);
387-
388-
var derBytes = ecdsa.SignHash(dataToSign, DSASignatureFormat.Rfc3279DerSequence);
389-
var signedString = System.Convert.ToBase64String(derBytes);
390-
391-
return signedString;
355+
throw new Exception("ECDSA signing is supported only on NETCOREAPP3_0 and above");
392356
}
393357

394358
/// <summary>

samples/client/petstore/csharp/restsharp/standard2.0/Petstore/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ private enum PrivateKeyType
9090
/// <param name="path">Path</param>
9191
/// <param name="requestOptions">Request options</param>
9292
/// <returns>Http signed headers</returns>
93-
internal Dictionary<string, string> GetHttpSignedHeader(string basePath,string method, string path, RequestOptions requestOptions)
93+
public Dictionary<string, string> GetHttpSignedHeader(string basePath,string method, string path, RequestOptions requestOptions)
9494
{
9595
const string HEADER_REQUEST_TARGET = "(request-target)";
9696
//The time when the HTTP signature expires. The API server should reject HTTP requests

samples/client/petstore/csharp/unityWebRequest/standard2.0/Petstore/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs

+2-38
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ private enum PrivateKeyType
9090
/// <param name="path">Path</param>
9191
/// <param name="requestOptions">Request options</param>
9292
/// <returns>Http signed headers</returns>
93-
internal Dictionary<string, string> GetHttpSignedHeader(string basePath,string method, string path, RequestOptions requestOptions)
93+
public Dictionary<string, string> GetHttpSignedHeader(string basePath,string method, string path, RequestOptions requestOptions)
9494
{
9595
const string HEADER_REQUEST_TARGET = "(request-target)";
9696
//The time when the HTTP signature expires. The API server should reject HTTP requests
@@ -352,43 +352,7 @@ private string GetRSASignature(byte[] stringToSign)
352352
/// <returns>ECDSA signature</returns>
353353
private string GetECDSASignature(byte[] dataToSign)
354354
{
355-
if (!File.Exists(KeyFilePath) && string.IsNullOrEmpty(KeyString))
356-
{
357-
throw new Exception("No API key has been provided.");
358-
}
359-
360-
var keyStr = KeyString;
361-
const string ecKeyHeader = "-----BEGIN EC PRIVATE KEY-----";
362-
const string ecKeyFooter = "-----END EC PRIVATE KEY-----";
363-
var ecKeyBase64String = keyStr.Replace(ecKeyHeader, "").Replace(ecKeyFooter, "").Trim();
364-
var keyBytes = System.Convert.FromBase64String(ecKeyBase64String);
365-
var ecdsa = ECDsa.Create();
366-
367-
var byteCount = 0;
368-
if (KeyPassPhrase != null)
369-
{
370-
IntPtr unmanagedString = IntPtr.Zero;
371-
try
372-
{
373-
// convert secure string to byte array
374-
unmanagedString = Marshal.SecureStringToGlobalAllocUnicode(KeyPassPhrase);
375-
ecdsa.ImportEncryptedPkcs8PrivateKey(Encoding.UTF8.GetBytes(Marshal.PtrToStringUni(unmanagedString)), keyBytes, out byteCount);
376-
}
377-
finally
378-
{
379-
if (unmanagedString != IntPtr.Zero)
380-
{
381-
Marshal.ZeroFreeBSTR(unmanagedString);
382-
}
383-
}
384-
}
385-
else
386-
ecdsa.ImportPkcs8PrivateKey(keyBytes, out byteCount);
387-
388-
var derBytes = ecdsa.SignHash(dataToSign, DSASignatureFormat.Rfc3279DerSequence);
389-
var signedString = System.Convert.ToBase64String(derBytes);
390-
391-
return signedString;
355+
throw new Exception("ECDSA signing is supported only on NETCOREAPP3_0 and above");
392356
}
393357

394358
/// <summary>

0 commit comments

Comments
 (0)