summary refs log tree commit diff
path: root/crypto/src
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2015-11-14 17:31:27 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2015-11-14 17:31:27 +0700
commit7ec76c089556414e135f9d16d1e58666145e8b15 (patch)
treef94653be1faf2fcd0269b04343c31f97495ab5a3 /crypto/src
parentMerge branch 'master' of git.bouncycastle.org:bc-csharp into pcl (diff)
parentCheck there is no trailing data in Asn1Object.FromByteArray (diff)
downloadBouncyCastle.NET-ed25519-7ec76c089556414e135f9d16d1e58666145e8b15.tar.xz
Merge branch 'master' of git.bouncycastle.org:bc-csharp into pcl
Diffstat (limited to 'crypto/src')
-rw-r--r--crypto/src/asn1/Asn1Object.cs13
-rw-r--r--crypto/src/crypto/tls/TlsUtilities.cs5
2 files changed, 12 insertions, 6 deletions
diff --git a/crypto/src/asn1/Asn1Object.cs b/crypto/src/asn1/Asn1Object.cs

index 08bd599c1..a86fdbb4a 100644 --- a/crypto/src/asn1/Asn1Object.cs +++ b/crypto/src/asn1/Asn1Object.cs
@@ -13,13 +13,18 @@ namespace Org.BouncyCastle.Asn1 public static Asn1Object FromByteArray( byte[] data) { - try + try { - return new Asn1InputStream(data).ReadObject(); + MemoryStream input = new MemoryStream(data, false); + Asn1InputStream asn1 = new Asn1InputStream(input, data.Length); + Asn1Object result = asn1.ReadObject(); + if (input.Position != input.Length) + throw new IOException("extra data found after object"); + return result; } catch (InvalidCastException) { - throw new IOException("cannot recognise object in stream"); + throw new IOException("cannot recognise object in byte array"); } } @@ -36,7 +41,7 @@ namespace Org.BouncyCastle.Asn1 } catch (InvalidCastException) { - throw new IOException("cannot recognise object in stream"); + throw new IOException("cannot recognise object in stream"); } } diff --git a/crypto/src/crypto/tls/TlsUtilities.cs b/crypto/src/crypto/tls/TlsUtilities.cs
index a8c8a2b28..26fb0d5e8 100644 --- a/crypto/src/crypto/tls/TlsUtilities.cs +++ b/crypto/src/crypto/tls/TlsUtilities.cs
@@ -529,11 +529,12 @@ namespace Org.BouncyCastle.Crypto.Tls public static Asn1Object ReadAsn1Object(byte[] encoding) { - Asn1InputStream asn1 = new Asn1InputStream(encoding); + MemoryStream input = new MemoryStream(encoding, false); + Asn1InputStream asn1 = new Asn1InputStream(input, encoding.Length); Asn1Object result = asn1.ReadObject(); if (null == result) throw new TlsFatalAlert(AlertDescription.decode_error); - if (null != asn1.ReadObject()) + if (input.Position != input.Length) throw new TlsFatalAlert(AlertDescription.decode_error); return result; }