-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of github.com:securosys-com/hcvault-ce-rest-integ…
…ration
- Loading branch information
Showing
42 changed files
with
35,198 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -0,0 +1,181 @@ | ||
//go:build go1.11 || go1.12 || go1.13 || go1.14 || go1.15 | ||
|
||
package pkcs7 | ||
|
||
import ( | ||
"crypto/x509" | ||
"encoding/pem" | ||
"io/ioutil" | ||
"os" | ||
"os/exec" | ||
"testing" | ||
) | ||
|
||
func TestVerifyEC2(t *testing.T) { | ||
fixture := UnmarshalDSATestFixture(EC2IdentityDocumentFixture) | ||
p7, err := Parse(fixture.Input) | ||
if err != nil { | ||
t.Errorf("Parse encountered unexpected error: %v", err) | ||
} | ||
p7.Certificates = []*x509.Certificate{fixture.Certificate} | ||
if err := p7.Verify(); err != nil { | ||
t.Errorf("Verify failed with error: %v", err) | ||
} | ||
} | ||
|
||
var EC2IdentityDocumentFixture = ` | ||
-----BEGIN PKCS7----- | ||
MIAGCSqGSIb3DQEHAqCAMIACAQExCzAJBgUrDgMCGgUAMIAGCSqGSIb3DQEHAaCA | ||
JIAEggGmewogICJwcml2YXRlSXAiIDogIjE3Mi4zMC4wLjI1MiIsCiAgImRldnBh | ||
eVByb2R1Y3RDb2RlcyIgOiBudWxsLAogICJhdmFpbGFiaWxpdHlab25lIiA6ICJ1 | ||
cy1lYXN0LTFhIiwKICAidmVyc2lvbiIgOiAiMjAxMC0wOC0zMSIsCiAgImluc3Rh | ||
bmNlSWQiIDogImktZjc5ZmU1NmMiLAogICJiaWxsaW5nUHJvZHVjdHMiIDogbnVs | ||
bCwKICAiaW5zdGFuY2VUeXBlIiA6ICJ0Mi5taWNybyIsCiAgImFj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HgYDVQQKExdBbWF6b24gV2ViIFNl | ||
cnZpY2VzIExMQzCCAbcwggEsBgcqhkjOOAQBMIIBHwKBgQCjkvcS2bb1VQ4yt/5e | ||
ih5OO6kK/n1Lzllr7D8ZwtQP8fOEpp5E2ng+D6Ud1Z1gYipr58Kj3nssSNpI6bX3 | ||
VyIQzK7wLclnd/YozqNNmgIyZecN7EglK9ITHJLP+x8FtUpt3QbyYXJdmVMegN6P | ||
hviYt5JH/nYl4hh3Pa1HJdskgQIVALVJ3ER11+Ko4tP6nwvHwh6+ERYRAoGBAI1j | ||
k+tkqMVHuAFcvAGKocTgsjJem6/5qomzJuKDmbJNu9Qxw3rAotXau8Qe+MBcJl/U | ||
hhy1KHVpCGl9fueQ2s6IL0CaO/buycU1CiYQk40KNHCcHfNiZbdlx1E9rpUp7bnF | ||
lRa2v1ntMX3caRVDdbtPEWmdxSCYsYFDk4mZrOLBA4GEAAKBgEbmeve5f8LIE/Gf | ||
MNmP9CM5eovQOGx5ho8WqD+aTebs+k2tn92BBPqeZqpWRa5P/+jrdKml1qx4llHW | ||
MXrs3IgIb6+hUIB+S8dz8/mmO0bpr76RoZVCXYab2CZedFut7qc3WUH9+EUAH5mw | ||
vSeDCOUMYQR7R9LINYwouHIziqQYMAkGByqGSM44BAMDLwAwLAIUWXBlk40xTwSw | ||
7HX32MxXYruse9ACFBNGmdX2ZBrVNGrN9N2f6ROk0k9K | ||
-----END CERTIFICATE-----` | ||
|
||
func TestDSASignWithOpenSSLAndVerify(t *testing.T) { | ||
content := []byte(` | ||
A ship in port is safe, | ||
but that's not what ships are built for. | ||
-- Grace Hopper`) | ||
// write the content to a temp file | ||
tmpContentFile, err := ioutil.TempFile("", "TestDSASignWithOpenSSLAndVerify_content") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
ioutil.WriteFile(tmpContentFile.Name(), content, 0o755) | ||
|
||
// write the signer cert to a temp file | ||
tmpSignerCertFile, err := ioutil.TempFile("", "TestDSASignWithOpenSSLAndVerify_signer") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
ioutil.WriteFile(tmpSignerCertFile.Name(), dsaPublicCert, 0o755) | ||
|
||
// write the signer key to a temp file | ||
tmpSignerKeyFile, err := ioutil.TempFile("", "TestDSASignWithOpenSSLAndVerify_key") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
ioutil.WriteFile(tmpSignerKeyFile.Name(), dsaPrivateKey, 0o755) | ||
|
||
tmpSignedFile, err := ioutil.TempFile("", "TestDSASignWithOpenSSLAndVerify_signature") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
// call openssl to sign the content | ||
opensslCMD := exec.Command("openssl", "smime", "-sign", "-nodetach", "-md", "sha1", | ||
"-in", tmpContentFile.Name(), "-out", tmpSignedFile.Name(), | ||
"-signer", tmpSignerCertFile.Name(), "-inkey", tmpSignerKeyFile.Name(), | ||
"-certfile", tmpSignerCertFile.Name(), "-outform", "PEM") | ||
out, err := opensslCMD.CombinedOutput() | ||
if err != nil { | ||
t.Fatalf("openssl command failed with %s: %s", err, out) | ||
} | ||
|
||
// verify the signed content | ||
pemSignature, err := ioutil.ReadFile(tmpSignedFile.Name()) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
t.Logf("%s\n", pemSignature) | ||
derBlock, _ := pem.Decode(pemSignature) | ||
if derBlock == nil { | ||
t.Fatalf("failed to read DER block from signature PEM %s", tmpSignedFile.Name()) | ||
} | ||
p7, err := Parse(derBlock.Bytes) | ||
if err != nil { | ||
t.Fatalf("Parse encountered unexpected error: %v", err) | ||
} | ||
if err := p7.Verify(); err != nil { | ||
t.Fatalf("Verify failed with error: %v", err) | ||
} | ||
os.Remove(tmpSignerCertFile.Name()) // clean up | ||
os.Remove(tmpSignerKeyFile.Name()) // clean up | ||
os.Remove(tmpContentFile.Name()) // clean up | ||
} | ||
|
||
var dsaPrivateKey = []byte(`-----BEGIN PRIVATE KEY----- | ||
MIIBSwIBADCCASwGByqGSM44BAEwggEfAoGBAP1/U4EddRIpUt9KnC7s5Of2EbdS | ||
PO9EAMMeP4C2USZpRV1AIlH7WT2NWPq/xfW6MPbLm1Vs14E7gB00b/JmYLdrmVCl | ||
pJ+f6AR7ECLCT7up1/63xhv4O1fnxqimFQ8E+4P208UewwI1VBNaFpEy9nXzrith | ||
1yrv8iIDGZ3RSAHHAhUAl2BQjxUjC8yykrmCouuEC/BYHPUCgYEA9+GghdabPd7L | ||
vKtcNrhXuXmUr7v6OuqC+VdMCz0HgmdRWVeOutRZT+ZxBxCBgLRJFnEj6EwoFhO3 | ||
zwkyjMim4TwWeotUfI0o4KOuHiuzpnWRbqN/C/ohNWLx+2J6ASQ7zKTxvqhRkImo | ||
g9/hWuWfBpKLZl6Ae1UlZAFMO/7PSSoEFgIUfW4aPdQBn9gJZp2KuNpzgHzvfsE= | ||
-----END PRIVATE KEY-----`) | ||
|
||
var dsaPublicCert = []byte(`-----BEGIN CERTIFICATE----- | ||
MIIDOjCCAvWgAwIBAgIEPCY/UDANBglghkgBZQMEAwIFADBsMRAwDgYDVQQGEwdV | ||
bmtub3duMRAwDgYDVQQIEwdVbmtub3duMRAwDgYDVQQHEwdVbmtub3duMRAwDgYD | ||
VQQKEwdVbmtub3duMRAwDgYDVQQLEwdVbmtub3duMRAwDgYDVQQDEwdVbmtub3du | ||
MB4XDTE4MTAyMjEzNDMwN1oXDTQ2MDMwOTEzNDMwN1owbDEQMA4GA1UEBhMHVW5r | ||
bm93bjEQMA4GA1UECBMHVW5rbm93bjEQMA4GA1UEBxMHVW5rbm93bjEQMA4GA1UE | ||
ChMHVW5rbm93bjEQMA4GA1UECxMHVW5rbm93bjEQMA4GA1UEAxMHVW5rbm93bjCC | ||
AbgwggEsBgcqhkjOOAQBMIIBHwKBgQD9f1OBHXUSKVLfSpwu7OTn9hG3UjzvRADD | ||
Hj+AtlEmaUVdQCJR+1k9jVj6v8X1ujD2y5tVbNeBO4AdNG/yZmC3a5lQpaSfn+gE | ||
exAiwk+7qdf+t8Yb+DtX58aophUPBPuD9tPFHsMCNVQTWhaRMvZ1864rYdcq7/Ii | ||
Axmd0UgBxwIVAJdgUI8VIwvMspK5gqLrhAvwWBz1AoGBAPfhoIXWmz3ey7yrXDa4 | ||
V7l5lK+7+jrqgvlXTAs9B4JnUVlXjrrUWU/mcQcQgYC0SRZxI+hMKBYTt88JMozI | ||
puE8FnqLVHyNKOCjrh4rs6Z1kW6jfwv6ITVi8ftiegEkO8yk8b6oUZCJqIPf4Vrl | ||
nwaSi2ZegHtVJWQBTDv+z0kqA4GFAAKBgQDCriMPbEVBoRK4SOUeFwg7+VRf4TTp | ||
rcOQC9IVVoCjXzuWEGrp3ZI7YWJSpFnSch4lk29RH8O0HpI/NOzKnOBtnKr782pt | ||
1k/bJVMH9EaLd6MKnAVjrCDMYBB0MhebZ8QHY2elZZCWoqDYAcIDOsEx+m4NLErT | ||
ypPnjS5M0jm1PKMhMB8wHQYDVR0OBBYEFC0Yt5XdM0Kc95IX8NQ8XRssGPx7MA0G | ||
CWCGSAFlAwQDAgUAAzAAMC0CFQCIgQtrZZ9hdZG1ROhR5hc8nYEmbgIUAIlgC688 | ||
qzy/7yePTlhlpj+ahMM= | ||
-----END CERTIFICATE-----`) | ||
|
||
type DSATestFixture struct { | ||
Input []byte | ||
Certificate *x509.Certificate | ||
} | ||
|
||
func UnmarshalDSATestFixture(testPEMBlock string) DSATestFixture { | ||
var result DSATestFixture | ||
var derBlock *pem.Block | ||
pemBlock := []byte(testPEMBlock) | ||
for { | ||
derBlock, pemBlock = pem.Decode(pemBlock) | ||
if derBlock == nil { | ||
break | ||
} | ||
switch derBlock.Type { | ||
case "PKCS7": | ||
result.Input = derBlock.Bytes | ||
case "CERTIFICATE": | ||
result.Certificate, _ = x509.ParseCertificate(derBlock.Bytes) | ||
} | ||
} | ||
|
||
return result | ||
} |
This file contains 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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# Copyright (c) HashiCorp, Inc. | ||
# SPDX-License-Identifier: BUSL-1.1 | ||
|
||
variable "cluster_id" { | ||
type = string | ||
} | ||
|
||
variable "cluster_meta" { | ||
type = string | ||
default = null | ||
} | ||
|
||
variable "common_tags" { | ||
type = map(string) | ||
default = null | ||
} | ||
|
||
variable "other_resources" { | ||
type = list(string) | ||
default = [] | ||
} | ||
|
||
locals { | ||
cluster_name = var.cluster_meta == null ? var.cluster_id : "${var.cluster_id}-${var.cluster_meta}" | ||
} | ||
resource "aws_kms_key" "key" { | ||
description = "auto-unseal-key-${local.cluster_name}" | ||
deletion_window_in_days = 7 // 7 is the shortest allowed window | ||
tags = var.common_tags | ||
} | ||
|
||
resource "aws_kms_alias" "alias" { | ||
name = "alias/auto-unseal-key-${local.cluster_name}" | ||
target_key_id = aws_kms_key.key.key_id | ||
} | ||
|
||
output "alias" { | ||
description = "The key alias name" | ||
value = aws_kms_alias.alias.name | ||
} | ||
|
||
output "id" { | ||
description = "The key ID" | ||
value = aws_kms_key.key.key_id | ||
} | ||
|
||
output "resource_name" { | ||
description = "The ARN" | ||
value = aws_kms_key.key.arn | ||
} | ||
|
||
output "resource_names" { | ||
description = "The list of names" | ||
value = compact(concat([aws_kms_key.key.arn], var.other_resources)) | ||
} |
This file contains 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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Copyright (c) HashiCorp, Inc. | ||
# SPDX-License-Identifier: BUSL-1.1 | ||
|
||
# A shim unseal key module for shamir seal types | ||
|
||
variable "cluster_id" { default = null } | ||
variable "cluster_meta" { default = null } | ||
variable "common_tags" { default = null } | ||
variable "names" { | ||
type = list(string) | ||
default = [] | ||
} | ||
|
||
output "alias" { value = null } | ||
output "id" { value = null } | ||
output "resource_name" { value = null } | ||
output "resource_names" { value = var.names } |
This file contains 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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# Copyright (c) HashiCorp, Inc. | ||
# SPDX-License-Identifier: BUSL-1.1 | ||
|
||
locals { | ||
|
||
// file name extensions for the install packages of vault for the various architectures, distributions and editions | ||
package_extensions = { | ||
amd64 = { | ||
ubuntu = "-1_amd64.deb" | ||
rhel = "-1.x86_64.rpm" | ||
} | ||
arm64 = { | ||
ubuntu = "-1_arm64.deb" | ||
rhel = "-1.aarch64.rpm" | ||
} | ||
} | ||
|
||
// product_version --> artifact_version | ||
artifact_version = replace(var.product_version, var.edition, "ent") | ||
|
||
// file name prefixes for the install packages of vault for the various distributions and artifact types (package or bundle) | ||
artifact_package_release_names = { | ||
ubuntu = { | ||
"ce" = "vault_" | ||
"ent" = "vault-enterprise_", | ||
"ent.fips1402" = "vault-enterprise-fips1402_", | ||
"ent.hsm" = "vault-enterprise-hsm_", | ||
"ent.hsm.fips1402" = "vault-enterprise-hsm-fips1402_", | ||
}, | ||
rhel = { | ||
"ce" = "vault-" | ||
"ent" = "vault-enterprise-", | ||
"ent.fips1402" = "vault-enterprise-fips1402-", | ||
"ent.hsm" = "vault-enterprise-hsm-", | ||
"ent.hsm.fips1402" = "vault-enterprise-hsm-fips1402-", | ||
} | ||
} | ||
|
||
// edition --> artifact name edition | ||
artifact_name_edition = { | ||
"ce" = "" | ||
"ent" = "" | ||
"ent.hsm" = ".hsm" | ||
"ent.fips1402" = ".fips1402" | ||
"ent.hsm.fips1402" = ".hsm.fips1402" | ||
} | ||
|
||
artifact_name_prefix = var.artifact_type == "package" ? local.artifact_package_release_names[var.distro][var.edition] : "vault_" | ||
artifact_name_extension = var.artifact_type == "package" ? local.package_extensions[var.arch][var.distro] : "_linux_${var.arch}.zip" | ||
artifact_name = var.artifact_type == "package" ? "${local.artifact_name_prefix}${replace(local.artifact_version, "-", "~")}${local.artifact_name_extension}" : "${local.artifact_name_prefix}${var.product_version}${local.artifact_name_extension}" | ||
} |
This file contains 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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Copyright (c) HashiCorp, Inc. | ||
# SPDX-License-Identifier: BUSL-1.1 | ||
|
||
terraform { | ||
required_providers { | ||
enos = { | ||
source = "app.terraform.io/hashicorp-qti/enos" | ||
version = ">= 0.2.3" | ||
} | ||
} | ||
} | ||
|
||
data "enos_artifactory_item" "vault" { | ||
username = var.artifactory_username | ||
token = var.artifactory_token | ||
name = local.artifact_name | ||
host = var.artifactory_host | ||
repo = var.artifactory_repo | ||
path = var.edition == "ce" ? "vault/*" : "vault-enterprise/*" | ||
properties = tomap({ | ||
"commit" = var.revision | ||
"product-name" = var.edition == "ce" ? "vault" : "vault-enterprise" | ||
"product-version" = local.artifact_version | ||
}) | ||
} |
This file contains 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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Copyright (c) HashiCorp, Inc. | ||
# SPDX-License-Identifier: BUSL-1.1 | ||
|
||
|
||
output "url" { | ||
value = data.enos_artifactory_item.vault.results[0].url | ||
description = "The artifactory download url for the artifact" | ||
} | ||
|
||
output "sha256" { | ||
value = data.enos_artifactory_item.vault.results[0].sha256 | ||
description = "The sha256 checksum for the artifact" | ||
} | ||
|
||
output "size" { | ||
value = data.enos_artifactory_item.vault.results[0].size | ||
description = "The size in bytes of the artifact" | ||
} | ||
|
||
output "name" { | ||
value = data.enos_artifactory_item.vault.results[0].name | ||
description = "The name of the artifact" | ||
} | ||
|
||
output "vault_artifactory_release" { | ||
value = { | ||
url = data.enos_artifactory_item.vault.results[0].url | ||
sha256 = data.enos_artifactory_item.vault.results[0].sha256 | ||
username = var.artifactory_username | ||
token = var.artifactory_token | ||
} | ||
} |
Oops, something went wrong.