MCPcopy Create free account
hub / github.com/crewjam/saml / TestDecryptionErrorsIndistinguishable

Function TestDecryptionErrorsIndistinguishable

decryption_errors_test.go:29–54  ·  view source on GitHub ↗

A sender of modified CBC ciphertexts must not learn from the error whether one failed on its padding or on the XML it decrypted to.

(t *testing.T)

Source from the content-addressed store, hash-verified

27// A sender of modified CBC ciphertexts must not learn from the error whether
28// one failed on its padding or on the XML it decrypted to.
29func TestDecryptionErrorsIndistinguishable(t *testing.T) {
30 e := spcovSetup(t)
31 parse := func(encrypted *etree.Element) error {
32 el := e.response().Element()
33 el.AddChild(encrypted)
34 _, err := e.sp.ParseXMLResponse(spcovSerialize(t, el), []string{spcovRequestID}, e.sp.AcsURL)
35 return spcovPrivateErr(t, err)
36 }
37
38 plaintext := []byte("<!-- nothing -->") // 16 bytes, so 16 bytes of padding
39 badPadding := e.encryptedAssertion(t, plaintext)
40 withPaddingCount(t, badPadding, 16)
41 noRoot := e.encryptedAssertion(t, plaintext)
42 notXML := e.encryptedAssertion(t, []byte("<a>\x01</a>"))
43 unbalanced := e.encryptedAssertion(t, []byte("<a>"))
44
45 const want = "failed to decrypt EncryptedAssertion: xmlenc: decryption failed"
46 for name, el := range map[string]*etree.Element{
47 "bad padding": badPadding,
48 "no root": noRoot,
49 "not XML": notXML,
50 "unbalanced": unbalanced,
51 } {
52 assert.Check(t, is.Error(parse(el), want), name)
53 }
54}

Callers

nothing calls this directly

Calls 9

spcovSetupFunction · 0.85
spcovSerializeFunction · 0.85
spcovPrivateErrFunction · 0.85
withPaddingCountFunction · 0.85
responseMethod · 0.80
ParseXMLResponseMethod · 0.80
encryptedAssertionMethod · 0.80
ElementMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected