From de60f1e82dfc3a89be9be2cb7a6ada01f9fa1ef7 Mon Sep 17 00:00:00 2001
From: Ghufran Zahidi <18732053+Ghufz@users.noreply.github.com>
Date: Thu, 8 Jun 2023 15:59:56 +0530
Subject: [PATCH 1/3] HttpSigningConfiguration accept api key in string format.
---
.../HttpSigningConfiguration.mustache | 70 +++++++++++++------
.../Client/HttpSigningConfiguration.cs | 70 +++++++++++++------
2 files changed, 100 insertions(+), 40 deletions(-)
diff --git a/modules/openapi-generator/src/main/resources/csharp-netcore/HttpSigningConfiguration.mustache b/modules/openapi-generator/src/main/resources/csharp-netcore/HttpSigningConfiguration.mustache
index 58a961b5da3c..a52c19aaf611 100644
--- a/modules/openapi-generator/src/main/resources/csharp-netcore/HttpSigningConfiguration.mustache
+++ b/modules/openapi-generator/src/main/resources/csharp-netcore/HttpSigningConfiguration.mustache
@@ -40,6 +40,11 @@ namespace {{packageName}}.Client
///
public string KeyFilePath { get; set; }
+ ///
+ /// Specify the API key in the form of a string, either configure the KeyString property or configure the KeyFilePath property.
+ ///
+ public string KeyString { get; set; }
+
///
/// Gets the key pass phrase for password protected key
///
@@ -108,6 +113,17 @@ namespace {{packageName}}.Client
var HttpSignedRequestHeader = new Dictionary();
var HttpSignatureHeader = new Dictionary();
+ //Read the api key from the file
+ if(!string.IsNullOrEmpty(this.KeyFilePath))
+ {
+ this.KeyString = ReadApiKeyFromFile(KeyFilePath);
+ }
+
+ if(string.IsNullOrEmpty(KeyString))
+ {
+ throw new Exception("No API key has been provided.");
+ }
+
if (HttpSigningHeader.Count == 0)
{
HttpSigningHeader.Add("(created)");
@@ -242,7 +258,7 @@ namespace {{packageName}}.Client
var headerValuesString = string.Join("\n", headerValuesList);
var signatureStringHash = GetStringHash(HashAlgorithm.ToString(), headerValuesString);
string headerSignatureStr = null;
- var keyType = GetKeyType(KeyFilePath);
+ var keyType = GetKeyType(KeyString);
if (keyType == PrivateKeyType.RSA)
{
@@ -293,7 +309,7 @@ namespace {{packageName}}.Client
private string GetRSASignature(byte[] stringToSign)
{
- RSA rsa = GetRSAProviderFromPemFile(KeyFilePath, KeyPassPhrase);
+ RSA rsa = GetRSAProviderFromPemFile(KeyString, KeyPassPhrase);
if (SigningAlgorithm == "RSASSA-PSS")
{
var signedbytes = rsa.SignHash(stringToSign, HashAlgorithm, RSASignaturePadding.Pss);
@@ -317,14 +333,9 @@ namespace {{packageName}}.Client
/// ECDSA signature
private string GetECDSASignature(byte[] dataToSign)
{
- if (!File.Exists(KeyFilePath))
- {
- throw new Exception("key file path does not exist.");
- }
-
const string ecKeyHeader = "-----BEGIN EC PRIVATE KEY-----";
const string ecKeyFooter = "-----END EC PRIVATE KEY-----";
- var keyStr = File.ReadAllText(KeyFilePath);
+ var keyStr = KeyString;
var ecKeyBase64String = keyStr.Replace(ecKeyHeader, "").Replace(ecKeyFooter, "").Trim();
var keyBytes = System.Convert.FromBase64String(ecKeyBase64String);
var ecdsa = ECDsa.Create();
@@ -415,18 +426,13 @@ namespace {{packageName}}.Client
return derBytes.ToArray();
}
- private RSACryptoServiceProvider GetRSAProviderFromPemFile(string pemfile, SecureString keyPassPhrase = null)
+ private RSACryptoServiceProvider GetRSAProviderFromPemFile(string keyString, SecureString keyPassPhrase = null)
{
const string pempubheader = "-----BEGIN PUBLIC KEY-----";
const string pempubfooter = "-----END PUBLIC KEY-----";
bool isPrivateKeyFile = true;
byte[] pemkey = null;
-
- if (!File.Exists(pemfile))
- {
- throw new Exception("private key file does not exist.");
- }
- string pemstr = File.ReadAllText(pemfile).Trim();
+ string pemstr = keyString;
if (pemstr.StartsWith(pempubheader) && pemstr.EndsWith(pempubfooter))
{
@@ -713,13 +719,13 @@ namespace {{packageName}}.Client
///
/// Detect the key type from the pem file.
///
- /// key file path in pem format
+ /// api key in string format
/// Private Key Type
- private PrivateKeyType GetKeyType(string keyFilePath)
+ private PrivateKeyType GetKeyType(string keyString)
{
- if (!File.Exists(keyFilePath))
+ if (string.IsNullOrEmpty(keyString))
{
- throw new Exception("Key file path does not exist.");
+ throw new Exception("No API key has been provided.");
}
const string ecPrivateKeyHeader = "BEGIN EC PRIVATE KEY";
@@ -729,7 +735,7 @@ namespace {{packageName}}.Client
//var pkcs8Header = "BEGIN PRIVATE KEY";
//var pkcs8Footer = "END PRIVATE KEY";
PrivateKeyType keyType;
- var key = File.ReadAllLines(keyFilePath);
+ var key = KeyString.TrimEnd().Split("\n");
if (key[0].Contains(rsaPrivateKeyHeader) &&
key[key.Length - 1].ToString().Contains(rsaPrivateFooter))
@@ -747,6 +753,30 @@ namespace {{packageName}}.Client
}
return keyType;
}
+
+ ///
+ /// Read the api key form the api key file path and stored it in KeyString property.
+ ///
+ /// api key file path
+ private string ReadApiKeyFromFile(string apiKeyFilePath)
+ {
+ string apiKeyString = null;
+ if(!string.IsNullOrEmpty(apiKeyFilePath) && !string.IsNullOrEmpty(this.KeyString))
+ {
+ throw new Exception("Configure either the KeyFilePath or configure the KeyString property.");
+ }
+
+ if(File.Exists(apiKeyFilePath))
+ {
+ apiKeyString = File.ReadAllText(apiKeyFilePath);
+ }
+ else
+ {
+ throw new Exception("Provided API key file path does not exists.");
+ }
+ return apiKeyString;
+ }
+
#endregion
}
}
diff --git a/samples/client/petstore/csharp-netcore/OpenAPIClient-net5.0/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs b/samples/client/petstore/csharp-netcore/OpenAPIClient-net5.0/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs
index 6a8f9c8dc016..851885599db8 100644
--- a/samples/client/petstore/csharp-netcore/OpenAPIClient-net5.0/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs
+++ b/samples/client/petstore/csharp-netcore/OpenAPIClient-net5.0/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs
@@ -48,6 +48,11 @@ public HttpSigningConfiguration()
///
public string KeyFilePath { get; set; }
+ ///
+ /// Specify the API key in the form of a string, either configure the KeyString property or configure the KeyFilePath property.
+ ///
+ public string KeyString { get; set; }
+
///
/// Gets the key pass phrase for password protected key
///
@@ -116,6 +121,17 @@ internal Dictionary GetHttpSignedHeader(string basePath,string m
var HttpSignedRequestHeader = new Dictionary();
var HttpSignatureHeader = new Dictionary();
+ //Read the api key from the file
+ if(!string.IsNullOrEmpty(this.KeyFilePath))
+ {
+ this.KeyString = ReadApiKeyFromFile(KeyFilePath);
+ }
+
+ if(string.IsNullOrEmpty(KeyString))
+ {
+ throw new Exception("No API key has been provided.");
+ }
+
if (HttpSigningHeader.Count == 0)
{
HttpSigningHeader.Add("(created)");
@@ -250,7 +266,7 @@ internal Dictionary GetHttpSignedHeader(string basePath,string m
var headerValuesString = string.Join("\n", headerValuesList);
var signatureStringHash = GetStringHash(HashAlgorithm.ToString(), headerValuesString);
string headerSignatureStr = null;
- var keyType = GetKeyType(KeyFilePath);
+ var keyType = GetKeyType(KeyString);
if (keyType == PrivateKeyType.RSA)
{
@@ -301,7 +317,7 @@ private int GetUnixTime(DateTime date2)
private string GetRSASignature(byte[] stringToSign)
{
- RSA rsa = GetRSAProviderFromPemFile(KeyFilePath, KeyPassPhrase);
+ RSA rsa = GetRSAProviderFromPemFile(KeyString, KeyPassPhrase);
if (SigningAlgorithm == "RSASSA-PSS")
{
var signedbytes = rsa.SignHash(stringToSign, HashAlgorithm, RSASignaturePadding.Pss);
@@ -325,14 +341,9 @@ private string GetRSASignature(byte[] stringToSign)
/// ECDSA signature
private string GetECDSASignature(byte[] dataToSign)
{
- if (!File.Exists(KeyFilePath))
- {
- throw new Exception("key file path does not exist.");
- }
-
const string ecKeyHeader = "-----BEGIN EC PRIVATE KEY-----";
const string ecKeyFooter = "-----END EC PRIVATE KEY-----";
- var keyStr = File.ReadAllText(KeyFilePath);
+ var keyStr = KeyString;
var ecKeyBase64String = keyStr.Replace(ecKeyHeader, "").Replace(ecKeyFooter, "").Trim();
var keyBytes = System.Convert.FromBase64String(ecKeyBase64String);
var ecdsa = ECDsa.Create();
@@ -423,18 +434,13 @@ private byte[] ConvertToECDSAANS1Format(byte[] signedBytes)
return derBytes.ToArray();
}
- private RSACryptoServiceProvider GetRSAProviderFromPemFile(string pemfile, SecureString keyPassPhrase = null)
+ private RSACryptoServiceProvider GetRSAProviderFromPemFile(string keyString, SecureString keyPassPhrase = null)
{
const string pempubheader = "-----BEGIN PUBLIC KEY-----";
const string pempubfooter = "-----END PUBLIC KEY-----";
bool isPrivateKeyFile = true;
byte[] pemkey = null;
-
- if (!File.Exists(pemfile))
- {
- throw new Exception("private key file does not exist.");
- }
- string pemstr = File.ReadAllText(pemfile).Trim();
+ string pemstr = keyString;
if (pemstr.StartsWith(pempubheader) && pemstr.EndsWith(pempubfooter))
{
@@ -721,13 +727,13 @@ private byte[] DecryptKey(byte[] cipherData, byte[] desKey, byte[] IV)
///
/// Detect the key type from the pem file.
///
- /// key file path in pem format
+ /// api key in string format
/// Private Key Type
- private PrivateKeyType GetKeyType(string keyFilePath)
+ private PrivateKeyType GetKeyType(string keyString)
{
- if (!File.Exists(keyFilePath))
+ if (string.IsNullOrEmpty(keyString))
{
- throw new Exception("Key file path does not exist.");
+ throw new Exception("No API key has been provided.");
}
const string ecPrivateKeyHeader = "BEGIN EC PRIVATE KEY";
@@ -737,7 +743,7 @@ private PrivateKeyType GetKeyType(string keyFilePath)
//var pkcs8Header = "BEGIN PRIVATE KEY";
//var pkcs8Footer = "END PRIVATE KEY";
PrivateKeyType keyType;
- var key = File.ReadAllLines(keyFilePath);
+ var key = KeyString.TrimEnd().Split("\n");
if (key[0].Contains(rsaPrivateKeyHeader) &&
key[key.Length - 1].ToString().Contains(rsaPrivateFooter))
@@ -755,6 +761,30 @@ private PrivateKeyType GetKeyType(string keyFilePath)
}
return keyType;
}
+
+ ///
+ /// Read the api key form the api key file path and stored it in KeyString property.
+ ///
+ /// api key file path
+ private string ReadApiKeyFromFile(string apiKeyFilePath)
+ {
+ string apiKeyString = null;
+ if(!string.IsNullOrEmpty(apiKeyFilePath) && !string.IsNullOrEmpty(this.KeyString))
+ {
+ throw new Exception("Configure either the KeyFilePath or configure the KeyString property.");
+ }
+
+ if(File.Exists(apiKeyFilePath))
+ {
+ apiKeyString = File.ReadAllText(apiKeyFilePath);
+ }
+ else
+ {
+ throw new Exception("Provided API key file path does not exists.");
+ }
+ return apiKeyString;
+ }
+
#endregion
}
}
From 570bbbf9e333fac7a567b7df0b074a1a52541b43 Mon Sep 17 00:00:00 2001
From: Ghufran Zahidi <18732053+Ghufz@users.noreply.github.com>
Date: Tue, 13 Jun 2023 15:02:15 +0530
Subject: [PATCH 2/3] updated the sample code.
---
.../HttpSigningConfiguration.mustache | 2 +-
.../Client/HttpSigningConfiguration.cs | 70 +++++++++++++------
.../Client/HttpSigningConfiguration.cs | 70 +++++++++++++------
.../Client/HttpSigningConfiguration.cs | 70 +++++++++++++------
.../Client/HttpSigningConfiguration.cs | 2 +-
.../Client/HttpSigningConfiguration.cs | 70 +++++++++++++------
.../Client/HttpSigningConfiguration.cs | 70 +++++++++++++------
7 files changed, 252 insertions(+), 102 deletions(-)
diff --git a/modules/openapi-generator/src/main/resources/csharp-netcore/HttpSigningConfiguration.mustache b/modules/openapi-generator/src/main/resources/csharp-netcore/HttpSigningConfiguration.mustache
index a52c19aaf611..9c7f89333f78 100644
--- a/modules/openapi-generator/src/main/resources/csharp-netcore/HttpSigningConfiguration.mustache
+++ b/modules/openapi-generator/src/main/resources/csharp-netcore/HttpSigningConfiguration.mustache
@@ -735,7 +735,7 @@ namespace {{packageName}}.Client
//var pkcs8Header = "BEGIN PRIVATE KEY";
//var pkcs8Footer = "END PRIVATE KEY";
PrivateKeyType keyType;
- var key = KeyString.TrimEnd().Split("\n");
+ var key = KeyString.TrimEnd().Split('\n');
if (key[0].Contains(rsaPrivateKeyHeader) &&
key[key.Length - 1].ToString().Contains(rsaPrivateFooter))
diff --git a/samples/client/petstore/csharp-netcore/OpenAPIClient-ConditionalSerialization/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs b/samples/client/petstore/csharp-netcore/OpenAPIClient-ConditionalSerialization/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs
index 6a8f9c8dc016..520d4c23b57b 100644
--- a/samples/client/petstore/csharp-netcore/OpenAPIClient-ConditionalSerialization/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs
+++ b/samples/client/petstore/csharp-netcore/OpenAPIClient-ConditionalSerialization/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs
@@ -48,6 +48,11 @@ public HttpSigningConfiguration()
///
public string KeyFilePath { get; set; }
+ ///
+ /// Specify the API key in the form of a string, either configure the KeyString property or configure the KeyFilePath property.
+ ///
+ public string KeyString { get; set; }
+
///
/// Gets the key pass phrase for password protected key
///
@@ -116,6 +121,17 @@ internal Dictionary GetHttpSignedHeader(string basePath,string m
var HttpSignedRequestHeader = new Dictionary();
var HttpSignatureHeader = new Dictionary();
+ //Read the api key from the file
+ if(!string.IsNullOrEmpty(this.KeyFilePath))
+ {
+ this.KeyString = ReadApiKeyFromFile(KeyFilePath);
+ }
+
+ if(string.IsNullOrEmpty(KeyString))
+ {
+ throw new Exception("No API key has been provided.");
+ }
+
if (HttpSigningHeader.Count == 0)
{
HttpSigningHeader.Add("(created)");
@@ -250,7 +266,7 @@ internal Dictionary GetHttpSignedHeader(string basePath,string m
var headerValuesString = string.Join("\n", headerValuesList);
var signatureStringHash = GetStringHash(HashAlgorithm.ToString(), headerValuesString);
string headerSignatureStr = null;
- var keyType = GetKeyType(KeyFilePath);
+ var keyType = GetKeyType(KeyString);
if (keyType == PrivateKeyType.RSA)
{
@@ -301,7 +317,7 @@ private int GetUnixTime(DateTime date2)
private string GetRSASignature(byte[] stringToSign)
{
- RSA rsa = GetRSAProviderFromPemFile(KeyFilePath, KeyPassPhrase);
+ RSA rsa = GetRSAProviderFromPemFile(KeyString, KeyPassPhrase);
if (SigningAlgorithm == "RSASSA-PSS")
{
var signedbytes = rsa.SignHash(stringToSign, HashAlgorithm, RSASignaturePadding.Pss);
@@ -325,14 +341,9 @@ private string GetRSASignature(byte[] stringToSign)
/// ECDSA signature
private string GetECDSASignature(byte[] dataToSign)
{
- if (!File.Exists(KeyFilePath))
- {
- throw new Exception("key file path does not exist.");
- }
-
const string ecKeyHeader = "-----BEGIN EC PRIVATE KEY-----";
const string ecKeyFooter = "-----END EC PRIVATE KEY-----";
- var keyStr = File.ReadAllText(KeyFilePath);
+ var keyStr = KeyString;
var ecKeyBase64String = keyStr.Replace(ecKeyHeader, "").Replace(ecKeyFooter, "").Trim();
var keyBytes = System.Convert.FromBase64String(ecKeyBase64String);
var ecdsa = ECDsa.Create();
@@ -423,18 +434,13 @@ private byte[] ConvertToECDSAANS1Format(byte[] signedBytes)
return derBytes.ToArray();
}
- private RSACryptoServiceProvider GetRSAProviderFromPemFile(string pemfile, SecureString keyPassPhrase = null)
+ private RSACryptoServiceProvider GetRSAProviderFromPemFile(string keyString, SecureString keyPassPhrase = null)
{
const string pempubheader = "-----BEGIN PUBLIC KEY-----";
const string pempubfooter = "-----END PUBLIC KEY-----";
bool isPrivateKeyFile = true;
byte[] pemkey = null;
-
- if (!File.Exists(pemfile))
- {
- throw new Exception("private key file does not exist.");
- }
- string pemstr = File.ReadAllText(pemfile).Trim();
+ string pemstr = keyString;
if (pemstr.StartsWith(pempubheader) && pemstr.EndsWith(pempubfooter))
{
@@ -721,13 +727,13 @@ private byte[] DecryptKey(byte[] cipherData, byte[] desKey, byte[] IV)
///
/// Detect the key type from the pem file.
///
- /// key file path in pem format
+ /// api key in string format
/// Private Key Type
- private PrivateKeyType GetKeyType(string keyFilePath)
+ private PrivateKeyType GetKeyType(string keyString)
{
- if (!File.Exists(keyFilePath))
+ if (string.IsNullOrEmpty(keyString))
{
- throw new Exception("Key file path does not exist.");
+ throw new Exception("No API key has been provided.");
}
const string ecPrivateKeyHeader = "BEGIN EC PRIVATE KEY";
@@ -737,7 +743,7 @@ private PrivateKeyType GetKeyType(string keyFilePath)
//var pkcs8Header = "BEGIN PRIVATE KEY";
//var pkcs8Footer = "END PRIVATE KEY";
PrivateKeyType keyType;
- var key = File.ReadAllLines(keyFilePath);
+ var key = KeyString.TrimEnd().Split('\n');
if (key[0].Contains(rsaPrivateKeyHeader) &&
key[key.Length - 1].ToString().Contains(rsaPrivateFooter))
@@ -755,6 +761,30 @@ private PrivateKeyType GetKeyType(string keyFilePath)
}
return keyType;
}
+
+ ///
+ /// Read the api key form the api key file path and stored it in KeyString property.
+ ///
+ /// api key file path
+ private string ReadApiKeyFromFile(string apiKeyFilePath)
+ {
+ string apiKeyString = null;
+ if(!string.IsNullOrEmpty(apiKeyFilePath) && !string.IsNullOrEmpty(this.KeyString))
+ {
+ throw new Exception("Configure either the KeyFilePath or configure the KeyString property.");
+ }
+
+ if(File.Exists(apiKeyFilePath))
+ {
+ apiKeyString = File.ReadAllText(apiKeyFilePath);
+ }
+ else
+ {
+ throw new Exception("Provided API key file path does not exists.");
+ }
+ return apiKeyString;
+ }
+
#endregion
}
}
diff --git a/samples/client/petstore/csharp-netcore/OpenAPIClient-httpclient/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs b/samples/client/petstore/csharp-netcore/OpenAPIClient-httpclient/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs
index 6a8f9c8dc016..520d4c23b57b 100644
--- a/samples/client/petstore/csharp-netcore/OpenAPIClient-httpclient/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs
+++ b/samples/client/petstore/csharp-netcore/OpenAPIClient-httpclient/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs
@@ -48,6 +48,11 @@ public HttpSigningConfiguration()
///
public string KeyFilePath { get; set; }
+ ///
+ /// Specify the API key in the form of a string, either configure the KeyString property or configure the KeyFilePath property.
+ ///
+ public string KeyString { get; set; }
+
///
/// Gets the key pass phrase for password protected key
///
@@ -116,6 +121,17 @@ internal Dictionary GetHttpSignedHeader(string basePath,string m
var HttpSignedRequestHeader = new Dictionary();
var HttpSignatureHeader = new Dictionary();
+ //Read the api key from the file
+ if(!string.IsNullOrEmpty(this.KeyFilePath))
+ {
+ this.KeyString = ReadApiKeyFromFile(KeyFilePath);
+ }
+
+ if(string.IsNullOrEmpty(KeyString))
+ {
+ throw new Exception("No API key has been provided.");
+ }
+
if (HttpSigningHeader.Count == 0)
{
HttpSigningHeader.Add("(created)");
@@ -250,7 +266,7 @@ internal Dictionary GetHttpSignedHeader(string basePath,string m
var headerValuesString = string.Join("\n", headerValuesList);
var signatureStringHash = GetStringHash(HashAlgorithm.ToString(), headerValuesString);
string headerSignatureStr = null;
- var keyType = GetKeyType(KeyFilePath);
+ var keyType = GetKeyType(KeyString);
if (keyType == PrivateKeyType.RSA)
{
@@ -301,7 +317,7 @@ private int GetUnixTime(DateTime date2)
private string GetRSASignature(byte[] stringToSign)
{
- RSA rsa = GetRSAProviderFromPemFile(KeyFilePath, KeyPassPhrase);
+ RSA rsa = GetRSAProviderFromPemFile(KeyString, KeyPassPhrase);
if (SigningAlgorithm == "RSASSA-PSS")
{
var signedbytes = rsa.SignHash(stringToSign, HashAlgorithm, RSASignaturePadding.Pss);
@@ -325,14 +341,9 @@ private string GetRSASignature(byte[] stringToSign)
/// ECDSA signature
private string GetECDSASignature(byte[] dataToSign)
{
- if (!File.Exists(KeyFilePath))
- {
- throw new Exception("key file path does not exist.");
- }
-
const string ecKeyHeader = "-----BEGIN EC PRIVATE KEY-----";
const string ecKeyFooter = "-----END EC PRIVATE KEY-----";
- var keyStr = File.ReadAllText(KeyFilePath);
+ var keyStr = KeyString;
var ecKeyBase64String = keyStr.Replace(ecKeyHeader, "").Replace(ecKeyFooter, "").Trim();
var keyBytes = System.Convert.FromBase64String(ecKeyBase64String);
var ecdsa = ECDsa.Create();
@@ -423,18 +434,13 @@ private byte[] ConvertToECDSAANS1Format(byte[] signedBytes)
return derBytes.ToArray();
}
- private RSACryptoServiceProvider GetRSAProviderFromPemFile(string pemfile, SecureString keyPassPhrase = null)
+ private RSACryptoServiceProvider GetRSAProviderFromPemFile(string keyString, SecureString keyPassPhrase = null)
{
const string pempubheader = "-----BEGIN PUBLIC KEY-----";
const string pempubfooter = "-----END PUBLIC KEY-----";
bool isPrivateKeyFile = true;
byte[] pemkey = null;
-
- if (!File.Exists(pemfile))
- {
- throw new Exception("private key file does not exist.");
- }
- string pemstr = File.ReadAllText(pemfile).Trim();
+ string pemstr = keyString;
if (pemstr.StartsWith(pempubheader) && pemstr.EndsWith(pempubfooter))
{
@@ -721,13 +727,13 @@ private byte[] DecryptKey(byte[] cipherData, byte[] desKey, byte[] IV)
///
/// Detect the key type from the pem file.
///
- /// key file path in pem format
+ /// api key in string format
/// Private Key Type
- private PrivateKeyType GetKeyType(string keyFilePath)
+ private PrivateKeyType GetKeyType(string keyString)
{
- if (!File.Exists(keyFilePath))
+ if (string.IsNullOrEmpty(keyString))
{
- throw new Exception("Key file path does not exist.");
+ throw new Exception("No API key has been provided.");
}
const string ecPrivateKeyHeader = "BEGIN EC PRIVATE KEY";
@@ -737,7 +743,7 @@ private PrivateKeyType GetKeyType(string keyFilePath)
//var pkcs8Header = "BEGIN PRIVATE KEY";
//var pkcs8Footer = "END PRIVATE KEY";
PrivateKeyType keyType;
- var key = File.ReadAllLines(keyFilePath);
+ var key = KeyString.TrimEnd().Split('\n');
if (key[0].Contains(rsaPrivateKeyHeader) &&
key[key.Length - 1].ToString().Contains(rsaPrivateFooter))
@@ -755,6 +761,30 @@ private PrivateKeyType GetKeyType(string keyFilePath)
}
return keyType;
}
+
+ ///
+ /// Read the api key form the api key file path and stored it in KeyString property.
+ ///
+ /// api key file path
+ private string ReadApiKeyFromFile(string apiKeyFilePath)
+ {
+ string apiKeyString = null;
+ if(!string.IsNullOrEmpty(apiKeyFilePath) && !string.IsNullOrEmpty(this.KeyString))
+ {
+ throw new Exception("Configure either the KeyFilePath or configure the KeyString property.");
+ }
+
+ if(File.Exists(apiKeyFilePath))
+ {
+ apiKeyString = File.ReadAllText(apiKeyFilePath);
+ }
+ else
+ {
+ throw new Exception("Provided API key file path does not exists.");
+ }
+ return apiKeyString;
+ }
+
#endregion
}
}
diff --git a/samples/client/petstore/csharp-netcore/OpenAPIClient-net47/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs b/samples/client/petstore/csharp-netcore/OpenAPIClient-net47/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs
index 6a8f9c8dc016..520d4c23b57b 100644
--- a/samples/client/petstore/csharp-netcore/OpenAPIClient-net47/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs
+++ b/samples/client/petstore/csharp-netcore/OpenAPIClient-net47/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs
@@ -48,6 +48,11 @@ public HttpSigningConfiguration()
///
public string KeyFilePath { get; set; }
+ ///
+ /// Specify the API key in the form of a string, either configure the KeyString property or configure the KeyFilePath property.
+ ///
+ public string KeyString { get; set; }
+
///
/// Gets the key pass phrase for password protected key
///
@@ -116,6 +121,17 @@ internal Dictionary GetHttpSignedHeader(string basePath,string m
var HttpSignedRequestHeader = new Dictionary();
var HttpSignatureHeader = new Dictionary();
+ //Read the api key from the file
+ if(!string.IsNullOrEmpty(this.KeyFilePath))
+ {
+ this.KeyString = ReadApiKeyFromFile(KeyFilePath);
+ }
+
+ if(string.IsNullOrEmpty(KeyString))
+ {
+ throw new Exception("No API key has been provided.");
+ }
+
if (HttpSigningHeader.Count == 0)
{
HttpSigningHeader.Add("(created)");
@@ -250,7 +266,7 @@ internal Dictionary GetHttpSignedHeader(string basePath,string m
var headerValuesString = string.Join("\n", headerValuesList);
var signatureStringHash = GetStringHash(HashAlgorithm.ToString(), headerValuesString);
string headerSignatureStr = null;
- var keyType = GetKeyType(KeyFilePath);
+ var keyType = GetKeyType(KeyString);
if (keyType == PrivateKeyType.RSA)
{
@@ -301,7 +317,7 @@ private int GetUnixTime(DateTime date2)
private string GetRSASignature(byte[] stringToSign)
{
- RSA rsa = GetRSAProviderFromPemFile(KeyFilePath, KeyPassPhrase);
+ RSA rsa = GetRSAProviderFromPemFile(KeyString, KeyPassPhrase);
if (SigningAlgorithm == "RSASSA-PSS")
{
var signedbytes = rsa.SignHash(stringToSign, HashAlgorithm, RSASignaturePadding.Pss);
@@ -325,14 +341,9 @@ private string GetRSASignature(byte[] stringToSign)
/// ECDSA signature
private string GetECDSASignature(byte[] dataToSign)
{
- if (!File.Exists(KeyFilePath))
- {
- throw new Exception("key file path does not exist.");
- }
-
const string ecKeyHeader = "-----BEGIN EC PRIVATE KEY-----";
const string ecKeyFooter = "-----END EC PRIVATE KEY-----";
- var keyStr = File.ReadAllText(KeyFilePath);
+ var keyStr = KeyString;
var ecKeyBase64String = keyStr.Replace(ecKeyHeader, "").Replace(ecKeyFooter, "").Trim();
var keyBytes = System.Convert.FromBase64String(ecKeyBase64String);
var ecdsa = ECDsa.Create();
@@ -423,18 +434,13 @@ private byte[] ConvertToECDSAANS1Format(byte[] signedBytes)
return derBytes.ToArray();
}
- private RSACryptoServiceProvider GetRSAProviderFromPemFile(string pemfile, SecureString keyPassPhrase = null)
+ private RSACryptoServiceProvider GetRSAProviderFromPemFile(string keyString, SecureString keyPassPhrase = null)
{
const string pempubheader = "-----BEGIN PUBLIC KEY-----";
const string pempubfooter = "-----END PUBLIC KEY-----";
bool isPrivateKeyFile = true;
byte[] pemkey = null;
-
- if (!File.Exists(pemfile))
- {
- throw new Exception("private key file does not exist.");
- }
- string pemstr = File.ReadAllText(pemfile).Trim();
+ string pemstr = keyString;
if (pemstr.StartsWith(pempubheader) && pemstr.EndsWith(pempubfooter))
{
@@ -721,13 +727,13 @@ private byte[] DecryptKey(byte[] cipherData, byte[] desKey, byte[] IV)
///
/// Detect the key type from the pem file.
///
- /// key file path in pem format
+ /// api key in string format
/// Private Key Type
- private PrivateKeyType GetKeyType(string keyFilePath)
+ private PrivateKeyType GetKeyType(string keyString)
{
- if (!File.Exists(keyFilePath))
+ if (string.IsNullOrEmpty(keyString))
{
- throw new Exception("Key file path does not exist.");
+ throw new Exception("No API key has been provided.");
}
const string ecPrivateKeyHeader = "BEGIN EC PRIVATE KEY";
@@ -737,7 +743,7 @@ private PrivateKeyType GetKeyType(string keyFilePath)
//var pkcs8Header = "BEGIN PRIVATE KEY";
//var pkcs8Footer = "END PRIVATE KEY";
PrivateKeyType keyType;
- var key = File.ReadAllLines(keyFilePath);
+ var key = KeyString.TrimEnd().Split('\n');
if (key[0].Contains(rsaPrivateKeyHeader) &&
key[key.Length - 1].ToString().Contains(rsaPrivateFooter))
@@ -755,6 +761,30 @@ private PrivateKeyType GetKeyType(string keyFilePath)
}
return keyType;
}
+
+ ///
+ /// Read the api key form the api key file path and stored it in KeyString property.
+ ///
+ /// api key file path
+ private string ReadApiKeyFromFile(string apiKeyFilePath)
+ {
+ string apiKeyString = null;
+ if(!string.IsNullOrEmpty(apiKeyFilePath) && !string.IsNullOrEmpty(this.KeyString))
+ {
+ throw new Exception("Configure either the KeyFilePath or configure the KeyString property.");
+ }
+
+ if(File.Exists(apiKeyFilePath))
+ {
+ apiKeyString = File.ReadAllText(apiKeyFilePath);
+ }
+ else
+ {
+ throw new Exception("Provided API key file path does not exists.");
+ }
+ return apiKeyString;
+ }
+
#endregion
}
}
diff --git a/samples/client/petstore/csharp-netcore/OpenAPIClient-net5.0/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs b/samples/client/petstore/csharp-netcore/OpenAPIClient-net5.0/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs
index 851885599db8..520d4c23b57b 100644
--- a/samples/client/petstore/csharp-netcore/OpenAPIClient-net5.0/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs
+++ b/samples/client/petstore/csharp-netcore/OpenAPIClient-net5.0/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs
@@ -743,7 +743,7 @@ private PrivateKeyType GetKeyType(string keyString)
//var pkcs8Header = "BEGIN PRIVATE KEY";
//var pkcs8Footer = "END PRIVATE KEY";
PrivateKeyType keyType;
- var key = KeyString.TrimEnd().Split("\n");
+ var key = KeyString.TrimEnd().Split('\n');
if (key[0].Contains(rsaPrivateKeyHeader) &&
key[key.Length - 1].ToString().Contains(rsaPrivateFooter))
diff --git a/samples/client/petstore/csharp-netcore/OpenAPIClient/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs b/samples/client/petstore/csharp-netcore/OpenAPIClient/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs
index 6a8f9c8dc016..520d4c23b57b 100644
--- a/samples/client/petstore/csharp-netcore/OpenAPIClient/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs
+++ b/samples/client/petstore/csharp-netcore/OpenAPIClient/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs
@@ -48,6 +48,11 @@ public HttpSigningConfiguration()
///
public string KeyFilePath { get; set; }
+ ///
+ /// Specify the API key in the form of a string, either configure the KeyString property or configure the KeyFilePath property.
+ ///
+ public string KeyString { get; set; }
+
///
/// Gets the key pass phrase for password protected key
///
@@ -116,6 +121,17 @@ internal Dictionary GetHttpSignedHeader(string basePath,string m
var HttpSignedRequestHeader = new Dictionary();
var HttpSignatureHeader = new Dictionary();
+ //Read the api key from the file
+ if(!string.IsNullOrEmpty(this.KeyFilePath))
+ {
+ this.KeyString = ReadApiKeyFromFile(KeyFilePath);
+ }
+
+ if(string.IsNullOrEmpty(KeyString))
+ {
+ throw new Exception("No API key has been provided.");
+ }
+
if (HttpSigningHeader.Count == 0)
{
HttpSigningHeader.Add("(created)");
@@ -250,7 +266,7 @@ internal Dictionary GetHttpSignedHeader(string basePath,string m
var headerValuesString = string.Join("\n", headerValuesList);
var signatureStringHash = GetStringHash(HashAlgorithm.ToString(), headerValuesString);
string headerSignatureStr = null;
- var keyType = GetKeyType(KeyFilePath);
+ var keyType = GetKeyType(KeyString);
if (keyType == PrivateKeyType.RSA)
{
@@ -301,7 +317,7 @@ private int GetUnixTime(DateTime date2)
private string GetRSASignature(byte[] stringToSign)
{
- RSA rsa = GetRSAProviderFromPemFile(KeyFilePath, KeyPassPhrase);
+ RSA rsa = GetRSAProviderFromPemFile(KeyString, KeyPassPhrase);
if (SigningAlgorithm == "RSASSA-PSS")
{
var signedbytes = rsa.SignHash(stringToSign, HashAlgorithm, RSASignaturePadding.Pss);
@@ -325,14 +341,9 @@ private string GetRSASignature(byte[] stringToSign)
/// ECDSA signature
private string GetECDSASignature(byte[] dataToSign)
{
- if (!File.Exists(KeyFilePath))
- {
- throw new Exception("key file path does not exist.");
- }
-
const string ecKeyHeader = "-----BEGIN EC PRIVATE KEY-----";
const string ecKeyFooter = "-----END EC PRIVATE KEY-----";
- var keyStr = File.ReadAllText(KeyFilePath);
+ var keyStr = KeyString;
var ecKeyBase64String = keyStr.Replace(ecKeyHeader, "").Replace(ecKeyFooter, "").Trim();
var keyBytes = System.Convert.FromBase64String(ecKeyBase64String);
var ecdsa = ECDsa.Create();
@@ -423,18 +434,13 @@ private byte[] ConvertToECDSAANS1Format(byte[] signedBytes)
return derBytes.ToArray();
}
- private RSACryptoServiceProvider GetRSAProviderFromPemFile(string pemfile, SecureString keyPassPhrase = null)
+ private RSACryptoServiceProvider GetRSAProviderFromPemFile(string keyString, SecureString keyPassPhrase = null)
{
const string pempubheader = "-----BEGIN PUBLIC KEY-----";
const string pempubfooter = "-----END PUBLIC KEY-----";
bool isPrivateKeyFile = true;
byte[] pemkey = null;
-
- if (!File.Exists(pemfile))
- {
- throw new Exception("private key file does not exist.");
- }
- string pemstr = File.ReadAllText(pemfile).Trim();
+ string pemstr = keyString;
if (pemstr.StartsWith(pempubheader) && pemstr.EndsWith(pempubfooter))
{
@@ -721,13 +727,13 @@ private byte[] DecryptKey(byte[] cipherData, byte[] desKey, byte[] IV)
///
/// Detect the key type from the pem file.
///
- /// key file path in pem format
+ /// api key in string format
/// Private Key Type
- private PrivateKeyType GetKeyType(string keyFilePath)
+ private PrivateKeyType GetKeyType(string keyString)
{
- if (!File.Exists(keyFilePath))
+ if (string.IsNullOrEmpty(keyString))
{
- throw new Exception("Key file path does not exist.");
+ throw new Exception("No API key has been provided.");
}
const string ecPrivateKeyHeader = "BEGIN EC PRIVATE KEY";
@@ -737,7 +743,7 @@ private PrivateKeyType GetKeyType(string keyFilePath)
//var pkcs8Header = "BEGIN PRIVATE KEY";
//var pkcs8Footer = "END PRIVATE KEY";
PrivateKeyType keyType;
- var key = File.ReadAllLines(keyFilePath);
+ var key = KeyString.TrimEnd().Split('\n');
if (key[0].Contains(rsaPrivateKeyHeader) &&
key[key.Length - 1].ToString().Contains(rsaPrivateFooter))
@@ -755,6 +761,30 @@ private PrivateKeyType GetKeyType(string keyFilePath)
}
return keyType;
}
+
+ ///
+ /// Read the api key form the api key file path and stored it in KeyString property.
+ ///
+ /// api key file path
+ private string ReadApiKeyFromFile(string apiKeyFilePath)
+ {
+ string apiKeyString = null;
+ if(!string.IsNullOrEmpty(apiKeyFilePath) && !string.IsNullOrEmpty(this.KeyString))
+ {
+ throw new Exception("Configure either the KeyFilePath or configure the KeyString property.");
+ }
+
+ if(File.Exists(apiKeyFilePath))
+ {
+ apiKeyString = File.ReadAllText(apiKeyFilePath);
+ }
+ else
+ {
+ throw new Exception("Provided API key file path does not exists.");
+ }
+ return apiKeyString;
+ }
+
#endregion
}
}
diff --git a/samples/client/petstore/csharp-netcore/OpenAPIClientCore/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs b/samples/client/petstore/csharp-netcore/OpenAPIClientCore/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs
index 6a8f9c8dc016..520d4c23b57b 100644
--- a/samples/client/petstore/csharp-netcore/OpenAPIClientCore/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs
+++ b/samples/client/petstore/csharp-netcore/OpenAPIClientCore/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs
@@ -48,6 +48,11 @@ public HttpSigningConfiguration()
///
public string KeyFilePath { get; set; }
+ ///
+ /// Specify the API key in the form of a string, either configure the KeyString property or configure the KeyFilePath property.
+ ///
+ public string KeyString { get; set; }
+
///
/// Gets the key pass phrase for password protected key
///
@@ -116,6 +121,17 @@ internal Dictionary GetHttpSignedHeader(string basePath,string m
var HttpSignedRequestHeader = new Dictionary();
var HttpSignatureHeader = new Dictionary();
+ //Read the api key from the file
+ if(!string.IsNullOrEmpty(this.KeyFilePath))
+ {
+ this.KeyString = ReadApiKeyFromFile(KeyFilePath);
+ }
+
+ if(string.IsNullOrEmpty(KeyString))
+ {
+ throw new Exception("No API key has been provided.");
+ }
+
if (HttpSigningHeader.Count == 0)
{
HttpSigningHeader.Add("(created)");
@@ -250,7 +266,7 @@ internal Dictionary GetHttpSignedHeader(string basePath,string m
var headerValuesString = string.Join("\n", headerValuesList);
var signatureStringHash = GetStringHash(HashAlgorithm.ToString(), headerValuesString);
string headerSignatureStr = null;
- var keyType = GetKeyType(KeyFilePath);
+ var keyType = GetKeyType(KeyString);
if (keyType == PrivateKeyType.RSA)
{
@@ -301,7 +317,7 @@ private int GetUnixTime(DateTime date2)
private string GetRSASignature(byte[] stringToSign)
{
- RSA rsa = GetRSAProviderFromPemFile(KeyFilePath, KeyPassPhrase);
+ RSA rsa = GetRSAProviderFromPemFile(KeyString, KeyPassPhrase);
if (SigningAlgorithm == "RSASSA-PSS")
{
var signedbytes = rsa.SignHash(stringToSign, HashAlgorithm, RSASignaturePadding.Pss);
@@ -325,14 +341,9 @@ private string GetRSASignature(byte[] stringToSign)
/// ECDSA signature
private string GetECDSASignature(byte[] dataToSign)
{
- if (!File.Exists(KeyFilePath))
- {
- throw new Exception("key file path does not exist.");
- }
-
const string ecKeyHeader = "-----BEGIN EC PRIVATE KEY-----";
const string ecKeyFooter = "-----END EC PRIVATE KEY-----";
- var keyStr = File.ReadAllText(KeyFilePath);
+ var keyStr = KeyString;
var ecKeyBase64String = keyStr.Replace(ecKeyHeader, "").Replace(ecKeyFooter, "").Trim();
var keyBytes = System.Convert.FromBase64String(ecKeyBase64String);
var ecdsa = ECDsa.Create();
@@ -423,18 +434,13 @@ private byte[] ConvertToECDSAANS1Format(byte[] signedBytes)
return derBytes.ToArray();
}
- private RSACryptoServiceProvider GetRSAProviderFromPemFile(string pemfile, SecureString keyPassPhrase = null)
+ private RSACryptoServiceProvider GetRSAProviderFromPemFile(string keyString, SecureString keyPassPhrase = null)
{
const string pempubheader = "-----BEGIN PUBLIC KEY-----";
const string pempubfooter = "-----END PUBLIC KEY-----";
bool isPrivateKeyFile = true;
byte[] pemkey = null;
-
- if (!File.Exists(pemfile))
- {
- throw new Exception("private key file does not exist.");
- }
- string pemstr = File.ReadAllText(pemfile).Trim();
+ string pemstr = keyString;
if (pemstr.StartsWith(pempubheader) && pemstr.EndsWith(pempubfooter))
{
@@ -721,13 +727,13 @@ private byte[] DecryptKey(byte[] cipherData, byte[] desKey, byte[] IV)
///
/// Detect the key type from the pem file.
///
- /// key file path in pem format
+ /// api key in string format
/// Private Key Type
- private PrivateKeyType GetKeyType(string keyFilePath)
+ private PrivateKeyType GetKeyType(string keyString)
{
- if (!File.Exists(keyFilePath))
+ if (string.IsNullOrEmpty(keyString))
{
- throw new Exception("Key file path does not exist.");
+ throw new Exception("No API key has been provided.");
}
const string ecPrivateKeyHeader = "BEGIN EC PRIVATE KEY";
@@ -737,7 +743,7 @@ private PrivateKeyType GetKeyType(string keyFilePath)
//var pkcs8Header = "BEGIN PRIVATE KEY";
//var pkcs8Footer = "END PRIVATE KEY";
PrivateKeyType keyType;
- var key = File.ReadAllLines(keyFilePath);
+ var key = KeyString.TrimEnd().Split('\n');
if (key[0].Contains(rsaPrivateKeyHeader) &&
key[key.Length - 1].ToString().Contains(rsaPrivateFooter))
@@ -755,6 +761,30 @@ private PrivateKeyType GetKeyType(string keyFilePath)
}
return keyType;
}
+
+ ///
+ /// Read the api key form the api key file path and stored it in KeyString property.
+ ///
+ /// api key file path
+ private string ReadApiKeyFromFile(string apiKeyFilePath)
+ {
+ string apiKeyString = null;
+ if(!string.IsNullOrEmpty(apiKeyFilePath) && !string.IsNullOrEmpty(this.KeyString))
+ {
+ throw new Exception("Configure either the KeyFilePath or configure the KeyString property.");
+ }
+
+ if(File.Exists(apiKeyFilePath))
+ {
+ apiKeyString = File.ReadAllText(apiKeyFilePath);
+ }
+ else
+ {
+ throw new Exception("Provided API key file path does not exists.");
+ }
+ return apiKeyString;
+ }
+
#endregion
}
}
From ac58a25c411d0175e432607f0fe4e0ba4cb65d89 Mon Sep 17 00:00:00 2001
From: Ghufran Zahidi <18732053+Ghufz@users.noreply.github.com>
Date: Tue, 13 Jun 2023 18:47:52 +0530
Subject: [PATCH 3/3] removed the either or check for keyFilePath and KeyString
---
.../csharp-netcore/HttpSigningConfiguration.mustache | 7 +------
.../Org.OpenAPITools/Client/HttpSigningConfiguration.cs | 7 +------
.../Org.OpenAPITools/Client/HttpSigningConfiguration.cs | 7 +------
.../Org.OpenAPITools/Client/HttpSigningConfiguration.cs | 7 +------
.../Org.OpenAPITools/Client/HttpSigningConfiguration.cs | 7 +------
.../Org.OpenAPITools/Client/HttpSigningConfiguration.cs | 7 +------
.../Org.OpenAPITools/Client/HttpSigningConfiguration.cs | 7 +------
7 files changed, 7 insertions(+), 42 deletions(-)
diff --git a/modules/openapi-generator/src/main/resources/csharp-netcore/HttpSigningConfiguration.mustache b/modules/openapi-generator/src/main/resources/csharp-netcore/HttpSigningConfiguration.mustache
index 9c7f89333f78..32dbb195b865 100644
--- a/modules/openapi-generator/src/main/resources/csharp-netcore/HttpSigningConfiguration.mustache
+++ b/modules/openapi-generator/src/main/resources/csharp-netcore/HttpSigningConfiguration.mustache
@@ -114,7 +114,7 @@ namespace {{packageName}}.Client
var HttpSignatureHeader = new Dictionary();
//Read the api key from the file
- if(!string.IsNullOrEmpty(this.KeyFilePath))
+ if(string.IsNullOrEmpty(this.KeyString))
{
this.KeyString = ReadApiKeyFromFile(KeyFilePath);
}
@@ -761,11 +761,6 @@ namespace {{packageName}}.Client
private string ReadApiKeyFromFile(string apiKeyFilePath)
{
string apiKeyString = null;
- if(!string.IsNullOrEmpty(apiKeyFilePath) && !string.IsNullOrEmpty(this.KeyString))
- {
- throw new Exception("Configure either the KeyFilePath or configure the KeyString property.");
- }
-
if(File.Exists(apiKeyFilePath))
{
apiKeyString = File.ReadAllText(apiKeyFilePath);
diff --git a/samples/client/petstore/csharp-netcore/OpenAPIClient-ConditionalSerialization/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs b/samples/client/petstore/csharp-netcore/OpenAPIClient-ConditionalSerialization/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs
index 520d4c23b57b..d9566545dcea 100644
--- a/samples/client/petstore/csharp-netcore/OpenAPIClient-ConditionalSerialization/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs
+++ b/samples/client/petstore/csharp-netcore/OpenAPIClient-ConditionalSerialization/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs
@@ -122,7 +122,7 @@ internal Dictionary GetHttpSignedHeader(string basePath,string m
var HttpSignatureHeader = new Dictionary();
//Read the api key from the file
- if(!string.IsNullOrEmpty(this.KeyFilePath))
+ if(string.IsNullOrEmpty(this.KeyString))
{
this.KeyString = ReadApiKeyFromFile(KeyFilePath);
}
@@ -769,11 +769,6 @@ private PrivateKeyType GetKeyType(string keyString)
private string ReadApiKeyFromFile(string apiKeyFilePath)
{
string apiKeyString = null;
- if(!string.IsNullOrEmpty(apiKeyFilePath) && !string.IsNullOrEmpty(this.KeyString))
- {
- throw new Exception("Configure either the KeyFilePath or configure the KeyString property.");
- }
-
if(File.Exists(apiKeyFilePath))
{
apiKeyString = File.ReadAllText(apiKeyFilePath);
diff --git a/samples/client/petstore/csharp-netcore/OpenAPIClient-httpclient/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs b/samples/client/petstore/csharp-netcore/OpenAPIClient-httpclient/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs
index 520d4c23b57b..d9566545dcea 100644
--- a/samples/client/petstore/csharp-netcore/OpenAPIClient-httpclient/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs
+++ b/samples/client/petstore/csharp-netcore/OpenAPIClient-httpclient/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs
@@ -122,7 +122,7 @@ internal Dictionary GetHttpSignedHeader(string basePath,string m
var HttpSignatureHeader = new Dictionary();
//Read the api key from the file
- if(!string.IsNullOrEmpty(this.KeyFilePath))
+ if(string.IsNullOrEmpty(this.KeyString))
{
this.KeyString = ReadApiKeyFromFile(KeyFilePath);
}
@@ -769,11 +769,6 @@ private PrivateKeyType GetKeyType(string keyString)
private string ReadApiKeyFromFile(string apiKeyFilePath)
{
string apiKeyString = null;
- if(!string.IsNullOrEmpty(apiKeyFilePath) && !string.IsNullOrEmpty(this.KeyString))
- {
- throw new Exception("Configure either the KeyFilePath or configure the KeyString property.");
- }
-
if(File.Exists(apiKeyFilePath))
{
apiKeyString = File.ReadAllText(apiKeyFilePath);
diff --git a/samples/client/petstore/csharp-netcore/OpenAPIClient-net47/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs b/samples/client/petstore/csharp-netcore/OpenAPIClient-net47/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs
index 520d4c23b57b..d9566545dcea 100644
--- a/samples/client/petstore/csharp-netcore/OpenAPIClient-net47/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs
+++ b/samples/client/petstore/csharp-netcore/OpenAPIClient-net47/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs
@@ -122,7 +122,7 @@ internal Dictionary GetHttpSignedHeader(string basePath,string m
var HttpSignatureHeader = new Dictionary();
//Read the api key from the file
- if(!string.IsNullOrEmpty(this.KeyFilePath))
+ if(string.IsNullOrEmpty(this.KeyString))
{
this.KeyString = ReadApiKeyFromFile(KeyFilePath);
}
@@ -769,11 +769,6 @@ private PrivateKeyType GetKeyType(string keyString)
private string ReadApiKeyFromFile(string apiKeyFilePath)
{
string apiKeyString = null;
- if(!string.IsNullOrEmpty(apiKeyFilePath) && !string.IsNullOrEmpty(this.KeyString))
- {
- throw new Exception("Configure either the KeyFilePath or configure the KeyString property.");
- }
-
if(File.Exists(apiKeyFilePath))
{
apiKeyString = File.ReadAllText(apiKeyFilePath);
diff --git a/samples/client/petstore/csharp-netcore/OpenAPIClient-net5.0/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs b/samples/client/petstore/csharp-netcore/OpenAPIClient-net5.0/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs
index 520d4c23b57b..d9566545dcea 100644
--- a/samples/client/petstore/csharp-netcore/OpenAPIClient-net5.0/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs
+++ b/samples/client/petstore/csharp-netcore/OpenAPIClient-net5.0/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs
@@ -122,7 +122,7 @@ internal Dictionary GetHttpSignedHeader(string basePath,string m
var HttpSignatureHeader = new Dictionary();
//Read the api key from the file
- if(!string.IsNullOrEmpty(this.KeyFilePath))
+ if(string.IsNullOrEmpty(this.KeyString))
{
this.KeyString = ReadApiKeyFromFile(KeyFilePath);
}
@@ -769,11 +769,6 @@ private PrivateKeyType GetKeyType(string keyString)
private string ReadApiKeyFromFile(string apiKeyFilePath)
{
string apiKeyString = null;
- if(!string.IsNullOrEmpty(apiKeyFilePath) && !string.IsNullOrEmpty(this.KeyString))
- {
- throw new Exception("Configure either the KeyFilePath or configure the KeyString property.");
- }
-
if(File.Exists(apiKeyFilePath))
{
apiKeyString = File.ReadAllText(apiKeyFilePath);
diff --git a/samples/client/petstore/csharp-netcore/OpenAPIClient/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs b/samples/client/petstore/csharp-netcore/OpenAPIClient/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs
index 520d4c23b57b..d9566545dcea 100644
--- a/samples/client/petstore/csharp-netcore/OpenAPIClient/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs
+++ b/samples/client/petstore/csharp-netcore/OpenAPIClient/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs
@@ -122,7 +122,7 @@ internal Dictionary GetHttpSignedHeader(string basePath,string m
var HttpSignatureHeader = new Dictionary();
//Read the api key from the file
- if(!string.IsNullOrEmpty(this.KeyFilePath))
+ if(string.IsNullOrEmpty(this.KeyString))
{
this.KeyString = ReadApiKeyFromFile(KeyFilePath);
}
@@ -769,11 +769,6 @@ private PrivateKeyType GetKeyType(string keyString)
private string ReadApiKeyFromFile(string apiKeyFilePath)
{
string apiKeyString = null;
- if(!string.IsNullOrEmpty(apiKeyFilePath) && !string.IsNullOrEmpty(this.KeyString))
- {
- throw new Exception("Configure either the KeyFilePath or configure the KeyString property.");
- }
-
if(File.Exists(apiKeyFilePath))
{
apiKeyString = File.ReadAllText(apiKeyFilePath);
diff --git a/samples/client/petstore/csharp-netcore/OpenAPIClientCore/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs b/samples/client/petstore/csharp-netcore/OpenAPIClientCore/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs
index 520d4c23b57b..d9566545dcea 100644
--- a/samples/client/petstore/csharp-netcore/OpenAPIClientCore/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs
+++ b/samples/client/petstore/csharp-netcore/OpenAPIClientCore/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs
@@ -122,7 +122,7 @@ internal Dictionary GetHttpSignedHeader(string basePath,string m
var HttpSignatureHeader = new Dictionary();
//Read the api key from the file
- if(!string.IsNullOrEmpty(this.KeyFilePath))
+ if(string.IsNullOrEmpty(this.KeyString))
{
this.KeyString = ReadApiKeyFromFile(KeyFilePath);
}
@@ -769,11 +769,6 @@ private PrivateKeyType GetKeyType(string keyString)
private string ReadApiKeyFromFile(string apiKeyFilePath)
{
string apiKeyString = null;
- if(!string.IsNullOrEmpty(apiKeyFilePath) && !string.IsNullOrEmpty(this.KeyString))
- {
- throw new Exception("Configure either the KeyFilePath or configure the KeyString property.");
- }
-
if(File.Exists(apiKeyFilePath))
{
apiKeyString = File.ReadAllText(apiKeyFilePath);