This repository was archived by the owner on Nov 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
Define Request From Local Cerificate #18
Open
HorizonSecuritySRL
wants to merge
18
commits into
Chatham:master
Choose a base branch
from
HorizonSecuritySRL:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 8 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
7fb9e79
Add CertPath
HorizonSecuritySRL 3c01b55
Initialization HttpClient
HorizonSecuritySRL bef516d
Update README.md
HorizonSecuritySRL 06cb607
Update Vault.csproj
HorizonSecuritySRL 16641a6
Update Vault.Tests.csproj
HorizonSecuritySRL 53ceb49
Update README.md
HorizonSecuritySRL 2b9f774
Update README.md
HorizonSecuritySRL 04a536f
Update Vault.csproj
HorizonSecuritySRL 9a99094
Update README.md
HorizonSecuritySRL 733c2eb
Update Vault.csproj
HorizonSecuritySRL 187cbf7
Update Vault.Tests.csproj
HorizonSecuritySRL 90bd0bd
CertificateCustomValidation
HorizonSecuritySRL 66fb741
Add Reference
HorizonSecuritySRL 13fbc70
Update VaultHttpClient.cs
HorizonSecuritySRL c7910a0
Update VaultHttpClient.cs
HorizonSecuritySRL 2f8e777
Update VaultHttpClient.cs
HorizonSecuritySRL 60a9bbc
Update VaultHttpClient.cs
HorizonSecuritySRL 29f65e6
Update VaultHttpClient.cs
HorizonSecuritySRL File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,98 +1,29 @@ | ||
| # Vault.NET [](https://ci.appveyor.com/project/chatham/vault-net/branch/master) | ||
| # Vault.NET Local Certificate | ||
|
|
||
| * Vault API: v0.9.1 | ||
| * .NET Standard 1.3 (.NET: >= 4.6, .NET Core: >= 1.0.0) | ||
| * .NET 4.5 | ||
| * Nuget: Vault [](https://www.nuget.org/packages/Vault/) | ||
| Required Packages/Assembly: | ||
|
|
||
| Vault.NET is an .NET API client for the interacting with [Vault](https://www.vaultproject.io/). This is a port of the go api client and provides generic methods for interacting with the paths in Vault. | ||
| - Microsoft.AspNet.WebApi.Client | ||
| - System.Net.Http.Formatting.dll | ||
|
|
||
| ## Example | ||
| I have defined a new property "CertPah" that is populated before the definition of the httpcliet. | ||
|
|
||
| ```csharp | ||
| using Vault; | ||
| In case it is empty, the behavior remains unchanged. | ||
|
|
||
| var vaultClient = new VaultClient(); | ||
| vaultClient.Token = "XXXXXX"; | ||
| ``` | ||
| If it is different from empty, then the certificate is taken locally and contributes to Vault API calls. | ||
|
|
||
| ### Generic Secret | ||
|
|
||
| ```csharp | ||
| var data = new Dictionary<string, string> | ||
| { | ||
| {"zip", "zap"} | ||
| }; | ||
| await vaultClient.Secret.Write("secret/foo", data); | ||
|
|
||
| var secret = await vaultClient.Secret.Read<Dictionary<string, string>>("secret/foo"); | ||
| Console.WriteLine(secret.Data["zip"]); | ||
|
|
||
| // zap | ||
| ``` | ||
|
|
||
| ### PKI | ||
|
|
||
| ```csharp | ||
| using Vault.Models.Secret.Pki; | ||
|
|
||
| var testRole = new RolesRequest | ||
| { | ||
| AllowAnyDomain = true, | ||
| EnforceHostnames = false, | ||
| MaxTtl = "1h" | ||
| }; | ||
| await vaultClient.Secret.Write("pki/roles/test", testRole); | ||
|
|
||
| var certRequest = new IssueRequest | ||
| ```csharp | ||
| public static async Task<Dictionary<string, string>> VaultAsync(string secretPath) | ||
| { | ||
| CommonName = "Test Cert" | ||
| }; | ||
| var cert = await vaultClient.Secret.Write<IssueRequest, IssueResponse>("pki/issue/test", certRequest); | ||
| Console.WriteLine(secret.Data.Certificate); | ||
|
|
||
| // -----BEGIN CERTIFICATE----- | ||
| // MII... | ||
| ``` | ||
|
|
||
| ### Username/Password Authentication | ||
|
|
||
| ```csharp | ||
| using Vault.Models.Auth.UserPass; | ||
|
|
||
| await vaultClient.Sys.EnableAuth("userpass", "userpass", "Userpass Mount"); | ||
|
|
||
| var usersRequest = new UsersRequest | ||
| { | ||
| Password = "password", | ||
| Policies = new List<string> { "default" }, | ||
| Ttl = "1h", | ||
| MaxTtl = "2h" | ||
| }; | ||
| await vaultClient.Auth.Write("userpass/users/username", usersRequest); | ||
|
|
||
| var loginRequest = new LoginRequest | ||
| { | ||
| Password = "password" | ||
| }; | ||
| var loginResponse = await vaultClient.Auth.Write<LoginRequest, NoData>("userpass/login/username", loginRequest); | ||
|
|
||
| // Set client token to authenticated token | ||
| vaultClient.Token = loginResponse.Auth.ClientToken; | ||
|
|
||
| // Proceed with authenticated requests | ||
| ``` | ||
|
|
||
| ## Models | ||
|
|
||
| Many request/response objects are provided in this package to support different backends. This is in no way an exhaustive list of all the objects. Since the models are the things that are going to most likely change between versions of vault, it may make sense to make your own to service your needs. These may get split into a seperate Nuget package in the future. | ||
|
|
||
| ## Testing | ||
|
|
||
| Since most of the operation of this library are just building requests and passing them to the vault API and the vault team provides an easy to use local development server, each test runs against its own vault server. This means that tests require the vault binary available to spin up the vault server instance. The test suite will first look for the environment variable `VAULT_BIN` and if not found will fall back to use the `vault` binary in the `$PATH`. | ||
| VaultOptions.Default.CertPath = new DirectoryInfo( | ||
| Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, @"..\..\" + "AppData\\cert.crt")) | ||
| ).ToString(); | ||
|
|
||
| Downloads for vault can be found [here](https://www.vaultproject.io/downloads.html). | ||
| var vaultClient = new VaultClient(); | ||
| vaultClient.Address = new System.Uri("https://vault.personal.domain.com:8200"); | ||
| vaultClient.Token = "token"; | ||
|
|
||
| ## Versioning | ||
| var secret = await vaultClient.Secret.Read<Dictionary<string, string>>(secretPath); | ||
|
|
||
| This library will follow the version of vault that it was developed against. Since most core operations of vault maintain backwards compatibility, this library can be used against many older and newer versions of vault. If features are added or bugs are fixed, a new point release will be created (ex. 0.6.4 -> 0.6.4.1). If there is some functionality that breaks on a newer version of vault, please submit a pull request. | ||
| return secret.Data; | ||
| } | ||
| ``` | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,6 +28,13 @@ | |
| <ItemGroup Condition=" '$(TargetFramework)' == 'net45' "> | ||
| <Reference Include="System.Web" /> | ||
| <Reference Include="System.Net.Http" /> | ||
| <Reference Include="System.Net.Formatting" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup Condition="'$(TargetFramework)' == 'net45'"> | ||
|
||
| <PackageReference Include="Microsoft.AspNet.WebApi.Client"> | ||
| <Version>5.2.4</Version> | ||
| </PackageReference> | ||
| </ItemGroup> | ||
|
|
||
| </Project> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please provide the description of the change in the description of the pull request. This is the main README for the repository.