From 5dcfe6cb354b58176f6f8b765335e8cf982bd72a Mon Sep 17 00:00:00 2001 From: Alexander Bauer Date: Tue, 12 Sep 2017 11:33:59 +0200 Subject: [PATCH] Fix RC2CBC Parameter parsing. Parameters are encoded as Sequence. See: https://tools.ietf.org/html/rfc3370#section-5.2 --- MimeKit/Cryptography/SecureMimeContext.cs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/MimeKit/Cryptography/SecureMimeContext.cs b/MimeKit/Cryptography/SecureMimeContext.cs index 49cae8312c..1b0fd7e8bd 100644 --- a/MimeKit/Cryptography/SecureMimeContext.cs +++ b/MimeKit/Cryptography/SecureMimeContext.cs @@ -833,17 +833,20 @@ internal protected static bool TryGetEncryptionAlgorithm (AlgorithmIdentifier id } if (identifier.Algorithm.Id == CmsEnvelopedGenerator.RC2Cbc) { - var param = (DerInteger) identifier.Parameters; - int bits = param.Value.IntValue; + // RC2CBCParameter see: https://tools.ietf.org/html/rfc3370#section-5.2 + var param = (DerSequence)identifier.Parameters; + + var rc2ParameterVersion = (DerInteger)param[0]; + int bits = rc2ParameterVersion.Value.IntValue; switch (bits) { - case 128: algorithm = EncryptionAlgorithm.RC2128; return true; - case 64: algorithm = EncryptionAlgorithm.RC264; return true; - case 40: algorithm = EncryptionAlgorithm.RC240; return true; + case 160: algorithm = EncryptionAlgorithm.RC240; return true; + case 120: algorithm = EncryptionAlgorithm.RC264; return true; + case 58: algorithm = EncryptionAlgorithm.RC2128; return true; } - } + } - algorithm = EncryptionAlgorithm.RC240; + algorithm = EncryptionAlgorithm.RC240; return false; }