Skip to content

Commit

Permalink
porting LicenseSerializer change so that r.PersistKeyInCsp is done in…
Browse files Browse the repository at this point in the history
… a finally block like everywhere else
  • Loading branch information
fschwiet committed Nov 6, 2013
1 parent b94872f commit ed4bafd
Showing 1 changed file with 23 additions and 17 deletions.
40 changes: 23 additions & 17 deletions src/KeyHub.Client/LicenseDeserializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,34 @@ public Dictionary<string, List<DomainLicense>> DeserializeAll(string publicKeyXm

using (var r = new RSACryptoServiceProvider(2048))
{
r.PersistKeyInCsp = false;
r.FromXmlString(publicKeyXml);

foreach (var licenseAndSignature in licensesAndSignatures)
try
{
var licenseBytes = Convert.FromBase64String(licenseAndSignature.Key);
var domainLicense = DomainLicense.Parse(Encoding.UTF8.GetString(licenseBytes));
r.FromXmlString(publicKeyXml);

if (!r.VerifyData(licenseBytes, new SHA256Managed(),
Convert.FromBase64String(licenseAndSignature.Value)))
foreach (var licenseAndSignature in licensesAndSignatures)
{
throw new Exception("Signature failed for license of domain " + domainLicense.Domain);
}
var licenseBytes = Convert.FromBase64String(licenseAndSignature.Key);
var domainLicense = DomainLicense.Parse(Encoding.UTF8.GetString(licenseBytes));

string domain = domainLicense.Domain;
List<DomainLicense> forDomain;
if (!licenses.TryGetValue(domain, out forDomain))
{
forDomain = new List<DomainLicense>();
licenses[domain] = forDomain;
if (!r.VerifyData(licenseBytes, new SHA256Managed(),
Convert.FromBase64String(licenseAndSignature.Value)))
{
throw new Exception("Signature failed for license of domain " + domainLicense.Domain);
}

string domain = domainLicense.Domain;
List<DomainLicense> forDomain;
if (!licenses.TryGetValue(domain, out forDomain))
{
forDomain = new List<DomainLicense>();
licenses[domain] = forDomain;
}
forDomain.Add(domainLicense);
}
forDomain.Add(domainLicense);
}
finally
{
r.PersistKeyInCsp = false;
}
}

Expand Down

0 comments on commit ed4bafd

Please sign in to comment.