You've already forked linux-packaging-mono
Imported Upstream version 5.8.0.22
Former-commit-id: df344e34b07851d296efb3e6604c8db42b6f7aa3
This commit is contained in:
parent
5f4a27cc8a
commit
7d05485754
@@ -52,7 +52,6 @@ using System.Runtime.InteropServices;
|
||||
[assembly: NeutralResourcesLanguage ("en-US")]
|
||||
|
||||
[assembly: AssemblyDelaySign (true)]
|
||||
[assembly: AssemblyKeyFile ("../mono.pub")]
|
||||
|
||||
[assembly: InternalsVisibleTo ("System, PublicKey=" + AssemblyRef.FrameworkPublicKeyFull2)]
|
||||
|
||||
|
@@ -5,6 +5,7 @@ include ../../build/rules.make
|
||||
LIBRARY = Mono.Security.dll
|
||||
LOCAL_MCS_FLAGS =
|
||||
LIB_REFS = bare/System
|
||||
KEYFILE = ../mono.pub
|
||||
LIB_MCS_FLAGS = -unsafe -nowarn:1030,3009
|
||||
TEST_MCS_FLAGS = $(LIB_MCS_FLAGS) -nowarn:169,219,618,672
|
||||
|
||||
|
@@ -1,96 +0,0 @@
|
||||
//
|
||||
// BufferOffsetSize.cs
|
||||
//
|
||||
// Author:
|
||||
// Martin Baulig <martin.baulig@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2014-2016 Xamarin Inc. (http://www.xamarin.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
using System;
|
||||
|
||||
namespace Mono.Security.Interface
|
||||
{
|
||||
public class BufferOffsetSize : SecretParameters, IBufferOffsetSize
|
||||
{
|
||||
public byte[] Buffer {
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public int Offset {
|
||||
get;
|
||||
internal set;
|
||||
}
|
||||
|
||||
public int Size {
|
||||
get { return EndOffset - Offset; }
|
||||
}
|
||||
|
||||
public int EndOffset {
|
||||
get;
|
||||
internal set;
|
||||
}
|
||||
|
||||
public BufferOffsetSize (byte[] buffer, int offset, int size)
|
||||
{
|
||||
Buffer = buffer;
|
||||
Offset = offset;
|
||||
EndOffset = offset + size;
|
||||
}
|
||||
|
||||
public BufferOffsetSize (byte[] buffer)
|
||||
: this (buffer, 0, buffer.Length)
|
||||
{
|
||||
}
|
||||
|
||||
public BufferOffsetSize (int size)
|
||||
: this (new byte [size])
|
||||
{
|
||||
}
|
||||
|
||||
public byte[] GetBuffer ()
|
||||
{
|
||||
var copy = new byte [Size];
|
||||
Array.Copy (Buffer, Offset, copy, 0, Size);
|
||||
return copy;
|
||||
}
|
||||
|
||||
public void TruncateTo (int newSize)
|
||||
{
|
||||
if (newSize > Size)
|
||||
throw new ArgumentException ("newSize");
|
||||
EndOffset = Offset + newSize;
|
||||
}
|
||||
|
||||
protected void SetBuffer (byte[] buffer, int offset, int size)
|
||||
{
|
||||
Buffer = buffer;
|
||||
Offset = offset;
|
||||
EndOffset = offset + size;
|
||||
}
|
||||
|
||||
protected override void Clear ()
|
||||
{
|
||||
Buffer = null;
|
||||
Offset = EndOffset = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,43 +0,0 @@
|
||||
//
|
||||
// IBufferOffsetSize.cs
|
||||
//
|
||||
// Author:
|
||||
// Martin Baulig <martin.baulig@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2015 Xamarin, Inc.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
namespace Mono.Security.Interface
|
||||
{
|
||||
public interface IBufferOffsetSize
|
||||
{
|
||||
byte[] Buffer {
|
||||
get;
|
||||
}
|
||||
|
||||
int Offset {
|
||||
get;
|
||||
}
|
||||
|
||||
int Size {
|
||||
get;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -27,6 +27,7 @@ using System;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Net.Security;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using SSA = System.Security.Authentication;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
@@ -70,8 +71,6 @@ namespace Mono.Security.Interface
|
||||
|
||||
Task AuthenticateAsServerAsync (X509Certificate serverCertificate, bool clientCertificateRequired, SSA.SslProtocols enabledSslProtocols, bool checkCertificateRevocation);
|
||||
|
||||
void Flush ();
|
||||
|
||||
int Read (byte[] buffer, int offset, int count);
|
||||
|
||||
void Write (byte[] buffer);
|
||||
@@ -86,6 +85,8 @@ namespace Mono.Security.Interface
|
||||
|
||||
void EndWrite (IAsyncResult asyncResult);
|
||||
|
||||
Task WriteAsync (byte[] buffer, int offset, int count, CancellationToken cancellationToken);
|
||||
|
||||
Task ShutdownAsync ();
|
||||
|
||||
TransportContext TransportContext {
|
||||
|
@@ -1,37 +0,0 @@
|
||||
//
|
||||
// IMonoTlsEventSink.cs
|
||||
//
|
||||
// Author:
|
||||
// Martin Baulig <martin.baulig@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2015 Xamarin, Inc.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
using System;
|
||||
|
||||
namespace Mono.Security.Interface
|
||||
{
|
||||
public interface IMonoTlsEventSink
|
||||
{
|
||||
void Error (Exception exception);
|
||||
|
||||
void ReceivedCloseNotify ();
|
||||
}
|
||||
}
|
||||
|
@@ -163,5 +163,14 @@ namespace Mono.Security.Interface
|
||||
X509CertificateCollection certificates, bool wantsChain, ref X509Chain chain,
|
||||
ref MonoSslPolicyErrors errors, ref int status11);
|
||||
#endregion
|
||||
|
||||
#region Misc
|
||||
|
||||
internal abstract bool SupportsCleanShutdown {
|
||||
get;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -167,6 +167,21 @@ namespace Mono.Security.Interface
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Internal Version
|
||||
|
||||
/*
|
||||
* Internal version number (not in any way related to the TLS Version).
|
||||
*
|
||||
* Used by the web-tests to check whether
|
||||
* the current Mono contains certain features or bug fixes.
|
||||
*
|
||||
* Negative version numbers are reserved for martin work branches.
|
||||
*
|
||||
*/
|
||||
internal const int InternalVersion = 1;
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -86,6 +86,13 @@ namespace Mono.Security.Interface
|
||||
get; set;
|
||||
}
|
||||
|
||||
/*
|
||||
* This is only supported if MonoTlsProvider.SupportsCleanShutdown is true.
|
||||
*/
|
||||
internal bool SendCloseNotify {
|
||||
get; set;
|
||||
}
|
||||
|
||||
/*
|
||||
* If you set this here, then it will override 'ServicePointManager.SecurityProtocol'.
|
||||
*/
|
||||
@@ -173,6 +180,7 @@ namespace Mono.Security.Interface
|
||||
EnabledProtocols = other.EnabledProtocols;
|
||||
EnabledCiphers = other.EnabledCiphers;
|
||||
CertificateValidationTime = other.CertificateValidationTime;
|
||||
SendCloseNotify = other.SendCloseNotify;
|
||||
if (other.TrustAnchors != null)
|
||||
TrustAnchors = new X509CertificateCollection (other.TrustAnchors);
|
||||
if (other.CertificateSearchPaths != null) {
|
||||
|
@@ -1,67 +0,0 @@
|
||||
//
|
||||
// SecretParameters.cs
|
||||
//
|
||||
// Author:
|
||||
// Martin Baulig <martin.baulig@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2014-2016 Xamarin Inc. (http://www.xamarin.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
using System;
|
||||
|
||||
namespace Mono.Security.Interface
|
||||
{
|
||||
public abstract class SecretParameters : IDisposable
|
||||
{
|
||||
protected abstract void Clear ();
|
||||
|
||||
bool disposed;
|
||||
|
||||
protected void CheckDisposed ()
|
||||
{
|
||||
if (disposed)
|
||||
throw new ObjectDisposedException (GetType ().Name);
|
||||
}
|
||||
|
||||
protected static void Clear (byte[] array)
|
||||
{
|
||||
Array.Clear (array, 0, array.Length);
|
||||
}
|
||||
|
||||
public void Dispose ()
|
||||
{
|
||||
Dispose (true);
|
||||
GC.SuppressFinalize (this);
|
||||
}
|
||||
|
||||
void Dispose (bool disposing)
|
||||
{
|
||||
if (!disposed) {
|
||||
disposed = true;
|
||||
Clear ();
|
||||
}
|
||||
}
|
||||
|
||||
~SecretParameters ()
|
||||
{
|
||||
Dispose (false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,86 +0,0 @@
|
||||
//
|
||||
// SecureBuffer.cs
|
||||
//
|
||||
// Author:
|
||||
// Martin Baulig <martin.baulig@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2014-2016 Xamarin Inc. (http://www.xamarin.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
using System;
|
||||
|
||||
namespace Mono.Security.Interface
|
||||
{
|
||||
public class SecureBuffer : SecretParameters, IBufferOffsetSize
|
||||
{
|
||||
byte[] buffer;
|
||||
|
||||
public byte[] Buffer {
|
||||
get {
|
||||
CheckDisposed ();
|
||||
return buffer;
|
||||
}
|
||||
}
|
||||
|
||||
public int Size {
|
||||
get {
|
||||
CheckDisposed ();
|
||||
return buffer != null ? buffer.Length : 0;
|
||||
}
|
||||
}
|
||||
|
||||
int IBufferOffsetSize.Offset {
|
||||
get { return 0; }
|
||||
}
|
||||
|
||||
public SecureBuffer (int size)
|
||||
{
|
||||
buffer = new byte [size];
|
||||
}
|
||||
|
||||
public SecureBuffer (byte[] buffer)
|
||||
{
|
||||
this.buffer = buffer;
|
||||
}
|
||||
|
||||
public byte[] StealBuffer ()
|
||||
{
|
||||
CheckDisposed ();
|
||||
var retval = this.buffer;
|
||||
this.buffer = null;
|
||||
return retval;
|
||||
}
|
||||
|
||||
public static SecureBuffer CreateCopy (byte[] buffer)
|
||||
{
|
||||
var copy = new byte [buffer.Length];
|
||||
Array.Copy (buffer, copy, buffer.Length);
|
||||
return new SecureBuffer (copy);
|
||||
}
|
||||
|
||||
protected override void Clear ()
|
||||
{
|
||||
if (buffer != null) {
|
||||
Array.Clear (buffer, 0, buffer.Length);
|
||||
buffer = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,334 +0,0 @@
|
||||
//
|
||||
// TlsBuffer.cs
|
||||
//
|
||||
// Author:
|
||||
// Martin Baulig <martin.baulig@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2014-2016 Xamarin Inc. (http://www.xamarin.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
using System;
|
||||
|
||||
namespace Mono.Security.Interface
|
||||
{
|
||||
public class TlsBuffer : SecretParameters
|
||||
{
|
||||
public int Position {
|
||||
get; set;
|
||||
}
|
||||
|
||||
public int Remaining {
|
||||
get { return Size - (Position - Offset); }
|
||||
}
|
||||
|
||||
public byte[] Buffer {
|
||||
get { return innerBuffer.Buffer; }
|
||||
}
|
||||
|
||||
public int Offset {
|
||||
get { return innerBuffer.Offset; }
|
||||
}
|
||||
|
||||
public int Size {
|
||||
get { return innerBuffer.Size; }
|
||||
}
|
||||
|
||||
public int EndOffset {
|
||||
get { return Offset + Size; }
|
||||
}
|
||||
|
||||
IBufferOffsetSize innerBuffer;
|
||||
|
||||
protected TlsBuffer ()
|
||||
: this (null, 0, 0)
|
||||
{
|
||||
}
|
||||
|
||||
public TlsBuffer (IBufferOffsetSize bos)
|
||||
{
|
||||
innerBuffer = bos;
|
||||
Position = bos.Offset;
|
||||
}
|
||||
|
||||
public TlsBuffer (byte[] buffer, int offset, int size)
|
||||
: this (new BufferOffsetSize (buffer, offset, size))
|
||||
{
|
||||
}
|
||||
|
||||
public TlsBuffer (byte[] buffer)
|
||||
: this (buffer, 0, buffer.Length)
|
||||
{
|
||||
}
|
||||
|
||||
public TlsBuffer (int size)
|
||||
: this (new byte [size], 0, size)
|
||||
{
|
||||
}
|
||||
|
||||
public byte ReadByte ()
|
||||
{
|
||||
if (Position >= EndOffset)
|
||||
throw new TlsException (AlertDescription.DecodeError, "Buffer overflow");
|
||||
return Buffer [Position++];
|
||||
}
|
||||
|
||||
public short ReadInt16 ()
|
||||
{
|
||||
if (Position + 1 >= EndOffset)
|
||||
throw new TlsException (AlertDescription.DecodeError, "Buffer overflow");
|
||||
var retval = (short)(Buffer [Position] << 8 | Buffer [Position + 1]);
|
||||
Position += 2;
|
||||
return retval;
|
||||
}
|
||||
|
||||
public int ReadInt24 ()
|
||||
{
|
||||
if (Position + 2 >= EndOffset)
|
||||
throw new TlsException (AlertDescription.DecodeError, "Buffer overflow");
|
||||
var retval = ((Buffer [Position] << 16) | (Buffer [Position+1] << 8) | Buffer [Position+2]);
|
||||
Position += 3;
|
||||
return retval;
|
||||
}
|
||||
|
||||
public int ReadInt32 ()
|
||||
{
|
||||
if (Position + 3 >= EndOffset)
|
||||
throw new TlsException (AlertDescription.DecodeError, "Buffer overflow");
|
||||
var retval = ((Buffer [Position] << 24) | (Buffer [Position+1] << 16) | (Buffer [Position+2] << 8) | Buffer [Position+3]);
|
||||
Position += 4;
|
||||
return retval;
|
||||
}
|
||||
|
||||
public TlsBuffer ReadBuffer (int length)
|
||||
{
|
||||
if (Position + length > EndOffset)
|
||||
throw new TlsException (AlertDescription.DecodeError, "Buffer overflow");
|
||||
var retval = new TlsBuffer (Buffer, Position, length);
|
||||
Position += length;
|
||||
return retval;
|
||||
}
|
||||
|
||||
public IBufferOffsetSize GetRemaining ()
|
||||
{
|
||||
return new BufferOffsetSize (Buffer, Position, Remaining);
|
||||
}
|
||||
|
||||
protected virtual void MakeRoomInternal (int size)
|
||||
{
|
||||
if (Position + size > EndOffset)
|
||||
throw new TlsException (AlertDescription.DecodeError, "Buffer overflow");
|
||||
}
|
||||
|
||||
public void Write (byte value)
|
||||
{
|
||||
MakeRoomInternal (1);
|
||||
Buffer [Position++] = value;
|
||||
}
|
||||
|
||||
public void Write (short value)
|
||||
{
|
||||
MakeRoomInternal (2);
|
||||
WriteInt16 (Buffer, Position, value);
|
||||
Position += 2;
|
||||
}
|
||||
|
||||
public static void WriteInt16 (byte[] buffer, int offset, short value)
|
||||
{
|
||||
buffer[offset] = ((byte)(value >> 8));
|
||||
buffer[offset+1] = ((byte)value);
|
||||
}
|
||||
|
||||
public void Write (int value)
|
||||
{
|
||||
MakeRoomInternal (4);
|
||||
WriteInt32 (Buffer, Position, value);
|
||||
Position += 4;
|
||||
}
|
||||
|
||||
public void WriteInt24 (int value)
|
||||
{
|
||||
MakeRoomInternal (3);
|
||||
WriteInt24 (Buffer, Position, value);
|
||||
Position += 3;
|
||||
}
|
||||
|
||||
#pragma warning disable 3001
|
||||
public void Write (ulong value)
|
||||
#pragma warning restore 3001
|
||||
{
|
||||
MakeRoomInternal (8);
|
||||
WriteInt64 (Buffer, Position, value);
|
||||
Position += 8;
|
||||
}
|
||||
|
||||
public static void WriteInt24 (byte[] buffer, int offset, int value)
|
||||
{
|
||||
buffer[offset] = ((byte)(value >> 16));
|
||||
buffer[offset+1] = ((byte)(value >> 8));
|
||||
buffer[offset+2] = ((byte)value);
|
||||
}
|
||||
|
||||
public static void WriteInt32 (byte[] buffer, int offset, int value)
|
||||
{
|
||||
buffer[offset] = ((byte)(value >> 24));
|
||||
buffer[offset+1] = ((byte)(value >> 16));
|
||||
buffer[offset+2] = ((byte)(value >> 8));
|
||||
buffer[offset+3] = ((byte)value);
|
||||
}
|
||||
|
||||
#pragma warning disable 3001
|
||||
public static void WriteInt64 (byte[] buffer, int offset, ulong value)
|
||||
#pragma warning restore 3001
|
||||
{
|
||||
buffer[offset] = (byte) (value >> 56);
|
||||
buffer[offset+1] = (byte) (value >> 48);
|
||||
buffer[offset+2] = (byte) (value >> 40);
|
||||
buffer[offset+3] = (byte) (value >> 32);
|
||||
buffer[offset+4] = (byte) (value >> 24);
|
||||
buffer[offset+5] = (byte) (value >> 16);
|
||||
buffer[offset+6] = (byte) (value >> 8);
|
||||
buffer[offset+7] = (byte) value;
|
||||
}
|
||||
|
||||
public void Write (byte[] buffer)
|
||||
{
|
||||
Write (buffer, 0, buffer.Length);
|
||||
}
|
||||
|
||||
public void Write (byte[] buffer, int offset, int size)
|
||||
{
|
||||
MakeRoomInternal (size);
|
||||
Array.Copy (buffer, offset, Buffer, Position, size);
|
||||
Position += size;
|
||||
}
|
||||
|
||||
public void Write (IBufferOffsetSize buffer)
|
||||
{
|
||||
Write (buffer.Buffer, buffer.Offset, buffer.Size);
|
||||
}
|
||||
|
||||
public SecureBuffer ReadSecureBuffer (int count)
|
||||
{
|
||||
return new SecureBuffer (ReadBytes (count));
|
||||
}
|
||||
|
||||
public byte[] ReadBytes (int count)
|
||||
{
|
||||
if (Position + count > EndOffset)
|
||||
throw new TlsException (AlertDescription.DecodeError, "Buffer overflow");
|
||||
var retval = new byte [count];
|
||||
Array.Copy (Buffer, Position, retval, 0, count);
|
||||
Position += count;
|
||||
return retval;
|
||||
}
|
||||
|
||||
internal static bool Compare (SecureBuffer buffer1, SecureBuffer buffer2)
|
||||
{
|
||||
if (buffer1 == null || buffer2 == null)
|
||||
return false;
|
||||
|
||||
if (buffer1.Size != buffer2.Size)
|
||||
return false;
|
||||
|
||||
for (int i = 0; i < buffer1.Size; i++) {
|
||||
if (buffer1.Buffer [i] != buffer2.Buffer [i])
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool Compare (IBufferOffsetSize buffer1, IBufferOffsetSize buffer2)
|
||||
{
|
||||
if (buffer1 == null || buffer2 == null)
|
||||
return false;
|
||||
|
||||
if (buffer1.Size != buffer2.Size)
|
||||
return false;
|
||||
|
||||
for (int i = 0; i < buffer1.Size; i++) {
|
||||
if (buffer1.Buffer [buffer1.Offset + i] != buffer2.Buffer [buffer2.Offset + i])
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool Compare (byte[] buffer1, byte[] buffer2)
|
||||
{
|
||||
if (buffer1 == null || buffer2 == null)
|
||||
return false;
|
||||
|
||||
return Compare (buffer1, 0, buffer1.Length, buffer2, 0, buffer2.Length);
|
||||
}
|
||||
|
||||
public static bool Compare (byte[] buffer1, int offset1, int size1, byte[] buffer2, int offset2, int size2)
|
||||
{
|
||||
if (buffer1 == null || buffer2 == null)
|
||||
return false;
|
||||
|
||||
if (size1 != size2)
|
||||
return false;
|
||||
|
||||
for (int i = 0; i < size1; i++) {
|
||||
if (buffer1 [offset1 + i] != buffer2 [offset2 + i])
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
public static int ConstantTimeCompare (byte[] buffer1, int offset1, int size1, byte[] buffer2, int offset2, int size2)
|
||||
{
|
||||
int status = 0;
|
||||
int effectiveSize;
|
||||
if (size1 < size2) {
|
||||
status--;
|
||||
effectiveSize = size1;
|
||||
} else if (size2 < size1) {
|
||||
status--;
|
||||
effectiveSize = size2;
|
||||
} else {
|
||||
effectiveSize = size1;
|
||||
}
|
||||
|
||||
for (int i = 0; i < effectiveSize; i++) {
|
||||
if (buffer1 [offset1 + i] != buffer2 [offset2 + i])
|
||||
status--;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
protected void SetBuffer (byte[] buffer, int offset, int size)
|
||||
{
|
||||
innerBuffer = new BufferOffsetSize (buffer, offset, size);
|
||||
}
|
||||
|
||||
protected override void Clear ()
|
||||
{
|
||||
var disposable = innerBuffer as IDisposable;
|
||||
if (disposable != null)
|
||||
disposable.Dispose ();
|
||||
innerBuffer = null;
|
||||
Position = 0;
|
||||
}
|
||||
|
||||
public static readonly byte[] EmptyArray = new byte [0];
|
||||
}
|
||||
}
|
||||
|
@@ -1,119 +0,0 @@
|
||||
//
|
||||
// TlsMultiBuffer.cs
|
||||
//
|
||||
// Author:
|
||||
// Martin Baulig <martin.baulig@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2014-2016 Xamarin Inc. (http://www.xamarin.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
using System;
|
||||
|
||||
namespace Mono.Security.Interface
|
||||
{
|
||||
public class TlsMultiBuffer
|
||||
{
|
||||
MemoryChunk first, last;
|
||||
|
||||
private class MemoryChunk : BufferOffsetSize
|
||||
{
|
||||
public MemoryChunk next;
|
||||
|
||||
public MemoryChunk (byte[] buffer, int offset, int size)
|
||||
: base (buffer, offset, size)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsEmpty {
|
||||
get { return first == null; }
|
||||
}
|
||||
|
||||
public bool IsSingle {
|
||||
get { return first != null && first.next == null; }
|
||||
}
|
||||
|
||||
public void Add (TlsBuffer buffer)
|
||||
{
|
||||
Add (buffer.Buffer, buffer.Offset, buffer.Size);
|
||||
}
|
||||
|
||||
public void Add (byte[] buffer)
|
||||
{
|
||||
Add (buffer, 0, buffer.Length);
|
||||
}
|
||||
|
||||
public void Add (byte[] buffer, int offset, int size)
|
||||
{
|
||||
var chunk = new MemoryChunk (buffer, offset, size);
|
||||
if (last == null)
|
||||
first = last = chunk;
|
||||
else {
|
||||
last.next = chunk;
|
||||
last = chunk;
|
||||
}
|
||||
}
|
||||
|
||||
public BufferOffsetSize[] GetBufferArray ()
|
||||
{
|
||||
int count = 0;
|
||||
for (var ptr = first; ptr != null; ptr = ptr.next)
|
||||
count++;
|
||||
var array = new BufferOffsetSize [count];
|
||||
count = 0;
|
||||
for (var ptr = first; ptr != null; ptr = ptr.next)
|
||||
array [count++] = ptr;
|
||||
return array;
|
||||
}
|
||||
|
||||
public void Clear ()
|
||||
{
|
||||
for (var ptr = first; ptr != null; ptr = ptr.next)
|
||||
ptr.Dispose ();
|
||||
first = last = null;
|
||||
}
|
||||
|
||||
public BufferOffsetSize GetBuffer ()
|
||||
{
|
||||
int totalSize = 0;
|
||||
for (var ptr = first; ptr != null; ptr = ptr.next)
|
||||
totalSize += ptr.Size;
|
||||
|
||||
var outBuffer = new BufferOffsetSize (new byte [totalSize]);
|
||||
int offset = 0;
|
||||
for (var ptr = first; ptr != null; ptr = ptr.next) {
|
||||
Buffer.BlockCopy (ptr.Buffer, ptr.Offset, outBuffer.Buffer, offset, ptr.Size);
|
||||
offset += ptr.Size;
|
||||
}
|
||||
return outBuffer;
|
||||
}
|
||||
|
||||
public BufferOffsetSize StealBuffer ()
|
||||
{
|
||||
if (IsSingle) {
|
||||
var retval = first;
|
||||
first = last = null;
|
||||
return retval;
|
||||
}
|
||||
|
||||
return GetBuffer ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -137,7 +137,7 @@ namespace Mono.Security.Protocol.Tls.Handshake.Client
|
||||
return null;
|
||||
|
||||
foreach (X509Certificate certificate in this.Context.ClientSettings.Certificates) {
|
||||
if (cert.GetName () == cert.GetIssuerName ())
|
||||
if (certificate.GetName () == cert.GetIssuerName ())
|
||||
return certificate;
|
||||
}
|
||||
return null;
|
||||
|
@@ -387,7 +387,7 @@ namespace Mono.Security.X509 {
|
||||
byte[] nullPassword = {0, 0};
|
||||
calculatedMac = MAC(nullPassword, macSalt.Value, _iterations, authSafeData);
|
||||
if (!Compare (macValue, calculatedMac))
|
||||
throw new CryptographicException ("Invalid MAC - file may have been tampe red!");
|
||||
throw new CryptographicException ("Invalid MAC - file may have been tampered with!");
|
||||
_password = nullPassword;
|
||||
}
|
||||
}
|
||||
|
@@ -142,8 +142,6 @@
|
||||
./Mono.Security.Interface/CipherSuiteCode.cs
|
||||
./Mono.Security.Interface/ExchangeAlgorithmType.cs
|
||||
./Mono.Security.Interface/HashAlgorithmType.cs
|
||||
./Mono.Security.Interface/IBufferOffsetSize.cs
|
||||
./Mono.Security.Interface/IMonoTlsEventSink.cs
|
||||
./Mono.Security.Interface/IMonoSslStream.cs
|
||||
./Mono.Security.Interface/MonoTlsConnectionInfo.cs
|
||||
./Mono.Security.Interface/MonoTlsProvider.cs
|
||||
@@ -153,8 +151,3 @@
|
||||
./Mono.Security.Interface/TlsProtocolCode.cs
|
||||
./Mono.Security.Interface/TlsProtocols.cs
|
||||
|
||||
./Mono.Security.Interface/BufferOffsetSize.cs
|
||||
./Mono.Security.Interface/SecretParameters.cs
|
||||
./Mono.Security.Interface/SecureBuffer.cs
|
||||
./Mono.Security.Interface/TlsBuffer.cs
|
||||
./Mono.Security.Interface/TlsMultiBuffer.cs
|
||||
|
Reference in New Issue
Block a user