parseSimpleSignRequest reads the HTTP-POST-SimpleSign message carried in messageParam (SAMLRequest or SAMLResponse) of the posted form of req. It returns nil and no error if the form carries neither SigAlg nor Signature, which means the message is a plain HTTP-POST binding message. req.ParseForm mus
(req *http.Request, messageParam string)
| 117 | // message that is processed cannot diverge. Both SigAlg and Signature must |
| 118 | // be present and non-empty. The signature itself is not checked. |
| 119 | func parseSimpleSignRequest(req *http.Request, messageParam string) (*simpleSignMessage, error) { |
| 120 | if !isSimpleSignRequest(req) { |
| 121 | return nil, nil |
| 122 | } |
| 123 | form := req.PostForm |
| 124 | |
| 125 | query := req.URL.Query() |
| 126 | for _, param := range simpleSignParams { |
| 127 | if len(form[param]) > 1 { |
| 128 | return nil, fmt.Errorf("form field %s appears more than once", param) |
| 129 | } |
| 130 | if _, ok := query[param]; ok { |
| 131 | return nil, fmt.Errorf("HTTP-POST-SimpleSign message must not carry %s in the URL query", param) |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | otherParam := redirectParamSAMLRequest |
| 136 | if messageParam == redirectParamSAMLRequest { |
| 137 | otherParam = redirectParamSAMLResponse |
| 138 | } |
| 139 | if _, ok := form[otherParam]; ok { |
| 140 | return nil, fmt.Errorf("form contains both %s and %s", redirectParamSAMLRequest, redirectParamSAMLResponse) |
| 141 | } |
| 142 | if _, ok := form[messageParam]; !ok { |
| 143 | return nil, fmt.Errorf("form does not contain %s", messageParam) |
| 144 | } |
| 145 | |
| 146 | m := &simpleSignMessage{ |
| 147 | MessageParam: messageParam, |
| 148 | SigAlg: form.Get(redirectParamSigAlg), |
| 149 | Signature: form.Get(redirectParamSignature), |
| 150 | KeyInfo: form.Get(simpleSignParamKeyInfo), |
| 151 | } |
| 152 | if m.SigAlg == "" || m.Signature == "" { |
| 153 | return nil, fmt.Errorf("form must contain both %s and %s, or neither", redirectParamSigAlg, redirectParamSignature) |
| 154 | } |
| 155 | _, m.HasRelayState = form[redirectParamRelayState] |
| 156 | m.RelayState = form.Get(redirectParamRelayState) |
| 157 | |
| 158 | var err error |
| 159 | m.XML, err = simpleSignBase64.DecodeString(form.Get(messageParam)) |
| 160 | if err != nil { |
| 161 | return nil, fmt.Errorf("cannot decode %s: %w", messageParam, err) |
| 162 | } |
| 163 | if len(m.XML) == 0 { |
| 164 | return nil, fmt.Errorf("%s is empty", messageParam) |
| 165 | } |
| 166 | return m, nil |
| 167 | } |
| 168 | |
| 169 | // verifySimpleSignSignature checks the SimpleSign signature of m against the |
| 170 | // IDP's signing certificates, chosen as for HTTP-Redirect binding signatures |