0N/A/*
2362N/A * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
1791N/Apackage sun.net.www.protocol.http.ntlm;
0N/A
0N/Aimport java.io.IOException;
0N/Aimport sun.misc.BASE64Encoder;
0N/Aimport sun.misc.BASE64Decoder;
0N/A
0N/A/*
0N/A * Hooks into Windows implementation of NTLM.
0N/A * This class will be replaced if a cross-platform version of NTLM
0N/A * is implemented in the future.
0N/A */
0N/A
0N/Apublic class NTLMAuthSequence {
0N/A
0N/A private String username;
0N/A private String password;
0N/A private String ntdomain;
0N/A private int state;
0N/A private long crdHandle;
0N/A private long ctxHandle;
0N/A
0N/A static {
5542N/A initFirst(Status.class);
0N/A }
0N/A
5542N/A // Used by native code to indicate when a particular protocol sequence is completed
5542N/A // and must not be re-used.
5542N/A
5542N/A class Status {
5542N/A boolean sequenceComplete;
5542N/A }
5542N/A
5542N/A Status status;
5542N/A
0N/A NTLMAuthSequence (String username, String password, String ntdomain)
0N/A throws IOException
0N/A {
0N/A this.username = username;
0N/A this.password = password;
0N/A this.ntdomain = ntdomain;
5542N/A this.status = new Status();
0N/A state = 0;
0N/A crdHandle = getCredentialsHandle (username, ntdomain, password);
0N/A if (crdHandle == 0) {
0N/A throw new IOException ("could not get credentials handle");
0N/A }
0N/A }
0N/A
0N/A public String getAuthHeader (String token) throws IOException {
0N/A byte[] input = null;
5542N/A
5542N/A assert !status.sequenceComplete;
5542N/A
0N/A if (token != null)
0N/A input = (new BASE64Decoder()).decodeBuffer(token);
5542N/A byte[] b = getNextToken (crdHandle, input, status);
0N/A if (b == null)
0N/A throw new IOException ("Internal authentication error");
0N/A return (new B64Encoder()).encode (b);
0N/A }
0N/A
5542N/A public boolean isComplete() {
5542N/A return status.sequenceComplete;
5542N/A }
5542N/A
5542N/A private native static void initFirst (Class<NTLMAuthSequence.Status> clazz);
0N/A
0N/A private native long getCredentialsHandle (String user, String domain, String password);
0N/A
5542N/A private native byte[] getNextToken (long crdHandle, byte[] lastToken, Status returned);
0N/A}
0N/A
0N/Aclass B64Encoder extends BASE64Encoder {
0N/A protected int bytesPerLine () {
0N/A return 1024;
0N/A }
0N/A}