Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dockerize #3

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
30 changes: 30 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# This is a Docker multi-stage build, which first defines a build step and then
# copies the build output to a clean image

# It is constructed this way to optimize for fast iterative build times and
# small final images

## Build step
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-alpine as builder

WORKDIR /etc/password-storage

# Copy over application files and build project
COPY . .
RUN dotnet publish -c release --self-contained -r linux-musl-x64 -o /etc/password-storage/build

## Runtime step
FROM mcr.microsoft.com/dotnet/core/runtime-deps:3.1-alpine

WORKDIR /etc/password-storage

# Copy the built files from the build step
COPY --from=builder /etc/password-storage/build .

# Link the application
# Create a non-privileged user to run as. Specify the GID and UID per convention
RUN ln -s /etc/password-storage/Twelve21.PasswordStorage /usr/local/bin/Twelve21.PasswordStorage && \
addgroup -g 1221 -S twelve21 && \
adduser -g 1221 -S twelve21 -G twelve21

ENTRYPOINT ["Twelve21.PasswordStorage"]
133 changes: 71 additions & 62 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,62 +1,71 @@
# Twelve21.PasswordStorage

This library is meant to provide utility functions for password storage. It is written in C# against .NET Core 2.2.

It currently only supports Argon2 calibration features. You can use this library to determine which parameters to pass to one of the Argon2 hashing functions.

This application is built upon the research in [this blog post](https://www.twelve21.io/how-to-choose-the-right-parameters-for-argon2/).

## Documentation

First, clone the git repository.

```
git clone https://https://github.com/bburman/Twelve21.PasswordStorage.git
```

Secondly, enter the directory and build the solution.

```
dotnet build
```

Next, enter the Twelve21.PasswordStorage subdirectory and run the Argon2 Calibration function.

```
cd ./Twelve21.PasswordStorage
dotnet run a2c
```

The application will run and show you the best results, similar to:

```
Best results:
M = 256 MB, T = 2, d = 8, Time = 0.732 s
M = 128 MB, T = 6, d = 8, Time = 0.99 s
M = 64 MB, T = 12, d = 8, Time = 0.968 s
M = 32 MB, T = 24, d = 8, Time = 0.896 s
M = 16 MB, T = 49, d = 8, Time = 0.973 s
M = 8 MB, T = 96, d = 8, Time = 0.991 s
M = 4 MB, T = 190, d = 8, Time = 0.977 s
M = 2 MB, T = 271, d = 8, Time = 0.973 s
M = 1 MB, T = 639, d = 8, Time = 0.991 s
```

For detailed help and options, add the --help option to the command line:

```
> dotnet run a2c -- --help


Usage: a2c [options]

Options:
-?|-h|--help Show help information
-t|--time The maximum time in milliseconds it should take to calculate the password hash. Defaults to 1000.
-p|--parallelism The degree of parallelism. Defaults to twice the number of CPU cores.
-i|--iterations The minimum number of iterations. Defaults to 2.
```

## License

[MIT License](https://opensource.org/licenses/MIT)
# Twelve21.PasswordStorage

This library is meant to provide utility functions for password storage. It is written in C# against .NET Core 2.2.

It currently only supports Argon2 calibration features. You can use this library to determine which parameters to pass to one of the Argon2 hashing functions.

This application is built upon the research in [this blog post](https://www.twelve21.io/how-to-choose-the-right-parameters-for-argon2/).

## Documentation

First, clone the git repository.

```
git clone https://https://github.com/bburman/Twelve21.PasswordStorage.git
```

Secondly, enter the directory and build the solution, or the Docker image.

```
# Either locally
dotnet build
# Or using Docker
docker build . -t password-storage
```

Next, run the Argon2 Calibration function.

```
# Either locally
cd ./Twelve21.PasswordStorage
dotnet run a2c
# Or using Docker
docker run -it password-storage a2c
```

The application will run and show you the best results, similar to:

```
Best results:
M = 256 MB, T = 2, d = 8, Time = 0.732 s
M = 128 MB, T = 6, d = 8, Time = 0.99 s
M = 64 MB, T = 12, d = 8, Time = 0.968 s
M = 32 MB, T = 24, d = 8, Time = 0.896 s
M = 16 MB, T = 49, d = 8, Time = 0.973 s
M = 8 MB, T = 96, d = 8, Time = 0.991 s
M = 4 MB, T = 190, d = 8, Time = 0.977 s
M = 2 MB, T = 271, d = 8, Time = 0.973 s
M = 1 MB, T = 639, d = 8, Time = 0.991 s
```

For detailed help and options, add the --help option to the command line:

```
# Either a local binary
> dotnet run a2c -- --help
# Or using Docker
> docker run -it password-storage --help


Usage: a2c [options]

Options:
-?|-h|--help Show help information
-t|--time The maximum time in milliseconds it should take to calculate the password hash. Defaults to 1000.
-p|--parallelism The degree of parallelism. Defaults to twice the number of CPU cores.
-i|--iterations The minimum number of iterations. Defaults to 2.
```

## License

[MIT License](https://opensource.org/licenses/MIT)
2 changes: 1 addition & 1 deletion Twelve21.PasswordStorage/Twelve21.PasswordStorage.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.2</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
9 changes: 2 additions & 7 deletions Twelve21.PasswordStorage/Utilities/SystemManagement.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
using System.Linq;
using System.Management;
using System;

namespace Twelve21.PasswordStorage.Utilities
{
public static class SystemManagement
{
public static int GetTotalCpuCores()
{
return new ManagementObjectSearcher("SELECT * FROM Win32_Processor")
.Get()
.Cast<ManagementBaseObject>()
.Select(mbo => int.Parse(mbo["NumberOfCores"].ToString()))
.Sum();
return Environment.ProcessorCount;
}
}
}