Skip to content

Commit

Permalink
Merge pull request #142 from Azure/dev
Browse files Browse the repository at this point in the history
Fair Play 3.6.0.0 changes
  • Loading branch information
gtrifonov committed Apr 25, 2016
2 parents ce9358d + 6ef79e9 commit 9d5bc5f
Show file tree
Hide file tree
Showing 25 changed files with 545 additions and 214 deletions.
4 changes: 2 additions & 2 deletions .nuget/windowsazure.mediaservices.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata>
<id>windowsazure.mediaservices</id>
<version>3.5.3.0</version>
<version>3.6.0.0</version>
<title>Windows Azure Media Services .NET SDK</title>
<authors>Microsoft Corporation</authors>
<owners>Microsoft Corporation</owners>
<licenseUrl>http://go.microsoft.com/fwlink/?LinkID=272666&amp;clcid=0x409</licenseUrl>
<projectUrl>http://aka.ms/wamsmsdn</projectUrl>
<iconUrl>http://nimbuspmteam.blob.core.windows.net/nuget/Media Services 150.png</iconUrl>
<requireLicenseAcceptance>true</requireLicenseAcceptance>
<description>This package contains Windows Azure Media Service library 3.5.3.0 for .NET.</description>
<description>This package contains Windows Azure Media Service library 3.6.0.0 for .NET.</description>
<releaseNotes>For more information, please check our forum: http://social.msdn.microsoft.com/Forums/en-US/MediaServices/threads

For MSDN documentation please visit http://aka.ms/wamsmsdn
Expand Down
71 changes: 64 additions & 7 deletions src/net/Client/Collections/ContentKeyBaseCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Linq;
using System.Net;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
using System.Threading.Tasks;
using Microsoft.WindowsAzure.MediaServices.Client.TransientFaultHandling;
Expand All @@ -36,16 +38,16 @@ public abstract class ContentKeyBaseCollection : CloudBaseCollection<IContentKey
/// </summary>
public const string ContentKeySet = "ContentKeys";

/// <summary>
/// Initializes a new instance of the <see cref="LocatorBaseCollection"/> class.
/// </summary>
/// <param name="cloudMediaContext">The <seealso cref="CloudMediaContext"/> instance.</param>
[SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors",
/// <summary>
/// Initializes a new instance of the <see cref="ContentKeyBaseCollection"/> class.
/// </summary>
/// <param name="cloudMediaContext">The <seealso cref="CloudMediaContext"/> instance.</param>
[SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors",
Justification = "By design")]
internal ContentKeyBaseCollection(MediaContextBase cloudMediaContext)
: base(cloudMediaContext)
: base(cloudMediaContext)
{
this.Queryable = this.MediaContext.MediaServicesClassFactory.CreateDataServiceContext().CreateQuery<IContentKey, ContentKeyData>(ContentKeySet);
this.Queryable = this.MediaContext.MediaServicesClassFactory.CreateDataServiceContext().CreateQuery<IContentKey, ContentKeyData>(ContentKeySet);
}

/// <summary>
Expand Down Expand Up @@ -171,6 +173,61 @@ internal static ContentKeyData InitializeCommonContentKey(Guid keyId, byte[] con
return contentKeyData;
}

/// <summary>
/// Creates the FairPlay ASk.
/// </summary>
/// <param name="keyId">The key id.</param>
/// <param name="contentKey">The content key data.</param>
/// <param name="name">The name.</param>
/// <param name="cert">The cert.</param>
/// <returns>The content key.</returns>
internal static ContentKeyData InitializeFairPlayASk(Guid keyId, byte[] contentKey, string name, X509Certificate2 cert)
{
byte[] encryptedContentKey = CommonEncryption.EncryptContentKeyToCertificate(cert, contentKey);

ContentKeyData contentKeyData = new ContentKeyData
{
Id = EncryptionUtils.GetKeyIdentifierAsString(keyId),
EncryptedContentKey = Convert.ToBase64String(encryptedContentKey),
ContentKeyType = (int)ContentKeyType.FairPlayASk,
ProtectionKeyId = cert.Thumbprint,
ProtectionKeyType = (int)ProtectionKeyType.X509CertificateThumbprint,
Name = name,
Checksum = EncryptionUtils.CalculateChecksum(contentKey, keyId)
};

return contentKeyData;
}

/// <summary>
/// Creates FairPlay Pfx Password.
/// </summary>
/// <param name="keyId">The key id.</param>
/// <param name="contentKey">The content key data.</param>
/// <param name="name">The name.</param>
/// <param name="cert">The cert.</param>
/// <returns>The content key.</returns>
internal static ContentKeyData InitializeFairPlayPfxPassword(Guid keyId, byte[] contentKey, string name, X509Certificate2 cert)
{
RSACryptoServiceProvider rsaPublicKey = cert.PublicKey.Key as RSACryptoServiceProvider;

RSAOAEPKeyExchangeFormatter keyFormatter = new RSAOAEPKeyExchangeFormatter(rsaPublicKey);

byte[] encryptedContentKey = keyFormatter.CreateKeyExchange(contentKey);

ContentKeyData contentKeyData = new ContentKeyData
{
Id = EncryptionUtils.GetKeyIdentifierAsString(keyId),
EncryptedContentKey = Convert.ToBase64String(encryptedContentKey),
ContentKeyType = (int)ContentKeyType.FairPlayPfxPassword,
ProtectionKeyId = cert.Thumbprint,
ProtectionKeyType = (int)ProtectionKeyType.X509CertificateThumbprint,
Name = name,
};

return contentKeyData;
}

/// <summary>
/// Creates an envelope encryption content key.
/// </summary>
Expand Down

0 comments on commit 9d5bc5f

Please sign in to comment.