mirror of
https://github.com/BepInEx/mono.git
synced 2026-11-16 11:21:08 -10:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e66d9abbb2 | ||
|
|
1f4613aa1a | ||
|
|
d092ad186f | ||
|
|
c6605763a3 | ||
|
|
0fb4040ef1 | ||
|
|
fea2566b12 | ||
|
|
f3c9015ec4 | ||
|
|
0429840e5b | ||
|
|
28d71e9727 | ||
|
|
f1bca3dc5b | ||
|
|
fbc487ff42 | ||
|
|
72c4a0ca08 | ||
|
|
9685274a8a | ||
|
|
5cb0e59bea | ||
|
|
fc364332ff | ||
|
|
ff204dae30 | ||
|
|
9b466abc49 | ||
|
|
ab058f8e49 | ||
|
|
cb4c3ca997 | ||
|
|
0dd35e9d64 | ||
|
|
7ba4e9e7b1 | ||
|
|
71277e78f6 | ||
|
|
c61b3bd6d9 | ||
|
|
7d78877800 | ||
|
|
87a052504b | ||
|
|
26e759903e | ||
|
|
12ca38606d | ||
|
|
0ab383de1e | ||
|
|
132135cb22 | ||
|
|
5066d707ac | ||
|
|
794f7a7612 | ||
|
|
fe516ba0bd | ||
|
|
b2acee0ade | ||
|
|
8af44d2b16 | ||
|
|
f4cf17d61d | ||
|
|
8f3ddb716e | ||
|
|
a4cd00b333 | ||
|
|
cb6a2fc7ff | ||
|
|
c81fe5e84d | ||
|
|
1cf175e95c | ||
|
|
01d1582fb7 | ||
|
|
f177485aaf | ||
|
|
1d4fc17faa | ||
|
|
dc29ba37a6 | ||
|
|
8bcbd3cc89 | ||
|
|
24901ef720 | ||
|
|
b263d37e15 | ||
|
|
56267e8476 | ||
|
|
1afb931de6 | ||
|
|
63b57ba7a1 | ||
|
|
cbeae56621 | ||
|
|
f527b26e19 | ||
|
|
ebee14deca | ||
|
|
929575bb0e | ||
|
|
4fe608c216 | ||
|
|
6b8abfeb7c | ||
|
|
000682fe19 | ||
|
|
282e0fb6d3 | ||
|
|
4cadbfc272 | ||
|
|
2071615b87 | ||
|
|
cbc738c44d | ||
|
|
7f9739d414 | ||
|
|
4432d94f47 | ||
|
|
84a67e67e0 | ||
|
|
3d2159b391 | ||
|
|
2cc5ff0ef3 | ||
|
|
ab5dc2d67e | ||
|
|
b339b6677c | ||
|
|
a6db6112ca | ||
|
|
fd2303ecb6 | ||
|
|
490cc373e4 | ||
|
|
b65d1a9ffc | ||
|
|
8531639386 | ||
|
|
25ef6061fd | ||
|
|
066fde97d3 | ||
|
|
28a417c2c0 | ||
|
|
c97a3fcfd2 | ||
|
|
3acee7af00 | ||
|
|
b6cd01f017 | ||
|
|
67a2f14e73 | ||
|
|
8043db4c77 | ||
|
|
252415606d | ||
|
|
50f2938561 | ||
|
|
6425f06ff6 | ||
|
|
485d5205f9 | ||
|
|
582c5d77f0 | ||
|
|
bda280c5e8 | ||
|
|
287f4303f3 | ||
|
|
48d6bff3ae | ||
|
|
ad6ef5f4bc | ||
|
|
dd46212fc2 | ||
|
|
41ecc70a69 | ||
|
|
e9d3a69282 | ||
|
|
e7ce1807d7 | ||
|
|
eb7e8d4af8 | ||
|
|
94651df9ed | ||
|
|
d320c3a40a | ||
|
|
97d59f280a | ||
|
|
7f68119da8 | ||
|
|
9b3d1a60fc | ||
|
|
75aeec5fb9 | ||
|
|
a625b98e26 | ||
|
|
07ef3c251b | ||
|
|
fd85ac4fd1 | ||
|
|
667dcaa655 | ||
|
|
d6ba1ed4fc | ||
|
|
5b035af74a | ||
|
|
b69e232073 | ||
|
|
edd2d56a32 | ||
|
|
d4d81a3e02 | ||
|
|
1d1ec7d504 | ||
|
|
5fc8e28ffa | ||
|
|
de60f3b49e | ||
|
|
7f560b39c8 | ||
|
|
73c2e4322e | ||
|
|
13166f48a8 | ||
|
|
e5b06307ca | ||
|
|
be1b671b09 | ||
|
|
817a7e7bf7 | ||
|
|
6279df6d70 | ||
|
|
cbc419bb3e | ||
|
|
39a8a8f8c0 | ||
|
|
3c9a821c7e | ||
|
|
bb900edab1 | ||
|
|
36e3d93a52 | ||
|
|
4b49283a9c | ||
|
|
00ef078380 | ||
|
|
0a3ea22257 | ||
|
|
04419ee95b | ||
|
|
fc339c2777 | ||
|
|
35b2b68bdf | ||
|
|
009d1279a2 | ||
|
|
d8eb6c91a2 | ||
|
|
d451def6a5 | ||
|
|
f95909190c | ||
|
|
fc65bbe329 | ||
|
|
eb6386af15 | ||
|
|
8236cbe950 | ||
|
|
3505d310df | ||
|
|
c0c8d0bec4 | ||
|
|
3872a400b2 | ||
|
|
a6612b4c64 | ||
|
|
4db9028cb9 | ||
|
|
b6e231d521 | ||
|
|
1ec5966c89 | ||
|
|
9280bb5e19 | ||
|
|
d470d1abbf | ||
|
|
0e4d13f5b7 | ||
|
|
933ceae45c | ||
|
|
2f1b9e8aac | ||
|
|
f03dbfcae2 | ||
|
|
d9211fcb50 | ||
|
|
153467c0c6 | ||
|
|
a1cac02732 | ||
|
|
7be144c0b7 | ||
|
|
71936252fe | ||
|
|
ab0791102f | ||
|
|
be24ada60a | ||
|
|
9c991786ac | ||
|
|
019a83f88f | ||
|
|
33697c0568 | ||
|
|
fbb82d3923 | ||
|
|
733b51587e | ||
|
|
f66e71e01b | ||
|
|
262128c941 | ||
|
|
eeb68ca307 | ||
|
|
6471bbd6ef | ||
|
|
96a2b36e82 | ||
|
|
7a704f61c9 | ||
|
|
39150458f0 | ||
|
|
0b522087c2 | ||
|
|
911cc1d438 | ||
|
|
e4b08aa7c9 | ||
|
|
2db07ca754 | ||
|
|
0d8219ea4a | ||
|
|
a38a8e4ad4 | ||
|
|
d0b9d91817 | ||
|
|
fd6d8198f7 | ||
|
|
54260048cc | ||
|
|
34ba13146f | ||
|
|
00ea5f1e17 | ||
|
|
e75b24b807 | ||
|
|
ecf65f0093 | ||
|
|
35cb8bac8a | ||
|
|
33074493a0 | ||
|
|
c5d7419186 | ||
|
|
ccf4d32e12 | ||
|
|
89014568b7 | ||
|
|
9161e4e5a9 | ||
|
|
6ac4a68c46 | ||
|
|
1b5e0f7331 | ||
|
|
c8863e1d31 | ||
|
|
dd951e909a | ||
|
|
3c21a0f3dd | ||
|
|
f031c8fba3 | ||
|
|
442d000b6c | ||
|
|
2cdb7e8648 | ||
|
|
e72203782b | ||
|
|
00e3c897d5 | ||
|
|
52a5acbd88 | ||
|
|
778e04f2d9 | ||
|
|
93ecaeb2c6 | ||
|
|
49df11fd5f | ||
|
|
c8c8b16bfd | ||
|
|
6f83951d1c | ||
|
|
f2ae4658f9 | ||
|
|
faf4fe66af | ||
|
|
998759345f | ||
|
|
c88d2cce1f | ||
|
|
3e589e2c39 | ||
|
|
4c944bc86e | ||
|
|
d3e6c9d17f | ||
|
|
7379ac1bfb | ||
|
|
2a029615aa | ||
|
|
9c345b1b02 | ||
|
|
074a1228cf | ||
|
|
e3596928d8 | ||
|
|
ac71acfd52 | ||
|
|
8909c17d9c | ||
|
|
e5d16f01fd | ||
|
|
9874928b85 | ||
|
|
9e99e20001 | ||
|
|
b3e79ebc05 |
No files matched your search
@@ -26,9 +26,6 @@
|
||||
[submodule "external/nuget-buildtasks"]
|
||||
path = external/nuget-buildtasks
|
||||
url = git://github.com/mono/NuGet.BuildTasks
|
||||
[submodule "external/buildtools"]
|
||||
path = external/buildtools
|
||||
url = git://github.com/mono/buildtools.git
|
||||
[submodule "external/cecil-legacy"]
|
||||
path = external/cecil-legacy
|
||||
url = git://github.com/mono/cecil.git
|
||||
|
||||
+9
-4
@@ -1,7 +1,7 @@
|
||||
# Process this file with autoconf to produce a configure script.
|
||||
#AC_PREREQ([2.62])
|
||||
|
||||
AC_INIT(mono, [5.3.0],
|
||||
AC_INIT(mono, [5.4.1],
|
||||
[http://bugzilla.xamarin.com/enter_bug.cgi?classification=Mono])
|
||||
|
||||
AC_CONFIG_SRCDIR([README.md])
|
||||
@@ -40,8 +40,8 @@ MONO_VERSION_BUILD=`echo $VERSION | cut -d . -f 3`
|
||||
# This can be reset to 0 when Mono's version number is bumped
|
||||
# since it's part of the corlib version (the prefix '1' in the full
|
||||
# version number is to ensure the number isn't treated as octal in C)
|
||||
MONO_CORLIB_COUNTER=2
|
||||
MONO_CORLIB_VERSION=`printf "1%02d%02d%02d%03d" $MONO_VERSION_MAJOR $MONO_VERSION_MINOR $MONO_VERSION_BUILD $MONO_CORLIB_COUNTER`
|
||||
MONO_CORLIB_COUNTER=3
|
||||
MONO_CORLIB_VERSION=`printf "1%02d%02d%02d%03d" $MONO_VERSION_MAJOR $MONO_VERSION_MINOR 0 $MONO_CORLIB_COUNTER`
|
||||
|
||||
AC_DEFINE_UNQUOTED(MONO_CORLIB_VERSION,$MONO_CORLIB_VERSION,[Version of the corlib-runtime interface])
|
||||
AC_SUBST(MONO_CORLIB_VERSION)
|
||||
@@ -3534,6 +3534,11 @@ fi
|
||||
|
||||
AM_CONDITIONAL(ENABLE_INTERPRETER, [test x$enable_interpreter = xyes])
|
||||
|
||||
if test "x$enable_interpreter" = "xyes" || test "x$mono_feature_disable_jit" != "xyes"; then
|
||||
AC_DEFINE(HAVE_ONLINE_VES, 1, [Some VES is available at runtime])
|
||||
fi
|
||||
|
||||
AM_CONDITIONAL(HAVE_ONLINE_VES, [test x$enable_interpreter = xyes] || [test x$mono_feature_disable_jit != xyes])
|
||||
|
||||
dnl
|
||||
dnl Simple Generational checks (sgen)
|
||||
@@ -4135,7 +4140,7 @@ AC_SUBST(mono_build_root)
|
||||
mono_runtime=mono/mini/mono
|
||||
AC_SUBST(mono_runtime)
|
||||
|
||||
CSC_LOCATION=`cd $srcdir && pwd`/external/roslyn-binaries/Microsoft.Net.Compilers/Microsoft.Net.Compilers.2.3.0/tools/csc.exe
|
||||
CSC_LOCATION=`cd $srcdir && pwd`/external/roslyn-binaries/Microsoft.Net.Compilers/Microsoft.Net.Compilers.2.3.1/tools/csc.exe
|
||||
|
||||
if test $csc_compiler = mcs; then
|
||||
CSC=$mcs_topdir/class/lib/build/mcs.exe
|
||||
|
||||
Vendored
+1
-1
Submodule external/api-snapshot updated: c0de20bce4...b09033be33.
Vendored
+1
-1
Submodule external/bockbuild updated: fe467c0593...0efdb371e6.
Vendored
-1
Submodule external/buildtools deleted from b5cc6e6ab5.
Vendored
+1
-1
Submodule external/cecil updated: f64903c0e0...c0eb983dac.
Vendored
+1
-1
Submodule external/corefx updated: e49886bd09...959fdbd00a.
Vendored
+1
-1
Submodule external/linker updated: 21e445c26c...99354bf5c1.
Vendored
+1
-1
Submodule external/nuget-buildtasks updated: 8d307472ea...b58ba42823.
Vendored
+1
-1
Submodule external/roslyn-binaries updated: 98069dbb17...1904c7d068.
Vendored
+1
-1
Submodule external/xunit-binaries updated: b8e20d265b...d4433b0972.
+10
@@ -181,6 +181,16 @@ Gives the path for the temporary LLVM bitcode file created during AOT.
|
||||
.I info
|
||||
Print the architecture the AOT in this copy of Mono targets and quit.
|
||||
.TP
|
||||
.I interp
|
||||
Generates all required wrappers, so that it is possible to run --interpreter without
|
||||
any code generation at runtime. This option only makes sense with \fBmscorlib.dll\fR.
|
||||
Embedders can set
|
||||
|
||||
.nf
|
||||
mono_jit_set_aot_mode (MONO_AOT_MODE_INTERP);
|
||||
.fi
|
||||
.ne
|
||||
.TP
|
||||
.I ld-flags
|
||||
Additional flags to pass to the C linker (if the current AOT mode calls for invoking it).
|
||||
.TP
|
||||
|
||||
@@ -20,9 +20,10 @@ TEST_RUNTIME_WRAPPERS_PATH = $(shell dirname $(RUNTIME))/_tmpinst/bin
|
||||
ifndef NO_TEST
|
||||
|
||||
test_nunit_lib = nunitlite.dll
|
||||
xunit_core := xunit.core xunit.abstractions xunit.assert
|
||||
xunit_core := xunit.core xunit.abstractions xunit.assert Xunit.NetCore.Extensions
|
||||
xunit_deps := System.Runtime
|
||||
xunit_class_deps := Xunit.NetCore.Extensions
|
||||
xunit_src := $(patsubst %,$(topdir)/../external/xunit-binaries/%,BenchmarkAttribute.cs BenchmarkDiscover.cs)
|
||||
xunit_class_deps :=
|
||||
|
||||
xunit_libs_ref = $(patsubst %,-r:$(topdir)/../external/xunit-binaries/%.dll,$(xunit_core))
|
||||
xunit_libs_ref += $(patsubst %,-r:$(topdir)/class/lib/$(PROFILE)/Facades/%.dll,$(xunit_deps))
|
||||
@@ -89,9 +90,6 @@ endif
|
||||
|
||||
tests_CLEAN_FILES += $(topdir)/build/deps/nunit-$(PROFILE).stamp
|
||||
|
||||
$(topdir)/class/lib/$(PROFILE)/$(PARENT_PROFILE)Xunit.NetCore.Extensions.dll:
|
||||
$(MAKE) -C $(topdir)/class/Xunit.NetCore.Extensions
|
||||
|
||||
endif
|
||||
|
||||
test_assemblies :=
|
||||
@@ -222,8 +220,8 @@ run-xunit-test-lib: xunit-test-local
|
||||
$$ok
|
||||
@rm -f xunit.execution.desktop.dll
|
||||
|
||||
$(xunit_test_lib): $(the_assembly) $(xtest_response) $(xunit_libs_dep)
|
||||
$(TEST_COMPILE) $(LIBRARY_FLAGS) $(XTEST_LIB_FLAGS) -target:library -out:$@ $(xtest_flags) @$(xtest_response)
|
||||
$(xunit_test_lib): $(the_assembly) $(xtest_response) $(xunit_libs_dep) $(xunit_src)
|
||||
$(TEST_COMPILE) $(LIBRARY_FLAGS) $(XTEST_LIB_FLAGS) -target:library -out:$@ $(xtest_flags) @$(xtest_response) $(xunit_src)
|
||||
|
||||
xtest_response_preprocessed = $(xtest_response)_preprocessed
|
||||
|
||||
|
||||
@@ -86,6 +86,8 @@ namespace Mono.Security.Interface
|
||||
|
||||
void EndWrite (IAsyncResult asyncResult);
|
||||
|
||||
Task ShutdownAsync ();
|
||||
|
||||
TransportContext TransportContext {
|
||||
get;
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ Mono.Security.Cryptography/PKCS8Test.cs
|
||||
Mono.Security.Cryptography/RSAManagedTest.cs
|
||||
Mono.Security.Cryptography/SHA224ManagedTest.cs
|
||||
Mono.Security.Cryptography/SHA224Test.cs
|
||||
Mono.Security.Interface/TestProvider.cs
|
||||
Mono.Security.Protocol.Ntlm/ChallengeResponseTest.cs
|
||||
Mono.Security.Protocol.Ntlm/MessageBaseTest.cs
|
||||
Mono.Security.Protocol.Ntlm/Type1MessageTest.cs
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
//
|
||||
// TestProvider.cs
|
||||
//
|
||||
// Author:
|
||||
// Martin Baulig <[email protected]>
|
||||
//
|
||||
// Copyright (c) 2017 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;
|
||||
using System.IO;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
|
||||
using Mono.Security;
|
||||
using Mono.Security.Interface;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace MonoTests.Mono.Security
|
||||
{
|
||||
[TestFixture]
|
||||
public class TestProvider
|
||||
{
|
||||
[Test]
|
||||
public void GetProvider ()
|
||||
{
|
||||
var provider = MonoTlsProviderFactory.GetProvider ();
|
||||
Assert.IsNotNull (provider, "TLS Provider");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -310,19 +310,20 @@ namespace System.IO.MemoryMappedFiles
|
||||
[MonoLimitation ("Named mappings scope is process local")]
|
||||
public static MemoryMappedFile OpenExisting (string mapName)
|
||||
{
|
||||
throw new NotImplementedException ();
|
||||
return OpenExisting (mapName, MemoryMappedFileRights.ReadWrite);
|
||||
}
|
||||
|
||||
[MonoLimitation ("Named mappings scope is process local")]
|
||||
public static MemoryMappedFile OpenExisting (string mapName, MemoryMappedFileRights desiredAccessRights)
|
||||
{
|
||||
throw new NotImplementedException ();
|
||||
return OpenExisting (mapName, desiredAccessRights, HandleInheritability.None);
|
||||
}
|
||||
|
||||
[MonoLimitation ("Named mappings scope is process local")]
|
||||
public static MemoryMappedFile OpenExisting (string mapName, MemoryMappedFileRights desiredAccessRights, HandleInheritability inheritability)
|
||||
{
|
||||
throw new NotImplementedException ();
|
||||
// FIXME: Actually use desiredAccessRights
|
||||
return CoreShmCreate (mapName, 0, MemoryMappedFileAccess.ReadWrite, MemoryMappedFileOptions.None, null, inheritability, FileMode.Open);
|
||||
}
|
||||
|
||||
public MemoryMappedViewStream CreateViewStream ()
|
||||
@@ -393,10 +394,9 @@ namespace System.IO.MemoryMappedFiles
|
||||
throw new NotImplementedException ();
|
||||
}
|
||||
|
||||
[MonoTODO]
|
||||
public SafeMemoryMappedFileHandle SafeMemoryMappedFileHandle {
|
||||
get {
|
||||
throw new NotImplementedException ();
|
||||
return handle;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -301,9 +301,12 @@ namespace MonoTests.System.IO.MemoryMappedFiles {
|
||||
var name = MkNamedMapping ();
|
||||
using (var m0 = MemoryMappedFile.CreateNew(name, 4096, MemoryMappedFileAccess.ReadWrite)) {
|
||||
using (var m1 = MemoryMappedFile.CreateOrOpen (name, 4096, MemoryMappedFileAccess.ReadWrite)) {
|
||||
using (MemoryMappedViewAccessor v0 = m0.CreateViewAccessor (), v1 = m1.CreateViewAccessor ()) {
|
||||
v0.Write (10, 0x12345);
|
||||
Assert.AreEqual (0x12345, v1.ReadInt32 (10));
|
||||
using (var m2 = MemoryMappedFile.OpenExisting (name)) {
|
||||
using (MemoryMappedViewAccessor v0 = m0.CreateViewAccessor (), v1 = m1.CreateViewAccessor (), v2 = m2.CreateViewAccessor ()) {
|
||||
v0.Write (10, 0x12345);
|
||||
Assert.AreEqual (0x12345, v1.ReadInt32 (10));
|
||||
Assert.AreEqual (0x12345, v2.ReadInt32 (10));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -466,5 +469,13 @@ namespace MonoTests.System.IO.MemoryMappedFiles {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void OpenExistingWithNoExistingThrows()
|
||||
{
|
||||
Assert.Throws<FileNotFoundException>(() => {
|
||||
MemoryMappedFile.OpenExisting (MkNamedMapping ());
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -375,8 +375,9 @@ namespace System.Net.Http
|
||||
|
||||
wrequest.ResendContentFactory = content.CopyTo;
|
||||
|
||||
var stream = await wrequest.GetRequestStreamAsync ().ConfigureAwait (false);
|
||||
await request.Content.CopyToAsync (stream).ConfigureAwait (false);
|
||||
using (var stream = await wrequest.GetRequestStreamAsync ().ConfigureAwait (false)) {
|
||||
await request.Content.CopyToAsync (stream).ConfigureAwait (false);
|
||||
}
|
||||
} else if (HttpMethod.Post.Equals (request.Method) || HttpMethod.Put.Equals (request.Method) || HttpMethod.Delete.Equals (request.Method)) {
|
||||
// Explicitly set this to make sure we're sending a "Content-Length: 0" header.
|
||||
// This fixes the issue that's been reported on the forums:
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
../../../external/corefx/src/Common/tests/System/AssertExtensions.cs
|
||||
../../../external/corefx/src/Common/tests/System/PlatformDetection.cs
|
||||
|
||||
# ../../../external/corefx/src/System.Runtime.Numerics/tests/*.cs
|
||||
|
||||
@@ -58,13 +58,13 @@ namespace MonoTests.System.ServiceProcess
|
||||
static ServiceInfo DISK_DRIVER_SERVICE = new ServiceInfo { ServiceName = "disk", DisplayName = "Disk Driver", ServiceType = ServiceType.KernelDriver };
|
||||
static ServiceInfo ROUTING_AND_REMOTE_ACCESS_SERVICE = new ServiceInfo { ServiceName = "RemoteAccess", DisplayName = "Routing and Remote Access", DependedOn = new [] { "bfe", "http", "rasman", "rpcss" } };
|
||||
static ServiceInfo SECONDARY_LOGON_SERVICE = new ServiceInfo { ServiceName = "seclogon", DisplayName = "Secondary Logon", Dependents = new [] { "te.service" } };
|
||||
static ServiceInfo SECURITY_ACCOUNTS_MANAGER_SERVICE = new ServiceInfo { ServiceName = "SamSs", DisplayName = "Security Accounts Manager", Dependents = new [] { "browser", "ktmrm", "lanmanserver", "msdtc" }, DependedOn = new [] { "rpcss" } };
|
||||
static ServiceInfo SECURITY_ACCOUNTS_MANAGER_SERVICE = new ServiceInfo { ServiceName = "SamSs", DisplayName = "Security Accounts Manager", Dependents = new [] { "ktmrm", "lanmanserver", "msdtc" }, DependedOn = new [] { "rpcss" } };
|
||||
static ServiceInfo COMPLUS_EVENTSYSTEM_SERVICE = new ServiceInfo { ServiceName = "EventSystem", DisplayName = "COM+ Event System", ServiceType = ServiceType.Win32ShareProcess, Dependents = new [] { "comsysapp", "sens" }, DependedOn = new [] { "rpcss" } };
|
||||
static ServiceInfo WINDOWS_IMAGE_ACQUISITION_SERVICE = new ServiceInfo { ServiceName = "stisvc", DisplayName = "Windows Image Acquisition (WIA)", ServiceType = ServiceType.Win32OwnProcess, DependedOn = new [] { "rpcss" } };
|
||||
static ServiceInfo WINDOWS_SEARCH_SERVICE = new ServiceInfo { ServiceName = "WSearch", DisplayName = "Windows Search", ServiceType = ServiceType.Win32OwnProcess, Dependents = new [] { "wmpnetworksvc", "workfolderssvc" }, DependedOn = new [] { "rpcss" } };
|
||||
static ServiceInfo WINDOWS_TIME_SERVICE = new ServiceInfo { ServiceName = "W32Time", DisplayName = "Windows Time" };
|
||||
static ServiceInfo WINDOWS_UPDATE_SERVICE = new ServiceInfo { ServiceName = "wuauserv", DisplayName = "Windows Update", DependedOn = new [] { "rpcss" } };
|
||||
static ServiceInfo WORKSTATION_SERVICE = new ServiceInfo { ServiceName = "LanmanWorkstation", DisplayName = "Workstation", Dependents = new [] { "browser", "netlogon", "sessionenv" }, DependedOn = new [] { "bowser", "mrxsmb20", "nsi" } };
|
||||
static ServiceInfo WORKSTATION_SERVICE = new ServiceInfo { ServiceName = "LanmanWorkstation", DisplayName = "Workstation", Dependents = new [] { "netlogon", "sessionenv" }, DependedOn = new [] { "bowser", "mrxsmb20", "nsi" } };
|
||||
|
||||
// A service which is expected to be disabled by default on all supported Windows versions.
|
||||
static ServiceInfo DISABLED_SERVICE = ROUTING_AND_REMOTE_ACCESS_SERVICE;
|
||||
|
||||
@@ -36,7 +36,11 @@ namespace Mono.AppleTls
|
||||
*/
|
||||
var certificate2 = certificate as X509Certificate2;
|
||||
if (certificate2 != null)
|
||||
#if MONOTOUCH
|
||||
return SecIdentity.Import (certificate2);
|
||||
#else
|
||||
return SecImportExport.ItemImport (certificate2);
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Reading Certificates from the Mac Keychain
|
||||
@@ -129,28 +133,28 @@ namespace Mono.AppleTls
|
||||
targetHost = targetHost.Substring (0, pos);
|
||||
}
|
||||
|
||||
var policy = SecPolicy.CreateSslPolicy (!serverMode, targetHost);
|
||||
var trust = new SecTrust (certificates, policy);
|
||||
using (var policy = SecPolicy.CreateSslPolicy (!serverMode, targetHost))
|
||||
using (var trust = new SecTrust (certificates, policy)) {
|
||||
if (validator.Settings.TrustAnchors != null) {
|
||||
var status = trust.SetAnchorCertificates (validator.Settings.TrustAnchors);
|
||||
if (status != SecStatusCode.Success)
|
||||
throw new InvalidOperationException (status.ToString ());
|
||||
trust.SetAnchorCertificatesOnly (false);
|
||||
}
|
||||
|
||||
if (validator.Settings.TrustAnchors != null) {
|
||||
var status = trust.SetAnchorCertificates (validator.Settings.TrustAnchors);
|
||||
if (status != SecStatusCode.Success)
|
||||
throw new InvalidOperationException (status.ToString ());
|
||||
trust.SetAnchorCertificatesOnly (false);
|
||||
if (validator.Settings.CertificateValidationTime != null) {
|
||||
var status = trust.SetVerifyDate (validator.Settings.CertificateValidationTime.Value);
|
||||
if (status != SecStatusCode.Success)
|
||||
throw new InvalidOperationException (status.ToString ());
|
||||
}
|
||||
|
||||
var result = trust.Evaluate ();
|
||||
if (result == SecTrustResult.Unspecified || result == SecTrustResult.Proceed)
|
||||
return true;
|
||||
|
||||
errors |= MonoSslPolicyErrors.RemoteCertificateChainErrors;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (validator.Settings.CertificateValidationTime != null) {
|
||||
var status = trust.SetVerifyDate (validator.Settings.CertificateValidationTime.Value);
|
||||
if (status != SecStatusCode.Success)
|
||||
throw new InvalidOperationException (status.ToString ());
|
||||
}
|
||||
|
||||
var result = trust.Evaluate ();
|
||||
if (result == SecTrustResult.Unspecified)
|
||||
return true;
|
||||
|
||||
errors |= MonoSslPolicyErrors.RemoteCertificateChainErrors;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -235,32 +235,41 @@ namespace Mono.AppleTls
|
||||
*
|
||||
*/
|
||||
|
||||
var trust = GetPeerTrust (!IsServer);
|
||||
X509CertificateCollection certificates;
|
||||
|
||||
if (trust == null || trust.Count == 0) {
|
||||
remoteCertificate = null;
|
||||
if (!IsServer)
|
||||
throw new TlsException (AlertDescription.CertificateUnknown);
|
||||
certificates = null;
|
||||
} else {
|
||||
if (trust.Count > 1)
|
||||
Debug ("WARNING: Got multiple certificates in SecTrust!");
|
||||
|
||||
certificates = new X509CertificateCollection ();
|
||||
for (int i = 0; i < trust.Count; i++)
|
||||
certificates.Add (trust [(IntPtr)i].ToX509Certificate ());
|
||||
|
||||
remoteCertificate = certificates [0];
|
||||
Debug ("Got peer trust: {0}", remoteCertificate);
|
||||
}
|
||||
|
||||
bool ok;
|
||||
SecTrust trust = null;
|
||||
X509CertificateCollection certificates = null;
|
||||
|
||||
try {
|
||||
trust = GetPeerTrust (!IsServer);
|
||||
|
||||
if (trust == null || trust.Count == 0) {
|
||||
remoteCertificate = null;
|
||||
if (!IsServer)
|
||||
throw new TlsException (AlertDescription.CertificateUnknown);
|
||||
certificates = null;
|
||||
} else {
|
||||
if (trust.Count > 1)
|
||||
Debug ("WARNING: Got multiple certificates in SecTrust!");
|
||||
|
||||
certificates = new X509CertificateCollection ();
|
||||
for (int i = 0; i < trust.Count; i++)
|
||||
certificates.Add (trust.GetCertificate (i));
|
||||
|
||||
remoteCertificate = new X509Certificate (certificates [0]);
|
||||
Debug ("Got peer trust: {0}", remoteCertificate);
|
||||
}
|
||||
|
||||
ok = ValidateCertificate (certificates);
|
||||
} catch (Exception ex) {
|
||||
Debug ("Certificate validation failed: {0}", ex);
|
||||
throw new TlsException (AlertDescription.CertificateUnknown, "Certificate validation threw exception.");
|
||||
} finally {
|
||||
if (trust != null)
|
||||
trust.Dispose ();
|
||||
if (certificates != null) {
|
||||
for (int i = 0; i < certificates.Count; i++)
|
||||
certificates [i].Dispose ();
|
||||
}
|
||||
}
|
||||
|
||||
if (!ok)
|
||||
@@ -665,7 +674,7 @@ namespace Mono.AppleTls
|
||||
if (value == IntPtr.Zero)
|
||||
throw new TlsException (AlertDescription.CertificateUnknown);
|
||||
}
|
||||
return (value == IntPtr.Zero) ? null : new SecTrust (value);
|
||||
return (value == IntPtr.Zero) ? null : new SecTrust (value, true);
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -848,12 +857,12 @@ namespace Mono.AppleTls
|
||||
[DllImport (SecurityLibrary)]
|
||||
extern static /* OSStatus */ SslStatus SSLClose (/* SSLContextRef */ IntPtr context);
|
||||
|
||||
public override void Close ()
|
||||
public override void Shutdown ()
|
||||
{
|
||||
if (Interlocked.Exchange (ref pendingIO, 1) == 1)
|
||||
throw new InvalidOperationException ();
|
||||
|
||||
Debug ("Close");
|
||||
Debug ("Shutdown");
|
||||
|
||||
lastException = null;
|
||||
|
||||
@@ -862,7 +871,7 @@ namespace Mono.AppleTls
|
||||
return;
|
||||
|
||||
var status = SSLClose (Handle);
|
||||
Debug ("Close done: {0}", status);
|
||||
Debug ("Shutdown done: {0}", status);
|
||||
CheckStatusAndThrow (status);
|
||||
} finally {
|
||||
closed = true;
|
||||
|
||||
@@ -38,12 +38,12 @@ namespace Mono.AppleTls
|
||||
}
|
||||
|
||||
protected override MNS.MobileTlsContext CreateContext (
|
||||
MNS.MobileAuthenticatedStream parent, bool serverMode, string targetHost,
|
||||
SslProtocols enabledProtocols, X509Certificate serverCertificate,
|
||||
X509CertificateCollection clientCertificates, bool askForClientCert)
|
||||
bool serverMode, string targetHost, SslProtocols enabledProtocols,
|
||||
X509Certificate serverCertificate, X509CertificateCollection clientCertificates,
|
||||
bool askForClientCert)
|
||||
{
|
||||
return new AppleTlsContext (
|
||||
parent, serverMode, targetHost,
|
||||
this, serverMode, targetHost,
|
||||
enabledProtocols, serverCertificate,
|
||||
clientCertificates, askForClientCert);
|
||||
}
|
||||
|
||||
@@ -67,6 +67,7 @@ namespace Mono.AppleTls {
|
||||
return code;
|
||||
}
|
||||
|
||||
#if !MONOTOUCH
|
||||
[DllImport (AppleTlsContext.SecurityLibrary)]
|
||||
extern static SecStatusCode SecItemImport (
|
||||
/* CFDataRef */ IntPtr importedData,
|
||||
@@ -217,6 +218,7 @@ namespace Mono.AppleTls {
|
||||
IntPtr keyUsage;
|
||||
IntPtr keyAttributes;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -66,6 +66,8 @@ namespace Mono.AppleTls {
|
||||
foreach (var certificate in certificates)
|
||||
array [i++] = new SecCertificate (certificate);
|
||||
Initialize (array, policy);
|
||||
for (i = 0; i < array.Length; i++)
|
||||
array [i].Dispose ();
|
||||
}
|
||||
|
||||
void Initialize (SecCertificate[] array, SecPolicy policy)
|
||||
@@ -122,6 +124,17 @@ namespace Mono.AppleTls {
|
||||
}
|
||||
}
|
||||
|
||||
internal X509Certificate GetCertificate (int index)
|
||||
{
|
||||
if (handle == IntPtr.Zero)
|
||||
throw new ObjectDisposedException ("SecTrust");
|
||||
if (index < 0 || index >= Count)
|
||||
throw new ArgumentOutOfRangeException ("index");
|
||||
|
||||
var ptr = SecTrustGetCertificateAtIndex (handle, (IntPtr)index);
|
||||
return new X509Certificate (ptr);
|
||||
}
|
||||
|
||||
[DllImport (AppleTlsContext.SecurityLibrary)]
|
||||
extern static SecStatusCode /* OSStatus */ SecTrustSetAnchorCertificates (IntPtr /* SecTrustRef */ trust, IntPtr /* CFArrayRef */ anchorCertificates);
|
||||
|
||||
|
||||
@@ -316,6 +316,9 @@ namespace Mono.Btls
|
||||
if (status == MonoBtlsSslError.WantRead) {
|
||||
wantMore = true;
|
||||
return 0;
|
||||
} else if (status == MonoBtlsSslError.ZeroReturn) {
|
||||
wantMore = false;
|
||||
return size;
|
||||
} else if (status != MonoBtlsSslError.None) {
|
||||
throw GetException (status);
|
||||
}
|
||||
@@ -358,26 +361,11 @@ namespace Mono.Btls
|
||||
}
|
||||
}
|
||||
|
||||
public override void Close ()
|
||||
public override void Shutdown ()
|
||||
{
|
||||
Debug ("Close!");
|
||||
|
||||
if (ssl != null) {
|
||||
ssl.Dispose ();
|
||||
ssl = null;
|
||||
}
|
||||
if (ctx != null) {
|
||||
ctx.Dispose ();
|
||||
ctx = null;
|
||||
}
|
||||
if (bio != null) {
|
||||
bio.Dispose ();
|
||||
bio = null;
|
||||
}
|
||||
if (errbio != null) {
|
||||
errbio.Dispose ();
|
||||
errbio = null;
|
||||
}
|
||||
Debug ("Shutdown!");
|
||||
// ssl.SetQuietShutdown ();
|
||||
ssl.Shutdown ();
|
||||
}
|
||||
|
||||
void Dispose<T> (ref T disposable)
|
||||
@@ -397,12 +385,12 @@ namespace Mono.Btls
|
||||
{
|
||||
try {
|
||||
if (disposing) {
|
||||
Dispose (ref ssl);
|
||||
Dispose (ref ctx);
|
||||
Dispose (ref remoteCertificate);
|
||||
Dispose (ref nativeServerCertificate);
|
||||
Dispose (ref nativeClientCertificate);
|
||||
Dispose (ref clientCertificate);
|
||||
Dispose (ref ctx);
|
||||
Dispose (ref ssl);
|
||||
Dispose (ref bio);
|
||||
Dispose (ref errbio);
|
||||
}
|
||||
|
||||
@@ -102,6 +102,20 @@ namespace Mono.Btls
|
||||
CheckError (ret == 1, callerName);
|
||||
}
|
||||
|
||||
protected internal void CheckLastError ([CallerMemberName] string callerName = null)
|
||||
{
|
||||
var error = Interlocked.Exchange (ref lastError, null);
|
||||
if (error == null)
|
||||
return;
|
||||
|
||||
string message;
|
||||
if (callerName != null)
|
||||
message = string.Format ("Caught unhandled exception in {0}.{1}.", GetType ().Name, callerName);
|
||||
else
|
||||
message = string.Format ("Caught unhandled exception.");
|
||||
throw new MonoBtlsException (message, error);
|
||||
}
|
||||
|
||||
[DllImport (BTLS_DYLIB)]
|
||||
extern static void mono_btls_free (IntPtr data);
|
||||
|
||||
|
||||
@@ -47,6 +47,7 @@ namespace Mono.Btls
|
||||
protected override bool ReleaseHandle ()
|
||||
{
|
||||
mono_btls_ssl_destroy (handle);
|
||||
handle = IntPtr.Zero;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -78,6 +79,12 @@ namespace Mono.Btls
|
||||
[DllImport (BTLS_DYLIB)]
|
||||
extern static void mono_btls_ssl_close (IntPtr handle);
|
||||
|
||||
[DllImport (BTLS_DYLIB)]
|
||||
extern static int mono_btls_ssl_shutdown (IntPtr handle);
|
||||
|
||||
[DllImport (BTLS_DYLIB)]
|
||||
extern static void mono_btls_ssl_set_quiet_shutdown (IntPtr handle, int mode);
|
||||
|
||||
[DllImport (BTLS_DYLIB)]
|
||||
extern static void mono_btls_ssl_set_bio (IntPtr handle, IntPtr bio);
|
||||
|
||||
@@ -131,6 +138,7 @@ namespace Mono.Btls
|
||||
return new BoringSslHandle (handle);
|
||||
}
|
||||
|
||||
MonoBtlsBio bio;
|
||||
PrintErrorsCallbackFunc printErrorsFunc;
|
||||
IntPtr printErrorsFuncPtr;
|
||||
|
||||
@@ -148,6 +156,7 @@ namespace Mono.Btls
|
||||
public void SetBio (MonoBtlsBio bio)
|
||||
{
|
||||
CheckThrow ();
|
||||
this.bio = bio;
|
||||
mono_btls_ssl_set_bio (
|
||||
Handle.DangerousGetHandle (),
|
||||
bio.Handle.DangerousGetHandle ());
|
||||
@@ -164,18 +173,17 @@ namespace Mono.Btls
|
||||
errors = null;
|
||||
}
|
||||
|
||||
if (errors != null) {
|
||||
Console.Error.WriteLine ("ERROR: {0} failed: {1}", callerName, errors);
|
||||
if (errors != null)
|
||||
throw new MonoBtlsException ("{0} failed: {1}.", callerName, errors);
|
||||
} else {
|
||||
Console.Error.WriteLine ("ERROR: {0} failed.", callerName);
|
||||
else
|
||||
throw new MonoBtlsException ("{0} failed.", callerName);
|
||||
}
|
||||
}
|
||||
|
||||
MonoBtlsSslError GetError (int ret_code)
|
||||
{
|
||||
CheckThrow ();
|
||||
bio.CheckLastError ();
|
||||
|
||||
var error = mono_btls_ssl_get_error (
|
||||
Handle.DangerousGetHandle (), ret_code);
|
||||
return (MonoBtlsSslError)error;
|
||||
@@ -287,15 +295,20 @@ namespace Mono.Btls
|
||||
var ret = mono_btls_ssl_read (
|
||||
Handle.DangerousGetHandle (), data, dataSize);
|
||||
|
||||
if (ret >= 0) {
|
||||
if (ret > 0) {
|
||||
dataSize = ret;
|
||||
return MonoBtlsSslError.None;
|
||||
}
|
||||
|
||||
var error = mono_btls_ssl_get_error (
|
||||
Handle.DangerousGetHandle (), ret);
|
||||
var error = GetError (ret);
|
||||
if (ret == 0 && error == MonoBtlsSslError.Syscall) {
|
||||
// End-of-stream
|
||||
dataSize = 0;
|
||||
return MonoBtlsSslError.None;
|
||||
}
|
||||
|
||||
dataSize = 0;
|
||||
return (MonoBtlsSslError)error;
|
||||
return error;
|
||||
}
|
||||
|
||||
public MonoBtlsSslError Write (IntPtr data, ref int dataSize)
|
||||
@@ -416,9 +429,24 @@ namespace Mono.Btls
|
||||
return Marshal.PtrToStringAnsi (namePtr);
|
||||
}
|
||||
|
||||
public void Shutdown ()
|
||||
{
|
||||
CheckThrow ();
|
||||
var ret = mono_btls_ssl_shutdown (Handle.DangerousGetHandle ());
|
||||
if (ret < 0)
|
||||
throw ThrowError ();
|
||||
}
|
||||
|
||||
public void SetQuietShutdown ()
|
||||
{
|
||||
CheckThrow ();
|
||||
mono_btls_ssl_set_quiet_shutdown (Handle.DangerousGetHandle (), 1);
|
||||
}
|
||||
|
||||
protected override void Close ()
|
||||
{
|
||||
mono_btls_ssl_close (Handle.DangerousGetHandle ());
|
||||
if (!Handle.IsInvalid)
|
||||
mono_btls_ssl_close (Handle.DangerousGetHandle ());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,12 +53,12 @@ namespace Mono.Btls
|
||||
}
|
||||
|
||||
protected override MNS.MobileTlsContext CreateContext (
|
||||
MNS.MobileAuthenticatedStream parent, bool serverMode, string targetHost,
|
||||
SslProtocols enabledProtocols, X509Certificate serverCertificate,
|
||||
X509CertificateCollection clientCertificates, bool askForClientCert)
|
||||
bool serverMode, string targetHost, SslProtocols enabledProtocols,
|
||||
X509Certificate serverCertificate, X509CertificateCollection clientCertificates,
|
||||
bool askForClientCert)
|
||||
{
|
||||
return new MonoBtlsContext (
|
||||
parent, serverMode, targetHost,
|
||||
this, serverMode, targetHost,
|
||||
enabledProtocols, serverCertificate,
|
||||
clientCertificates, askForClientCert);
|
||||
}
|
||||
|
||||
@@ -11,14 +11,14 @@ using System;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Net.Security;
|
||||
using System.Security.Authentication;
|
||||
using SD = System.Diagnostics;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Runtime.ExceptionServices;
|
||||
|
||||
namespace Mono.Net.Security
|
||||
{
|
||||
delegate AsyncOperationStatus AsyncOperation (AsyncProtocolRequest asyncRequest, AsyncOperationStatus status);
|
||||
|
||||
class BufferOffsetSize
|
||||
{
|
||||
public byte[] Buffer;
|
||||
@@ -37,6 +37,13 @@ namespace Mono.Net.Security
|
||||
|
||||
public BufferOffsetSize (byte[] buffer, int offset, int size)
|
||||
{
|
||||
if (buffer == null)
|
||||
throw new ArgumentNullException (nameof (buffer));
|
||||
if (offset < 0)
|
||||
throw new ArgumentOutOfRangeException (nameof (offset));
|
||||
if (size < 0 || offset + size > buffer.Length)
|
||||
throw new ArgumentOutOfRangeException (nameof (size));
|
||||
|
||||
Buffer = buffer;
|
||||
Offset = offset;
|
||||
Size = size;
|
||||
@@ -54,7 +61,7 @@ namespace Mono.Net.Security
|
||||
public readonly int InitialSize;
|
||||
|
||||
public BufferOffsetSize2 (int size)
|
||||
: base (new byte [size], 0, 0)
|
||||
: base (new byte[size], 0, 0)
|
||||
{
|
||||
InitialSize = size;
|
||||
}
|
||||
@@ -63,7 +70,7 @@ namespace Mono.Net.Security
|
||||
{
|
||||
Offset = Size = 0;
|
||||
TotalBytes = 0;
|
||||
Buffer = new byte [InitialSize];
|
||||
Buffer = new byte[InitialSize];
|
||||
Complete = false;
|
||||
}
|
||||
|
||||
@@ -74,11 +81,11 @@ namespace Mono.Net.Security
|
||||
|
||||
int missing = size - Remaining;
|
||||
if (Offset == 0 && Size == 0) {
|
||||
Buffer = new byte [size];
|
||||
Buffer = new byte[size];
|
||||
return;
|
||||
}
|
||||
|
||||
var buffer = new byte [Buffer.Length + missing];
|
||||
var buffer = new byte[Buffer.Length + missing];
|
||||
Buffer.CopyTo (buffer, 0);
|
||||
Buffer = buffer;
|
||||
}
|
||||
@@ -91,201 +98,296 @@ namespace Mono.Net.Security
|
||||
}
|
||||
}
|
||||
|
||||
enum AsyncOperationStatus {
|
||||
NotStarted,
|
||||
enum AsyncOperationStatus
|
||||
{
|
||||
Initialize,
|
||||
Continue,
|
||||
Running,
|
||||
Complete,
|
||||
WantRead,
|
||||
WantWrite,
|
||||
ReadDone,
|
||||
FinishWrite
|
||||
Complete
|
||||
}
|
||||
|
||||
class AsyncProtocolRequest
|
||||
class AsyncProtocolResult
|
||||
{
|
||||
public readonly MobileAuthenticatedStream Parent;
|
||||
public readonly BufferOffsetSize UserBuffer;
|
||||
|
||||
int RequestedSize;
|
||||
public int CurrentSize;
|
||||
public int UserResult;
|
||||
|
||||
AsyncOperation Operation;
|
||||
int Status;
|
||||
|
||||
public readonly int ID = ++next_id;
|
||||
static int next_id;
|
||||
|
||||
public readonly LazyAsyncResult UserAsyncResult;
|
||||
|
||||
public AsyncProtocolRequest (MobileAuthenticatedStream parent, LazyAsyncResult lazyResult, BufferOffsetSize userBuffer = null)
|
||||
{
|
||||
Parent = parent;
|
||||
UserAsyncResult = lazyResult;
|
||||
UserBuffer = userBuffer;
|
||||
public int UserResult {
|
||||
get;
|
||||
}
|
||||
public ExceptionDispatchInfo Error {
|
||||
get;
|
||||
}
|
||||
|
||||
public bool CompleteWithError (Exception ex)
|
||||
public AsyncProtocolResult (int result)
|
||||
{
|
||||
Status = (int)AsyncOperationStatus.Complete;
|
||||
if (UserAsyncResult == null)
|
||||
return true;
|
||||
if (!UserAsyncResult.InternalPeekCompleted)
|
||||
UserAsyncResult.InvokeCallback (ex);
|
||||
return false;
|
||||
UserResult = result;
|
||||
}
|
||||
|
||||
public AsyncProtocolResult (ExceptionDispatchInfo error)
|
||||
{
|
||||
Error = error;
|
||||
}
|
||||
}
|
||||
|
||||
abstract class AsyncProtocolRequest
|
||||
{
|
||||
public MobileAuthenticatedStream Parent {
|
||||
get;
|
||||
}
|
||||
|
||||
public bool RunSynchronously {
|
||||
get;
|
||||
}
|
||||
|
||||
public int ID => ++next_id;
|
||||
|
||||
public string Name => GetType ().Name;
|
||||
|
||||
public int UserResult {
|
||||
get;
|
||||
protected set;
|
||||
}
|
||||
|
||||
int Started;
|
||||
int RequestedSize;
|
||||
int WriteRequested;
|
||||
readonly object locker = new object ();
|
||||
|
||||
static int next_id;
|
||||
|
||||
public AsyncProtocolRequest (MobileAuthenticatedStream parent, bool sync)
|
||||
{
|
||||
Parent = parent;
|
||||
RunSynchronously = sync;
|
||||
}
|
||||
|
||||
[SD.Conditional ("MARTIN_DEBUG")]
|
||||
protected void Debug (string message, params object[] args)
|
||||
{
|
||||
Parent.Debug ("AsyncProtocolRequest({0}:{1}): {2}", Parent.ID, ID, string.Format (message, args));
|
||||
Parent.Debug ("{0}({1}:{2}): {3}", Name, Parent.ID, ID, string.Format (message, args));
|
||||
}
|
||||
|
||||
internal void RequestRead (int size)
|
||||
{
|
||||
var oldStatus = (AsyncOperationStatus)Interlocked.CompareExchange (ref Status, (int)AsyncOperationStatus.WantRead, (int)AsyncOperationStatus.Running);
|
||||
Debug ("RequestRead: {0} {1}", oldStatus, size);
|
||||
if (oldStatus == AsyncOperationStatus.Running)
|
||||
RequestedSize = size;
|
||||
else if (oldStatus == AsyncOperationStatus.WantRead)
|
||||
lock (locker) {
|
||||
RequestedSize += size;
|
||||
else if (oldStatus != AsyncOperationStatus.WantWrite)
|
||||
throw new InvalidOperationException ();
|
||||
}
|
||||
|
||||
internal void ResetRead ()
|
||||
{
|
||||
var oldStatus = (AsyncOperationStatus)Interlocked.CompareExchange (ref Status, (int)AsyncOperationStatus.Complete, (int)AsyncOperationStatus.WantRead);
|
||||
Debug ("ResetRead: {0} {1}", oldStatus, Status);
|
||||
}
|
||||
|
||||
internal void ResetWrite ()
|
||||
{
|
||||
var oldStatus = (AsyncOperationStatus)Interlocked.CompareExchange (ref Status, (int)AsyncOperationStatus.Complete, (int)AsyncOperationStatus.WantWrite);
|
||||
Debug ("ResetWrite: {0} {1}", oldStatus, Status);
|
||||
Debug ("RequestRead: {0}", size);
|
||||
}
|
||||
}
|
||||
|
||||
internal void RequestWrite ()
|
||||
{
|
||||
var oldStatus = (AsyncOperationStatus)Interlocked.CompareExchange (ref Status, (int)AsyncOperationStatus.WantWrite, (int)AsyncOperationStatus.Running);
|
||||
Debug ("RequestWrite: {0} {1}", oldStatus, Status);
|
||||
if (oldStatus == AsyncOperationStatus.Running)
|
||||
return;
|
||||
else if (oldStatus != AsyncOperationStatus.WantRead && oldStatus != AsyncOperationStatus.WantWrite)
|
||||
throw new InvalidOperationException ();
|
||||
WriteRequested = 1;
|
||||
}
|
||||
|
||||
internal void StartOperation (AsyncOperation operation)
|
||||
internal async Task<AsyncProtocolResult> StartOperation (CancellationToken cancellationToken)
|
||||
{
|
||||
Debug ("Start Operation: {0} {1}", Status, operation);
|
||||
if (Interlocked.CompareExchange (ref Status, (int)AsyncOperationStatus.Initialize, (int)AsyncOperationStatus.NotStarted) != (int)AsyncOperationStatus.NotStarted)
|
||||
Debug ("Start Operation: {0}", this);
|
||||
if (Interlocked.CompareExchange (ref Started, 1, 0) != 0)
|
||||
throw new InvalidOperationException ();
|
||||
|
||||
Operation = operation;
|
||||
|
||||
if (UserAsyncResult == null) {
|
||||
StartOperation ();
|
||||
return;
|
||||
}
|
||||
|
||||
ThreadPool.QueueUserWorkItem (_ => StartOperation ());
|
||||
}
|
||||
|
||||
void StartOperation ()
|
||||
{
|
||||
try {
|
||||
ProcessOperation ();
|
||||
if (UserAsyncResult != null && !UserAsyncResult.InternalPeekCompleted)
|
||||
UserAsyncResult.InvokeCallback (UserResult);
|
||||
await ProcessOperation (cancellationToken).ConfigureAwait (false);
|
||||
return new AsyncProtocolResult (UserResult);
|
||||
} catch (Exception ex) {
|
||||
if (UserAsyncResult == null)
|
||||
throw;
|
||||
if (!UserAsyncResult.InternalPeekCompleted)
|
||||
UserAsyncResult.InvokeCallback (ex);
|
||||
var info = Parent.SetException (MobileAuthenticatedStream.GetSSPIException (ex));
|
||||
return new AsyncProtocolResult (info);
|
||||
}
|
||||
}
|
||||
|
||||
void ProcessOperation ()
|
||||
async Task ProcessOperation (CancellationToken cancellationToken)
|
||||
{
|
||||
AsyncOperationStatus status;
|
||||
do {
|
||||
status = (AsyncOperationStatus)Interlocked.Exchange (ref Status, (int)AsyncOperationStatus.Running);
|
||||
|
||||
var status = AsyncOperationStatus.Initialize;
|
||||
while (status != AsyncOperationStatus.Complete) {
|
||||
cancellationToken.ThrowIfCancellationRequested ();
|
||||
Debug ("ProcessOperation: {0}", status);
|
||||
|
||||
status = ProcessOperation (status);
|
||||
|
||||
Debug ("ProcessOperation done: {0}", status);
|
||||
|
||||
AsyncOperationStatus oldStatus;
|
||||
if (status == AsyncOperationStatus.Complete) {
|
||||
oldStatus = (AsyncOperationStatus)Interlocked.CompareExchange (ref Status, (int)AsyncOperationStatus.FinishWrite, (int)AsyncOperationStatus.WantWrite);
|
||||
if (oldStatus == AsyncOperationStatus.WantWrite) {
|
||||
// We are done, but still need to flush the write queue.
|
||||
status = AsyncOperationStatus.FinishWrite;
|
||||
continue;
|
||||
var ret = await InnerRead (cancellationToken).ConfigureAwait (false);
|
||||
if (ret != null) {
|
||||
if (ret == 0) {
|
||||
// End-of-stream
|
||||
Debug ("END OF STREAM!");
|
||||
status = AsyncOperationStatus.ReadDone;
|
||||
} else if (ret < 0) {
|
||||
// remote prematurely closed connection.
|
||||
throw new IOException ("Remote prematurely closed connection.");
|
||||
}
|
||||
}
|
||||
|
||||
oldStatus = (AsyncOperationStatus)Interlocked.CompareExchange (ref Status, (int)status, (int)AsyncOperationStatus.Running);
|
||||
Debug ("ProcessOperation done: {0} -> {1}", oldStatus, status);
|
||||
Debug ("ProcessOperation run: {0}", status);
|
||||
|
||||
if (oldStatus != AsyncOperationStatus.Running) {
|
||||
if (status == oldStatus || status == AsyncOperationStatus.Continue || status == AsyncOperationStatus.Complete)
|
||||
status = oldStatus;
|
||||
else
|
||||
throw new InvalidOperationException ();
|
||||
AsyncOperationStatus newStatus;
|
||||
switch (status) {
|
||||
case AsyncOperationStatus.Initialize:
|
||||
case AsyncOperationStatus.Continue:
|
||||
case AsyncOperationStatus.ReadDone:
|
||||
newStatus = Run (status);
|
||||
break;
|
||||
default:
|
||||
throw new InvalidOperationException ();
|
||||
}
|
||||
} while (status != AsyncOperationStatus.Complete);
|
||||
|
||||
if (Interlocked.Exchange (ref WriteRequested, 0) != 0) {
|
||||
// Flush the write queue.
|
||||
await Parent.InnerWrite (RunSynchronously, cancellationToken);
|
||||
}
|
||||
|
||||
Debug ("ProcessOperation done: {0} -> {1}", status, newStatus);
|
||||
|
||||
status = newStatus;
|
||||
}
|
||||
}
|
||||
|
||||
AsyncOperationStatus ProcessOperation (AsyncOperationStatus status)
|
||||
async Task<int?> InnerRead (CancellationToken cancellationToken)
|
||||
{
|
||||
if (status == AsyncOperationStatus.WantRead) {
|
||||
if (RequestedSize < 0)
|
||||
int? totalRead = null;
|
||||
var requestedSize = Interlocked.Exchange (ref RequestedSize, 0);
|
||||
while (requestedSize > 0) {
|
||||
Debug ("ProcessOperation - read inner: {0}", requestedSize);
|
||||
|
||||
var ret = await Parent.InnerRead (RunSynchronously, requestedSize, cancellationToken).ConfigureAwait (false);
|
||||
Debug ("ProcessOperation - read inner done: {0} - {1}", requestedSize, ret);
|
||||
|
||||
if (ret <= 0)
|
||||
return ret;
|
||||
if (ret > requestedSize)
|
||||
throw new InvalidOperationException ();
|
||||
else if (RequestedSize == 0)
|
||||
return AsyncOperationStatus.Continue;
|
||||
|
||||
Debug ("ProcessOperation - read inner: {0}", RequestedSize);
|
||||
var ret = Parent.InnerRead (RequestedSize);
|
||||
Debug ("ProcessOperation - read inner done: {0} - {1}", RequestedSize, ret);
|
||||
totalRead += ret;
|
||||
requestedSize -= ret;
|
||||
var newRequestedSize = Interlocked.Exchange (ref RequestedSize, 0);
|
||||
requestedSize += newRequestedSize;
|
||||
}
|
||||
|
||||
if (ret < 0)
|
||||
return AsyncOperationStatus.ReadDone;
|
||||
return totalRead;
|
||||
}
|
||||
|
||||
RequestedSize -= ret;
|
||||
/*
|
||||
* This will operate on the internal buffers and never block.
|
||||
*/
|
||||
protected abstract AsyncOperationStatus Run (AsyncOperationStatus status);
|
||||
|
||||
if (ret == 0 || RequestedSize == 0)
|
||||
return AsyncOperationStatus.Continue;
|
||||
else
|
||||
return AsyncOperationStatus.WantRead;
|
||||
} else if (status == AsyncOperationStatus.WantWrite) {
|
||||
Debug ("ProcessOperation - want write");
|
||||
Parent.InnerWrite ();
|
||||
Debug ("ProcessOperation - want write done");
|
||||
return AsyncOperationStatus.Continue;
|
||||
} else if (status == AsyncOperationStatus.Initialize || status == AsyncOperationStatus.Continue) {
|
||||
Debug ("ProcessOperation - continue");
|
||||
status = Operation (this, status);
|
||||
Debug ("ProcessOperation - continue done: {0}", status);
|
||||
return status;
|
||||
} else if (status == AsyncOperationStatus.ReadDone) {
|
||||
Debug ("ProcessOperation - read done");
|
||||
status = Operation (this, status);
|
||||
Debug ("ProcessOperation - read done: {0}", status);
|
||||
return status;
|
||||
} else if (status == AsyncOperationStatus.FinishWrite) {
|
||||
Debug ("ProcessOperation - finish write");
|
||||
Parent.InnerWrite ();
|
||||
Debug ("ProcessOperation - finish write done");
|
||||
public override string ToString ()
|
||||
{
|
||||
return string.Format ("[{0}]", Name);
|
||||
}
|
||||
}
|
||||
|
||||
class AsyncHandshakeRequest : AsyncProtocolRequest
|
||||
{
|
||||
public AsyncHandshakeRequest (MobileAuthenticatedStream parent, bool sync)
|
||||
: base (parent, sync)
|
||||
{
|
||||
}
|
||||
|
||||
protected override AsyncOperationStatus Run (AsyncOperationStatus status)
|
||||
{
|
||||
return Parent.ProcessHandshake (status);
|
||||
}
|
||||
}
|
||||
|
||||
abstract class AsyncReadOrWriteRequest : AsyncProtocolRequest
|
||||
{
|
||||
protected BufferOffsetSize UserBuffer {
|
||||
get;
|
||||
}
|
||||
|
||||
protected int CurrentSize {
|
||||
get; set;
|
||||
}
|
||||
|
||||
public AsyncReadOrWriteRequest (MobileAuthenticatedStream parent, bool sync, byte[] buffer, int offset, int size)
|
||||
: base (parent, sync)
|
||||
{
|
||||
UserBuffer = new BufferOffsetSize (buffer, offset, size);
|
||||
}
|
||||
|
||||
public override string ToString ()
|
||||
{
|
||||
return string.Format ("[{0}: {1}]", Name, UserBuffer);
|
||||
}
|
||||
}
|
||||
|
||||
class AsyncReadRequest : AsyncReadOrWriteRequest
|
||||
{
|
||||
public AsyncReadRequest (MobileAuthenticatedStream parent, bool sync, byte[] buffer, int offset, int size)
|
||||
: base (parent, sync, buffer, offset, size)
|
||||
{
|
||||
}
|
||||
|
||||
protected override AsyncOperationStatus Run (AsyncOperationStatus status)
|
||||
{
|
||||
Debug ("ProcessRead - read user: {0} {1}", this, status);
|
||||
|
||||
var (ret, wantMore) = Parent.ProcessRead (UserBuffer);
|
||||
|
||||
Debug ("ProcessRead - read user done: {0} - {1} {2}", this, ret, wantMore);
|
||||
|
||||
if (ret < 0) {
|
||||
UserResult = -1;
|
||||
return AsyncOperationStatus.Complete;
|
||||
}
|
||||
|
||||
throw new InvalidOperationException ();
|
||||
CurrentSize += ret;
|
||||
UserBuffer.Offset += ret;
|
||||
UserBuffer.Size -= ret;
|
||||
|
||||
Debug ("Process Read - read user done #1: {0} - {1} {2}", this, CurrentSize, wantMore);
|
||||
|
||||
if (wantMore && CurrentSize == 0)
|
||||
return AsyncOperationStatus.Continue;
|
||||
|
||||
UserResult = CurrentSize;
|
||||
return AsyncOperationStatus.Complete;
|
||||
}
|
||||
}
|
||||
|
||||
class AsyncWriteRequest : AsyncReadOrWriteRequest
|
||||
{
|
||||
public AsyncWriteRequest (MobileAuthenticatedStream parent, bool sync, byte[] buffer, int offset, int size)
|
||||
: base (parent, sync, buffer, offset, size)
|
||||
{
|
||||
}
|
||||
|
||||
protected override AsyncOperationStatus Run (AsyncOperationStatus status)
|
||||
{
|
||||
Debug ("ProcessWrite - write user: {0} {1}", this, status);
|
||||
|
||||
if (UserBuffer.Size == 0) {
|
||||
UserResult = CurrentSize;
|
||||
return AsyncOperationStatus.Complete;
|
||||
}
|
||||
|
||||
var (ret, wantMore) = Parent.ProcessWrite (UserBuffer);
|
||||
|
||||
Debug ("ProcessWrite - write user done: {0} - {1} {2}", this, ret, wantMore);
|
||||
|
||||
if (ret < 0) {
|
||||
UserResult = -1;
|
||||
return AsyncOperationStatus.Complete;
|
||||
}
|
||||
|
||||
CurrentSize += ret;
|
||||
UserBuffer.Offset += ret;
|
||||
UserBuffer.Size -= ret;
|
||||
|
||||
if (wantMore)
|
||||
return AsyncOperationStatus.Continue;
|
||||
|
||||
UserResult = CurrentSize;
|
||||
return AsyncOperationStatus.Complete;
|
||||
}
|
||||
}
|
||||
|
||||
class AsyncShutdownRequest : AsyncProtocolRequest
|
||||
{
|
||||
public AsyncShutdownRequest (MobileAuthenticatedStream parent)
|
||||
: base (parent, false)
|
||||
{
|
||||
}
|
||||
|
||||
protected override AsyncOperationStatus Run (AsyncOperationStatus status)
|
||||
{
|
||||
return Parent.ProcessShutdown (status);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
@@ -575,6 +575,11 @@ namespace Mono.Net.Security.Private
|
||||
|
||||
#region IMonoSslStream
|
||||
|
||||
Task IMonoSslStream.ShutdownAsync ()
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
AuthenticatedStream IMonoSslStream.AuthenticatedStream {
|
||||
get { return this; }
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ using System.IO;
|
||||
using System.Net;
|
||||
using System.Net.Security;
|
||||
using System.Globalization;
|
||||
using System.Security.Authentication;
|
||||
using System.Runtime.ExceptionServices;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
@@ -36,8 +37,13 @@ namespace Mono.Net.Security
|
||||
{
|
||||
abstract class MobileAuthenticatedStream : AuthenticatedStream, MSI.IMonoSslStream
|
||||
{
|
||||
/*
|
||||
* This is intentionally called `xobileTlsContext'. It is a "dangerous" object
|
||||
* that must not be touched outside the `ioLock' and we need to be very careful
|
||||
* where we access it.
|
||||
*/
|
||||
MobileTlsContext xobileTlsContext;
|
||||
Exception lastException;
|
||||
ExceptionDispatchInfo lastException;
|
||||
|
||||
AsyncProtocolRequest asyncHandshakeRequest;
|
||||
AsyncProtocolRequest asyncReadRequest;
|
||||
@@ -47,11 +53,12 @@ namespace Mono.Net.Security
|
||||
|
||||
object ioLock = new object ();
|
||||
int closeRequested;
|
||||
bool shutdown;
|
||||
|
||||
static int uniqueNameInteger = 123;
|
||||
|
||||
public MobileAuthenticatedStream (Stream innerStream, bool leaveInnerStreamOpen, SslStream owner,
|
||||
MSI.MonoTlsSettings settings, MSI.MonoTlsProvider provider)
|
||||
MSI.MonoTlsSettings settings, MSI.MonoTlsProvider provider)
|
||||
: base (innerStream, leaveInnerStreamOpen)
|
||||
{
|
||||
SslStream = owner;
|
||||
@@ -78,42 +85,47 @@ namespace Mono.Net.Security
|
||||
get { return xobileTlsContext != null; }
|
||||
}
|
||||
|
||||
internal MobileTlsContext Context {
|
||||
get {
|
||||
CheckThrow (true);
|
||||
return xobileTlsContext;
|
||||
}
|
||||
}
|
||||
|
||||
internal void CheckThrow (bool authSuccessCheck)
|
||||
internal void CheckThrow (bool authSuccessCheck, bool shutdownCheck = false)
|
||||
{
|
||||
if (closeRequested != 0)
|
||||
throw new InvalidOperationException ("Stream is closed.");
|
||||
if (lastException != null)
|
||||
throw lastException;
|
||||
lastException.Throw ();
|
||||
if (authSuccessCheck && !IsAuthenticated)
|
||||
throw new InvalidOperationException ("Must be authenticated.");
|
||||
throw new InvalidOperationException (SR.net_auth_noauth);
|
||||
if (shutdownCheck && shutdown)
|
||||
throw new InvalidOperationException (SR.net_ssl_io_already_shutdown);
|
||||
}
|
||||
|
||||
Exception SetException (Exception e)
|
||||
internal static Exception GetSSPIException (Exception e)
|
||||
{
|
||||
e = SetException_internal (e);
|
||||
if (e != null && xobileTlsContext != null)
|
||||
xobileTlsContext.Dispose ();
|
||||
return e;
|
||||
if (e is OperationCanceledException || e is IOException || e is ObjectDisposedException || e is AuthenticationException)
|
||||
return e;
|
||||
return new AuthenticationException (SR.net_auth_SSPI, e);
|
||||
}
|
||||
|
||||
Exception SetException_internal (Exception e)
|
||||
internal static Exception GetIOException (Exception e, string message)
|
||||
{
|
||||
if (lastException == null)
|
||||
lastException = e;
|
||||
return lastException;
|
||||
if (e is OperationCanceledException || e is IOException || e is ObjectDisposedException || e is AuthenticationException)
|
||||
return e;
|
||||
return new IOException (message, e);
|
||||
}
|
||||
|
||||
internal ExceptionDispatchInfo SetException (Exception e)
|
||||
{
|
||||
var info = ExceptionDispatchInfo.Capture (e);
|
||||
var old = Interlocked.CompareExchange (ref lastException, info, null);
|
||||
return old ?? info;
|
||||
}
|
||||
|
||||
SslProtocols DefaultProtocols {
|
||||
get { return SslProtocols.Tls12 | SslProtocols.Tls11 | SslProtocols.Tls; }
|
||||
}
|
||||
|
||||
enum OperationType {
|
||||
Read,
|
||||
Write,
|
||||
Shutdown
|
||||
}
|
||||
|
||||
public void AuthenticateAsClient (string targetHost)
|
||||
{
|
||||
AuthenticateAsClient (targetHost, new X509CertificateCollection (), DefaultProtocols, false);
|
||||
@@ -121,8 +133,8 @@ namespace Mono.Net.Security
|
||||
|
||||
public void AuthenticateAsClient (string targetHost, X509CertificateCollection clientCertificates, SslProtocols enabledSslProtocols, bool checkCertificateRevocation)
|
||||
{
|
||||
ValidateCreateContext (false, targetHost, enabledSslProtocols, null, clientCertificates, false);
|
||||
ProcessAuthentication (null);
|
||||
var task = ProcessAuthentication (true, false, targetHost, enabledSslProtocols, null, clientCertificates, false);
|
||||
task.Wait ();
|
||||
}
|
||||
|
||||
public IAsyncResult BeginAuthenticateAsClient (string targetHost, AsyncCallback asyncCallback, object asyncState)
|
||||
@@ -132,15 +144,13 @@ namespace Mono.Net.Security
|
||||
|
||||
public IAsyncResult BeginAuthenticateAsClient (string targetHost, X509CertificateCollection clientCertificates, SslProtocols enabledSslProtocols, bool checkCertificateRevocation, AsyncCallback asyncCallback, object asyncState)
|
||||
{
|
||||
ValidateCreateContext (false, targetHost, enabledSslProtocols, null, clientCertificates, false);
|
||||
var result = new LazyAsyncResult (this, asyncState, asyncCallback);
|
||||
ProcessAuthentication (result);
|
||||
return result;
|
||||
var task = ProcessAuthentication (false, false, targetHost, enabledSslProtocols, null, clientCertificates, false);
|
||||
return TaskToApm.Begin (task, asyncCallback, asyncState);
|
||||
}
|
||||
|
||||
public void EndAuthenticateAsClient (IAsyncResult asyncResult)
|
||||
{
|
||||
EndProcessAuthentication (asyncResult);
|
||||
TaskToApm.End (asyncResult);
|
||||
}
|
||||
|
||||
public void AuthenticateAsServer (X509Certificate serverCertificate)
|
||||
@@ -150,8 +160,8 @@ namespace Mono.Net.Security
|
||||
|
||||
public void AuthenticateAsServer (X509Certificate serverCertificate, bool clientCertificateRequired, SslProtocols enabledSslProtocols, bool checkCertificateRevocation)
|
||||
{
|
||||
ValidateCreateContext (true, string.Empty, enabledSslProtocols, serverCertificate, null, clientCertificateRequired);
|
||||
ProcessAuthentication (null);
|
||||
var task = ProcessAuthentication (true, true, string.Empty, enabledSslProtocols, serverCertificate, null, clientCertificateRequired);
|
||||
task.Wait ();
|
||||
}
|
||||
|
||||
public IAsyncResult BeginAuthenticateAsServer (X509Certificate serverCertificate, AsyncCallback asyncCallback, object asyncState)
|
||||
@@ -161,218 +171,214 @@ namespace Mono.Net.Security
|
||||
|
||||
public IAsyncResult BeginAuthenticateAsServer (X509Certificate serverCertificate, bool clientCertificateRequired, SslProtocols enabledSslProtocols, bool checkCertificateRevocation, AsyncCallback asyncCallback, object asyncState)
|
||||
{
|
||||
ValidateCreateContext (true, string.Empty, enabledSslProtocols, serverCertificate, null, clientCertificateRequired);
|
||||
var result = new LazyAsyncResult (this, asyncState, asyncCallback);
|
||||
ProcessAuthentication (result);
|
||||
return result;
|
||||
var task = ProcessAuthentication (false, true, string.Empty, enabledSslProtocols, serverCertificate, null, clientCertificateRequired);
|
||||
return TaskToApm.Begin (task, asyncCallback, asyncState);
|
||||
}
|
||||
|
||||
public void EndAuthenticateAsServer (IAsyncResult asyncResult)
|
||||
{
|
||||
EndProcessAuthentication (asyncResult);
|
||||
TaskToApm.End (asyncResult);
|
||||
}
|
||||
|
||||
public Task AuthenticateAsClientAsync (string targetHost)
|
||||
{
|
||||
return Task.Factory.FromAsync (BeginAuthenticateAsClient, EndAuthenticateAsClient, targetHost, null);
|
||||
return ProcessAuthentication (false, false, targetHost, DefaultProtocols, null, null, false);
|
||||
}
|
||||
|
||||
public Task AuthenticateAsClientAsync (string targetHost, X509CertificateCollection clientCertificates, SslProtocols enabledSslProtocols, bool checkCertificateRevocation)
|
||||
{
|
||||
return Task.Factory.FromAsync ((callback, state) => BeginAuthenticateAsClient (targetHost, clientCertificates, enabledSslProtocols, checkCertificateRevocation, callback, state), EndAuthenticateAsClient, null);
|
||||
return ProcessAuthentication (false, false, targetHost, enabledSslProtocols, null, clientCertificates, false);
|
||||
}
|
||||
|
||||
public Task AuthenticateAsServerAsync (X509Certificate serverCertificate)
|
||||
{
|
||||
return Task.Factory.FromAsync (BeginAuthenticateAsServer, EndAuthenticateAsServer, serverCertificate, null);
|
||||
return AuthenticateAsServerAsync (serverCertificate, false, DefaultProtocols, false);
|
||||
}
|
||||
|
||||
public Task AuthenticateAsServerAsync (X509Certificate serverCertificate, bool clientCertificateRequired, SslProtocols enabledSslProtocols, bool checkCertificateRevocation)
|
||||
{
|
||||
return Task.Factory.FromAsync ((callback, state) => BeginAuthenticateAsServer (serverCertificate, clientCertificateRequired, enabledSslProtocols, checkCertificateRevocation, callback, state), EndAuthenticateAsServer, null);
|
||||
return ProcessAuthentication (false, true, string.Empty, enabledSslProtocols, serverCertificate, null, clientCertificateRequired);
|
||||
}
|
||||
|
||||
public Task ShutdownAsync ()
|
||||
{
|
||||
Debug ("ShutdownAsync");
|
||||
|
||||
/*
|
||||
* SSLClose() is a little bit tricky as it might attempt to send a close_notify alert
|
||||
* and thus call our write callback.
|
||||
*
|
||||
* It is also not thread-safe with SSLRead() or SSLWrite(), so we need to take the I/O lock here.
|
||||
*/
|
||||
var asyncRequest = new AsyncShutdownRequest (this);
|
||||
var task = StartOperation (OperationType.Shutdown, asyncRequest, CancellationToken.None);
|
||||
return task;
|
||||
}
|
||||
|
||||
public AuthenticatedStream AuthenticatedStream {
|
||||
get { return this; }
|
||||
}
|
||||
|
||||
internal void ProcessAuthentication (LazyAsyncResult lazyResult)
|
||||
async Task ProcessAuthentication (
|
||||
bool runSynchronously, bool serverMode, string targetHost, SslProtocols enabledProtocols,
|
||||
X509Certificate serverCertificate, X509CertificateCollection clientCertificates, bool clientCertRequired)
|
||||
{
|
||||
var asyncRequest = new AsyncProtocolRequest (this, lazyResult);
|
||||
if (Interlocked.CompareExchange (ref asyncHandshakeRequest, asyncRequest, null) != null)
|
||||
throw new InvalidOperationException ("Invalid nested call.");
|
||||
|
||||
try {
|
||||
if (lastException != null)
|
||||
throw lastException;
|
||||
if (xobileTlsContext == null)
|
||||
throw new InvalidOperationException ();
|
||||
|
||||
readBuffer.Reset ();
|
||||
writeBuffer.Reset ();
|
||||
|
||||
try {
|
||||
asyncRequest.StartOperation (ProcessHandshake);
|
||||
} catch (Exception ex) {
|
||||
ExceptionDispatchInfo.Capture (SetException (ex)).Throw ();
|
||||
}
|
||||
} finally {
|
||||
if (lazyResult == null || lastException != null) {
|
||||
readBuffer.Reset ();
|
||||
writeBuffer.Reset ();
|
||||
asyncHandshakeRequest = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal void EndProcessAuthentication (IAsyncResult result)
|
||||
{
|
||||
if (result == null)
|
||||
throw new ArgumentNullException ("asyncResult");
|
||||
|
||||
var lazyResult = (LazyAsyncResult)result;
|
||||
if (Interlocked.Exchange (ref asyncHandshakeRequest, null) == null)
|
||||
throw new InvalidOperationException ("Invalid end call.");
|
||||
|
||||
lazyResult.InternalWaitForCompletion ();
|
||||
|
||||
readBuffer.Reset ();
|
||||
writeBuffer.Reset ();
|
||||
|
||||
var e = lazyResult.Result as Exception;
|
||||
if (e != null)
|
||||
ExceptionDispatchInfo.Capture (SetException (e)).Throw ();
|
||||
}
|
||||
|
||||
internal void ValidateCreateContext (bool serverMode, string targetHost, SslProtocols enabledProtocols, X509Certificate serverCertificate, X509CertificateCollection clientCertificates, bool clientCertRequired)
|
||||
{
|
||||
if (xobileTlsContext != null)
|
||||
throw new InvalidOperationException ();
|
||||
|
||||
if (serverMode) {
|
||||
if (serverCertificate == null)
|
||||
throw new ArgumentException ("serverCertificate");
|
||||
} else {
|
||||
throw new ArgumentException (nameof (serverCertificate));
|
||||
} else {
|
||||
if (targetHost == null)
|
||||
throw new ArgumentException ("targetHost");
|
||||
throw new ArgumentException (nameof (targetHost));
|
||||
if (targetHost.Length == 0)
|
||||
targetHost = "?" + Interlocked.Increment (ref uniqueNameInteger).ToString (NumberFormatInfo.InvariantInfo);
|
||||
}
|
||||
|
||||
xobileTlsContext = CreateContext (this, serverMode, targetHost, enabledProtocols, serverCertificate, clientCertificates, clientCertRequired);
|
||||
if (lastException != null)
|
||||
lastException.Throw ();
|
||||
|
||||
var asyncRequest = new AsyncHandshakeRequest (this, runSynchronously);
|
||||
if (Interlocked.CompareExchange (ref asyncHandshakeRequest, asyncRequest, null) != null)
|
||||
throw new InvalidOperationException ("Invalid nested call.");
|
||||
// Make sure no other async requests can be started during the handshake.
|
||||
if (Interlocked.CompareExchange (ref asyncReadRequest, asyncRequest, null) != null)
|
||||
throw new InvalidOperationException ("Invalid nested call.");
|
||||
if (Interlocked.CompareExchange (ref asyncWriteRequest, asyncRequest, null) != null)
|
||||
throw new InvalidOperationException ("Invalid nested call.");
|
||||
|
||||
AsyncProtocolResult result;
|
||||
|
||||
try {
|
||||
lock (ioLock) {
|
||||
if (xobileTlsContext != null)
|
||||
throw new InvalidOperationException ();
|
||||
readBuffer.Reset ();
|
||||
writeBuffer.Reset ();
|
||||
|
||||
xobileTlsContext = CreateContext (
|
||||
serverMode, targetHost, enabledProtocols, serverCertificate,
|
||||
clientCertificates, clientCertRequired);
|
||||
}
|
||||
|
||||
try {
|
||||
result = await asyncRequest.StartOperation (CancellationToken.None).ConfigureAwait (false);
|
||||
} catch (Exception ex) {
|
||||
result = new AsyncProtocolResult (SetException (GetSSPIException (ex)));
|
||||
}
|
||||
} finally {
|
||||
lock (ioLock) {
|
||||
readBuffer.Reset ();
|
||||
writeBuffer.Reset ();
|
||||
asyncWriteRequest = null;
|
||||
asyncReadRequest = null;
|
||||
asyncHandshakeRequest = null;
|
||||
}
|
||||
}
|
||||
|
||||
if (result.Error != null)
|
||||
result.Error.Throw ();
|
||||
}
|
||||
|
||||
protected abstract MobileTlsContext CreateContext (
|
||||
MobileAuthenticatedStream parent, bool serverMode, string targetHost,
|
||||
SSA.SslProtocols enabledProtocols, X509Certificate serverCertificate,
|
||||
X509CertificateCollection clientCertificates, bool askForClientCert);
|
||||
bool serverMode, string targetHost, SSA.SslProtocols enabledProtocols,
|
||||
X509Certificate serverCertificate, X509CertificateCollection clientCertificates,
|
||||
bool askForClientCert);
|
||||
|
||||
public override IAsyncResult BeginRead (byte[] buffer, int offset, int count, AsyncCallback asyncCallback, object asyncState)
|
||||
{
|
||||
return BeginReadOrWrite (ref asyncReadRequest, ref readBuffer, ProcessRead, new BufferOffsetSize (buffer, offset, count), asyncCallback, asyncState);
|
||||
var asyncRequest = new AsyncReadRequest (this, false, buffer, offset, count);
|
||||
var task = StartOperation (OperationType.Read, asyncRequest, CancellationToken.None);
|
||||
return TaskToApm.Begin (task, asyncCallback, asyncState);
|
||||
}
|
||||
|
||||
public override int EndRead (IAsyncResult asyncResult)
|
||||
{
|
||||
return (int)EndReadOrWrite (asyncResult, ref asyncReadRequest);
|
||||
return TaskToApm.End<int> (asyncResult);
|
||||
}
|
||||
|
||||
public override IAsyncResult BeginWrite (byte[] buffer, int offset, int count, AsyncCallback asyncCallback, object asyncState)
|
||||
{
|
||||
return BeginReadOrWrite (ref asyncWriteRequest, ref writeBuffer, ProcessWrite, new BufferOffsetSize (buffer, offset, count), asyncCallback, asyncState);
|
||||
var asyncRequest = new AsyncWriteRequest (this, false, buffer, offset, count);
|
||||
var task = StartOperation (OperationType.Write, asyncRequest, CancellationToken.None);
|
||||
return TaskToApm.Begin (task, asyncCallback, asyncState);
|
||||
}
|
||||
|
||||
public override void EndWrite (IAsyncResult asyncResult)
|
||||
{
|
||||
EndReadOrWrite (asyncResult, ref asyncWriteRequest);
|
||||
TaskToApm.End (asyncResult);
|
||||
}
|
||||
|
||||
public override int Read (byte[] buffer, int offset, int count)
|
||||
{
|
||||
return ProcessReadOrWrite (ref asyncReadRequest, ref readBuffer, ProcessRead, new BufferOffsetSize (buffer, offset, count), null);
|
||||
var asyncRequest = new AsyncReadRequest (this, true, buffer, offset, count);
|
||||
var task = StartOperation (OperationType.Read, asyncRequest, CancellationToken.None);
|
||||
return task.Result;
|
||||
}
|
||||
|
||||
public void Write (byte[] buffer)
|
||||
{
|
||||
Write (buffer, 0, buffer.Length);
|
||||
}
|
||||
|
||||
public override void Write (byte[] buffer, int offset, int count)
|
||||
{
|
||||
ProcessReadOrWrite (ref asyncWriteRequest, ref writeBuffer, ProcessWrite, new BufferOffsetSize (buffer, offset, count), null);
|
||||
var asyncRequest = new AsyncWriteRequest (this, true, buffer, offset, count);
|
||||
var task = StartOperation (OperationType.Write, asyncRequest, CancellationToken.None);
|
||||
task.Wait ();
|
||||
}
|
||||
|
||||
IAsyncResult BeginReadOrWrite (ref AsyncProtocolRequest nestedRequest, ref BufferOffsetSize2 internalBuffer, AsyncOperation operation, BufferOffsetSize userBuffer, AsyncCallback asyncCallback, object asyncState)
|
||||
public override Task<int> ReadAsync (byte[] buffer, int offset, int count, CancellationToken cancellationToken)
|
||||
{
|
||||
LazyAsyncResult lazyResult = new LazyAsyncResult (this, asyncState, asyncCallback);
|
||||
ProcessReadOrWrite (ref nestedRequest, ref internalBuffer, operation, userBuffer, lazyResult);
|
||||
return lazyResult;
|
||||
var asyncRequest = new AsyncReadRequest (this, false, buffer, offset, count);
|
||||
return StartOperation (OperationType.Read, asyncRequest, cancellationToken);
|
||||
}
|
||||
|
||||
object EndReadOrWrite (IAsyncResult asyncResult, ref AsyncProtocolRequest nestedRequest)
|
||||
public override Task WriteAsync (byte[] buffer, int offset, int count, CancellationToken cancellationToken)
|
||||
{
|
||||
if (asyncResult == null)
|
||||
throw new ArgumentNullException("asyncResult");
|
||||
var asyncRequest = new AsyncWriteRequest (this, false, buffer, offset, count);
|
||||
return StartOperation (OperationType.Write, asyncRequest, cancellationToken);
|
||||
}
|
||||
|
||||
var lazyResult = (LazyAsyncResult)asyncResult;
|
||||
async Task<int> StartOperation (OperationType type, AsyncProtocolRequest asyncRequest, CancellationToken cancellationToken)
|
||||
{
|
||||
CheckThrow (true, type != OperationType.Read);
|
||||
Debug ("StartOperationAsync: {0} {1}", asyncRequest, type);
|
||||
|
||||
if (Interlocked.Exchange (ref nestedRequest, null) == null)
|
||||
throw new InvalidOperationException ("Invalid end call.");
|
||||
|
||||
// No "artificial" timeouts implemented so far, InnerStream controls timeout.
|
||||
lazyResult.InternalWaitForCompletion ();
|
||||
|
||||
Debug ("EndReadOrWrite");
|
||||
|
||||
var e = lazyResult.Result as Exception;
|
||||
if (e != null) {
|
||||
var ioEx = e as IOException;
|
||||
if (ioEx != null)
|
||||
throw ioEx;
|
||||
throw new IOException ("read failed", e);
|
||||
if (type == OperationType.Read) {
|
||||
if (Interlocked.CompareExchange (ref asyncReadRequest, asyncRequest, null) != null)
|
||||
throw new InvalidOperationException ("Invalid nested call.");
|
||||
} else {
|
||||
if (Interlocked.CompareExchange (ref asyncWriteRequest, asyncRequest, null) != null)
|
||||
throw new InvalidOperationException ("Invalid nested call.");
|
||||
}
|
||||
|
||||
return lazyResult.Result;
|
||||
}
|
||||
AsyncProtocolResult result;
|
||||
|
||||
int ProcessReadOrWrite (ref AsyncProtocolRequest nestedRequest, ref BufferOffsetSize2 internalBuffer, AsyncOperation operation, BufferOffsetSize userBuffer, LazyAsyncResult lazyResult)
|
||||
{
|
||||
if (userBuffer == null || userBuffer.Buffer == null)
|
||||
throw new ArgumentNullException ("buffer");
|
||||
if (userBuffer.Offset < 0)
|
||||
throw new ArgumentOutOfRangeException ("offset");
|
||||
if (userBuffer.Size < 0 || userBuffer.Offset + userBuffer.Size > userBuffer.Buffer.Length)
|
||||
throw new ArgumentOutOfRangeException ("count");
|
||||
|
||||
CheckThrow (true);
|
||||
|
||||
var name = internalBuffer == readBuffer ? "read" : "write";
|
||||
Debug ("ProcessReadOrWrite: {0} {1}", name, userBuffer);
|
||||
|
||||
var asyncRequest = new AsyncProtocolRequest (this, lazyResult, userBuffer);
|
||||
return StartOperation (ref nestedRequest, ref internalBuffer, operation, asyncRequest, name);
|
||||
}
|
||||
|
||||
int StartOperation (ref AsyncProtocolRequest nestedRequest, ref BufferOffsetSize2 internalBuffer, AsyncOperation operation, AsyncProtocolRequest asyncRequest, string name)
|
||||
{
|
||||
if (Interlocked.CompareExchange (ref nestedRequest, asyncRequest, null) != null)
|
||||
throw new InvalidOperationException ("Invalid nested call.");
|
||||
|
||||
bool failed = false;
|
||||
try {
|
||||
internalBuffer.Reset ();
|
||||
asyncRequest.StartOperation (operation);
|
||||
return asyncRequest.UserResult;
|
||||
lock (ioLock) {
|
||||
if (type == OperationType.Read)
|
||||
readBuffer.Reset ();
|
||||
else
|
||||
writeBuffer.Reset ();
|
||||
}
|
||||
result = await asyncRequest.StartOperation (cancellationToken).ConfigureAwait (false);
|
||||
} catch (Exception e) {
|
||||
failed = true;
|
||||
if (e is IOException)
|
||||
throw;
|
||||
throw new IOException (name + " failed", e);
|
||||
var info = SetException (GetIOException (e, asyncRequest.Name + " failed"));
|
||||
result = new AsyncProtocolResult (info);
|
||||
} finally {
|
||||
if (asyncRequest.UserAsyncResult == null || failed) {
|
||||
internalBuffer.Reset ();
|
||||
nestedRequest = null;
|
||||
lock (ioLock) {
|
||||
if (type == OperationType.Read) {
|
||||
readBuffer.Reset ();
|
||||
asyncReadRequest = null;
|
||||
} else {
|
||||
writeBuffer.Reset ();
|
||||
asyncWriteRequest = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (result.Error != null)
|
||||
result.Error.Throw ();
|
||||
return result.UserResult;
|
||||
}
|
||||
|
||||
static int nextId;
|
||||
@@ -384,26 +390,31 @@ namespace Mono.Net.Security
|
||||
Console.Error.WriteLine ("MobileAuthenticatedStream({0}): {1}", ID, string.Format (message, args));
|
||||
}
|
||||
|
||||
#region Called back from native code via SslConnection
|
||||
#region Called back from native code via SslConnection
|
||||
|
||||
/*
|
||||
* Called from within SSLRead() and SSLHandshake(). We only access tha managed byte[] here.
|
||||
*/
|
||||
internal int InternalRead (byte[] buffer, int offset, int size, out bool wantMore)
|
||||
internal int InternalRead (byte[] buffer, int offset, int size, out bool outWantMore)
|
||||
{
|
||||
try {
|
||||
Debug ("InternalRead: {0} {1} {2} {3}", offset, size, asyncReadRequest != null, readBuffer != null);
|
||||
Debug ("InternalRead: {0} {1} {2} {3} {4}", offset, size,
|
||||
asyncHandshakeRequest != null ? "handshake" : "",
|
||||
asyncReadRequest != null ? "async" : "",
|
||||
readBuffer != null ? readBuffer.ToString () : "");
|
||||
var asyncRequest = asyncHandshakeRequest ?? asyncReadRequest;
|
||||
return InternalRead (asyncRequest, readBuffer, buffer, offset, size, out wantMore);
|
||||
var (ret, wantMore) = InternalRead (asyncRequest, readBuffer, buffer, offset, size);
|
||||
outWantMore = wantMore;
|
||||
return ret;
|
||||
} catch (Exception ex) {
|
||||
Debug ("InternalRead failed: {0}", ex);
|
||||
SetException_internal (ex);
|
||||
wantMore = false;
|
||||
SetException (GetIOException (ex, "InternalRead() failed"));
|
||||
outWantMore = false;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
int InternalRead (AsyncProtocolRequest asyncRequest, BufferOffsetSize internalBuffer, byte[] buffer, int offset, int size, out bool wantMore)
|
||||
(int, bool) InternalRead (AsyncProtocolRequest asyncRequest, BufferOffsetSize internalBuffer, byte[] buffer, int offset, int size)
|
||||
{
|
||||
if (asyncRequest == null)
|
||||
throw new InvalidOperationException ();
|
||||
@@ -422,11 +433,10 @@ namespace Mono.Net.Security
|
||||
* native function again.
|
||||
*/
|
||||
if (internalBuffer.Size == 0 && !internalBuffer.Complete) {
|
||||
Debug ("InternalRead #1: {0} {1}", internalBuffer.Offset, internalBuffer.TotalBytes);
|
||||
Debug ("InternalRead #1: {0} {1} {2}", internalBuffer.Offset, internalBuffer.TotalBytes, size);
|
||||
internalBuffer.Offset = internalBuffer.Size = 0;
|
||||
asyncRequest.RequestRead (size);
|
||||
wantMore = true;
|
||||
return 0;
|
||||
return (0, true);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -441,8 +451,7 @@ namespace Mono.Net.Security
|
||||
Buffer.BlockCopy (internalBuffer.Buffer, internalBuffer.Offset, buffer, offset, len);
|
||||
internalBuffer.Offset += len;
|
||||
internalBuffer.Size -= len;
|
||||
wantMore = !internalBuffer.Complete && len < size;
|
||||
return len;
|
||||
return (len, !internalBuffer.Complete && len < size);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -456,7 +465,7 @@ namespace Mono.Net.Security
|
||||
return InternalWrite (asyncRequest, writeBuffer, buffer, offset, size);
|
||||
} catch (Exception ex) {
|
||||
Debug ("InternalWrite failed: {0}", ex);
|
||||
SetException_internal (ex);
|
||||
SetException (GetIOException (ex, "InternalWrite() failed"));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -511,22 +520,30 @@ namespace Mono.Net.Security
|
||||
return true;
|
||||
}
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region Inner Stream
|
||||
#region Inner Stream
|
||||
|
||||
/*
|
||||
* Read / write data from the inner stream; we're only called from managed code and only manipulate
|
||||
* the internal buffers.
|
||||
*/
|
||||
internal int InnerRead (int requestedSize)
|
||||
internal async Task<int> InnerRead (bool sync, int requestedSize, CancellationToken cancellationToken)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested ();
|
||||
Debug ("InnerRead: {0} {1} {2} {3}", readBuffer.Offset, readBuffer.Size, readBuffer.Remaining, requestedSize);
|
||||
|
||||
var len = System.Math.Min (readBuffer.Remaining, requestedSize);
|
||||
if (len == 0)
|
||||
throw new InvalidOperationException ();
|
||||
var ret = InnerStream.Read (readBuffer.Buffer, readBuffer.EndOffset, len);
|
||||
|
||||
Task<int> task;
|
||||
if (sync)
|
||||
task = Task.Run (() => InnerStream.Read (readBuffer.Buffer, readBuffer.EndOffset, len));
|
||||
else
|
||||
task = InnerStream.ReadAsync (readBuffer.Buffer, readBuffer.EndOffset, len, cancellationToken);
|
||||
|
||||
var ret = await task.ConfigureAwait (false);
|
||||
Debug ("InnerRead done: {0} {1} - {2}", readBuffer.Remaining, len, ret);
|
||||
|
||||
if (ret >= 0) {
|
||||
@@ -549,165 +566,126 @@ namespace Mono.Net.Security
|
||||
return ret;
|
||||
}
|
||||
|
||||
internal void InnerWrite ()
|
||||
internal async Task InnerWrite (bool sync, CancellationToken cancellationToken)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested ();
|
||||
Debug ("InnerWrite: {0} {1}", writeBuffer.Offset, writeBuffer.Size);
|
||||
InnerFlush ();
|
||||
|
||||
if (writeBuffer.Size == 0)
|
||||
return;
|
||||
|
||||
Task task;
|
||||
if (sync)
|
||||
task = Task.Run (() => InnerStream.Write (writeBuffer.Buffer, writeBuffer.Offset, writeBuffer.Size));
|
||||
else
|
||||
task = InnerStream.WriteAsync (writeBuffer.Buffer, writeBuffer.Offset, writeBuffer.Size);
|
||||
|
||||
await task.ConfigureAwait (false);
|
||||
|
||||
writeBuffer.TotalBytes += writeBuffer.Size;
|
||||
writeBuffer.Offset = writeBuffer.Size = 0;
|
||||
}
|
||||
|
||||
internal void InnerFlush ()
|
||||
{
|
||||
if (writeBuffer.Size > 0) {
|
||||
InnerStream.Write (writeBuffer.Buffer, writeBuffer.Offset, writeBuffer.Size);
|
||||
writeBuffer.TotalBytes += writeBuffer.Size;
|
||||
writeBuffer.Offset = writeBuffer.Size = 0;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
#region Main async I/O loop
|
||||
|
||||
#region Main async I/O loop
|
||||
|
||||
AsyncOperationStatus ProcessHandshake (AsyncProtocolRequest asyncRequest, AsyncOperationStatus status)
|
||||
internal AsyncOperationStatus ProcessHandshake (AsyncOperationStatus status)
|
||||
{
|
||||
Debug ("ProcessHandshake: {0}", status);
|
||||
|
||||
/*
|
||||
* The first time we're called (AsyncOperationStatus.Initialize), we need to setup the SslContext and
|
||||
* start the handshake.
|
||||
*/
|
||||
if (status == AsyncOperationStatus.Initialize) {
|
||||
xobileTlsContext.StartHandshake ();
|
||||
return AsyncOperationStatus.Continue;
|
||||
} else if (status == AsyncOperationStatus.ReadDone) {
|
||||
// remote prematurely closed connection.
|
||||
throw new IOException ("Remote prematurely closed connection.");
|
||||
} else if (status != AsyncOperationStatus.Continue) {
|
||||
throw new InvalidOperationException ();
|
||||
}
|
||||
|
||||
/*
|
||||
* SSLHandshake() will return repeatedly with 'SslStatus.WouldBlock', we then need
|
||||
* to take care of I/O and call it again.
|
||||
*/
|
||||
if (!xobileTlsContext.ProcessHandshake ()) {
|
||||
lock (ioLock) {
|
||||
/*
|
||||
* Flush the internal write buffer.
|
||||
*/
|
||||
InnerFlush ();
|
||||
return AsyncOperationStatus.Continue;
|
||||
}
|
||||
* The first time we're called (AsyncOperationStatus.Initialize), we need to setup the SslContext and
|
||||
* start the handshake.
|
||||
*/
|
||||
if (status == AsyncOperationStatus.Initialize) {
|
||||
xobileTlsContext.StartHandshake ();
|
||||
return AsyncOperationStatus.Continue;
|
||||
} else if (status == AsyncOperationStatus.ReadDone) {
|
||||
throw new IOException (SR.net_auth_eof);
|
||||
} else if (status != AsyncOperationStatus.Continue) {
|
||||
throw new InvalidOperationException ();
|
||||
}
|
||||
|
||||
xobileTlsContext.FinishHandshake ();
|
||||
return AsyncOperationStatus.Complete;
|
||||
}
|
||||
|
||||
AsyncOperationStatus ProcessRead (AsyncProtocolRequest asyncRequest, AsyncOperationStatus status)
|
||||
{
|
||||
Debug ("ProcessRead - read user: {0} {1}", status, asyncRequest.UserBuffer);
|
||||
|
||||
int ret;
|
||||
bool wantMore;
|
||||
lock (ioLock) {
|
||||
ret = Context.Read (asyncRequest.UserBuffer.Buffer, asyncRequest.UserBuffer.Offset, asyncRequest.UserBuffer.Size, out wantMore);
|
||||
}
|
||||
Debug ("ProcessRead - read user done: {0} - {1} {2}", asyncRequest.UserBuffer, ret, wantMore);
|
||||
|
||||
if (ret < 0) {
|
||||
asyncRequest.UserResult = -1;
|
||||
return AsyncOperationStatus.Complete;
|
||||
}
|
||||
|
||||
asyncRequest.CurrentSize += ret;
|
||||
asyncRequest.UserBuffer.Offset += ret;
|
||||
asyncRequest.UserBuffer.Size -= ret;
|
||||
|
||||
Debug ("Process Read - read user done #1: {0} - {1} {2}", asyncRequest.UserBuffer, asyncRequest.CurrentSize, wantMore);
|
||||
|
||||
if (wantMore && asyncRequest.CurrentSize == 0)
|
||||
return AsyncOperationStatus.WantRead;
|
||||
|
||||
asyncRequest.ResetRead ();
|
||||
asyncRequest.UserResult = asyncRequest.CurrentSize;
|
||||
return AsyncOperationStatus.Complete;
|
||||
}
|
||||
|
||||
AsyncOperationStatus ProcessWrite (AsyncProtocolRequest asyncRequest, AsyncOperationStatus status)
|
||||
{
|
||||
Debug ("ProcessWrite - write user: {0} {1}", status, asyncRequest.UserBuffer);
|
||||
|
||||
if (asyncRequest.UserBuffer.Size == 0) {
|
||||
asyncRequest.UserResult = asyncRequest.CurrentSize;
|
||||
return AsyncOperationStatus.Complete;
|
||||
}
|
||||
|
||||
int ret;
|
||||
bool wantMore;
|
||||
lock (ioLock) {
|
||||
ret = Context.Write (asyncRequest.UserBuffer.Buffer, asyncRequest.UserBuffer.Offset, asyncRequest.UserBuffer.Size, out wantMore);
|
||||
}
|
||||
Debug ("ProcessWrite - write user done: {0} - {1} {2}", asyncRequest.UserBuffer, ret, wantMore);
|
||||
|
||||
if (ret < 0) {
|
||||
asyncRequest.UserResult = -1;
|
||||
return AsyncOperationStatus.Complete;
|
||||
}
|
||||
|
||||
asyncRequest.CurrentSize += ret;
|
||||
asyncRequest.UserBuffer.Offset += ret;
|
||||
asyncRequest.UserBuffer.Size -= ret;
|
||||
|
||||
if (wantMore || writeBuffer.Size > 0)
|
||||
return AsyncOperationStatus.WantWrite;
|
||||
|
||||
asyncRequest.ResetWrite ();
|
||||
asyncRequest.UserResult = asyncRequest.CurrentSize;
|
||||
return AsyncOperationStatus.Complete;
|
||||
}
|
||||
|
||||
AsyncOperationStatus ProcessClose (AsyncProtocolRequest asyncRequest, AsyncOperationStatus status)
|
||||
{
|
||||
Debug ("ProcessClose: {0}", status);
|
||||
|
||||
lock (ioLock) {
|
||||
if (xobileTlsContext == null)
|
||||
/*
|
||||
* SSLHandshake() will return repeatedly with 'SslStatus.WouldBlock', we then need
|
||||
* to take care of I/O and call it again.
|
||||
*/
|
||||
if (xobileTlsContext.ProcessHandshake ()) {
|
||||
xobileTlsContext.FinishHandshake ();
|
||||
return AsyncOperationStatus.Complete;
|
||||
|
||||
xobileTlsContext.Close ();
|
||||
xobileTlsContext = null;
|
||||
}
|
||||
return AsyncOperationStatus.Continue;
|
||||
}
|
||||
}
|
||||
|
||||
AsyncOperationStatus ProcessFlush (AsyncProtocolRequest asyncRequest, AsyncOperationStatus status)
|
||||
internal (int, bool) ProcessRead (BufferOffsetSize userBuffer)
|
||||
{
|
||||
Debug ("ProcessFlush: {0}", status);
|
||||
return AsyncOperationStatus.Complete;
|
||||
lock (ioLock) {
|
||||
// This operates on the internal buffer and will never block.
|
||||
var ret = xobileTlsContext.Read (userBuffer.Buffer, userBuffer.Offset, userBuffer.Size, out bool wantMore);
|
||||
return (ret, wantMore);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
internal (int, bool) ProcessWrite (BufferOffsetSize userBuffer)
|
||||
{
|
||||
lock (ioLock) {
|
||||
// This operates on the internal buffer and will never block.
|
||||
var ret = xobileTlsContext.Write (userBuffer.Buffer, userBuffer.Offset, userBuffer.Size, out bool wantMore);
|
||||
return (ret, wantMore);
|
||||
}
|
||||
}
|
||||
|
||||
internal AsyncOperationStatus ProcessShutdown (AsyncOperationStatus status)
|
||||
{
|
||||
Debug ("ProcessShutdown: {0}", status);
|
||||
|
||||
lock (ioLock) {
|
||||
xobileTlsContext.Shutdown ();
|
||||
shutdown = true;
|
||||
return AsyncOperationStatus.Complete;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public override bool IsServer {
|
||||
get { return xobileTlsContext != null && xobileTlsContext.IsServer; }
|
||||
get {
|
||||
CheckThrow (false);
|
||||
return xobileTlsContext != null && xobileTlsContext.IsServer;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool IsAuthenticated {
|
||||
get { return xobileTlsContext != null && lastException == null && xobileTlsContext.IsAuthenticated; }
|
||||
get {
|
||||
lock (ioLock) {
|
||||
// Don't use CheckThrow(), we want to return false if we're not authenticated.
|
||||
return xobileTlsContext != null && lastException == null && xobileTlsContext.IsAuthenticated;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override bool IsMutuallyAuthenticated {
|
||||
get {
|
||||
return IsAuthenticated &&
|
||||
(Context.IsServer? Context.LocalServerCertificate: Context.LocalClientCertificate) != null &&
|
||||
Context.IsRemoteCertificateAvailable;
|
||||
lock (ioLock) {
|
||||
// Don't use CheckThrow() here.
|
||||
if (!IsAuthenticated)
|
||||
return false;
|
||||
if ((xobileTlsContext.IsServer ? xobileTlsContext.LocalServerCertificate : xobileTlsContext.LocalClientCertificate) == null)
|
||||
return false;
|
||||
return xobileTlsContext.IsRemoteCertificateAvailable;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Dispose (bool disposing)
|
||||
{
|
||||
try {
|
||||
lastException = new ObjectDisposedException ("MobileAuthenticatedStream");
|
||||
lock (ioLock) {
|
||||
Debug ("Dispose: {0}", xobileTlsContext != null);
|
||||
lastException = ExceptionDispatchInfo.Capture (new ObjectDisposedException ("MobileAuthenticatedStream"));
|
||||
if (xobileTlsContext != null) {
|
||||
xobileTlsContext.Dispose ();
|
||||
xobileTlsContext = null;
|
||||
@@ -720,26 +698,53 @@ namespace Mono.Net.Security
|
||||
|
||||
public override void Flush ()
|
||||
{
|
||||
CheckThrow (true);
|
||||
var asyncRequest = new AsyncProtocolRequest (this, null);
|
||||
StartOperation (ref asyncWriteRequest, ref writeBuffer, ProcessFlush, asyncRequest, "flush");
|
||||
// Write() automatically flushes the underlying stream.
|
||||
}
|
||||
|
||||
public override void Close ()
|
||||
{
|
||||
/*
|
||||
* SSLClose() is a little bit tricky as it might attempt to send a close_notify alert
|
||||
* and thus call our write callback.
|
||||
*
|
||||
* It is also not thread-safe with SSLRead() or SSLWrite(), so we need to take the I/O lock here.
|
||||
*/
|
||||
if (Interlocked.Exchange (ref closeRequested, 1) == 1)
|
||||
return;
|
||||
if (xobileTlsContext == null)
|
||||
return;
|
||||
public SslProtocols SslProtocol {
|
||||
get {
|
||||
lock (ioLock) {
|
||||
CheckThrow (true);
|
||||
return (SslProtocols)xobileTlsContext.NegotiatedProtocol;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var asyncRequest = new AsyncProtocolRequest (this, null);
|
||||
StartOperation (ref asyncWriteRequest, ref writeBuffer, ProcessClose, asyncRequest, "close");
|
||||
public X509Certificate RemoteCertificate {
|
||||
get {
|
||||
lock (ioLock) {
|
||||
CheckThrow (true);
|
||||
return xobileTlsContext.RemoteCertificate;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public X509Certificate LocalCertificate {
|
||||
get {
|
||||
lock (ioLock) {
|
||||
CheckThrow (true);
|
||||
return InternalLocalCertificate;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public X509Certificate InternalLocalCertificate {
|
||||
get {
|
||||
lock (ioLock) {
|
||||
CheckThrow (false);
|
||||
if (xobileTlsContext == null)
|
||||
return null;
|
||||
return xobileTlsContext.IsServer ? xobileTlsContext.LocalServerCertificate : xobileTlsContext.LocalClientCertificate;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public MSI.MonoTlsConnectionInfo GetConnectionInfo ()
|
||||
{
|
||||
lock (ioLock) {
|
||||
CheckThrow (true);
|
||||
return xobileTlsContext.ConnectionInfo;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
@@ -769,7 +774,7 @@ namespace Mono.Net.Security
|
||||
}
|
||||
|
||||
public override bool CanWrite {
|
||||
get { return IsAuthenticated & InnerStream.CanWrite; }
|
||||
get { return IsAuthenticated & InnerStream.CanWrite && !shutdown; }
|
||||
}
|
||||
|
||||
public override bool CanSeek {
|
||||
@@ -803,46 +808,10 @@ namespace Mono.Net.Security
|
||||
set { InnerStream.WriteTimeout = value; }
|
||||
}
|
||||
|
||||
public SslProtocols SslProtocol {
|
||||
get {
|
||||
CheckThrow (true);
|
||||
return (SslProtocols)Context.NegotiatedProtocol;
|
||||
}
|
||||
}
|
||||
|
||||
public X509Certificate RemoteCertificate {
|
||||
get {
|
||||
CheckThrow (true);
|
||||
return Context.RemoteCertificate;
|
||||
}
|
||||
}
|
||||
|
||||
public X509Certificate LocalCertificate {
|
||||
get {
|
||||
CheckThrow (true);
|
||||
return InternalLocalCertificate;
|
||||
}
|
||||
}
|
||||
|
||||
public X509Certificate InternalLocalCertificate {
|
||||
get {
|
||||
CheckThrow (false);
|
||||
if (!HasContext)
|
||||
return null;
|
||||
return Context.IsServer ? Context.LocalServerCertificate : Context.LocalClientCertificate;
|
||||
}
|
||||
}
|
||||
|
||||
public MSI.MonoTlsConnectionInfo GetConnectionInfo ()
|
||||
{
|
||||
CheckThrow (true);
|
||||
return Context.ConnectionInfo;
|
||||
}
|
||||
|
||||
public SSA.CipherAlgorithmType CipherAlgorithm {
|
||||
get {
|
||||
CheckThrow (true);
|
||||
var info = Context.ConnectionInfo;
|
||||
var info = GetConnectionInfo ();
|
||||
if (info == null)
|
||||
return SSA.CipherAlgorithmType.None;
|
||||
switch (info.CipherAlgorithmType) {
|
||||
@@ -861,7 +830,7 @@ namespace Mono.Net.Security
|
||||
public SSA.HashAlgorithmType HashAlgorithm {
|
||||
get {
|
||||
CheckThrow (true);
|
||||
var info = Context.ConnectionInfo;
|
||||
var info = GetConnectionInfo ();
|
||||
if (info == null)
|
||||
return SSA.HashAlgorithmType.None;
|
||||
switch (info.HashAlgorithmType) {
|
||||
@@ -883,7 +852,7 @@ namespace Mono.Net.Security
|
||||
public SSA.ExchangeAlgorithmType KeyExchangeAlgorithm {
|
||||
get {
|
||||
CheckThrow (true);
|
||||
var info = Context.ConnectionInfo;
|
||||
var info = GetConnectionInfo ();
|
||||
if (info == null)
|
||||
return SSA.ExchangeAlgorithmType.None;
|
||||
switch (info.ExchangeAlgorithmType) {
|
||||
@@ -898,7 +867,7 @@ namespace Mono.Net.Security
|
||||
}
|
||||
}
|
||||
|
||||
#region Need to Implement
|
||||
#region Need to Implement
|
||||
public int CipherStrength {
|
||||
get {
|
||||
throw new NotImplementedException ();
|
||||
@@ -920,7 +889,7 @@ namespace Mono.Net.Security
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -169,7 +169,7 @@ namespace Mono.Net.Security
|
||||
|
||||
public abstract int Write (byte[] buffer, int offset, int count, out bool wantMore);
|
||||
|
||||
public abstract void Close ();
|
||||
public abstract void Shutdown ();
|
||||
|
||||
protected bool ValidateCertificate (X509Certificate leaf, X509Chain chain)
|
||||
{
|
||||
|
||||
@@ -83,6 +83,8 @@ namespace Mono.Net.Security
|
||||
if (initialized)
|
||||
return;
|
||||
|
||||
InitializeProviderRegistration ();
|
||||
|
||||
MSI.MonoTlsProvider provider;
|
||||
try {
|
||||
provider = CreateDefaultProviderImpl ();
|
||||
|
||||
@@ -9,6 +9,8 @@ partial class SR
|
||||
{
|
||||
public const string mono_net_io_shutdown = "mono_net_io_shutdown";
|
||||
public const string mono_net_io_renegotiate = "mono_net_io_renegotiate";
|
||||
|
||||
public const string net_ssl_io_already_shutdown = "Write operations are not allowed after the channel was shutdown.";
|
||||
|
||||
public const string net_log_set_socketoption_reuseport_default_on = "net_log_set_socketoption_reuseport_default_on";
|
||||
public const string net_log_set_socketoption_reuseport_not_supported = "net_log_set_socketoption_reuseport_not_supported";
|
||||
|
||||
@@ -46,6 +46,7 @@ namespace System.ComponentModel
|
||||
case 32: /* ERROR_SHARING_VIOLATION */ return "Sharing violation";
|
||||
case 33: /* ERROR_LOCK_VIOLATION */ return "Lock violation";
|
||||
case 50: /* ERROR_NOT_SUPPORTED */ return "Operation not supported";
|
||||
case 55: /* ERROR_DEV_NOT_EXIST */ return "Device does not exist";
|
||||
case 87: /* ERROR_INVALID_PARAMETER */ return "Invalid parameter";
|
||||
case 120: /* ERROR_CALL_NOT_IMPLEMENTED */ return "Call not implemented";
|
||||
case 123: /* ERROR_INVALID_NAME */ return "Invalid name";
|
||||
@@ -142,7 +143,6 @@ namespace System.ComponentModel
|
||||
case 52: /* ERROR_DUP_NAME */ return "Duplicate name";
|
||||
case 53: /* ERROR_BAD_NETPATH */ return "Bad netpath";
|
||||
case 54: /* ERROR_NETWORK_BUSY */ return "Network busy";
|
||||
case 55: /* ERROR_DEV_NOT_EXIST */ return "Device does not exist";
|
||||
case 56: /* ERROR_TOO_MANY_CMDS */ return "Too many commands";
|
||||
case 57: /* ERROR_ADAP_HDW_ERR */ return "ADAP HDW error";
|
||||
case 58: /* ERROR_BAD_NET_RESP */ return "Bad net response";
|
||||
|
||||
@@ -223,6 +223,11 @@ namespace System.Net.Security
|
||||
return Impl.AuthenticateAsServerAsync (serverCertificate, clientCertificateRequired, enabledSslProtocols, checkCertificateRevocation);
|
||||
}
|
||||
|
||||
public virtual Task ShutdownAsync ()
|
||||
{
|
||||
return Impl.ShutdownAsync ();
|
||||
}
|
||||
|
||||
public override bool IsAuthenticated {
|
||||
get { return Impl.IsAuthenticated; }
|
||||
}
|
||||
|
||||
@@ -152,6 +152,11 @@ namespace System.Net.Security
|
||||
throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
|
||||
}
|
||||
|
||||
public virtual Task ShutdownAsync ()
|
||||
{
|
||||
throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
|
||||
}
|
||||
|
||||
public override bool IsAuthenticated {
|
||||
get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
|
||||
}
|
||||
|
||||
@@ -24,11 +24,12 @@
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
//
|
||||
using System.Security.Principal;
|
||||
namespace System.Net {
|
||||
public class HttpListenerBasicIdentity {
|
||||
internal const string EXCEPTION_MESSAGE = "System.Net.HttpListenerBasicIdentity is not supported on the current platform.";
|
||||
public class HttpListenerBasicIdentity : GenericIdentity {
|
||||
const string EXCEPTION_MESSAGE = "System.Net.HttpListenerBasicIdentity is not supported on the current platform.";
|
||||
|
||||
public HttpListenerBasicIdentity (string username, string password)
|
||||
public HttpListenerBasicIdentity (string username, string password) : base (username, "Basic")
|
||||
{
|
||||
throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
|
||||
}
|
||||
|
||||
@@ -56,7 +56,6 @@ namespace System.Net
|
||||
object socketLock = new object ();
|
||||
IWebConnectionState state;
|
||||
WebExceptionStatus status;
|
||||
WaitCallback initConn;
|
||||
bool keepAlive;
|
||||
byte [] buffer;
|
||||
EventHandler abortHandler;
|
||||
|
||||
@@ -37,12 +37,18 @@ namespace MonoTests.System.Net {
|
||||
[ExpectedException (typeof (ArgumentNullException))]
|
||||
public void Basic1 ()
|
||||
{
|
||||
#if MONOTOUCH_WATCH || __WATCHOS__
|
||||
Assert.Ignore ("HttpListenerBasicIdentity is not supported on watchOS");
|
||||
#endif
|
||||
HttpListenerBasicIdentity bi = new HttpListenerBasicIdentity (null, null);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Basic2 ()
|
||||
{
|
||||
#if MONOTOUCH_WATCH || __WATCHOS__
|
||||
Assert.Ignore ("HttpListenerBasicIdentity is not supported on watchOS");
|
||||
#endif
|
||||
HttpListenerBasicIdentity bi = new HttpListenerBasicIdentity ("", null);
|
||||
Assert.AreEqual ("Basic", bi.AuthenticationType, "#01");
|
||||
Assert.AreEqual ("", bi.Name, "#02");
|
||||
@@ -53,6 +59,9 @@ namespace MonoTests.System.Net {
|
||||
[Test]
|
||||
public void Basic3 ()
|
||||
{
|
||||
#if MONOTOUCH_WATCH || __WATCHOS__
|
||||
Assert.Ignore ("HttpListenerBasicIdentity is not supported on watchOS");
|
||||
#endif
|
||||
HttpListenerBasicIdentity bi = new HttpListenerBasicIdentity ("hey", null);
|
||||
Assert.AreEqual ("Basic", bi.AuthenticationType, "#01");
|
||||
Assert.AreEqual ("hey", bi.Name, "#02");
|
||||
@@ -63,6 +72,9 @@ namespace MonoTests.System.Net {
|
||||
[Test]
|
||||
public void Basic4 ()
|
||||
{
|
||||
#if MONOTOUCH_WATCH || __WATCHOS__
|
||||
Assert.Ignore ("HttpListenerBasicIdentity is not supported on watchOS");
|
||||
#endif
|
||||
HttpListenerBasicIdentity bi = new HttpListenerBasicIdentity ("hey", "pass");
|
||||
Assert.AreEqual ("Basic", bi.AuthenticationType, "#01");
|
||||
Assert.AreEqual ("hey", bi.Name, "#02");
|
||||
|
||||
@@ -276,6 +276,7 @@ ReferenceSources/SettingsSectionInternal.cs
|
||||
ReferenceSources/SecureStringHelper.cs
|
||||
ReferenceSources/Socket.cs
|
||||
ReferenceSources/SR.cs
|
||||
ReferenceSources/SR2.cs
|
||||
ReferenceSources/SRCategoryAttribute.cs
|
||||
ReferenceSources/Win32Exception.cs
|
||||
|
||||
|
||||
@@ -245,7 +245,6 @@ Mono.Net.Dns/ResolverError.cs
|
||||
Mono.Net.Dns/SimpleResolverEventArgs.cs
|
||||
ReferenceSources/BinaryCompatibility.cs
|
||||
ReferenceSources/ConfigurationManagerInternalFactory.cs
|
||||
ReferenceSources/SR2.cs
|
||||
|
||||
../referencesource/System/misc/PrivilegedConfigurationManager.cs
|
||||
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
thisdir = class/Xunit.NetCore.Extensions
|
||||
SUBDIRS =
|
||||
include ../../build/rules.make
|
||||
|
||||
XUNIT_LIBS := xunit.core xunit.abstractions xunit.execution.desktop xunit.assert
|
||||
|
||||
LIBRARY = Xunit.NetCore.Extensions.dll
|
||||
LIB_REFS = System System.Core Facades/System.Runtime.InteropServices.RuntimeInformation Facades/System.Runtime Facades/System.Threading.Tasks
|
||||
LIB_MCS_FLAGS = $(patsubst %,-r:$(topdir)/../external/xunit-binaries/%.dll,$(XUNIT_LIBS))
|
||||
|
||||
EXTRA_DISTFILES =
|
||||
|
||||
NO_TEST = yes
|
||||
NO_INSTALL = yes
|
||||
NO_SIGN_ASSEMBLY = yes
|
||||
|
||||
include ../../build/library.make
|
||||
@@ -1,13 +0,0 @@
|
||||
using System;
|
||||
using Xunit;
|
||||
using Xunit.Sdk;
|
||||
|
||||
namespace Microsoft.Xunit.Performance
|
||||
{
|
||||
[TraitDiscoverer("Microsoft.Xunit.Performance.BenchmarkDiscoverer", "Xunit.NetCore.Extensions")]
|
||||
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
|
||||
public class BenchmarkAttribute : Attribute, ITraitAttribute
|
||||
{
|
||||
public long InnerIterationCount { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using Xunit.Sdk;
|
||||
using Xunit.Abstractions;
|
||||
|
||||
namespace Xunit.NetCore.Extensions
|
||||
{
|
||||
public class BenchmarkDiscoverer : ITraitDiscoverer
|
||||
{
|
||||
public IEnumerable<KeyValuePair<string, string>> GetTraits(IAttributeInfo traitAttribute)
|
||||
{
|
||||
yield return new KeyValuePair<string, string>("Benchmark", "True");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
../../../external/buildtools/src/xunit.netcore.extensions/*.cs
|
||||
../../../external/buildtools/src/xunit.netcore.extensions/Attributes/*.cs
|
||||
../../../external/buildtools/src/xunit.netcore.extensions/Discoverers/*.cs
|
||||
|
||||
Microsoft.Xunit.Performance/BenchmarkAttribute.cs
|
||||
Microsoft.Xunit.Performance/BenchmarkDiscover.cs
|
||||
@@ -35,6 +35,7 @@ namespace System.Reflection.Emit
|
||||
[ComVisible (true)]
|
||||
[Serializable]
|
||||
[Flags]
|
||||
#region Sync with sre-internals.h
|
||||
public enum AssemblyBuilderAccess {
|
||||
Run = 1,
|
||||
Save = 2,
|
||||
@@ -42,4 +43,5 @@ namespace System.Reflection.Emit
|
||||
ReflectionOnly = 6,
|
||||
RunAndCollect = 9
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
@@ -131,7 +131,7 @@ namespace System.Reflection.Emit {
|
||||
}
|
||||
|
||||
[MethodImplAttribute(MethodImplOptions.InternalCall)]
|
||||
private extern void create_dynamic_method (DynamicMethod m);
|
||||
private static extern void create_dynamic_method (DynamicMethod m);
|
||||
|
||||
private void CreateDynMethod () {
|
||||
if (mhandle.Value == IntPtr.Zero) {
|
||||
|
||||
@@ -71,6 +71,9 @@ namespace System.Reflection.Emit {
|
||||
return _tb.InternalResolve ();
|
||||
}
|
||||
|
||||
internal override Type RuntimeResolve () {
|
||||
return _tb.RuntimeResolve ();
|
||||
}
|
||||
|
||||
public override Assembly Assembly {
|
||||
get {
|
||||
|
||||
@@ -229,7 +229,9 @@ namespace System.Reflection.Emit {
|
||||
}
|
||||
|
||||
internal FieldInfo RuntimeResolve () {
|
||||
return typeb.CreateType ().GetField (this);
|
||||
// typeb.CreateType() populates this.handle
|
||||
var type_handle = new RuntimeTypeHandle (typeb.CreateType () as RuntimeType);
|
||||
return FieldInfo.GetFieldFromHandle (handle, type_handle);
|
||||
}
|
||||
|
||||
public override Module Module {
|
||||
|
||||
@@ -87,7 +87,7 @@ namespace System.Reflection.Emit
|
||||
internal override Type InternalResolve ()
|
||||
{
|
||||
if (mbuilder != null)
|
||||
return MethodBase.GetMethodFromHandle (mbuilder.MethodHandleInternal).GetGenericArguments () [index];
|
||||
return MethodBase.GetMethodFromHandle (mbuilder.MethodHandleInternal, mbuilder.TypeBuilder.InternalResolve ().TypeHandle).GetGenericArguments () [index];
|
||||
return tbuilder.InternalResolve ().GetGenericArguments () [index];
|
||||
}
|
||||
|
||||
|
||||
@@ -814,7 +814,7 @@ namespace System.Reflection.Emit {
|
||||
make_room (6);
|
||||
ll_emit (opcode);
|
||||
int token = token_gen.GetToken (cls, opcode != OpCodes.Ldtoken);
|
||||
if (cls is TypeBuilderInstantiation || cls is SymbolType || cls is TypeBuilder || cls is GenericTypeParameterBuilder)
|
||||
if (cls is TypeBuilderInstantiation || cls is SymbolType || cls is TypeBuilder || cls is GenericTypeParameterBuilder || cls is EnumBuilder)
|
||||
add_token_fixup (cls);
|
||||
emit_int (token);
|
||||
}
|
||||
|
||||
@@ -749,6 +749,14 @@ namespace System.Reflection.Emit {
|
||||
token = typedef_tokengen --;
|
||||
else
|
||||
token = typeref_tokengen --;
|
||||
} else if (member is EnumBuilder) {
|
||||
token = GetPseudoToken ((member as EnumBuilder).GetTypeBuilder(), create_open_instance);
|
||||
if (create_open_instance)
|
||||
inst_tokens_open[member] = token;
|
||||
else
|
||||
inst_tokens[member] = token;
|
||||
// n.b. don't register with the runtime, the TypeBuilder already did it.
|
||||
return token;
|
||||
} else if (member is ConstructorBuilder) {
|
||||
if (member.Module == this && !(member as ConstructorBuilder).TypeBuilder.ContainsGenericParameters)
|
||||
token = methoddef_tokengen --;
|
||||
@@ -779,7 +787,8 @@ namespace System.Reflection.Emit {
|
||||
}
|
||||
|
||||
internal int GetToken (MemberInfo member, bool create_open_instance) {
|
||||
if (member is TypeBuilderInstantiation || member is FieldOnTypeBuilderInst || member is ConstructorOnTypeBuilderInst || member is MethodOnTypeBuilderInst || member is SymbolType || member is FieldBuilder || member is TypeBuilder || member is ConstructorBuilder || member is MethodBuilder || member is GenericTypeParameterBuilder)
|
||||
if (member is TypeBuilderInstantiation || member is FieldOnTypeBuilderInst || member is ConstructorOnTypeBuilderInst || member is MethodOnTypeBuilderInst || member is SymbolType || member is FieldBuilder || member is TypeBuilder || member is ConstructorBuilder || member is MethodBuilder || member is GenericTypeParameterBuilder ||
|
||||
member is EnumBuilder)
|
||||
return GetPseudoToken (member, create_open_instance);
|
||||
return getToken (this, member, create_open_instance);
|
||||
}
|
||||
@@ -872,6 +881,8 @@ namespace System.Reflection.Emit {
|
||||
finished = (member as FieldBuilder).RuntimeResolve ();
|
||||
} else if (member is TypeBuilder) {
|
||||
finished = (member as TypeBuilder).RuntimeResolve ();
|
||||
} else if (member is EnumBuilder) {
|
||||
finished = (member as EnumBuilder).RuntimeResolve ();
|
||||
} else if (member is ConstructorBuilder) {
|
||||
finished = (member as ConstructorBuilder).RuntimeResolve ();
|
||||
} else if (member is MethodBuilder) {
|
||||
|
||||
@@ -741,7 +741,7 @@ namespace System.Runtime.InteropServices
|
||||
#else
|
||||
public static bool IsComObject (object o)
|
||||
{
|
||||
throw new PlatformNotSupportedException ();
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -73,19 +73,59 @@ namespace System.Runtime.Remoting.Messaging {
|
||||
[Serializable]
|
||||
internal class CADMethodRef
|
||||
{
|
||||
internal string FullTypeName;
|
||||
internal IntPtr MethodHandlePtr;
|
||||
Type[] GetTypes (string[] typeArray)
|
||||
{
|
||||
Type[] res = new Type [typeArray.Length];
|
||||
for (int i = 0; i < typeArray.Length; ++i)
|
||||
res [i] = Type.GetType (typeArray [i], true);
|
||||
return res;
|
||||
}
|
||||
|
||||
public RuntimeMethodHandle MethodHandle {
|
||||
get {
|
||||
return new RuntimeMethodHandle (MethodHandlePtr);
|
||||
}
|
||||
bool ctor;
|
||||
string typeName;
|
||||
string methodName;
|
||||
string[] param_names;
|
||||
string[] generic_arg_names;
|
||||
|
||||
public MethodBase Resolve ()
|
||||
{
|
||||
Type type = Type.GetType (typeName, true);
|
||||
MethodBase sig_cand = null;
|
||||
Type[] param_types = GetTypes (param_names);
|
||||
if (ctor)
|
||||
sig_cand = type.GetConstructor (BindingFlags.Public|BindingFlags.NonPublic|BindingFlags.Instance, null, param_types, null);
|
||||
else
|
||||
sig_cand = type.GetMethod (methodName, BindingFlags.Public|BindingFlags.NonPublic|BindingFlags.Instance, null, param_types, null);
|
||||
|
||||
if (sig_cand != null && generic_arg_names != null)
|
||||
sig_cand = ((MethodInfo)sig_cand).MakeGenericMethod (GetTypes (generic_arg_names));
|
||||
|
||||
if (sig_cand == null)
|
||||
throw new RemotingException ($"Method '{methodName}' not found in type '{typeName}'");
|
||||
|
||||
return sig_cand;
|
||||
}
|
||||
|
||||
public CADMethodRef (IMethodMessage msg)
|
||||
{
|
||||
MethodHandlePtr = msg.MethodBase.MethodHandle.Value;
|
||||
FullTypeName = msg.MethodBase.DeclaringType.AssemblyQualifiedName;
|
||||
MethodBase method = msg.MethodBase;
|
||||
typeName = method.DeclaringType.AssemblyQualifiedName;
|
||||
ctor = method.IsConstructor;
|
||||
methodName = method.Name;
|
||||
|
||||
if (!ctor && method.IsGenericMethod) {
|
||||
var ga = method.GetGenericArguments ();
|
||||
generic_arg_names = new string [ga.Length];
|
||||
for (int i = 0; i < ga.Length; ++i)
|
||||
generic_arg_names [i] = ga [i].AssemblyQualifiedName;
|
||||
|
||||
method = ((MethodInfo)method).GetGenericMethodDefinition ();
|
||||
}
|
||||
|
||||
var param_types = method.GetParameters ();
|
||||
param_names = new string [param_types.Length];
|
||||
for (int i = 0; i < param_types.Length; ++i)
|
||||
param_names [i] = param_types [i].ParameterType.AssemblyQualifiedName;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,62 +142,11 @@ namespace System.Runtime.Remoting.Messaging {
|
||||
serializedMethod = CADSerializer.SerializeObject (methodRef).GetBuffer ();
|
||||
}
|
||||
|
||||
internal MethodBase method {
|
||||
get { return GetMethod (); }
|
||||
}
|
||||
|
||||
internal MethodBase GetMethod ()
|
||||
{
|
||||
CADMethodRef methRef = (CADMethodRef)CADSerializer.DeserializeObjectSafe (serializedMethod);
|
||||
|
||||
MethodBase _method;
|
||||
|
||||
Type tt = Type.GetType (methRef.FullTypeName, true);
|
||||
if (tt.IsGenericType || tt.IsGenericTypeDefinition) {
|
||||
_method = MethodBase.GetMethodFromHandleNoGenericCheck (methRef.MethodHandle);
|
||||
} else {
|
||||
_method = MethodBase.GetMethodFromHandle (methRef.MethodHandle);
|
||||
}
|
||||
|
||||
if (tt != _method.DeclaringType) {
|
||||
// The target domain has loaded the type from a different assembly.
|
||||
// We need to locate the correct type and get the method from it
|
||||
Type [] signature = GetSignature (_method, true);
|
||||
if (_method.IsGenericMethod) {
|
||||
MethodBase [] methods = tt.GetMethods (BindingFlags.Public|BindingFlags.NonPublic|BindingFlags.Instance);
|
||||
Type [] base_args = _method.GetGenericArguments ();
|
||||
foreach (MethodBase method in methods) {
|
||||
if (!method.IsGenericMethod || method.Name != _method.Name)
|
||||
continue;
|
||||
Type [] method_args = method.GetGenericArguments ();
|
||||
if (base_args.Length != method_args.Length)
|
||||
continue;
|
||||
|
||||
MethodInfo method_instance = ((MethodInfo) method).MakeGenericMethod (base_args);
|
||||
Type [] base_sig = GetSignature (method_instance, false);
|
||||
if (base_sig.Length != signature.Length) {
|
||||
continue;
|
||||
}
|
||||
bool dont = false;
|
||||
for (int i = base_sig.Length - 1; i >= 0; i--) {
|
||||
if (base_sig [i] != signature [i]) {
|
||||
dont = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (dont)
|
||||
continue;
|
||||
return method_instance;
|
||||
}
|
||||
return _method;
|
||||
}
|
||||
|
||||
MethodBase mb = tt.GetMethod (_method.Name, BindingFlags.Public|BindingFlags.NonPublic|BindingFlags.Instance, null, signature, null);
|
||||
if (mb == null)
|
||||
throw new RemotingException ("Method '" + _method.Name + "' not found in type '" + tt + "'");
|
||||
return mb;
|
||||
}
|
||||
return _method;
|
||||
return methRef.Resolve ();
|
||||
}
|
||||
|
||||
static protected Type [] GetSignature (MethodBase methodBase, bool load)
|
||||
@@ -174,6 +163,7 @@ namespace System.Runtime.Remoting.Messaging {
|
||||
}
|
||||
return signature;
|
||||
}
|
||||
|
||||
// Helper to marshal properties
|
||||
internal static int MarshalProperties (IDictionary dict, ref ArrayList args) {
|
||||
IDictionary serDict = dict;
|
||||
@@ -457,7 +447,7 @@ namespace System.Runtime.Remoting.Messaging {
|
||||
_returnValue = MarshalArgument ( retMsg.ReturnValue, ref serializeList);
|
||||
_args = MarshalArguments ( retMsg.Args, ref serializeList);
|
||||
|
||||
_sig = GetSignature (method, true);
|
||||
_sig = GetSignature (GetMethod (), true);
|
||||
|
||||
if (null != retMsg.Exception) {
|
||||
if (null == serializeList)
|
||||
|
||||
@@ -495,8 +495,11 @@ namespace System
|
||||
|
||||
public override int GetHashCode ()
|
||||
{
|
||||
/* same implementation as CoreCLR */
|
||||
return GetType ().GetHashCode ();
|
||||
MethodInfo m;
|
||||
|
||||
m = Method;
|
||||
|
||||
return (m != null ? m.GetHashCode () : GetType ().GetHashCode ()) ^ RuntimeHelpers.GetHashCode (m_target);
|
||||
}
|
||||
|
||||
protected virtual MethodInfo GetMethodImpl ()
|
||||
|
||||
@@ -49,9 +49,15 @@ namespace MonoTests.System.Globalization
|
||||
|
||||
c = CultureInfo.InvariantCulture;
|
||||
Assert.AreEqual (2, c.NumberFormat.CurrencyDecimalDigits, "#3");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllCulturesCanParseNegativeNumber ()
|
||||
{
|
||||
foreach (var c in CultureInfo.GetCultures (CultureTypes.AllCultures))
|
||||
{
|
||||
int.Parse ("-1", c);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1844,5 +1844,68 @@ public class AssemblyBuilderTest
|
||||
} catch (NotSupportedException e) {
|
||||
}
|
||||
}
|
||||
|
||||
class AssemblyBuilderResolver {
|
||||
private Assembly mock;
|
||||
private ResolveEventHandler d;
|
||||
private string theName;
|
||||
|
||||
public AssemblyBuilderResolver (string theName) {
|
||||
mock = CreateMock (theName);
|
||||
d = new ResolveEventHandler (HandleResolveEvent);
|
||||
this.theName = theName;
|
||||
}
|
||||
|
||||
public void StartHandling () {
|
||||
AppDomain.CurrentDomain.AssemblyResolve += d;
|
||||
}
|
||||
|
||||
public void StopHandling () {
|
||||
AppDomain.CurrentDomain.AssemblyResolve -= d;
|
||||
}
|
||||
|
||||
public Assembly HandleResolveEvent (Object sender, ResolveEventArgs args) {
|
||||
if (args.Name.StartsWith (theName))
|
||||
return mock;
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
private static Assembly CreateMock (string name) {
|
||||
var an = new AssemblyName (name);
|
||||
var ab = AssemblyBuilder.DefineDynamicAssembly (an, AssemblyBuilderAccess.ReflectionOnly);
|
||||
var mb = ab.DefineDynamicModule (an.Name);
|
||||
|
||||
// Just make some content for the assembly
|
||||
var tb = mb.DefineType ("Foo", TypeAttributes.Public);
|
||||
tb.DefineDefaultConstructor (MethodAttributes.Public);
|
||||
|
||||
tb.CreateType ();
|
||||
|
||||
return ab;
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ResolveEventHandlerReflectionOnlyError ()
|
||||
{
|
||||
// Regression test for 57850.
|
||||
|
||||
// If a ResolveEventHandler returns a reflection-only
|
||||
// AssemblyBuilder, we should throw a FileNotFoundException.
|
||||
var s = "ResolveEventHandlerReflectionOnlyErrorAssembly";
|
||||
var h = new AssemblyBuilderResolver (s);
|
||||
Assert.Throws<FileNotFoundException>(() => {
|
||||
h.StartHandling ();
|
||||
var aName = new AssemblyName (s);
|
||||
try {
|
||||
AppDomain.CurrentDomain.Load (aName);
|
||||
} finally {
|
||||
h.StopHandling ();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -328,6 +328,61 @@ namespace MonoTests.System.Reflection.Emit
|
||||
Assert.Fail ("Expected CreateInstance of a broken type to throw TLE");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestEnumBuilderTokenUsable () {
|
||||
// Regression test for https://bugzilla.xamarin.com/show_bug.cgi?id=58361
|
||||
// Create an EnumBuilder and use it in an ILGenerator that consumes its token.
|
||||
var modBuilder = GenerateModule ();
|
||||
EnumBuilder enumBuilder = GenerateEnum (modBuilder);
|
||||
|
||||
var tb = modBuilder.DefineType ("Foo", TypeAttributes.Public);
|
||||
|
||||
var cb = tb.DefineConstructor (MethodAttributes.Public, CallingConventions.Standard,
|
||||
Type.EmptyTypes);
|
||||
|
||||
var ilg = cb.GetILGenerator ();
|
||||
|
||||
ilg.Emit (OpCodes.Ldtoken, enumBuilder);
|
||||
ilg.Emit (OpCodes.Pop);
|
||||
ilg.Emit (OpCodes.Ret);
|
||||
|
||||
var t = tb.CreateType ();
|
||||
enumBuilder.CreateType ();
|
||||
|
||||
var ci = t.GetConstructor (Type.EmptyTypes);
|
||||
var x = ci.Invoke (null);
|
||||
Assert.IsNotNull (x);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestEnumBuilderTokenUsableCrossAssembly () {
|
||||
// Regression test for https://bugzilla.xamarin.com/show_bug.cgi?id=58361
|
||||
// Create an EnumBuilder and use it in an ILGenerator that consumes its token in a different assembly.
|
||||
var modBuilder = GenerateModule ();
|
||||
var modBuilder2 = GenerateModule ();
|
||||
EnumBuilder enumBuilder = GenerateEnum (modBuilder2);
|
||||
|
||||
// N.B. "tb" is in modBuilder but enumBuilder is in modBuilder2
|
||||
var tb = modBuilder.DefineType ("Foo", TypeAttributes.Public);
|
||||
|
||||
var cb = tb.DefineConstructor (MethodAttributes.Public, CallingConventions.Standard,
|
||||
Type.EmptyTypes);
|
||||
|
||||
var ilg = cb.GetILGenerator ();
|
||||
|
||||
ilg.Emit (OpCodes.Ldtoken, enumBuilder);
|
||||
ilg.Emit (OpCodes.Pop);
|
||||
ilg.Emit (OpCodes.Ret);
|
||||
|
||||
var t = tb.CreateType ();
|
||||
enumBuilder.CreateType ();
|
||||
|
||||
var ci = t.GetConstructor (Type.EmptyTypes);
|
||||
var x = ci.Invoke (null);
|
||||
Assert.IsNotNull (x);
|
||||
}
|
||||
|
||||
|
||||
private static void VerifyType (Type type)
|
||||
{
|
||||
Assert.IsNotNull (type.Assembly, "#V1");
|
||||
|
||||
@@ -353,5 +353,60 @@ namespace MonoTests.System.Reflection.Emit
|
||||
|
||||
Assert.AreEqual (TypeAttributes.Public, gparam.Attributes, "#1");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ActionConstructorInfoTest ()
|
||||
{
|
||||
// Regression test for https://bugzilla.xamarin.com/show_bug.cgi?id=58454
|
||||
//
|
||||
// Need to check that GenericTypeParameterBuilderTest:InternalResolve() passes the declaring type to GetMethodFromHandle()
|
||||
//
|
||||
/* Want to generate:
|
||||
|
||||
public class Store<TState> {
|
||||
public Action<TSelection> Subscribe<TSelection> (TState state) {
|
||||
return new Action<TSelection> (Foo<TSelection>);
|
||||
}
|
||||
public static void Foo<X> (X x) { }
|
||||
}
|
||||
|
||||
... and then: new Store<string>().Subscribe<int>("x");
|
||||
*/
|
||||
|
||||
SetUp (AssemblyBuilderAccess.Run);
|
||||
|
||||
var tb = module.DefineType ("Store");
|
||||
var tparsStore = tb.DefineGenericParameters ("TState");
|
||||
|
||||
tb.DefineDefaultConstructor (MethodAttributes.Public);
|
||||
|
||||
var methFoo = tb.DefineMethod ("Foo", MethodAttributes.Public | MethodAttributes.Static);
|
||||
var tparsFoo = methFoo.DefineGenericParameters ("X");
|
||||
methFoo.SetReturnType (typeof(void));
|
||||
methFoo.SetParameters (tparsFoo[0]);
|
||||
methFoo.GetILGenerator().Emit (OpCodes.Ret);
|
||||
|
||||
var methSub = tb.DefineMethod ("Subscribe", MethodAttributes.Public | MethodAttributes.Static);
|
||||
var tparsSub = methSub.DefineGenericParameters ("TSelection");
|
||||
var actOfSel = typeof(Action<>).MakeGenericType (tparsSub[0]); // Action<TSelection>
|
||||
methSub.SetReturnType (actOfSel);
|
||||
methSub.SetParameters (tparsStore[0]); // TState
|
||||
var ilg = methSub.GetILGenerator ();
|
||||
ilg.Emit (OpCodes.Ldnull); // instance == null
|
||||
ilg.Emit (OpCodes.Ldftn, methFoo.MakeGenericMethod (tparsSub[0])); // ldftn void class Store`1<!TState>::Foo<!!0> (!!0)
|
||||
var aaa = TypeBuilder.GetConstructor (actOfSel, typeof(Action<>).GetConstructors()[0]);
|
||||
ilg.Emit (OpCodes.Newobj, aaa); // new Action<TSelection> (Foo<TSelection>);
|
||||
ilg.Emit (OpCodes.Ret);
|
||||
|
||||
var tgen = tb.CreateType (); // TState`1
|
||||
|
||||
var t = tgen.MakeGenericType(typeof(string));
|
||||
var x = t.GetConstructor(Type.EmptyTypes).Invoke (null); // x = new Store<string> ()
|
||||
var mgen = t.GetMethod("Subscribe");
|
||||
var m = mgen.MakeGenericMethod (typeof (int)); // Action<int> Store<string>.Subscribe<int> (string)
|
||||
var y = m.Invoke (x, new object[] {"hello"}); // x.Subscribte<int> ("hello")
|
||||
Assert.IsNotNull (y);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -480,5 +480,136 @@ namespace MonoTests.System.Reflection.Emit
|
||||
Assert.AreEqual (0x02, il [14]); //typedef
|
||||
Assert.AreEqual (0x01, il [19]); //typeref
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void MethodRefTokenSame () {
|
||||
// Get the same non-virtual method from a base and a derived type so
|
||||
// that the MemberInfo:DeclaredType differs but the tokens are the same.
|
||||
//
|
||||
// Regression test for bugzilla #59364
|
||||
|
||||
DefineBasicMethod ();
|
||||
|
||||
var m1 = typeof (object).GetMethod ("GetType");
|
||||
var m2 = typeof (string).GetMethod ("GetType");
|
||||
|
||||
var value_getter = typeof (RuntimeMethodHandle).GetProperty ("Value").GetMethod;
|
||||
|
||||
var il = il_gen;
|
||||
|
||||
var loc = il.DeclareLocal (typeof (RuntimeMethodHandle));
|
||||
|
||||
// return ((int)(RuntimeMethodHandle (m1).Value == RuntimeMethodHandle (m2).Value)).ToString ()
|
||||
il.Emit (OpCodes.Ldtoken, m1);
|
||||
il.Emit (OpCodes.Stloc, loc);
|
||||
il.Emit (OpCodes.Ldloca, loc);
|
||||
il.Emit (OpCodes.Call, value_getter);
|
||||
il.Emit (OpCodes.Ldtoken, m2);
|
||||
il.Emit (OpCodes.Stloc, loc);
|
||||
il.Emit (OpCodes.Ldloca, loc);
|
||||
il.Emit (OpCodes.Call, value_getter);
|
||||
il.Emit (OpCodes.Ceq);
|
||||
il.Emit (OpCodes.Box, typeof (Int32));
|
||||
il.Emit (OpCodes.Callvirt, typeof (object).GetMethod ("ToString"));
|
||||
il.Emit (OpCodes.Ret);
|
||||
|
||||
var baked = tb.CreateType ();
|
||||
|
||||
var x = Activator.CreateInstance (baked);
|
||||
var m = baked.GetMethod ("F");
|
||||
|
||||
var s = m.Invoke (x, null);
|
||||
|
||||
Assert.AreEqual ("1", s);
|
||||
|
||||
}
|
||||
|
||||
public class Base<T> {
|
||||
public int x;
|
||||
|
||||
public void M () { }
|
||||
}
|
||||
|
||||
public class Derived : Base<string> {
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FieldRefTokenSame () {
|
||||
DefineBasicMethod ();
|
||||
|
||||
// Get the same field from a base and a derived type so hat
|
||||
// the MemberInfo:DeclaredType differs but the tokens are the same.
|
||||
//
|
||||
// Regression test for bugzilla #59364
|
||||
|
||||
var f1 = typeof (Base<string>).GetField ("x");
|
||||
var f2 = typeof (Derived).GetField ("x");
|
||||
|
||||
var value_getter = typeof (RuntimeFieldHandle).GetProperty("Value").GetMethod;
|
||||
|
||||
var il = il_gen;
|
||||
|
||||
var loc = il.DeclareLocal (typeof (RuntimeFieldHandle));
|
||||
|
||||
il.Emit (OpCodes.Ldtoken, f1);
|
||||
il.Emit (OpCodes.Stloc, loc);
|
||||
il.Emit (OpCodes.Ldloca, loc);
|
||||
il.Emit (OpCodes.Call, value_getter);
|
||||
il.Emit (OpCodes.Ldtoken, f2);
|
||||
il.Emit (OpCodes.Stloc, loc);
|
||||
il.Emit (OpCodes.Ldloca, loc);
|
||||
il.Emit (OpCodes.Call, value_getter);
|
||||
il.Emit (OpCodes.Ceq);
|
||||
il.Emit (OpCodes.Box, typeof (Int32));
|
||||
il.Emit (OpCodes.Callvirt, typeof (object).GetMethod ("ToString"));
|
||||
il.Emit (OpCodes.Ret);
|
||||
|
||||
var baked = tb.CreateType ();
|
||||
|
||||
var x = Activator.CreateInstance (baked);
|
||||
var m = baked.GetMethod ("F");
|
||||
|
||||
var s = m.Invoke (x, null);
|
||||
|
||||
Assert.AreEqual ("1", s);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void MethodSpecTokenSame () {
|
||||
DefineBasicMethod ();
|
||||
// Get the same method from a base generic instance and
|
||||
// a type derived from it so that the
|
||||
// MemberInfo:DeclaredType differs but the tokens are
|
||||
// the same.
|
||||
//
|
||||
// Regression test for bugzilla #60233
|
||||
|
||||
var m1 = typeof (Base<string>).GetMethod ("M");
|
||||
var m2 = typeof (Derived).GetMethod ("M");
|
||||
|
||||
var il = il_gen;
|
||||
|
||||
var loc = il.DeclareLocal (typeof (Derived));
|
||||
|
||||
il.Emit (OpCodes.Newobj, typeof (Derived).GetConstructor(new Type[]{}));
|
||||
il.Emit (OpCodes.Stloc, loc);
|
||||
il.Emit (OpCodes.Ldloc, loc);
|
||||
il.Emit (OpCodes.Call, m1);
|
||||
il.Emit (OpCodes.Ldloc, loc);
|
||||
il.Emit (OpCodes.Call, m2);
|
||||
il.Emit (OpCodes.Ldstr, "1");
|
||||
il.Emit (OpCodes.Ret);
|
||||
|
||||
var baked = tb.CreateType ();
|
||||
|
||||
var x = Activator.CreateInstance (baked);
|
||||
var m = baked.GetMethod ("F");
|
||||
|
||||
var s = m.Invoke (x, null);
|
||||
|
||||
Assert.AreEqual ("1", s);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -100,21 +100,41 @@ namespace MonoTests.System.Reflection.Emit
|
||||
|
||||
private ModuleBuilder module;
|
||||
|
||||
string tempDir = Path.Combine (Path.GetTempPath (), typeof (TypeBuilderTest).FullName);
|
||||
|
||||
static string ASSEMBLY_NAME = "MonoTests.System.Reflection.Emit.TypeBuilderTest";
|
||||
|
||||
[SetUp]
|
||||
protected void SetUp ()
|
||||
{
|
||||
Random AutoRand = new Random ();
|
||||
string basePath = tempDir;
|
||||
while (Directory.Exists (tempDir))
|
||||
tempDir = Path.Combine (basePath, AutoRand.Next ().ToString ());
|
||||
Directory.CreateDirectory (tempDir);
|
||||
|
||||
AssemblyName assemblyName = new AssemblyName ();
|
||||
assemblyName.Name = ASSEMBLY_NAME;
|
||||
|
||||
assembly =
|
||||
Thread.GetDomain ().DefineDynamicAssembly (
|
||||
assemblyName, AssemblyBuilderAccess.RunAndSave, Path.GetTempPath ());
|
||||
assemblyName, AssemblyBuilderAccess.RunAndSave, tempDir);
|
||||
|
||||
module = assembly.DefineDynamicModule (ASSEMBLY_NAME, ASSEMBLY_NAME + ".dll");
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
protected void TearDown ()
|
||||
{
|
||||
try {
|
||||
Directory.Delete (tempDir, true);
|
||||
} catch (DirectoryNotFoundException) {
|
||||
} catch (IOException) {
|
||||
// Can happen on Windows if assemblies from this dir are still used
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static int typeIndexer = 0;
|
||||
|
||||
// Return a unique type name
|
||||
@@ -738,30 +758,6 @@ namespace MonoTests.System.Reflection.Emit
|
||||
Assert.IsTrue (tb2.IsSealed, "#2");
|
||||
}
|
||||
|
||||
static string CreateTempAssembly ()
|
||||
{
|
||||
FileStream f = null;
|
||||
string path;
|
||||
Random rnd;
|
||||
int num = 0;
|
||||
|
||||
rnd = new Random ();
|
||||
do {
|
||||
num = rnd.Next ();
|
||||
num++;
|
||||
path = Path.Combine (Path.GetTempPath (), "tmp" + num.ToString ("x") + ".dll");
|
||||
|
||||
try {
|
||||
f = new FileStream (path, FileMode.CreateNew);
|
||||
} catch { }
|
||||
} while (f == null);
|
||||
|
||||
f.Close ();
|
||||
|
||||
|
||||
return "tmp" + num.ToString ("x") + ".dll";
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IsSerializable ()
|
||||
{
|
||||
@@ -774,10 +770,10 @@ namespace MonoTests.System.Reflection.Emit
|
||||
tb.SetCustomAttribute (new CustomAttributeBuilder (ctors [0], new object [0]));
|
||||
Type createdType = tb.CreateType ();
|
||||
|
||||
string an = CreateTempAssembly ();
|
||||
string an = "IsSerializableTestAssembly.dll";
|
||||
assembly.Save (an);
|
||||
Assert.IsTrue (createdType.IsSerializable, "#3");
|
||||
File.Delete (Path.Combine (Path.GetTempPath (), an));
|
||||
File.Delete (Path.Combine (tempDir, an));
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -2054,7 +2050,7 @@ namespace MonoTests.System.Reflection.Emit
|
||||
|
||||
assembly =
|
||||
Thread.GetDomain ().DefineDynamicAssembly (
|
||||
assemblyName, AssemblyBuilderAccess.RunAndSave | (AssemblyBuilderAccess)0x800, Path.GetTempPath ());
|
||||
assemblyName, AssemblyBuilderAccess.RunAndSave | (AssemblyBuilderAccess)0x800, tempDir);
|
||||
|
||||
module = assembly.DefineDynamicModule ("module1");
|
||||
|
||||
@@ -9706,7 +9702,7 @@ namespace MonoTests.System.Reflection.Emit
|
||||
|
||||
[Test] //bug #399047
|
||||
public void FieldOnTypeBuilderInstDontInflateWhenEncoded () {
|
||||
assembly = Thread.GetDomain ().DefineDynamicAssembly (new AssemblyName (ASSEMBLY_NAME), AssemblyBuilderAccess.RunAndSave, Path.GetTempPath ());
|
||||
assembly = Thread.GetDomain ().DefineDynamicAssembly (new AssemblyName (ASSEMBLY_NAME), AssemblyBuilderAccess.RunAndSave, tempDir);
|
||||
|
||||
module = assembly.DefineDynamicModule ("Instance.exe");
|
||||
|
||||
@@ -9743,10 +9739,11 @@ namespace MonoTests.System.Reflection.Emit
|
||||
|
||||
assembly.SetEntryPoint (main);
|
||||
G.CreateType ();
|
||||
P.CreateType ();
|
||||
var PCreated = P.CreateType ();
|
||||
|
||||
assembly.Save ("Instance.exe");
|
||||
Thread.GetDomain ().ExecuteAssembly(Path.GetTempPath () + Path.DirectorySeparatorChar + "Instance.exe");
|
||||
|
||||
PCreated.InvokeMember ("Main", BindingFlags.Public | BindingFlags.Static | BindingFlags.InvokeMethod, null, null, null);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -9756,7 +9753,7 @@ namespace MonoTests.System.Reflection.Emit
|
||||
FieldBuilder fb = tb.DefineInitializedData ("Foo", new byte [] {1,2,3,4}, FieldAttributes.Static|FieldAttributes.Public);
|
||||
tb.CreateType ();
|
||||
|
||||
assembly = Thread.GetDomain ().DefineDynamicAssembly (new AssemblyName (ASSEMBLY_NAME+"2"), AssemblyBuilderAccess.RunAndSave, Path.GetTempPath ());
|
||||
assembly = Thread.GetDomain ().DefineDynamicAssembly (new AssemblyName (ASSEMBLY_NAME+"2"), AssemblyBuilderAccess.RunAndSave, tempDir);
|
||||
module = assembly.DefineDynamicModule ("Instance.exe");
|
||||
|
||||
TypeBuilder tb2 = module.DefineType ("Type2", TypeAttributes.Public);
|
||||
@@ -9783,7 +9780,7 @@ namespace MonoTests.System.Reflection.Emit
|
||||
FieldBuilder fb = tb.DefineInitializedData ("Foo", new byte [] {1,2,3,4}, FieldAttributes.Static|FieldAttributes.Public);
|
||||
tb.CreateType ();
|
||||
|
||||
assembly = Thread.GetDomain ().DefineDynamicAssembly (new AssemblyName (ASSEMBLY_NAME+"2"), AssemblyBuilderAccess.RunAndSave, Path.GetTempPath ());
|
||||
assembly = Thread.GetDomain ().DefineDynamicAssembly (new AssemblyName (ASSEMBLY_NAME+"2"), AssemblyBuilderAccess.RunAndSave, tempDir);
|
||||
module = assembly.DefineDynamicModule ("Instance.exe");
|
||||
|
||||
TypeBuilder tb2 = module.DefineType ("Type2", TypeAttributes.Public);
|
||||
@@ -11306,5 +11303,110 @@ namespace MonoTests.System.Reflection.Emit
|
||||
|
||||
Assert.AreSame (buildX, defX);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FieldsWithSameName () {
|
||||
// Regression test for https://bugzilla.xamarin.com/show_bug.cgi?id=57222
|
||||
var typeBuilder = module.DefineType ("type1", TypeAttributes.Public | TypeAttributes.Class);
|
||||
|
||||
var mainMethod = typeBuilder.DefineMethod ("Main", MethodAttributes.Public | MethodAttributes.Static, typeof (int), new Type[0]);
|
||||
var mainMethodIl = mainMethod.GetILGenerator ();
|
||||
|
||||
var f1 = typeBuilder.DefineField ("x", typeof (byte), FieldAttributes.Private | FieldAttributes.Static);
|
||||
var f2 = typeBuilder.DefineField ("x", typeof (sbyte), FieldAttributes.Private | FieldAttributes.Static);
|
||||
|
||||
mainMethodIl.Emit (OpCodes.Ldsflda, f1);
|
||||
mainMethodIl.Emit (OpCodes.Ldsflda, f2);
|
||||
mainMethodIl.Emit (OpCodes.Pop);
|
||||
mainMethodIl.Emit (OpCodes.Pop);
|
||||
mainMethodIl.Emit (OpCodes.Ldc_I4_0);
|
||||
mainMethodIl.Emit (OpCodes.Ret);
|
||||
|
||||
typeBuilder.CreateType ();
|
||||
assembly.SetEntryPoint (mainMethod);
|
||||
|
||||
assembly.Save (ASSEMBLY_NAME + ".dll");
|
||||
}
|
||||
[Test]
|
||||
public void FieldsWithSameNameAndType () {
|
||||
// https://bugzilla.xamarin.com/show_bug.cgi?id=57222
|
||||
var typeBuilder = module.DefineType ("type1", TypeAttributes.Public | TypeAttributes.Class);
|
||||
|
||||
var mainMethod = typeBuilder.DefineMethod ("Main", MethodAttributes.Public | MethodAttributes.Static, typeof (int), new Type[0]);
|
||||
var mainMethodIl = mainMethod.GetILGenerator ();
|
||||
|
||||
var f1 = typeBuilder.DefineField ("x", typeof (sbyte), FieldAttributes.Private | FieldAttributes.Static);
|
||||
var f2 = typeBuilder.DefineField ("x", typeof (sbyte), FieldAttributes.Private | FieldAttributes.Static);
|
||||
|
||||
mainMethodIl.Emit (OpCodes.Ldsflda, f1);
|
||||
mainMethodIl.Emit (OpCodes.Ldsflda, f2);
|
||||
mainMethodIl.Emit (OpCodes.Pop);
|
||||
mainMethodIl.Emit (OpCodes.Pop);
|
||||
mainMethodIl.Emit (OpCodes.Ldc_I4_0);
|
||||
mainMethodIl.Emit (OpCodes.Ret);
|
||||
|
||||
typeBuilder.CreateType ();
|
||||
assembly.SetEntryPoint (mainMethod);
|
||||
|
||||
assembly.Save (ASSEMBLY_NAME + ".dll");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void MethodsWithSameNameAndSig () {
|
||||
// https://bugzilla.xamarin.com/show_bug.cgi?id=57222
|
||||
var typeBuilder = module.DefineType ("type1", TypeAttributes.Public | TypeAttributes.Class);
|
||||
|
||||
var mainMethod = typeBuilder.DefineMethod ("Main", MethodAttributes.Public | MethodAttributes.Static, typeof (int), new Type[0]);
|
||||
var mainMethodIl = mainMethod.GetILGenerator ();
|
||||
|
||||
var m1 = typeBuilder.DefineMethod ("X", MethodAttributes.Private | MethodAttributes.Static, typeof (void), new Type [0]);
|
||||
var m2 = typeBuilder.DefineMethod ("X", MethodAttributes.Private | MethodAttributes.Static, typeof (void), new Type [0]);
|
||||
m1.GetILGenerator ().Emit (OpCodes.Ret);
|
||||
m2.GetILGenerator ().Emit (OpCodes.Ret);
|
||||
|
||||
mainMethodIl.Emit (OpCodes.Call, m1);
|
||||
mainMethodIl.Emit (OpCodes.Call, m2);
|
||||
mainMethodIl.Emit (OpCodes.Ldc_I4_0);
|
||||
mainMethodIl.Emit (OpCodes.Ret);
|
||||
|
||||
typeBuilder.CreateType ();
|
||||
assembly.SetEntryPoint (mainMethod);
|
||||
|
||||
assembly.Save (ASSEMBLY_NAME + ".dll");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TwoAssembliesMidFlightTest () {
|
||||
// Check that one AssemblyBuilder can refer to a TypeBuilder from another AssemblyBuilder.
|
||||
// Regression test for https://bugzilla.xamarin.com/show_bug.cgi?id=58421
|
||||
var name2 = "MonoTests.System.Reflection.Emit.TypeBuilderTest2";
|
||||
var assemblyName2 = new AssemblyName (name2);
|
||||
var assembly2 =
|
||||
Thread.GetDomain ().DefineDynamicAssembly (
|
||||
assemblyName2, AssemblyBuilderAccess.RunAndSave, tempDir);
|
||||
|
||||
var module2 = assembly2.DefineDynamicModule (name2, name2 + ".dll");
|
||||
|
||||
var tb = module.DefineType ("Foo", TypeAttributes.Public);
|
||||
var tb2 = module2.DefineType ("Foo2", TypeAttributes.Public);
|
||||
|
||||
var cb = tb.DefineConstructor (MethodAttributes.Public, CallingConventions.Standard,
|
||||
Type.EmptyTypes);
|
||||
|
||||
var ilg = cb.GetILGenerator ();
|
||||
|
||||
ilg.Emit (OpCodes.Ldtoken, tb2); // N.B. type from the other AssemblyBuilder
|
||||
ilg.Emit (OpCodes.Pop);
|
||||
ilg.Emit (OpCodes.Ret);
|
||||
|
||||
var t = tb.CreateType ();
|
||||
tb2.CreateType ();
|
||||
|
||||
var ci = t.GetConstructor (Type.EmptyTypes);
|
||||
var x = ci.Invoke (null);
|
||||
assembly.Save (ASSEMBLY_NAME + ".dll");
|
||||
assembly2.Save (name2 + ".dll");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
//
|
||||
// MonoTests.System.Runtime.Remoting.Proxies.RealProxyTest.cs
|
||||
//
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.Runtime.Remoting.Messaging;
|
||||
using System.Runtime.Remoting.Proxies;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace MonoTests.System.Runtime.Remoting.Proxies {
|
||||
[TestFixture]
|
||||
public class RealProxyTest {
|
||||
|
||||
public class ExampleInterfaceProxy : RealProxy {
|
||||
public bool Called;
|
||||
|
||||
public ExampleInterfaceProxy () : base (typeof(IComparable))
|
||||
{
|
||||
Called = false;
|
||||
}
|
||||
|
||||
public override IMessage Invoke (IMessage msg)
|
||||
{
|
||||
Called = true;
|
||||
return new ReturnMessage (typeof(IComparable), null, 0, null, null);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InterfaceProxyGetTypeOkay ()
|
||||
{
|
||||
// Regression test for #17325
|
||||
// Check that GetType () for a proxy of an interface
|
||||
// returns the interface.
|
||||
var prox = new ExampleInterfaceProxy ();
|
||||
var tprox = prox.GetTransparentProxy ();
|
||||
|
||||
Assert.IsNotNull (tprox, "#1");
|
||||
|
||||
var tproxType = tprox.GetType ();
|
||||
|
||||
Assert.IsFalse (prox.Called, "#2"); // this is true on .NET Framework, but false on Mono.
|
||||
|
||||
Assert.IsNotNull (tproxType, "#3");
|
||||
Assert.IsTrue (tproxType.IsAssignableFrom (typeof(IComparable)), "#4");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InterfaceProxyGetTypeViaReflectionOkay ()
|
||||
{
|
||||
// Regression test for #17325
|
||||
// Check that GetType () for a proxy of an interface
|
||||
// returns the interface.
|
||||
//
|
||||
// This versions calls GetType using reflection, which
|
||||
// avoids the fast path in the JIT.
|
||||
var prox = new ExampleInterfaceProxy ();
|
||||
var tprox = prox.GetTransparentProxy ();
|
||||
|
||||
Assert.IsNotNull (tprox, "#1");
|
||||
|
||||
|
||||
var m = typeof(object).GetMethod ("GetType");
|
||||
|
||||
var tproxType = m.Invoke (tprox, null);
|
||||
|
||||
Assert.IsTrue (prox.Called, "#2");
|
||||
|
||||
Assert.IsNotNull (tproxType, "#3");
|
||||
Assert.IsTrue (tproxType is Type, "#4");
|
||||
Assert.IsTrue ((tproxType as Type).IsAssignableFrom (typeof(IComparable)), "#5");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -341,7 +341,7 @@ namespace MonoTests.System.Runtime.Remoting
|
||||
Thread tr = new Thread (new ThreadStart (CallbackThread));
|
||||
tr.Start();
|
||||
|
||||
bool terminated = tr.Join(2000);
|
||||
bool terminated = tr.Join(10000);
|
||||
Assert.IsTrue(terminated, "Thread didn't get lock of context bound object.");
|
||||
|
||||
Assert.IsTrue (!otResult, "Concurrency detected in CallbackThread");
|
||||
|
||||
@@ -68,8 +68,6 @@ namespace MonoTests.System.Security.Cryptography.X509Certificates {
|
||||
public void TearDown ()
|
||||
{
|
||||
Thread.CurrentThread.CurrentCulture = oldcult;
|
||||
File.Delete("temp.cer");
|
||||
File.Delete("temp.b64");
|
||||
}
|
||||
|
||||
#if !MOBILE && !MONOMAC
|
||||
|
||||
-1
@@ -37,7 +37,6 @@ public void SetUp () {
|
||||
[TearDown]
|
||||
public void TearDown () {
|
||||
Thread.CurrentThread.CurrentCulture = oldcult;
|
||||
File.Delete("temp.b64");
|
||||
try {
|
||||
File.Delete (temp_certificate_filename);
|
||||
} catch {
|
||||
|
||||
@@ -1258,7 +1258,7 @@ namespace MonoTests.System.Threading.Tasks
|
||||
{
|
||||
var t = Task.Delay (300);
|
||||
Assert.IsTrue (TaskStatus.WaitingForActivation == t.Status || TaskStatus.Running == t.Status, "#1");
|
||||
Assert.IsTrue (t.Wait (400), "#2");
|
||||
Assert.IsTrue (t.Wait (1200), "#2");
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
||||
@@ -2261,11 +2261,14 @@ namespace MonoTests.System
|
||||
|
||||
[Test]
|
||||
public void GetGenericMethodDefinitionOverInflatedMethodOnGTD () {
|
||||
var s = new List<int> () { 1, 2, 3 }.ConvertAll ( i => i.ToString () );
|
||||
Assert.AreEqual (3, s.Count);
|
||||
var l = typeof (List<>);
|
||||
var m = l.GetMethod ("ConvertAll");
|
||||
var infl = m.MakeGenericMethod (typeof (int));
|
||||
var res = m.GetGenericMethodDefinition ();
|
||||
Assert.AreEqual (m, res, "#1");
|
||||
Assert.AreEqual (1, infl.GetGenericArguments().Length, "#2");
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
||||
@@ -203,6 +203,7 @@ System.Runtime.Remoting.Channels/ChannelServicesTest.cs
|
||||
System.Runtime.Remoting.Contexts/SynchronizationAttributeTest.cs
|
||||
System.Runtime.Remoting.Messaging/CallContextTest.cs
|
||||
System.Runtime.Remoting.Metadata.W3cXsd2001/SoapHexBinaryTest.cs
|
||||
System.Runtime.Remoting.Proxies/RealProxyTest.cs
|
||||
System.Runtime.Serialization/FormatterServicesTests.cs
|
||||
System.Runtime.Serialization/ObjectIDGeneratorTests.cs
|
||||
System.Runtime.Serialization/SerializationBinderTest.cs
|
||||
|
||||
@@ -39,6 +39,7 @@ System.Runtime.Remoting.Channels/ChannelServicesTest.cs
|
||||
System.Runtime.Remoting.Contexts/SynchronizationAttributeTest.cs
|
||||
System.Runtime.Remoting.Messaging/CallContextTest.cs
|
||||
System.Runtime.Remoting.Metadata.W3cXsd2001/SoapHexBinaryTest.cs
|
||||
System.Runtime.Remoting.Proxies/RealProxyTest.cs
|
||||
System.Security.AccessControl/AuthorizationRuleTest.cs
|
||||
System.Security.AccessControl/CommonAceTest.cs
|
||||
System.Security.AccessControl/CommonAclTest.cs
|
||||
|
||||
+3
-2
@@ -47,10 +47,11 @@ namespace System.Runtime.ExceptionServices {
|
||||
// Copy over the details we need to save.
|
||||
m_Exception = exception;
|
||||
#if MONO
|
||||
var count = exception.captured_traces == null ? 0 : exception.captured_traces.Length;
|
||||
var traces = exception.captured_traces;
|
||||
var count = traces == null ? 0 : traces.Length;
|
||||
var stack_traces = new System.Diagnostics.StackTrace [count + 1];
|
||||
if (count != 0)
|
||||
Array.Copy (exception.captured_traces, 0, stack_traces, 0, count);
|
||||
Array.Copy (traces, 0, stack_traces, 0, count);
|
||||
|
||||
stack_traces [count] = new System.Diagnostics.StackTrace (exception, 0, true);
|
||||
m_stackTrace = stack_traces;
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
// CS0128: A local variable named `x' is already defined in this scope
|
||||
// Line: 9
|
||||
|
||||
class X
|
||||
{
|
||||
public static void Main ()
|
||||
{
|
||||
Foo (out int x);
|
||||
Foo (out int x);
|
||||
}
|
||||
|
||||
static void Foo (out int arg)
|
||||
{
|
||||
arg = 2;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// CS0128: A local variable named `s' is already defined in this scope
|
||||
// Line: 12
|
||||
|
||||
class C
|
||||
{
|
||||
public static void Main ()
|
||||
{
|
||||
object o = null;
|
||||
|
||||
var x1 = o is string s;
|
||||
var x2 = o is string s;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// CS0136: A local variable named `s' cannot be declared in this scope because it would give a different meaning to `s', which is already used in a `parent or current' scope to denote something else
|
||||
// Line: 10
|
||||
|
||||
internal class Program
|
||||
{
|
||||
public static void Main ()
|
||||
{
|
||||
object o = null;
|
||||
if (o is string s) {
|
||||
int s = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
// CS0165: Use of unassigned local variable `s'
|
||||
// Line: 12
|
||||
|
||||
class X
|
||||
{
|
||||
static string Foo (object arg)
|
||||
{
|
||||
if (arg is string s) {
|
||||
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
// CS0165: Use of unassigned local variable `v'
|
||||
// Line: 52
|
||||
|
||||
struct Vector3
|
||||
{
|
||||
int field1, field2, field3;
|
||||
}
|
||||
|
||||
public class C
|
||||
{
|
||||
void Update ()
|
||||
{
|
||||
int v1 = 0;
|
||||
int v2 = 0;
|
||||
int v3 = 0;
|
||||
int v4 = 0;
|
||||
int v5 = 0;
|
||||
int v6 = 0;
|
||||
int v7 = 0;
|
||||
int v8 = 0;
|
||||
int v9 = 0;
|
||||
int v10 = 0;
|
||||
int v11 = 0;
|
||||
int v12 = 0;
|
||||
int v13 = 0;
|
||||
int v14 = 0;
|
||||
int v15 = 0;
|
||||
int v16 = 0;
|
||||
int v17 = 0;
|
||||
int v18 = 0;
|
||||
int v19 = 0;
|
||||
int v20 = 0;
|
||||
int v21 = 0;
|
||||
int v22 = 0;
|
||||
int v23 = 0;
|
||||
int v24 = 0;
|
||||
int v25 = 0;
|
||||
int v26 = 0;
|
||||
int v27 = 0;
|
||||
int v29;
|
||||
|
||||
Vector3 v;
|
||||
if (v1 == 0)
|
||||
{
|
||||
v = new Vector3 ();
|
||||
}
|
||||
else if (v2 >= 0.5)
|
||||
{
|
||||
v = new Vector3 ();
|
||||
}
|
||||
|
||||
System.GC.KeepAlive (v);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
// CS0165: Use of unassigned local variable `v'
|
||||
// Line: 52
|
||||
|
||||
struct Vector3
|
||||
{
|
||||
int field1, field2, field3;
|
||||
}
|
||||
|
||||
public class C
|
||||
{
|
||||
void Update ()
|
||||
{
|
||||
int v1 = 0;
|
||||
int v2 = 0;
|
||||
int v3 = 0;
|
||||
int v4 = 0;
|
||||
int v5 = 0;
|
||||
int v6 = 0;
|
||||
int v7 = 0;
|
||||
int v8 = 0;
|
||||
int v9 = 0;
|
||||
int v10 = 0;
|
||||
int v11 = 0;
|
||||
int v12 = 0;
|
||||
int v13 = 0;
|
||||
int v14 = 0;
|
||||
int v15 = 0;
|
||||
int v16 = 0;
|
||||
int v17 = 0;
|
||||
int v18 = 0;
|
||||
int v19 = 0;
|
||||
int v20 = 0;
|
||||
int v21 = 0;
|
||||
int v22 = 0;
|
||||
int v23 = 0;
|
||||
int v24 = 0;
|
||||
int v25 = 0;
|
||||
int v26 = 0;
|
||||
int v27 = 0;
|
||||
int v29;
|
||||
|
||||
Vector3 v;
|
||||
while (v8 != 0) {
|
||||
v = new Vector3 ();
|
||||
}
|
||||
|
||||
System.GC.KeepAlive (v);
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
// CS0815: An implicitly typed local variable declaration cannot be initialized with `void'
|
||||
// Line: 8
|
||||
// Compiler options: -langversion:experimental
|
||||
|
||||
class X
|
||||
{
|
||||
public static void Main ()
|
||||
{
|
||||
Foo (out var x = Main ());
|
||||
}
|
||||
|
||||
static void Foo (out int i)
|
||||
{
|
||||
i = 0;
|
||||
}
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
// CS1061: No overload for method `Call' takes `0' arguments
|
||||
// Line: 11
|
||||
|
||||
using System;
|
||||
|
||||
class Program
|
||||
{
|
||||
static void Main ()
|
||||
{
|
||||
Action<dynamic, object> action = delegate { };
|
||||
Foo (action).NoDynamicBinding ();
|
||||
}
|
||||
|
||||
static T Foo<T>(Action<T, T> x)
|
||||
{
|
||||
throw new NotImplementedException ();
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
// CS1501: Argument `#1' cannot convert `ref string' expression to type `ref int'
|
||||
// Line: 8
|
||||
// Compiler options: -langversion:experimental
|
||||
|
||||
class C
|
||||
{
|
||||
public static void Main ()
|
||||
{
|
||||
Foo (ref var x = "");
|
||||
}
|
||||
|
||||
static void Foo (ref int i)
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
// CS1621: The yield statement cannot be used inside anonymous method blocks
|
||||
// Line: 12
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
|
||||
public class Test
|
||||
{
|
||||
public IEnumerator Foo ()
|
||||
{
|
||||
Call (() => {
|
||||
yield break;
|
||||
});
|
||||
|
||||
yield break;
|
||||
}
|
||||
|
||||
void Call (Action a)
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
// CS1644: Feature `declaration expression' cannot be used because it is not part of the C# 5.0 language specification
|
||||
// Line: 12
|
||||
// CS1644: Feature `out variable declaration' cannot be used because it is not part of the C# 5.0 language specification
|
||||
// Line: 9
|
||||
// Compiler options: -langversion:5
|
||||
|
||||
class C
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
// CS1644: Feature `pattern matching' cannot be used because it is not part of the C# 6.0 language specification
|
||||
// Line: 9
|
||||
// Compiler options: -langversion:6
|
||||
|
||||
class Class
|
||||
{
|
||||
static void Foo (object arg)
|
||||
{
|
||||
if (arg is Type v) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
// CS4001: Cannot await `void' expression
|
||||
// Line: 10
|
||||
|
||||
using System;
|
||||
|
||||
class A
|
||||
{
|
||||
static async void Test ()
|
||||
{
|
||||
await Console.WriteLine;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// CS8116: The nullable type `byte?' pattern matching is not allowed. Consider using underlying type `byte'
|
||||
// Line: 11
|
||||
|
||||
using System;
|
||||
|
||||
class C
|
||||
{
|
||||
public static void Main ()
|
||||
{
|
||||
object o2 = null;
|
||||
bool r2 = o2 is Nullable<byte> t3;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// CS8117: Cannot use null as pattern matching operand
|
||||
// Line: 8
|
||||
|
||||
class C
|
||||
{
|
||||
static object Test ()
|
||||
{
|
||||
return null is object res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
// CS8122: An expression tree cannot contain a pattern matching operator
|
||||
// Line: 12
|
||||
|
||||
using System;
|
||||
using System.Linq.Expressions;
|
||||
|
||||
class X
|
||||
{
|
||||
public static void Main ()
|
||||
{
|
||||
object o = 1;
|
||||
Expression<Func<bool>> e = () => o is int y;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
// CS8196: Reference to an implicitly typed out variable `x1' is not permitted in the same argument list
|
||||
// Line: 8
|
||||
|
||||
public class C
|
||||
{
|
||||
public static void Main ()
|
||||
{
|
||||
Test (out var x1, out x1);
|
||||
}
|
||||
|
||||
static void Test (out int x, out int x2)
|
||||
{
|
||||
x = 1;
|
||||
x2 = 2;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
// CS8196: Reference to an implicitly typed out variable `x1' is not permitted in the same argument list
|
||||
// Line: 8
|
||||
|
||||
public class C
|
||||
{
|
||||
public static void Main ()
|
||||
{
|
||||
Test (out var x1, out x1);
|
||||
}
|
||||
|
||||
static void Test (out int x, out int x2)
|
||||
{
|
||||
x = 1;
|
||||
x2 = 2;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
// CS8047: Declaration expression cannot be used in this context
|
||||
// Line: 8
|
||||
// Compiler options: -langversion:experimental
|
||||
// CS8197: Cannot infer the type of implicitly-typed out variable `y'
|
||||
// Line: 9
|
||||
|
||||
public class C
|
||||
{
|
||||
@@ -1,6 +1,5 @@
|
||||
// CS8046: An expression tree cannot contain a declaration expression
|
||||
// CS8198: An expression tree cannot contain out variable declaration
|
||||
// Line: 11
|
||||
// Compiler options: -langversion:experimental
|
||||
|
||||
using System;
|
||||
using System.Linq.Expressions;
|
||||
@@ -0,0 +1,13 @@
|
||||
// CS8200: Out variable and pattern variable declarations are not allowed within constructor initializers, field initializers, or property initializers
|
||||
// Line: 6
|
||||
|
||||
public class C
|
||||
{
|
||||
bool res = Foo (out int arg);
|
||||
|
||||
static bool Foo (out int arg)
|
||||
{
|
||||
arg = 2;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// CS8200: Out variable and pattern variable declarations are not allowed within constructor initializers, field initializers, or property initializers
|
||||
// Line: 11
|
||||
|
||||
public class C
|
||||
{
|
||||
bool Prop { get; } = Foo (out int arg);
|
||||
|
||||
static bool Foo (out int arg)
|
||||
{
|
||||
arg = 2;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
// CS8200: Out variable and pattern variable declarations are not allowed within constructor initializers, field initializers, or property initializers
|
||||
// Line: 8
|
||||
|
||||
using System;
|
||||
|
||||
public class C
|
||||
{
|
||||
event Action H = Foo (out var res);
|
||||
|
||||
static Action Foo (out int arg)
|
||||
{
|
||||
arg = 2;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
// CS8200: Out variable and pattern variable declarations are not allowed within constructor initializers, field initializers, or property initializers
|
||||
// Line: 6
|
||||
|
||||
public class C
|
||||
{
|
||||
bool res = Foo () is string s;
|
||||
|
||||
static object Foo ()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
// CS8200: Out variable and pattern variable declarations are not allowed within constructor initializers, field initializers, or property initializers
|
||||
// Line: 6
|
||||
|
||||
class X
|
||||
{
|
||||
public static bool Test { get; } = Foo () is bool x;
|
||||
|
||||
static object Foo ()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
// CS8200: Out variable and pattern variable declarations are not allowed within constructor initializers, field initializers, or property initializers
|
||||
// Line: 11
|
||||
|
||||
public class C
|
||||
{
|
||||
public C (bool value)
|
||||
{
|
||||
}
|
||||
|
||||
public C ()
|
||||
: this (Foo (out int arg))
|
||||
{
|
||||
}
|
||||
|
||||
static bool Foo (out int arg)
|
||||
{
|
||||
arg = 2;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
// CS8201: Out variable and pattern variable declarations are not allowed within a query clause
|
||||
// Line: 11
|
||||
|
||||
using System.Linq;
|
||||
|
||||
class Program
|
||||
{
|
||||
public static void Main ()
|
||||
{
|
||||
var a = "abcdef";
|
||||
var res = from x in a from y in M (a, out var z) select x;
|
||||
}
|
||||
|
||||
public static T M<T>(T x, out T z) => z = x;
|
||||
}
|
||||
Loaded 100 of 272 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user