1 package de.j32.avmfritz;
3 import java.io.IOException;
4 import java.io.InputStream;
5 import java.io.UnsupportedEncodingException;
6 import java.security.MessageDigest;
7 import java.security.NoSuchAlgorithmException;
9 import javax.xml.bind.annotation.adapters.HexBinaryAdapter;
11 import org.w3c.dom.Document;
12 import org.xml.sax.SAXException;
14 import de.j32.util.Util;
15 import de.j32.util.XmlUtil;
21 public LoginXML(InputStream is)
22 throws SAXException, IOException
24 xml_ = XmlUtil.parse(is);
27 public boolean iswriteaccess()
31 return xml_.getElementsByTagName("iswriteaccess").item(0).getTextContent().equals("1");
33 catch (NullPointerException e) {
34 throw new SAXException();
42 return Util.nonnull(xml_.getElementsByTagName("SID").item(0).getTextContent());
44 catch (NullPointerException e) {
45 throw new SAXException();
49 public String challenge()
53 return Util.nonnull(xml_.getElementsByTagName("Challenge").item(0).getTextContent());
55 catch (NullPointerException e) {
56 throw new SAXException();
60 public String response(String password)
64 String c = challenge();
65 MessageDigest md = MessageDigest.getInstance("MD5");
66 md.update((c + "-" + password).getBytes("UTF-16LE"));
67 return c + "-" + new HexBinaryAdapter().marshal(md.digest()).toLowerCase();
68 } catch (NoSuchAlgorithmException e) {
69 // Is it at all feasible for this to happen ?
70 throw new RuntimeException("missing MD5 implementation");
71 } catch (UnsupportedEncodingException e) {
72 throw new RuntimeException("missing UTF-16LE encoding");