From c24720b3454e36b37936cdfab8e8f517503815e7 Mon Sep 17 00:00:00 2001 From: sgrampone Date: Wed, 2 Oct 2024 13:39:52 -0300 Subject: [PATCH] Add log to SecurityAPI --- .../GeneXusCryptographyNetCore.csproj | 1 + .../GeneXusFtpsNetCore.csproj | 1 + .../GeneXusJWTNetCore.csproj | 1 + .../GeneXusSftpNetCore.csproj | 1 + .../GeneXusXmlSignatureNetCore.csproj | 1 + .../SecurityAPICommonsNetCore.csproj | 4 + .../Asymmetric/AsymmetricCipher.cs | 84 ++++++---- .../Asymmetric/AsymmetricSigner.cs | 66 +++++--- .../Asymmetric/StandardSigner.cs | 22 ++- .../AsymmetricEncryptionAlgorithm.cs | 22 ++- .../AsymmetricEncryptionPadding.cs | 21 ++- .../AsymmetricSigningAlgorithm.cs | 26 ++- .../AsymmetricUtils/SignatureStandardUtils.cs | 7 + .../Checksum/ChecksumCreator.cs | 21 ++- .../ChecksumUtils/ChecksumAlgorithm.cs | 10 +- .../ChecksumUtils/ChecksumInputType.cs | 10 ++ .../GeneXusCryptography.csproj | 1 + .../GeneXusCryptography/Hash/Hashing.cs | 12 +- .../HashUtils/HashAlgorithm.cs | 9 + .../GeneXusCryptography/Mac/Cmac.cs | 23 ++- .../GeneXusCryptography/Mac/Hmac.cs | 21 ++- .../PasswordDerivation/PasswordDerivation.cs | 10 ++ .../PasswordDerivationAlgorithm.cs | 8 +- .../Symmetric/SymmetricBlockCipher.cs | 136 ++++++++------- .../Symmetric/SymmetricStreamCipher.cs | 26 ++- .../SymmetricUtils/SymmetricBlockAlgorithm.cs | 9 + .../SymmetricUtils/SymmetricBlockMode.cs | 9 + .../SymmetricUtils/SymmetricBlockPadding.cs | 9 +- .../SymmetricStreamAlgorithm.cs | 13 +- .../GeneXusFtps/GeneXusFtps.csproj | 3 +- .../GeneXusFtps/GeneXusFtps/FtpsClient.cs | 56 +++++-- .../GeneXusFtps/GeneXusFtps/FtpsOptions.cs | 7 +- .../GeneXusFtpsUtils/FtpConnectionMode.cs | 14 +- .../GeneXusFtpsUtils/FtpEncoding.cs | 12 +- .../GeneXusFtpsUtils/FtpEncryptionMode.cs | 14 +- .../GeneXusFtpsUtils/FtpsProtocol.cs | 11 +- .../GeneXusJWT/GeneXusJWT.csproj | 1 + .../GeneXusJWT/JWT/JWTCreator.cs | 50 +++++- .../GeneXusJWT/JWTClaims/RegisteredClaim.cs | 18 +- .../GeneXusJWT/JWTClaims/RegisteredClaims.cs | 16 +- .../GeneXusJWT/Utils/JWTAlgorithm.cs | 21 ++- .../GeneXusJWT/Utils/UnixTimeStampCreator.cs | 4 + .../GeneXusSftp/GeneXusSftp.csproj | 3 +- .../GeneXusSftp/Sftp/SftpClient.cs | 49 +++++- .../GeneXusSftp/Sftp/SftpOptions.cs | 9 +- .../GeneXusXmlSignature/DSig/XmlDSigSigner.cs | 155 +++++++++++------- .../GeneXusXmlSignature.csproj | 1 + .../Utils/AsymmetricSigningAlgorithm.cs | 8 + .../Utils/CanonicalizerWrapper.cs | 11 ++ .../GeneXusXmlSignature/Utils/KeyInfoType.cs | 7 + .../Utils/MessageDigestAlgorithmWrapper.cs | 9 + .../Utils/SignatureElementType.cs | 4 + .../Utils/TransformsWrapper.cs | 9 + .../Utils/XmlSignatureWrapper.cs | 9 + .../SecurityAPICommons/Commons/PublicKey.cs | 36 +++- .../Config/AvailableEncoding.cs | 11 +- .../SecurityAPICommons/Config/EncodingUtil.cs | 17 +- .../Encoders/Base64Encoder.cs | 12 ++ .../Encoders/Base64UrlEncoder.cs | 18 ++ .../Encoders/HexaEncoder.cs | 7 + .../Keys/CertificateX509.cs | 36 +++- .../Keys/PrivateKeyManager.cs | 62 +++++-- .../Keys/SymmetricKeyType.cs | 22 ++- .../SecurityAPICommons.csproj | 4 + .../SecurityAPICommons/Utils/SecurityUtils.cs | 52 +++--- 65 files changed, 1008 insertions(+), 354 deletions(-) diff --git a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetcore/GeneXusCryptographyNetCore/GeneXusCryptographyNetCore.csproj b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetcore/GeneXusCryptographyNetCore/GeneXusCryptographyNetCore.csproj index 174ed6a9a..e2137681c 100644 --- a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetcore/GeneXusCryptographyNetCore/GeneXusCryptographyNetCore.csproj +++ b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetcore/GeneXusCryptographyNetCore/GeneXusCryptographyNetCore.csproj @@ -50,6 +50,7 @@ + diff --git a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetcore/GeneXusFtpsNetCore/GeneXusFtpsNetCore.csproj b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetcore/GeneXusFtpsNetCore/GeneXusFtpsNetCore.csproj index 7aebe6d39..2559693cf 100644 --- a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetcore/GeneXusFtpsNetCore/GeneXusFtpsNetCore.csproj +++ b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetcore/GeneXusFtpsNetCore/GeneXusFtpsNetCore.csproj @@ -26,6 +26,7 @@ + diff --git a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetcore/GeneXusJWTNetCore/GeneXusJWTNetCore.csproj b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetcore/GeneXusJWTNetCore/GeneXusJWTNetCore.csproj index 96047c388..1cbbcddc7 100644 --- a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetcore/GeneXusJWTNetCore/GeneXusJWTNetCore.csproj +++ b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetcore/GeneXusJWTNetCore/GeneXusJWTNetCore.csproj @@ -42,6 +42,7 @@ + diff --git a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetcore/GeneXusSftpNetCore/GeneXusSftpNetCore.csproj b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetcore/GeneXusSftpNetCore/GeneXusSftpNetCore.csproj index a3a002ff1..62babd2f8 100644 --- a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetcore/GeneXusSftpNetCore/GeneXusSftpNetCore.csproj +++ b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetcore/GeneXusSftpNetCore/GeneXusSftpNetCore.csproj @@ -25,6 +25,7 @@ + diff --git a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetcore/GeneXusXmlSignatureNetCore/GeneXusXmlSignatureNetCore.csproj b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetcore/GeneXusXmlSignatureNetCore/GeneXusXmlSignatureNetCore.csproj index 666954743..aebbe002c 100644 --- a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetcore/GeneXusXmlSignatureNetCore/GeneXusXmlSignatureNetCore.csproj +++ b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetcore/GeneXusXmlSignatureNetCore/GeneXusXmlSignatureNetCore.csproj @@ -31,6 +31,7 @@ + diff --git a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetcore/SecurityAPICommonsNetCore/SecurityAPICommonsNetCore.csproj b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetcore/SecurityAPICommonsNetCore/SecurityAPICommonsNetCore.csproj index 7bdacca1e..4e20b4259 100644 --- a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetcore/SecurityAPICommonsNetCore/SecurityAPICommonsNetCore.csproj +++ b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetcore/SecurityAPICommonsNetCore/SecurityAPICommonsNetCore.csproj @@ -47,4 +47,8 @@ + + + + diff --git a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusCryptography/Asymmetric/AsymmetricCipher.cs b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusCryptography/Asymmetric/AsymmetricCipher.cs index 7940ad117..049efdc2b 100644 --- a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusCryptography/Asymmetric/AsymmetricCipher.cs +++ b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusCryptography/Asymmetric/AsymmetricCipher.cs @@ -12,6 +12,7 @@ using Org.BouncyCastle.Utilities.Encoders; using System.Security; using SecurityAPICommons.Utils; +using log4net; namespace GeneXusCryptography.Asymmetric { @@ -21,7 +22,7 @@ namespace GeneXusCryptography.Asymmetric [SecuritySafeCritical] public class AsymmetricCipher : SecurityAPIObject, IAsymmetricCipherObject { - + private static readonly ILog logger = LogManager.GetLogger(typeof(AsymmetricCipher)); /// /// AsymmetricCipher class constructor /// @@ -35,12 +36,13 @@ public AsymmetricCipher() : base() [SecuritySafeCritical] public string DoEncrypt_WithPrivateKey(string hashAlgorithm, string asymmetricEncryptionPadding, PrivateKeyManager key, string plainText) { + logger.Debug("DoEncrypt_WithPrivateKey"); this.error.cleanError(); /******* INPUT VERIFICATION - BEGIN *******/ - SecurityUtils.validateObjectInput("hashAlgorithm", hashAlgorithm, this.error); - SecurityUtils.validateStringInput("asymmetricEncryptionPadding", asymmetricEncryptionPadding, this.error); - SecurityUtils.validateStringInput("plainText", plainText, this.error); - SecurityUtils.validateObjectInput("key", key, this.error); + SecurityUtils.validateObjectInput(this.GetType().Name, "DoEncrypt_WithPrivateKey", "hashAlgorithm", hashAlgorithm, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "DoEncrypt_WithPrivateKey", "asymmetricEncryptionPadding", asymmetricEncryptionPadding, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "DoEncrypt_WithPrivateKey", "plainText", plainText, this.error); + SecurityUtils.validateObjectInput(this.GetType().Name, "DoEncrypt_WithPrivateKey", "key", key, this.error); if (this.HasError()) { return ""; @@ -55,13 +57,13 @@ public string DoEncrypt_WithPrivateKey(string hashAlgorithm, string asymmetricEn public string DoEncrypt_WithPublicKey(string hashAlgorithm, string asymmetricEncryptionPadding, PublicKey key, string plainText) #pragma warning restore CA1707 // Identifiers should not contain underscores { - + logger.Debug("DoEncrypt_WithPublicKey"); this.error.cleanError(); /******* INPUT VERIFICATION - BEGIN *******/ - SecurityUtils.validateObjectInput("hashAlgorithm", hashAlgorithm, this.error); - SecurityUtils.validateStringInput("asymmetricEncryptionPadding", asymmetricEncryptionPadding, this.error); - SecurityUtils.validateStringInput("plainText", plainText, this.error); - SecurityUtils.validateObjectInput("key", key, this.error); + SecurityUtils.validateObjectInput(this.GetType().Name, "DoEncrypt_WithPublicKey", "hashAlgorithm", hashAlgorithm, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "DoEncrypt_WithPublicKey", "asymmetricEncryptionPadding", asymmetricEncryptionPadding, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "DoEncrypt_WithPublicKey", "plainText", plainText, this.error); + SecurityUtils.validateObjectInput(this.GetType().Name, "DoEncrypt_WithPublicKey", "key", key, this.error); if (this.HasError()) { return ""; @@ -75,13 +77,13 @@ public string DoEncrypt_WithPublicKey(string hashAlgorithm, string asymmetricEnc [SecuritySafeCritical] public string DoEncrypt_WithCertificate(string hashAlgorithm, string asymmetricEncryptionPadding, CertificateX509 certificate, string plainText) { - + logger.Debug("DoEncrypt_WithCertificate"); this.error.cleanError(); /******* INPUT VERIFICATION - BEGIN *******/ - SecurityUtils.validateObjectInput("hashAlgorithm", hashAlgorithm, this.error); - SecurityUtils.validateStringInput("asymmetricEncryptionPadding", asymmetricEncryptionPadding, this.error); - SecurityUtils.validateStringInput("plainText", plainText, this.error); - SecurityUtils.validateObjectInput("certificate", certificate, this.error); + SecurityUtils.validateObjectInput(this.GetType().Name, "DoEncrypt_WithCertificate", "hashAlgorithm", hashAlgorithm, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "DoEncrypt_WithCertificate", "asymmetricEncryptionPadding", asymmetricEncryptionPadding, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "DoEncrypt_WithCertificate", "plainText", plainText, this.error); + SecurityUtils.validateObjectInput(this.GetType().Name, "DoEncrypt_WithCertificate", "certificate", certificate, this.error); if (this.HasError()) { return ""; @@ -95,12 +97,13 @@ public string DoEncrypt_WithCertificate(string hashAlgorithm, string asymmetricE [SecuritySafeCritical] public string DoDecrypt_WithPrivateKey(string hashAlgorithm, string asymmetricEncryptionPadding, PrivateKeyManager key, string encryptedInput) { + logger.Debug("DoDecrypt_WithPrivateKey"); this.error.cleanError(); /******* INPUT VERIFICATION - BEGIN *******/ - SecurityUtils.validateObjectInput("hashAlgorithm", hashAlgorithm, this.error); - SecurityUtils.validateStringInput("asymmetricEncryptionPadding", asymmetricEncryptionPadding, this.error); - SecurityUtils.validateStringInput("encryptedInput", encryptedInput, this.error); - SecurityUtils.validateObjectInput("key", key, this.error); + SecurityUtils.validateObjectInput(this.GetType().Name, "DoDecrypt_WithPrivateKey", "hashAlgorithm", hashAlgorithm, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "DoDecrypt_WithPrivateKey", "asymmetricEncryptionPadding", asymmetricEncryptionPadding, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "DoDecrypt_WithPrivateKey", "encryptedInput", encryptedInput, this.error); + SecurityUtils.validateObjectInput(this.GetType().Name, "DoDecrypt_WithPrivateKey", "key", key, this.error); if (this.HasError()) { return ""; @@ -114,12 +117,13 @@ public string DoDecrypt_WithPrivateKey(string hashAlgorithm, string asymmetricEn [SecuritySafeCritical] public string DoDecrypt_WithCertificate(string hashAlgorithm, string asymmetricEncryptionPadding, CertificateX509 certificate, string encryptedInput) { + logger.Debug("DoDecrypt_WithCertificate"); this.error.cleanError(); /******* INPUT VERIFICATION - BEGIN *******/ - SecurityUtils.validateObjectInput("hashAlgorithm", hashAlgorithm, this.error); - SecurityUtils.validateStringInput("asymmetricEncryptionPadding", asymmetricEncryptionPadding, this.error); - SecurityUtils.validateStringInput("encryptedInput", encryptedInput, this.error); - SecurityUtils.validateObjectInput("certificate", certificate, this.error); + SecurityUtils.validateObjectInput(this.GetType().Name, "DoDecrypt_WithCertificate", "hashAlgorithm", hashAlgorithm, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "DoDecrypt_WithCertificate", "asymmetricEncryptionPadding", asymmetricEncryptionPadding, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "DoDecrypt_WithCertificate", "encryptedInput", encryptedInput, this.error); + SecurityUtils.validateObjectInput(this.GetType().Name, "DoDecrypt_WithCertificate", "certificate", certificate, this.error); if (this.HasError()) { return ""; @@ -135,13 +139,13 @@ public string DoDecrypt_WithCertificate(string hashAlgorithm, string asymmetricE public string DoDecrypt_WithPublicKey(string hashAlgorithm, string asymmetricEncryptionPadding, PublicKey key, string encryptedInput) #pragma warning restore CA1707 // Identifiers should not contain underscores { - + logger.Debug("DoDecrypt_WithPublicKey"); this.error.cleanError(); /******* INPUT VERIFICATION - BEGIN *******/ - SecurityUtils.validateObjectInput("hashAlgorithm", hashAlgorithm, this.error); - SecurityUtils.validateStringInput("asymmetricEncryptionPadding", asymmetricEncryptionPadding, this.error); - SecurityUtils.validateStringInput("encryptedInput", encryptedInput, this.error); - SecurityUtils.validateObjectInput("key", key, this.error); + SecurityUtils.validateObjectInput(this.GetType().Name, "DoDecrypt_WithPublicKey", "hashAlgorithm", hashAlgorithm, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "DoDecrypt_WithPublicKey", "asymmetricEncryptionPadding", asymmetricEncryptionPadding, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "DoDecrypt_WithPublicKey", "encryptedInput", encryptedInput, this.error); + SecurityUtils.validateObjectInput(this.GetType().Name, "DoDecrypt_WithPublicKey", "key", key, this.error); if (this.HasError()) { return ""; @@ -170,6 +174,7 @@ public string DoDecrypt_WithPublicKey(string hashAlgorithm, string asymmetricEnc /// string Base64 encrypted plainText text private string DoEncryptInternal(string hashAlgorithm, string asymmetricEncryptionPadding, Key key, bool isPrivate, string plainText, bool isPublicKey) { + logger.Debug("DoEncryptInternal"); this.error.cleanError(); HashAlgorithm hash = HashAlgorithmUtils.getHashAlgorithm(hashAlgorithm, this.error); @@ -226,9 +231,10 @@ private string DoEncryptInternal(string hashAlgorithm, string asymmetricEncrypti { return doEncrypt(algorithm, hash, padding, asymKey, plainText); } - catch (InvalidCipherTextException) + catch (InvalidCipherTextException e) { - this.error.setError("AE036", "Algoritmo inválido" + algorithm); + this.error.setError("AE036", string.Format("Algoritmo inválido {0}", algorithm)); + logger.Error("DoEncryptInternal", e); return ""; } @@ -249,6 +255,7 @@ private string DoEncryptInternal(string hashAlgorithm, string asymmetricEncrypti /// string decypted encryptedInput text private string DoDecryptInternal(string hashAlgorithm, string asymmetricEncryptionPadding, Key key, bool isPrivate, string encryptedInput, bool isPublicKey) { + logger.Debug("DoDecryptInternal"); this.error.cleanError(); HashAlgorithm hash = HashAlgorithmUtils.getHashAlgorithm(hashAlgorithm, this.error); @@ -305,8 +312,9 @@ private string DoDecryptInternal(string hashAlgorithm, string asymmetricEncrypti } catch (InvalidCipherTextException e) { - this.error.setError("AE039", "Algoritmo inválido" + algorithm); - throw new InvalidCipherTextException("Algoritmo inválido" + algorithm, e); + this.error.setError("AE039", string.Format("Algoritmo inválido {0} ", algorithm)); + logger.Error("DoDecryptInternal", e); + throw new InvalidCipherTextException(string.Format("Algoritmo inválido {0} ", algorithm), e); } } @@ -321,7 +329,7 @@ private string DoDecryptInternal(string hashAlgorithm, string asymmetricEncrypti /// string decypted encryptedInput text private string doDecrypt(AsymmetricEncryptionAlgorithm asymmetricEncryptionAlgorithm, HashAlgorithm hashAlgorithm, AsymmetricEncryptionPadding asymmetricEncryptionPadding, AsymmetricKeyParameter asymmetricKeyParameter, string encryptedInput) { - + logger.Debug("doDecrypt"); IAsymmetricBlockCipher asymEngine = getEngine(asymmetricEncryptionAlgorithm); IDigest hash = getDigest(hashAlgorithm); IAsymmetricBlockCipher cipher = getPadding(asymEngine, hash, asymmetricEncryptionPadding); @@ -337,6 +345,7 @@ private string doDecrypt(AsymmetricEncryptionAlgorithm asymmetricEncryptionAlgor if (outputBytes == null || outputBytes.Length == 0) { this.error.setError("AE040", "Asymmetric decryption error"); + logger.Error("Asymmetric decryption error"); return ""; } EncodingUtil eu = new EncodingUtil(); @@ -356,6 +365,7 @@ private string doDecrypt(AsymmetricEncryptionAlgorithm asymmetricEncryptionAlgor /// Base64 encrypted encryptedInput text private string doEncrypt(AsymmetricEncryptionAlgorithm asymmetricEncryptionAlgorithm, HashAlgorithm hashAlgorithm, AsymmetricEncryptionPadding asymmetricEncryptionPadding, AsymmetricKeyParameter asymmetricKeyParameter, string plainText) { + logger.Debug("doEncrypt"); IAsymmetricBlockCipher asymEngine = getEngine(asymmetricEncryptionAlgorithm); IDigest hash = getDigest(hashAlgorithm); IAsymmetricBlockCipher cipher = getPadding(asymEngine, hash, asymmetricEncryptionPadding); @@ -377,6 +387,7 @@ private string doEncrypt(AsymmetricEncryptionAlgorithm asymmetricEncryptionAlgor if (outputBytes == null || outputBytes.Length == 0) { this.error.setError("AE041", "Asymmetric encryption error"); + logger.Error("Asymmetric encryption error"); return ""; } this.error.cleanError(); @@ -390,13 +401,14 @@ private string doEncrypt(AsymmetricEncryptionAlgorithm asymmetricEncryptionAlgor /// IAsymmetricBlockCipher Engine for the specified algorithm private IAsymmetricBlockCipher getEngine(AsymmetricEncryptionAlgorithm asymmetricEncryptionAlgorithm) { - + logger.Debug("getEngine"); switch (asymmetricEncryptionAlgorithm) { case AsymmetricEncryptionAlgorithm.RSA: return new RsaEngine(); default: this.error.setError("AE042", "Unrecognized algorithm"); + logger.Error("Unrecognized algorithm"); return null; } @@ -408,11 +420,13 @@ private IAsymmetricBlockCipher getEngine(AsymmetricEncryptionAlgorithm asymmetri /// IDigest Engine for the specified algorithm private IDigest getDigest(HashAlgorithm hashAlgorithm) { + logger.Debug("getDigest"); Hashing hash = new Hashing(); IDigest digest = hash.createHash(hashAlgorithm); if (digest == null) { this.error.setError("AE043", "Unrecognized HashAlgorithm"); + logger.Error("Unrecognized HashAlgorithm"); return null; } return digest; @@ -426,6 +440,7 @@ private IDigest getDigest(HashAlgorithm hashAlgorithm) /// AsymmetricBlockCipher Engine specific for the algoritm, hash and padding private IAsymmetricBlockCipher getPadding(IAsymmetricBlockCipher asymBlockCipher, IDigest hash, AsymmetricEncryptionPadding asymmetricEncryptionPadding) { + logger.Debug("getPadding"); switch (asymmetricEncryptionPadding) { case AsymmetricEncryptionPadding.NOPADDING: @@ -445,6 +460,7 @@ private IAsymmetricBlockCipher getPadding(IAsymmetricBlockCipher asymBlockCipher return new ISO9796d1Encoding(asymBlockCipher); default: error.setError("AE044", "Unrecognized AsymmetricEncryptionPadding"); + logger.Error("Unrecognized AsymmetricEncryptionPadding"); return null; } } diff --git a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusCryptography/Asymmetric/AsymmetricSigner.cs b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusCryptography/Asymmetric/AsymmetricSigner.cs index 0e59fbb2d..06f48dfcf 100644 --- a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusCryptography/Asymmetric/AsymmetricSigner.cs +++ b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusCryptography/Asymmetric/AsymmetricSigner.cs @@ -12,6 +12,7 @@ using System.Security; using SecurityAPICommons.Utils; using System.IO; +using log4net; namespace GeneXusCryptography.Asymmetric { @@ -21,7 +22,7 @@ namespace GeneXusCryptography.Asymmetric [SecuritySafeCritical] public class AsymmetricSigner : SecurityAPIObject, IAsymmetricSignerObject { - + private static readonly ILog logger = LogManager.GetLogger(typeof(AsymmetricSigner)); /// /// AsymmetricSigner class constructor @@ -34,13 +35,14 @@ public AsymmetricSigner() : base() /********EXTERNAL OBJECT PUBLIC METHODS - BEGIN ********/ [SecuritySafeCritical] - public String DoSign(PrivateKeyManager key, string hashAlgorithm, string plainText) + public string DoSign(PrivateKeyManager key, string hashAlgorithm, string plainText) { + logger.Debug("DoSign"); this.error.cleanError(); /*******INPUT VERIFICATION - BEGIN*******/ - SecurityUtils.validateObjectInput("key", key, this.error); - SecurityUtils.validateStringInput("hashAlgorithm", hashAlgorithm, this.error); - SecurityUtils.validateStringInput("plainText", plainText, this.error); + SecurityUtils.validateObjectInput(this.GetType().Name, "DoSign", "key", key, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "DoSign", "hashAlgorithm", hashAlgorithm, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "DoSign", "plainText", plainText, this.error); if (this.HasError()) { return ""; }; /*******INPUT VERIFICATION - END*******/ @@ -61,15 +63,16 @@ public String DoSign(PrivateKeyManager key, string hashAlgorithm, string plainTe } [SecuritySafeCritical] - public String DoSignFile(PrivateKeyManager key, string hashAlgorithm, string path) + public string DoSignFile(PrivateKeyManager key, string hashAlgorithm, string path) { + logger.Debug("DoSignFile"); this.error.cleanError(); /*******INPUT VERIFICATION - BEGIN*******/ - SecurityUtils.validateObjectInput("key", key, this.error); - SecurityUtils.validateStringInput("hashAlgorithm", hashAlgorithm, this.error); - SecurityUtils.validateStringInput("path", path, this.error); + SecurityUtils.validateObjectInput(this.GetType().Name, "DoSignFile", "key", key, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "DoSignFile", "hashAlgorithm", hashAlgorithm, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "DoSignFile", "path", path, this.error); if (this.HasError()) { return ""; } /*******INPUT VERIFICATION - END*******/ @@ -89,12 +92,13 @@ public String DoSignFile(PrivateKeyManager key, string hashAlgorithm, string pat [SecuritySafeCritical] public bool DoVerify(CertificateX509 cert, string plainText, string signature) { + logger.Debug("DoVerify"); this.error.cleanError(); /*******INPUT VERIFICATION - BEGIN*******/ - SecurityUtils.validateObjectInput("cert", cert, this.error); - SecurityUtils.validateStringInput("plainText", plainText, this.error); - SecurityUtils.validateStringInput("signature", signature, this.error); + SecurityUtils.validateObjectInput(this.GetType().Name, "DoVerify", "cert", cert, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "DoVerify", "plainText", plainText, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "DoVerify", "signature", signature, this.error); if (this.HasError()) { return false; } /*******INPUT VERIFICATION - END*******/ @@ -117,13 +121,14 @@ public bool DoVerify(CertificateX509 cert, string plainText, string signature) [SecuritySafeCritical] public bool DoVerifyWithPublicKey(PublicKey key, string plainText, string signature, string hash) { + logger.Debug("DoVerifyWithPublicKey"); this.error.cleanError(); /******* INPUT VERIFICATION - BEGIN *******/ - SecurityUtils.validateObjectInput("key", key, this.error); - SecurityUtils.validateStringInput("plainText", plainText, this.error); - SecurityUtils.validateStringInput("signature", signature, this.error); - SecurityUtils.validateStringInput("hashAlgorithm", hash, this.error); + SecurityUtils.validateObjectInput(this.GetType().Name, "DoVerifyWithPublicKey", "key", key, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "DoVerifyWithPublicKey", "plainText", plainText, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "DoVerifyWithPublicKey", "signature", signature, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "DoVerifyWithPublicKey", "hashAlgorithm", hash, this.error); if (this.HasError()) { return false; @@ -148,12 +153,13 @@ public bool DoVerifyWithPublicKey(PublicKey key, string plainText, string signat [SecuritySafeCritical] public bool DoVerifyFile(CertificateX509 cert, string path, string signature) { + logger.Debug("DoVerifyFile"); this.error.cleanError(); /*******INPUT VERIFICATION - BEGIN*******/ - SecurityUtils.validateObjectInput("cert", cert, this.error); - SecurityUtils.validateStringInput("path", path, this.error); - SecurityUtils.validateStringInput("signature", signature, this.error); + SecurityUtils.validateObjectInput(this.GetType().Name, "DoVerifyFile", "cert", cert, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "DoVerifyFile", "path", path, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "DoVerifyFile", "signature", signature, this.error); if (this.HasError()) { return false; } /*******INPUT VERIFICATION - END*******/ @@ -172,13 +178,14 @@ public bool DoVerifyFile(CertificateX509 cert, string path, string signature) [SecuritySafeCritical] public bool DoVerifyFileWithPublicKey(PublicKey key, string path, string signature, string hash) { + logger.Debug("DoVerifyFileWithPublicKey"); this.error.cleanError(); /******* INPUT VERIFICATION - BEGIN *******/ - SecurityUtils.validateObjectInput("key", key, this.error); - SecurityUtils.validateStringInput("path", path, this.error); - SecurityUtils.validateStringInput("signature", signature, this.error); - SecurityUtils.validateStringInput("hashAlgorithm", hash, this.error); + SecurityUtils.validateObjectInput(this.GetType().Name, "DoVerifyFileWithPublicKey", "key", key, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "DoVerifyFileWithPublicKey", "path", path, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "DoVerifyFileWithPublicKey", "signature", signature, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "DoVerifyFileWithPublicKey", "hashAlgorithm", hash, this.error); if (this.HasError()) { return false; @@ -199,8 +206,9 @@ public bool DoVerifyFileWithPublicKey(PublicKey key, string path, string signatu /********EXTERNAL OBJECT PUBLIC METHODS - END ********/ - private String Sign(PrivateKey key, string hashAlgorithm, Stream input) + private string Sign(PrivateKey key, string hashAlgorithm, Stream input) { + logger.Debug("Sign"); PrivateKeyManager keyMan = (PrivateKeyManager)key; if (keyMan.HasError()) { @@ -223,6 +231,7 @@ private String Sign(PrivateKey key, string hashAlgorithm, Stream input) catch (Exception e) { error.setError("AE01", e.Message); + logger.Error("Sign", e); return ""; } String result = ""; @@ -233,6 +242,8 @@ private String Sign(PrivateKey key, string hashAlgorithm, Stream input) catch (Exception e) { error.setError("AE018", e.Message); + logger. + Error("Sign", e); return ""; } return result; @@ -240,6 +251,7 @@ private String Sign(PrivateKey key, string hashAlgorithm, Stream input) private bool Verify(Key key, Stream input, string signature, string hash) { + logger.Debug("Verify"); PublicKey cert = null; bool isKey = false; if (hash == null) @@ -288,12 +300,14 @@ private bool Verify(Key key, Stream input, string signature, string hash) catch (Exception e) { error.setError("AE019", e.Message); + logger.Error("Verify", e); return false; } if (signatureBytes == null || signatureBytes.Length == 0) { this.error.setError("AE020", "Error reading signature"); + logger.Error("Error reading signature"); return false; } bool result = false; @@ -304,6 +318,7 @@ private bool Verify(Key key, Stream input, string signature, string hash) catch (Exception e) { error.setError("AE021", e.Message); + logger.Error("Verify", e); return false; } return result; @@ -313,6 +328,7 @@ private bool Verify(Key key, Stream input, string signature, string hash) private void SetUpSigner(ISigner signer, Stream input, AsymmetricKeyParameter asymmetricKeyParameter, bool toSign) { + logger.Debug("SetUpSigner"); try { signer.Init(toSign, asymmetricKeyParameter); @@ -320,6 +336,7 @@ private void SetUpSigner(ISigner signer, Stream input, AsymmetricKeyParameter as catch (Exception e) { error.setError("AE022", e.Message); + logger.Error("SetUpSigner", e); return; } byte[] buffer = new byte[8192]; @@ -334,6 +351,7 @@ private void SetUpSigner(ISigner signer, Stream input, AsymmetricKeyParameter as catch (Exception e) { error.setError("AE023", e.Message); + logger.Error("SetUpSigner", e); return; } } diff --git a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusCryptography/Asymmetric/StandardSigner.cs b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusCryptography/Asymmetric/StandardSigner.cs index d9049dac3..1622a0732 100644 --- a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusCryptography/Asymmetric/StandardSigner.cs +++ b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusCryptography/Asymmetric/StandardSigner.cs @@ -11,6 +11,7 @@ using SecurityAPICommons.Keys; using SecurityAPICommons.Utils; using Org.BouncyCastle.Utilities.Collections; +using log4net; namespace GeneXusCryptography.Asymmetric @@ -18,6 +19,7 @@ namespace GeneXusCryptography.Asymmetric [SecuritySafeCritical] public class StandardSigner : SecurityAPIObject, IStandardSignerObject { + private static readonly ILog logger = LogManager.GetLogger(typeof(StandardSigner)); public StandardSigner() : base() { @@ -29,13 +31,14 @@ public StandardSigner() : base() [SecuritySafeCritical] public string Sign(string plainText, SignatureStandardOptions options) { + logger.Debug("Sign"); this.error.cleanError(); /******* INPUT VERIFICATION - BEGIN *******/ - SecurityUtils.validateObjectInput("signatureStandardOptions", options, this.error); - SecurityUtils.validateObjectInput("private key", options.GetPrivateKey(), this.error); - SecurityUtils.validateObjectInput("certificate", options.GetCertificate(), this.error); - SecurityUtils.validateStringInput("plainText", plainText, this.error); + SecurityUtils.validateObjectInput(this.GetType().Name, "Sign", "signatureStandardOptions", options, this.error); + SecurityUtils.validateObjectInput(this.GetType().Name, "Sign", "private key", options.GetPrivateKey(), this.error); + SecurityUtils.validateObjectInput(this.GetType().Name, "Sign", "certificate", options.GetCertificate(), this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "Sign", "plainText", plainText, this.error); if (this.HasError()) { return ""; @@ -59,6 +62,7 @@ public string Sign(string plainText, SignatureStandardOptions options) catch (Exception e) { error.setError("SS002", e.Message); + logger.Error("Sign", e); result = ""; } @@ -69,12 +73,13 @@ public string Sign(string plainText, SignatureStandardOptions options) public bool Verify(string signed, string plainText, SignatureStandardOptions options) { + logger.Debug("Verify"); this.error.cleanError(); /******* INPUT VERIFICATION - BEGIN *******/ - SecurityUtils.validateObjectInput("signatureStandardOptions", options, this.error); + SecurityUtils.validateObjectInput(this.GetType().Name, "Verify", "signatureStandardOptions", options, this.error); //SecurityUtils.validateStringInput("plainText", plainText, this.error); - SecurityUtils.validateStringInput("signed", signed, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "Verify", "signed", signed, this.error); if (this.HasError()) { return false; @@ -99,6 +104,7 @@ public bool Verify(string signed, string plainText, SignatureStandardOptions opt catch (Exception e) { error.setError("SS002", e.Message); + logger.Error("Verify", e); result = false; } @@ -109,6 +115,7 @@ public bool Verify(string signed, string plainText, SignatureStandardOptions opt private string Sign_internal(byte[] input, PrivateKeyManager key, CertificateX509 cert, SignatureStandard signatureStandard, bool encapsulated) { + logger.Debug("Sign_internal"); PrivateKeyManager keyMan = (PrivateKeyManager)key; if (keyMan.HasError()) @@ -152,6 +159,7 @@ private string Sign_internal(byte[] input, PrivateKeyManager key, CertificateX50 private bool Verify_internal(byte[] cmsSignedData, byte[] data, bool encapsulated) { + logger.Debug("Verify_internal"); CmsSignedData cms = encapsulated ? new CmsSignedData(cmsSignedData) : new CmsSignedData(new CmsProcessableByteArray(data), cmsSignedData); SignerInformationStore signers = cms.GetSignerInfos(); @@ -182,6 +190,7 @@ private bool Verify_internal(byte[] cmsSignedData, byte[] data, bool encapsulate private string DigestCalculator(CertificateX509 cert) { + logger.Debug("DigestCalculator"); string value = cert.getPublicKeyHash(); switch (value) { @@ -193,6 +202,7 @@ private string DigestCalculator(CertificateX509 cert) return CmsSignedGenerator.DigestSha512; default: this.error.setError("SS003", "Unrecognizable certificate hash algorithm"); + logger.Error("Unrecognizable certificate hash algorithm"); return ""; } diff --git a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusCryptography/AsymmetricUtils/AsymmetricEncryptionAlgorithm.cs b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusCryptography/AsymmetricUtils/AsymmetricEncryptionAlgorithm.cs index 3ea56c26e..040d61632 100644 --- a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusCryptography/AsymmetricUtils/AsymmetricEncryptionAlgorithm.cs +++ b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusCryptography/AsymmetricUtils/AsymmetricEncryptionAlgorithm.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.Linq; using System.Security; +using log4net; namespace GeneXusCryptography.AsymmetricUtils @@ -25,19 +26,21 @@ public enum AsymmetricEncryptionAlgorithm [SecuritySafeCritical] public static class AsymmetricEncryptionAlgorithmUtils { - - /// - /// Mapping between string name and AsymmetricEncryptionAlgorithm enum representation - /// - /// string asymmetricEncryptionAlgorithm - /// Error type for error management - /// AsymmetricEncryptionAlgorithm enum representation - public static AsymmetricEncryptionAlgorithm getAsymmetricEncryptionAlgorithm(string asymmetricEncryptionAlgorithm, Error error) + private static readonly ILog logger = LogManager.GetLogger(typeof(AsymmetricEncryptionAlgorithmUtils)); + /// + /// Mapping between string name and AsymmetricEncryptionAlgorithm enum representation + /// + /// string asymmetricEncryptionAlgorithm + /// Error type for error management + /// AsymmetricEncryptionAlgorithm enum representation + public static AsymmetricEncryptionAlgorithm getAsymmetricEncryptionAlgorithm(string asymmetricEncryptionAlgorithm, Error error) { + logger.Debug("getAsymmetricEncryptionAlgorithm"); if (error == null) return AsymmetricEncryptionAlgorithm.NONE; if(asymmetricEncryptionAlgorithm == null) { error.setError("AE001", "Unrecognized AsymmetricEncryptionAlgorithm"); + logger.Error("Unrecognized AsymmetricEncryptionAlgorithm"); return AsymmetricEncryptionAlgorithm.NONE; } switch (asymmetricEncryptionAlgorithm.ToUpper(System.Globalization.CultureInfo.InvariantCulture).Trim()) @@ -46,6 +49,7 @@ public static AsymmetricEncryptionAlgorithm getAsymmetricEncryptionAlgorithm(str return AsymmetricEncryptionAlgorithm.RSA; default: error.setError("AE001", "Unrecognized AsymmetricEncryptionAlgorithm"); + logger.Error("Unrecognized AsymmetricEncryptionAlgorithm"); return AsymmetricEncryptionAlgorithm.NONE; } } @@ -57,6 +61,7 @@ public static AsymmetricEncryptionAlgorithm getAsymmetricEncryptionAlgorithm(str /// string asymmetricEncryptionAlgorithm name public static string valueOf(AsymmetricEncryptionAlgorithm asymmetricEncryptionAlgorithm, Error error) { + logger.Debug("valueOf"); if (error == null) return ""; switch (asymmetricEncryptionAlgorithm) { @@ -64,6 +69,7 @@ public static string valueOf(AsymmetricEncryptionAlgorithm asymmetricEncryptionA return "RSA"; default: error.setError("AE002", "Unrecognized AsymmetricEncryptionAlgorithm"); + logger.Error("Unrecognized AsymmetricEncryptionAlgorithm"); return ""; } diff --git a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusCryptography/AsymmetricUtils/AsymmetricEncryptionPadding.cs b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusCryptography/AsymmetricUtils/AsymmetricEncryptionPadding.cs index d4853240d..85cffc9f3 100644 --- a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusCryptography/AsymmetricUtils/AsymmetricEncryptionPadding.cs +++ b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusCryptography/AsymmetricUtils/AsymmetricEncryptionPadding.cs @@ -1,3 +1,4 @@ +using log4net; using SecurityAPICommons.Commons; using System; using System.Collections.Generic; @@ -24,18 +25,21 @@ public enum AsymmetricEncryptionPadding [SecuritySafeCritical] public static class AsymmetricEncryptionPaddingUtils { - /// - /// Mapping between string name and AsymmetricEncryptionPadding enum representation - /// - /// string asymmetricEncryptionPadding - /// Error type for error management - /// AsymmetricEncryptionPadding enum representation - public static AsymmetricEncryptionPadding getAsymmetricEncryptionPadding(string asymmetricEncryptionPadding, Error error) + private static readonly ILog logger = LogManager.GetLogger(typeof(AsymmetricEncryptionPaddingUtils)); + /// + /// Mapping between string name and AsymmetricEncryptionPadding enum representation + /// + /// string asymmetricEncryptionPadding + /// Error type for error management + /// AsymmetricEncryptionPadding enum representation + public static AsymmetricEncryptionPadding getAsymmetricEncryptionPadding(string asymmetricEncryptionPadding, Error error) { + logger.Debug("getAsymmetricEncryptionPadding"); if (error == null) return AsymmetricEncryptionPadding.NOPADDING; if( asymmetricEncryptionPadding == null) { error.setError("AE003", "Unrecognized AsymmetricEncryptionPadding"); + logger.Error("Unrecognized AsymmetricEncryptionPadding"); return AsymmetricEncryptionPadding.NOPADDING; } @@ -51,6 +55,7 @@ public static AsymmetricEncryptionPadding getAsymmetricEncryptionPadding(string return AsymmetricEncryptionPadding.ISO97961PADDING; default: error.setError("AE003", "Unrecognized AsymmetricEncryptionPadding"); + logger.Error("Unrecognized AsymmetricEncryptionPadding"); return AsymmetricEncryptionPadding.NOPADDING; } } @@ -62,6 +67,7 @@ public static AsymmetricEncryptionPadding getAsymmetricEncryptionPadding(string /// string name of asymmetricEncryptionPadding public static string valueOf(AsymmetricEncryptionPadding asymmetricEncryptionPadding, Error error) { + logger.Debug("valueOf"); if (error == null) return ""; switch (asymmetricEncryptionPadding) { @@ -75,6 +81,7 @@ public static string valueOf(AsymmetricEncryptionPadding asymmetricEncryptionPad return "ISO97961PADDING"; default: error.setError("AE004", "Unrecognized AsymmetricEncryptionPadding"); + logger.Error("Unrecognized AsymmetricEncryptionPadding"); return ""; } } diff --git a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusCryptography/AsymmetricUtils/AsymmetricSigningAlgorithm.cs b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusCryptography/AsymmetricUtils/AsymmetricSigningAlgorithm.cs index 3624f125b..8b2135e88 100644 --- a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusCryptography/AsymmetricUtils/AsymmetricSigningAlgorithm.cs +++ b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusCryptography/AsymmetricUtils/AsymmetricSigningAlgorithm.cs @@ -1,4 +1,5 @@ +using log4net; using Org.BouncyCastle.Cms; using Org.BouncyCastle.Crypto; using Org.BouncyCastle.Crypto.Signers; @@ -28,19 +29,21 @@ public enum AsymmetricSigningAlgorithm [SecuritySafeCritical] public static class AsymmetricSigningAlgorithmUtils { - - /// - /// Mapping between string name and AsymmetricSigningAlgorithm enum representation - /// - /// string asymmetricSigningAlgorithm - /// Error type for error management - /// AsymmetricSigningAlgorithm enum representation - public static AsymmetricSigningAlgorithm GetAsymmetricSigningAlgorithm(string asymmetricSigningAlgorithm, Error error) + private static readonly ILog logger = LogManager.GetLogger(typeof(AsymmetricSigningAlgorithmUtils)); + /// + /// Mapping between string name and AsymmetricSigningAlgorithm enum representation + /// + /// string asymmetricSigningAlgorithm + /// Error type for error management + /// AsymmetricSigningAlgorithm enum representation + public static AsymmetricSigningAlgorithm GetAsymmetricSigningAlgorithm(string asymmetricSigningAlgorithm, Error error) { + logger.Debug("GetAsymmetricSigningAlgorithm"); if (error == null) return AsymmetricSigningAlgorithm.NONE; if (asymmetricSigningAlgorithm == null) { error.setError("AE005", "Unrecognized AsymmetricSigningAlgorithm"); + logger.Error("Unrecognized AsymmetricSigningAlgorithm"); return AsymmetricSigningAlgorithm.NONE; } @@ -52,6 +55,7 @@ public static AsymmetricSigningAlgorithm GetAsymmetricSigningAlgorithm(string as return AsymmetricSigningAlgorithm.ECDSA; default: error.setError("AE005", "Unrecognized AsymmetricSigningAlgorithm"); + logger.Error("Unrecognized AsymmetricSigningAlgorithm"); return AsymmetricSigningAlgorithm.NONE; } } @@ -63,6 +67,7 @@ public static AsymmetricSigningAlgorithm GetAsymmetricSigningAlgorithm(string as /// string value of the algorithm public static string ValueOf(AsymmetricSigningAlgorithm asymmetricSigningAlgorithm, Error error) { + logger.Debug("ValueOf"); if (error == null) return ""; switch (asymmetricSigningAlgorithm) { @@ -72,16 +77,19 @@ public static string ValueOf(AsymmetricSigningAlgorithm asymmetricSigningAlgorit return "ECDSA"; default: error.setError("AE005", "Unrecognized AsymmetricSigningAlgorithm"); + logger.Error("Unrecognized AsymmetricSigningAlgorithm"); return ""; } } public static ISigner GetSigner(AsymmetricSigningAlgorithm asymmetricSigningAlgorithm, IDigest hash, Error error) { + logger.Debug("GetSigner"); if(error == null) return null; if (hash == null) { error.setError("AE008", "Hash digest is null"); + logger.Error("Hash digest is null"); return null; } ISigner sig = null; @@ -100,6 +108,7 @@ public static ISigner GetSigner(AsymmetricSigningAlgorithm asymmetricSigningAlgo public static string GetCMSSigningAlgortithm(AsymmetricSigningAlgorithm asymmetricSigningAlgorithm, Error error) { + logger.Debug("GetCMSSigningAlgortithm"); if (error == null) return null; switch (asymmetricSigningAlgorithm) { @@ -109,6 +118,7 @@ public static string GetCMSSigningAlgortithm(AsymmetricSigningAlgorithm asymmetr return CmsSignedDataGenerator.EncryptionECDsa; default: error.setError("AE008", "Not recogrnized AsymmetricSigningAlgorithm"); + logger.Error("Unrecognized AsymmetricSigningAlgorithm"); return ""; } } diff --git a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusCryptography/AsymmetricUtils/SignatureStandardUtils.cs b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusCryptography/AsymmetricUtils/SignatureStandardUtils.cs index 4796f18ee..0c404d594 100644 --- a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusCryptography/AsymmetricUtils/SignatureStandardUtils.cs +++ b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusCryptography/AsymmetricUtils/SignatureStandardUtils.cs @@ -1,4 +1,5 @@ using System.Security; +using log4net; using SecurityAPICommons.Commons; namespace GeneXusCryptography.AsymmetricUtils @@ -12,13 +13,16 @@ public enum SignatureStandard [SecuritySafeCritical] public static class SignatureStandardUtils { + private static readonly ILog logger = LogManager.GetLogger(typeof(SignatureStandardUtils)); public static SignatureStandard getSignatureStandard(string signatureStandard, Error error) { + logger.Debug("getSignatureStandard"); if (error == null) return SignatureStandard.NONE; if (signatureStandard == null) { error.setError("SS001", "Unrecognized SignatureStandard"); + logger.Error("Unrecognized SignatureStandard"); return SignatureStandard.NONE; } switch (signatureStandard.ToUpper(System.Globalization.CultureInfo.InvariantCulture).Trim()) @@ -27,12 +31,14 @@ public static SignatureStandard getSignatureStandard(string signatureStandard, return SignatureStandard.CMS; default: error.setError("SS001", "Unrecognized SignatureStandard"); + logger.Error("Unrecognized SignatureStandard"); return SignatureStandard.NONE; } } public static string valueOf(SignatureStandard signatureStandard, Error error) { + logger.Debug("valueOf"); if (error == null) return ""; switch (signatureStandard) { @@ -40,6 +46,7 @@ public static string valueOf(SignatureStandard signatureStandard, Error error) return "CMS"; default: error.setError("SS002", "Unrecognized SignatureStandard"); + logger.Error("Unrecognized SignatureStandard"); return ""; } } diff --git a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusCryptography/Checksum/ChecksumCreator.cs b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusCryptography/Checksum/ChecksumCreator.cs index a05e23fce..fde2734db 100644 --- a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusCryptography/Checksum/ChecksumCreator.cs +++ b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusCryptography/Checksum/ChecksumCreator.cs @@ -2,6 +2,7 @@ using GeneXusCryptography.Commons; using GeneXusCryptography.Hash; using GeneXusCryptography.HashUtils; +using log4net; using Org.BouncyCastle.Utilities.Encoders; using SecurityAPICommons.Commons; using SecurityAPICommons.Utils; @@ -13,6 +14,7 @@ namespace GeneXusCryptography.Checksum [SecuritySafeCritical] public class ChecksumCreator : SecurityAPIObject, IChecksumObject { + private static readonly ILog logger = LogManager.GetLogger(typeof(ChecksumCreator)); public ChecksumCreator() : base() { @@ -22,12 +24,13 @@ public ChecksumCreator() : base() [SecuritySafeCritical] public string GenerateChecksum(string input, string inputType, string checksumAlgorithm) { + logger.Debug("GenerateChecksum"); this.error.cleanError(); /*******INPUT VERIFICATION - BEGIN*******/ - SecurityUtils.validateStringInput("input", input, this.error); - SecurityUtils.validateStringInput("inputType", inputType, this.error); - SecurityUtils.validateStringInput("checksumAlgorithm", checksumAlgorithm, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "GenerateChecksum", "input", input, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "GenerateChecksum", "inputType", inputType, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "GenerateChecksum", "checksumAlgorithm", checksumAlgorithm, this.error); if (this.HasError()) { return ""; }; /*******INPUT VERIFICATION - END*******/ @@ -49,13 +52,14 @@ public string GenerateChecksum(string input, string inputType, string checksumAl [SecuritySafeCritical] public bool VerifyChecksum(string input, string inputType, string checksumAlgorithm, string digest) { + logger.Debug("VerifyChecksum"); this.error.cleanError(); /*******INPUT VERIFICATION - BEGIN*******/ - SecurityUtils.validateStringInput("input", input, this.error); - SecurityUtils.validateStringInput("inputType", inputType, this.error); - SecurityUtils.validateStringInput("checksumAlgorithm", checksumAlgorithm, this.error); - SecurityUtils.validateStringInput("digest", digest, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "VerifyChecksum", "input", input, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "VerifyChecksum", "inputType", inputType, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "VerifyChecksum", "checksumAlgorithm", checksumAlgorithm, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "VerifyChecksum", "digest", digest, this.error); if (this.HasError()) { return false; }; /*******INPUT VERIFICATION - END*******/ @@ -73,6 +77,7 @@ public bool VerifyChecksum(string input, string inputType, string checksumAlgori private string CalculateCRC(byte[] input, ChecksumAlgorithm checksumAlgorithm) { + logger.Debug("CalculateCRC"); CRCParameters parms = ChecksumAlgorithmUtils.getParameters(checksumAlgorithm, this.error); if (this.HasError()) { @@ -98,6 +103,7 @@ private string CalculateCRC(byte[] input, ChecksumAlgorithm checksumAlgorithm) private string CalculateHash(byte[] input, ChecksumAlgorithm checksumAlgorithm) { + logger.Debug("CalculateHash"); HashAlgorithm alg = getHashAlgorithm(checksumAlgorithm); if (this.HasError()) { @@ -112,6 +118,7 @@ private string CalculateHash(byte[] input, ChecksumAlgorithm checksumAlgorithm) catch (Exception e) { error.setError("CH001", e.Message); + logger.Error("CalculateHash", e); return ""; } if (hash.HasError()) diff --git a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusCryptography/ChecksumUtils/ChecksumAlgorithm.cs b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusCryptography/ChecksumUtils/ChecksumAlgorithm.cs index 5f34760c6..479ee6950 100644 --- a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusCryptography/ChecksumUtils/ChecksumAlgorithm.cs +++ b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusCryptography/ChecksumUtils/ChecksumAlgorithm.cs @@ -1,3 +1,4 @@ +using log4net; using SecurityAPICommons.Commons; using System.Security; @@ -20,13 +21,15 @@ public enum ChecksumAlgorithm [SecuritySafeCritical] public static class ChecksumAlgorithmUtils { - + private static readonly ILog logger = LogManager.GetLogger(typeof(ChecksumAlgorithmUtils)); public static ChecksumAlgorithm getChecksumAlgorithm(string checksumAlgorithm, Error error) { + logger.Debug("getChecksumAlgorithm"); if (error == null) return ChecksumAlgorithm.NONE; if (checksumAlgorithm == null) { error.setError("CHA04", "Unrecognized checksum algorithm"); + logger.Error("Unrecognized checksum algorithm"); return ChecksumAlgorithm.NONE; } switch (checksumAlgorithm.ToUpper(System.Globalization.CultureInfo.InvariantCulture).Trim()) @@ -125,12 +128,14 @@ public static ChecksumAlgorithm getChecksumAlgorithm(string checksumAlgorithm, E return ChecksumAlgorithm.SHA512; default: error.setError("CHA01", "Unrecognized checksum algorithm"); + logger.Error("Unrecognized checksum algorithm"); return ChecksumAlgorithm.NONE; } } public static string valueOf(ChecksumAlgorithm checksumAlgorithm, Error error) { + logger.Debug("valueOf"); if (error == null) return null; switch (checksumAlgorithm) @@ -229,6 +234,7 @@ public static string valueOf(ChecksumAlgorithm checksumAlgorithm, Error error) return "SHA512"; default: error.setError("CHA02", "Unrecognized checksum algorithm"); + logger.Error("Unrecognized checksum algorithm"); return null; } } @@ -249,6 +255,7 @@ public static bool isHash(ChecksumAlgorithm checksumAlgorithm) public static CRCParameters getParameters(ChecksumAlgorithm checksumAlgorithm, Error error) { + logger.Debug("getParameters"); if (error == null) return new CRCParameters(0, 0x00, 0x00, false, false, 0x00); switch (checksumAlgorithm) { @@ -338,6 +345,7 @@ public static CRCParameters getParameters(ChecksumAlgorithm checksumAlgorithm, E return new CRCParameters(32, 0x000000AF, 0x00000000, false, false, 0x0000000); default: error.setError("CHA03", "Unrecognized checksum algorithm"); + logger.Error("Unrecognized checksum algorithm"); return new CRCParameters(0, 0x00, 0x00, false, false, 0x00); } } diff --git a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusCryptography/ChecksumUtils/ChecksumInputType.cs b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusCryptography/ChecksumUtils/ChecksumInputType.cs index 7e4563c32..d8e85e02b 100644 --- a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusCryptography/ChecksumUtils/ChecksumInputType.cs +++ b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusCryptography/ChecksumUtils/ChecksumInputType.cs @@ -5,6 +5,7 @@ using System; using System.Security; using System.Text; +using log4net; namespace GeneXusCryptography.ChecksumUtils { @@ -19,12 +20,15 @@ public enum ChecksumInputType [SecuritySafeCritical] public static class ChecksumInputTypeUtils { + private static readonly ILog logger = LogManager.GetLogger(typeof(ChecksumInputTypeUtils)); public static ChecksumInputType getChecksumInputType(string checksumInputType, Error error) { + logger.Debug("getChecksumInputType"); if (error == null) return ChecksumInputType.NONE; if (checksumInputType == null) { error.setError("CHI06", "Unrecognized checksum input type"); + logger.Error("Unrecognized checksum input type"); return ChecksumInputType.NONE; } switch (checksumInputType.ToUpper(System.Globalization.CultureInfo.InvariantCulture).Trim()) @@ -41,12 +45,14 @@ public static ChecksumInputType getChecksumInputType(string checksumInputType, E return ChecksumInputType.LOCAL_FILE; default: error.setError("CHI01", "Unrecognized checksum input type"); + logger.Error("Unrecognized checksum input type"); return ChecksumInputType.NONE; } } public static string valueOf(ChecksumInputType checksumInputType, Error error) { + logger.Debug("valueOf"); if (error == null) return ""; switch (checksumInputType) { @@ -62,12 +68,14 @@ public static string valueOf(ChecksumInputType checksumInputType, Error error) return "LOCAL_FILE"; default: error.setError("CHI02", "Unrecognized checksum input type"); + logger.Error("Unrecognized checksum input type"); return ""; } } public static byte[] getBytes(ChecksumInputType checksumInputType, string input, Error error) { + logger.Debug("getBytes"); if (error == null) return null; EncodingUtil eu = new EncodingUtil(); byte[] aux = null; @@ -101,6 +109,7 @@ public static byte[] getBytes(ChecksumInputType checksumInputType, string input, catch (Exception e) { error.setError("CHI04", e.Message); + logger.Error("getBytes", e); } break; case ChecksumInputType.LOCAL_FILE: @@ -108,6 +117,7 @@ public static byte[] getBytes(ChecksumInputType checksumInputType, string input, break; default: error.setError("CHI05", "Unrecognized checksum input type"); + logger.Error("Unrecognized checksum input type"); break; } return aux; diff --git a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusCryptography/GeneXusCryptography.csproj b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusCryptography/GeneXusCryptography.csproj index 1d9a763cc..24bc5cbe4 100644 --- a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusCryptography/GeneXusCryptography.csproj +++ b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusCryptography/GeneXusCryptography.csproj @@ -10,6 +10,7 @@ + \ No newline at end of file diff --git a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusCryptography/Hash/Hashing.cs b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusCryptography/Hash/Hashing.cs index 4f1b8f9d7..c7675c33c 100644 --- a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusCryptography/Hash/Hashing.cs +++ b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusCryptography/Hash/Hashing.cs @@ -10,6 +10,7 @@ using SecurityAPICommons.Utils; using Org.BouncyCastle.Utilities.Encoders; using System.IO; +using log4net; namespace GeneXusCryptography.Hash { @@ -19,7 +20,7 @@ namespace GeneXusCryptography.Hash [SecuritySafeCritical] public class Hashing : SecurityAPIObject, IHashObject { - + private static readonly ILog logger = LogManager.GetLogger(typeof(Hashing)); /// /// Hashing constructor /// @@ -41,11 +42,12 @@ public Hashing() : base() [SecuritySafeCritical] public string DoHash(string hashAlgorithm, string txtToHash) { + logger.Debug("DoHash"); this.error.cleanError(); /*******INPUT VERIFICATION - BEGIN*******/ - SecurityUtils.validateStringInput("hashAlgorithm", hashAlgorithm, this.error); - SecurityUtils.validateStringInput("txtToHash", txtToHash, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "DoHash", "hashAlgorithm", hashAlgorithm, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "DoHash", "txtToHash", txtToHash, this.error); if (this.HasError()) { return ""; }; /*******INPUT VERIFICATION - END*******/ @@ -70,6 +72,7 @@ public string DoHash(string hashAlgorithm, string txtToHash) [SecuritySafeCritical] public byte[] CalculateHash(HashAlgorithm hashAlgorithm, byte[] input) { + logger.Debug("CalculateHash"); IDigest alg = createHash(hashAlgorithm); byte[] buffer = new byte[8192]; int n; @@ -89,6 +92,7 @@ public byte[] CalculateHash(HashAlgorithm hashAlgorithm, byte[] input) catch (Exception e) { error.setError("HA001", e.Message); + logger.Error("CalculateHash", e); return null; } return retValue; @@ -105,6 +109,7 @@ public byte[] CalculateHash(HashAlgorithm hashAlgorithm, byte[] input) /// IDigest algorithm instantiated class internal IDigest createHash(HashAlgorithm hashAlgorithm) { + logger.Debug("createHash"); switch (hashAlgorithm) { case HashAlgorithm.MD5: @@ -179,6 +184,7 @@ internal IDigest createHash(HashAlgorithm hashAlgorithm) return new WhirlpoolDigest(); default: this.error.setError("HA002", "Unrecognized HashAlgorithm"); + logger.Error("Unrecognized HashAlgorithm"); return null; } } diff --git a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusCryptography/HashUtils/HashAlgorithm.cs b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusCryptography/HashUtils/HashAlgorithm.cs index 8f605451e..ddcd48e33 100644 --- a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusCryptography/HashUtils/HashAlgorithm.cs +++ b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusCryptography/HashUtils/HashAlgorithm.cs @@ -1,4 +1,5 @@ +using log4net; using SecurityAPICommons.Commons; using System; using System.Collections.Generic; @@ -28,6 +29,7 @@ public enum HashAlgorithm [SecuritySafeCritical] public static class HashAlgorithmUtils { + private static readonly ILog logger = LogManager.GetLogger(typeof(HashAlgorithmUtils)); /// /// Mapping between string name and HashAlgorithm enum representation @@ -37,10 +39,12 @@ public static class HashAlgorithmUtils /// HashAlgorithm enum representation public static HashAlgorithm getHashAlgorithm(string hashAlgorithm, Error error) { + logger.Debug("getHashAlgorithm"); if (error == null) return HashAlgorithm.NONE; if (hashAlgorithm == null) { error.setError("HAA01", "Unrecognized HashAlgorihm"); + logger.Error("Unrecognized HashAlgorihm"); return HashAlgorithm.NONE; } switch (hashAlgorithm.ToUpper(System.Globalization.CultureInfo.InvariantCulture).Trim()) @@ -111,9 +115,11 @@ public static HashAlgorithm getHashAlgorithm(string hashAlgorithm, Error error) return HashAlgorithm.SHA3_512; case "SHAKE_128": error.setError("HAA04", "Not implemented algorithm SHAKE_128"); + logger.Error("Not implemented algorithm SHAKE_128"); return HashAlgorithm.NONE; case "SHAKE_256": error.setError("HAA05", "Not implemented algorithm SHAKE_256"); + logger.Error("Not implemented algorithm SHAKE_256"); return HashAlgorithm.NONE; case "SM3": return HashAlgorithm.SM3; @@ -123,6 +129,7 @@ public static HashAlgorithm getHashAlgorithm(string hashAlgorithm, Error error) return HashAlgorithm.WHIRLPOOL; default: error.setError("HAA02", "Unrecognized HashAlgorihm"); + logger.Error("Unrecognized HashAlgorihm"); return HashAlgorithm.NONE; } } @@ -135,6 +142,7 @@ public static HashAlgorithm getHashAlgorithm(string hashAlgorithm, Error error) /// string name value of HashAlgorithm public static string valueOf(HashAlgorithm hashAlgorithm, Error error) { + logger.Debug("valueOf"); if (error == null) return "Unrecognized algorithm"; switch (hashAlgorithm) { @@ -214,6 +222,7 @@ public static string valueOf(HashAlgorithm hashAlgorithm, Error error) return "WHIRLPOOL"; default: error.setError("HAA03", "Unrecognized HashAlgorihm"); + logger.Error("Unrecognized HashAlgorihm"); return "Unrecognized algorithm"; } } diff --git a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusCryptography/Mac/Cmac.cs b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusCryptography/Mac/Cmac.cs index 49cb4582b..2368fae10 100644 --- a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusCryptography/Mac/Cmac.cs +++ b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusCryptography/Mac/Cmac.cs @@ -11,12 +11,14 @@ using Org.BouncyCastle.Crypto.Parameters; using Org.BouncyCastle.Crypto.Macs; using System.IO; +using log4net; namespace GeneXusCryptography.Mac { [SecuritySafeCritical] public class Cmac : SecurityAPIObject, ICmacObject { + private static readonly ILog logger = LogManager.GetLogger(typeof(Cmac)); public Cmac() : base() { @@ -28,12 +30,13 @@ public Cmac() : base() [SecuritySafeCritical] public string calculate(string plainText, string key, string algorithm, int macSize) { + logger.Debug("calculate"); this.error.cleanError(); /*******INPUT VERIFICATION - BEGIN*******/ - SecurityUtils.validateStringInput("plainText", plainText, this.error); - SecurityUtils.validateStringInput("key", key, this.error); - SecurityUtils.validateStringInput("algorithm", algorithm, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "calculate", "plainText", plainText, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "calculate", "key", key, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "calculate", "algorithm", algorithm, this.error); if (this.HasError()) { return ""; }; /*******INPUT VERIFICATION - END*******/ @@ -59,12 +62,14 @@ public string calculate(string plainText, string key, string algorithm, int macS if (macSize > blockSize) { this.error.setError("CM001", "The mac length must be less or equal than the algorithm block size."); + logger.Error("The mac length must be less or equal than the algorithm block size."); return ""; } if (blockSize != 64 && blockSize != 128) { this.error.setError("CM002", "The block size must be 64 or 128 bits for CMAC. Wrong symmetric algorithm"); + logger.Error("The block size must be 64 or 128 bits for CMAC. Wrong symmetric algorithm"); return ""; } EncodingUtil eu = new EncodingUtil(); @@ -89,13 +94,14 @@ public string calculate(string plainText, string key, string algorithm, int macS [SecuritySafeCritical] public bool verify(string plainText, string key, string mac, string algorithm, int macSize) { + logger.Debug("verify"); this.error.cleanError(); /*******INPUT VERIFICATION - BEGIN*******/ - SecurityUtils.validateStringInput("plainText", plainText, this.error); - SecurityUtils.validateStringInput("key", key, this.error); - SecurityUtils.validateStringInput("mac", mac, this.error); - SecurityUtils.validateStringInput("algorithm", algorithm, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "verify", "plainText", plainText, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "verify", "key", key, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "verify", "mac", mac, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "verify", "algorithm", algorithm, this.error); if (this.HasError()) { return false; }; /*******INPUT VERIFICATION - END*******/ @@ -109,6 +115,7 @@ public bool verify(string plainText, string key, string mac, string algorithm, i private byte[] calculate(Stream input, byte[] key, int macSize, IBlockCipher blockCipher) { + logger.Debug("calculate"); ICipherParameters parms = new KeyParameter(key); CMac mac = macSize != 0 ? new CMac(blockCipher, macSize) : new CMac(blockCipher); @@ -120,6 +127,7 @@ private byte[] calculate(Stream input, byte[] key, int macSize, IBlockCipher blo catch (Exception e) { this.error.setError("CM003", e.Message); + logger.Error("calculate", e); return null; } @@ -138,6 +146,7 @@ private byte[] calculate(Stream input, byte[] key, int macSize, IBlockCipher blo { this.error.setError("CM004", e.Message); + logger.Error("calculate", e); return null; } diff --git a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusCryptography/Mac/Hmac.cs b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusCryptography/Mac/Hmac.cs index f003c3290..96b13f1a6 100644 --- a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusCryptography/Mac/Hmac.cs +++ b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusCryptography/Mac/Hmac.cs @@ -11,12 +11,14 @@ using GeneXusCryptography.HashUtils; using SecurityAPICommons.Utils; using System.IO; +using log4net; namespace GeneXusCryptography.Mac { [SecuritySafeCritical] public class Hmac : SecurityAPIObject, IHmacObject { + private static readonly ILog logger = LogManager.GetLogger(typeof(Hmac)); public Hmac() : base() { @@ -30,9 +32,9 @@ public string calculate(string plainText, string password, string algorithm) this.error.cleanError(); /*******INPUT VERIFICATION - BEGIN*******/ - SecurityUtils.validateStringInput("plainText", plainText, this.error); - SecurityUtils.validateStringInput("password", password, this.error); - SecurityUtils.validateStringInput("algorithm", algorithm, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "calculate", "plainText", plainText, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "calculate", "password", password, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "calculate", "algorithm", algorithm, this.error); if (this.HasError()) { return ""; }; /*******INPUT VERIFICATION - END*******/ @@ -60,13 +62,14 @@ public string calculate(string plainText, string password, string algorithm) [SecuritySafeCritical] public bool verify(string plainText, string password, string mac, string algorithm) { + logger.Debug("verify"); this.error.cleanError(); /*******INPUT VERIFICATION - BEGIN*******/ - SecurityUtils.validateStringInput("plainText", plainText, this.error); - SecurityUtils.validateStringInput("password", password, this.error); - SecurityUtils.validateStringInput("algorithm", algorithm, this.error); - SecurityUtils.validateStringInput("mac", mac, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "verify", "plainText", plainText, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "verify", "password", password, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "verify", "algorithm", algorithm, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "verify", "mac", mac, this.error); if (this.HasError()) { return false; }; /*******INPUT VERIFICATION - END*******/ @@ -77,7 +80,7 @@ public bool verify(string plainText, string password, string mac, string algorit private byte[] calculate(Stream input, byte[] password, HashUtils.HashAlgorithm algorithm) { - + logger.Debug("calculate"); IDigest digest = new Hashing().createHash(algorithm); if (this.HasError()) { return null; } @@ -89,6 +92,7 @@ private byte[] calculate(Stream input, byte[] password, HashUtils.HashAlgorithm catch (Exception e) { this.error.setError("HM001", e.Message); + logger.Error("calculate", e); return null; } @@ -106,6 +110,7 @@ private byte[] calculate(Stream input, byte[] password, HashUtils.HashAlgorithm catch (Exception e) { this.error.setError("HM002", e.Message); + logger.Error("calculate", e); return null; } return retValue; diff --git a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusCryptography/PasswordDerivation/PasswordDerivation.cs b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusCryptography/PasswordDerivation/PasswordDerivation.cs index 59ceced72..4785dab29 100644 --- a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusCryptography/PasswordDerivation/PasswordDerivation.cs +++ b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusCryptography/PasswordDerivation/PasswordDerivation.cs @@ -7,6 +7,7 @@ using System; using System.Security; using SecurityAPICommons.Utils; +using log4net; namespace GeneXusCryptography.PasswordDerivation { @@ -16,6 +17,7 @@ namespace GeneXusCryptography.PasswordDerivation [SecuritySafeCritical] public class PasswordDerivation : SecurityAPIObject, IPasswordDerivationObject { + private static readonly ILog logger = LogManager.GetLogger(typeof(PasswordDerivation)); /// @@ -45,6 +47,7 @@ public PasswordDerivation() : base() public string DoGenerateSCrypt(string password, string salt, int CPUCost, int blockSize, int parallelization, int keyLenght) { + logger.Debug("DoGenerateSCrypt"); this.error.cleanError(); EncodingUtil eu = new EncodingUtil(); @@ -63,6 +66,7 @@ public string DoGenerateSCrypt(string password, string salt, int CPUCost, int bl catch (Exception e) { this.error.setError("PD001", e.Message); + logger.Error("DoGenerateSCrypt", e); return ""; } return Base64.ToBase64String(encryptedBytes); @@ -77,6 +81,7 @@ public string DoGenerateSCrypt(string password, string salt, int CPUCost, int bl [SecuritySafeCritical] public string DoGenerateDefaultSCrypt(string password, string salt) { + logger.Debug("DoGenerateDefaultSCrypt"); int N = 16384; int r = 8; int p = 1; @@ -94,6 +99,7 @@ public string DoGenerateDefaultSCrypt(string password, string salt) [SecuritySafeCritical] public string DoGenerateBcrypt(string password, string salt, int cost) { + logger.Debug("DoGenerateBcrypt"); this.error.cleanError(); EncodingUtil eu = new EncodingUtil(); @@ -112,6 +118,7 @@ public string DoGenerateBcrypt(string password, string salt, int cost) catch (Exception e) { this.error.setError("PD002", e.Message); + logger.Error("DoGenerateBcrypt", e); return ""; } @@ -127,6 +134,7 @@ public string DoGenerateBcrypt(string password, string salt, int cost) [SecuritySafeCritical] public string DoGenerateDefaultBcrypt(string password, string salt) { + logger.Debug("DoGenerateDefaultBcrypt"); int cost = 6; return DoGenerateBcrypt(password, salt, cost); } @@ -135,7 +143,9 @@ public string DoGenerateDefaultBcrypt(string password, string salt) public string DoGenerateArgon2(string argon2Version10, string argon2HashType, int iterations, int memory, int parallelism, String password, string salt, int hashLength) { + logger.Debug("DoGenerateArgon2"); this.error.setError("PD004", "Not implemented function for Net"); + logger.Error("Not implemented function for Net"); return ""; } diff --git a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusCryptography/PasswordDerivation/PasswordDerivationAlgorithm.cs b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusCryptography/PasswordDerivation/PasswordDerivationAlgorithm.cs index 97aa812fe..7a2e2e2a5 100644 --- a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusCryptography/PasswordDerivation/PasswordDerivationAlgorithm.cs +++ b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusCryptography/PasswordDerivation/PasswordDerivationAlgorithm.cs @@ -4,7 +4,7 @@ using System.Collections.Generic; using System.Linq; using System.Security; - +using log4net; namespace GeneXusCryptography.PasswordDerivation { @@ -24,6 +24,7 @@ public enum PasswordDerivationAlgorithm [SecuritySafeCritical] public static class PasswordDerivationAlgorithmUtils { + private static readonly ILog logger = LogManager.GetLogger(typeof(PasswordDerivationAlgorithmUtils)); /// /// Mapping between string name and PasswordDerivationAlgorithm enum representation /// @@ -32,10 +33,12 @@ public static class PasswordDerivationAlgorithmUtils /// PasswordDerivationAlgorithm enum representation public static PasswordDerivationAlgorithm getPasswordDerivationAlgorithm(string passwordDerivationAlgorithm, Error error) { + logger.Debug("getPasswordDerivationAlgorithm"); if (error == null) return PasswordDerivationAlgorithm.NONE; if (passwordDerivationAlgorithm == null) { error.setError("PDA03", "Unrecognized PasswordDerivationAlgorithm"); + logger.Error("Unrecognized PasswordDerivationAlgorithm"); return PasswordDerivationAlgorithm.NONE; } switch (passwordDerivationAlgorithm.Trim()) @@ -48,6 +51,7 @@ public static PasswordDerivationAlgorithm getPasswordDerivationAlgorithm(string return PasswordDerivationAlgorithm.Argon2; default: error.setError("PDA01", "Unrecognized PasswordDerivationAlgorithm"); + logger.Error("Unrecognized PasswordDerivationAlgorithm"); return PasswordDerivationAlgorithm.NONE; } } @@ -59,6 +63,7 @@ public static PasswordDerivationAlgorithm getPasswordDerivationAlgorithm(string /// PasswordDerivationAlgorithm value in string public static string valueOf(PasswordDerivationAlgorithm passwordDerivationAlgorithm, Error error) { + logger.Debug("valueOf"); if (error == null) return "Unrecognized algorithm"; switch (passwordDerivationAlgorithm) { @@ -70,6 +75,7 @@ public static string valueOf(PasswordDerivationAlgorithm passwordDerivationAlgor return "Argon2"; default: error.setError("PDA02", "Unrecognized PasswordDerivationAlgorithm"); + logger.Error("Unrecognized PasswordDerivationAlgorithm"); return "Unrecognized algorithm"; } } diff --git a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusCryptography/Symmetric/SymmetricBlockCipher.cs b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusCryptography/Symmetric/SymmetricBlockCipher.cs index d242273ff..820f493f2 100644 --- a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusCryptography/Symmetric/SymmetricBlockCipher.cs +++ b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusCryptography/Symmetric/SymmetricBlockCipher.cs @@ -13,6 +13,7 @@ using SecurityAPICommons.Config; using SecurityAPICommons.Utils; using System.IO; +using log4net; namespace GeneXusCryptography.Symmetric { @@ -22,7 +23,7 @@ namespace GeneXusCryptography.Symmetric [SecuritySafeCritical] public class SymmetricBlockCipher : SecurityAPIObject, ISymmetricBlockCipherObject { - + private static readonly ILog logger = LogManager.GetLogger(typeof(SymmetricBlockCipher)); @@ -52,14 +53,15 @@ public SymmetricBlockCipher() : base() public string DoAEADEncrypt(string symmetricBlockAlgorithm, string symmetricBlockMode, string key, int macSize, string nonce, string plainText) { + logger.Debug("DoAEADEncrypt"); this.error.cleanError(); /*******INPUT VERIFICATION - BEGIN*******/ - SecurityUtils.validateStringInput("symmetricBlockAlgorithm", symmetricBlockAlgorithm, this.error); - SecurityUtils.validateStringInput("symmetricBlockMode", symmetricBlockMode, this.error); - SecurityUtils.validateStringInput("key", key, this.error); - SecurityUtils.validateStringInput("nonce", nonce, this.error); - SecurityUtils.validateStringInput("plainText", plainText, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "DoAEADEncrypt", "symmetricBlockAlgorithm", symmetricBlockAlgorithm, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "DoAEADEncrypt", "symmetricBlockMode", symmetricBlockMode, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "DoAEADEncrypt", "key", key, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "DoAEADEncrypt", "nonce", nonce, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "DoAEADEncrypt", "plainText", plainText, this.error); if (this.HasError()) { return ""; }; /*******INPUT VERIFICATION - END*******/ @@ -87,14 +89,15 @@ public string DoAEADEncrypt(string symmetricBlockAlgorithm, string symmetricBloc public string DoAEADDecrypt(string symmetricBlockAlgorithm, string symmetricBlockMode, string key, int macSize, string nonce, string encryptedInput) { + logger.Debug("DoAEADDecrypt"); this.error.cleanError(); /*******INPUT VERIFICATION - BEGIN*******/ - SecurityUtils.validateStringInput("symmetricBlockAlgorithm", symmetricBlockAlgorithm, this.error); - SecurityUtils.validateStringInput("symmetricBlockMode", symmetricBlockMode, this.error); - SecurityUtils.validateStringInput("key", key, this.error); - SecurityUtils.validateStringInput("nonce", nonce, this.error); - SecurityUtils.validateStringInput("encryptedInput", encryptedInput, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "DoAEADDecrypt", "symmetricBlockAlgorithm", symmetricBlockAlgorithm, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "DoAEADDecrypt", "symmetricBlockMode", symmetricBlockMode, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "DoAEADDecrypt", "key", key, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "DoAEADDecrypt", "nonce", nonce, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "DoAEADDecrypt", "encryptedInput", encryptedInput, this.error); if (this.HasError()) { return ""; }; /*******INPUT VERIFICATION - END*******/ @@ -106,6 +109,7 @@ public string DoAEADDecrypt(string symmetricBlockAlgorithm, string symmetricBloc catch (Exception e) { this.error.setError("SB001", e.Message); + logger.Error("DoAEADEncrypt", e); return ""; } @@ -136,15 +140,16 @@ public string DoAEADDecrypt(string symmetricBlockAlgorithm, string symmetricBloc public string DoEncrypt(string symmetricBlockAlgorithm, string symmetricBlockMode, string symmetricBlockPadding, string key, string IV, string plainText) { + logger.Debug("DoEncrypt"); this.error.cleanError(); /*******INPUT VERIFICATION - BEGIN*******/ - SecurityUtils.validateStringInput("symmetricBlockAlgorithm", symmetricBlockAlgorithm, this.error); - SecurityUtils.validateStringInput("symmetricBlockMode", symmetricBlockMode, this.error); - SecurityUtils.validateStringInput("symmetricBlockPadding", symmetricBlockPadding, this.error); - SecurityUtils.validateStringInput("key", key, this.error); - SecurityUtils.validateStringInput("IV", IV, this.error); - SecurityUtils.validateStringInput("plainText", plainText, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "DoEncrypt", "symmetricBlockAlgorithm", symmetricBlockAlgorithm, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "DoEncrypt", "symmetricBlockMode", symmetricBlockMode, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "DoEncrypt", "symmetricBlockPadding", symmetricBlockPadding, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "DoEncrypt", "key", key, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "DoEncrypt", "IV", IV, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "DoEncrypt", "plainText", plainText, this.error); if (this.HasError()) { return ""; }; /*******INPUT VERIFICATION - END*******/ @@ -175,15 +180,16 @@ public string DoEncrypt(string symmetricBlockAlgorithm, string symmetricBlockMod public string DoDecrypt(string symmetricBlockAlgorithm, string symmetricBlockMode, string symmetricBlockPadding, string key, string IV, string encryptedInput) { + logger.Debug("DoDecrypt"); this.error.cleanError(); /*******INPUT VERIFICATION - BEGIN*******/ - SecurityUtils.validateStringInput("symmetricBlockAlgorithm", symmetricBlockAlgorithm, this.error); - SecurityUtils.validateStringInput("symmetricBlockMode", symmetricBlockMode, this.error); - SecurityUtils.validateStringInput("symmetricBlockPadding", symmetricBlockPadding, this.error); - SecurityUtils.validateStringInput("key", key, this.error); - SecurityUtils.validateStringInput("IV", IV, this.error); - SecurityUtils.validateStringInput("encryptedInput", encryptedInput, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "DoDecrypt", "symmetricBlockAlgorithm", symmetricBlockAlgorithm, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "DoDecrypt", "symmetricBlockMode", symmetricBlockMode, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "DoDecrypt", "symmetricBlockPadding", symmetricBlockPadding, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "DoDecrypt", "key", key, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "DoDecrypt", "IV", IV, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "DoDecrypt", "encryptedInput", encryptedInput, this.error); if (this.HasError()) { return ""; }; /*******INPUT VERIFICATION - END*******/ @@ -195,6 +201,7 @@ public string DoDecrypt(string symmetricBlockAlgorithm, string symmetricBlockMod catch (Exception e) { this.error.setError("SB002", e.Message); + logger.Error("DoDecrypt", e); return ""; } @@ -212,16 +219,17 @@ public string DoDecrypt(string symmetricBlockAlgorithm, string symmetricBlockMod } [SecuritySafeCritical] - public bool DoAEADEncryptFile(String symmetricBlockAlgorithm, String symmetricBlockMode, String key, int macSize, - String nonce, String pathInputFile, String pathOutputFile) + public bool DoAEADEncryptFile(string symmetricBlockAlgorithm, string symmetricBlockMode, string key, int macSize, + string nonce, string pathInputFile, string pathOutputFile) { + logger.Debug("DoAEADEncryptFile"); this.error.cleanError(); /*******INPUT VERIFICATION - BEGIN*******/ - SecurityUtils.validateStringInput("symmetricBlockAlgorithm", symmetricBlockAlgorithm, this.error); - SecurityUtils.validateStringInput("symmetricBlockMode", symmetricBlockMode, this.error); - SecurityUtils.validateStringInput("key", key, this.error); - SecurityUtils.validateStringInput("nonce", nonce, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "DoAEADEncryptFile", "symmetricBlockAlgorithm", symmetricBlockAlgorithm, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "DoAEADEncryptFile", "symmetricBlockMode", symmetricBlockMode, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "DoAEADEncryptFile", "key", key, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "DoAEADEncryptFile", "nonce", nonce, this.error); if (this.HasError()) { return false; }; /*******INPUT VERIFICATION - END*******/ @@ -229,16 +237,17 @@ public bool DoAEADEncryptFile(String symmetricBlockAlgorithm, String symmetricBl } [SecuritySafeCritical] - public bool DoAEADDecryptFile(String symmetricBlockAlgorithm, String symmetricBlockMode, String key, int macSize, - String nonce, String pathInputFile, String pathOutputFile) + public bool DoAEADDecryptFile(string symmetricBlockAlgorithm, string symmetricBlockMode, string key, int macSize, + string nonce, string pathInputFile, string pathOutputFile) { + logger.Debug("DoAEADDecryptFile"); this.error.cleanError(); /*******INPUT VERIFICATION - BEGIN*******/ - SecurityUtils.validateStringInput("symmetricBlockAlgorithm", symmetricBlockAlgorithm, this.error); - SecurityUtils.validateStringInput("symmetricBlockMode", symmetricBlockMode, this.error); - SecurityUtils.validateStringInput("key", key, this.error); - SecurityUtils.validateStringInput("nonce", nonce, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "DoAEADDecryptFile", "symmetricBlockAlgorithm", symmetricBlockAlgorithm, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "DoAEADDecryptFile", "symmetricBlockMode", symmetricBlockMode, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "DoAEADDecryptFile", "key", key, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "DoAEADDecryptFile", "nonce", nonce, this.error); if (this.HasError()) { return false; }; /*******INPUT VERIFICATION - END*******/ @@ -246,17 +255,18 @@ public bool DoAEADDecryptFile(String symmetricBlockAlgorithm, String symmetricBl } [SecuritySafeCritical] - public bool DoEncryptFile(String symmetricBlockAlgorithm, String symmetricBlockMode, String symmetricBlockPadding, - String key, String IV, String pathInputFile, String pathOutputFile) + public bool DoEncryptFile(string symmetricBlockAlgorithm, string symmetricBlockMode, string symmetricBlockPadding, + string key, string IV, string pathInputFile, string pathOutputFile) { + logger.Debug("DoEncryptFile"); this.error.cleanError(); /*******INPUT VERIFICATION - BEGIN*******/ - SecurityUtils.validateStringInput("symmetricBlockAlgorithm", symmetricBlockAlgorithm, this.error); - SecurityUtils.validateStringInput("symmetricBlockMode", symmetricBlockMode, this.error); - SecurityUtils.validateStringInput("symmetricBlockPadding", symmetricBlockPadding, this.error); - SecurityUtils.validateStringInput("key", key, this.error); - SecurityUtils.validateStringInput("IV", IV, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "DoEncryptFile", "symmetricBlockAlgorithm", symmetricBlockAlgorithm, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "DoEncryptFile", "symmetricBlockMode", symmetricBlockMode, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "DoEncryptFile", "symmetricBlockPadding", symmetricBlockPadding, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "DoEncryptFile", "key", key, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "DoEncryptFile", "IV", IV, this.error); if (this.HasError()) { return false; }; /*******INPUT VERIFICATION - END*******/ @@ -264,16 +274,17 @@ public bool DoEncryptFile(String symmetricBlockAlgorithm, String symmetricBlockM } [SecuritySafeCritical] - public bool DoDecryptFile(String symmetricBlockAlgorithm, String symmetricBlockMode, String symmetricBlockPadding, - String key, String IV, String pathInputFile, String pathOutputFile) + public bool DoDecryptFile(string symmetricBlockAlgorithm, string symmetricBlockMode, string symmetricBlockPadding, + string key, string IV, string pathInputFile, string pathOutputFile) { + logger.Debug("DoDecryptFile"); this.error.cleanError(); /*******INPUT VERIFICATION - BEGIN*******/ - SecurityUtils.validateStringInput("symmetricBlockAlgorithm", symmetricBlockAlgorithm, this.error); - SecurityUtils.validateStringInput("symmetricBlockMode", symmetricBlockMode, this.error); - SecurityUtils.validateStringInput("symmetricBlockPadding", symmetricBlockPadding, this.error); - SecurityUtils.validateStringInput("key", key, this.error); - SecurityUtils.validateStringInput("IV", IV, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "DoDecryptFile", "symmetricBlockAlgorithm", symmetricBlockAlgorithm, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "DoDecryptFile", "symmetricBlockMode", symmetricBlockMode, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "DoDecryptFile", "symmetricBlockPadding", symmetricBlockPadding, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "DoDecryptFile", "key", key, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "DoDecryptFile", "IV", IV, this.error); if (this.HasError()) { return false; }; /*******INPUT VERIFICATION - END*******/ @@ -294,6 +305,7 @@ public bool DoDecryptFile(String symmetricBlockAlgorithm, String symmetricBlockM private BufferedBlockCipher getCipher(SymmetricBlockAlgorithm algorithm, SymmetricBlockMode mode, SymmetricBlockPadding padding) { + logger.Debug("getCipher"); IBlockCipher engine = getCipherEngine(algorithm); IBlockCipherPadding paddingCipher = getPadding(padding); IBlockCipher bc; @@ -337,7 +349,7 @@ private static bool usesCTS(SymmetricBlockMode mode, SymmetricBlockPadding paddi /// IBlockCipher with the algorithm Engine internal IBlockCipher getCipherEngine(SymmetricBlockAlgorithm algorithm) { - + logger.Debug("getCipherEngine"); IBlockCipher engine = null; switch (algorithm) @@ -437,6 +449,7 @@ internal IBlockCipher getCipherEngine(SymmetricBlockAlgorithm algorithm) break; default: this.error.setError("SB003", "Unrecognized symmetric block algoritm"); + logger.Error("Unrecognized symmetric block algoritm"); break; } return engine; @@ -449,7 +462,7 @@ internal IBlockCipher getCipherEngine(SymmetricBlockAlgorithm algorithm) /// IBlockCipherPadding with loaded padding type, if padding is WITHCTS returns null private IBlockCipherPadding getPadding(SymmetricBlockPadding padding) { - + logger.Debug("getPadding"); IBlockCipherPadding paddingCipher = null; switch (padding) @@ -476,6 +489,7 @@ private IBlockCipherPadding getPadding(SymmetricBlockPadding padding) break; default: this.error.setError("SB004", "Unrecognized symmetric block padding."); + logger.Error("Unrecognized symmetric block padding."); break; } return paddingCipher; @@ -488,7 +502,7 @@ private IBlockCipherPadding getPadding(SymmetricBlockPadding padding) /// AEADBlockCipher loaded with a given BlockCipher private IAeadBlockCipher getAEADCipherMode(IBlockCipher blockCipher, SymmetricBlockMode mode) { - + logger.Debug("getAEADCipherMode"); IAeadBlockCipher bc = null; switch (mode) @@ -507,6 +521,7 @@ private IAeadBlockCipher getAEADCipherMode(IBlockCipher blockCipher, SymmetricBl break; default: this.error.setError("SB005", "Unrecognized symmetric AEAD mode"); + logger.Error("Unrecognized symmetric AEAD mode"); break; } return bc; @@ -520,7 +535,7 @@ private IAeadBlockCipher getAEADCipherMode(IBlockCipher blockCipher, SymmetricBl /// BlockCipher with mode loaded private IBlockCipher getCipherMode(IBlockCipher blockCipher, SymmetricBlockMode mode) { - + logger.Debug("getCipherMode"); IBlockCipher bc = null; switch (mode) @@ -556,6 +571,7 @@ private IBlockCipher getCipherMode(IBlockCipher blockCipher, SymmetricBlockMode default: this.error.setError("SB006", "Unrecognized symmetric block mode"); + logger.Error("Unrecognized symmetric block mode"); break; } return bc; @@ -585,6 +601,7 @@ private byte[] SetUp(string symmetricBlockAlgorithm, string symmetricBlockMode, private byte[] encryptAEAD(SymmetricBlockAlgorithm algorithm, SymmetricBlockMode mode, byte[] key, byte[] nonce, byte[] txt, int macSize, bool toEncrypt, bool isFile, string pathInput, string pathOutput) { + logger.Debug("encryptAEAD"); IBlockCipher engine = getCipherEngine(algorithm); IAeadBlockCipher bbc = getAEADCipherMode(engine, mode); if (this.HasError()) { return null; } @@ -599,6 +616,7 @@ private byte[] encryptAEAD(SymmetricBlockAlgorithm algorithm, SymmetricBlockMode catch (Exception e) { this.error.setError("SB007", e.Message); + logger.Error("encryptAEAD", e); return null; } byte[] outputBytes = null; @@ -629,6 +647,7 @@ private byte[] encryptAEAD(SymmetricBlockAlgorithm algorithm, SymmetricBlockMode catch (Exception e) { this.error.setError("SB011", e.Message); + logger.Error("encryptAEAD", e); return null; } outputBytes = new byte[1]; @@ -645,6 +664,7 @@ private byte[] encryptAEAD(SymmetricBlockAlgorithm algorithm, SymmetricBlockMode catch (Exception e) { this.error.setError("SB008", e.Message); + logger.Error("encryptAEAD", e); return null; } @@ -657,7 +677,7 @@ private byte[] encryptAEAD(SymmetricBlockAlgorithm algorithm, SymmetricBlockMode private byte[] encrypt(SymmetricBlockAlgorithm algorithm, SymmetricBlockMode mode, SymmetricBlockPadding padding, byte[] key, byte[] iv, byte[] input, bool toEncrypt, bool isFile, string pathInput, string pathOutput) { - + logger.Debug("encrypt"); BufferedBlockCipher bbc = getCipher(algorithm, mode, padding); KeyParameter keyParam = new KeyParameter(key); if (this.HasError()) { return null; } @@ -677,6 +697,7 @@ private byte[] encrypt(SymmetricBlockAlgorithm algorithm, SymmetricBlockMode mod catch (Exception e) { this.error.setError("SB009", e.Message); + logger.Error("encrypt", e); return null; } byte[] outputBytes = null; @@ -707,6 +728,7 @@ private byte[] encrypt(SymmetricBlockAlgorithm algorithm, SymmetricBlockMode mod catch (Exception e) { this.error.setError("SB012", e.Message); + logger.Error("encrypt", e); return null; } outputBytes = new byte[1]; @@ -725,6 +747,7 @@ private byte[] encrypt(SymmetricBlockAlgorithm algorithm, SymmetricBlockMode mod catch (Exception e) { this.error.setError("SB010", e.Message); + logger.Error("encrypt", e); return null; } } @@ -735,9 +758,10 @@ private byte[] encrypt(SymmetricBlockAlgorithm algorithm, SymmetricBlockMode mod private bool SetUpFile(string symmetricBlockAlgorithm, string symmetricBlockMode, string symmetricBlockPadding, string nonce, string key, string pathInput, string pathOutput, int macSize, bool toEncrypt, bool isAEAD) { + logger.Debug("SetUpFile"); /*******INPUT VERIFICATION - BEGIN*******/ - SecurityUtils.validateStringInput("pathInputFile", pathInput, this.error); - SecurityUtils.validateStringInput("pathOutputFile", pathOutput, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "SetUpFile", "pathInputFile", pathInput, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "SetUpFile", "pathOutputFile", pathOutput, this.error); if (this.HasError()) { return false; }; /*******INPUT VERIFICATION - END*******/ byte[] output = SetUp(symmetricBlockAlgorithm, symmetricBlockMode, symmetricBlockPadding, nonce, key, null, macSize, toEncrypt, isAEAD, true, pathInput, pathOutput); diff --git a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusCryptography/Symmetric/SymmetricStreamCipher.cs b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusCryptography/Symmetric/SymmetricStreamCipher.cs index ab4877476..7d05af8ed 100644 --- a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusCryptography/Symmetric/SymmetricStreamCipher.cs +++ b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusCryptography/Symmetric/SymmetricStreamCipher.cs @@ -11,6 +11,7 @@ using System.Security; using SecurityAPICommons.Utils; +using log4net; namespace GeneXusCryptography.Symmetric { @@ -20,7 +21,7 @@ namespace GeneXusCryptography.Symmetric [SecuritySafeCritical] public class SymmetricStreamCipher : SecurityAPIObject, ISymmectricStreamCipherObject { - + private static readonly ILog logger = LogManager.GetLogger(typeof(SymmetricStreamCipher)); public SymmetricStreamCipher() : base() { @@ -44,12 +45,13 @@ public SymmetricStreamCipher() : base() public string DoEncrypt(string symmetricStreamAlgorithm, string key, string IV, string plainText) { + logger.Debug("DoEncrypt"); this.error.cleanError(); /*******INPUT VERIFICATION - BEGIN*******/ - SecurityUtils.validateStringInput("symmetricStreamAlgorithm", symmetricStreamAlgorithm, this.error); - SecurityUtils.validateStringInput("key", key, this.error); - SecurityUtils.validateStringInput("plainText", plainText, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "DoEncrypt", "symmetricStreamAlgorithm", symmetricStreamAlgorithm, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "DoEncrypt", "key", key, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "DoEncrypt", "plainText", plainText, this.error); if (this.HasError()) { return ""; }; /*******INPUT VERIFICATION - END*******/ @@ -81,12 +83,13 @@ public string DoEncrypt(string symmetricStreamAlgorithm, string key, string IV, public string DoDecrypt(string symmetricStreamAlgorithm, string key, string IV, string encryptedInput) { + logger.Debug("DoDecrypt"); this.error.cleanError(); /*******INPUT VERIFICATION - BEGIN*******/ - SecurityUtils.validateStringInput("symmetricStreamAlgorithm", symmetricStreamAlgorithm, this.error); - SecurityUtils.validateStringInput("key", key, this.error); - SecurityUtils.validateStringInput("encryptedInput", encryptedInput, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "DoDecrypt", "symmetricStreamAlgorithm", symmetricStreamAlgorithm, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "DoDecrypt", "key", key, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "DoDecrypt", "encryptedInput", encryptedInput, this.error); if (this.HasError()) { return ""; }; /*******INPUT VERIFICATION - END*******/ @@ -98,6 +101,7 @@ public string DoDecrypt(string symmetricStreamAlgorithm, string key, string IV, catch (Exception e) { this.error.setError("SS001", e.Message); + logger.Error("DoDecrypt", e); return ""; } @@ -126,7 +130,7 @@ public string DoDecrypt(string symmetricStreamAlgorithm, string key, string IV, /// IStreamCipher with the algorithm Stream Engine private IStreamCipher getCipherEngine(SymmetricStreamAlgorithm algorithm) { - + logger.Debug("getCipherEngine"); IStreamCipher engine = null; switch (algorithm) @@ -150,7 +154,8 @@ private IStreamCipher getCipherEngine(SymmetricStreamAlgorithm algorithm) engine = new IsaacEngine(); break; default: - this.GetError().setError("SS005", "Cipher " + algorithm + " not recognised."); + this.GetError().setError("SS005", String.Format("Cipher {0} not recognised.", algorithm)); + logger.Error(String.Format("Cipher {0} not recognised.", algorithm)); break; } return engine; @@ -171,6 +176,7 @@ private byte[] setUp(String symmetricStreamAlgorithm, string key, string IV, byt private byte[] encrypt(SymmetricStreamAlgorithm algorithm, byte[] key, byte[] IV, byte[] input, bool toEncrypt) { + logger.Debug("encrypt"); IStreamCipher engine = getCipherEngine(algorithm); if (this.HasError()) { return null; } @@ -192,6 +198,7 @@ private byte[] encrypt(SymmetricStreamAlgorithm algorithm, byte[] key, byte[] IV catch (Exception e) { this.error.setError("SS003", e.Message); + logger.Error("encrypt", e); return null; } @@ -204,6 +211,7 @@ private byte[] encrypt(SymmetricStreamAlgorithm algorithm, byte[] key, byte[] IV catch (Exception e) { this.error.setError("SS004", e.Message); + logger.Error("encrypt", e); return null; } return output; diff --git a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusCryptography/SymmetricUtils/SymmetricBlockAlgorithm.cs b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusCryptography/SymmetricUtils/SymmetricBlockAlgorithm.cs index 9b65810be..995d3ff82 100644 --- a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusCryptography/SymmetricUtils/SymmetricBlockAlgorithm.cs +++ b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusCryptography/SymmetricUtils/SymmetricBlockAlgorithm.cs @@ -1,4 +1,5 @@ +using log4net; using SecurityAPICommons.Commons; using System; using System.Collections.Generic; @@ -27,6 +28,7 @@ public enum SymmetricBlockAlgorithm [SecuritySafeCritical] public static class SymmetricBlockAlgorithmUtils { + private static readonly ILog logger = LogManager.GetLogger(typeof(SymmetricBlockAlgorithmUtils)); /// /// Mapping between string name and SymmetricBlockAlgorithm enum representation /// @@ -35,10 +37,12 @@ public static class SymmetricBlockAlgorithmUtils /// SymmetricBlockAlgorithm enum representaton public static SymmetricBlockAlgorithm getSymmetricBlockAlgorithm(string symmetricBlockAlgorithm, Error error) { + logger.Debug("getSymmetricBlockAlgorithm"); if (error == null) return SymmetricBlockAlgorithm.NONE; if (symmetricBlockAlgorithm == null) { error.setError("SBA05", "Unrecognized SymmetricBlockAlgorithm"); + logger.Error("Unrecognized SymmetricBlockAlgorithm"); return SymmetricBlockAlgorithm.NONE; } switch (symmetricBlockAlgorithm.ToUpper(System.Globalization.CultureInfo.InvariantCulture).Trim()) @@ -107,6 +111,7 @@ public static SymmetricBlockAlgorithm getSymmetricBlockAlgorithm(string symmetri return SymmetricBlockAlgorithm.TEA; default: error.setError("SBA01", "Unrecognized SymmetricBlockAlgorithm"); + logger.Error("Unrecognized SymmetricBlockAlgorithm"); return SymmetricBlockAlgorithm.NONE; } @@ -121,6 +126,7 @@ public static SymmetricBlockAlgorithm getSymmetricBlockAlgorithm(string symmetri /// value of SymmetricBlockAlgorithm in string public static string valueOf(SymmetricBlockAlgorithm symmetricBlockAlgorithm, Error error) { + logger.Debug("valueOf"); if (error == null) return "SymmetricBlockAlgorithm"; @@ -190,6 +196,7 @@ public static string valueOf(SymmetricBlockAlgorithm symmetricBlockAlgorithm, Er return "TEA"; default: error.setError("SBA02", "Unrecognized SymmetricBlockAlgorithm"); + logger.Error("Unrecognized SymmetricBlockAlgorithm"); return "SymmetricBlockAlgorithm"; } } @@ -202,6 +209,7 @@ public static string valueOf(SymmetricBlockAlgorithm symmetricBlockAlgorithm, Er /// the specific block size for the algorithm, algorithm unknown if 0 public static int getBlockSize(SymmetricBlockAlgorithm algorithm, Error error) { + logger.Debug("getBlockSize"); if (error == null) return 0; switch (algorithm) { @@ -247,6 +255,7 @@ public static int getBlockSize(SymmetricBlockAlgorithm algorithm, Error error) return 1024; default: error.setError("SBA03", "Unrecognized SymmetricBlockAlgorithm"); + logger.Error("Unrecognized SymmetricBlockAlgorithm"); return 0; } } diff --git a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusCryptography/SymmetricUtils/SymmetricBlockMode.cs b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusCryptography/SymmetricUtils/SymmetricBlockMode.cs index 8374f45ee..60612400d 100644 --- a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusCryptography/SymmetricUtils/SymmetricBlockMode.cs +++ b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusCryptography/SymmetricUtils/SymmetricBlockMode.cs @@ -1,4 +1,5 @@ +using log4net; using SecurityAPICommons.Commons; using System; using System.Collections.Generic; @@ -28,6 +29,7 @@ public enum SymmetricBlockMode [SecuritySafeCritical] public static class SymmetricBlockModeUtils { + private static readonly ILog logger = LogManager.GetLogger(typeof(SymmetricBlockModeUtils)); /// /// Mapping between string name and SymmetricBlockMode enum representation /// @@ -36,10 +38,12 @@ public static class SymmetricBlockModeUtils /// SymmetricBlockMode enum representation public static SymmetricBlockMode getSymmetricBlockMode(string symmetricBlockMode, Error error) { + logger.Debug("getSymmetricBlockMode"); if (error == null) return SymmetricBlockMode.NONE; if (symmetricBlockMode == null) { error.setError("SBM04", "Unrecognized SymmetricBlockMode"); + logger.Error("Unrecognized SymmetricBlockMode"); return SymmetricBlockMode.NONE; } @@ -75,6 +79,7 @@ public static SymmetricBlockMode getSymmetricBlockMode(string symmetricBlockMode return SymmetricBlockMode.AEAD_CCM; default: error.setError("SBM01", "Unrecognized SymmetricBlockMode"); + logger.Error("Unrecognized SymmetricBlockMode"); return SymmetricBlockMode.NONE; } } @@ -88,6 +93,7 @@ public static SymmetricBlockMode getSymmetricBlockMode(string symmetricBlockMode /// SymmetricBlockMode name value in string public static string valueOf(SymmetricBlockMode symmetricBlockMode, Error error) { + logger.Debug("valueOf"); if (error == null) return "Unrecognized operation mode"; switch (symmetricBlockMode) @@ -124,6 +130,7 @@ public static string valueOf(SymmetricBlockMode symmetricBlockMode, Error error) return "AEAD_CCM"; default: error.setError("SBM02", "Unrecognized SymmetricBlockMode"); + logger.Error("Unrecognized SymmetricBlockMode"); return "Unrecognized operation mode"; } } @@ -136,6 +143,7 @@ public static string valueOf(SymmetricBlockMode symmetricBlockMode, Error error) /// boolean true if operation mode is AEAD type public static bool isAEAD(SymmetricBlockMode symmetricBlockMode, Error error) { + logger.Debug("isAEAD"); if (error == null) return false; switch (symmetricBlockMode) { @@ -146,6 +154,7 @@ public static bool isAEAD(SymmetricBlockMode symmetricBlockMode, Error error) return true; default: error.setError("SBM03", "Unrecognized Symmetric AEAD BlockMode"); + logger.Error("Unrecognized Symmetric AEAD BlockMode"); return false; } } diff --git a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusCryptography/SymmetricUtils/SymmetricBlockPadding.cs b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusCryptography/SymmetricUtils/SymmetricBlockPadding.cs index 08385df93..765e52a93 100644 --- a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusCryptography/SymmetricUtils/SymmetricBlockPadding.cs +++ b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusCryptography/SymmetricUtils/SymmetricBlockPadding.cs @@ -1,4 +1,5 @@ +using log4net; using SecurityAPICommons.Commons; using System; using System.Collections.Generic; @@ -25,6 +26,7 @@ public enum SymmetricBlockPadding [SecuritySafeCritical] public static class SymmetricBlockPaddingUtils { + private static readonly ILog logger = LogManager.GetLogger(typeof(SymmetricBlockPaddingUtils)); /// /// Mapping between string name and SymmetricBlockPadding enum representation /// @@ -33,10 +35,12 @@ public static class SymmetricBlockPaddingUtils /// SymmetricBlockPadding enum representation public static SymmetricBlockPadding getSymmetricBlockPadding(string symmetricBlockPadding, Error error) { + logger.Debug("getSymmetricBlockPadding"); if (error == null) return SymmetricBlockPadding.NOPADDING; if (symmetricBlockPadding == null) { error.setError("SBP03", "Unrecognized SymmetricBlockPadding"); + logger.Error("Unrecognized SymmetricBlockPadding"); return SymmetricBlockPadding.NOPADDING; } switch (symmetricBlockPadding.ToUpper(System.Globalization.CultureInfo.InvariantCulture).Trim()) @@ -57,6 +61,7 @@ public static SymmetricBlockPadding getSymmetricBlockPadding(string symmetricBlo return SymmetricBlockPadding.WITHCTS; default: error.setError("SBP01", "Unrecognized SymmetricBlockPadding"); + logger.Error("Unrecognized SymmetricBlockPadding"); return SymmetricBlockPadding.NOPADDING; } } @@ -68,6 +73,7 @@ public static SymmetricBlockPadding getSymmetricBlockPadding(string symmetricBlo /// string name value of SymmetricBlockPadding public static string valueOf(SymmetricBlockPadding symmetricBlockPadding, Error error) { + logger.Debug("valueOf"); if (error == null) return "Unrecognized block padding"; switch (symmetricBlockPadding) { @@ -86,7 +92,8 @@ public static string valueOf(SymmetricBlockPadding symmetricBlockPadding, Error case SymmetricBlockPadding.WITHCTS: return "WITHCTS"; default: - error.setError("SBP02", "Unrecognized SymmetricBlockPadding"); + error.setError("SBP02", ?"Unrecognized SymmetricBlockPadding"); + logger.Error("Unrecognized SymmetricBlockPadding"); return "Unrecognized block padding"; } } diff --git a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusCryptography/SymmetricUtils/SymmetricStreamAlgorithm.cs b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusCryptography/SymmetricUtils/SymmetricStreamAlgorithm.cs index 72289d62a..762330a0b 100644 --- a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusCryptography/SymmetricUtils/SymmetricStreamAlgorithm.cs +++ b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusCryptography/SymmetricUtils/SymmetricStreamAlgorithm.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.Linq; using System.Security; +using log4net; namespace GeneXusCryptography.SymmetricUtils @@ -25,6 +26,7 @@ public enum SymmetricStreamAlgorithm [SecuritySafeCritical] public static class SymmetricStreamAlgorithmUtils { + private static readonly ILog logger = LogManager.GetLogger(typeof(SymmetricStreamAlgorithmUtils)); /// /// Mapping between String name and SymmetricStreamAlgorithm enum representation /// @@ -33,10 +35,12 @@ public static class SymmetricStreamAlgorithmUtils /// SymmetricStreamAlgorithm enum representation public static SymmetricStreamAlgorithm getSymmetricStreamAlgorithm(String symmetricStreamAlgorithm, Error error) { + logger.Debug("getSymmetricStreamAlgorithm"); if (error == null) return SymmetricStreamAlgorithm.NONE; if (symmetricStreamAlgorithm == null) { error.setError("SSA05", "Unrecognized SymmetricStreamAlgorithm"); + logger.Error("Unrecognized SymmetricStreamAlgorithm"); return SymmetricStreamAlgorithm.NONE; } @@ -56,6 +60,7 @@ public static SymmetricStreamAlgorithm getSymmetricStreamAlgorithm(String symmet return SymmetricStreamAlgorithm.ISAAC; default: error.setError("SSA01", "Unrecognized SymmetricStreamAlgorithm"); + logger.Error("Unrecognized SymmetricStreamAlgorithm"); return SymmetricStreamAlgorithm.NONE; } } @@ -67,6 +72,7 @@ public static SymmetricStreamAlgorithm getSymmetricStreamAlgorithm(String symmet /// String SymmetrcStreamAlgorithm name value public static String valueOf(SymmetricStreamAlgorithm symmetrcStreamAlgorithm, Error error) { + logger.Debug("valueOf"); if (error == null) return "Unrecognized algorithm"; switch (symmetrcStreamAlgorithm) { @@ -84,6 +90,7 @@ public static String valueOf(SymmetricStreamAlgorithm symmetrcStreamAlgorithm, E return "ISAAC"; default: error.setError("SSA02", "Unrecognized SymmetricStreamAlgorithm"); + logger.Error("Unrecognized SymmetricStreamAlgorithm"); return "Unrecognized algorithm"; } } @@ -96,6 +103,7 @@ public static String valueOf(SymmetricStreamAlgorithm symmetrcStreamAlgorithm, E /// array int with fixed length 3 with key, if array[0]=0 is range, else fixed values public static int[] getKeySize(SymmetricStreamAlgorithm algorithm, Error error) { + logger.Debug("getKeySize"); if (error == null) return null; int[] keySize = new int[3]; switch (algorithm) @@ -123,6 +131,7 @@ public static int[] getKeySize(SymmetricStreamAlgorithm algorithm, Error error) break; default: error.setError("SSA03", "Unrecognized SymmetricStreamAlgorithm"); + logger.Error("Unrecognized SymmetricStreamAlgorithm"); break; } return keySize; @@ -137,6 +146,7 @@ public static int[] getKeySize(SymmetricStreamAlgorithm algorithm, Error error) /// true if the algorithm uses an IV or nonce, false if it do not internal static bool usesIV(SymmetricStreamAlgorithm algorithm, Error error) { + logger.Debug("usesIV"); switch (algorithm) { case SymmetricStreamAlgorithm.RC4: @@ -148,7 +158,8 @@ internal static bool usesIV(SymmetricStreamAlgorithm algorithm, Error error) case SymmetricStreamAlgorithm.XSALSA20: return true; default: - error.setError("SSA04", "Unrecognized SymmetricStreamAlgorithm"); + error.setError("SSA04", ?"Unrecognized SymmetricStreamAlgorithm"); + logger.Error("Unrecognized SymmetricStreamAlgorithm"); return true; } diff --git a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusFtps/GeneXusFtps.csproj b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusFtps/GeneXusFtps.csproj index 6265ea2ec..665991d04 100644 --- a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusFtps/GeneXusFtps.csproj +++ b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusFtps/GeneXusFtps.csproj @@ -7,7 +7,8 @@ GeneXus.SecurityApi.Ftps - + + diff --git a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusFtps/GeneXusFtps/FtpsClient.cs b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusFtps/GeneXusFtps/FtpsClient.cs index daa9b0d81..f76aceccb 100644 --- a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusFtps/GeneXusFtps/FtpsClient.cs +++ b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusFtps/GeneXusFtps/FtpsClient.cs @@ -1,6 +1,7 @@ using FluentFTP; using GeneXusFtps.GeneXusCommons; using GeneXusFtps.GeneXusFtpsUtils; +using log4net; using SecurityAPICommons.Utils; using System; using System.IO; @@ -16,7 +17,9 @@ namespace GeneXusFtps.GeneXusFtps [SecuritySafeCritical] public sealed class FtpsClient : IFtpsClientObject, IDisposable { - private FtpClient client; + private static readonly ILog logger = LogManager.GetLogger(typeof(FtpsClient)); + + private FtpClient client; private string pwd; private ExtensionsWhiteList whiteList; @@ -31,9 +34,11 @@ public FtpsClient() : base() [SecuritySafeCritical] public override bool Connect(FtpsOptions options) { - if(options == null) + logger.Debug("Connect"); + if (options == null) { this.error.setError("FS000", "Options parameter is null"); + logger.Error("Options parameter is null"); return false; } if (options.HasError()) @@ -45,6 +50,7 @@ public override bool Connect(FtpsOptions options) || SecurityUtils.compareStrings("", options.Password)) { this.error.setError("FS001", "Empty connection data"); + logger.Error("Empty connection data"); return false; } @@ -96,18 +102,21 @@ public override bool Connect(FtpsOptions options) { this.client.Disconnect(); this.error.setError("FS008", "Connection error"); + logger.Error("Connection error"); return false; } } catch (Exception e) { - this.error.setError("FS002", "Connection error " + e.Message); + this.error.setError("FS002", String.Format("Connection error {0}", e.Message)); + logger.Error("Connect", e); this.client = null; return false; } if (!this.client.IsConnected) { this.error.setError("FS009", "Connection error"); + logger.Error("Connection error"); return false; } this.whiteList = options.WhiteList; @@ -117,22 +126,26 @@ public override bool Connect(FtpsOptions options) [SecuritySafeCritical] public override bool Put(string localPath, string remoteDir) { + logger.Debug("Put"); if (this.whiteList != null) { if (!this.whiteList.IsValid(localPath)) { this.error.setError("WL001", "Invalid file extension"); + logger.Error("Invalid file extension"); return false; } } if(remoteDir == null) { this.error.setError("FS000", "RemoteDir parameter is null"); + logger.Error("RemoteDir parameter is null"); return false; } if (this.client == null || !this.client.IsConnected) { this.error.setError("FS003", "The connection is invalid, reconect"); + logger.Error("The connection is invalid, reconect"); return false; } try @@ -146,7 +159,8 @@ public override bool Put(string localPath, string remoteDir) } catch (Exception e) { - this.error.setError("FS013", "Error changing directory " + e.Message); + this.error.setError("FS013", String.Format("Error changing directory {0}", e.Message)); + logger.Error("Put", e); return false; } bool isStored = false; @@ -160,13 +174,15 @@ public override bool Put(string localPath, string remoteDir) if (!isStored) { - this.error.setError("FS012", " Reply String: " + this.client.LastReply.ErrorMessage); + this.error.setError("FS012", String.Format(" Reply String: {0} ", this.client.LastReply.ErrorMessage)); + logger.Error(String.Format(" Reply String: {0} ", this.client.LastReply.ErrorMessage)); } } catch (Exception e1) { - this.error.setError("FS004", "Erorr uploading file to server " + e1.Message); + this.error.setError("FS004", String.Format("Erorr uploading file to server {0}", e1.Message)); + logger.Error("Put", e1); return false; } return isStored; @@ -175,22 +191,26 @@ public override bool Put(string localPath, string remoteDir) [SecuritySafeCritical] public override bool Get(string remoteFilePath, string localDir) { + logger.Debug("Get"); if (this.whiteList != null) { if (!this.whiteList.IsValid(remoteFilePath)) { this.error.setError("WL002", "Invalid file extension"); + logger.Error("Invalid file extension"); return false; } } if(localDir == null) { this.error.setError("FS000", "LocalDir parameter is null"); + logger.Error("LocalDir parameter is null"); return false; } if (this.client == null || !this.client.IsConnected) { this.error.setError("FS010", "The connection is invalid, reconect"); + logger.Error("The connection is invalid, reconect"); return false; } try @@ -204,7 +224,8 @@ public override bool Get(string remoteFilePath, string localDir) } catch (Exception e) { - this.error.setError("FS013", "Error changing directory " + e.Message); + this.error.setError("FS013", String.Format("Error changing directory {0}", e.Message)); + logger.Error("Get", e); return false; } @@ -218,7 +239,8 @@ public override bool Get(string remoteFilePath, string localDir) } catch (Exception e1) { - this.error.setError("FS005", "Error retrieving file " + e1.Message); + this.error.setError("FS005", String.Format("Error retrieving file {0}", e1.Message)); + logger.Error("Get", e1); fileStream.Close(); return false; } @@ -226,6 +248,7 @@ public override bool Get(string remoteFilePath, string localDir) if (fileStream == null || !isDownloaded) { this.error.setError("FS007", "Could not retrieve file"); + logger.Error("Could not retrieve file"); return false; } } @@ -235,9 +258,11 @@ public override bool Get(string remoteFilePath, string localDir) [SecuritySafeCritical] public override bool Rm(string remoteFilePath) { + logger.Debug("Rm"); if (this.client == null || !this.client.IsConnected) { this.error.setError("FS019", "The connection is invalid, reconect"); + logger.Error("The connection is invalid, reconect"); return false; } try @@ -251,7 +276,8 @@ public override bool Rm(string remoteFilePath) } catch (Exception e) { - this.error.setError("FS020", "Error changing directory " + e.Message); + this.error.setError("FS020", String.Format("Error changing directory {0}", e.Message)); + logger.Error("Rm", e); return false; } @@ -262,7 +288,8 @@ public override bool Rm(string remoteFilePath) } catch (Exception e1) { - this.error.setError("FS021", "Error retrieving file " + e1.Message); + this.error.setError("FS021", String.Format("Error retrieving file {0}", e1.Message)); + logger.Error("Rm", e1); return false; } @@ -273,6 +300,7 @@ public override bool Rm(string remoteFilePath) [SecuritySafeCritical] public override void Disconnect() { + logger.Debug("Disconnect"); try { this.client.Disconnect(); @@ -285,9 +313,11 @@ public override void Disconnect() [SecuritySafeCritical] public override string GetWorkingDirectory() { + logger.Debug("GetWorkingDirectory"); if (this.client == null || !this.client.IsConnected) { this.error.setError("FS007", "The connection is invalid, reconect"); + logger.Error("The connection is invalid, reconect"); return ""; } String pwd = ""; @@ -298,6 +328,7 @@ public override string GetWorkingDirectory() catch (IOException) { this.error.setError("FS006", "Could not obtain working directory, try reconnect"); + logger.Error("Could not obtain working directory, try reconnect"); return ""; } if (pwd == null) @@ -353,6 +384,7 @@ private FtpDataType SetEncoding(FtpsOptions options) private SslProtocols SetProtocol(FtpsOptions options) { + logger.Debug("SetProtocol"); #pragma warning disable SYSLIB0039 // Type or member is obsolete #pragma warning disable CA5397 // Do not use deprecated SslProtocols values switch (options.GetFtpsProtocol()) @@ -365,10 +397,12 @@ private SslProtocols SetProtocol(FtpsOptions options) return SslProtocols.Tls12; case FtpsProtocol.SSLv2: this.error.setError("FS0014", "Deprecated protocol, not implemented for .Net"); + logger.Error("Deprecated protocol, not implemented for .Net"); return SslProtocols.None; case FtpsProtocol.SSLv3: this.error.setError("FS0015", "Deprecated protocol, not implemented for .Net"); - return SslProtocols.None; + logger.Error("Deprecated protocol, not implemented for .Net"); + return SslProtocols.None; default: return SslProtocols.Tls; } diff --git a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusFtps/GeneXusFtps/FtpsOptions.cs b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusFtps/GeneXusFtps/FtpsOptions.cs index d2c45fdc6..2357052d6 100644 --- a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusFtps/GeneXusFtps/FtpsOptions.cs +++ b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusFtps/GeneXusFtps/FtpsOptions.cs @@ -1,4 +1,5 @@ -using GeneXusFtps.GeneXusFtpsUtils; +using GeneXusFtps.GeneXusFtpsUtils; +using log4net; using SecurityAPICommons.Commons; using SecurityAPICommons.Utils; using System; @@ -9,6 +10,9 @@ namespace GeneXusFtps.GeneXusFtps [SecuritySafeCritical] public class FtpsOptions : SecurityAPIObject { + + private static readonly ILog logger = LogManager.GetLogger(typeof(FtpsOptions)); + private string _host; public string Host { @@ -108,6 +112,7 @@ public void SetTrustStorePath(String value) || SecurityUtils.extensionIs(value, ".jks") || SecurityUtils.extensionIs(value, ".crt"))) { error.setError("FO001", "Unexpected extension for trust store); valid extensions: .p12 .jks .pfx"); + logger.Error("Unexpected extension for trust store); valid extensions: .p12 .jks .pfx"); } else { diff --git a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusFtps/GeneXusFtpsUtils/FtpConnectionMode.cs b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusFtps/GeneXusFtpsUtils/FtpConnectionMode.cs index a981a8b34..38ade0a9e 100644 --- a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusFtps/GeneXusFtpsUtils/FtpConnectionMode.cs +++ b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusFtps/GeneXusFtpsUtils/FtpConnectionMode.cs @@ -1,3 +1,4 @@ +using log4net; using SecurityAPICommons.Commons; using System; using System.Security; @@ -13,13 +14,17 @@ public enum FtpConnectionMode [SecuritySafeCritical] public static class FtpConnectionModeUtils { + private static readonly ILog logger = LogManager.GetLogger(typeof(FtpConnectionModeUtils)); + [SecuritySafeCritical] - public static FtpConnectionMode getFtpMode(String ftpMode, Error error) + public static FtpConnectionMode getFtpMode(string ftpMode, Error error) { - if(error == null) return FtpConnectionMode.NONE; + logger.Debug("getFtpMode"); + if (error == null) return FtpConnectionMode.NONE; if (ftpMode == null) { error.setError("FM001", "Unrecognized FtpMode"); + logger.Error("Unrecognized FtpMode"); return FtpConnectionMode.NONE; } switch (ftpMode.ToUpper(System.Globalization.CultureInfo.InvariantCulture).Trim()) @@ -30,13 +35,15 @@ public static FtpConnectionMode getFtpMode(String ftpMode, Error error) return FtpConnectionMode.PASSIVE; default: error.setError("FM001", "Unrecognized FtpMode"); + logger.Error("Unrecognized FtpMode"); return FtpConnectionMode.NONE; } } [SecuritySafeCritical] - public static String valueOf(FtpConnectionMode ftpMode, Error error) + public static string valueOf(FtpConnectionMode ftpMode, Error error) { + logger.Debug("valueOf"); if (error == null) return ""; switch (ftpMode) { @@ -46,6 +53,7 @@ public static String valueOf(FtpConnectionMode ftpMode, Error error) return "PASSIVE"; default: error.setError("FM002", "Unrecognized FtpMode"); + logger.Error("Unrecognized FtpMode"); return ""; } } diff --git a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusFtps/GeneXusFtpsUtils/FtpEncoding.cs b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusFtps/GeneXusFtpsUtils/FtpEncoding.cs index b6fc800cd..987a2dd77 100644 --- a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusFtps/GeneXusFtpsUtils/FtpEncoding.cs +++ b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusFtps/GeneXusFtpsUtils/FtpEncoding.cs @@ -1,3 +1,4 @@ +using log4net; using SecurityAPICommons.Commons; using System; using System.Security; @@ -13,13 +14,17 @@ public enum FtpEncoding [SecuritySafeCritical] public static class FtpEncodingUtils { + private static readonly ILog logger = LogManager.GetLogger(typeof(FtpEncodingUtils)); + [SecuritySafeCritical] - public static FtpEncoding getFtpEncoding(String ftpEncoding, Error error) + public static FtpEncoding getFtpEncoding(string ftpEncoding, Error error) { + logger.Debug("getFtpEncoding"); if(error == null) return FtpEncoding.NONE; if (ftpEncoding == null) { error.setError("FE001", "Unknown encoding"); + logger.Error("Unknown encoding"); return FtpEncoding.NONE; } switch (ftpEncoding.ToUpper(System.Globalization.CultureInfo.InvariantCulture).Trim()) @@ -30,13 +35,15 @@ public static FtpEncoding getFtpEncoding(String ftpEncoding, Error error) return FtpEncoding.ASCII; default: error.setError("FE001", "Unknown encoding"); + logger.Error("Unknown encoding"); return FtpEncoding.NONE; } } [SecuritySafeCritical] - public static String valueOf(FtpEncoding ftpEncoding, Error error) + public static string valueOf(FtpEncoding ftpEncoding, Error error) { + logger.Debug("valueOf"); if (error == null) return ""; switch (ftpEncoding) { @@ -46,6 +53,7 @@ public static String valueOf(FtpEncoding ftpEncoding, Error error) return "ASCII"; default: error.setError("FE002", "Unknown encoding"); + logger.Error("Unknown encoding"); return ""; } } diff --git a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusFtps/GeneXusFtpsUtils/FtpEncryptionMode.cs b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusFtps/GeneXusFtpsUtils/FtpEncryptionMode.cs index 700fbc55d..dcb778d9e 100644 --- a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusFtps/GeneXusFtpsUtils/FtpEncryptionMode.cs +++ b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusFtps/GeneXusFtpsUtils/FtpEncryptionMode.cs @@ -1,3 +1,4 @@ +using log4net; using SecurityAPICommons.Commons; using System; using System.Security; @@ -13,13 +14,17 @@ public enum FtpEncryptionMode [SecuritySafeCritical] public static class FtpEncryptionModeUtils { + private static readonly ILog logger = LogManager.GetLogger(typeof(FtpEncryptionModeUtils)); + [SecuritySafeCritical] - public static FtpEncryptionMode getFtpEncryptionMode(String ftpEncryptionMode, Error error) + public static FtpEncryptionMode getFtpEncryptionMode(string ftpEncryptionMode, Error error) { - if(error == null) return FtpEncryptionMode.NONE; + logger.Debug("getFtpEncryptionMode"); + if (error == null) return FtpEncryptionMode.NONE; if (ftpEncryptionMode == null) { error.setError("EM001", "Unknown encryption mode"); + logger.Error("Unknown encryption mode"); return FtpEncryptionMode.NONE; } switch (ftpEncryptionMode.ToUpper(System.Globalization.CultureInfo.InvariantCulture).Trim()) @@ -30,13 +35,15 @@ public static FtpEncryptionMode getFtpEncryptionMode(String ftpEncryptionMode, E return FtpEncryptionMode.EXPLICIT; default: error.setError("EM001", "Unknown encryption mode"); + logger.Error("Unknown encryption mode"); return FtpEncryptionMode.NONE; } } [SecuritySafeCritical] - public static String valueOf(FtpEncryptionMode ftpEncryptionMode, Error error) + public static string valueOf(FtpEncryptionMode ftpEncryptionMode, Error error) { + logger.Debug("valueOf"); if (error == null) return ""; switch (ftpEncryptionMode) { @@ -46,6 +53,7 @@ public static String valueOf(FtpEncryptionMode ftpEncryptionMode, Error error) return "EXPLICIT"; default: error.setError("EM002", "Unknown encryption mode"); + logger.Error("Unknown encryption mode"); return ""; } } diff --git a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusFtps/GeneXusFtpsUtils/FtpsProtocol.cs b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusFtps/GeneXusFtpsUtils/FtpsProtocol.cs index 969b35f38..0d4365702 100644 --- a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusFtps/GeneXusFtpsUtils/FtpsProtocol.cs +++ b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusFtps/GeneXusFtpsUtils/FtpsProtocol.cs @@ -1,6 +1,7 @@ using SecurityAPICommons.Commons; using System; using System.Security; +using log4net; namespace GeneXusFtps.GeneXusFtpsUtils { @@ -16,14 +17,17 @@ public enum FtpsProtocol [SecuritySafeCritical] public static class FtpsProtocolUtils { + private static readonly ILog logger = LogManager.GetLogger(typeof(FtpsProtocolUtils)); [SecuritySafeCritical] - public static FtpsProtocol getFtpsProtocol(String ftpsProtocol, Error error) + public static FtpsProtocol getFtpsProtocol(string ftpsProtocol, Error error) { + logger.Debug("getFtpsProtocol"); if(error == null) return FtpsProtocol.NONE; if (ftpsProtocol == null) { error.setError("FP001", "Unknown protocol"); + logger.Error("Unknown protocol"); return FtpsProtocol.NONE; } switch (ftpsProtocol.Trim()) @@ -40,6 +44,7 @@ public static FtpsProtocol getFtpsProtocol(String ftpsProtocol, Error error) return FtpsProtocol.SSLv3; default: error.setError("FP001", "Unknown protocol"); + logger.Error("Unknown protocol"); return FtpsProtocol.NONE; } @@ -47,8 +52,9 @@ public static FtpsProtocol getFtpsProtocol(String ftpsProtocol, Error error) } [SecuritySafeCritical] - public static String valueOf(FtpsProtocol ftpsProtocol, Error error) + public static string valueOf(FtpsProtocol ftpsProtocol, Error error) { + logger.Debug("valueOf"); if (error == null) return ""; switch (ftpsProtocol) { @@ -64,6 +70,7 @@ public static String valueOf(FtpsProtocol ftpsProtocol, Error error) return "SSLv3"; default: error.setError("FP002", "Unknown protocol"); + logger.Error("Unknown protocol"); return ""; } } diff --git a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusJWT/GeneXusJWT.csproj b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusJWT/GeneXusJWT.csproj index 2cac667b1..2ed298bad 100644 --- a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusJWT/GeneXusJWT.csproj +++ b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusJWT/GeneXusJWT.csproj @@ -25,6 +25,7 @@ + \ No newline at end of file diff --git a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusJWT/JWT/JWTCreator.cs b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusJWT/JWT/JWTCreator.cs index aead850e9..6ed046f37 100644 --- a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusJWT/JWT/JWTCreator.cs +++ b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusJWT/JWT/JWTCreator.cs @@ -15,12 +15,15 @@ using Newtonsoft.Json.Linq; using Newtonsoft.Json; using GeneXusJWT.JWTClaims; +using log4net; namespace GeneXusJWT.GenexusJWT { [SecuritySafeCritical] public class JWTCreator : SecurityAPIObject, IJWTObject { + private static readonly ILog logger = LogManager.GetLogger(typeof(JWTCreator)); + private int counter; @@ -41,6 +44,7 @@ public JWTCreator() : base() [SecuritySafeCritical] public string DoCreate(string algorithm, PrivateClaims privateClaims, JWTOptions options) { + logger.Debug("DoCreate"); this.error.cleanError(); return Create_Aux(algorithm, privateClaims, options, null, true); } @@ -48,6 +52,7 @@ public string DoCreate(string algorithm, PrivateClaims privateClaims, JWTOptions [SecuritySafeCritical] public string DoCreateFromJSON(string algorithm, string json, JWTOptions options) { + logger.Debug("DoCreateFromJSON"); this.error.cleanError(); return Create_Aux(algorithm, null, options, json, false); } @@ -55,6 +60,7 @@ public string DoCreateFromJSON(string algorithm, string json, JWTOptions options [SecuritySafeCritical] public bool DoVerify(String token, String expectedAlgorithm, PrivateClaims privateClaims, JWTOptions options) { + logger.Debug("DoVerify"); this.error.cleanError(); return DoVerify(token, expectedAlgorithm, privateClaims, options, true, true); } @@ -62,6 +68,7 @@ public bool DoVerify(String token, String expectedAlgorithm, PrivateClaims priva [SecuritySafeCritical] public bool DoVerifyJustSignature(String token, String expectedAlgorithm, JWTOptions options) { + logger.Debug("DoVerifyJustSignature"); this.error.cleanError(); return DoVerify(token, expectedAlgorithm, null, options, false, false); } @@ -69,6 +76,7 @@ public bool DoVerifyJustSignature(String token, String expectedAlgorithm, JWTOpt [SecuritySafeCritical] public bool DoVerifySignature(String token, String expectedAlgorithm, JWTOptions options) { + logger.Debug("DoVerifySignature"); this.error.cleanError(); return DoVerify(token, expectedAlgorithm, null, options, false, true); } @@ -76,6 +84,7 @@ public bool DoVerifySignature(String token, String expectedAlgorithm, JWTOptions [SecuritySafeCritical] public string GetPayload(string token) { + logger.Debug("GetPayload"); this.error.cleanError(); string res = ""; try @@ -85,6 +94,7 @@ public string GetPayload(string token) catch (Exception e) { this.error.setError("JW001", e.Message); + logger.Error("GetPayload", e); return ""; } return res; @@ -94,6 +104,7 @@ public string GetPayload(string token) [SecuritySafeCritical] public string GetHeader(string token) { + logger.Debug("GetHeader"); this.error.cleanError(); string res = ""; try @@ -103,6 +114,7 @@ public string GetHeader(string token) catch (Exception e) { this.error.setError("JW002", e.Message); + logger.Error("GetHeader", e); return ""; } return res; @@ -111,6 +123,7 @@ public string GetHeader(string token) [SecuritySafeCritical] public string GetTokenID(string token) { + logger.Debug("GetTokenID"); this.error.cleanError(); string res = ""; try @@ -121,6 +134,7 @@ public string GetTokenID(string token) catch (Exception e) { this.error.setError("JW003", e.Message); + logger.Error("GetTokenID", e); return ""; } return res; @@ -132,9 +146,11 @@ public string GetTokenID(string token) [SecuritySafeCritical] private string Create_Aux(string algorithm, PrivateClaims privateClaims, JWTOptions options, string payloadString, bool hasClaims) { + logger.Debug("Create_Aux"); if (options == null) { this.error.setError("JW004", "Options parameter is null"); + logger.Error("Options parameter is null"); return ""; } JWTAlgorithm alg = JWTAlgorithmUtils.getJWTAlgorithm(algorithm, this.error); @@ -159,6 +175,7 @@ private string Create_Aux(string algorithm, PrivateClaims privateClaims, JWTOpti if (privateClaims == null) { this.error.setError("JW005", "PrivateClaims parameter is null"); + logger.Error("PrivateClaims parameter is null"); return ""; } payload = doBuildPayload(privateClaims, options); @@ -172,6 +189,7 @@ private string Create_Aux(string algorithm, PrivateClaims privateClaims, JWTOpti catch (Exception ex) { this.error.setError("", ex.Message); + logger.Error("Create_Aux", ex); return ""; } } @@ -204,6 +222,7 @@ private string Create_Aux(string algorithm, PrivateClaims privateClaims, JWTOpti break; default: this.error.setError("JW019", "Not recognized key algorithm"); + logger.Error("Not recognized key algorithm"); return ""; } }catch(Exception e) @@ -217,6 +236,7 @@ private string Create_Aux(string algorithm, PrivateClaims privateClaims, JWTOpti if(options.getSecret() == null) { this.error.setError("JW021", "Set the secret using JWTOptions.SetSecret function"); + logger.Error("Set the secret using JWTOptions.SetSecret function"); return ""; } SymmetricSecurityKey symKey = new SymmetricSecurityKey(options.getSecret()); @@ -248,6 +268,7 @@ private string Create_Aux(string algorithm, PrivateClaims privateClaims, JWTOpti { this.error.setError("JW006", e.Message); + logger.Error("Create_Aux", e); return ""; } @@ -258,9 +279,11 @@ private string Create_Aux(string algorithm, PrivateClaims privateClaims, JWTOpti [SecuritySafeCritical] private bool DoVerify(string token, string expectedAlgorithm, PrivateClaims privateClaims, JWTOptions options, bool verifyClaims, bool verifyRegClaims) { + logger.Debug("DoVerify"); if (options == null) { this.error.setError("JW007", "Options parameter is null"); + logger.Error("Options parameter is null"); return false; } JWTAlgorithm expectedJWTAlgorithm = JWTAlgorithmUtils.getJWTAlgorithm(expectedAlgorithm, this.error); @@ -322,6 +345,7 @@ private bool DoVerify(string token, string expectedAlgorithm, PrivateClaims priv if (JWTAlgorithmUtils.getJWTAlgorithm(jwtToken.Header.Alg, this.error) != expectedJWTAlgorithm || this.HasError()) { this.error.setError("JW009", "Expected algorithm does not match token algorithm"); + logger.Error("Expected algorithm does not match token algorithm"); return false; } SecurityKey genericKey = null; @@ -331,6 +355,7 @@ private bool DoVerify(string token, string expectedAlgorithm, PrivateClaims priv if(cert == null) { this.error.setError("JW022", "Public key or certificate not loaded for verification"); + logger.Error("Public key or certificate not loaded for verification"); return false; } if (cert.HasError()) @@ -350,6 +375,7 @@ private bool DoVerify(string token, string expectedAlgorithm, PrivateClaims priv break; default: this.error.setError("JW019", "Not recognized key algorithm"); + logger.Error("Not recognized key algorithm"); return false; } }catch(Exception e) @@ -363,6 +389,7 @@ private bool DoVerify(string token, string expectedAlgorithm, PrivateClaims priv if(options.getSecret() == null) { this.error.setError("JW022", "Symmetric key not loaded for verification"); + logger.Error("Symmetric key not loaded for verification"); return false; } SymmetricSecurityKey symKey = new SymmetricSecurityKey(options.getSecret()); @@ -380,6 +407,7 @@ private bool DoVerify(string token, string expectedAlgorithm, PrivateClaims priv catch (Exception e) { this.error.setError("JW008", e.Message); + logger.Error("DoVerify", e); return false; } @@ -392,6 +420,7 @@ private bool DoVerify(string token, string expectedAlgorithm, PrivateClaims priv private JwtPayload doBuildPayload(PrivateClaims privateClaims, JWTOptions options) { + logger.Debug("doBuildPayload"); JwtPayload payload = new JwtPayload(); // ****START BUILD PAYLOAD****// // Adding private claims @@ -435,6 +464,7 @@ private JwtPayload doBuildPayload(PrivateClaims privateClaims, JWTOptions option else { this.error.setError("JW014", "Unrecognized data type"); + logger.Error("Unrecognized data type"); } //System.Security.Claims.Claim netPrivateClaim = new System.Security.Claims.Claim(privateClaim.getKey(), privateClaim.getValue()); @@ -485,7 +515,7 @@ private JwtPayload doBuildPayload(PrivateClaims privateClaims, JWTOptions option private bool validateRegisteredClaims(JwtSecurityToken jwtToken, JWTOptions options) { - + logger.Debug("validateRegisteredClaims"); // Adding registered claims if (options.hasRegisteredClaims()) { @@ -523,6 +553,7 @@ private bool validateRegisteredClaims(JwtSecurityToken jwtToken, JWTOptions opti else { error.setError("JW017", String.Format("{0} wrong registered claim key", registeredClaimKey)); + logger.Error(String.Format("{0} wrong registered claim key", registeredClaimKey)); return false; } } @@ -535,8 +566,9 @@ private static bool isRevoqued(JwtSecurityToken jwtToken, JWTOptions options) return rList.isInRevocationList(jwtToken.Payload.Jti); } - private String getTokenPart(string token, String part) + private string getTokenPart(string token, String part) { + logger.Debug("getTokenPart"); JwtSecurityToken jwtToken = new JwtSecurityToken(token); switch (part) @@ -549,6 +581,7 @@ private String getTokenPart(string token, String part) return jwtToken.Payload.Jti; default: error.setError("JW012", "Unknown token segment"); + logger.Error("Unknown token segment"); return ""; } @@ -556,6 +589,7 @@ private String getTokenPart(string token, String part) private bool verifyPrivateClaims(JwtSecurityToken jwtToken, PrivateClaims privateClaims, JWTOptions options) { + logger.Debug("verifyPrivateClaims"); RegisteredClaims registeredClaims = options.getAllRegisteredClaims(); PublicClaims publicClaims = options.getAllPublicClaims(); if (privateClaims == null || privateClaims.isEmpty()) @@ -571,6 +605,7 @@ private bool verifyPrivateClaims(JwtSecurityToken jwtToken, PrivateClaims privat catch (Exception e) { this.error.setError("JW018", e.Message); + logger.Error("verifyPrivateClaims", e); return false; } this.counter = 0; @@ -586,13 +621,14 @@ private bool verifyPrivateClaims(JwtSecurityToken jwtToken, PrivateClaims privat private bool verifyNestedClaims(Dictionary pclaimMap, Dictionary map, RegisteredClaims registeredClaims, PublicClaims publicClaims) { + logger.Debug("verifyNestedClaims"); List mapClaimKeyList = new List(map.Keys); List pClaimKeyList = new List(pclaimMap.Keys); if (pClaimKeyList.Count > pClaimKeyList.Count) { return false; } - foreach (String mapKey in mapClaimKeyList) + foreach (string mapKey in mapClaimKeyList) { if (!isRegistered(mapKey, registeredClaims) && !isPublic(mapKey, publicClaims)) @@ -656,6 +692,7 @@ private bool verifyNestedClaims(Dictionary pclaimMap, Dictionary private void AddHeaderParameters(JwtHeader header, JWTOptions options) { + logger.Debug("AddHeaderParameters"); HeaderParameters parameters = options.GetHeaderParameters(); List list = parameters.GetAll(); Dictionary map = parameters.GetMap(); @@ -667,6 +704,7 @@ private void AddHeaderParameters(JwtHeader header, JWTOptions options) private static bool VerifyHeader(JwtSecurityToken jwtToken, JWTOptions options) { + logger.Debug("VerifyHeader"); int claimsNumber = jwtToken.Header.Count; HeaderParameters parameters = options.GetHeaderParameters(); if (parameters.IsEmpty() && claimsNumber == 2) @@ -678,12 +716,12 @@ private static bool VerifyHeader(JwtSecurityToken jwtToken, JWTOptions options) return false; } - List allParms = parameters.GetAll(); + List allParms = parameters.GetAll(); if (claimsNumber != allParms.Count + 2) { return false; } - Dictionary map = parameters.GetMap(); + Dictionary map = parameters.GetMap(); foreach (string s in allParms) @@ -704,7 +742,7 @@ private static bool VerifyHeader(JwtSecurityToken jwtToken, JWTOptions options) { return false; } - String optionsValue = ((string)map[s]).Trim(); + string optionsValue = ((string)map[s]).Trim(); if (!SecurityUtils.compareStrings(claimValue, optionsValue.Trim())) { return false; diff --git a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusJWT/JWTClaims/RegisteredClaim.cs b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusJWT/JWTClaims/RegisteredClaim.cs index 45ed4455f..b2d613a02 100644 --- a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusJWT/JWTClaims/RegisteredClaim.cs +++ b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusJWT/JWTClaims/RegisteredClaim.cs @@ -5,6 +5,7 @@ using System.Security; using SecurityAPICommons.Commons; using SecurityAPICommons.Utils; +using log4net; namespace GeneXusJWT.GenexusJWTClaims { @@ -17,8 +18,11 @@ public enum RegisteredClaim [SecuritySafeCritical] public static class RegisteredClaimUtils { - public static string valueOf(RegisteredClaim registeredClaim, Error error) + + private static readonly ILog logger = LogManager.GetLogger(typeof(RegisteredClaimUtils)); + public static string valueOf(RegisteredClaim registeredClaim, Error error) { + logger.Debug("valueOf"); if(error == null) return "Unknown registered claim"; switch (registeredClaim) { @@ -38,6 +42,7 @@ public static string valueOf(RegisteredClaim registeredClaim, Error error) return "jti"; default: error.setError("RC001", "Unknown registered Claim"); + logger.Error("Unknown registered claim"); return "Unknown registered claim"; } @@ -45,10 +50,12 @@ public static string valueOf(RegisteredClaim registeredClaim, Error error) public static RegisteredClaim getRegisteredClaim(string registeredClaim, Error error) { + logger.Debug("getRegisteredClaim"); if(error == null) return RegisteredClaim.NONE; if (registeredClaim == null) { error.setError("RCL01", "Unknown registered Claim"); + logger.Error("Unknown registered claim"); return RegisteredClaim.NONE; } switch (registeredClaim.Trim()) @@ -69,7 +76,8 @@ public static RegisteredClaim getRegisteredClaim(string registeredClaim, Error e return RegisteredClaim.jti; default: error.setError("RCL02", "Unknown registered Claim"); - return RegisteredClaim.NONE; + logger.Error("Unknown registered claim"); + return RegisteredClaim.NONE; } } @@ -107,7 +115,7 @@ public static bool isTimeValidatingClaim(string claimKey) public static bool validateClaim(string registeredClaimKey, string registeredClaimValue, long registeredClaimCustomTime, JwtSecurityToken token, Error error) { - + logger.Debug("validateClaim"); if (error == null) return false; RegisteredClaim claim = RegisteredClaimUtils.getRegisteredClaim(registeredClaimKey, error); if (error.existsError()) @@ -118,6 +126,7 @@ public static bool validateClaim(string registeredClaimKey, string registeredCla if(token == null) { error.setError("RCL13", "Token parameter is null"); + logger.Error("Token parameter is null"); return false; } Int32 newTime = 0; @@ -173,7 +182,8 @@ public static bool validateClaim(string registeredClaimKey, string registeredCla return SecurityUtils.compareStrings(token.Payload.Jti, registeredClaimValue); default: error.setError("RCL03", "Unknown registered Claim"); - return false; + logger.Error("Unknown registered claim"); + return false; } } } diff --git a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusJWT/JWTClaims/RegisteredClaims.cs b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusJWT/JWTClaims/RegisteredClaims.cs index f1e3d9794..3906b53e6 100644 --- a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusJWT/JWTClaims/RegisteredClaims.cs +++ b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusJWT/JWTClaims/RegisteredClaims.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Globalization; using System.Security; +using log4net; using SecurityAPICommons.Commons; using SecurityAPICommons.Utils; @@ -12,7 +13,9 @@ public class RegisteredClaims : Claims { private IDictionary customTimeValidationClaims; - public RegisteredClaims() + private static readonly ILog logger = LogManager.GetLogger(typeof(RegisteredClaims)); + + public RegisteredClaims() { customTimeValidationClaims = new Dictionary(); @@ -22,6 +25,7 @@ public RegisteredClaims() public bool setClaim(string key, string value, Error error) { + logger.Debug("setClaim"); if (error == null) return false; if (RegisteredClaimUtils.exists(key)) { @@ -30,12 +34,15 @@ public bool setClaim(string key, string value, Error error) else { error.setError("RCS02", "Wrong registered key value"); - return false; + logger.Error("Wrong registered key value"); + + return false; } } public bool setTimeValidatingClaim(string key, string value, string customValidationSeconds, Error error) { + logger.Debug("setTimeValidatingClaim"); if (error == null) return false; if (RegisteredClaimUtils.exists(key) && RegisteredClaimUtils.isTimeValidatingClaim(key)) { @@ -49,6 +56,7 @@ public bool setTimeValidatingClaim(string key, string value, string customValida catch (Exception) { error.setError("RCS04", "Date format error; expected yyyy/MM/dd HH:mm:ss"); + logger.Error("Date format error; expected yyyy/MM/dd HH:mm:ss"); return false; } return setClaim(key, date.ToString(CultureInfo.InvariantCulture), error); @@ -56,6 +64,7 @@ public bool setTimeValidatingClaim(string key, string value, string customValida else { error.setError("RCS02", "Wrong registered key value"); + logger.Error("Wrong registered key value"); return false; } } @@ -92,6 +101,7 @@ public bool hasCustomValidationClaims() public override object getClaimValue(string key, Error error) { + logger.Debug("getClaimValue"); if (error == null) return ""; if (RegisteredClaimUtils.exists(key)) { @@ -103,11 +113,13 @@ public override object getClaimValue(string key, Error error) } } error.setError("RCS03", String.Format("Could not find a claim with {0} key value", key)); + logger.Error(String.Format("Could not find a claim with {0} key value", key)); return ""; } else { error.setError("RC002", "Wrong registered key value"); + logger.Error("Wrong registered key value"); return ""; } } diff --git a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusJWT/Utils/JWTAlgorithm.cs b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusJWT/Utils/JWTAlgorithm.cs index 55b96c2e0..a1214e5a1 100644 --- a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusJWT/Utils/JWTAlgorithm.cs +++ b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusJWT/Utils/JWTAlgorithm.cs @@ -2,6 +2,7 @@ using Microsoft.IdentityModel.Tokens; using System; using System.Security; +using log4net; @@ -16,8 +17,10 @@ public enum JWTAlgorithm [SecuritySafeCritical] public static class JWTAlgorithmUtils { - public static string valueOf(JWTAlgorithm jWTAlgorithm, Error error) + private static readonly ILog logger = LogManager.GetLogger(typeof(JWTAlgorithmUtils)); + public static string valueOf(JWTAlgorithm jWTAlgorithm, Error error) { + logger.Debug("valueOf"); if(error == null) return "Unrecognized algorithm"; switch (jWTAlgorithm) { @@ -38,16 +41,19 @@ public static string valueOf(JWTAlgorithm jWTAlgorithm, Error error) default: error.setError("JWA01", "Unrecognized algorithm"); + logger.Error("Unrecognized algorithm"); return "Unrecognized algorithm"; } } public static JWTAlgorithm getJWTAlgorithm(string jWTAlgorithm, Error error) { + logger.Debug("getJWTAlgorithm"); if(error == null) return JWTAlgorithm.NONE; if (jWTAlgorithm == null) { error.setError("JWA02", "Unrecognized algorithm"); + logger.Error("Unrecognized algorithm"); return JWTAlgorithm.NONE; } switch (jWTAlgorithm.ToUpper(System.Globalization.CultureInfo.InvariantCulture).Trim()) @@ -69,7 +75,8 @@ public static JWTAlgorithm getJWTAlgorithm(string jWTAlgorithm, Error error) default: error.setError("JWA02", "Unrecognized algorithm"); - return JWTAlgorithm.NONE; + logger.Error("Unrecognized algorithm"); + return JWTAlgorithm.NONE; } } @@ -77,7 +84,8 @@ public static JWTAlgorithm getJWTAlgorithm(string jWTAlgorithm, Error error) public static JWTAlgorithm getJWTAlgorithm_forVerification(string jWTAlgorithm, Error error) #pragma warning restore CA1707 // Identifiers should not contain underscores { - if(error == null) return JWTAlgorithm.NONE; + logger.Debug("getJWTAlgorithm_forVerification"); + if (error == null) return JWTAlgorithm.NONE; switch (jWTAlgorithm) { case SecurityAlgorithms.RsaSha256: @@ -96,7 +104,8 @@ public static JWTAlgorithm getJWTAlgorithm_forVerification(string jWTAlgorithm, return JWTAlgorithm.ES512; default: error.setError("JWA05", "Unrecognized algorithm"); - return JWTAlgorithm.NONE; + logger.Error("Unrecognized algorithm"); + return JWTAlgorithm.NONE; } } @@ -119,6 +128,7 @@ public static bool isPrivate(JWTAlgorithm jWTAlgorithm) internal static SigningCredentials getSigningCredentials(JWTAlgorithm jWTAlgorithm, SecurityKey key, Error error) { + logger.Debug("getSigningCredentials"); switch (jWTAlgorithm) { case JWTAlgorithm.HS256: @@ -138,7 +148,8 @@ internal static SigningCredentials getSigningCredentials(JWTAlgorithm jWTAlgorit default: error.setError("JWA06", "Unrecognized algorithm"); - return null; + logger.Error("Unrecognized algorithm"); + return null; } } diff --git a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusJWT/Utils/UnixTimeStampCreator.cs b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusJWT/Utils/UnixTimeStampCreator.cs index e5adec932..2e672f916 100644 --- a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusJWT/Utils/UnixTimeStampCreator.cs +++ b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusJWT/Utils/UnixTimeStampCreator.cs @@ -2,18 +2,21 @@ using System.Globalization; using System.Security; using SecurityAPICommons.Commons; +using log4net; namespace GeneXusJWT.Utils { [SecuritySafeCritical] public class UnixTimeStampCreator: SecurityAPIObject { + private static readonly ILog logger = LogManager.GetLogger(typeof(UnixTimeStampCreator)); [SecuritySafeCritical] public UnixTimeStampCreator() : base() { } [SecuritySafeCritical] public string Create(string date) { + logger.Debug("Create"); long newdate; try { @@ -23,6 +26,7 @@ public string Create(string date) catch (Exception) { error.setError("UTS01", "Date format error; expected yyyy/MM/dd HH:mm:ss"); + logger.Error("Date format error; expected yyyy/MM/dd HH:mm:ss"); return ""; } return newdate.ToString(CultureInfo.InvariantCulture); diff --git a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusSftp/GeneXusSftp.csproj b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusSftp/GeneXusSftp.csproj index 7af257688..8af03a693 100644 --- a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusSftp/GeneXusSftp.csproj +++ b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusSftp/GeneXusSftp.csproj @@ -12,6 +12,7 @@ - + + \ No newline at end of file diff --git a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusSftp/Sftp/SftpClient.cs b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusSftp/Sftp/SftpClient.cs index 6e3db9e63..5094fbfb7 100644 --- a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusSftp/Sftp/SftpClient.cs +++ b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusSftp/Sftp/SftpClient.cs @@ -11,6 +11,7 @@ using System.Security; using System.Text; using System.Threading.Tasks; +using log4net; namespace Sftp.GeneXusSftp @@ -19,7 +20,9 @@ namespace Sftp.GeneXusSftp public sealed class SftpClient : ISftpClientObject, IDisposable { - private Renci.SshNet.SftpClient channel; + private static readonly ILog logger = LogManager.GetLogger(typeof(SftpClient)); + + private Renci.SshNet.SftpClient channel; private static KnownHostStore _knownHosts; private bool fingerprint; private ExtensionsWhiteList whiteList; @@ -40,9 +43,11 @@ public SftpClient() : base() [SecuritySafeCritical] public override bool Connect(SftpOptions options) { + logger.Debug("Connect"); if(options == null) { this.error.setError("SF000", "Options parameter is null"); + logger.Error("Options parameter is null"); return false; } if (options.HasError()) @@ -61,6 +66,7 @@ public override bool Connect(SftpOptions options) { this.error.setError("SF001", "Authentication misconfiguration. Missing user or password"); + logger.Error("Authentication misconfiguration. Missing user or password"); return false; } } @@ -68,6 +74,7 @@ public override bool Connect(SftpOptions options) if (SecurityUtils.compareStrings("", options.Host)) { this.error.setError("SF003", "Empty host"); + logger.Error("Empty host"); return false; } try @@ -90,6 +97,7 @@ public override bool Connect(SftpOptions options) catch (Exception e) { this.error.setError("SF004", e.Message); + logger.Error("Connect", e); return false; } @@ -100,24 +108,28 @@ public override bool Connect(SftpOptions options) } [SecuritySafeCritical] - public override bool Put(String localPath, String remoteDir) + public override bool Put(string localPath, string remoteDir) { + logger.Debug("Put"); if (this.whiteList != null) { if (!this.whiteList.IsValid(localPath)) { this.error.setError("WL001", "Invalid file extension"); + logger.Error("Invalid file extension"); return false; } } if (SecurityUtils.compareStrings("", localPath) || localPath == null || localPath.IndexOfAny(Path.GetInvalidPathChars()) >= 0) { this.error.setError("SF0012", "localPath cannot be empty"); + logger.Error("localPath cannot be empty"); return false; } if (remoteDir.IndexOfAny(Path.GetInvalidPathChars()) >= 0) { this.error.setError("SF015", "Invalid remoteDir"); + logger.Error("Invalid remoteDir"); return false; } string local_path = localPath; @@ -125,6 +137,7 @@ public override bool Put(String localPath, String remoteDir) if (this.channel == null || !this.channel.IsConnected) { this.error.setError("SF005", "The channel is invalid, reconect"); + logger.Error("The channel is invalid, reconect"); return false; } if (remoteDir.Length > 1) @@ -186,12 +199,14 @@ public override bool Put(String localPath, String remoteDir) catch (Exception s) { this.error.setError("SF012", s.Message); + logger.Error("Put", s); return false; } } else { this.error.setError("SF013", e.Message); + logger.Error("Put", e); return false; } @@ -205,36 +220,42 @@ public override bool Put(String localPath, String remoteDir) catch (Exception e) { this.error.setError("SF011", e.Message); + logger.Error("Put", e); return false; } } [SecuritySafeCritical] - public override bool Get(String remoteFilePath, String localDir) + public override bool Get(string remoteFilePath, string localDir) { + logger.Debug("Get"); if (this.whiteList != null) { if (!this.whiteList.IsValid(remoteFilePath)) { this.error.setError("WL002", "Invalid file extension"); + logger.Error("Invalid file extension"); return false; } } if (SecurityUtils.compareStrings("", remoteFilePath) || remoteFilePath == null || remoteFilePath.IndexOfAny(Path.GetInvalidPathChars()) >= 0) { this.error.setError("SF013", "remoteFilePath cannot be empty"); + logger.Error("remoteFilePath cannot be empty"); return false; } if (localDir.IndexOfAny(Path.GetInvalidPathChars()) >= 0) { this.error.setError("SF014", "Invalid localDir"); + logger.Error("Invalid localDir"); return false; } if (this.channel == null || !this.channel.IsConnected) { this.error.setError("SF007", "The channel is invalid, reconect"); + logger.Error("The channel is invalid, reconect"); return false; } string rDir = ""; @@ -262,23 +283,27 @@ public override bool Get(String remoteFilePath, String localDir) catch (Exception e) { this.error.setError("SF008", e.Message); + logger.Error("Get", e); return false; } return true; } [SecuritySafeCritical] - public override bool Rm(String remoteFilePath) + public override bool Rm(string remoteFilePath) { + logger.Debug("Rm"); if (SecurityUtils.compareStrings("", remoteFilePath) || remoteFilePath == null || remoteFilePath.IndexOfAny(Path.GetInvalidPathChars()) >= 0) { this.error.setError("SF018", "remoteFilePath cannot be empty"); + logger.Error("remoteFilePath cannot be empty"); return false; } if (this.channel == null || !this.channel.IsConnected) { this.error.setError("SF019", "The channel is invalid, reconect"); + logger.Error("The channel is invalid, reconect"); return false; } string rDir = ""; @@ -300,6 +325,7 @@ public override bool Rm(String remoteFilePath) catch (Exception e) { this.error.setError("SF008", e.Message); + logger.Error("Rm", e); return false; } return true; @@ -308,6 +334,7 @@ public override bool Rm(String remoteFilePath) [SecuritySafeCritical] public override void Disconnect() { + logger.Debug("Disconnect"); if (this.channel != null && this.channel.IsConnected) { this.channel.Disconnect(); @@ -317,6 +344,7 @@ public override void Disconnect() [SecuritySafeCritical] public override string GetWorkingDirectory() { + logger.Debug("GetWorkingDirectory"); if (this.channel != null && this.channel.IsConnected) { try @@ -326,6 +354,7 @@ public override string GetWorkingDirectory() catch (Exception) { this.error.setError("SF017", "Could not get working directory, try reconnect"); + logger.Error("Could not get working directory, try reconnect"); return ""; } } @@ -337,10 +366,7 @@ public override string GetWorkingDirectory() private void SetupChannelSftp(SftpOptions options, bool useKey) { - - - - + logger.Debug("SetupChannelSftp"); List method = new List(); if (useKey) @@ -364,6 +390,7 @@ private void SetupChannelSftp(SftpOptions options, bool useKey) if (SecurityUtils.compareStrings("", options.KnownHostsPath)) { this.error.setError("SF009", "Options misconfiguration, known_hosts path is empty but host key checking is true"); + logger.Error("Options misconfiguration, known_hosts path is empty but host key checking is true"); return; } @@ -388,6 +415,7 @@ private void SetupChannelSftp(SftpOptions options, bool useKey) private string GetFileNamne(string path) { + logger.Debug("GetFileNamne"); string[] pathArr = null; if (path.Contains("/")) { @@ -403,18 +431,22 @@ private string GetFileNamne(string path) private static bool CanTrustHost(string hostname, HostKeyEventArgs e) { + logger.Debug("CanTrustHost"); if (_knownHosts.Knows(hostname, e.HostKeyName, e.HostKey, 22)) { + logger.Debug("CanTrustHost - true"); return true; } else { + logger.Debug("CanTrustHost - false"); return false; } } private void checkFingerpint(ConnectionInfo con, string knownHostsPath) { + logger.Debug("checkFingerpint"); _knownHosts = new KnownHostStore(knownHostsPath); using (Renci.SshNet.SftpClient client1 = new Renci.SshNet.SftpClient(con)) { @@ -433,6 +465,7 @@ private void checkFingerpint(ConnectionInfo con, string knownHostsPath) { this.error.setError("SF012", "unknown host"); + logger.Error("unknown host"); this.channel = null; this.fingerprint = false; } diff --git a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusSftp/Sftp/SftpOptions.cs b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusSftp/Sftp/SftpOptions.cs index c01a7fd1d..25af8d57c 100644 --- a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusSftp/Sftp/SftpOptions.cs +++ b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusSftp/Sftp/SftpOptions.cs @@ -1,4 +1,5 @@ -using SecurityAPICommons.Commons; +using log4net; +using SecurityAPICommons.Commons; using SecurityAPICommons.Utils; using System; using System.Collections.Generic; @@ -12,6 +13,8 @@ namespace Sftp.GeneXusSftp [SecuritySafeCritical] public class SftpOptions : SecurityAPIObject { + private static readonly ILog logger = LogManager.GetLogger(typeof(SftpOptions)); + private string host; public string Host { @@ -83,6 +86,7 @@ public SftpOptions() : base() private void SetKeyPath(String value) { + logger.Debug("SetKeyPath"); //C# apps allways runs on windows, shouldn't correct \\ on local paths //string path = $"/{value.Replace(@"\", "/")}"; string path = value; @@ -91,6 +95,7 @@ private void SetKeyPath(String value) { this.error.setError("OP001", "Private key must be base64 encoded file (Valid extensions: .pem, .key, empty)"); + logger.Error("Private key must be base64 encoded file (Valid extensions: .pem, .key, empty)"); } else { @@ -101,12 +106,14 @@ private void SetKeyPath(String value) private void SetKnownHostsPath(String value) { + logger.Debug("SetKnownHostsPath"); //C# apps allways runs on windows, shouldn't correct \\ on local paths //var path = $"/{value.Replace(@"\", "/")}"; string path = value; if (!SecurityUtils.extensionIs(path, "")) { this.error.setError("OP002", "No extension is allowed for known_hosts file"); + logger.Error("No extension is allowed for known_hosts file"); } else { diff --git a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusXmlSignature/DSig/XmlDSigSigner.cs b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusXmlSignature/DSig/XmlDSigSigner.cs index 26a605870..6db8e6ce4 100644 --- a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusXmlSignature/DSig/XmlDSigSigner.cs +++ b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusXmlSignature/DSig/XmlDSigSigner.cs @@ -9,12 +9,14 @@ using SecurityAPICommons.Commons; using SecurityAPICommons.Utils; using SecurityAPICommons.Keys; +using log4net; namespace GeneXusXmlSignature.GeneXusDSig { [SecuritySafeCritical] public class XmlDSigSigner : SecurityAPIObject, IXmlDSigSignerObject { + private static readonly ILog logger = LogManager.GetLogger(typeof(XmlDSigSigner)); private AsymmetricAlgorithm privateKey; private AsymmetricAlgorithm publicKey; @@ -32,13 +34,14 @@ public XmlDSigSigner() : base() public bool DoSignFile(string xmlFilePath, PrivateKeyManager privateKey, CertificateX509 certificate, string outputPath, DSigOptions options) { + logger.Debug("DoSignFile"); this.error.cleanError(); /******* INPUT VERIFICATION - BEGIN *******/ - SecurityUtils.validateStringInput("xmlFilePath", xmlFilePath, this.error); - SecurityUtils.validateObjectInput("privateKey", privateKey, this.error); - SecurityUtils.validateObjectInput("certificate", certificate, this.error); - SecurityUtils.validateStringInput("outputPath", outputPath, this.error); - SecurityUtils.validateObjectInput("options", options, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "DoSignFile", "xmlFilePath", xmlFilePath, this.error); + SecurityUtils.validateObjectInput(this.GetType().Name, "DoSignFile", "privateKey", privateKey, this.error); + SecurityUtils.validateObjectInput(this.GetType().Name, "DoSignFile", "certificate", certificate, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "DoSignFile", "outputPath", outputPath, this.error); + SecurityUtils.validateObjectInput(this.GetType().Name, "DoSignFile", "options", options, this.error); if (this.HasError()) { return false; @@ -52,12 +55,13 @@ public bool DoSignFile(string xmlFilePath, PrivateKeyManager privateKey, public string DoSign(string xmlInput, PrivateKeyManager privateKey, CertificateX509 certificate, DSigOptions options) { + logger.Debug("DoSign"); this.error.cleanError(); /******* INPUT VERIFICATION - BEGIN *******/ - SecurityUtils.validateStringInput("xmlInput", xmlInput, this.error); - SecurityUtils.validateObjectInput("privateKey", privateKey, this.error); - SecurityUtils.validateObjectInput("certificate", certificate, this.error); - SecurityUtils.validateObjectInput("options", options, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "DoSign", "xmlInput", xmlInput, this.error); + SecurityUtils.validateObjectInput(this.GetType().Name, "DoSign", "privateKey", privateKey, this.error); + SecurityUtils.validateObjectInput(this.GetType().Name, "DoSign", "certificate", certificate, this.error); + SecurityUtils.validateObjectInput(this.GetType().Name, "DoSign", "options", options, this.error); if (this.HasError()) { return ""; @@ -72,13 +76,14 @@ public bool DoSignFileElement(string xmlFilePath, string xPath, PrivateKeyManager privateKey, CertificateX509 certificate, string outputPath, DSigOptions options) { + logger.Debug("DoSignFileElement"); this.error.cleanError(); /******* INPUT VERIFICATION - BEGIN *******/ - SecurityUtils.validateStringInput("xmlFilePath", xmlFilePath, this.error); - SecurityUtils.validateObjectInput("privateKey", privateKey, this.error); - SecurityUtils.validateObjectInput("certificate", certificate, this.error); - SecurityUtils.validateStringInput("outputPath", outputPath, this.error); - SecurityUtils.validateObjectInput("options", options, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "DoSignFileElement", "xmlFilePath", xmlFilePath, this.error); + SecurityUtils.validateObjectInput(this.GetType().Name, "DoSignFileElement", "privateKey", privateKey, this.error); + SecurityUtils.validateObjectInput(this.GetType().Name, "DoSignFileElement", "certificate", certificate, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "DoSignFileElement", "outputPath", outputPath, this.error); + SecurityUtils.validateObjectInput(this.GetType().Name, "DoSignFileElement", "options", options, this.error); if (this.HasError()) { return false; @@ -92,13 +97,14 @@ public bool DoSignFileElement(string xmlFilePath, string xPath, public string DoSignElement(string xmlInput, string xPath, PrivateKeyManager privateKey, CertificateX509 certificate, DSigOptions options) { + logger.Debug("DoSignElement"); this.error.cleanError(); /******* INPUT VERIFICATION - BEGIN *******/ - SecurityUtils.validateStringInput("xmlInput", xmlInput, this.error); - SecurityUtils.validateStringInput("xPath", xPath, this.error); - SecurityUtils.validateObjectInput("privateKey", privateKey, this.error); - SecurityUtils.validateObjectInput("certificate", certificate, this.error); - SecurityUtils.validateObjectInput("options", options, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "DoSignElement", "xmlInput", xmlInput, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "DoSignElement", "xPath", xPath, this.error); + SecurityUtils.validateObjectInput(this.GetType().Name, "DoSignElement", "privateKey", privateKey, this.error); + SecurityUtils.validateObjectInput(this.GetType().Name, "DoSignElement", "certificate", certificate, this.error); + SecurityUtils.validateObjectInput(this.GetType().Name, "DoSignElement", "options", options, this.error); if (this.HasError()) { return ""; @@ -111,10 +117,11 @@ public string DoSignElement(string xmlInput, string xPath, PrivateKeyManager pri [SecuritySafeCritical] public bool DoVerify(string xmlSigned, DSigOptions options) { + logger.Debug("DoVerify"); this.error.cleanError(); /******* INPUT VERIFICATION - BEGIN *******/ - SecurityUtils.validateStringInput("xmlSigned", xmlSigned, this.error); - SecurityUtils.validateObjectInput("options", options, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "DoVerify", "xmlSigned", xmlSigned, this.error); + SecurityUtils.validateObjectInput(this.GetType().Name, "DoVerify", "options", options, this.error); if (this.HasError()) { return false; @@ -127,10 +134,11 @@ public bool DoVerify(string xmlSigned, DSigOptions options) [SecuritySafeCritical] public bool DoVerifyFile(string xmlFilePath, DSigOptions options) { + logger.Debug("DoVerifyFile"); this.error.cleanError(); /******* INPUT VERIFICATION - BEGIN *******/ - SecurityUtils.validateStringInput("xmlFilePath", xmlFilePath, this.error); - SecurityUtils.validateObjectInput("options", options, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "DoVerifyFile", "xmlFilePath", xmlFilePath, this.error); + SecurityUtils.validateObjectInput(this.GetType().Name, "DoVerifyFile", "options", options, this.error); if (this.HasError()) { return false; @@ -142,11 +150,12 @@ public bool DoVerifyFile(string xmlFilePath, DSigOptions options) [SecuritySafeCritical] public bool DoVerifyWithCert(string xmlSigned, CertificateX509 certificate, DSigOptions options) { + logger.Debug("DoVerifyWithCert"); this.error.cleanError(); /******* INPUT VERIFICATION - BEGIN *******/ - SecurityUtils.validateStringInput("xmlSigned", xmlSigned, this.error); - SecurityUtils.validateObjectInput("certificate", certificate, this.error); - SecurityUtils.validateObjectInput("options", options, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "DoVerifyWithCert", "xmlSigned", xmlSigned, this.error); + SecurityUtils.validateObjectInput(this.GetType().Name, "DoVerifyWithCert", "certificate", certificate, this.error); + SecurityUtils.validateObjectInput(this.GetType().Name, "DoVerifyWithCert", "options", options, this.error); if (this.HasError()) { return false; @@ -158,11 +167,12 @@ public bool DoVerifyWithCert(string xmlSigned, CertificateX509 certificate, DSig [SecuritySafeCritical] public bool DoVerifyFileWithCert(string xmlFilePath, CertificateX509 certificate, DSigOptions options) { + logger.Debug("DoVerifyFileWithCert"); this.error.cleanError(); /******* INPUT VERIFICATION - BEGIN *******/ - SecurityUtils.validateStringInput("xmlFilePath", xmlFilePath, this.error); - SecurityUtils.validateObjectInput("certificate", certificate, this.error); - SecurityUtils.validateObjectInput("options", options, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "DoVerifyFileWithCert", "xmlFilePath", xmlFilePath, this.error); + SecurityUtils.validateObjectInput(this.GetType().Name, "DoVerifyFileWithCert", "certificate", certificate, this.error); + SecurityUtils.validateObjectInput(this.GetType().Name, "DoVerifyFileWithCert", "options", options, this.error); if (this.HasError()) { return false; @@ -174,14 +184,15 @@ public bool DoVerifyFileWithCert(string xmlFilePath, CertificateX509 certificate [SecuritySafeCritical] public bool DoSignFileWithPublicKey(string xmlFilePath, PrivateKey privateKey, SecurityAPICommons.Commons.PublicKey publicKey, string outputPath, DSigOptions options, string hash) { + logger.Debug("DoSignFileWithPublicKey"); this.error.cleanError(); /******* INPUT VERIFICATION - BEGIN *******/ - SecurityUtils.validateStringInput("xmlFilePath", xmlFilePath, this.error); - SecurityUtils.validateObjectInput("privateKey", privateKey, this.error); - SecurityUtils.validateObjectInput("publicKey", publicKey, this.error); - SecurityUtils.validateStringInput("outputPath", outputPath, this.error); - SecurityUtils.validateObjectInput("options", options, this.error); - SecurityUtils.validateStringInput("hash", hash, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "DoSignFileWithPublicKey", "xmlFilePath", xmlFilePath, this.error); + SecurityUtils.validateObjectInput(this.GetType().Name, "DoSignFileWithPublicKey", "privateKey", privateKey, this.error); + SecurityUtils.validateObjectInput(this.GetType().Name, "DoSignFileWithPublicKey", "publicKey", publicKey, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "DoSignFileWithPublicKey", "outputPath", outputPath, this.error); + SecurityUtils.validateObjectInput(this.GetType().Name, "DoSignFileWithPublicKey", "options", options, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "DoSignFileWithPublicKey", "hash", hash, this.error); if (this.HasError()) { return false; @@ -195,13 +206,14 @@ public bool DoSignFileWithPublicKey(string xmlFilePath, PrivateKey privateKey, S [SecuritySafeCritical] public string DoSignWithPublicKey(string xmlInput, PrivateKey privateKey, SecurityAPICommons.Commons.PublicKey publicKey, DSigOptions options, string hash) { + logger.Debug("DoSignWithPublicKey"); this.error.cleanError(); /******* INPUT VERIFICATION - BEGIN *******/ - SecurityUtils.validateStringInput("xmlInput", xmlInput, this.error); - SecurityUtils.validateObjectInput("privateKey", privateKey, this.error); - SecurityUtils.validateObjectInput("publicKey", publicKey, this.error); - SecurityUtils.validateObjectInput("options", options, this.error); - SecurityUtils.validateStringInput("hash", hash, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "DoSignWithPublicKey", "xmlInput", xmlInput, this.error); + SecurityUtils.validateObjectInput(this.GetType().Name, "DoSignWithPublicKey", "privateKey", privateKey, this.error); + SecurityUtils.validateObjectInput(this.GetType().Name, "DoSignWithPublicKey", "publicKey", publicKey, this.error); + SecurityUtils.validateObjectInput(this.GetType().Name, "DoSignWithPublicKey", "options", options, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "DoSignWithPublicKey", "hash", hash, this.error); if (this.HasError()) { return ""; @@ -217,15 +229,16 @@ public bool DoSignFileElementWithPublicKey(string xmlFilePath, string xPath, PrivateKey privateKey, SecurityAPICommons.Commons.PublicKey publicKey, string outputPath, DSigOptions options, string hash) { + logger.Debug("DoSignFileElementWithPublicKey"); this.error.cleanError(); /******* INPUT VERIFICATION - BEGIN *******/ - SecurityUtils.validateStringInput("xmlFilePath", xmlFilePath, this.error); - SecurityUtils.validateStringInput("xPath", xPath, this.error); - SecurityUtils.validateObjectInput("privateKey", privateKey, this.error); - SecurityUtils.validateObjectInput("publicKey", publicKey, this.error); - SecurityUtils.validateStringInput("outputPath", outputPath, this.error); - SecurityUtils.validateObjectInput("options", options, this.error); - SecurityUtils.validateStringInput("hash", hash, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "DoSignFileElementWithPublicKey", "xmlFilePath", xmlFilePath, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "DoSignFileElementWithPublicKey", "xPath", xPath, this.error); + SecurityUtils.validateObjectInput(this.GetType().Name, "DoSignFileElementWithPublicKey", "privateKey", privateKey, this.error); + SecurityUtils.validateObjectInput(this.GetType().Name, "DoSignFileElementWithPublicKey", "publicKey", publicKey, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "DoSignFileElementWithPublicKey", "outputPath", outputPath, this.error); + SecurityUtils.validateObjectInput(this.GetType().Name, "DoSignFileElementWithPublicKey", "options", options, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "DoSignFileElementWithPublicKey", "hash", hash, this.error); if (this.HasError()) { return false; @@ -240,14 +253,15 @@ public bool DoSignFileElementWithPublicKey(string xmlFilePath, string xPath, public string DoSignElementWithPublicKey(string xmlInput, string xPath, PrivateKey privateKey, SecurityAPICommons.Commons.PublicKey publicKey , DSigOptions options, string hash) { + logger.Debug("DoSignElementWithPublicKey"); this.error.cleanError(); /******* INPUT VERIFICATION - BEGIN *******/ - SecurityUtils.validateStringInput("xmlInput", xmlInput, this.error); - SecurityUtils.validateStringInput("xPath", xPath, this.error); - SecurityUtils.validateObjectInput("privateKey", privateKey, this.error); - SecurityUtils.validateObjectInput("publicKey", publicKey, this.error); - SecurityUtils.validateObjectInput("options", options, this.error); - SecurityUtils.validateStringInput("hash", hash, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "DoSignElementWithPublicKey", "xmlInput", xmlInput, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "DoSignElementWithPublicKey", "xPath", xPath, this.error); + SecurityUtils.validateObjectInput(this.GetType().Name, "DoSignElementWithPublicKey", "privateKey", privateKey, this.error); + SecurityUtils.validateObjectInput(this.GetType().Name, "DoSignElementWithPublicKey", "publicKey", publicKey, this.error); + SecurityUtils.validateObjectInput(this.GetType().Name, "DoSignElementWithPublicKey", "options", options, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "DoSignElementWithPublicKey", "hash", hash, this.error); if (this.HasError()) { return ""; @@ -261,11 +275,12 @@ public string DoSignElementWithPublicKey(string xmlInput, string xPath, PrivateK [SecuritySafeCritical] public bool DoVerifyWithPublicKey(string xmlSigned, SecurityAPICommons.Commons.PublicKey publicKey, DSigOptions options) { + logger.Debug("DoVerifyWithPublicKey"); this.error.cleanError(); /******* INPUT VERIFICATION - BEGIN *******/ - SecurityUtils.validateStringInput("xmlSigned", xmlSigned, this.error); - SecurityUtils.validateObjectInput("publicKey", publicKey, this.error); - SecurityUtils.validateObjectInput("options", options, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "DoVerifyWithPublicKey", "xmlSigned", xmlSigned, this.error); + SecurityUtils.validateObjectInput(this.GetType().Name, "DoVerifyWithPublicKey", "publicKey", publicKey, this.error); + SecurityUtils.validateObjectInput(this.GetType().Name, "DoVerifyWithPublicKey", "options", options, this.error); if (this.HasError()) { return false; @@ -278,11 +293,12 @@ public bool DoVerifyWithPublicKey(string xmlSigned, SecurityAPICommons.Commons.P [SecuritySafeCritical] public bool DoVerifyFileWithPublicKey(string xmlFilePath, SecurityAPICommons.Commons.PublicKey publicKey, DSigOptions options) { + logger.Debug("DoVerifyFileWithPublicKey"); this.error.cleanError(); /******* INPUT VERIFICATION - BEGIN *******/ - SecurityUtils.validateStringInput("xmlFilePath", xmlFilePath, this.error); - SecurityUtils.validateObjectInput("publicKey", publicKey, this.error); - SecurityUtils.validateObjectInput("options", options, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "DoVerifyFileWithPublicKey", "xmlFilePath", xmlFilePath, this.error); + SecurityUtils.validateObjectInput(this.GetType().Name, "DoVerifyFileWithPublicKey", "publicKey", publicKey, this.error); + SecurityUtils.validateObjectInput(this.GetType().Name, "DoVerifyFileWithPublicKey", "options", options, this.error); if (this.HasError()) { return false; @@ -297,10 +313,12 @@ public bool DoVerifyFileWithPublicKey(string xmlFilePath, SecurityAPICommons.Com private string AxuiliarSign(string xmlInput, PrivateKey key, Key publicKey, string outputPath, DSigOptions options, bool isFile, string xPath, string hash) { + logger.Debug("AxuiliarSign"); if (TransformsWrapperUtils.getTransformsWrapper(options.DSigSignatureType, this.error) != TransformsWrapper.ENVELOPED) { error.setError("XD001", "Not implemented DSigType"); + logger.Error("Not implemented DSigType"); } SecurityAPICommons.Commons.PublicKey cert = null; cert = (hash != null) ? (SecurityAPICommons.Commons.PublicKey)publicKey : (CertificateX509)publicKey; @@ -312,6 +330,7 @@ private string AxuiliarSign(string xmlInput, PrivateKey key, else if (SecurityUtils.compareStrings(cert.getAlgorithm(), "ECDSA")) { this.error.setError("XD014", "XML signature with ECDSA keys is not implemented on Net Framework"); + logger.Error("XML signature with ECDSA keys is not implemented on Net Framework"); return ""; } @@ -342,10 +361,12 @@ private string AxuiliarSign(string xmlInput, PrivateKey key, private bool AuxiliarVerify(string xmlInput, DSigOptions options, Key key, bool isFile, bool withCert) { + logger.Debug("AuxiliarVerify"); if (TransformsWrapperUtils.getTransformsWrapper(options.DSigSignatureType, this.error) != TransformsWrapper.ENVELOPED) { error.setError("XD001", "Not implemented DSigType"); + logger.Error("Not implemented DSigType"); } XmlDocument xmlDoc = LoadDocument(isFile, xmlInput, options); if (this.HasError()) @@ -357,6 +378,7 @@ private bool AuxiliarVerify(string xmlInput, DSigOptions options, Key key, bool if (SecurityUtils.compareStrings(key.getAlgorithm(), "ECDSA")) { this.error.setError("XD014", "XML signature with ECDSA keys is not implemented on Net Framework"); + logger.Error("XML signature with ECDSA keys is not implemented on Net Framework"); return false; } return Verify(xmlDoc, withCert, key, options); @@ -370,6 +392,7 @@ private bool AuxiliarVerify(string xmlInput, DSigOptions options, Key key, bool private string Sign(XmlDocument xmlInput, PrivateKeyManager key, SecurityAPICommons.Commons.PublicKey certificate, string dSigType, string canonicalizationType, string keyInfoType, string xpath, string id, string hash) { + logger.Debug("Sign"); inicializeInstanceVariables(key, certificate, hash); SignatureElementType signatureElementType; @@ -381,6 +404,7 @@ private string Sign(XmlDocument xmlInput, PrivateKeyManager key, SecurityAPIComm if (id == null || SecurityUtils.compareStrings(id, "")) { this.error.setError("XD003", "Identifier attribute name missing"); + logger.Error("Identifier attribute name missing"); return ""; } } @@ -476,6 +500,7 @@ private string Sign(XmlDocument xmlInput, PrivateKeyManager key, SecurityAPIComm catch (Exception e) { this.error.setError("XD004", e.Message); + logger.Error("Sign", e); return ""; } XmlElement xmlDigitalSignature = null; @@ -486,6 +511,7 @@ private string Sign(XmlDocument xmlInput, PrivateKeyManager key, SecurityAPIComm catch (Exception ex) { this.error.setError("XD005", ex.Message); + logger.Error("Sign", ex); return ""; } @@ -502,6 +528,7 @@ private string Sign(XmlDocument xmlInput, PrivateKeyManager key, SecurityAPIComm private bool Verify(XmlDocument doc, bool withCert, Key certificate, DSigOptions options) { + logger.Debug("Verify"); doc.PreserveWhitespace = true; XmlNodeList nodeList = null; SignedXml signedXML = null; @@ -580,6 +607,7 @@ private bool Verify(XmlDocument doc, bool withCert, Key certificate, DSigOptions catch (Exception e) { this.error.setError("XD006", e.Message); + logger.Error("Verify", e); return false; } @@ -588,6 +616,7 @@ private bool Verify(XmlDocument doc, bool withCert, Key certificate, DSigOptions private KeyInfo createKeyInfo(SecurityAPICommons.Commons.PublicKey certificate, string keyInfoType, string hash) { + logger.Debug("createKeyInfo"); KeyInfo keyInfo = new KeyInfo(); KeyInfoType kinfo = KeyInfoTypeUtils.getKeyInfoType(keyInfoType, this.error); switch (kinfo) @@ -606,6 +635,7 @@ private KeyInfo createKeyInfo(SecurityAPICommons.Commons.PublicKey certificate, if (hash != null) { this.error.setError("XD002", "The file included is a Public Key, cannot include a certificate on the signature"); + logger.Error("The file included is a Public Key, cannot include a certificate on the signature"); return null; } X509Certificate2 x509Certificate = ((CertificateX509)certificate).Cert; @@ -626,7 +656,7 @@ private KeyInfo createKeyInfo(SecurityAPICommons.Commons.PublicKey certificate, private static void addCanonTransform(Reference reference, CanonicalizerWrapper canonW) { - + logger.Debug("addCanonTransform"); switch (canonW) { case CanonicalizerWrapper.ALGO_ID_C14N_OMIT_COMMENTS: @@ -647,7 +677,7 @@ private static void addCanonTransform(Reference reference, CanonicalizerWrapper private void inicializeInstanceVariables(PrivateKeyManager key, SecurityAPICommons.Commons.PublicKey certificate, string hash) { - + logger.Debug("inicializeInstanceVariables"); this.privateKey = key.getPrivateKeyForXML(); this.publicKey = certificate.getAsymmetricAlgorithm(); this.asymAlgorithm = certificate.getAlgorithm(); @@ -664,6 +694,7 @@ private void inicializeInstanceVariables(PrivateKeyManager key, SecurityAPICommo // Create the XML that represents the transform. private static XmlDsigXPathTransform CreateXPathTransform(string XPathString, XmlDocument xdoc) { + logger.Debug("CreateXPathTransform"); // Create a new XMLDocument object. XmlDocument doc = new XmlDocument() { XmlResolver = null }; @@ -698,12 +729,14 @@ private static XmlDsigXPathTransform CreateXPathTransform(string XPathString, Xm private XmlDocument LoadDocument(bool isFile, String path, DSigOptions options) { + logger.Debug("LoadDocument"); XmlDocument xmlDoc = null; if (isFile) { if (!SignatureUtils.validateExtensionXML(path)) { this.error.setError("XD013", "Not XML file"); + logger.Error("Not XML file"); return null; } xmlDoc = SignatureUtils.documentFromFile(path, options.XmlSchemaPath, this.error); diff --git a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusXmlSignature/GeneXusXmlSignature.csproj b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusXmlSignature/GeneXusXmlSignature.csproj index ea8ad6834..96f9b8e02 100644 --- a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusXmlSignature/GeneXusXmlSignature.csproj +++ b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusXmlSignature/GeneXusXmlSignature.csproj @@ -10,6 +10,7 @@ + diff --git a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusXmlSignature/Utils/AsymmetricSigningAlgorithm.cs b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusXmlSignature/Utils/AsymmetricSigningAlgorithm.cs index f0a5a935f..ccf7c7b0b 100644 --- a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusXmlSignature/Utils/AsymmetricSigningAlgorithm.cs +++ b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusXmlSignature/Utils/AsymmetricSigningAlgorithm.cs @@ -3,6 +3,7 @@ using System.Linq; using System.Security; using SecurityAPICommons.Commons; +using log4net; namespace GeneXusXmlSignature.GeneXusUtils { @@ -24,6 +25,8 @@ public enum AsymmetricSigningAlgorithm public static class AsymmetricSigningAlgorithmUtils { + private static readonly ILog logger = LogManager.GetLogger(typeof(AsymmetricSigningAlgorithmUtils)); + /// /// Mapping between string name and AsymmetricSigningAlgorithm enum representation /// @@ -32,10 +35,12 @@ public static class AsymmetricSigningAlgorithmUtils /// AsymmetricSigningAlgorithm enum representation public static AsymmetricSigningAlgorithm getAsymmetricSigningAlgorithm(string asymmetricSigningAlgorithm, Error error) { + logger.Debug("getAsymmetricSigningAlgorithm"); if (error == null) return AsymmetricSigningAlgorithm.NONE; if (asymmetricSigningAlgorithm == null) { error.setError("ASA03", "Unrecognized AsymmetricSigningAlgorithm"); + logger.Error("Unrecognized AsymmetricSigningAlgorithm"); return AsymmetricSigningAlgorithm.NONE; } switch (asymmetricSigningAlgorithm.ToUpper(System.Globalization.CultureInfo.InvariantCulture).Trim()) @@ -46,6 +51,7 @@ public static AsymmetricSigningAlgorithm getAsymmetricSigningAlgorithm(string as return AsymmetricSigningAlgorithm.ECDSA; default: error.setError("ASA01", "Unrecognized AsymmetricSigningAlgorithm"); + logger.Error("Unrecognized AsymmetricSigningAlgorithm"); return AsymmetricSigningAlgorithm.NONE; } } @@ -57,6 +63,7 @@ public static AsymmetricSigningAlgorithm getAsymmetricSigningAlgorithm(string as /// string value of the algorithm public static string valueOf(AsymmetricSigningAlgorithm asymmetricSigningAlgorithm, Error error) { + logger.Debug("valueOf"); if (error == null) return ""; switch (asymmetricSigningAlgorithm) { @@ -66,6 +73,7 @@ public static string valueOf(AsymmetricSigningAlgorithm asymmetricSigningAlgorit return "ECDSA"; default: error.setError("ASA02", "Unrecognized AsymmetricSigningAlgorithm"); + logger.Error("Unrecognized AsymmetricSigningAlgorithm"); return ""; } } diff --git a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusXmlSignature/Utils/CanonicalizerWrapper.cs b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusXmlSignature/Utils/CanonicalizerWrapper.cs index 5ab8d98b0..33c02d038 100644 --- a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusXmlSignature/Utils/CanonicalizerWrapper.cs +++ b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusXmlSignature/Utils/CanonicalizerWrapper.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Security; +using log4net; using SecurityAPICommons.Commons; namespace GeneXusXmlSignature.GeneXusUtils @@ -17,12 +18,15 @@ public enum CanonicalizerWrapper [SecuritySafeCritical] public static class CanonicalizerWrapperUtils { + private static readonly ILog logger = LogManager.GetLogger(typeof(CanonicalizerWrapperUtils)); public static CanonicalizerWrapper getCanonicalizerWrapper(string canonicalizerWrapper, Error error) { + logger.Debug("getCanonicalizerWrapper"); if (error == null) return CanonicalizerWrapper.NONE; if (canonicalizerWrapper == null) { error.setError("CAW05", "Unrecognized CanonicalizationMethod"); + logger.Error("Unrecognized CanonicalizationMethod"); return CanonicalizerWrapper.NONE; } switch (canonicalizerWrapper.Trim()) @@ -37,12 +41,14 @@ public static CanonicalizerWrapper getCanonicalizerWrapper(string canonicalizerW return CanonicalizerWrapper.ALGO_ID_C14N_EXCL_WITH_COMMENTS; default: error.setError("CAW01", "Unrecognized CanonicalizationMethod"); + logger.Error("Unrecognized CanonicalizationMethod"); return CanonicalizerWrapper.NONE; } } public static string valueOf(CanonicalizerWrapper canonicalizerWrapper, Error error) { + logger.Debug("valueOf"); if (error == null) return ""; switch (canonicalizerWrapper) { @@ -56,12 +62,14 @@ public static string valueOf(CanonicalizerWrapper canonicalizerWrapper, Error er return "exc_C14N_WITH_COMMENTS"; default: error.setError("CAW02", "Unrecognized CanonicalizationMethod"); + logger.Error("Unrecognized CanonicalizationMethod"); return ""; } } public static string valueOfInternal(CanonicalizerWrapper canonicalizerWrapper, Error error) { + logger.Debug("valueOfInternal"); if (error == null) return ""; switch (canonicalizerWrapper) { @@ -75,12 +83,14 @@ public static string valueOfInternal(CanonicalizerWrapper canonicalizerWrapper, return "ALGO_ID_C14N_EXCL_WITH_COMMENTS"; default: error.setError("CAW03", "Unrecognized CanonicalizationMethod"); + logger.Error("Unrecognized CanonicalizationMethod"); return ""; } } public static string getCanonicalizationMethodAlorithm(CanonicalizerWrapper canonicalizerWrapper, Error error) { + logger.Debug("getCanonicalizationMethodAlorithm"); if (error == null) return null; switch (canonicalizerWrapper) { @@ -94,6 +104,7 @@ public static string getCanonicalizationMethodAlorithm(CanonicalizerWrapper cano return Constants.ALGO_ID_C14N_EXCL_WITH_COMMENTS; default: error.setError("CAW04", "Unrecognized CanonicalizationMethod"); + logger.Error("Unrecognized CanonicalizationMethod"); return null; } diff --git a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusXmlSignature/Utils/KeyInfoType.cs b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusXmlSignature/Utils/KeyInfoType.cs index 6a40c6b78..42f1165cc 100644 --- a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusXmlSignature/Utils/KeyInfoType.cs +++ b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusXmlSignature/Utils/KeyInfoType.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Security; +using log4net; using SecurityAPICommons.Commons; namespace GeneXusXmlSignature.GeneXusUtils @@ -15,12 +16,15 @@ public enum KeyInfoType [SecuritySafeCritical] public static class KeyInfoTypeUtils { + private static readonly ILog logger = LogManager.GetLogger(typeof(KeyInfoTypeUtils)); public static KeyInfoType getKeyInfoType(string keyInfoType, Error error) { + logger.Debug("getKeyInfoType"); if (error == null) return KeyInfoType.NONE; if (keyInfoType == null) { error.setError("KIT03", "Unrecognized KeyInfoType"); + logger.Error("Unrecognized KeyInfoType"); return KeyInfoType.NONE; } switch (keyInfoType.Trim()) @@ -33,6 +37,7 @@ public static KeyInfoType getKeyInfoType(string keyInfoType, Error error) return KeyInfoType.X509Certificate; default: error.setError("KIT01", "Unrecognized KeyInfoType"); + logger.Error("Unrecognized KeyInfoType"); return KeyInfoType.NONE; } @@ -40,6 +45,7 @@ public static KeyInfoType getKeyInfoType(string keyInfoType, Error error) public static string valueOf(KeyInfoType keyInfoType, Error error) { + logger.Debug("valueOf"); if (error == null) return ""; switch (keyInfoType) { @@ -51,6 +57,7 @@ public static string valueOf(KeyInfoType keyInfoType, Error error) return "X509Certificate"; default: error.setError("KIT02", "Unrecognized KeyInfoType"); + logger.Error("Unrecognized KeyInfoType"); return ""; } } diff --git a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusXmlSignature/Utils/MessageDigestAlgorithmWrapper.cs b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusXmlSignature/Utils/MessageDigestAlgorithmWrapper.cs index 486986a7a..b65a58e5f 100644 --- a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusXmlSignature/Utils/MessageDigestAlgorithmWrapper.cs +++ b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusXmlSignature/Utils/MessageDigestAlgorithmWrapper.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Security; +using log4net; using SecurityAPICommons.Commons; namespace GeneXusXmlSignature.GeneXusUtils @@ -15,13 +16,16 @@ public enum MessageDigestAlgorithmWrapper [SecuritySafeCritical] public static class MessageDigestAlgorithmWrapperUtils { + private static readonly ILog logger = LogManager.GetLogger(typeof(MessageDigestAlgorithmWrapperUtils)); public static MessageDigestAlgorithmWrapper getMessageDigestAlgorithmWrapper(string messageDigestAlgorithmWrapper, Error error) { + logger.Debug("getMessageDigestAlgorithmWrapper"); if (error == null) return MessageDigestAlgorithmWrapper.NONE; if (messageDigestAlgorithmWrapper == null) { error.setError("MDA04", "Not recognized digest algorithm"); + logger.Error("Not recognized digest algorithm"); return MessageDigestAlgorithmWrapper.NONE; } switch (messageDigestAlgorithmWrapper.ToUpper(System.Globalization.CultureInfo.InvariantCulture).Trim()) @@ -34,6 +38,7 @@ public static MessageDigestAlgorithmWrapper getMessageDigestAlgorithmWrapper(str return MessageDigestAlgorithmWrapper.SHA512; default: error.setError("MDA01", "Not recognized digest algorithm"); + logger.Error("Not recognized digest algorithm"); return MessageDigestAlgorithmWrapper.NONE; } @@ -41,6 +46,7 @@ public static MessageDigestAlgorithmWrapper getMessageDigestAlgorithmWrapper(str public static string valueOf(MessageDigestAlgorithmWrapper messageDigestAlgorithmWrapper, Error error) { + logger.Debug("valueOf"); if (error == null) return null; switch (messageDigestAlgorithmWrapper) { @@ -52,12 +58,14 @@ public static string valueOf(MessageDigestAlgorithmWrapper messageDigestAlgorith return "SHA512"; default: error.setError("MDA02", "Not recognized digest algorithm"); + logger.Error("Not recognized digest algorithm"); return null; } } public static string getDigestMethod(MessageDigestAlgorithmWrapper messageDigestAlgorithmWrapper, Error error) { + logger.Debug("getDigestMethod"); if (error == null) return null; switch (messageDigestAlgorithmWrapper) { @@ -69,6 +77,7 @@ public static string getDigestMethod(MessageDigestAlgorithmWrapper messageDigest return Constants.ALGO_ID_DIGEST_SHA512; default: error.setError("MDA03", "Not recognized digest algorithm"); + logger.Error("Not recognized digest algorithm"); return null; } } diff --git a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusXmlSignature/Utils/SignatureElementType.cs b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusXmlSignature/Utils/SignatureElementType.cs index 374e79274..c1467a625 100644 --- a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusXmlSignature/Utils/SignatureElementType.cs +++ b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusXmlSignature/Utils/SignatureElementType.cs @@ -1,5 +1,6 @@ using System.Security; +using log4net; using SecurityAPICommons.Commons; namespace GeneXusXmlSignature.GeneXusUtils @@ -13,8 +14,10 @@ public enum SignatureElementType [SecuritySafeCritical] public static class SignatureElementTypeUtils { + private static readonly ILog logger = LogManager.GetLogger(typeof(SignatureElementTypeUtils)); public static string ValueOf(SignatureElementType signatureElementType, Error error) { + logger.Debug("ValueOf"); if (error == null) return ""; switch (signatureElementType) { @@ -26,6 +29,7 @@ public static string ValueOf(SignatureElementType signatureElementType, Error er return "document"; default: error.setError("SET01", "Unrecognized SignatureElementType"); + logger.Error("Unrecognized SignatureElementType"); return ""; } } diff --git a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusXmlSignature/Utils/TransformsWrapper.cs b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusXmlSignature/Utils/TransformsWrapper.cs index 5c7a7af92..158066f41 100644 --- a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusXmlSignature/Utils/TransformsWrapper.cs +++ b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusXmlSignature/Utils/TransformsWrapper.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Security; +using log4net; using SecurityAPICommons.Commons; namespace GeneXusXmlSignature.GeneXusUtils @@ -15,12 +16,15 @@ public enum TransformsWrapper [SecuritySafeCritical] public static class TransformsWrapperUtils { + private static readonly ILog logger = LogManager.GetLogger(typeof(TransformsWrapperUtils)); public static TransformsWrapper getTransformsWrapper(string transformsWrapper, Error error) { + logger.Debug("getTransformsWrapper"); if (error == null) return TransformsWrapper.NONE; if (transformsWrapper == null) { error.setError("TRW04", "Unrecognized transformation"); + logger.Error("Unrecognized transformation"); return TransformsWrapper.NONE; } switch (transformsWrapper.ToUpper(System.Globalization.CultureInfo.InvariantCulture).Trim()) @@ -33,6 +37,7 @@ public static TransformsWrapper getTransformsWrapper(string transformsWrapper, E return TransformsWrapper.DETACHED; default: error.setError("TRW01", "Unrecognized transformation"); + logger.Error("Unrecognized transformation"); return TransformsWrapper.NONE; } } @@ -40,6 +45,7 @@ public static TransformsWrapper getTransformsWrapper(string transformsWrapper, E public static string valueOf(TransformsWrapper transformsWrapper, Error error) { + logger.Debug("valueOf"); if (error == null) return null; switch (transformsWrapper) { @@ -51,12 +57,14 @@ public static string valueOf(TransformsWrapper transformsWrapper, Error error) return "DETACHED"; default: error.setError("TRW02", "Unrecognized transformation"); + logger.Error("Unrecognized transformation"); return null; } } public static string getSignatureTypeTransform(TransformsWrapper transformsWrapper, Error error) { + logger.Debug("getSignatureTypeTransform"); if (error == null) return null; switch (transformsWrapper) { @@ -68,6 +76,7 @@ public static string getSignatureTypeTransform(TransformsWrapper transformsWrapp return "http://www.w3.org/2000/09/xmldsig#detached-signature"; default: error.setError("TRW03", "Unrecognized transformation"); + logger.Error("Unrecognized transformation"); return null; } diff --git a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusXmlSignature/Utils/XmlSignatureWrapper.cs b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusXmlSignature/Utils/XmlSignatureWrapper.cs index 171958b1b..f0b6af925 100644 --- a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusXmlSignature/Utils/XmlSignatureWrapper.cs +++ b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusXmlSignature/Utils/XmlSignatureWrapper.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Security; +using log4net; using SecurityAPICommons.Commons; namespace GeneXusXmlSignature.GeneXusUtils @@ -17,12 +18,15 @@ public enum XmlSignatureWrapper [SecuritySafeCritical] public static class XMLSignatureWrapperUtils { + private static readonly ILog logger = LogManager.GetLogger(typeof(XMLSignatureWrapperUtils)); public static XmlSignatureWrapper getXMLSignatureWrapper(string xMLSignatureWrapper, Error error) { + logger.Debug("getXMLSignatureWrapper"); if (error == null) return XmlSignatureWrapper.NONE; if (xMLSignatureWrapper == null) { error.setError("XSW04", "Unrecognized algorithm"); + logger.Error("Unrecognized algorithm"); return XmlSignatureWrapper.NONE; } switch (xMLSignatureWrapper.ToUpper(System.Globalization.CultureInfo.InvariantCulture).Trim()) @@ -39,12 +43,14 @@ public static XmlSignatureWrapper getXMLSignatureWrapper(string xMLSignatureWrap return XmlSignatureWrapper.ECDSA_SHA256; default: error.setError("XSW01", "Unrecognized algorithm"); + logger.Error("Unrecognized algorithm"); return XmlSignatureWrapper.NONE; } } public static string valueOf(XmlSignatureWrapper xMLSignatureWrapper, Error error) { + logger.Debug("valueOf"); if (error == null) return null; switch (xMLSignatureWrapper) { @@ -60,12 +66,14 @@ public static string valueOf(XmlSignatureWrapper xMLSignatureWrapper, Error erro return "ECDSA_SHA256"; default: error.setError("XSW02", "Unrecognized algorithm"); + logger.Error("Unrecognized algorithm"); return null; } } public static string getSignatureMethodAlgorithm(XmlSignatureWrapper xMLSignatureWrapper, Error error) { + logger.Debug("getSignatureMethodAlgorithm"); if (error == null) return null; switch (xMLSignatureWrapper) { @@ -81,6 +89,7 @@ public static string getSignatureMethodAlgorithm(XmlSignatureWrapper xMLSignatur return Constants.ALGO_ID_SIGNATURE_ECDSA_SHA256; default: error.setError("XSW03", "Unrecognized algorithm"); + logger.Error("Unrecognized algorithm"); return null; } } diff --git a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/SecurityAPICommons/Commons/PublicKey.cs b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/SecurityAPICommons/Commons/PublicKey.cs index 10eed5399..34e77309d 100644 --- a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/SecurityAPICommons/Commons/PublicKey.cs +++ b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/SecurityAPICommons/Commons/PublicKey.cs @@ -12,12 +12,15 @@ using Org.BouncyCastle.Utilities.Encoders; using Org.BouncyCastle.X509; using SecurityAPICommons.Utils; +using log4net; namespace SecurityAPICommons.Commons { [SecuritySafeCritical] public class PublicKey : Key { + private static readonly ILog logger = LogManager.GetLogger(typeof(PublicKey)); + public SubjectPublicKeyInfo subjectPublicKeyInfo; [SecuritySafeCritical] @@ -30,12 +33,13 @@ public PublicKey() : base() override public bool Load(string path) { - + logger.Debug("Load"); /******* INPUT VERIFICATION - BEGIN *******/ - SecurityUtils.validateStringInput("path", path, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "Load", "path", path, this.error); if (!(SecurityUtils.extensionIs(path, ".pem") || SecurityUtils.extensionIs(path, "key"))) { this.error.setError("PU001", "Public key should be loaded from a .pem or .key file"); + logger.Error("Public key should be loaded from a .pem or .key file"); return false; } /******* INPUT VERIFICATION - END *******/ @@ -47,6 +51,7 @@ public bool Load(string path) catch (Exception e) { this.error.setError("PU002", e.Message); + logger.Error("Load", e); return false; } return loaded; @@ -56,9 +61,9 @@ public bool Load(string path) override public bool FromBase64(string base64Data) { - + logger.Debug("FromBase64"); /******* INPUT VERIFICATION - BEGIN *******/ - SecurityUtils.validateStringInput("base64Data", base64Data, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "FromBase64", "base64Data", base64Data, this.error); if (this.HasError()) { return false; @@ -78,6 +83,7 @@ public bool FromBase64(string base64Data) catch (Exception e) { this.error.setError("PU003", e.Message); + logger.Error("FromBase64", e); flag = false; } setAlgorithm(); @@ -89,9 +95,11 @@ public bool FromBase64(string base64Data) override public string ToBase64() { + logger.Debug("ToBase64"); if (this.subjectPublicKeyInfo == null) { this.error.setError("PU004", "Not loaded key"); + logger.Error("Not loaded key"); return ""; } string base64Encoded = ""; @@ -104,6 +112,7 @@ public string ToBase64() catch (Exception e) { this.error.setError("PU005", e.Message); + logger.Error("ToBase64", e); } return base64Encoded; @@ -112,9 +121,10 @@ public string ToBase64() [SecuritySafeCritical] public bool FromJwks(string jwks, string kid) { + logger.Debug("FromJwks"); /******* INPUT VERIFICATION - BEGIN *******/ - SecurityUtils.validateStringInput("jwks", jwks, this.error); - SecurityUtils.validateStringInput("kid", kid, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "FromJwks", "jwks", jwks, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "FromJwks", "kid", kid, this.error); if (this.HasError()) { return false; @@ -131,6 +141,7 @@ public bool FromJwks(string jwks, string kid) catch (Exception e) { this.error.setError("PU016", e.Message); + logger.Error("FromJwks", e); return false; } flag = this.FromBase64(b64); @@ -143,6 +154,7 @@ public bool FromJwks(string jwks, string kid) private string FromJson(string json, string id) { + logger.Debug("FromJson"); JwkSet set; try { @@ -151,6 +163,7 @@ private string FromJson(string json, string id) catch (Exception e) { this.error.setError("PU015", e.Message); + logger.Error("FromJson", e); return ""; } @@ -172,6 +185,7 @@ private string FromJson(string json, string id) private bool loadPublicKeyFromFile(string path, string alias, string password) { + logger.Debug("loadPublicKeyFromFile"); bool loaded = false; try { @@ -180,6 +194,7 @@ private bool loadPublicKeyFromFile(string path, string alias, string password) catch (Exception e) { this.error.setError("PU006", e.Message); + logger.Error("loadPublicKeyFromFile", e); return false; } return loaded; @@ -188,6 +203,7 @@ private bool loadPublicKeyFromFile(string path, string alias, string password) private bool loadPublicKeyFromFile(string path) { + logger.Debug("loadPublicKeyFromFile"); bool flag = false; using (StreamReader streamReader = new StreamReader(path)) { @@ -219,17 +235,20 @@ private bool loadPublicKeyFromFile(string path) if (obj.GetType() == typeof(System.Security.Cryptography.X509Certificates.X509Certificate)) { this.error.setError("PU009", "This file contains a certificate, use the Certificate object instead"); + logger.Error("This file contains a certificate, use the Certificate object instead"); flag = false; } if (obj.GetType() == typeof(Org.BouncyCastle.X509.X509Certificate)) { this.error.setError("PU011", "This file contains a certificate, use the Certificate object instead"); + logger.Error("This file contains a certificate, use the Certificate object instead"); flag = false; } if (obj.GetType() == typeof(X509CertificateStructure)) { this.error.setError("PU012", "This file contains a certificate, use the Certificate object instead"); + logger.Error("This file contains a certificate, use the Certificate object instead"); flag = false; } @@ -265,6 +284,7 @@ public void setAlgorithm() override public AsymmetricKeyParameter getAsymmetricKeyParameter() { + logger.Debug("getAsymmetricKeyParameter"); AsymmetricKeyParameter akp = null; try { @@ -273,6 +293,7 @@ public AsymmetricKeyParameter getAsymmetricKeyParameter() catch (Exception e) { this.error.setError("PU006", e.Message); + logger.Error("getAsymmetricKeyParameter", e); return null; } return akp; @@ -282,6 +303,7 @@ public AsymmetricKeyParameter getAsymmetricKeyParameter() override public AsymmetricAlgorithm getAsymmetricAlgorithm() { + logger.Debug("getAsymmetricAlgorithm"); AsymmetricAlgorithm alg = null; switch (this.getAlgorithm()) { @@ -319,11 +341,13 @@ public AsymmetricAlgorithm getAsymmetricAlgorithm() catch(PlatformNotSupportedException) { this.error.setError("PU013", "Not implemented for not Windows platforms, use a x509 certificate instead"); + logger.Error("Not implemented for not Windows platforms, use a x509 certificate instead"); } #endif break; default: this.error.setError("PU014", "Unrecognized algorithm"); + logger.Error("Unrecognized algorithm"); break; } return alg; diff --git a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/SecurityAPICommons/Config/AvailableEncoding.cs b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/SecurityAPICommons/Config/AvailableEncoding.cs index fee657b2c..d6ce12a4a 100644 --- a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/SecurityAPICommons/Config/AvailableEncoding.cs +++ b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/SecurityAPICommons/Config/AvailableEncoding.cs @@ -5,6 +5,7 @@ using System.Threading.Tasks; using System.Security; using SecurityAPICommons.Commons; +using log4net; namespace SecurityAPICommons.Config { @@ -19,12 +20,15 @@ public enum AvailableEncoding [SecuritySafeCritical] public static class AvailableEncodingUtils { - public static AvailableEncoding getAvailableEncoding(string encoding, Error error) + private static readonly ILog logger = LogManager.GetLogger(typeof(AvailableEncodingUtils)); + public static AvailableEncoding getAvailableEncoding(string encoding, Error error) { + logger.Debug("getAvailableEncoding"); if(error == null) return AvailableEncoding.NONE; if (encoding == null) { error.setError("AE001", "Unknown encoding or not available"); + logger.Error("Unknown encoding or not available"); return AvailableEncoding.NONE; } encoding = encoding.Replace("-", "_"); @@ -51,6 +55,7 @@ public static AvailableEncoding getAvailableEncoding(string encoding, Error erro return AvailableEncoding.GB2312; default: error.setError("AE001", "Unknown encoding or not available"); + logger.Error("Unknown encoding or not available"); return AvailableEncoding.NONE; } } @@ -106,6 +111,7 @@ public static string valueOf(AvailableEncoding availableEncoding) public static string encapsulateGetString(byte[] input, AvailableEncoding availableEncoding, Error error) { + logger.Debug("encapsulateGetString"); if (error == null) return ""; const string strUniRepChr = "�"; //Unicode Character 'REPLACEMENT CHARACTER' (U+FFFD) switch (availableEncoding) @@ -195,12 +201,14 @@ public static string encapsulateGetString(byte[] input, AvailableEncoding availa default: error.setError("AE001", "Unknown encoding"); + logger.Error("Unknown encoding"); return ""; } } public static byte[] encapsulateeGetBytes(string input, AvailableEncoding availableEncoding, Error error) { + logger.Debug("encapsulateeGetBytes"); if (error == null) return null; const string strUniRepChr = "�"; //Unicode Character 'REPLACEMENT CHARACTER' (U+FFFD) switch (availableEncoding) @@ -268,6 +276,7 @@ public static byte[] encapsulateeGetBytes(string input, AvailableEncoding availa default: error.setError("AE001", "Unknown encoding"); + logger.Error("Unknown encoding"); return null; } } diff --git a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/SecurityAPICommons/Config/EncodingUtil.cs b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/SecurityAPICommons/Config/EncodingUtil.cs index f2e6ccda6..9a9febec4 100644 --- a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/SecurityAPICommons/Config/EncodingUtil.cs +++ b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/SecurityAPICommons/Config/EncodingUtil.cs @@ -5,6 +5,7 @@ using System.Threading.Tasks; using System.Security; using SecurityAPICommons.Commons; +using log4net; namespace SecurityAPICommons.Config { @@ -12,12 +13,12 @@ namespace SecurityAPICommons.Config public class EncodingUtil : SecurityAPIObject { + private static readonly ILog logger = LogManager.GetLogger(typeof(EncodingUtil)); - - /// - /// EncodingUtil class constructor - /// - [SecuritySafeCritical] + /// + /// EncodingUtil class constructor + /// + [SecuritySafeCritical] public EncodingUtil() : base() { @@ -32,6 +33,7 @@ public static string getEncoding() [SecuritySafeCritical] public void setEncoding(string enc) { + logger.Debug("setEncoding"); if (AvailableEncodingUtils.existsEncoding(enc)) { SecurityApiGlobal.GLOBALENCODING = enc; @@ -39,6 +41,7 @@ public void setEncoding(string enc) else { this.error.setError("EU003", "set encoding error"); + logger.Error("set encoding error"); } } /// @@ -49,6 +52,7 @@ public void setEncoding(string enc) [SecuritySafeCritical] public byte[] getBytes(string inputText) { + logger.Debug("getBytes"); byte[] output = null; String encoding = SecurityApiGlobal.GLOBALENCODING; AvailableEncoding aEncoding = AvailableEncodingUtils.getAvailableEncoding(encoding, this.error); @@ -71,6 +75,7 @@ public byte[] getBytes(string inputText) #pragma warning restore CA1031 // Do not catch general exception types { this.error.setError("EU001", e.Message); + logger.Error("getBytes", e); return null; } @@ -86,6 +91,7 @@ public byte[] getBytes(string inputText) [SecuritySafeCritical] public string getString(byte[] inputBytes) { + logger.Debug("getString"); String res = null; String encoding = SecurityApiGlobal.GLOBALENCODING; @@ -110,6 +116,7 @@ public string getString(byte[] inputBytes) #pragma warning restore CA1031 // Do not catch general exception types { this.error.setError("EU002", e.Message); + logger.Error("getString", e); return ""; } this.error.cleanError(); diff --git a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/SecurityAPICommons/Encoders/Base64Encoder.cs b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/SecurityAPICommons/Encoders/Base64Encoder.cs index 50b2e87a2..fe83fa8bf 100644 --- a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/SecurityAPICommons/Encoders/Base64Encoder.cs +++ b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/SecurityAPICommons/Encoders/Base64Encoder.cs @@ -3,6 +3,7 @@ using SecurityAPICommons.Commons; using SecurityAPICommons.Config; using Org.BouncyCastle.Utilities.Encoders; +using log4net; namespace SecurityAPICommons.Encoders { @@ -13,6 +14,7 @@ namespace SecurityAPICommons.Encoders public class Base64Encoder : SecurityAPIObject { + private static readonly ILog logger = LogManager.GetLogger(typeof(Base64Encoder)); /// /// Base64Encoder constructor @@ -31,6 +33,7 @@ public Base64Encoder() : base() [SecuritySafeCritical] public string toBase64(string text) { + logger.Debug("toBase64"); this.error.cleanError(); EncodingUtil eu = new EncodingUtil(); byte[] textBytes = eu.getBytes(text); @@ -47,6 +50,7 @@ public string toBase64(string text) catch (Exception e) { this.error.setError("BS001", e.Message); + logger.Error("toBase64", e); return ""; } return result; @@ -59,6 +63,7 @@ public string toBase64(string text) [SecuritySafeCritical] public string toPlainText(string base64Text) { + logger.Debug("toPlainText"); this.error.cleanError(); byte[] bytes; try @@ -68,6 +73,7 @@ public string toPlainText(string base64Text) catch (Exception e) { this.error.setError("BS002", e.Message); + logger.Error("toPlainText", e); return ""; } EncodingUtil eu = new EncodingUtil(); @@ -87,6 +93,7 @@ public string toPlainText(string base64Text) [SecuritySafeCritical] public string toStringHexa(string base64Text) { + logger.Debug("toStringHexa"); this.error.cleanError(); byte[] bytes; try @@ -96,6 +103,7 @@ public string toStringHexa(string base64Text) catch (Exception e) { this.error.setError("BS003", e.Message); + logger.Error("toStringHexa", e); return ""; } string result = ""; @@ -106,6 +114,7 @@ public string toStringHexa(string base64Text) catch (Exception e) { this.error.setError("BS004", e.Message); + logger.Error("toStringHexa", e); return ""; } return result; @@ -119,6 +128,7 @@ public string toStringHexa(string base64Text) [SecuritySafeCritical] public string fromStringHexaToBase64(string stringHexa) { + logger.Debug("fromStringHexaToBase64"); this.error.cleanError(); byte[] stringBytes; try @@ -128,6 +138,7 @@ public string fromStringHexaToBase64(string stringHexa) catch (Exception e) { this.error.setError("BS005", e.Message); + logger.Error("fromStringHexaToBase64", e); return ""; } string result = ""; @@ -138,6 +149,7 @@ public string fromStringHexaToBase64(string stringHexa) catch (Exception e) { this.error.setError("BS006", e.Message); + logger.Error("fromStringHexaToBase64", e); return ""; } return result; diff --git a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/SecurityAPICommons/Encoders/Base64UrlEncoder.cs b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/SecurityAPICommons/Encoders/Base64UrlEncoder.cs index f300d761a..572e69f6d 100644 --- a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/SecurityAPICommons/Encoders/Base64UrlEncoder.cs +++ b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/SecurityAPICommons/Encoders/Base64UrlEncoder.cs @@ -4,12 +4,16 @@ using SecurityAPICommons.Config; using Org.BouncyCastle.Utilities.Encoders; using System.Text; +using log4net; namespace SecurityAPICommons.Encoders { + [SecuritySafeCritical] public class Base64UrlEncoder: SecurityAPIObject { + private static readonly ILog logger = LogManager.GetLogger(typeof(Base64UrlEncoder)); + [SecuritySafeCritical] public Base64UrlEncoder() : base() { @@ -19,6 +23,7 @@ public Base64UrlEncoder() : base() [SecuritySafeCritical] public string toBase64(string text) { + logger.Debug("toBase64"); this.error.cleanError(); EncodingUtil eu = new EncodingUtil(); byte[] textBytes = eu.getBytes(text); @@ -36,6 +41,7 @@ public string toBase64(string text) catch (Exception e) { this.error.setError("BS001", e.Message); + logger.Error("toBase64", e); return ""; } return result; @@ -44,6 +50,7 @@ public string toBase64(string text) [SecuritySafeCritical] public string toPlainText(string base64Text) { + logger.Debug("toPlainText"); this.error.cleanError(); byte[] bytes; try @@ -53,6 +60,7 @@ public string toPlainText(string base64Text) catch (Exception e) { this.error.setError("BS002", e.Message); + logger.Error("toPlainText", e); return ""; } EncodingUtil eu = new EncodingUtil(); @@ -68,6 +76,7 @@ public string toPlainText(string base64Text) [SecuritySafeCritical] public string toStringHexa(string base64Text) { + logger.Debug("toStringHexa"); this.error.cleanError(); byte[] bytes; try @@ -77,6 +86,7 @@ public string toStringHexa(string base64Text) catch (Exception e) { this.error.setError("BS003", e.Message); + logger.Error("toStringHexa", e); return ""; } string result = ""; @@ -87,6 +97,7 @@ public string toStringHexa(string base64Text) catch (Exception e) { this.error.setError("BS004", e.Message); + logger.Error("toStringHexa", e); return ""; } return result; @@ -95,6 +106,7 @@ public string toStringHexa(string base64Text) [SecuritySafeCritical] public string fromStringHexaToBase64(string stringHexa) { + logger.Debug("fromStringHexaToBase64"); this.error.cleanError(); byte[] stringBytes; try @@ -104,6 +116,7 @@ public string fromStringHexaToBase64(string stringHexa) catch (Exception e) { this.error.setError("BS005", e.Message); + logger.Error("fromStringHexaToBase64", e); return ""; } string result = ""; @@ -115,6 +128,7 @@ public string fromStringHexaToBase64(string stringHexa) catch (Exception e) { this.error.setError("BS006", e.Message); + logger.Error("fromStringHexaToBase64", e); return ""; } return result; @@ -123,6 +137,7 @@ public string fromStringHexaToBase64(string stringHexa) [SecuritySafeCritical] public string base64ToBase64Url(string base64Text) { + logger.Debug("base64ToBase64Url"); this.error.cleanError(); string result = ""; try @@ -134,6 +149,7 @@ public string base64ToBase64Url(string base64Text) catch (Exception e) { this.error.setError("BS007", e.Message); + logger.Error("base64ToBase64Url", e); return ""; } return result; @@ -142,6 +158,7 @@ public string base64ToBase64Url(string base64Text) [SecuritySafeCritical] public string base64UrlToBase64(string base64UrlText) { + logger.Debug("base64UrlToBase64"); this.error.cleanError(); string result = ""; try @@ -153,6 +170,7 @@ public string base64UrlToBase64(string base64UrlText) catch (Exception e) { this.error.setError("BS008", e.Message); + logger.Error("base64UrlToBase64", e); return ""; } return result; diff --git a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/SecurityAPICommons/Encoders/HexaEncoder.cs b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/SecurityAPICommons/Encoders/HexaEncoder.cs index 949fdc793..1f1b19128 100644 --- a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/SecurityAPICommons/Encoders/HexaEncoder.cs +++ b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/SecurityAPICommons/Encoders/HexaEncoder.cs @@ -3,6 +3,7 @@ using Org.BouncyCastle.Utilities.Encoders; using System; using System.Security; +using log4net; namespace SecurityAPICommons.Encoders @@ -13,6 +14,7 @@ namespace SecurityAPICommons.Encoders [SecuritySafeCritical] public class HexaEncoder : SecurityAPIObject { + private static readonly ILog logger = LogManager.GetLogger(typeof(HexaEncoder)); /// @@ -33,6 +35,7 @@ public HexaEncoder() : base() [SecuritySafeCritical] public string toHexa(string plainText) { + logger.Debug("toHexa"); this.error.cleanError(); EncodingUtil eu = new EncodingUtil(); byte[] stringBytes = eu.getBytes(plainText); @@ -49,6 +52,7 @@ public string toHexa(string plainText) catch (Exception e) { this.error.setError("HE001", e.Message); + logger.Error("toHexa", e); return ""; } return hexa.ToUpper(); @@ -62,6 +66,7 @@ public string toHexa(string plainText) [SecuritySafeCritical] public string fromHexa(string stringHexa) { + logger.Debug("fromHexa"); this.error.cleanError(); byte[] resBytes; try @@ -71,6 +76,7 @@ public string fromHexa(string stringHexa) catch (Exception e) { this.error.setError("HE002", e.Message); + logger.Error("fromHexa", e); return ""; } EncodingUtil eu = new EncodingUtil(); @@ -86,6 +92,7 @@ public string fromHexa(string stringHexa) [SecuritySafeCritical] public bool isHexa(string input) { + logger.Debug("isHexa"); this.error.cleanError(); try { diff --git a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/SecurityAPICommons/Keys/CertificateX509.cs b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/SecurityAPICommons/Keys/CertificateX509.cs index 09297f073..eaaeb9ea0 100644 --- a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/SecurityAPICommons/Keys/CertificateX509.cs +++ b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/SecurityAPICommons/Keys/CertificateX509.cs @@ -13,13 +13,16 @@ using SecurityAPICommons.Commons; using Org.BouncyCastle.Asn1.X509; using SecurityAPICommons.Utils; +using log4net; namespace SecurityAPICommons.Keys { [SecuritySafeCritical] public sealed class CertificateX509 : Certificate, IDisposable { - private string publicKeyAlgorithm; + private static readonly ILog logger = LogManager.GetLogger(typeof(CertificateX509)); + + private string publicKeyAlgorithm; private X509Certificate2 cert; public X509Certificate2 Cert => cert; [SecuritySafeCritical] @@ -88,8 +91,9 @@ public CertificateX509() : base() public bool Load(string path) { this.error.cleanError(); + logger.Debug("Load"); /******* INPUT VERIFICATION - BEGIN *******/ - SecurityUtils.validateStringInput("path", path, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "Load", "path", path, this.error); if (this.HasError()) { return false; @@ -104,8 +108,9 @@ public bool Load(string path) public bool LoadPKCS12(string path, string alias, string password) { this.error.cleanError(); + logger.Debug("LoadPKCS12"); /******* INPUT VERIFICATION - BEGIN *******/ - SecurityUtils.validateStringInput("path", path, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "LoadPKCS12", "path", path, this.error); if (this.HasError()) { return false; @@ -121,6 +126,7 @@ public bool LoadPKCS12(string path, string alias, string password) #pragma warning restore CA1031 // Do not catch general exception types { this.error.setError("CE001", e.Message); + logger.Error("LoadPKCS12", e); return false; } if (result) @@ -136,8 +142,9 @@ public bool LoadPKCS12(string path, string alias, string password) public bool FromBase64(string base64Data) { this.error.cleanError(); + logger.Debug("FromBase64"); /******* INPUT VERIFICATION - BEGIN *******/ - SecurityUtils.validateStringInput("base64Data", base64Data, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "FromBase64", "base64Data", base64Data, this.error); if (this.HasError()) { return false; @@ -157,6 +164,7 @@ public bool FromBase64(string base64Data) catch (Exception e) { this.error.setError("CE002", e.Message); + logger.Error("FromBase64", e); flag = false; } return flag; @@ -166,9 +174,11 @@ public bool FromBase64(string base64Data) override public string ToBase64() { + logger.Debug("ToBase64"); if (!this.inicialized) { this.error.setError("CE003", "Not loaded certificate"); + logger.Error("Not loaded certificate"); return ""; } try @@ -178,6 +188,7 @@ public string ToBase64() catch (Exception e) { this.error.setError("CE004", e.Message); + logger.Error("ToBase64", e); return ""; } @@ -224,7 +235,7 @@ public string getPublicKeyHash() /// boolean true if loaded correctly private bool loadPublicKeyFromFile(string path, string alias, string password) { - + logger.Debug("loadPublicKeyFromFile"); bool flag = false; if (SecurityUtils.extensionIs(path, ".pem")) { @@ -241,6 +252,7 @@ private bool loadPublicKeyFromFile(string path, string alias, string password) if (SecurityUtils.extensionIs(path, ".jks")) { this.error.setError("CE010", "Java Key Stores not allowed on .Net applications"); + logger.Error("Java Key Stores not allowed on .Net applications"); // throw new Exception("Java Key Stores not allowed on .Net applications"); } return flag; @@ -253,6 +265,7 @@ private bool loadPublicKeyFromFile(string path, string alias, string password) /// boolean true if loaded correctly private bool loadPublicKeyFromPEMFile(string path) { + logger.Debug("loadPublicKeyFromPEMFile"); bool flag = false; using (StreamReader streamReader = new StreamReader(path)) @@ -262,6 +275,7 @@ private bool loadPublicKeyFromPEMFile(string path) if (obj.GetType() == typeof(AsymmetricKeyParameter)) { this.error.setError("CE008", "The file contains a private key"); + logger.Error("The file contains a private key"); flag = false; } @@ -273,6 +287,7 @@ private bool loadPublicKeyFromPEMFile(string path) this.hasPublicKey = true; return true;*/ this.error.setError("CE009", "It is a public key not a certificate, use PublicKey Object instead"); + logger.Error("It is a public key not a certificate, use PublicKey Object instead"); flag = false; } @@ -309,6 +324,7 @@ private bool loadPublicKeyFromPEMFile(string path) /// boolean true if loaded correctly private bool loadPublicKeyFromDERFile(string path) { + logger.Debug("loadPublicKeyFromDERFile"); bool flag = false; FileStream fs = null; Org.BouncyCastle.X509.X509Certificate cert = null; @@ -325,6 +341,7 @@ private bool loadPublicKeyFromDERFile(string path) catch(Exception e) { this.error.setError("CE011",e.Message); + logger.Error("loadPublicKeyFromDERFile", e); return false; // throw new FileLoadException(path + " certificate coud not be loaded"); } @@ -345,7 +362,7 @@ private bool loadPublicKeyFromDERFile(string path) override public AsymmetricAlgorithm getAsymmetricAlgorithm() { - + logger.Debug("getAsymmetricAlgorithm"); AsymmetricAlgorithm alg = null; try { @@ -359,6 +376,7 @@ public AsymmetricAlgorithm getAsymmetricAlgorithm() break; default: this.error.setError("CE012", "Unrecrognized key type"); + logger.Error("Unrecrognized key type"); alg = null; break; } @@ -378,10 +396,12 @@ public AsymmetricAlgorithm getAsymmetricAlgorithm() /// boolean true if loaded correctly private bool loadPublicKeyFromPKCS12File(string path, string password) { + logger.Debug("loadPublicKeyFromPKCS12File"); bool flag = false; if (password == null) { this.error.setError("CE014", "Password is required for PKCS12 certificates"); + logger.Error("Password is required for PKCS12 certificates"); return false; } @@ -401,7 +421,7 @@ private bool loadPublicKeyFromPKCS12File(string path, string password) catch (Exception e) { this.error.setError("CE015", e.Message); - // throw new FileLoadException(path + "not found."); + logger.Error("loadPublicKeyFromPKCS12File", e); } if (pkcs12 != null) @@ -422,6 +442,8 @@ private bool loadPublicKeyFromPKCS12File(string path, string password) } this.error.setError("CE007", "path not found."); + logger.Error("path not found."); + return flag; } diff --git a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/SecurityAPICommons/Keys/PrivateKeyManager.cs b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/SecurityAPICommons/Keys/PrivateKeyManager.cs index bbef4ad24..ef063711f 100644 --- a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/SecurityAPICommons/Keys/PrivateKeyManager.cs +++ b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/SecurityAPICommons/Keys/PrivateKeyManager.cs @@ -21,12 +21,14 @@ using System.Security.AccessControl; using System.Globalization; using System.Runtime.InteropServices; +using log4net; namespace SecurityAPICommons.Keys { [SecuritySafeCritical] public class PrivateKeyManager : PrivateKey { + private static readonly ILog logger = LogManager.GetLogger(typeof(PrivateKeyManager)); private PrivateKeyInfo privateKeyInfo; private bool hasPrivateKey; @@ -50,9 +52,10 @@ public PrivateKeyManager() : base() override public bool Load(string privateKeyPath) { + logger.Debug("Load"); this.error.cleanError(); /******* INPUT VERIFICATION - BEGIN *******/ - SecurityUtils.validateStringInput("path", privateKeyPath, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "Load", "path", privateKeyPath, this.error); if (this.HasError()) { return false; @@ -66,10 +69,11 @@ public bool Load(string privateKeyPath) override public bool LoadEncrypted(string privateKeyPath, string encryptionPassword) { + logger.Debug("LoadEncrypted"); this.error.cleanError(); /******* INPUT VERIFICATION - BEGIN *******/ - SecurityUtils.validateStringInput("path", privateKeyPath, this.error); - SecurityUtils.validateStringInput("password", encryptionPassword, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "LoadEncrypted", "path", privateKeyPath, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "LoadEncrypted", "password", encryptionPassword, this.error); if (this.HasError()) { return false; @@ -87,9 +91,10 @@ public bool LoadEncrypted(string privateKeyPath, string encryptionPassword) override public bool LoadPKCS12(string privateKeyPath, string alias, string password) { + logger.Debug("LoadPKCS12"); this.error.cleanError(); /******* INPUT VERIFICATION - BEGIN *******/ - SecurityUtils.validateStringInput("path", privateKeyPath, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "LoadPKCS12", "path", privateKeyPath, this.error); if (this.HasError()) { return false; @@ -105,6 +110,7 @@ public bool LoadPKCS12(string privateKeyPath, string alias, string password) #pragma warning restore CA1031 // Do not catch general exception types { this.error.setError("PK001", e.Message); + logger.Error("LoadPKCS12", e); return false; } if (this.HasError()) @@ -118,9 +124,10 @@ public bool LoadPKCS12(string privateKeyPath, string alias, string password) override public bool FromBase64(string base64) { + logger.Debug("FromBase64"); this.error.cleanError(); /******* INPUT VERIFICATION - BEGIN *******/ - SecurityUtils.validateStringInput("base64", base64, this.error); + SecurityUtils.validateStringInput(this.GetType().Name, "FromBase64", "base64", base64, this.error); if (this.HasError()) { return false; @@ -135,6 +142,7 @@ public bool FromBase64(string base64) catch (Exception e) { this.error.setError("PK002", e.Message); + logger.Error("FromBase64", e); return false; } this.hasPrivateKey = res; @@ -145,6 +153,7 @@ public bool FromBase64(string base64) override public string ToBase64() { + logger.Debug("ToBase64"); if (this.hasPrivateKey) { string encoded = ""; @@ -155,11 +164,13 @@ public string ToBase64() catch (Exception e) { this.error.setError("PK003", e.Message); + logger.Error("ToBase64", e); return ""; } return encoded; } this.error.setError("PK0016", "No private key loaded"); + logger.Error("No private key loaded"); return ""; @@ -189,6 +200,7 @@ public void setAlgorithm() private bool ReadBase64(string base64) { + logger.Debug("ReadBase64"); byte[] keybytes = Base64.Decode(base64); Asn1InputStream istream = new Asn1InputStream(keybytes); Asn1Sequence seq = (Asn1Sequence)istream.ReadObject(); @@ -198,6 +210,7 @@ private bool ReadBase64(string base64) { this.error.setError("PK004", "Could not read private key from base64 string"); + logger.Error("Could not read private key from base64 string"); return false; } @@ -208,9 +221,11 @@ private bool ReadBase64(string base64) [SecuritySafeCritical] public AsymmetricAlgorithm getPrivateKeyForXML() { + logger.Debug("getPrivateKeyForXML"); if (!this.hasPrivateKey) { this.error.setError("PK011", "No private key loaded"); + logger.Error("No private key loaded"); return null; } string algorithm = getAlgorithm(); @@ -238,6 +253,7 @@ public AsymmetricAlgorithm getPrivateKeyForXML() }catch(Exception e ) { this.error.setError("PK026", e.Message); + logger.Error("getPrivateKeyForXML", e); return null; } } @@ -245,10 +261,10 @@ public AsymmetricAlgorithm getPrivateKeyForXML() #else - /****System.Security.Cryptography.CryptographicException: The system cannot find the file specified.****/ - /****HACK****/ - //https://social.msdn.microsoft.com/Forums/vstudio/en-US/7ea48fd0-8d6b-43ed-b272-1a0249ae490f/systemsecuritycryptographycryptographicexception-the-system-cannot-find-the-file-specified?forum=clr#37d4d83d-0eb3-497a-af31-030f5278781a - CspParameters cspParameters = new CspParameters(); + /****System.Security.Cryptography.CryptographicException: The system cannot find the file specified.****/ + /****HACK****/ + //https://social.msdn.microsoft.com/Forums/vstudio/en-US/7ea48fd0-8d6b-43ed-b272-1a0249ae490f/systemsecuritycryptographycryptographicexception-the-system-cannot-find-the-file-specified?forum=clr#37d4d83d-0eb3-497a-af31-030f5278781a + CspParameters cspParameters = new CspParameters(); cspParameters.Flags = CspProviderFlags.UseMachineKeyStore; if (SecurityUtils.compareStrings(Config.SecurityApiGlobal.GLOBALKEYCOONTAINERNAME, "")) { @@ -275,6 +291,7 @@ public AsymmetricAlgorithm getPrivateKeyForXML() else { this.error.setError("PK012", "XML signature with ECDSA keys is not implemented on Net Framework"); + logger.Error("XML signature with ECDSA keys is not implemented on Net Framework"); return null; //https://stackoverflow.com/questions/27420789/sign-xml-with-ecdsa-and-sha256-in-net?rq=1 // https://www.powershellgallery.com/packages/Posh-ACME/2.6.0/Content/Private%5CConvertFrom-BCKey.ps1 @@ -287,6 +304,7 @@ public AsymmetricAlgorithm getPrivateKeyForXML() override public AsymmetricKeyParameter getAsymmetricKeyParameter() { + logger.Debug("getAsymmetricKeyParameter"); AsymmetricKeyParameter akp = null; //string alg = this.privateKeyInfo.PrivateKeyAlgorithm.Algorithm.Id; try @@ -296,6 +314,7 @@ public AsymmetricKeyParameter getAsymmetricKeyParameter() catch (Exception e) { this.error.setError("PK013", e.Message); + logger.Error("getAsymmetricKeyParameter", e); } return akp; } @@ -314,6 +333,7 @@ internal bool loadKeyFromFile(string path, string alias, string password) } private bool loadPrivateKeyFromFile(string path, string alias, string password) { + logger.Debug("loadPrivateKeyFromFile"); bool flag = false; if (SecurityUtils.extensionIs(path, ".pem") || SecurityUtils.extensionIs(path, ".key")) @@ -327,6 +347,7 @@ private bool loadPrivateKeyFromFile(string path, string alias, string password) if (SecurityUtils.extensionIs(path, ".jks")) { this.error.setError("PK014", "Java Key Stores not allowed on .Net applications"); + logger.Error("Java Key Stores not allowed on .Net applications"); //throw new Exception("Java Key Stores not allowed on .Net applications"); } if (flag) { setAlgorithm(); } @@ -341,10 +362,12 @@ private bool loadPrivateKeyFromFile(string path, string alias, string password) /// private bool loadPrivateKeyFromPKCS12File(string path, string password) { + logger.Debug("loadPrivateKeyFromPKCS12File"); bool flag = false; if (password == null) { - this.error.setError("PK008", "Alias and Password are required for PKCS12 keys"); + this.error.setError("PK008", "Password is required for PKCS12 keys"); + logger.Error("Password is required for PKCS12 keys"); return false; } Pkcs12Store pkcs12 = null; @@ -361,6 +384,7 @@ private bool loadPrivateKeyFromPKCS12File(string path, string password) catch(Exception e) { this.error.setError("PK015", e.Message); + logger.Error("loadPrivateKeyFromPKCS12File", e); //throw new FileLoadException(path + "not found or wrong password."); } @@ -383,6 +407,7 @@ private bool loadPrivateKeyFromPKCS12File(string path, string password) } this.error.setError("PK016", "Path not found"); + logger.Error("Path not found"); return flag; } @@ -394,6 +419,7 @@ private bool loadPrivateKeyFromPKCS12File(string path, string password) /// boolean true if loaded correctly private bool loadPrivateKeyFromPEMFile(string path) { + logger.Debug("loadPrivateKeyFromPEMFile"); bool flag = false; using (StreamReader streamReader = new StreamReader(path)) { @@ -418,6 +444,7 @@ private bool loadPrivateKeyFromPEMFile(string path) catch (Exception ex) { this.error.setError("PK017", ex.Message); + logger.Error("loadPrivateKeyFromPEMFile", ex); return false; } } @@ -433,6 +460,7 @@ private bool loadPrivateKeyFromPEMFile(string path) if (obj.GetType() == typeof(Pkcs8EncryptedPrivateKeyInfo)) { this.error.setError("PK018", "Encrypted key, remove the key password or use the adecuate function"); + logger.Error("Encrypted key, remove the key password or use the adecuate function"); flag = false; } if (obj.GetType() == typeof(AsymmetricCipherKeyPair)) @@ -447,6 +475,7 @@ private bool loadPrivateKeyFromPEMFile(string path) if (obj.GetType() == typeof(X509Certificate)) { this.error.setError("PK009", "The file contains a public key"); + logger.Error("The file contains a public key"); flag = false; @@ -470,7 +499,7 @@ private bool loadPrivateKeyFromPEMFile(string path) /// PrivateKeyInfo from AsymmetricKeyParameter private PrivateKeyInfo createPrivateKeyInfo(AsymmetricKeyParameter key) { - + logger.Debug("createPrivateKeyInfo"); if (key is DsaPrivateKeyParameters) { @@ -528,9 +557,11 @@ private PrivateKeyInfo createPrivateKeyInfo(AsymmetricKeyParameter key) return new PrivateKeyInfo(algID, keyStruct.ToAsn1Object()); } - this.error.setError("PK019", "Class provided is not convertible: " + key.GetType().FullName); + this.error.setError("PK019", String.Format("Class provided is not convertible: {0}", key.GetType().FullName)); + logger.Error(String.Format("Class provided is not convertible: {0}", key.GetType().FullName)); this.hasPrivateKey = false; - throw new ArgumentNullException("Class provided is not convertible: " + key.GetType().FullName); + throw new ArgumentNullException(String.Format("Class provided is not convertible: {0}", key.GetType().FullName)); + } @@ -538,9 +569,11 @@ private PrivateKeyInfo createPrivateKeyInfo(AsymmetricKeyParameter key) override public AsymmetricAlgorithm getAsymmetricAlgorithm() { + logger.Debug("getAsymmetricAlgorithm"); if (!this.hasPrivateKey) { this.error.setError("PK011", "No private key loaded"); + logger.Error("No private key loaded"); return null; } AsymmetricAlgorithm alg; @@ -592,6 +625,7 @@ public AsymmetricAlgorithm getAsymmetricAlgorithm() if (!System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Windows)) { this.error.setError("PK025", "ECDSA JWT signature not implemented for Net on Linux systems"); + logger.Error("ECDSA JWT signature not implemented for Net on Linux systems"); return null; } #endif @@ -611,12 +645,14 @@ public AsymmetricAlgorithm getAsymmetricAlgorithm() catch (Exception e) { this.error.setError("PK020", e.Message); + logger.Error("getAsymmetricAlgorithm", e); return null; } break; default: this.error.setError("PK021", "Unrecognized key type"); + logger.Error("Unrecognized key type"); return null; } if (alg != null) diff --git a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/SecurityAPICommons/Keys/SymmetricKeyType.cs b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/SecurityAPICommons/Keys/SymmetricKeyType.cs index dbe6565ff..af341376c 100644 --- a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/SecurityAPICommons/Keys/SymmetricKeyType.cs +++ b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/SecurityAPICommons/Keys/SymmetricKeyType.cs @@ -1,4 +1,5 @@ +using log4net; using SecurityAPICommons.Commons; using System; using System.Collections.Generic; @@ -14,6 +15,7 @@ namespace SecurityAPICommons.Keys [SecuritySafeCritical] public enum SymmetricKeyType { + #pragma warning disable CS1591 // Missing XML comment for publicly visible type or member NONE, GENERICRANDOM #pragma warning restore CS1591 // Missing XML comment for publicly visible type or member @@ -24,18 +26,21 @@ public enum SymmetricKeyType [SecuritySafeCritical] public static class SymmetricKeyTypeUtils { - /// - /// Mapping between string name and SymmetricKeyType enum representation - /// - /// string symmetricKeyType - /// Error type for error management - /// SymmetricKeyType enum representation - public static SymmetricKeyType getSymmetricKeyType(string symmetricKeyType, Error error) + private static readonly ILog logger = LogManager.GetLogger(typeof(SymmetricKeyTypeUtils)); + /// + /// Mapping between string name and SymmetricKeyType enum representation + /// + /// string symmetricKeyType + /// Error type for error management + /// SymmetricKeyType enum representation + public static SymmetricKeyType getSymmetricKeyType(string symmetricKeyType, Error error) { + logger.Debug("getSymmetricKeyType"); if (error == null) return SymmetricKeyType.NONE; if(symmetricKeyType == null) { error.setError("SK001", "Unrecognized key type"); + logger.Error("Unrecognized key type"); return SymmetricKeyType.NONE; } @@ -45,6 +50,7 @@ public static SymmetricKeyType getSymmetricKeyType(string symmetricKeyType, Erro return SymmetricKeyType.GENERICRANDOM; default: error.setError("SK001", "Unrecognized key type"); + logger.Error("Unrecognized key type"); return SymmetricKeyType.NONE; } } @@ -56,6 +62,7 @@ public static SymmetricKeyType getSymmetricKeyType(string symmetricKeyType, Erro /// string value of key type in string public static string valueOf(SymmetricKeyType symmetricKeyType, Error error) { + logger.Debug("valueOf"); if (error == null) return ""; switch (symmetricKeyType) { @@ -63,6 +70,7 @@ public static string valueOf(SymmetricKeyType symmetricKeyType, Error error) return "GENERICRANDOM"; default: error.setError("SK002", "Unrecognized key type"); + logger.Error("Unrecognized key type"); return ""; } } diff --git a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/SecurityAPICommons/SecurityAPICommons.csproj b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/SecurityAPICommons/SecurityAPICommons.csproj index 4a9c504e2..d21314467 100644 --- a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/SecurityAPICommons/SecurityAPICommons.csproj +++ b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/SecurityAPICommons/SecurityAPICommons.csproj @@ -14,4 +14,8 @@ + + + + \ No newline at end of file diff --git a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/SecurityAPICommons/Utils/SecurityUtils.cs b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/SecurityAPICommons/Utils/SecurityUtils.cs index 741e6ed04..0cd77f3d2 100644 --- a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/SecurityAPICommons/Utils/SecurityUtils.cs +++ b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/SecurityAPICommons/Utils/SecurityUtils.cs @@ -5,6 +5,7 @@ using System; using System.IO; using System.Security; +using log4net; namespace SecurityAPICommons.Utils { @@ -12,6 +13,8 @@ namespace SecurityAPICommons.Utils public static class SecurityUtils { + private static readonly ILog logger = LogManager.GetLogger(typeof(SecurityUtils)); + /// /// Compares two strings ignoring casing /// @@ -147,30 +150,33 @@ public static Stream StringToStream(String input, Error error) } } - public static bool validateStringInput(string name, string value, Error error) - { - if (value == null) - { - error.setError("SU005", String.Format("The parameter %s cannot be empty", name)); - return false; - } - if (value.Length == 0) - { - error.setError("SU006", String.Format("The parameter %s cannot be empty", name)); - return false; - } - return true; - } + public static bool validateStringInput(string classs, string method, string name, string value, Error error) + { + if (value == null) + { + error.setError("SU005", String.Format("The parameter %s cannot be empty", name)); + logger.Error(String.Format("Class: {0} Method: {1} - The parameter {2} cannot be empty", classs, method, name)); + return false; + } + if (value.Length == 0) + { + error.setError("SU006", String.Format("The parameter %s cannot be empty", name)); + logger.Error(String.Format("Class: {0} Method: {1} - The parameter {2} cannot be empty", classs, method, name)); + return false; + } + return true; + } - public static bool validateObjectInput(string name, Object value, Error error) - { - if (value == null) - { - error.setError("SU007", String.Format("The parameter %a cannot be empty", name)); - return false; - } - return true; - } + public static bool validateObjectInput(string classs, string method, string name, Object value, Error error) + { + if (value == null) + { + error.setError("SU007", String.Format("The parameter %a cannot be empty", name)); + logger.Error(String.Format("Class: {0} Method: {1} - The parameter {2} cannot be empty", classs, method, name)); + return false; + } + return true; + } } }