home *** CD-ROM | disk | FTP | other *** search
- package sun.net.www.protocol.http;
-
- import java.net.PasswordAuthentication;
- import java.net.URL;
- import java.security.MessageDigest;
- import java.security.NoSuchAlgorithmException;
- import java.util.Arrays;
- import sun.net.www.HeaderParser;
-
- class DigestAuthentication extends AuthenticationInfo {
- // $FF: renamed from: pw java.net.PasswordAuthentication
- private PasswordAuthentication field_0;
- private URL url;
- private String authMethod;
- private static final char[] charArray = new char[]{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
-
- public DigestAuthentication(URL var1, String var2, String var3, PasswordAuthentication var4) {
- super('s', var1.getHost(), var1.getPort(), var2);
- this.authMethod = var3;
- this.url = var1;
- this.field_0 = var4;
- }
-
- boolean supportsPreemptiveAuthorization() {
- return false;
- }
-
- String getHeaderName() {
- return "";
- }
-
- String getHeaderValue() {
- return "";
- }
-
- boolean setHeaders(HttpURLConnection var1, HeaderParser var2) {
- String var3 = var2.findValue("nonce");
- String var4 = this.url.getFile();
- if (var3 != null && this.authMethod != null && this.field_0 != null && super.realm != null) {
- if (this.authMethod.length() >= 1) {
- this.authMethod = Character.toUpperCase(this.authMethod.charAt(0)) + this.authMethod.substring(1).toLowerCase();
- }
-
- String var5 = var2.findValue("algorithm");
- if (var5 == null || "".equals(var5)) {
- var5 = "MD5";
- }
-
- char[] var7 = this.field_0.getPassword();
-
- String var6;
- label106: {
- boolean var9;
- try {
- var6 = this.computeDigest(this.field_0.getUserName(), var7, super.realm, var1.getMethod(), var4, var3, var5);
- if (var7 != null) {
- Arrays.fill(var7, ' ');
- }
-
- var7 = null;
- break label106;
- } catch (NoSuchAlgorithmException var14) {
- var9 = false;
- } finally {
- if (var7 != null) {
- Arrays.fill(var7, ' ');
- }
-
- }
-
- return var9;
- }
-
- String var8 = this.authMethod + " username=\"" + this.field_0.getUserName() + "\", realm=\"" + super.realm + "\", nonce=\"" + var3 + "\", uri=\"" + var4 + "\", response=\"" + var6 + "\"";
- var1.setAuthenticationProperty("Authorization", var8);
- return true;
- } else {
- return false;
- }
- }
-
- private String computeDigest(String var1, char[] var2, String var3, String var4, String var5, String var6, String var7) throws NoSuchAlgorithmException {
- MessageDigest var8 = MessageDigest.getInstance(var7);
- String var9 = var1 + ":" + var3 + ":";
- String var10 = this.encode(var9, var2, var8);
- String var11 = var4 + ":" + var5;
- String var12 = this.encode(var11, (char[])null, var8);
- String var13 = var10 + ":" + var6 + ":" + var12;
- String var14 = this.encode(var13, (char[])null, var8);
- return var14;
- }
-
- private String encode(String var1, char[] var2, MessageDigest var3) {
- var3.update(var1.getBytes());
- if (var2 != null) {
- byte[] var4 = new byte[var2.length];
-
- for(int var5 = 0; var5 < var2.length; ++var5) {
- var4[var5] = (byte)var2[var5];
- }
-
- var3.update(var4);
- Arrays.fill(var4, (byte)0);
- }
-
- byte[] var8 = var3.digest();
- StringBuffer var9 = new StringBuffer(var8.length * 2);
-
- for(int var6 = 0; var6 < var8.length; ++var6) {
- int var7 = var8[var6] >>> 4 & 15;
- var9.append(charArray[var7]);
- var7 = var8[var6] & 15;
- var9.append(charArray[var7]);
- }
-
- return var9.toString();
- }
- }
-