Skip to content

Commit

Permalink
dockerfiles and libsecp256k1 with recovery
Browse files Browse the repository at this point in the history
  • Loading branch information
tkstanczak committed Feb 26, 2018
1 parent 47c0fa2 commit 7abae9f
Show file tree
Hide file tree
Showing 17 changed files with 159 additions and 22 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ bld/
[Bb]in/
[Oo]bj/
[Ll]og/
[Oo]ut/

# Visual Studio 2015 cache/options directory
.vs/
Expand Down Expand Up @@ -258,4 +259,4 @@ paket-files/

# Python Tools for Visual Studio (PTVS)
__pycache__/
*.pyc
*.pyc
19 changes: 19 additions & 0 deletions src/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM microsoft/dotnet-nightly:2.1-sdk AS build-env
WORKDIR /app

# copy sln and restore as distinct layers
COPY Nethermind ./Nethermind/
COPY tests/GeneralStateTests ./tests/GeneralStateTests/
COPY tests/BlockchainTests ./tests/BlockchainTests/
COPY tests/TransactionTests ./tests/TransactionTests/
RUN dir
RUN dir tests
RUN dir Nethermind
RUN dotnet publish Nethermind/Nethermind.sln -c Release -o out

# build runtime image
FROM microsoft/dotnet-nightly:2.1-runtime-alpine
WORKDIR /app
COPY --from=build-env /app/Nethermind/Nethermind.Blockchain.Test.Runner/out ./
RUN ls
ENTRYPOINT ["dotnet", "Nethermind.Blockchain.Test.Runner.dll"]
25 changes: 25 additions & 0 deletions src/Dockerfile.globalization
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
FROM microsoft/dotnet-nightly:2.1-sdk AS build-env
WORKDIR /app

# copy csproj and restore as distinct layers
COPY *.csproj ./
COPY NuGet.config ./
RUN dotnet restore

# copy everything else and build
COPY . ./
RUN dotnet publish -c Release -o out --no-restore


# build runtime image
FROM microsoft/dotnet-nightly:2.1-runtime-alpine

ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT false
RUN apk add --no-cache icu-libs

ENV LC_ALL en_US.UTF-8
ENV LANG en_US.UTF-8

WORKDIR /app
COPY --from=build-env /app/out ./
ENTRYPOINT ["dotnet", "dotnetapp.dll"]
8 changes: 0 additions & 8 deletions src/Nethermind/Nethermind.Core/Nethermind.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,4 @@
</ProjectReference>
<ProjectReference Include="..\Nethermind.Secp256k1\Nethermind.Secp256k1.csproj" />
</ItemGroup>
<ItemGroup>
<None Update="Secp256k1.x64.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Secp256k1.x86.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
Binary file removed src/Nethermind/Nethermind.Core/Secp256k1.x64.dll
Binary file not shown.
Binary file removed src/Nethermind/Nethermind.Core/Secp256k1.x86.dll
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
15 changes: 15 additions & 0 deletions src/Nethermind/Nethermind.Secp256k1/Nethermind.Secp256k1.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,20 @@
<None Include="./External/Win64/secp256k1.dll" Link="secp256k1.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="./External/Posix/libsecp256k1.a" Link="libsecp256k1.a">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="./External/Posix/libsecp256k1.la" Link="libsecp256k1.la">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="./External/Posix/libsecp256k1.so" Link="libsecp256k1.so">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="./External/Posix/libsecp256k1.so.0" Link="libsecp256k1.so.0">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="./External/Posix/libsecp256k1.so.0.0.0" Link="libsecp256k1.so.0.0.0">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
33 changes: 21 additions & 12 deletions src/Nethermind/Nethermind.Secp256k1/Proxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,39 +40,48 @@ static Proxy()
}

[SuppressUnmanagedCodeSecurity]
[DllImport("secp256k1.dll")]
//[DllImport("secp256k1.dll")]
[DllImport("libsecp256k1")]
private static extern /* secp256k1_context */ IntPtr secp256k1_context_create(uint flags);

[SuppressUnmanagedCodeSecurity]
[DllImport("secp256k1.dll")]
//[DllImport("secp256k1.dll")]
[DllImport("libsecp256k1")]
private static extern /* void */ IntPtr secp256k1_context_destroy(IntPtr context);

[SuppressUnmanagedCodeSecurity]
[DllImport("secp256k1.dll")]
//[DllImport("secp256k1.dll")]
[DllImport("libsecp256k1")]
private static extern bool secp256k1_ec_seckey_verify( /* secp256k1_context */ IntPtr context, byte[] seckey);

[SuppressUnmanagedCodeSecurity]
[DllImport("secp256k1.dll")]
//[DllImport("secp256k1.dll")]
[DllImport("libsecp256k1")]
private static extern bool secp256k1_ec_pubkey_create( /* secp256k1_context */ IntPtr context, byte[] pubkey, byte[] seckey);

[SuppressUnmanagedCodeSecurity]
[DllImport("secp256k1.dll")]
//[DllImport("secp256k1.dll")]
[DllImport("libsecp256k1")]
private static extern bool secp256k1_ec_pubkey_serialize( /* secp256k1_context */ IntPtr context, byte[] serializedPublicKey, ref uint outputSize, byte[] publicKey, uint flags);

[SuppressUnmanagedCodeSecurity]
[DllImport("secp256k1.dll")]
//[DllImport("secp256k1.dll")]
[DllImport("libsecp256k1")]
private static extern bool secp256k1_ecdsa_sign_recoverable( /* secp256k1_context */ IntPtr context, byte[] signature, byte[] messageHash, byte[] privateKey, IntPtr nonceFunction, IntPtr nonceData);

[SuppressUnmanagedCodeSecurity]
[DllImport("secp256k1.dll")]
private static extern bool secp256k1_ecdsa_recoverable_signature_serialize_compact( /* secp256k1_context */ IntPtr context, byte[] compactSignature, out int recoveryId, byte[] signature);
// [SuppressUnmanagedCodeSecurity]
//[DllImport("secp256k1.dll")]
[DllImport("libsecp256k1")]
public static extern bool secp256k1_ecdsa_recoverable_signature_serialize_compact( /* secp256k1_context */ IntPtr context, byte[] compactSignature, out int recoveryId, byte[] signature);

[SuppressUnmanagedCodeSecurity]
[DllImport("secp256k1.dll")]
//[DllImport("secp256k1.dll")]
[DllImport("libsecp256k1")]
private static extern bool secp256k1_ecdsa_recoverable_signature_parse_compact( /* secp256k1_context */ IntPtr context, byte[] signature, byte[] compactSignature, int recoveryId);

[SuppressUnmanagedCodeSecurity]
[DllImport("secp256k1.dll")]
//[DllImport("secp256k1.dll")]
[DllImport("libsecp256k1")]
private static extern bool secp256k1_ecdsa_recover( /* secp256k1_context */ IntPtr context, byte[] publicKey, byte[] signature, byte[] message);

public static bool VerifyPrivateKey(byte[] privateKey)
Expand Down Expand Up @@ -119,7 +128,7 @@ public static byte[] SignCompact(byte[] messageHash, byte[] privateKey, out int
}

public static byte[] RecoverKeyFromCompact(byte[] messageHash, byte[] compactSignature, int recoveryId, bool compressed)
{
{
byte[] publicKey = new byte[64];
byte[] serializedPublicKey = new byte[compressed ? 33 : 65];
uint outputSize = (uint)serializedPublicKey.Length;
Expand Down
6 changes: 6 additions & 0 deletions src/Nethermind/NuGet.Config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
</packageSources>
</configuration>
9 changes: 9 additions & 0 deletions src/NuGet.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<!--To inherit the global NuGet package sources remove the <clear/> line below -->
<clear />
<add key="dotnet-core" value="https://dotnet.myget.org/F/dotnet-core/api/v3/index.json" />
<add key="api.nuget.org" value="https://api.nuget.org/v3/index.json" />
</packageSources>
</configuration>
60 changes: 60 additions & 0 deletions src/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# .NET Core Docker Alpine Production Sample (Preview)

This .NET Core Docker sample demonstrates a best practice pattern for building Alpine based Docker images for .NET Core apps for production.

The primary goal of Alpine is very small deployments. Images can be pulled quicker and will have a smaller attack surface area. The .NET Core Alpine Docker images are currently in preview. See the [.NET Core Alpine Docker Image announcement](https://github.com/dotnet/dotnet-docker-nightly/issues/500) for additional details.

The [sample Dockerfile](Dockerfile) creates a .NET Core application Docker image based off of the [.NET Core Runtime Alpine Preview Docker image](https://hub.docker.com/r/microsoft/dotnet-nightly/).

It uses the [Docker multi-stage build feature](https://github.com/dotnet/announcements/issues/18) to build the sample in a container based on the larger [.NET Core SDK Docker image](https://hub.docker.com/r/microsoft/dotnet/) and then copies the final build result into a Docker image based on the smaller [.NET Core Docker Runtime image](https://hub.docker.com/r/microsoft/dotnet/). The SDK image contains tools that are required to build applications while the runtime image does not.

This sample requires [Docker 17.06](https://docs.docker.com/release-notes/docker-ce) or later of the [Docker client](https://www.docker.com/products/docker). You need the latest Windows 10 or Windows Server 2016 to use [Windows containers](http://aka.ms/windowscontainers). The instructions assume you have the [Git](https://git-scm.com/downloads) client installed.

## Getting the sample

The easiest way to get the sample is by cloning the samples repository with git, using the following instructions.

```console
git clone https://github.com/dotnet/dotnet-docker-samples/
```

You can also [download the repository as a zip](https://github.com/dotnet/dotnet-docker-samples/archive/master.zip).

## Build and run the sample with Docker

You can build and run the sample in Docker using the following commands. The instructions assume that you are in the root of the repository.

```console
cd dotnetapp-prod-alpine-preview
docker build -t dotnetapp-prod-alpine-preview .
docker run --rm dotnetapp-prod-alpine-preview Hello .NET Core from Docker
```

Note: The instructions above work only with Linux containers.

## Build and run the sample without the Globalization Invariant Mode

The Alpine based .NET Core Runtime Docker image has the [.NET Core 2.0 Globalization Invariant Mode](https://github.com/dotnet/announcements/issues/20) enabled in order to reduce the default size of the image. Use cases that cannot tolerate Globalization Invariant Mode can reset the `DOTNET_SYSTEM_GLOBALIZATION_INVARIANT` environment variable and install the required ICU package. The [Globalization Dockerfile](Dockerfile.globalization) illustrates how this can be done.

You can build and run the sample in Docker using the following commands. The instructions assume that you are in the root of the repository.

```console
cd dotnetapp-prod-alpine-preview
docker build -t dotnetapp-prod-alpine-preview -f Dockerfile.globalization .
docker run --rm dotnetapp-prod-alpine-preview Hello .NET Core from Docker
```

Note: The instructions above work only with Linux containers.

## Docker Images used in this sample

The following Docker images are used in this sample

* [microsoft/dotnet-nightly:2.1-sdk](https://hub.docker.com/r/microsoft/dotnet-nightly)
* [microsoft/dotnet-nightly:2.1-runtime-alpine](https://hub.docker.com/r/microsoft/dotnet-nightly)

## Related Resources

* [ASP.NET Core Production Docker sample](../aspnetapp/README.md)
* [.NET Core Docker samples](../README.md)
* [.NET Framework Docker samples](https://github.com/Microsoft/dotnet-framework-docker-samples)
1 change: 1 addition & 0 deletions src/clean.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
gci -include bin,obj -recurse | remove-item -force -recurse
2 changes: 1 addition & 1 deletion src/tests
Submodule tests updated 228 files

0 comments on commit 7abae9f

Please sign in to comment.