fixed problems in certificate validation code (updates in Mono?) Also disabled linking in release to avoid problems.

This commit is contained in:
Philipp Crocoll
2014-02-02 23:36:19 +01:00
parent a765bd125e
commit bc1d5fb5f2
14 changed files with 6152 additions and 1853 deletions

View File

@@ -43,7 +43,10 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AndroidUseSharedRuntime>False</AndroidUseSharedRuntime>
<AndroidLinkMode>SdkOnly</AndroidLinkMode>
<AndroidLinkMode>None</AndroidLinkMode>
<AndroidLinkSkip />
<EmbedAssembliesIntoApk>True</EmbedAssembliesIntoApk>
<BundleAssemblies>False</BundleAssemblies>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'ReleaseNoNet|AnyCPU'">
<OutputPath>bin\ReleaseNoNet\</OutputPath>

View File

@@ -18,11 +18,12 @@ namespace Kp2aUnitTests
{
TestRunner runner = new TestRunner();
// Run all tests from this assembly
runner.AddTests(Assembly.GetExecutingAssembly());
//runner.AddTests(Assembly.GetExecutingAssembly());
//runner.AddTests(new List<Type> { typeof(TestSynchronizeCachedDatabase)});
//runner.AddTests(typeof(TestLoadDb).GetMethod("LoadErrorWithCertificateTrustFailure"));
//runner.AddTests(typeof(TestLoadDb).GetMethod("LoadWithAcceptedCertificateTrustFailure"));
//runner.AddTests(new List<Type> { typeof(TestLoadDb) });
runner.AddTests(new List<Type> { typeof(TestLoadDb) });
//runner.AddTests(new List<Type> { typeof(TestCachingFileStorage) });
//runner.AddTests(typeof(TestLoadDb).GetMethod("TestLoadKdb1"));
//runner.AddTests(typeof(TestLoadDb).GetMethod("TestLoadWithKeyfileOnly"));

View File

@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.IO;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
using Android.App;
using Android.Content;
using Android.OS;
@@ -27,6 +28,7 @@ namespace Kp2aUnitTests
private YesNoCancelResult _yesNoCancelResult = YesNoCancelResult.Yes;
private Dictionary<PreferenceKey, bool> _preferences = new Dictionary<PreferenceKey, bool>();
private int id = new Random().Next(1000);
public void SetShutdown()
{
@@ -140,6 +142,7 @@ namespace Kp2aUnitTests
public bool TriggerReloadCalled;
private TestFileStorage _testFileStorage;
private bool _serverCertificateErrorResponse;
public TestKp2aApp()
{
@@ -151,13 +154,49 @@ namespace Kp2aUnitTests
TriggerReloadCalled = true;
}
public RemoteCertificateValidationCallback CertificateValidationCallback
{
get
{
Kp2aLog.Log("TESTAPP: " + id + "/ " + ServerCertificateErrorResponse);
if (!ServerCertificateErrorResponse)
{
return (sender, certificate, chain, errors) =>
{
if (errors == SslPolicyErrors.None)
return true;
return false;
};
}
// return null; //default behavior
return (sender, certificate, chain, errors) =>
{
return true;
};
}
}
public bool OnServerCertificateError(int sslPolicyErrors)
{
ServerCertificateErrorCalled = true;
return ServerCertificateErrorResponse;
}
public bool ServerCertificateErrorResponse { get; set; }
public bool ServerCertificateErrorResponse
{
get { return _serverCertificateErrorResponse; }
set {
_serverCertificateErrorResponse = value;
FileStorage = new BuiltInFileStorage(this); // recreate because of possibly changed validation behavior
}
}
protected bool ServerCertificateErrorCalled { get; set; }

View File

@@ -261,7 +261,8 @@ namespace Kp2aUnitTests
[TestMethod]
public void FileNotFoundExceptionWithWebDav()
{
var fileStorage = new BuiltInFileStorage(new TestKp2aApp());
var app = new TestKp2aApp();
var fileStorage = app.FileStorage;
//should work:
using (var stream = fileStorage.OpenFileForRead(RemoteIoc1and1))