diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2023-04-04 12:49:47 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2023-04-04 12:49:47 +0700 |
commit | 6f9cc11b84ec08927f574fc870d26a7f297b3d58 (patch) | |
tree | f81d2a34d39ecb1acd7298db0b5932e7d35d9d2e /crypto/src | |
parent | HQC: Remove null check (potential side-channel) (diff) | |
download | BouncyCastle.NET-ed25519-6f9cc11b84ec08927f574fc870d26a7f297b3d58.tar.xz |
PKCS10: check for null/empty extension request value
Diffstat (limited to 'crypto/src')
-rw-r--r-- | crypto/src/pkcs/Pkcs10CertificationRequest.cs | 43 |
1 files changed, 26 insertions, 17 deletions
diff --git a/crypto/src/pkcs/Pkcs10CertificationRequest.cs b/crypto/src/pkcs/Pkcs10CertificationRequest.cs index 9256b91f3..dbaaa34f6 100644 --- a/crypto/src/pkcs/Pkcs10CertificationRequest.cs +++ b/crypto/src/pkcs/Pkcs10CertificationRequest.cs @@ -487,41 +487,50 @@ namespace Org.BouncyCastle.Pkcs try { attributePkcs = AttributePkcs.GetInstance(item); - } catch (ArgumentException ex) { throw new ArgumentException("encountered non PKCS attribute in extensions block", ex); } - if (attributePkcs.AttrType.Equals(PkcsObjectIdentifiers.Pkcs9AtExtensionRequest)) + if (PkcsObjectIdentifiers.Pkcs9AtExtensionRequest.Equals(attributePkcs.AttrType)) { X509ExtensionsGenerator generator = new X509ExtensionsGenerator(); - Asn1Sequence extensionSequence = Asn1Sequence.GetInstance(attributePkcs.AttrValues[0]); + var attrValues = attributePkcs.AttrValues; + if (attrValues == null || attrValues.Count == 0) + throw new InvalidOperationException("pkcs_9_at_extensionRequest present but has no value"); + Asn1Sequence extensionSequence = Asn1Sequence.GetInstance(attrValues[0]); - foreach (Asn1Encodable seqItem in extensionSequence) + try { - - Asn1Sequence itemSeq = Asn1Sequence.GetInstance(seqItem); - if (itemSeq.Count == 2) + foreach (Asn1Encodable seqItem in extensionSequence) { - generator.AddExtension(DerObjectIdentifier.GetInstance(itemSeq[0]), false, Asn1OctetString.GetInstance(itemSeq[1]).GetOctets()); - } - else if (itemSeq.Count == 3) - { - generator.AddExtension(DerObjectIdentifier.GetInstance(itemSeq[0]), DerBoolean.GetInstance(itemSeq[1]).IsTrue, Asn1OctetString.GetInstance(itemSeq[2]).GetOctets()); - } - else - { - throw new ArgumentException("incorrect sequence size of X509Extension got " + itemSeq.Count + " expected 2 or 3"); + Asn1Sequence itemSeq = Asn1Sequence.GetInstance(seqItem); + + if (itemSeq.Count == 2) + { + generator.AddExtension(DerObjectIdentifier.GetInstance(itemSeq[0]), false, Asn1OctetString.GetInstance(itemSeq[1]).GetOctets()); + } + else if (itemSeq.Count == 3) + { + bool critical = DerBoolean.GetInstance(itemSeq[1]).IsTrue; + generator.AddExtension(DerObjectIdentifier.GetInstance(itemSeq[0]), critical, Asn1OctetString.GetInstance(itemSeq[2]).GetOctets()); + } + else + { + throw new InvalidOperationException("incorrect sequence size of X509Extension got " + itemSeq.Count + " expected 2 or 3"); + } } } + catch (ArgumentException e) + { + throw new InvalidOperationException("asn1 processing issue: " + e.Message, e); + } return generator.Generate(); } - } } |