Skip to content

Commit

Permalink
Merge branch '3.3.6'
Browse files Browse the repository at this point in the history
  • Loading branch information
andreasohlund committed Apr 22, 2013
2 parents 0f5a9d5 + 2d816ed commit 3ead51b
Show file tree
Hide file tree
Showing 21 changed files with 679 additions and 507 deletions.
2 changes: 0 additions & 2 deletions default.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@ $coreDirs = "unicastTransport", "ObjectBuilder", "config", "faults", "utils","se
$assemblies += dir $buildBase\nservicebus.core\NLog.dll
$assemblies += dir $buildBase\nservicebus.core\Raven.Abstractions.dll
$assemblies += dir $buildBase\nservicebus.core\Raven.Client.Lightweight.dll
$assemblies += dir $buildBase\nservicebus.core\rhino.licensing.dll
$assemblies += dir $buildBase\nservicebus.core\Newtonsoft.Json.dll

Ilmerge $ilMergeKey $outDir "NServiceBus.Core" $assemblies $attributeAssembly "dll" $script:ilmergeTargetFramework "$buildBase\NServiceBusCoreMergeLog.txt" $ilMergeExclude
Expand Down Expand Up @@ -516,7 +515,6 @@ function Prepare-Binaries{
Copy-Item $buildBase\nservicebus.core\AutoFac.dll $coreOnlyDir\dependencies\ -Exclude **Tests.dll
Copy-Item $buildBase\nservicebus.core\Raven*.dll $coreOnlyDir\dependencies\ -Exclude **Tests.dll, Raven.Client.Debug.dll, Raven.Client.MvcIntegration.dll
Copy-Item $buildBase\nservicebus.core\NLog.dll $coreOnlyDir\dependencies\ -Exclude **Tests.dll
Copy-Item $buildBase\nservicebus.core\rhino.licensing.dll $coreOnlyDir\dependencies\ -Exclude **Tests.dll
Copy-Item $buildBase\nservicebus.core\Newtonsoft.Json.dll $coreOnlyDir\dependencies\ -Exclude **Tests.dll
Copy-Item $buildBase\nservicebus.core\ICSharpCode.NRefactory.dll $coreOnlyDir\dependencies\ -Exclude **Tests.dll
Copy-Item $buildBase\nservicebus.core\Esent.Interop.dll $coreOnlyDir\dependencies\ -Exclude **Tests.dll
Expand Down
Binary file removed lib/rhino.licensing/Rhino.Licensing.dll
Binary file not shown.
464 changes: 0 additions & 464 deletions lib/rhino.licensing/Rhino.Licensing.xml

This file was deleted.

1 change: 0 additions & 1 deletion lib/rhino.licensing/acknowledgements.txt

This file was deleted.

25 changes: 0 additions & 25 deletions lib/rhino.licensing/license.txt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,11 @@ public void It_should_configure_the_document_store_with_the_connection_string()
Assert.AreEqual("http://localhost:8080", store.Url);
Assert.AreEqual("b5058088-3a5d-4f35-8a64-49b06719d6ef", store.ApiKey);
}

[Test]
public void It_should_configure_the_document_store_to_use_the_calling_assembly_name_as_the_database()
{
Assert.AreEqual("UnitTests", store.DefaultDatabase);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -120,16 +120,15 @@ static Configure RavenPersistenceWithConnectionString(Configure config, string c
}
else
{
if (database == null)
{
database = databaseNamingConvention();
}

store.Url = RavenPersistenceConstants.DefaultUrl;
store.ResourceManagerId = RavenPersistenceConstants.DefaultResourceManagerId;
}
if (database == null)
{
database = databaseNamingConvention();
}

if (database != null)
if (store.DefaultDatabase == null)
{
store.DefaultDatabase = database;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,15 @@
<Reference Include="NServiceBus.ObjectBuilder">
<HintPath>..\..\..\..\build\nservicebus.core\NServiceBus.ObjectBuilder.dll</HintPath>
</Reference>
<Reference Include="Rhino.Licensing">
<HintPath>..\..\..\..\lib\rhino.licensing\Rhino.Licensing.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.configuration" />
<Reference Include="System.Core" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
<Reference Include="System.Management" />
<Reference Include="System.Security" />
<Reference Include="System.ServiceModel" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
</ItemGroup>
Expand All @@ -74,6 +73,17 @@
<Compile Include="LicenseValidator.cs" />
<Compile Include="License.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Rhino.Licensing\AbstractLicenseValidator.cs" />
<Compile Include="Rhino.Licensing\ILicensingService.cs" />
<Compile Include="Rhino.Licensing\InvalidationType.cs" />
<Compile Include="Rhino.Licensing\ISubscriptionLicensingService.cs" />
<Compile Include="Rhino.Licensing\LicenseExpiredException.cs" />
<Compile Include="Rhino.Licensing\LicenseFileNotFoundException.cs" />
<Compile Include="Rhino.Licensing\LicenseNotFoundException.cs" />
<Compile Include="Rhino.Licensing\LicenseType.cs" />
<Compile Include="Rhino.Licensing\LicenseValidator.cs" />
<Compile Include="Rhino.Licensing\RhinoLicensingException.cs" />
<Compile Include="Rhino.Licensing\StringLicenseValidator.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,265 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Security.Cryptography;
using System.Security.Cryptography.Xml;
using System.Threading;
using System.Xml;
using log4net;

namespace Rhino.Licensing
{
/// <summary>
/// Base license validator.
/// </summary>
public abstract class AbstractLicenseValidator
{
/// <summary>
/// License validator logger
/// </summary>
protected readonly ILog Log = LogManager.GetLogger(typeof(LicenseValidator));

private readonly string publicKey;
private readonly Timer nextLeaseTimer;

/// <summary>
/// Fired when license data is invalidated
/// </summary>
public event Action<InvalidationType> LicenseInvalidated;

/// <summary>
/// Gets the expiration date of the license
/// </summary>
public DateTime ExpirationDate
{
get; private set;
}

/// <summary>
/// Gets the Type of the license
/// </summary>
public LicenseType LicenseType
{
get; private set;
}

/// <summary>
/// Gets the Id of the license holder
/// </summary>
public Guid UserId
{
get; private set;
}

/// <summary>
/// Gets the name of the license holder
/// </summary>
public string Name
{
get; private set;
}

/// <summary>
/// Gets extra license information
/// </summary>
public IDictionary<string, string> LicenseAttributes
{
get; private set;
}

/// <summary>
/// Gets or Sets the license content
/// </summary>
protected abstract string License
{
get; set;
}

private void LeaseLicenseAgain(object state)
{
if (HasExistingLicense())
return;

RaiseLicenseInvalidated();
}

private void RaiseLicenseInvalidated()
{
var licenseInvalidated = LicenseInvalidated;
if (licenseInvalidated == null)
throw new InvalidOperationException("License was invalidated, but there is no one subscribe to the LicenseInvalidated event");
licenseInvalidated(InvalidationType.TimeExpired);
}

/// <summary>
/// Creates a license validator with specified public key.
/// </summary>
/// <param name="publicKey">public key</param>
protected AbstractLicenseValidator(string publicKey)
{
LeaseTimeout = TimeSpan.FromHours(5);
LicenseAttributes = new Dictionary<string, string>();
nextLeaseTimer = new Timer(LeaseLicenseAgain);
this.publicKey = publicKey;
}

/// <summary>
/// Validates loaded license
/// </summary>
public virtual void AssertValidLicense()
{
LicenseAttributes.Clear();
if (HasExistingLicense())
{
return;
}

Log.WarnFormat("Could not validate existing license\r\n{0}", License);
throw new LicenseNotFoundException();
}

private bool HasExistingLicense()
{
try
{
if (TryLoadingLicenseValuesFromValidatedXml() == false)
{
Log.WarnFormat("Failed validating license:\r\n{0}", License);
return false;
}
Log.InfoFormat("License expiration date is {0}", ExpirationDate);

bool result = DateTime.UtcNow < ExpirationDate;

if (!result)
throw new LicenseExpiredException("Expiration Date : " + ExpirationDate);

return true;
}
catch (RhinoLicensingException)
{
throw;
}
catch (Exception)
{
return false;
}
}

/// <summary>
/// Loads license data from validated license file.
/// </summary>
/// <returns></returns>
public bool TryLoadingLicenseValuesFromValidatedXml()
{
try
{
var doc = new XmlDocument();
doc.LoadXml(License);

if (TryGetValidDocument(publicKey, doc) == false)
{
Log.WarnFormat("Could not validate xml signature of:\r\n{0}", License);
return false;
}

if (doc.FirstChild == null)
{
Log.WarnFormat("Could not find first child of:\r\n{0}", License);
return false;
}

var result = ValidateXmlDocumentLicense(doc);
if (result)
{
nextLeaseTimer.Change(LeaseTimeout, LeaseTimeout);
}
return result;
}
catch (RhinoLicensingException)
{
throw;
}
catch (Exception e)
{
Log.Error("Could not validate license", e);
return false;
}
}

/// <summary>
/// Lease timeout
/// </summary>
public TimeSpan LeaseTimeout { get; set; }

internal bool ValidateXmlDocumentLicense(XmlDocument doc)
{
XmlNode id = doc.SelectSingleNode("/license/@id");
if (id == null)
{
Log.WarnFormat("Could not find id attribute in license:\r\n{0}", License);
return false;
}

UserId = new Guid(id.Value);

XmlNode date = doc.SelectSingleNode("/license/@expiration");
if (date == null)
{
Log.WarnFormat("Could not find expiration in license:\r\n{0}", License);
return false;
}

ExpirationDate = DateTime.ParseExact(date.Value, "yyyy-MM-ddTHH:mm:ss.fffffff", CultureInfo.InvariantCulture);

XmlNode licenseType = doc.SelectSingleNode("/license/@type");
if (licenseType == null)
{
Log.WarnFormat("Could not find license type in {0}", licenseType);
return false;
}

LicenseType = (LicenseType)Enum.Parse(typeof(LicenseType), licenseType.Value);

XmlNode name = doc.SelectSingleNode("/license/name/text()");
if (name == null)
{
Log.WarnFormat("Could not find licensee's name in license:\r\n{0}", License);
return false;
}

Name = name.Value;

var license = doc.SelectSingleNode("/license");
foreach (XmlAttribute attrib in license.Attributes)
{
if (attrib.Name == "type" || attrib.Name == "expiration" || attrib.Name == "id")
continue;

LicenseAttributes[attrib.Name] = attrib.Value;
}

return true;
}

private bool TryGetValidDocument(string licensePublicKey, XmlDocument doc)
{
var rsa = new RSACryptoServiceProvider();
rsa.FromXmlString(licensePublicKey);

var nsMgr = new XmlNamespaceManager(doc.NameTable);
nsMgr.AddNamespace("sig", "http://www.w3.org/2000/09/xmldsig#");

var signedXml = new SignedXml(doc);
var sig = (XmlElement)doc.SelectSingleNode("//sig:Signature", nsMgr);
if (sig == null)
{
Log.WarnFormat("Could not find this signature node on license:\r\n{0}", License);
return false;
}
signedXml.LoadXml(sig);

return signedXml.CheckSignature(rsa);
}
}
}
Loading

0 comments on commit 3ead51b

Please sign in to comment.