Skip to content

Commit

Permalink
Added test steps to check hash algo choice for RSA sign/verify
Browse files Browse the repository at this point in the history
  • Loading branch information
vishalnayak committed Nov 3, 2017
1 parent f245daf commit d5f001f
Showing 1 changed file with 48 additions and 1 deletion.
49 changes: 48 additions & 1 deletion builtin/logical/transit/backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,54 @@ func testTransit_RSA(t *testing.T, keyType string) {
t.Fatalf("bad: err: %v\nresp: %#v", err, resp)
}
if !resp.Data["valid"].(bool) {
t.Fatal("failed to verify the RSA signature")
t.Fatalf("failed to verify the RSA signature")
}

signReq.Data = map[string]interface{}{
"input": plaintext,
"algorithm": "invalid",
}
resp, err = b.HandleRequest(signReq)
if err != nil {
t.Fatal(err)
}
if resp == nil || !resp.IsError() {
t.Fatal("expected an error response")
}

signReq.Data = map[string]interface{}{
"input": plaintext,
"algorithm": "sha2-512",
}
resp, err = b.HandleRequest(signReq)
if err != nil || (resp != nil && resp.IsError()) {
t.Fatalf("bad: err: %v\nresp: %#v", err, resp)
}
signature = resp.Data["signature"].(string)

verifyReq.Data = map[string]interface{}{
"input": plaintext,
"signature": signature,
}
resp, err = b.HandleRequest(verifyReq)
if err != nil || (resp != nil && resp.IsError()) {
t.Fatalf("bad: err: %v\nresp: %#v", err, resp)
}
if resp.Data["valid"].(bool) {
t.Fatalf("expected validation to fail")
}

verifyReq.Data = map[string]interface{}{
"input": plaintext,
"signature": signature,
"algorithm": "sha2-512",
}
resp, err = b.HandleRequest(verifyReq)
if err != nil || (resp != nil && resp.IsError()) {
t.Fatalf("bad: err: %v\nresp: %#v", err, resp)
}
if !resp.Data["valid"].(bool) {
t.Fatalf("failed to verify the RSA signature")
}
}

Expand Down

0 comments on commit d5f001f

Please sign in to comment.