122 } |
123 } |
123 |
124 |
124 // Encode the map and send it. |
125 // Encode the map and send it. |
125 clStr := packSasl(clMap) |
126 clStr := packSasl(clMap) |
126 b64 := base64.StdEncoding |
127 b64 := base64.StdEncoding |
127 clObj := &auth{XMLName: xml.Name{Space: NsSASL, Local: "response"}, Chardata: b64.EncodeToString([]byte(clStr))} |
128 clObj := &auth{XMLName: xml.Name{Space: NsSASL, Local: "response"}, |
|
129 Chardata: b64.EncodeToString([]byte(clStr))} |
128 cl.sendXml <- clObj |
130 cl.sendXml <- clObj |
129 } |
131 } |
130 |
132 |
131 func (cl *Client) saslDigest2(srvMap map[string]string) { |
133 func (cl *Client) saslDigest2(srvMap map[string]string) { |
132 if cl.saslExpected == srvMap["rspauth"] { |
134 if cl.saslExpected == srvMap["rspauth"] { |
166 } |
168 } |
167 |
169 |
168 // Computes the response string for digest authentication. |
170 // Computes the response string for digest authentication. |
169 func saslDigestResponse(username, realm, passwd, nonce, cnonceStr, |
171 func saslDigestResponse(username, realm, passwd, nonce, cnonceStr, |
170 authenticate, digestUri, nonceCountStr string) string { |
172 authenticate, digestUri, nonceCountStr string) string { |
171 h := func(text string) []byte { |
173 h := func(text string) string { |
172 h := md5.New() |
174 h := md5.New() |
173 h.Write([]byte(text)) |
175 h.Write([]byte(text)) |
174 return h.Sum(nil) |
176 return string(h.Sum(nil)) |
175 } |
177 } |
176 hex := func(bytes []byte) string { |
178 hex := func(input string) string { |
177 return fmt.Sprintf("%x", bytes) |
179 return fmt.Sprintf("%x", input) |
178 } |
180 } |
179 kd := func(secret, data string) []byte { |
181 kd := func(secret, data string) string { |
180 return h(secret + ":" + data) |
182 return h(secret + ":" + data) |
181 } |
183 } |
182 |
184 |
183 a1 := string(h(username+":"+realm+":"+passwd)) + ":" + |
185 a1 := h(username+":"+realm+":"+passwd) + ":" + |
184 nonce + ":" + cnonceStr |
186 nonce + ":" + cnonceStr |
185 a2 := authenticate + ":" + digestUri |
187 a2 := authenticate + ":" + digestUri |
186 response := hex(kd(hex(h(a1)), nonce+":"+ |
188 response := hex(kd(hex(h(a1)), nonce+":"+ |
187 nonceCountStr+":"+cnonceStr+":auth:"+ |
189 nonceCountStr+":"+cnonceStr+":auth:"+ |
188 hex(h(a2)))) |
190 hex(h(a2)))) |