forked from loafle/openapi-generator-original
Fixed the HttpSigning issue for ECDSA key supplied as string. (#17459)
Co-authored-by: Aanisha Mishra <aanisha.mishra05@gmail.com> Co-authored-by: Vikrant Balyan (vvb) <vvb@cisco.com> Co-authored-by: Vikrant Balyan <vvb@users.noreply.github.com> Co-authored-by: Sebastien Rosset <serosset@cisco.com>
This commit is contained in:
parent
c252216700
commit
35b47e6382
@ -102,14 +102,13 @@ namespace {{packageName}}.Client
|
|||||||
const string HEADER_AUTHORIZATION = "Authorization";
|
const string HEADER_AUTHORIZATION = "Authorization";
|
||||||
|
|
||||||
//Read the api key from the file
|
//Read the api key from the file
|
||||||
if(string.IsNullOrEmpty(this.KeyString))
|
if(File.Exists(KeyFilePath))
|
||||||
{
|
{
|
||||||
this.KeyString = ReadApiKeyFromFile(KeyFilePath);
|
this.KeyString = ReadApiKeyFromFile(KeyFilePath);
|
||||||
}
|
}
|
||||||
|
else if(string.IsNullOrEmpty(KeyString))
|
||||||
if(string.IsNullOrEmpty(KeyString))
|
|
||||||
{
|
{
|
||||||
throw new Exception("No API key has been provided.");
|
throw new Exception("No API key has been provided. Supply it using either KeyFilePath or KeyString");
|
||||||
}
|
}
|
||||||
|
|
||||||
//Hash table to store singed headers
|
//Hash table to store singed headers
|
||||||
@ -317,6 +316,10 @@ namespace {{packageName}}.Client
|
|||||||
|
|
||||||
private string GetRSASignature(byte[] stringToSign)
|
private string GetRSASignature(byte[] stringToSign)
|
||||||
{
|
{
|
||||||
|
if (string.IsNullOrEmpty(KeyString))
|
||||||
|
{
|
||||||
|
throw new Exception("No API key has been provided.");
|
||||||
|
}
|
||||||
RSA rsa = GetRSAProviderFromPemFile(KeyString, KeyPassPhrase);
|
RSA rsa = GetRSAProviderFromPemFile(KeyString, KeyPassPhrase);
|
||||||
if (SigningAlgorithm == "RSASSA-PSS")
|
if (SigningAlgorithm == "RSASSA-PSS")
|
||||||
{
|
{
|
||||||
@ -342,8 +345,10 @@ namespace {{packageName}}.Client
|
|||||||
private string GetECDSASignature(byte[] dataToSign)
|
private string GetECDSASignature(byte[] dataToSign)
|
||||||
{
|
{
|
||||||
{{#net60OrLater}}
|
{{#net60OrLater}}
|
||||||
if (!File.Exists(KeyFilePath))
|
if (!File.Exists(KeyFilePath) && string.IsNullOrEmpty(KeyString))
|
||||||
throw new Exception("key file path does not exist.");
|
{
|
||||||
|
throw new Exception("No API key has been provided.");
|
||||||
|
}
|
||||||
|
|
||||||
var keyStr = KeyString;
|
var keyStr = KeyString;
|
||||||
const string ecKeyHeader = "-----BEGIN EC PRIVATE KEY-----";
|
const string ecKeyHeader = "-----BEGIN EC PRIVATE KEY-----";
|
||||||
@ -443,6 +448,11 @@ namespace {{packageName}}.Client
|
|||||||
|
|
||||||
private RSACryptoServiceProvider GetRSAProviderFromPemFile(string keyString, SecureString keyPassPhrase = null)
|
private RSACryptoServiceProvider GetRSAProviderFromPemFile(string keyString, SecureString keyPassPhrase = null)
|
||||||
{
|
{
|
||||||
|
if (string.IsNullOrEmpty(KeyString))
|
||||||
|
{
|
||||||
|
throw new Exception("No API key has been provided.");
|
||||||
|
}
|
||||||
|
|
||||||
const string pempubheader = "-----BEGIN PUBLIC KEY-----";
|
const string pempubheader = "-----BEGIN PUBLIC KEY-----";
|
||||||
const string pempubfooter = "-----END PUBLIC KEY-----";
|
const string pempubfooter = "-----END PUBLIC KEY-----";
|
||||||
bool isPrivateKeyFile = true;
|
bool isPrivateKeyFile = true;
|
||||||
|
@ -110,14 +110,13 @@ namespace Org.OpenAPITools.Client
|
|||||||
const string HEADER_AUTHORIZATION = "Authorization";
|
const string HEADER_AUTHORIZATION = "Authorization";
|
||||||
|
|
||||||
//Read the api key from the file
|
//Read the api key from the file
|
||||||
if(string.IsNullOrEmpty(this.KeyString))
|
if(File.Exists(KeyFilePath))
|
||||||
{
|
{
|
||||||
this.KeyString = ReadApiKeyFromFile(KeyFilePath);
|
this.KeyString = ReadApiKeyFromFile(KeyFilePath);
|
||||||
}
|
}
|
||||||
|
else if(string.IsNullOrEmpty(KeyString))
|
||||||
if(string.IsNullOrEmpty(KeyString))
|
|
||||||
{
|
{
|
||||||
throw new Exception("No API key has been provided.");
|
throw new Exception("No API key has been provided. Supply it using either KeyFilePath or KeyString");
|
||||||
}
|
}
|
||||||
|
|
||||||
//Hash table to store singed headers
|
//Hash table to store singed headers
|
||||||
@ -325,6 +324,10 @@ namespace Org.OpenAPITools.Client
|
|||||||
|
|
||||||
private string GetRSASignature(byte[] stringToSign)
|
private string GetRSASignature(byte[] stringToSign)
|
||||||
{
|
{
|
||||||
|
if (string.IsNullOrEmpty(KeyString))
|
||||||
|
{
|
||||||
|
throw new Exception("No API key has been provided.");
|
||||||
|
}
|
||||||
RSA rsa = GetRSAProviderFromPemFile(KeyString, KeyPassPhrase);
|
RSA rsa = GetRSAProviderFromPemFile(KeyString, KeyPassPhrase);
|
||||||
if (SigningAlgorithm == "RSASSA-PSS")
|
if (SigningAlgorithm == "RSASSA-PSS")
|
||||||
{
|
{
|
||||||
@ -412,6 +415,11 @@ namespace Org.OpenAPITools.Client
|
|||||||
|
|
||||||
private RSACryptoServiceProvider GetRSAProviderFromPemFile(string keyString, SecureString keyPassPhrase = null)
|
private RSACryptoServiceProvider GetRSAProviderFromPemFile(string keyString, SecureString keyPassPhrase = null)
|
||||||
{
|
{
|
||||||
|
if (string.IsNullOrEmpty(KeyString))
|
||||||
|
{
|
||||||
|
throw new Exception("No API key has been provided.");
|
||||||
|
}
|
||||||
|
|
||||||
const string pempubheader = "-----BEGIN PUBLIC KEY-----";
|
const string pempubheader = "-----BEGIN PUBLIC KEY-----";
|
||||||
const string pempubfooter = "-----END PUBLIC KEY-----";
|
const string pempubfooter = "-----END PUBLIC KEY-----";
|
||||||
bool isPrivateKeyFile = true;
|
bool isPrivateKeyFile = true;
|
||||||
|
@ -110,14 +110,13 @@ namespace Org.OpenAPITools.Client
|
|||||||
const string HEADER_AUTHORIZATION = "Authorization";
|
const string HEADER_AUTHORIZATION = "Authorization";
|
||||||
|
|
||||||
//Read the api key from the file
|
//Read the api key from the file
|
||||||
if(string.IsNullOrEmpty(this.KeyString))
|
if(File.Exists(KeyFilePath))
|
||||||
{
|
{
|
||||||
this.KeyString = ReadApiKeyFromFile(KeyFilePath);
|
this.KeyString = ReadApiKeyFromFile(KeyFilePath);
|
||||||
}
|
}
|
||||||
|
else if(string.IsNullOrEmpty(KeyString))
|
||||||
if(string.IsNullOrEmpty(KeyString))
|
|
||||||
{
|
{
|
||||||
throw new Exception("No API key has been provided.");
|
throw new Exception("No API key has been provided. Supply it using either KeyFilePath or KeyString");
|
||||||
}
|
}
|
||||||
|
|
||||||
//Hash table to store singed headers
|
//Hash table to store singed headers
|
||||||
@ -325,6 +324,10 @@ namespace Org.OpenAPITools.Client
|
|||||||
|
|
||||||
private string GetRSASignature(byte[] stringToSign)
|
private string GetRSASignature(byte[] stringToSign)
|
||||||
{
|
{
|
||||||
|
if (string.IsNullOrEmpty(KeyString))
|
||||||
|
{
|
||||||
|
throw new Exception("No API key has been provided.");
|
||||||
|
}
|
||||||
RSA rsa = GetRSAProviderFromPemFile(KeyString, KeyPassPhrase);
|
RSA rsa = GetRSAProviderFromPemFile(KeyString, KeyPassPhrase);
|
||||||
if (SigningAlgorithm == "RSASSA-PSS")
|
if (SigningAlgorithm == "RSASSA-PSS")
|
||||||
{
|
{
|
||||||
@ -412,6 +415,11 @@ namespace Org.OpenAPITools.Client
|
|||||||
|
|
||||||
private RSACryptoServiceProvider GetRSAProviderFromPemFile(string keyString, SecureString keyPassPhrase = null)
|
private RSACryptoServiceProvider GetRSAProviderFromPemFile(string keyString, SecureString keyPassPhrase = null)
|
||||||
{
|
{
|
||||||
|
if (string.IsNullOrEmpty(KeyString))
|
||||||
|
{
|
||||||
|
throw new Exception("No API key has been provided.");
|
||||||
|
}
|
||||||
|
|
||||||
const string pempubheader = "-----BEGIN PUBLIC KEY-----";
|
const string pempubheader = "-----BEGIN PUBLIC KEY-----";
|
||||||
const string pempubfooter = "-----END PUBLIC KEY-----";
|
const string pempubfooter = "-----END PUBLIC KEY-----";
|
||||||
bool isPrivateKeyFile = true;
|
bool isPrivateKeyFile = true;
|
||||||
|
@ -110,14 +110,13 @@ namespace Org.OpenAPITools.Client
|
|||||||
const string HEADER_AUTHORIZATION = "Authorization";
|
const string HEADER_AUTHORIZATION = "Authorization";
|
||||||
|
|
||||||
//Read the api key from the file
|
//Read the api key from the file
|
||||||
if(string.IsNullOrEmpty(this.KeyString))
|
if(File.Exists(KeyFilePath))
|
||||||
{
|
{
|
||||||
this.KeyString = ReadApiKeyFromFile(KeyFilePath);
|
this.KeyString = ReadApiKeyFromFile(KeyFilePath);
|
||||||
}
|
}
|
||||||
|
else if(string.IsNullOrEmpty(KeyString))
|
||||||
if(string.IsNullOrEmpty(KeyString))
|
|
||||||
{
|
{
|
||||||
throw new Exception("No API key has been provided.");
|
throw new Exception("No API key has been provided. Supply it using either KeyFilePath or KeyString");
|
||||||
}
|
}
|
||||||
|
|
||||||
//Hash table to store singed headers
|
//Hash table to store singed headers
|
||||||
@ -325,6 +324,10 @@ namespace Org.OpenAPITools.Client
|
|||||||
|
|
||||||
private string GetRSASignature(byte[] stringToSign)
|
private string GetRSASignature(byte[] stringToSign)
|
||||||
{
|
{
|
||||||
|
if (string.IsNullOrEmpty(KeyString))
|
||||||
|
{
|
||||||
|
throw new Exception("No API key has been provided.");
|
||||||
|
}
|
||||||
RSA rsa = GetRSAProviderFromPemFile(KeyString, KeyPassPhrase);
|
RSA rsa = GetRSAProviderFromPemFile(KeyString, KeyPassPhrase);
|
||||||
if (SigningAlgorithm == "RSASSA-PSS")
|
if (SigningAlgorithm == "RSASSA-PSS")
|
||||||
{
|
{
|
||||||
@ -412,6 +415,11 @@ namespace Org.OpenAPITools.Client
|
|||||||
|
|
||||||
private RSACryptoServiceProvider GetRSAProviderFromPemFile(string keyString, SecureString keyPassPhrase = null)
|
private RSACryptoServiceProvider GetRSAProviderFromPemFile(string keyString, SecureString keyPassPhrase = null)
|
||||||
{
|
{
|
||||||
|
if (string.IsNullOrEmpty(KeyString))
|
||||||
|
{
|
||||||
|
throw new Exception("No API key has been provided.");
|
||||||
|
}
|
||||||
|
|
||||||
const string pempubheader = "-----BEGIN PUBLIC KEY-----";
|
const string pempubheader = "-----BEGIN PUBLIC KEY-----";
|
||||||
const string pempubfooter = "-----END PUBLIC KEY-----";
|
const string pempubfooter = "-----END PUBLIC KEY-----";
|
||||||
bool isPrivateKeyFile = true;
|
bool isPrivateKeyFile = true;
|
||||||
|
@ -110,14 +110,13 @@ namespace Org.OpenAPITools.Client
|
|||||||
const string HEADER_AUTHORIZATION = "Authorization";
|
const string HEADER_AUTHORIZATION = "Authorization";
|
||||||
|
|
||||||
//Read the api key from the file
|
//Read the api key from the file
|
||||||
if(string.IsNullOrEmpty(this.KeyString))
|
if(File.Exists(KeyFilePath))
|
||||||
{
|
{
|
||||||
this.KeyString = ReadApiKeyFromFile(KeyFilePath);
|
this.KeyString = ReadApiKeyFromFile(KeyFilePath);
|
||||||
}
|
}
|
||||||
|
else if(string.IsNullOrEmpty(KeyString))
|
||||||
if(string.IsNullOrEmpty(KeyString))
|
|
||||||
{
|
{
|
||||||
throw new Exception("No API key has been provided.");
|
throw new Exception("No API key has been provided. Supply it using either KeyFilePath or KeyString");
|
||||||
}
|
}
|
||||||
|
|
||||||
//Hash table to store singed headers
|
//Hash table to store singed headers
|
||||||
@ -325,6 +324,10 @@ namespace Org.OpenAPITools.Client
|
|||||||
|
|
||||||
private string GetRSASignature(byte[] stringToSign)
|
private string GetRSASignature(byte[] stringToSign)
|
||||||
{
|
{
|
||||||
|
if (string.IsNullOrEmpty(KeyString))
|
||||||
|
{
|
||||||
|
throw new Exception("No API key has been provided.");
|
||||||
|
}
|
||||||
RSA rsa = GetRSAProviderFromPemFile(KeyString, KeyPassPhrase);
|
RSA rsa = GetRSAProviderFromPemFile(KeyString, KeyPassPhrase);
|
||||||
if (SigningAlgorithm == "RSASSA-PSS")
|
if (SigningAlgorithm == "RSASSA-PSS")
|
||||||
{
|
{
|
||||||
@ -412,6 +415,11 @@ namespace Org.OpenAPITools.Client
|
|||||||
|
|
||||||
private RSACryptoServiceProvider GetRSAProviderFromPemFile(string keyString, SecureString keyPassPhrase = null)
|
private RSACryptoServiceProvider GetRSAProviderFromPemFile(string keyString, SecureString keyPassPhrase = null)
|
||||||
{
|
{
|
||||||
|
if (string.IsNullOrEmpty(KeyString))
|
||||||
|
{
|
||||||
|
throw new Exception("No API key has been provided.");
|
||||||
|
}
|
||||||
|
|
||||||
const string pempubheader = "-----BEGIN PUBLIC KEY-----";
|
const string pempubheader = "-----BEGIN PUBLIC KEY-----";
|
||||||
const string pempubfooter = "-----END PUBLIC KEY-----";
|
const string pempubfooter = "-----END PUBLIC KEY-----";
|
||||||
bool isPrivateKeyFile = true;
|
bool isPrivateKeyFile = true;
|
||||||
|
@ -110,14 +110,13 @@ namespace Org.OpenAPITools.Client
|
|||||||
const string HEADER_AUTHORIZATION = "Authorization";
|
const string HEADER_AUTHORIZATION = "Authorization";
|
||||||
|
|
||||||
//Read the api key from the file
|
//Read the api key from the file
|
||||||
if(string.IsNullOrEmpty(this.KeyString))
|
if(File.Exists(KeyFilePath))
|
||||||
{
|
{
|
||||||
this.KeyString = ReadApiKeyFromFile(KeyFilePath);
|
this.KeyString = ReadApiKeyFromFile(KeyFilePath);
|
||||||
}
|
}
|
||||||
|
else if(string.IsNullOrEmpty(KeyString))
|
||||||
if(string.IsNullOrEmpty(KeyString))
|
|
||||||
{
|
{
|
||||||
throw new Exception("No API key has been provided.");
|
throw new Exception("No API key has been provided. Supply it using either KeyFilePath or KeyString");
|
||||||
}
|
}
|
||||||
|
|
||||||
//Hash table to store singed headers
|
//Hash table to store singed headers
|
||||||
@ -325,6 +324,10 @@ namespace Org.OpenAPITools.Client
|
|||||||
|
|
||||||
private string GetRSASignature(byte[] stringToSign)
|
private string GetRSASignature(byte[] stringToSign)
|
||||||
{
|
{
|
||||||
|
if (string.IsNullOrEmpty(KeyString))
|
||||||
|
{
|
||||||
|
throw new Exception("No API key has been provided.");
|
||||||
|
}
|
||||||
RSA rsa = GetRSAProviderFromPemFile(KeyString, KeyPassPhrase);
|
RSA rsa = GetRSAProviderFromPemFile(KeyString, KeyPassPhrase);
|
||||||
if (SigningAlgorithm == "RSASSA-PSS")
|
if (SigningAlgorithm == "RSASSA-PSS")
|
||||||
{
|
{
|
||||||
@ -349,8 +352,10 @@ namespace Org.OpenAPITools.Client
|
|||||||
/// <returns>ECDSA signature</returns>
|
/// <returns>ECDSA signature</returns>
|
||||||
private string GetECDSASignature(byte[] dataToSign)
|
private string GetECDSASignature(byte[] dataToSign)
|
||||||
{
|
{
|
||||||
if (!File.Exists(KeyFilePath))
|
if (!File.Exists(KeyFilePath) && string.IsNullOrEmpty(KeyString))
|
||||||
throw new Exception("key file path does not exist.");
|
{
|
||||||
|
throw new Exception("No API key has been provided.");
|
||||||
|
}
|
||||||
|
|
||||||
var keyStr = KeyString;
|
var keyStr = KeyString;
|
||||||
const string ecKeyHeader = "-----BEGIN EC PRIVATE KEY-----";
|
const string ecKeyHeader = "-----BEGIN EC PRIVATE KEY-----";
|
||||||
@ -446,6 +451,11 @@ namespace Org.OpenAPITools.Client
|
|||||||
|
|
||||||
private RSACryptoServiceProvider GetRSAProviderFromPemFile(string keyString, SecureString keyPassPhrase = null)
|
private RSACryptoServiceProvider GetRSAProviderFromPemFile(string keyString, SecureString keyPassPhrase = null)
|
||||||
{
|
{
|
||||||
|
if (string.IsNullOrEmpty(KeyString))
|
||||||
|
{
|
||||||
|
throw new Exception("No API key has been provided.");
|
||||||
|
}
|
||||||
|
|
||||||
const string pempubheader = "-----BEGIN PUBLIC KEY-----";
|
const string pempubheader = "-----BEGIN PUBLIC KEY-----";
|
||||||
const string pempubfooter = "-----END PUBLIC KEY-----";
|
const string pempubfooter = "-----END PUBLIC KEY-----";
|
||||||
bool isPrivateKeyFile = true;
|
bool isPrivateKeyFile = true;
|
||||||
|
@ -110,14 +110,13 @@ namespace Org.OpenAPITools.Client
|
|||||||
const string HEADER_AUTHORIZATION = "Authorization";
|
const string HEADER_AUTHORIZATION = "Authorization";
|
||||||
|
|
||||||
//Read the api key from the file
|
//Read the api key from the file
|
||||||
if(string.IsNullOrEmpty(this.KeyString))
|
if(File.Exists(KeyFilePath))
|
||||||
{
|
{
|
||||||
this.KeyString = ReadApiKeyFromFile(KeyFilePath);
|
this.KeyString = ReadApiKeyFromFile(KeyFilePath);
|
||||||
}
|
}
|
||||||
|
else if(string.IsNullOrEmpty(KeyString))
|
||||||
if(string.IsNullOrEmpty(KeyString))
|
|
||||||
{
|
{
|
||||||
throw new Exception("No API key has been provided.");
|
throw new Exception("No API key has been provided. Supply it using either KeyFilePath or KeyString");
|
||||||
}
|
}
|
||||||
|
|
||||||
//Hash table to store singed headers
|
//Hash table to store singed headers
|
||||||
@ -325,6 +324,10 @@ namespace Org.OpenAPITools.Client
|
|||||||
|
|
||||||
private string GetRSASignature(byte[] stringToSign)
|
private string GetRSASignature(byte[] stringToSign)
|
||||||
{
|
{
|
||||||
|
if (string.IsNullOrEmpty(KeyString))
|
||||||
|
{
|
||||||
|
throw new Exception("No API key has been provided.");
|
||||||
|
}
|
||||||
RSA rsa = GetRSAProviderFromPemFile(KeyString, KeyPassPhrase);
|
RSA rsa = GetRSAProviderFromPemFile(KeyString, KeyPassPhrase);
|
||||||
if (SigningAlgorithm == "RSASSA-PSS")
|
if (SigningAlgorithm == "RSASSA-PSS")
|
||||||
{
|
{
|
||||||
@ -412,6 +415,11 @@ namespace Org.OpenAPITools.Client
|
|||||||
|
|
||||||
private RSACryptoServiceProvider GetRSAProviderFromPemFile(string keyString, SecureString keyPassPhrase = null)
|
private RSACryptoServiceProvider GetRSAProviderFromPemFile(string keyString, SecureString keyPassPhrase = null)
|
||||||
{
|
{
|
||||||
|
if (string.IsNullOrEmpty(KeyString))
|
||||||
|
{
|
||||||
|
throw new Exception("No API key has been provided.");
|
||||||
|
}
|
||||||
|
|
||||||
const string pempubheader = "-----BEGIN PUBLIC KEY-----";
|
const string pempubheader = "-----BEGIN PUBLIC KEY-----";
|
||||||
const string pempubfooter = "-----END PUBLIC KEY-----";
|
const string pempubfooter = "-----END PUBLIC KEY-----";
|
||||||
bool isPrivateKeyFile = true;
|
bool isPrivateKeyFile = true;
|
||||||
|
@ -110,14 +110,13 @@ namespace Org.OpenAPITools.Client
|
|||||||
const string HEADER_AUTHORIZATION = "Authorization";
|
const string HEADER_AUTHORIZATION = "Authorization";
|
||||||
|
|
||||||
//Read the api key from the file
|
//Read the api key from the file
|
||||||
if(string.IsNullOrEmpty(this.KeyString))
|
if(File.Exists(KeyFilePath))
|
||||||
{
|
{
|
||||||
this.KeyString = ReadApiKeyFromFile(KeyFilePath);
|
this.KeyString = ReadApiKeyFromFile(KeyFilePath);
|
||||||
}
|
}
|
||||||
|
else if(string.IsNullOrEmpty(KeyString))
|
||||||
if(string.IsNullOrEmpty(KeyString))
|
|
||||||
{
|
{
|
||||||
throw new Exception("No API key has been provided.");
|
throw new Exception("No API key has been provided. Supply it using either KeyFilePath or KeyString");
|
||||||
}
|
}
|
||||||
|
|
||||||
//Hash table to store singed headers
|
//Hash table to store singed headers
|
||||||
@ -325,6 +324,10 @@ namespace Org.OpenAPITools.Client
|
|||||||
|
|
||||||
private string GetRSASignature(byte[] stringToSign)
|
private string GetRSASignature(byte[] stringToSign)
|
||||||
{
|
{
|
||||||
|
if (string.IsNullOrEmpty(KeyString))
|
||||||
|
{
|
||||||
|
throw new Exception("No API key has been provided.");
|
||||||
|
}
|
||||||
RSA rsa = GetRSAProviderFromPemFile(KeyString, KeyPassPhrase);
|
RSA rsa = GetRSAProviderFromPemFile(KeyString, KeyPassPhrase);
|
||||||
if (SigningAlgorithm == "RSASSA-PSS")
|
if (SigningAlgorithm == "RSASSA-PSS")
|
||||||
{
|
{
|
||||||
@ -412,6 +415,11 @@ namespace Org.OpenAPITools.Client
|
|||||||
|
|
||||||
private RSACryptoServiceProvider GetRSAProviderFromPemFile(string keyString, SecureString keyPassPhrase = null)
|
private RSACryptoServiceProvider GetRSAProviderFromPemFile(string keyString, SecureString keyPassPhrase = null)
|
||||||
{
|
{
|
||||||
|
if (string.IsNullOrEmpty(KeyString))
|
||||||
|
{
|
||||||
|
throw new Exception("No API key has been provided.");
|
||||||
|
}
|
||||||
|
|
||||||
const string pempubheader = "-----BEGIN PUBLIC KEY-----";
|
const string pempubheader = "-----BEGIN PUBLIC KEY-----";
|
||||||
const string pempubfooter = "-----END PUBLIC KEY-----";
|
const string pempubfooter = "-----END PUBLIC KEY-----";
|
||||||
bool isPrivateKeyFile = true;
|
bool isPrivateKeyFile = true;
|
||||||
|
@ -110,14 +110,13 @@ namespace Org.OpenAPITools.Client
|
|||||||
const string HEADER_AUTHORIZATION = "Authorization";
|
const string HEADER_AUTHORIZATION = "Authorization";
|
||||||
|
|
||||||
//Read the api key from the file
|
//Read the api key from the file
|
||||||
if(string.IsNullOrEmpty(this.KeyString))
|
if(File.Exists(KeyFilePath))
|
||||||
{
|
{
|
||||||
this.KeyString = ReadApiKeyFromFile(KeyFilePath);
|
this.KeyString = ReadApiKeyFromFile(KeyFilePath);
|
||||||
}
|
}
|
||||||
|
else if(string.IsNullOrEmpty(KeyString))
|
||||||
if(string.IsNullOrEmpty(KeyString))
|
|
||||||
{
|
{
|
||||||
throw new Exception("No API key has been provided.");
|
throw new Exception("No API key has been provided. Supply it using either KeyFilePath or KeyString");
|
||||||
}
|
}
|
||||||
|
|
||||||
//Hash table to store singed headers
|
//Hash table to store singed headers
|
||||||
@ -325,6 +324,10 @@ namespace Org.OpenAPITools.Client
|
|||||||
|
|
||||||
private string GetRSASignature(byte[] stringToSign)
|
private string GetRSASignature(byte[] stringToSign)
|
||||||
{
|
{
|
||||||
|
if (string.IsNullOrEmpty(KeyString))
|
||||||
|
{
|
||||||
|
throw new Exception("No API key has been provided.");
|
||||||
|
}
|
||||||
RSA rsa = GetRSAProviderFromPemFile(KeyString, KeyPassPhrase);
|
RSA rsa = GetRSAProviderFromPemFile(KeyString, KeyPassPhrase);
|
||||||
if (SigningAlgorithm == "RSASSA-PSS")
|
if (SigningAlgorithm == "RSASSA-PSS")
|
||||||
{
|
{
|
||||||
@ -349,8 +352,10 @@ namespace Org.OpenAPITools.Client
|
|||||||
/// <returns>ECDSA signature</returns>
|
/// <returns>ECDSA signature</returns>
|
||||||
private string GetECDSASignature(byte[] dataToSign)
|
private string GetECDSASignature(byte[] dataToSign)
|
||||||
{
|
{
|
||||||
if (!File.Exists(KeyFilePath))
|
if (!File.Exists(KeyFilePath) && string.IsNullOrEmpty(KeyString))
|
||||||
throw new Exception("key file path does not exist.");
|
{
|
||||||
|
throw new Exception("No API key has been provided.");
|
||||||
|
}
|
||||||
|
|
||||||
var keyStr = KeyString;
|
var keyStr = KeyString;
|
||||||
const string ecKeyHeader = "-----BEGIN EC PRIVATE KEY-----";
|
const string ecKeyHeader = "-----BEGIN EC PRIVATE KEY-----";
|
||||||
@ -446,6 +451,11 @@ namespace Org.OpenAPITools.Client
|
|||||||
|
|
||||||
private RSACryptoServiceProvider GetRSAProviderFromPemFile(string keyString, SecureString keyPassPhrase = null)
|
private RSACryptoServiceProvider GetRSAProviderFromPemFile(string keyString, SecureString keyPassPhrase = null)
|
||||||
{
|
{
|
||||||
|
if (string.IsNullOrEmpty(KeyString))
|
||||||
|
{
|
||||||
|
throw new Exception("No API key has been provided.");
|
||||||
|
}
|
||||||
|
|
||||||
const string pempubheader = "-----BEGIN PUBLIC KEY-----";
|
const string pempubheader = "-----BEGIN PUBLIC KEY-----";
|
||||||
const string pempubfooter = "-----END PUBLIC KEY-----";
|
const string pempubfooter = "-----END PUBLIC KEY-----";
|
||||||
bool isPrivateKeyFile = true;
|
bool isPrivateKeyFile = true;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user