Skip to content
This repository has been archived by the owner on Apr 1, 2024. It is now read-only.

Use BCrypt/NCrypt on Windows platforms #66

Merged
merged 50 commits into from
Feb 22, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
a5d2b34
Make IAsymmetricKeyAlgorithmProvider : IDisposable
AArnott Dec 9, 2015
052fe1f
Work toward PCLCrypto.WinRT asymmetric keys use BCrypt
AArnott Dec 9, 2015
5091652
Merge branch 'master' into RSAviaBCrypt
AArnott Jan 3, 2016
cf79947
Implement RSA for WinRT using BCrypt
AArnott Jan 11, 2016
dc69535
Update PInvoke.BCrypt package
AArnott Jan 15, 2016
b83c6a5
Update PInvoke library
AArnott Jan 15, 2016
a3253c0
Fork BCrypt to NCrypt key base class
AArnott Jan 15, 2016
66408af
Allow unsafe blocks in all projects
AArnott Feb 6, 2016
857d149
Update PInvoke package dependencies
AArnott Feb 6, 2016
d0d03fc
Fill in extra parameters when reading non-full RSA private keys
AArnott Feb 7, 2016
5c5ec72
Fix package restore
AArnott Feb 7, 2016
7a77db4
Merge remote-tracking branch 'origin/master' into RSAviaBCrypt_WIP
AArnott Feb 7, 2016
e986039
Fix build breaks
AArnott Feb 7, 2016
508386a
AllowUnsafeBlocks for all projects and configs
AArnott Feb 7, 2016
3fb7e80
Fix break
AArnott Feb 7, 2016
7e780cc
Fix BCrypt RSA private key import/export
AArnott Feb 8, 2016
f4850c3
Fix BCrypt key pair import
AArnott Feb 8, 2016
cd703f4
Fixes KeyPairInterop tests on Desktop, UWP, WinRT
AArnott Feb 8, 2016
9a1f10a
All tests pass on Desktop now
AArnott Feb 9, 2016
cfb0ec0
Split out a compound test into a Theory.
AArnott Feb 9, 2016
6a89497
Fix some UWP tests that were throwing the wrong exception type
AArnott Feb 9, 2016
da88314
Unblock tests that failed due to lack of ECDSA support
AArnott Feb 9, 2016
a594aa5
Fix a few more tests
AArnott Feb 9, 2016
d6b7552
Avoid throwing for certain kinds of invalid signatures
AArnott Feb 9, 2016
44c9faa
Update PInvoke to fix another failing test
AArnott Feb 10, 2016
948d544
Implement ECDSA Import keys
AArnott Feb 15, 2016
876add3
Throw appropriate NotSupportedException
AArnott Feb 15, 2016
50aaa87
ECDsa key based on NCrypt
AArnott Feb 15, 2016
3220a42
Rename NCrypt base classes
AArnott Feb 15, 2016
51da752
Share more code across NCrypt keys and providers
AArnott Feb 15, 2016
1b26eb5
Rename keys and provider files
AArnott Feb 15, 2016
557c074
Remove asymmetric key derived types
AArnott Feb 15, 2016
4d33b11
Move a few files into src directory
AArnott Feb 15, 2016
2a2c75a
Fix build warnings
AArnott Feb 21, 2016
de2dfa4
Remove IDisposable from ISymmetricKeyAlgorithmProvider
AArnott Feb 21, 2016
373f703
Fix many failing tests in Android
AArnott Feb 21, 2016
f0dba3b
Fix private key roundtripping tests on Android
AArnott Feb 21, 2016
a960b64
Don't complain about missing parameter docs in tests
AArnott Feb 22, 2016
e207518
Add test for equivalent D computation from BCryptPrivateKey
AArnott Feb 22, 2016
7cd3f35
Fix some of the badly calculated parameters
AArnott Feb 22, 2016
4030f38
Disable the failing part of the test
AArnott Feb 22, 2016
db8cf4c
Fix test failure from not throwing for invalid algorithm parameter co…
AArnott Feb 22, 2016
2e1cece
Remove failing test from WP8 (silverlight)
AArnott Feb 22, 2016
b6bd118
Stop strong-name signing test assembly
AArnott Feb 22, 2016
ad27909
Fix NRE thrown from iOS
AArnott Feb 22, 2016
257834b
Fix failing tests on iOS
AArnott Feb 22, 2016
64f19b0
Suppress documentation warnings in test project
AArnott Feb 22, 2016
7eb300b
Remove Mono.Security dependency
AArnott Feb 22, 2016
092cd29
Update nuspec's representation of our nuget's dependencies
AArnott Feb 22, 2016
900ec59
Fix build break (desktop still needs Mono.Security)
AArnott Feb 22, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions EnlistmentInfo.props → src/EnlistmentInfo.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</PropertyGroup>

<PropertyGroup>
<ProjectRoot>$([MSBuild]::MakeRelative($(MSBuildProjectDirectory), '$(MSBuildThisFileDirectory)'))</ProjectRoot>
<ProjectRoot>$([MSBuild]::MakeRelative($(MSBuildProjectDirectory), '$(MSBuildThisFileDirectory)..\'))</ProjectRoot>
<SolutionDir>$(ProjectRoot)src\</SolutionDir>
<RestorePackages>true</RestorePackages>

Expand All @@ -18,11 +18,12 @@

<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>

<SignAssembly>true</SignAssembly>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>$(SolutionDir)opensource.snk</AssemblyOriginatorKeyFile>

<CodeAnalysisRuleSet Condition=" $(MSBuildProjectName.Contains('Tests')) ">$(MSBuildThisFileDirectory)src\PCLCrypto.Tests.ruleset</CodeAnalysisRuleSet>
<CodeAnalysisRuleSet Condition=" $(MSBuildProjectName.Contains('Tests')) ">$(SolutionDir)PCLCrypto.Tests.ruleset</CodeAnalysisRuleSet>

</PropertyGroup>

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion NuGet.config → src/NuGet.config
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<config>
<add key="repositorypath" value="packages" />
<add key="repositorypath" value="..\packages" />
</config>
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
Expand Down
2 changes: 1 addition & 1 deletion src/PCLCrypto.Android/PCLCrypto.Android.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="Mono.Android" />
<Reference Include="Mono.Security" />
<Reference Include="mscorlib" />
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Numerics" />
<Reference Include="System.Runtime" />
<Reference Include="System.Threading.Tasks" />
<Reference Include="System.Xml.Linq" />
Expand Down
8 changes: 7 additions & 1 deletion src/PCLCrypto.Android/RsaAsymmetricKeyAlgorithmProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ public ICryptographicKey CreateKeyPair(int keySize)
D = privateKeyParameters.PrivateExponent.ToByteArray(),
};

// Normalize RSAParameters (remove leading zeros, etc.)
parameters = KeyFormatter.Pkcs1.Read(KeyFormatter.Pkcs1.Write(parameters));

return new RsaCryptographicKey(key.Public, key.Private, parameters, this.algorithm);
}

Expand All @@ -77,7 +80,10 @@ public ICryptographicKey ImportKeyPair(byte[] keyBlob, CryptographicPrivateKeyBl
{
Requires.NotNull(keyBlob, "keyBlob");

RSAParameters parameters = KeyFormatter.GetFormatter(blobType).Read(keyBlob);
RSAParameters parameters = KeyFormatter.GetFormatter(blobType)
.Read(keyBlob)
.ComputeFullPrivateKeyData();

IPrivateKey privateKey;
IPublicKey publicKey;

Expand Down
45 changes: 24 additions & 21 deletions src/PCLCrypto.Android/RsaCryptographicKey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,27 +102,6 @@ public byte[] ExportPublicKey(CryptographicPublicKeyBlobType blobType)
return KeyFormatter.GetFormatter(blobType).Write(this.parameters, includePrivateKey: false);
}

/// <summary>
/// Disposes of managed resources associated with this object.
/// </summary>
public void Dispose()
{
this.publicKey.Dispose();
this.privateKey.Dispose();
}

/// <inheritdoc />
protected internal override byte[] Sign(byte[] data)
{
using (Signature instance = Signature.GetInstance(GetSignatureName(this.Algorithm)))
{
instance.InitSign(this.privateKey);
instance.Update(data);
byte[] signature = instance.Sign();
return signature;
}
}

/// <inheritdoc />
protected internal override bool VerifySignature(byte[] data, byte[] signature)
{
Expand Down Expand Up @@ -186,6 +165,30 @@ protected internal override byte[] Decrypt(byte[] data, byte[] iv)
}
}

/// <inheritdoc />
protected internal override byte[] Sign(byte[] data)
{
using (Signature instance = Signature.GetInstance(GetSignatureName(this.Algorithm)))
{
instance.InitSign(this.privateKey);
instance.Update(data);
byte[] signature = instance.Sign();
return signature;
}
}

/// <inheritdoc />
protected override void Dispose(bool disposing)
{
if (disposing)
{
this.publicKey?.Dispose();
this.privateKey?.Dispose();
}

base.Dispose(disposing);
}

/// <summary>
/// Gets the string to pass to <see cref="Cipher.GetInstance(string)"/>
/// for the given algorithm.
Expand Down
21 changes: 13 additions & 8 deletions src/PCLCrypto.Android/SymmetricCryptographicKey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,6 @@ public byte[] ExportPublicKey(CryptographicPublicKeyBlobType blobType = Cryptogr
throw new NotSupportedException();
}

/// <inheritdoc />
public void Dispose()
{
this.key.Dispose();
this.encryptingCipher.DisposeIfNotNull();
this.decryptingCipher.DisposeIfNotNull();
}

/// <inheritdoc />
protected internal override byte[] Encrypt(byte[] data, byte[] iv)
{
Expand Down Expand Up @@ -144,6 +136,19 @@ protected internal override ICryptoTransform CreateDecryptor(byte[] iv)
return new CryptoTransformAdaptor(this.Name, this.Mode, this.Padding, this.decryptingCipher);
}

/// <inheritdoc />
protected override void Dispose(bool disposing)
{
if (disposing)
{
this.key.Dispose();
this.encryptingCipher.DisposeIfNotNull();
this.decryptingCipher.DisposeIfNotNull();
}

base.Dispose(disposing);
}

/// <summary>
/// Gets the padding substring to include in the string
/// passed to <see cref="Cipher.GetInstance(string)"/>
Expand Down
7 changes: 0 additions & 7 deletions src/PCLCrypto.Android/SymmetricKeyAlgorithmProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,6 @@ public ICryptographicKey CreateSymmetricKey(byte[] keyMaterial)
return new SymmetricCryptographicKey(this, this.Name, this.Mode, this.Padding, keyMaterial);
}

/// <summary>
/// Disposes resources associated with this instance.
/// </summary>
public void Dispose()
{
}

/// <summary>
/// Gets the block size (in bytes) for the specified algorithm.
/// </summary>
Expand Down
2 changes: 2 additions & 0 deletions src/PCLCrypto.Android/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
"version": "1.3.8",
"suppressParent": "none"
},
"PInvoke.BCrypt": "0.1.433-rc-gfce000155c",
"PInvoke.NCrypt": "0.1.433-rc-gfce000155c",
"StyleCop.Analyzers": "1.0.0-beta015",
"Validation": "2.2.8"
},
Expand Down
27 changes: 15 additions & 12 deletions src/PCLCrypto.Desktop/CngCryptographicKey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,6 @@ public byte[] ExportPublicKey(CryptographicPublicKeyBlobType blobType)
return this.key.Export(CngAsymmetricKeyAlgorithmProvider.GetPlatformKeyBlobType(blobType));
}

/// <summary>
/// Disposes of managed resources associated with this object.
/// </summary>
public void Dispose()
{
// Delete the key since we may have created it with a name,
// so that we can export it, but we do not wish for it to be
// permanently recorded in the device's key store.
this.key.Delete();
this.key.Dispose();
}

/// <inheritdoc />
protected internal override byte[] Sign(byte[] data)
{
Expand Down Expand Up @@ -126,5 +114,20 @@ protected internal override bool VerifyHash(byte[] data, byte[] signature)
return cng.VerifyHash(data, signature);
}
}

/// <inheritdoc />
protected override void Dispose(bool disposing)
{
if (disposing)
{
// Delete the key since we may have created it with a name,
// so that we can export it, but we do not wish for it to be
// permanently recorded in the device's key store.
this.key.Delete();
this.key.Dispose();
}

base.Dispose(disposing);
}
}
}
1 change: 1 addition & 0 deletions src/PCLCrypto.Desktop/PCLCrypto.Desktop.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Numerics" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
Expand Down
2 changes: 2 additions & 0 deletions src/PCLCrypto.Desktop/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
"version": "1.3.8",
"suppressParent": "none"
},
"PInvoke.BCrypt": "0.1.433-rc-gfce000155c",
"PInvoke.NCrypt": "0.1.433-rc-gfce000155c",
"StyleCop.Analyzers": "1.0.0-beta015",
"Validation": "2.2.8"
},
Expand Down
Loading