From 4f0dbbe6381f6d878b1699507d933d05fb14cd4c Mon Sep 17 00:00:00 2001 From: Lex Li Date: Tue, 31 Oct 2023 03:46:28 -0400 Subject: [PATCH] Added a new test case. --- .../Security/AESPrivacyProviderTestFixture.cs | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/Tests/CSharpCore/Unit/Security/AESPrivacyProviderTestFixture.cs b/Tests/CSharpCore/Unit/Security/AESPrivacyProviderTestFixture.cs index 2b8184fe..70f31568 100644 --- a/Tests/CSharpCore/Unit/Security/AESPrivacyProviderTestFixture.cs +++ b/Tests/CSharpCore/Unit/Security/AESPrivacyProviderTestFixture.cs @@ -113,6 +113,43 @@ public void TestEncrypt2() Assert.Equal(ByteTool.Convert(original.ToBytes()), ByteTool.Convert(decrypted.ToBytes())); } + [Fact] + public void TestEncrypt3() + { + byte[] received = + ByteTool.Convert( + "04 35 CC AE 0C FA 1E 41 CC DD F8 BA 49 27 7E 47 C9 8D 73 63 3B 1A CE 56 97 2D CB 0A 2D DF A1 AC 0F B0 8E 3B 25 EF F1 B6 3B 76 3F 74 84 7C E6 C0 DC AE DE EC D9 9E 5F"); + OctetString engineId = new OctetString(ByteTool.Convert("80 00 1F 88 80 38 92 B3 6C 6C 89 40 65 00 00 00 00")); + + IPrivacyProvider priv; + if (AESPrivacyProviderBase.IsSupported) + { + priv = new AESPrivacyProvider(new OctetString("privkey1"), + new SHA1AuthenticationProvider(new OctetString("authkey1"))); + } + else + { + return; + } + + Scope scope = new Scope(engineId, OctetString.Empty, + new GetRequestPdu(282716518, + new List { new Variable(new ObjectIdentifier("1.3.6.1.2.1.1.1.0")) })); + SecurityParameters parameters = new SecurityParameters(engineId, new Integer32(0x0B), new Integer32(0x176), + new OctetString("usr-sha-aes"), new OctetString(new byte[12]), + new OctetString(ByteTool.Convert("FA 24 36 97 A4 79 E6 35"))); + var original = scope.GetData(VersionCode.V3); + ISnmpData data = priv.Encrypt(original, parameters); + Assert.Equal(SnmpType.OctetString, data.TypeCode); + var encrypted = ByteTool.Convert(data.ToBytes()); + Assert.Equal(ByteTool.Convert(received), encrypted); + + ISnmpData decrypted_received = priv.Decrypt(DataFactory.CreateSnmpData(received), parameters); + var recovered_received = ByteTool.Convert(decrypted_received.ToBytes()); + var recovered_encrypted = ByteTool.Convert(priv.Decrypt(data, parameters).ToBytes()); + Assert.Equal(recovered_received, recovered_encrypted); + } + #if NET6_0 [Theory] [MemberData(nameof(Data))]