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) throws SAXException, IOException
23 xml_ = XmlUtil.parse(is);
26 public boolean iswriteaccess() throws SAXException
29 return xml_.getElementsByTagName("iswriteaccess").item(0)
30 .getTextContent().equals("1");
32 catch (NullPointerException e) {
33 throw new SAXException();
37 public String sid() throws SAXException
40 return Util.nonnull(xml_.getElementsByTagName("SID").item(0)
43 catch (NullPointerException e) {
44 throw new SAXException();
48 public String challenge() throws SAXException
51 return Util.nonnull(xml_.getElementsByTagName("Challenge").item(0)
54 catch (NullPointerException e) {
55 throw new SAXException();
59 public String response(String password) throws SAXException
62 String c = challenge();
63 MessageDigest md = MessageDigest.getInstance("MD5");
64 md.update((c + "-" + password).getBytes("UTF-16LE"));
66 + new HexBinaryAdapter().marshal(md.digest()).toLowerCase();
68 catch (NoSuchAlgorithmException e) {
69 throw new AssertionError("missing MD5 implementation");
71 catch (UnsupportedEncodingException e) {
72 throw new AssertionError("missing UTF-16LE encoding");