1

always out print the same message.. what is my fault?

result message [responseCode : 401, responseMessage : Unauthorized]

//http request1

    HttpURLConnection con = (HttpURLConnection) obj.openConnection();
    con.connect();

//http response1 401 and make response

    NtrHashtable authorizationParameters = identifyAuthorization(con);

    String md1 = username + ":" + authorizationParameters.get("realm") + ":" + password;
    md5.update(md1.getBytes());
    String digestedMd1 = digest32HexDigits(md5.digest());

    String md2 = "POST" + ":" + path;
    md5.update(md2.getBytes());
    String digestedMd2 = digest32HexDigits(md5.digest());

    byte[] tmpCnonce = new byte[16];
    SecureRandom rand;
    rand = SecureRandom.getInstance("SHA1PRNG");
    rand.nextBytes(tmpCnonce);
    String cnonce = rand.getSeed(1024).toString();

    String tmpResponse = digestedMd1 + ":" + 
    authorizationParameters.get("nonce") + ":" +
         "00000001" + ":" +
         cnonce + ":" +
         authorizationParameters.get("qop") + ":" +
         digestedMd2;
    md5.update(tmpResponse.getBytes());
    String response = digest32HexDigits(md5.digest());  

//Construct Response to digest challenge

    String authorizationRequest = authorizationParameters.get("schema") + " " + 
              "username=\"" + username + "\", " +
              "realm=\"" + authorizationParameters.get("realm") + "\", " +
              "nonce=\"" + authorizationParameters.get("nonce") + "\", " +
              "uri=\"" + path + "\", " +
              "qop=\"" + authorizationParameters.get("qop") + "\", " +
              "cnonce=\"" + cnonce + "\", " +
              "nc=" + "00000001" + ", " +
              "response=\"" + response + "\", " +
              "opaque=\"" + authorizationParameters.get("opaque") + "\"";

// http request2 authorization header

    con = (HttpURLConnection) obj.openConnection();
    con.setRequestMethod("POST");
    con.setRequestProperty("authorization", authorizationRequest);

//digest32HexDigits

    private static String digest32HexDigits(byte[] digest) {
        StringBuffer digestString = new StringBuffer();
        int low, hi ;

        for(int i=0; i < digest.length; i++) {
           low = (digest[i] & 0x0f);
           hi = ((digest[i] & 0xf0)>>4);
           digestString.append(Integer.toString(hi, 16));
           digestString.append(Integer.toString(low, 16));
        }
        return digestString.toString();
     }

//System.out.println(authorizationRequest);

authorization : Digest username="changeit", realm="changeit", nonce="1384790250915:6792652dc7defc4bb2a8dd35cc5a5fd974b2b2a4002448e17310507e63ba682c", uri="/changeit/changeit/", qop="auth", cnonce="[B@1dc80063", nc=00000001, response="2bf3f7b58a0de6cc844456044e0f820f", opaque="53C20D789CFC51F65C0250C790A2F130"

i don't know.. where is my fault..

osnium76
  • 67
  • 8

0 Answers0