Skip to content

Instantly share code, notes, and snippets.

@linki
Created March 16, 2017 12:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save linki/d863073450bac262f9a5fe53fb9efead to your computer and use it in GitHub Desktop.
Save linki/d863073450bac262f9a5fe53fb9efead to your computer and use it in GitHub Desktop.
mock metadata server
func main() {
metadataServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
switch r.RequestURI {
case "/dynamic/instance-identity/document":
w.Write([]byte(document))
case "/dynamic/instance-identity/pkcs7":
w.Write([]byte(pkcs7))
case "/dynamic/instance-identity/signature":
w.Write([]byte(signature))
}
// w.WriteHeader(http.StatusOK)
}))
metadata := ec2metadata.New(
session.New(),
aws.NewConfig().WithEndpoint(metadataServer.URL),
)
if available := metadata.Available(); !available {
log.Fatal("metadata not available")
}
_, err := metadata.GetInstanceIdentityDocument()
if err != nil {
log.Fatal(err)
}
fixture := UnmarshalTestFixture(pkcs7_2)
p7, err := fullsailorpkcs7.Parse(fixture.Input)
if err != nil {
log.Fatal(err)
}
p7.Certificates = []*x509.Certificate{fixture.Certificate}
if err := p7.Verify(); err != nil {
log.Fatal(err)
}
fmt.Println(string(p7.Content))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment