readSimpleSignMessage authenticates the SimpleSign message m and returns the root element of its protocol message. The SimpleSign signature is checked before the XML is parsed. If the root element also carries an enveloped XML signature, that signature must be valid as well. Errors are reported thr
(m *simpleSignMessage, retErr *InvalidResponseError)
| 236 | // |
| 237 | // Errors are reported through retErr, mirroring the other Validate* methods. |
| 238 | func (sp *ServiceProvider) readSimpleSignMessage(m *simpleSignMessage, retErr *InvalidResponseError) (*etree.Element, error) { |
| 239 | retErr.Response = string(m.XML) |
| 240 | if err := sp.verifySimpleSignSignature(m); err != nil { |
| 241 | retErr.PrivateErr = err |
| 242 | return nil, retErr |
| 243 | } |
| 244 | |
| 245 | if err := xmlroundtrip.Validate(m.XML); err != nil { |
| 246 | retErr.PrivateErr = fmt.Errorf("invalid xml: %w", err) |
| 247 | return nil, retErr |
| 248 | } |
| 249 | doc := etree.NewDocument() |
| 250 | if err := doc.ReadFromBytes(m.XML); err != nil { |
| 251 | retErr.PrivateErr = err |
| 252 | return nil, retErr |
| 253 | } |
| 254 | if doc.Root() == nil { |
| 255 | retErr.PrivateErr = errors.New("invalid xml: no root") |
| 256 | return nil, retErr |
| 257 | } |
| 258 | |
| 259 | signed, err := sp.validatedElement(doc.Root()) |
| 260 | switch { |
| 261 | case err == nil: |
| 262 | // Read the message from what the enveloped signature covers. |
| 263 | return signed, nil |
| 264 | case errors.Is(err, errSignatureElementNotPresent): |
| 265 | return doc.Root(), nil |
| 266 | default: |
| 267 | retErr.PrivateErr = err |
| 268 | return nil, retErr |
| 269 | } |
| 270 | } |
| 271 | |
| 272 | // The auto-submitting forms for the HTTP-POST-SimpleSign binding. Their |
| 273 | // <script> elements are identical to those of the HTTP-POST forms made by |
no test coverage detected