Skip to content

Commit

Permalink
Microsoft Azure Key Vault Extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
herveyw-msft committed Apr 22, 2015
1 parent d7d5c57 commit d85c6b1
Show file tree
Hide file tree
Showing 43 changed files with 4,118 additions and 2 deletions.
36 changes: 34 additions & 2 deletions AzureManagementLibraries.sln
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Search.Test", "src\Search.T
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ApiManagementManagement", "src\ApiManagementManagement\ApiManagementManagement.csproj", "{C85D57A0-BFC7-4483-AAEF-9ABB9313873B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "KeyVault.Core", "src\KeyVault\Microsoft.Azure.KeyVault.Core\KeyVault.Core.csproj", "{B419782D-CA57-40F9-9322-340A4E852E82}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "KeyVault.Extensions", "src\KeyVault\Microsoft.Azure.KeyVault.Extensions\KeyVault.Extensions.csproj", "{937E445A-5604-4998-A9F5-9BE1E39001A4}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -556,7 +560,6 @@ Global
{2C21CBE7-5D68-434A-BB20-463886BE5551}.Release|Any CPU.ActiveCfg = Portable-Release|Any CPU
{2C21CBE7-5D68-434A-BB20-463886BE5551}.Release|Any CPU.Build.0 = Portable-Release|Any CPU
{BEC7DBF7-A3B1-4088-BDFF-C1C2A0FD6F56}.Debug|Any CPU.ActiveCfg = Portable-Debug|Any CPU
{BEC7DBF7-A3B1-4088-BDFF-C1C2A0FD6F56}.Debug|Any CPU.Build.0 = Portable-Debug|Any CPU
{BEC7DBF7-A3B1-4088-BDFF-C1C2A0FD6F56}.Net40-Debug|Any CPU.ActiveCfg = Net40-Debug|Any CPU
{BEC7DBF7-A3B1-4088-BDFF-C1C2A0FD6F56}.Net40-Debug|Any CPU.Build.0 = Net40-Debug|Any CPU
{BEC7DBF7-A3B1-4088-BDFF-C1C2A0FD6F56}.Net40-Release|Any CPU.ActiveCfg = Net40-Release|Any CPU
Expand All @@ -568,7 +571,6 @@ Global
{BEC7DBF7-A3B1-4088-BDFF-C1C2A0FD6F56}.Portable-Debug|Any CPU.ActiveCfg = Portable-Debug|Any CPU
{BEC7DBF7-A3B1-4088-BDFF-C1C2A0FD6F56}.Portable-Release|Any CPU.ActiveCfg = Portable-Release|Any CPU
{BEC7DBF7-A3B1-4088-BDFF-C1C2A0FD6F56}.Release|Any CPU.ActiveCfg = Portable-Release|Any CPU
{BEC7DBF7-A3B1-4088-BDFF-C1C2A0FD6F56}.Release|Any CPU.Build.0 = Portable-Release|Any CPU
{3B082B9B-96DD-4112-88E3-BE89BAE124C1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3B082B9B-96DD-4112-88E3-BE89BAE124C1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3B082B9B-96DD-4112-88E3-BE89BAE124C1}.Net40-Debug|Any CPU.ActiveCfg = Debug|Any CPU
Expand Down Expand Up @@ -601,6 +603,34 @@ Global
{C85D57A0-BFC7-4483-AAEF-9ABB9313873B}.Portable-Release|Any CPU.Build.0 = Portable-Release|Any CPU
{C85D57A0-BFC7-4483-AAEF-9ABB9313873B}.Release|Any CPU.ActiveCfg = Portable-Release|Any CPU
{C85D57A0-BFC7-4483-AAEF-9ABB9313873B}.Release|Any CPU.Build.0 = Portable-Release|Any CPU
{B419782D-CA57-40F9-9322-340A4E852E82}.Debug|Any CPU.ActiveCfg = Portable-Debug|Any CPU
{B419782D-CA57-40F9-9322-340A4E852E82}.Debug|Any CPU.Build.0 = Portable-Debug|Any CPU
{B419782D-CA57-40F9-9322-340A4E852E82}.Net40-Debug|Any CPU.ActiveCfg = Net40-Debug|Any CPU
{B419782D-CA57-40F9-9322-340A4E852E82}.Net40-Debug|Any CPU.Build.0 = Net40-Debug|Any CPU
{B419782D-CA57-40F9-9322-340A4E852E82}.Net40-Release|Any CPU.ActiveCfg = Net40-Release|Any CPU
{B419782D-CA57-40F9-9322-340A4E852E82}.Net40-Release|Any CPU.Build.0 = Net40-Release|Any CPU
{B419782D-CA57-40F9-9322-340A4E852E82}.Net45-Debug|Any CPU.ActiveCfg = Net45-Debug|Any CPU
{B419782D-CA57-40F9-9322-340A4E852E82}.Net45-Debug|Any CPU.Build.0 = Net45-Debug|Any CPU
{B419782D-CA57-40F9-9322-340A4E852E82}.Net45-Release|Any CPU.ActiveCfg = Net45-Release|Any CPU
{B419782D-CA57-40F9-9322-340A4E852E82}.Net45-Release|Any CPU.Build.0 = Net45-Release|Any CPU
{B419782D-CA57-40F9-9322-340A4E852E82}.Portable-Debug|Any CPU.ActiveCfg = Portable-Debug|Any CPU
{B419782D-CA57-40F9-9322-340A4E852E82}.Portable-Debug|Any CPU.Build.0 = Portable-Debug|Any CPU
{B419782D-CA57-40F9-9322-340A4E852E82}.Portable-Release|Any CPU.ActiveCfg = Portable-Release|Any CPU
{B419782D-CA57-40F9-9322-340A4E852E82}.Portable-Release|Any CPU.Build.0 = Portable-Release|Any CPU
{B419782D-CA57-40F9-9322-340A4E852E82}.Release|Any CPU.ActiveCfg = Portable-Release|Any CPU
{B419782D-CA57-40F9-9322-340A4E852E82}.Release|Any CPU.Build.0 = Portable-Release|Any CPU
{937E445A-5604-4998-A9F5-9BE1E39001A4}.Debug|Any CPU.ActiveCfg = Portable-Debug|Any CPU
{937E445A-5604-4998-A9F5-9BE1E39001A4}.Net40-Debug|Any CPU.ActiveCfg = Net40-Debug|Any CPU
{937E445A-5604-4998-A9F5-9BE1E39001A4}.Net40-Debug|Any CPU.Build.0 = Net40-Debug|Any CPU
{937E445A-5604-4998-A9F5-9BE1E39001A4}.Net40-Release|Any CPU.ActiveCfg = Net40-Release|Any CPU
{937E445A-5604-4998-A9F5-9BE1E39001A4}.Net40-Release|Any CPU.Build.0 = Net40-Release|Any CPU
{937E445A-5604-4998-A9F5-9BE1E39001A4}.Net45-Debug|Any CPU.ActiveCfg = Net45-Debug|Any CPU
{937E445A-5604-4998-A9F5-9BE1E39001A4}.Net45-Debug|Any CPU.Build.0 = Net45-Debug|Any CPU
{937E445A-5604-4998-A9F5-9BE1E39001A4}.Net45-Release|Any CPU.ActiveCfg = Net45-Release|Any CPU
{937E445A-5604-4998-A9F5-9BE1E39001A4}.Net45-Release|Any CPU.Build.0 = Net45-Release|Any CPU
{937E445A-5604-4998-A9F5-9BE1E39001A4}.Portable-Debug|Any CPU.ActiveCfg = Portable-Debug|Any CPU
{937E445A-5604-4998-A9F5-9BE1E39001A4}.Portable-Release|Any CPU.ActiveCfg = Portable-Release|Any CPU
{937E445A-5604-4998-A9F5-9BE1E39001A4}.Release|Any CPU.ActiveCfg = Portable-Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -638,6 +668,8 @@ Global
{BEC7DBF7-A3B1-4088-BDFF-C1C2A0FD6F56} = {868850B4-1073-41A1-ABA8-A3B465880148}
{3B082B9B-96DD-4112-88E3-BE89BAE124C1} = {868850B4-1073-41A1-ABA8-A3B465880148}
{C85D57A0-BFC7-4483-AAEF-9ABB9313873B} = {868850B4-1073-41A1-ABA8-A3B465880148}
{B419782D-CA57-40F9-9322-340A4E852E82} = {868850B4-1073-41A1-ABA8-A3B465880148}
{937E445A-5604-4998-A9F5-9BE1E39001A4} = {868850B4-1073-41A1-ABA8-A3B465880148}
EndGlobalSection
GlobalSection(TestCaseManagementSettings) = postSolution
CategoryFile = WindowsAzureLibraries.vsmdi
Expand Down
115 changes: 115 additions & 0 deletions src/KeyVault/Microsoft.Azure.KeyVault.Core/IKey.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
//
// Copyright © Microsoft Corporation, All Rights Reserved
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS
// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
// ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A
// PARTICULAR PURPOSE, MERCHANTABILITY OR NON-INFRINGEMENT.
//
// See the Apache License, Version 2.0 for the specific language
// governing permissions and limitations under the License.

using System;
using System.Threading;
using System.Threading.Tasks;

namespace Microsoft.Azure.KeyVault.Core
{
/// <summary>
/// Interface for Keys
/// </summary>
public interface IKey : IDisposable
{
/// <summary>
/// The default encryption algorithm for this key
/// </summary>
string DefaultEncryptionAlgorithm { get; }

/// <summary>
/// The default key wrap algorithm for this key
/// </summary>
string DefaultKeyWrapAlgorithm { get; }

/// <summary>
/// The default signature algorithm for this key
/// </summary>
string DefaultSignatureAlgorithm { get; }

/// <summary>
/// The key identifier
/// </summary>
string Kid { get; }

/// <summary>
/// Decrypts the specified cipher text.
/// </summary>
/// <param name="ciphertext">The cipher text to decrypt</param>
/// <param name="iv">The initialization vector</param>
/// <param name="authenticationData">The authentication data</param>
/// <param name="algorithm">The algorithm to use</param>
/// <param name="token">Cancellation token</param>
/// <returns>The plain text</returns>
/// <remarks>If algorithm is not specified, an implementation should use its default algorithm.
/// Not all algorithms require, or support, all parameters.</remarks>
Task<byte[]> DecryptAsync( byte[] ciphertext, byte[] iv, byte[] authenticationData, byte[] authenticationTag, string algorithm, CancellationToken token );

/// <summary>
/// Encrypts the specified plain text.
/// </summary>
/// <param name="plaintext">The plain text to encrypt</param>
/// <param name="iv">The initialization vector</param>
/// <param name="authenticationData">The authentication data</param>
/// <param name="algorithm">The algorithm to use</param>
/// <param name="token">Cancellation token</param>
/// <returns>A Tuple consisting of the cipher text, the authentication tag (if applicable), the algorithm used</returns>
/// <remarks>If the algorithm is not specified, an implementation should use its default algorithm.
/// Not all algorithyms require, or support, all parameters.</remarks>
Task<Tuple<byte[], byte[], string>> EncryptAsync( byte[] plaintext, byte[] iv, byte[] authenticationData, string algorithm, CancellationToken token );

/// <summary>
/// Encrypts the specified key material.
/// </summary>
/// <param name="key">The key material to encrypt</param>
/// <param name="algorithm">The algorithm to use</param>
/// <param name="token">Cancellation token</param>
/// <returns>A Tuple consisting of the encrypted key and the algorithm used</returns>
/// <remarks>If the algorithm is not specified, an implementation should use its default algorithm</remarks>
Task<Tuple<byte[], string>> WrapKeyAsync( byte[] key, string algorithm, CancellationToken token );

/// <summary>
/// Decrypts the specified key material.
/// </summary>
/// <param name="encryptedKey">The encrypted key material</param>
/// <param name="algorithm">The algorithm to use</param>
/// <param name="token">Cancellation token</param>
/// <returns>The decrypted key material</returns>
/// <remarks>If the algorithm is not specified, an implementation should use its default algorithm</remarks>
Task<byte[]> UnwrapKeyAsync( byte[] encryptedKey, string algorithm, CancellationToken token );

/// <summary>
/// Signs the specified digest.
/// </summary>
/// <param name="digest">The digest to sign</param>
/// <param name="algorithm">The algorithm to use</param>
/// <param name="token">Cancellation token</param>
/// <returns>A Tuple consisting of the signature and the algorithm used</returns>
/// <remarks>If the algorithm is not specified, an implementation should use its default algorithm</remarks>
Task<Tuple<byte[], string>> SignAsync( byte[] digest, string algorithm, CancellationToken token );

/// <summary>
/// Verifies the specified signature value
/// </summary>
/// <param name="digest">The digest</param>
/// <param name="signature">The signature value</param>
/// <param name="algorithm">The algorithm to use</param>
/// <param name="token">Cancellation token</param>
/// <returns>A bool indicating whether the signature was successfully verified</returns>
Task<bool> VerifyAsync( byte[] digest, byte[] signature, string algorithm, CancellationToken token );
}
}
38 changes: 38 additions & 0 deletions src/KeyVault/Microsoft.Azure.KeyVault.Core/IKeyResolver.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//
// Copyright © Microsoft Corporation, All Rights Reserved
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS
// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
// ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A
// PARTICULAR PURPOSE, MERCHANTABILITY OR NON-INFRINGEMENT.
//
// See the Apache License, Version 2.0 for the specific language
// governing permissions and limitations under the License.

using System.Threading;
using System.Threading.Tasks;

namespace Microsoft.Azure.KeyVault.Core
{
/// <summary>
/// Interface for key resolvers.
/// </summary>
public interface IKeyResolver
{
/// <summary>
/// Provides an IKey implementation for the specified key identifier.
/// </summary>
/// <param name="kid">The key identifier to resolve</param>
/// <param name="token">Cancellation token</param>
/// <returns>The resolved IKey implementation or null</returns>
/// <remarks>Implementations should check the format of the kid to ensure that it is recognized. Null, rather than
/// an exception, should be returned for unrecognized key identifiers to enable chaining of key resolvers.</remarks>
Task<IKey> ResolveKeyAsync( string kid, CancellationToken token );
}
}
49 changes: 49 additions & 0 deletions src/KeyVault/Microsoft.Azure.KeyVault.Core/KeyVault.Core.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\..\</SolutionDir>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{B419782D-CA57-40F9-9322-340A4E852E82}</ProjectGuid>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Microsoft.Azure.KeyVault.Core</RootNamespace>
<AssemblyName>Microsoft.Azure.KeyVault.Core</AssemblyName>
<OutputType>Library</OutputType>
<RestorePackages>true</RestorePackages>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<Import Project="$(SolutionDir)\tools\Library.Settings.targets" />
<ItemGroup>
<Compile Include="Generated\**\*.cs" />
<Compile Include="IKey.cs" />
<Compile Include="IKeyResolver.cs" />
</ItemGroup>
<ItemGroup>
<None Include="Microsoft.Azure.KeyVault.Core.nuspec" />
<None Include="Microsoft.Azure.KeyVault.Core.nuget.proj">
<SubType>Designer</SubType>
</None>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup Condition="'$(LibraryFxTarget)' == 'net40'">
<Reference Include="Microsoft.Threading.Tasks, Version=1.0.12.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Threading.Tasks.Extensions, Version=1.0.12.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.Extensions.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Reference Include="System.Net" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" Condition=" '$(LibraryFxTarget)' == 'portable' " />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" Condition=" '$(LibraryFxTarget)' != 'portable' " />
<Import Project="..\..\..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets" Condition="Exists('..\..\..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets')" />
<Target Name="EnsureBclBuildImported" BeforeTargets="BeforeBuild" Condition="'$(BclBuildImported)' == ''">
<Error Condition="!Exists('..\..\..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets')" Text="This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=317567." HelpKeyword="BCLBUILD2001" />
<Error Condition="Exists('..\..\..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets')" Text="The build restored NuGet packages. Build the project again to include these packages in the build. For more information, see http://go.microsoft.com/fwlink/?LinkID=317568." HelpKeyword="BCLBUILD2002" />
</Target>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<!--
Microsoft.Azure.KeyVault.Core
-->
<SdkNuGetPackage Include="Microsoft.Azure.KeyVault.Core">
<PackageVersion>0.9.0-preview</PackageVersion>
<Folder>$(MSBuildThisFileDirectory)</Folder>
</SdkNuGetPackage>
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata minClientVersion="2.5">
<id>Microsoft.Azure.KeyVault.Core</id>
<title>Microsoft Azure Key Vault Core Library</title>
<releaseNotes>Initial release</releaseNotes>
<version>$version$</version>
<authors>Microsoft</authors>
<owners>azure-sdk, Microsoft</owners>
<licenseUrl>http://aka.ms/windowsazureapache2</licenseUrl>
<projectUrl>https://github.com/Azure/azure-sdk-for-net</projectUrl>
<iconUrl>http://go.microsoft.com/fwlink/?LinkID=288890</iconUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<summary>IKey and IKeyResolver interfaces.</summary>
<description>Provides IKey and IKeyResolver interfaces for locating keys from identifiers
and performing operations with keys.</description>
<copyright>Copyright © Microsoft Corporation</copyright>
<tags>Microsoft Azure key vault "key vault" azureofficial windowsazureofficial</tags>
<references>
<group targetFramework="net45">
<reference file="Microsoft.Azure.KeyVault.Core.dll" />
</group>
<group targetFramework="net40">
<reference file="Microsoft.Azure.KeyVault.Core.dll" />
</group>
<group targetFramework="portable-net45+wp8+wpa81+win">
<reference file="Microsoft.Azure.KeyVault.Core.dll" />
</group>
</references>
</metadata>
<files>
<file src="KeyVault\Microsoft.Azure.KeyVault.Core\**\*.cs" target="src" />
<file src="..\binaries\net45\Microsoft.Azure.KeyVault.Core.dll" target="lib\portable-net45+wp8+wpa81+win" />
<file src="..\binaries\net45\Microsoft.Azure.KeyVault.Core.pdb" target="lib\portable-net45+wp8+wpa81+win" />
<file src="..\binaries\net45\Microsoft.Azure.KeyVault.Core.xml" target="lib\portable-net45+wp8+wpa81+win" />
<file src="..\binaries\net40\Microsoft.Azure.KeyVault.Core.dll" target="lib\net40" />
<file src="..\binaries\net40\Microsoft.Azure.KeyVault.Core.pdb" target="lib\net40" />
<file src="..\binaries\net40\Microsoft.Azure.KeyVault.Core.xml" target="lib\net40" />
<file src="..\binaries\net45\Microsoft.Azure.KeyVault.Core.dll" target="lib\net45" />
<file src="..\binaries\net45\Microsoft.Azure.KeyVault.Core.pdb" target="lib\net45" />
<file src="..\binaries\net45\Microsoft.Azure.KeyVault.Core.xml" target="lib\net45" />
</files>
</package>
6 changes: 6 additions & 0 deletions src/KeyVault/Microsoft.Azure.KeyVault.Core/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.Bcl" version="1.1.8" targetFramework="net45" />
<package id="Microsoft.Bcl.Async" version="1.0.168" targetFramework="net45" />
<package id="Microsoft.Bcl.Build" version="1.0.14" targetFramework="net45" />
</packages>
Loading

0 comments on commit d85c6b1

Please sign in to comment.