ctypes-commit Mailing List for ctypes (Page 95)
Brought to you by:
theller
You can subscribe to this list here.
2004 |
Jan
|
Feb
|
Mar
|
Apr
(8) |
May
(90) |
Jun
(143) |
Jul
(106) |
Aug
(94) |
Sep
(84) |
Oct
(163) |
Nov
(60) |
Dec
(58) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2005 |
Jan
(128) |
Feb
(79) |
Mar
(227) |
Apr
(192) |
May
(179) |
Jun
(41) |
Jul
(53) |
Aug
(103) |
Sep
(28) |
Oct
(38) |
Nov
(81) |
Dec
(17) |
2006 |
Jan
(184) |
Feb
(111) |
Mar
(188) |
Apr
(67) |
May
(58) |
Jun
(123) |
Jul
(73) |
Aug
|
Sep
|
Oct
(1) |
Nov
|
Dec
|
From: Bradley L S. <bs...@us...> - 2004-08-29 01:23:23
|
Update of /cvsroot/ctypes/ctypes-java/src/java/ctypes/java/win32/sspi In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18550/src/java/ctypes/java/win32/sspi Log Message: Directory /cvsroot/ctypes/ctypes-java/src/java/ctypes/java/win32/sspi added to the repository |
From: Bradley L S. <bs...@us...> - 2004-08-29 01:21:46
|
Update of /cvsroot/ctypes/ctypes-java/src/examples/demos/petzold/chapt3 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18264/src/examples/demos/petzold/chapt3 Added Files: HelloJava.java Log Message: --- NEW FILE: HelloJava.java --- /* * HelloJava.java - * * This file is part of the Jawin Project: http://jawinproject.sourceforge.net/ * * Please consult the LICENSE file in the project root directory, * or at the project site before using this software. */ /* $Id: HelloJava.java,v 1.1 2004/08/29 01:21:33 bschatz Exp $ */ package demos.petzold.chapt3; import org.jawin.win32.DT_Constants; import org.jawin.win32.GDI32; import org.jawin.win32.MSG; import org.jawin.win32.MiscellaneousConstants; import org.jawin.win32.PAINTSTRUCT; import org.jawin.win32.RECT; import org.jawin.win32.User32; import org.jawin.win32.W32Process; import org.jawin.win32.WM_Constants; import org.jawin.win32.WNDCLASS; import org.jawin.win32.WNDPROC; import org.jawin.win32.WS_Constants; import ctypes.java.CException; import ctypes.java.CInt; import ctypes.java.CReturnable; import ctypes.java.CShort; import ctypes.java.CType; import ctypes.java.CWCharPtr; import ctypes.java.CWString; class TestWNDPROC extends WNDPROC implements WM_Constants, DT_Constants, WS_Constants, MiscellaneousConstants { public CReturnable call(CType[] args) { CInt hwnd = (CInt)args[0]; CInt msg = (CInt)args[1]; CInt wParam = (CInt)args[2]; CInt lParam = (CInt)args[3]; try { switch (msg.getValue()) { /* case WM_CREATE: PlaySound (TEXT ("hellowin.wav"), NULL, SND_FILENAME | SND_ASYNC) ; return 0 ; */ case WM_PAINT : { PAINTSTRUCT ps = new PAINTSTRUCT(); RECT rect = new RECT(); CInt hdc = User32.BeginPaint(hwnd, ps); User32.GetClientRect(hwnd, rect); User32.DrawTextW( hdc, new CWString("Hello, Java/Win32!"), new CInt(-1), rect, new CInt(DT_SINGLELINE | DT_CENTER | DT_VCENTER)); User32.EndPaint(hwnd, ps); return new CInt(0); } case WM_DESTROY : User32.PostQuitMessage(new CInt(0)); return new CInt(0); } return User32.DefWindowProcW(hwnd, msg, wParam, lParam); } catch (CException e) { //COMEBACK need some way to handle callback exceptions e.printStackTrace(); return new CInt(0); } } } /** * Port of Petzold chapter 3 to Jawin * * @version $Revision: 1.1 $ * @author Stuart Halloway, http://www.relevancellc.com/halloway/weblog/ */ public class HelloJava implements WS_Constants, MiscellaneousConstants { public static void main(String[] args) throws Exception { CInt hInst = W32Process.GetModuleHandleW(null); WNDCLASS wndclass = new WNDCLASS(); wndclass.style = new CInt(CS_HREDRAW | CS_VREDRAW); wndclass.lpfnWndProc = new TestWNDPROC(); wndclass.hIcon = User32.LoadIconW(new CInt(NULL), new CInt(IDI_APPLICATION)); wndclass.hCursor = User32.LoadCursorW(new CInt(NULL), new CInt(IDC_ARROW)); wndclass.lpszClassName = new CWCharPtr(new CWString("HelloWin")); wndclass.hbrBackground = GDI32.GetStockObject(new CInt(WHITE_BRUSH)); wndclass.hInstance = hInst; CShort atom = User32.RegisterClassW(wndclass); CInt hwnd = User32.CreateWindowExW(new CInt(0), new CWString("HelloWin"), // window class name new CWString("The Hello Program"), // window caption new CInt(WS_OVERLAPPEDWINDOW), // window style new CInt(CW_USEDEFAULT), // initial x position new CInt(CW_USEDEFAULT), // initial y position new CInt(CW_USEDEFAULT), // initial x size new CInt(CW_USEDEFAULT), // initial y size new CInt(NULL), // parent window handle new CInt(NULL), // window menu handle hInst, // program instance handle new CInt(NULL)); // creation parameters User32.ShowWindow(hwnd, new CInt(SW_SHOW)); User32.UpdateWindow(hwnd); MSG msg = new MSG(); while (User32.GetMessageW(msg, new CInt(NULL), new CInt(0), new CInt(0)).getValue() == 1) { User32.TranslateMessage(msg); User32.DispatchMessageW(msg); } } } |
From: Bradley L S. <bs...@us...> - 2004-08-29 01:21:46
|
Update of /cvsroot/ctypes/ctypes-java/src/examples/org/jawin/win32 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18264/src/examples/org/jawin/win32 Added Files: RECT.java WS_Constants.java DT_Constants.java POINT.java User32.java WNDCLASS.java GDI32.java W32Process.java MiscellaneousConstants.java WM_Constants.java WNDPROC.java PAINTSTRUCT.java MSG.java Log Message: --- NEW FILE: DT_Constants.java --- //****************************************************************** // Released under the DevelopMentor OpenSource Software License. // Please consult the LICENSE file in the project root directory, // or at http://www.develop.com for details before using this // software. //****************************************************************** package org.jawin.win32; public interface DT_Constants { public static final int DT_TOP =0x00000000; public static final int DT_LEFT =0x00000000; public static final int DT_CENTER =0x00000001; public static final int DT_RIGHT =0x00000002; public static final int DT_VCENTER =0x00000004; public static final int DT_BOTTOM =0x00000008; public static final int DT_WORDBREAK =0x00000010; public static final int DT_SINGLELINE =0x00000020; public static final int DT_EXPANDTABS =0x00000040; public static final int DT_TABSTOP =0x00000080; public static final int DT_NOCLIP =0x00000100; public static final int DT_EXTERNALLEADING =0x00000200; public static final int DT_CALCRECT =0x00000400; public static final int DT_NOPREFIX =0x00000800; public static final int DT_INTERNAL =0x00001000; } --- NEW FILE: WNDCLASS.java --- //****************************************************************** // Released under the DevelopMentor OpenSource Software License. // Please consult the LICENSE file in the project root directory, // or at http://www.develop.com for details before using this // software. //****************************************************************** package org.jawin.win32; import ctypes.java.CCallbackFunction; import ctypes.java.CInt; import ctypes.java.CStruct; import ctypes.java.CWCharPtr; public class WNDCLASS extends CStruct { public CInt style = new CInt(); public CCallbackFunction lpfnWndProc; public CInt cbClsExtra= new CInt(); public CInt cbWndExtra= new CInt(); public CInt hInstance= new CInt(); public CInt hIcon= new CInt(); public CInt hCursor= new CInt(); public CInt hbrBackground= new CInt(); public CWCharPtr lpszMenuName; public CWCharPtr lpszClassName; } --- NEW FILE: User32.java --- // ****************************************************************** // Released under the DevelopMentor OpenSource Software License. // Please consult the LICENSE file in the project root directory, // or at http://www.develop.com for details before using this // software. //****************************************************************** package org.jawin.win32; import ctypes.java.CException; import ctypes.java.CFunction; import ctypes.java.CInt; import ctypes.java.CShort; import ctypes.java.CWString; public class User32 { public static CInt LoadIconW(CInt handle, CInt iconConstant) throws CException { CFunction fp = new CFunction("USER32.DLL", "LoadIconW"); Object[] args = { handle, iconConstant }; return (CInt) fp.call(CInt.class, args, CFunction.FUNCFLAG_STDCALL); } public static CInt LoadCursorW(CInt hinst, CInt cursor) throws CException { CFunction fp = new CFunction("USER32.DLL", "LoadCursorW"); Object[] args = { hinst, cursor }; return (CInt) fp.call(CInt.class, args, CFunction.FUNCFLAG_STDCALL); } public static CInt CreateWindowExW(CInt dwExStyle, CWString lpClassName, CWString lpWindowName, CInt dwStyle, CInt X, CInt Y, CInt nWidth, CInt nHeight, CInt hWndParent, CInt hMenu, CInt hInstance, CInt lpParam) throws CException { CFunction fp = new CFunction("USER32.DLL", "CreateWindowExW"); Object[] args = { dwExStyle, lpClassName, lpWindowName, dwStyle, X, Y, nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam }; return (CInt) fp.call(CInt.class, args, CFunction.FUNCFLAG_STDCALL); } public static boolean ShowWindow(CInt hwnd, CInt nCmdShow) throws CException { CFunction fp = new CFunction("USER32.DLL", "ShowWindow"); Object[] args = { hwnd, nCmdShow }; CInt res = (CInt) fp.call(CInt.class, args, CFunction.FUNCFLAG_STDCALL); return (0 != res.getValue()); } public static void UpdateWindow(CInt hWnd) throws CException { CFunction fp = new CFunction("USER32.DLL", "UpdateWindow"); Object[] args = { hWnd }; fp.call(args, CFunction.FUNCFLAG_STDCALL); } public static CShort RegisterClassW(WNDCLASS cls) throws CException { CFunction fp = new CFunction("USER32.DLL", "RegisterClassW"); Object[] args = { cls }; return (CShort) fp.call(CShort.class, args, CFunction.FUNCFLAG_STDCALL); } public static CInt BeginPaint(CInt hwnd, PAINTSTRUCT ps) throws CException { CFunction fp = new CFunction("USER32.DLL", "BeginPaint"); Object[] args = { hwnd, ps }; return (CInt) fp.call(CInt.class, args, CFunction.FUNCFLAG_STDCALL); } public static void GetClientRect(CInt hwnd, RECT r) throws CException { CFunction fp = new CFunction("USER32.DLL", "GetClientRect"); Object[] args = { hwnd, r }; fp.call(args, CFunction.FUNCFLAG_STDCALL); } public static CInt DrawTextW(CInt hwnd, CWString lpString, CInt nCount, RECT lpRect, CInt nFormat) throws CException { CFunction fp = new CFunction("USER32.DLL", "DrawTextW"); Object[] args = { hwnd, lpString, nCount, lpRect, nFormat }; return (CInt) fp.call(CInt.class, args, CFunction.FUNCFLAG_STDCALL); } public static void EndPaint(CInt hwnd, PAINTSTRUCT ps) throws CException { CFunction fp = new CFunction("USER32.DLL", "EndPaint"); Object[] args = { hwnd, ps }; fp.call(args, CFunction.FUNCFLAG_STDCALL); } public static void PostQuitMessage(CInt nExitCode) throws CException { CFunction fp = new CFunction("USER32.DLL", "PostQuitMessage"); Object[] args = { nExitCode }; fp.call(args, CFunction.FUNCFLAG_STDCALL); } public static CInt DefWindowProcW(CInt hwnd, CInt msg, CInt wParam, CInt lParam) throws CException { CFunction fp = new CFunction("USER32.DLL", "DefWindowProcW"); Object[] args = { hwnd, msg, wParam, lParam }; return (CInt) fp.call(CInt.class, args, CFunction.FUNCFLAG_STDCALL); } public static CInt GetMessageW(MSG msg, CInt hWnd, CInt wMsgFilterMin, CInt wMsgFilterMax) throws CException { CFunction fp = new CFunction("USER32.DLL", "GetMessageW"); Object[] args = { msg, hWnd, wMsgFilterMin, wMsgFilterMax }; return (CInt) fp.call(CInt.class, args, CFunction.FUNCFLAG_STDCALL); } public static CInt TranslateMessage(MSG msg) throws CException { CFunction fp = new CFunction("USER32.DLL", "TranslateMessage"); Object[] args = { msg }; return (CInt) fp.call(CInt.class, args, CFunction.FUNCFLAG_STDCALL); } public static CInt DispatchMessageW(MSG msg) throws CException { CFunction fp = new CFunction("USER32.DLL", "DispatchMessageW"); Object[] args = { msg }; return (CInt) fp.call(CInt.class, args, CFunction.FUNCFLAG_STDCALL); } } --- NEW FILE: WNDPROC.java --- //****************************************************************** // Released under the DevelopMentor OpenSource Software License. // Please consult the LICENSE file in the project root directory, // or at http://www.develop.com for details before using this // software. //****************************************************************** package org.jawin.win32; import ctypes.java.CCallbackFunction; import ctypes.java.CInt; public abstract class WNDPROC extends CCallbackFunction { public Class getResultType() { return CInt.class; } // declare the type of the parameters for the callback public Class[] getConverters() { Class[] converters = { CInt.class, CInt.class, CInt.class, CInt.class }; return converters; } } --- NEW FILE: MSG.java --- //****************************************************************** // Released under the DevelopMentor OpenSource Software License. // Please consult the LICENSE file in the project root directory, // or at http://www.develop.com for details before using this // software. //****************************************************************** package org.jawin.win32; import ctypes.java.CInt; import ctypes.java.CStruct; public class MSG extends CStruct{ public CInt hwnd= new CInt(); public CInt message= new CInt(); public CInt wParam= new CInt(); public CInt lParam= new CInt(); public CInt time= new CInt(); public POINT pt = new POINT(); } --- NEW FILE: RECT.java --- // ****************************************************************** // Released under the DevelopMentor OpenSource Software License. // Please consult the LICENSE file in the project root directory, // or at http://www.develop.com for details before using this // software. //****************************************************************** package org.jawin.win32; import ctypes.java.CInt; import ctypes.java.CStruct; public class RECT extends CStruct { public CInt left; public CInt top; public CInt right; public CInt bottom; } --- NEW FILE: PAINTSTRUCT.java --- //****************************************************************** // Released under the DevelopMentor OpenSource Software License. // Please consult the LICENSE file in the project root directory, // or at http://www.develop.com for details before using this // software. //****************************************************************** package org.jawin.win32; import ctypes.java.CBuffer; import ctypes.java.CInt; import ctypes.java.CStruct; public class PAINTSTRUCT extends CStruct { public CInt hdc; public CInt fErase; public RECT rcPaint = new RECT(); public CInt fRestore; public CInt fIncUpdate; public CBuffer rgbReserved = new CBuffer(32); } --- NEW FILE: POINT.java --- //****************************************************************** // Released under the DevelopMentor OpenSource Software License. // Please consult the LICENSE file in the project root directory, // or at http://www.develop.com for details before using this // software. //****************************************************************** package org.jawin.win32; import ctypes.java.CInt; import ctypes.java.CStruct; public class POINT extends CStruct { public CInt x= new CInt(); public CInt y= new CInt(); } --- NEW FILE: GDI32.java --- //****************************************************************** // Released under the DevelopMentor OpenSource Software License. // Please consult the LICENSE file in the project root directory, // or at http://www.develop.com for details before using this // software. //****************************************************************** package org.jawin.win32; import ctypes.java.CException; import ctypes.java.CFunction; import ctypes.java.CInt; public class GDI32 { public static CInt GetStockObject(CInt object) throws CException { CFunction fp = new CFunction("GDI32.DLL", "GetStockObject"); Object[] args = { object }; return (CInt) fp.call(CInt.class, args, CFunction.FUNCFLAG_STDCALL); } } --- NEW FILE: W32Process.java --- //****************************************************************** // Released under the DevelopMentor OpenSource Software License. // Please consult the LICENSE file in the project root directory, // or at http://www.develop.com for details before using this // software. //****************************************************************** package org.jawin.win32; import ctypes.java.CException; import ctypes.java.CFunction; import ctypes.java.CInt; import ctypes.java.CWString; public class W32Process { //avoid conflict with java.lang.Process public static CInt GetCurrentProcess() throws CException { CFunction fp = new CFunction("KERNEL32.DLL", "GetCurrentProcess"); return (CInt) fp.call(null, CFunction.FUNCFLAG_STDCALL); } public static CInt GetModuleHandleW(CWString lpModuleName) throws CException { CFunction fp = new CFunction("KERNEL32.DLL", "GetModuleHandleW"); Object[] args = { lpModuleName }; return (CInt) fp.call(CInt.class, args, CFunction.FUNCFLAG_STDCALL); } } --- NEW FILE: WM_Constants.java --- //****************************************************************** // Released under the DevelopMentor OpenSource Software License. // Please consult the LICENSE file in the project root directory, // or at http://www.develop.com for details before using this // software. //****************************************************************** package org.jawin.win32; public interface WM_Constants { public final static int WM_NULL =0x0000; public final static int WM_CREATE =0x0001; public final static int WM_DESTROY =0x0002; public final static int WM_MOVE =0x0003; public final static int WM_SIZE =0x0005; public final static int WM_ACTIVATE =0x0006; public final static int WM_SETFOCUS =0x0007; public final static int WM_KILLFOCUS =0x0008; public final static int WM_ENABLE =0x000A; public final static int WM_SETREDRAW =0x000B; public final static int WM_SETTEXT =0x000C; public final static int WM_GETTEXT =0x000D; public final static int WM_GETTEXTLENGTH =0x000E; public final static int WM_PAINT =0x000F; public final static int WM_CLOSE =0x0010; public final static int WM_QUERYENDSESSION =0x0011; public final static int WM_QUIT =0x0012; public final static int WM_QUERYOPEN =0x0013; public final static int WM_ERASEBKGND =0x0014; public final static int WM_SYSCOLORCHANGE =0x0015; public final static int WM_ENDSESSION =0x0016; public final static int WM_SHOWWINDOW =0x0018; public final static int WM_WININICHANGE =0x001A; } --- NEW FILE: MiscellaneousConstants.java --- //****************************************************************** // Released under the DevelopMentor OpenSource Software License. // Please consult the LICENSE file in the project root directory, // or at http://www.develop.com for details before using this // software. //****************************************************************** package org.jawin.win32; /** * constants that I haven't gotten around to declaring * with their siblings */ public interface MiscellaneousConstants { public static final int NULL = 0; public static final int IDI_APPLICATION = 32512; public static final int IDC_ARROW = 32512; public static final int CS_VREDRAW = 0x0001; public static final int CS_HREDRAW = 0x0002; public static final int WHITE_BRUSH = 0; public static final int CW_USEDEFAULT = 0x80000000; public static final int SW_SHOW = 5; } --- NEW FILE: WS_Constants.java --- //****************************************************************** // Released under the DevelopMentor OpenSource Software License. // Please consult the LICENSE file in the project root directory, // or at http://www.develop.com for details before using this // software. //****************************************************************** package org.jawin.win32; public interface WS_Constants { public static final int WS_OVERLAPPED = 0x00000000; public static final int WS_POPUP = 0x80000000; public static final int WS_CHILD = 0x40000000; public static final int WS_MINIMIZE = 0x20000000; public static final int WS_VISIBLE = 0x10000000; public static final int WS_DISABLED = 0x08000000; public static final int WS_CLIPSIBLINGS = 0x04000000; public static final int WS_CLIPCHILDREN = 0x02000000; public static final int WS_MAXIMIZE = 0x01000000; public static final int WS_CAPTION = 0x00C00000; /* WS_BORDER | WS_DLGFRAME */ public static final int WS_BORDER = 0x00800000; public static final int WS_DLGFRAME = 0x00400000; public static final int WS_VSCROLL = 0x00200000; public static final int WS_HSCROLL = 0x00100000; public static final int WS_SYSMENU = 0x00080000; public static final int WS_THICKFRAME = 0x00040000; public static final int WS_GROUP = 0x00020000; public static final int WS_TABSTOP = 0x00010000; public static final int WS_MINIMIZEBOX = 0x00020000; public static final int WS_MAXIMIZEBOX = 0x00010000; public static final int WS_OVERLAPPEDWINDOW = (WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX); } |
From: Bradley L S. <bs...@us...> - 2004-08-29 01:21:41
|
Update of /cvsroot/ctypes/ctypes-java/src/examples/org In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18199/src/examples/org Log Message: Directory /cvsroot/ctypes/ctypes-java/src/examples/org added to the repository |
From: Bradley L S. <bs...@us...> - 2004-08-29 01:21:41
|
Update of /cvsroot/ctypes/ctypes-java/src/examples/demos/petzold/chapt3 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18199/src/examples/demos/petzold/chapt3 Log Message: Directory /cvsroot/ctypes/ctypes-java/src/examples/demos/petzold/chapt3 added to the repository |
From: Bradley L S. <bs...@us...> - 2004-08-29 01:21:41
|
Update of /cvsroot/ctypes/ctypes-java/src/examples/demos In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18199/src/examples/demos Log Message: Directory /cvsroot/ctypes/ctypes-java/src/examples/demos added to the repository |
From: Bradley L S. <bs...@us...> - 2004-08-29 01:21:41
|
Update of /cvsroot/ctypes/ctypes-java/src/examples/org/jawin In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18199/src/examples/org/jawin Log Message: Directory /cvsroot/ctypes/ctypes-java/src/examples/org/jawin added to the repository |
From: Bradley L S. <bs...@us...> - 2004-08-29 01:21:40
|
Update of /cvsroot/ctypes/ctypes-java/src/examples/org/jawin/win32 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18199/src/examples/org/jawin/win32 Log Message: Directory /cvsroot/ctypes/ctypes-java/src/examples/org/jawin/win32 added to the repository |
From: Bradley L S. <bs...@us...> - 2004-08-29 01:21:38
|
Update of /cvsroot/ctypes/ctypes-java/src/examples/demos/petzold In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18199/src/examples/demos/petzold Log Message: Directory /cvsroot/ctypes/ctypes-java/src/examples/demos/petzold added to the repository |
From: Bradley L S. <bs...@us...> - 2004-08-29 01:21:06
|
Update of /cvsroot/ctypes/ctypes-java/src/examples/ctypes/java/ntlm/httpauth In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18108/src/examples/ctypes/java/ntlm/httpauth Added Files: HTTPAuthA.java NTLMAuthenticator.java HTTPAuth.java HTTPSProxyAuthA.java NTLMSecurityException.java HTTPProxyAuth.java HTTPSProxyAuth.java Log Message: --- NEW FILE: NTLMSecurityException.java --- /* * Created on 24/07/2003 * */ package ctypes.java.ntlm.httpauth; import ctypes.java.CException; /** * @author Bradley Schatz * * Copyright 2003 */ public class NTLMSecurityException extends CException { public NTLMSecurityException() { super(); } public NTLMSecurityException(String arg0) { super(arg0); } /** * @param arg0 * @param arg1 */ public NTLMSecurityException(String arg0, Throwable arg1) { super(arg0, arg1); // TODO Auto-generated constructor stub } /** * @param arg0 */ public NTLMSecurityException(Throwable arg0) { super(arg0); // TODO Auto-generated constructor stub } } --- NEW FILE: HTTPSProxyAuthA.java --- /* * Created on 22/07/2003 * */ package ctypes.java.ntlm.httpauth; import java.io.DataInputStream; import java.io.DataOutputStream; import java.net.Socket; import org.apache.commons.codec.binary.Base64; import org.apache.commons.httpclient.Header; import org.apache.commons.httpclient.HttpParser; import org.apache.commons.httpclient.StatusLine; import ctypes.java.CBuffer; import ctypes.java.CException; import ctypes.java.CString; import ctypes.java.CULong; import ctypes.java.win32.NTStatus; import ctypes.java.win32.WinError; import ctypes.java.win32.sspi.CredHandle; import ctypes.java.win32.sspi.CtxtHandle; import ctypes.java.win32.sspi.PSecPkgInfoA; import ctypes.java.win32.sspi.SSPI; import ctypes.java.win32.sspi.SecBuffer; import ctypes.java.win32.sspi.SecBufferDesc; import ctypes.java.win32.sspi.SecPkgInfoA; import ctypes.java.win32.sspi.TimeStamp; /** * @author Bradley Schatz * * Copyright 2003 Managed Data Security */ public class HTTPSProxyAuthA { int maxTokenSize = -1; CtxtHandle securityContext = null; public HTTPSProxyAuthA() { try { Socket s = new Socket("sbs1", 8443); DataOutputStream os = new DataOutputStream(s.getOutputStream()); os.writeBytes("CONNECT fastmail.fm:443 HTTP/1.0\r\n"); os.writeBytes("User-Agent: Foo\r\n"); os.writeBytes("Host: fastmail.fm\r\n"); os.writeBytes("Content-Length: 0\r\n"); os.writeBytes("Proxy-Connection: Keep-Alive\r\n"); os.writeBytes("Pragma: no-cache\r\n\r\n"); DataInputStream is = new DataInputStream(s.getInputStream()); int status = new StatusLine(is.readLine()).getStatusCode(); if (status != 407) { return; } boolean wantsNTLMAuth = false; int contentLen = 0; Header[] headers = HttpParser.parseHeaders(is); for (int i = 0; i < headers.length; i++) { Header h = headers[i]; if (h.getName().equals("Proxy-Authenticate")) { if (h.getValue().startsWith("NTLM")) { wantsNTLMAuth = true; } } else if (headers[i].getName().equals("Content-Length")) { contentLen = Integer.parseInt(headers[i].getValue()); } } for (int i = 0; i < contentLen; i++) { System.out.print(is.readByte()); } if (!wantsNTLMAuth) { return; } //byte[] b = createType1Message(); NTLMAuthenticator au = new NTLMAuthenticator(); byte[] b = au.createType1Message(); b = Base64.encodeBase64(b); os.writeBytes("CONNECT fastmail.fm:443 HTTP/1.0\r\n"); os.writeBytes("User-Agent: Foo\r\n"); os.writeBytes("Host: fastmail.fm\r\n"); os.writeBytes("Content-Length: 0\r\n"); os.writeBytes("Proxy-Connection: Keep-Alive\r\n"); os.writeBytes("Pragma: no-cache\r\n"); os.writeBytes("Proxy-Authorization: NTLM "); os.write(b); os.writeBytes("\r\n\r\n"); is = new DataInputStream(s.getInputStream()); status = new StatusLine(is.readLine()).getStatusCode(); if (status != 407) { return; } headers = HttpParser.parseHeaders(is); String responseToken = null; contentLen = 0; for (int i = 0; i < headers.length; i++) { Header h = headers[i]; System.out.println(h.toExternalForm()); if (h.getName().equals("Proxy-Authenticate")) { String value = h.getValue(); System.out.println(value); responseToken = value.substring("NTLM ".length()); } else if (h.getName().equals("Content-Length")) { contentLen = Integer.parseInt(h.getValue()); } } for (int i = 0; i < contentLen; i++) { is.readByte(); } if (responseToken == null) { return; } byte[] intoken = Base64.decodeBase64(responseToken.getBytes()); b = au.createType3Message(intoken); b = Base64.encodeBase64(b); os.writeBytes("CONNECT fastmail.fm:443 HTTP/1.0\r\n"); os.writeBytes("User-Agent: Foo\r\n"); os.writeBytes("Host: fastmail.fm\r\n"); os.writeBytes("Content-Length: 0\r\n"); os.writeBytes("Proxy-Connection: Keep-Alive\r\n"); os.writeBytes("Pragma: no-cache\r\n"); os.writeBytes("Proxy-Authorization: NTLM "); os.write(b); os.writeBytes("\r\n\r\n"); is = new DataInputStream(s.getInputStream()); status = new StatusLine(is.readLine()).getStatusCode(); if (status != 200) { return; } contentLen = -1; headers = HttpParser.parseHeaders(is); for (int i = 0; i < headers.length; i++) { System.err.println(headers[i].toExternalForm()); if (headers[i].getName().equals("Content-Length")) { contentLen = Integer.parseInt(headers[i].getValue()); } } for (int i = 0; i < contentLen; i++) { System.out.print(is.readByte()); } } catch (Exception e) { e.printStackTrace(); } } public static void main(String[] args) { HTTPSProxyAuthA a = new HTTPSProxyAuthA(); } public boolean SEC_SUCCESS(long ret) { if (ret >= 0) return true; return false; } public byte[] createType1Message() throws NTLMSecurityException { try { CredHandle credential = new CredHandle(); TimeStamp ptsExpiry = new TimeStamp(); System.out.println(credential.toString()); long ss = SSPI.AcquireCredentialsHandleA( null, new CString("NTLM"), new CULong(SSPI.SECPKG_CRED_OUTBOUND), null, null, null, null, credential, ptsExpiry); credential.dump(0); System.out.println(ptsExpiry.toString()); if (ss != NTStatus.STATUS_SUCCESS) { throw new NTLMSecurityException("Failed acquiring credentials handle"); } PSecPkgInfoA pskg = new PSecPkgInfoA(); ss = SSPI.QuerySecurityPackageInfoA(new CString("NTLM"), pskg); if (ss != NTStatus.STATUS_SUCCESS) { throw new NTLMSecurityException("Failed querying security package info"); } pskg.dump(0); SecPkgInfoA secpkginfo = (SecPkgInfoA) pskg.getSubject(); CBuffer buff = new CBuffer((int) secpkginfo.cbMaxToken.getValue()); SecBufferDesc OutBuffDesc = new SecBufferDesc(); SecBuffer OutSecBuff = new SecBuffer(); OutBuffDesc.ulVersion.setValue(0); OutBuffDesc.cBuffers.setValue(1); OutBuffDesc.pBuffers.setSubject(OutSecBuff); maxTokenSize = (int) secpkginfo.cbMaxToken.getValue(); OutSecBuff.cbBuffer.setValue(maxTokenSize); OutSecBuff.BufferType.setValue(SSPI.SECBUFFER_TOKEN); OutSecBuff.pvBuffer.setSubject(buff); securityContext = new CtxtHandle(); CULong ContextAttributes = new CULong(); ss = SSPI.InitializeSecurityContextA( credential, null, new CString("InetSvcs"), new CULong(0), new CULong(0), new CULong(SSPI.SECURITY_NATIVE_DREP), null, new CULong(0), securityContext, OutBuffDesc, ContextAttributes, ptsExpiry); if (!SEC_SUCCESS(ss)) { if (ss == WinError.SEC_E_LOGON_DENIED) { throw new NTLMSecurityException("Logon Denied"); } throw new NTLMSecurityException("Indeterminate exception"); } OutBuffDesc.dump(0); if ((ss == WinError.SEC_I_COMPLETE_NEEDED) || (ss == WinError.SEC_I_COMPLETE_AND_CONTINUE)) { ss = SSPI.CompleteAuthToken(securityContext, OutBuffDesc); if (!SEC_SUCCESS(ss)) { throw new NTLMSecurityException("Failed Completing Auth token"); } } long len = OutSecBuff.cbBuffer.getValue(); CBuffer buf = (CBuffer) OutSecBuff.pvBuffer.getSubject(); byte[] b = new byte[(int) len]; System.arraycopy(buf.getData(), 0, b, 0, (int) len); return b; } catch (CException e) { throw new NTLMSecurityException(e); } } byte[] createType3Message(byte[] serverTicket) throws NTLMSecurityException { try { SecBufferDesc OutBuffDesc = new SecBufferDesc(); SecBuffer OutSecBuff = new SecBuffer(); OutBuffDesc.ulVersion.setValue(0); OutBuffDesc.cBuffers.setValue(1); OutBuffDesc.pBuffers.setSubject(OutSecBuff); CBuffer buff = new CBuffer(maxTokenSize); OutSecBuff.cbBuffer.setValue(maxTokenSize); OutSecBuff.BufferType.setValue(SSPI.SECBUFFER_TOKEN); OutSecBuff.pvBuffer.setSubject(buff); SecBufferDesc InBuffDesc = new SecBufferDesc(); SecBuffer InSecBuff = new SecBuffer(); CBuffer pBuffIn = new CBuffer(maxTokenSize); pBuffIn.setData(serverTicket); InBuffDesc.ulVersion.setValue(0); InBuffDesc.cBuffers.setValue(1); InBuffDesc.pBuffers.setSubject(InSecBuff); InSecBuff.cbBuffer.setValue(serverTicket.length); InSecBuff.BufferType.setValue(SSPI.SECBUFFER_TOKEN); InSecBuff.pvBuffer.setSubject(pBuffIn); System.err.println("Second call to initsecuritycontext"); TimeStamp ptsExpiry = new TimeStamp(); CULong ContextAttributes = new CULong(); securityContext.dump(0); long ss = SSPI.InitializeSecurityContextA( null, securityContext, new CString("InetSvcs"), new CULong(0), new CULong(0), new CULong(SSPI.SECURITY_NATIVE_DREP), InBuffDesc, new CULong(0), securityContext, OutBuffDesc, ContextAttributes, ptsExpiry); if (!SEC_SUCCESS(ss)) { if (ss == WinError.SEC_E_LOGON_DENIED) { throw new NTLMSecurityException("Denied by server"); } throw new NTLMSecurityException("Denied by server"); } long len = OutSecBuff.cbBuffer.getValue(); CBuffer buf = (CBuffer) OutSecBuff.pvBuffer.getSubject(); byte[] b = new byte[(int) len]; System.arraycopy(buf.getData(), 0, b, 0, (int) len); return b; } catch (CException e) { throw new NTLMSecurityException(e); } } } --- NEW FILE: HTTPSProxyAuth.java --- /* * Created on 22/07/2003 * */ package ctypes.java.ntlm.httpauth; import java.io.DataInputStream; import java.io.DataOutputStream; import java.net.Socket; import org.apache.commons.codec.binary.Base64; import org.apache.commons.httpclient.Header; import org.apache.commons.httpclient.HttpParser; import org.apache.commons.httpclient.StatusLine; import ctypes.java.CBuffer; import ctypes.java.CException; import ctypes.java.CString; import ctypes.java.CULong; import ctypes.java.win32.NTStatus; import ctypes.java.win32.WinError; import ctypes.java.win32.sspi.CredHandle; import ctypes.java.win32.sspi.CtxtHandle; import ctypes.java.win32.sspi.PSecPkgInfoA; import ctypes.java.win32.sspi.SSPI; import ctypes.java.win32.sspi.SecBuffer; import ctypes.java.win32.sspi.SecBufferDesc; import ctypes.java.win32.sspi.SecPkgInfoA; import ctypes.java.win32.sspi.TimeStamp; /** * @author Bradley Schatz * * Copyright 2003 Managed Data Security */ public class HTTPSProxyAuth { int maxTokenSize = -1; CtxtHandle securityContext = null; public HTTPSProxyAuth() { try { Socket s = new Socket("sbs1", 8443); DataOutputStream os = new DataOutputStream(s.getOutputStream()); os.writeBytes("CONNECT fastmail.fm:443 HTTP/1.0\r\n"); os.writeBytes("User-Agent: Foo\r\n"); os.writeBytes("Host: fastmail.fm\r\n"); os.writeBytes("Content-Length: 0\r\n"); os.writeBytes("Proxy-Connection: Keep-Alive\r\n"); os.writeBytes("Pragma: no-cache\r\n\r\n"); DataInputStream is = new DataInputStream(s.getInputStream()); int status = new StatusLine(is.readLine()).getStatusCode(); if (status != 407) { return; } boolean wantsNTLMAuth = false; int contentLen = 0; Header[] headers = HttpParser.parseHeaders(is); for (int i = 0; i < headers.length; i++) { Header h = headers[i]; if (h.getName().equals("Proxy-Authenticate")) { if (h.getValue().startsWith("NTLM")) { wantsNTLMAuth = true; } } else if (headers[i].getName().equals("Content-Length")) { contentLen = Integer.parseInt(headers[i].getValue()); } } for (int i = 0; i < contentLen; i++) { System.out.print(is.readByte()); } if (!wantsNTLMAuth) { return; } byte[] b = createType1Message(); b = Base64.encodeBase64(b); os.writeBytes("CONNECT fastmail.fm:443 HTTP/1.0\r\n"); os.writeBytes("User-Agent: Foo\r\n"); os.writeBytes("Host: fastmail.fm\r\n"); os.writeBytes("Content-Length: 0\r\n"); os.writeBytes("Proxy-Connection: Keep-Alive\r\n"); os.writeBytes("Pragma: no-cache\r\n"); os.writeBytes("Proxy-Authorization: NTLM "); os.write(b); os.writeBytes("\r\n\r\n"); is = new DataInputStream(s.getInputStream()); status = new StatusLine(is.readLine()).getStatusCode(); if (status != 407) { return; } headers = HttpParser.parseHeaders(is); String responseToken = null; contentLen = 0; for (int i = 0; i < headers.length; i++) { Header h = headers[i]; System.out.println(h.toExternalForm()); if (h.getName().equals("Proxy-Authenticate")) { String value = h.getValue(); System.out.println(value); responseToken = value.substring("NTLM ".length()); } else if (h.getName().equals("Content-Length")) { contentLen = Integer.parseInt(h.getValue()); } } for (int i = 0; i < contentLen; i++) { is.readByte(); } if (responseToken == null) { return; } byte[] intoken = Base64.decodeBase64(responseToken.getBytes()); b = createType3Message(intoken); b = Base64.encodeBase64(b); os.writeBytes("CONNECT fastmail.fm:443 HTTP/1.0\r\n"); os.writeBytes("User-Agent: Foo\r\n"); os.writeBytes("Host: fastmail.fm\r\n"); os.writeBytes("Content-Length: 0\r\n"); os.writeBytes("Proxy-Connection: Keep-Alive\r\n"); os.writeBytes("Pragma: no-cache\r\n"); os.writeBytes("Proxy-Authorization: NTLM "); os.write(b); os.writeBytes("\r\n\r\n"); is = new DataInputStream(s.getInputStream()); status = new StatusLine(is.readLine()).getStatusCode(); if (status != 200) { return; } contentLen = -1; headers = HttpParser.parseHeaders(is); for (int i = 0; i < headers.length; i++) { System.err.println(headers[i].toExternalForm()); if (headers[i].getName().equals("Content-Length")) { contentLen = Integer.parseInt(headers[i].getValue()); } } for (int i = 0; i < contentLen; i++) { System.out.print(is.readByte()); } } catch (Exception e) { e.printStackTrace(); } } public static void main(String[] args) { HTTPSProxyAuth a = new HTTPSProxyAuth(); } public boolean SEC_SUCCESS(long ret) { if (ret >= 0) return true; return false; } public byte[] createType1Message() throws NTLMSecurityException { try { CredHandle credential = new CredHandle(); TimeStamp ptsExpiry = new TimeStamp(); System.out.println(credential.toString()); long ss = SSPI.AcquireCredentialsHandleA( null, new CString("NTLM"), new CULong(SSPI.SECPKG_CRED_OUTBOUND), null, null, null, null, credential, ptsExpiry); credential.dump(0); System.out.println(ptsExpiry.toString()); if (ss != NTStatus.STATUS_SUCCESS) { throw new NTLMSecurityException("Failed acquiring credentials handle"); } PSecPkgInfoA pskg = new PSecPkgInfoA(); ss = SSPI.QuerySecurityPackageInfoA(new CString("NTLM"), pskg); if (ss != NTStatus.STATUS_SUCCESS) { throw new NTLMSecurityException("Failed querying security package info"); } pskg.dump(0); SecPkgInfoA secpkginfo = (SecPkgInfoA) pskg.getSubject(); CBuffer buff = new CBuffer((int) secpkginfo.cbMaxToken.getValue()); SecBufferDesc OutBuffDesc = new SecBufferDesc(); SecBuffer OutSecBuff = new SecBuffer(); OutBuffDesc.ulVersion.setValue(0); OutBuffDesc.cBuffers.setValue(1); OutBuffDesc.pBuffers.setSubject(OutSecBuff); maxTokenSize = (int) secpkginfo.cbMaxToken.getValue(); OutSecBuff.cbBuffer.setValue(maxTokenSize); OutSecBuff.BufferType.setValue(SSPI.SECBUFFER_TOKEN); OutSecBuff.pvBuffer.setSubject(buff); securityContext = new CtxtHandle(); CULong ContextAttributes = new CULong(); ss = SSPI.InitializeSecurityContextA( credential, null, new CString("InetSvcs"), new CULong(0), new CULong(0), new CULong(SSPI.SECURITY_NATIVE_DREP), null, new CULong(0), securityContext, OutBuffDesc, ContextAttributes, ptsExpiry); if (!SEC_SUCCESS(ss)) { if (ss == WinError.SEC_E_LOGON_DENIED) { throw new NTLMSecurityException("Logon Denied"); } throw new NTLMSecurityException("Indeterminate exception"); } OutBuffDesc.dump(0); if ((ss == WinError.SEC_I_COMPLETE_NEEDED) || (ss == WinError.SEC_I_COMPLETE_AND_CONTINUE)) { ss = SSPI.CompleteAuthToken(securityContext, OutBuffDesc); if (!SEC_SUCCESS(ss)) { throw new NTLMSecurityException("Failed Completing Auth token"); } } long len = OutSecBuff.cbBuffer.getValue(); CBuffer buf = (CBuffer) OutSecBuff.pvBuffer.getSubject(); byte[] b = new byte[(int) len]; System.arraycopy(buf.getData(), 0, b, 0, (int) len); return b; } catch (CException e) { throw new NTLMSecurityException(e); } } byte[] createType3Message(byte[] serverTicket) throws NTLMSecurityException { try { SecBufferDesc OutBuffDesc = new SecBufferDesc(); SecBuffer OutSecBuff = new SecBuffer(); OutBuffDesc.ulVersion.setValue(0); OutBuffDesc.cBuffers.setValue(1); OutBuffDesc.pBuffers.setSubject(OutSecBuff); CBuffer buff = new CBuffer(maxTokenSize); OutSecBuff.cbBuffer.setValue(maxTokenSize); OutSecBuff.BufferType.setValue(SSPI.SECBUFFER_TOKEN); OutSecBuff.pvBuffer.setSubject(buff); SecBufferDesc InBuffDesc = new SecBufferDesc(); SecBuffer InSecBuff = new SecBuffer(); CBuffer pBuffIn = new CBuffer(maxTokenSize); pBuffIn.setData(serverTicket); InBuffDesc.ulVersion.setValue(0); InBuffDesc.cBuffers.setValue(1); InBuffDesc.pBuffers.setSubject(InSecBuff); InSecBuff.cbBuffer.setValue(serverTicket.length); InSecBuff.BufferType.setValue(SSPI.SECBUFFER_TOKEN); InSecBuff.pvBuffer.setSubject(pBuffIn); System.err.println("Second call to initsecuritycontext"); TimeStamp ptsExpiry = new TimeStamp(); CULong ContextAttributes = new CULong(); securityContext.dump(0); long ss = SSPI.InitializeSecurityContextA( null, securityContext, new CString("InetSvcs"), new CULong(0), new CULong(0), new CULong(SSPI.SECURITY_NATIVE_DREP), InBuffDesc, new CULong(0), securityContext, OutBuffDesc, ContextAttributes, ptsExpiry); if (!SEC_SUCCESS(ss)) { if (ss == WinError.SEC_E_LOGON_DENIED) { throw new NTLMSecurityException("Denied by server"); } throw new NTLMSecurityException("Denied by server"); } long len = OutSecBuff.cbBuffer.getValue(); CBuffer buf = (CBuffer) OutSecBuff.pvBuffer.getSubject(); byte[] b = new byte[(int) len]; System.arraycopy(buf.getData(), 0, b, 0, (int) len); return b; } catch (CException e) { throw new NTLMSecurityException(e); } } } --- NEW FILE: HTTPAuthA.java --- /* * Created on 22/07/2003 * */ package ctypes.java.ntlm.httpauth; import java.io.DataInputStream; import java.io.DataOutputStream; import java.net.Socket; import ctypes.java.CBuffer; import ctypes.java.CException; import ctypes.java.CString; import ctypes.java.CULong; import ctypes.java.win32.NTStatus; import ctypes.java.win32.WinError; import ctypes.java.win32.sspi.CredHandle; import ctypes.java.win32.sspi.CtxtHandle; import ctypes.java.win32.sspi.PSecPkgInfoA; import ctypes.java.win32.sspi.SSPI; import ctypes.java.win32.sspi.SecBuffer; import ctypes.java.win32.sspi.SecBufferDesc; import ctypes.java.win32.sspi.SecPkgInfoA; import ctypes.java.win32.sspi.TimeStamp; import org.apache.commons.codec.binary.Base64; import org.apache.commons.httpclient.Header; import org.apache.commons.httpclient.HttpParser; import org.apache.commons.httpclient.StatusLine; /** * @author Bradley Schatz * * Copyright 2003 Managed Data Security */ public class HTTPAuthA { int maxTokenSize = -1; CtxtHandle securityContext = null; public HTTPAuthA() { try { Socket s = new Socket("papasmurf", 80); DataOutputStream os = new DataOutputStream(s.getOutputStream()); os.writeBytes("GET /protected/index.htm HTTP/1.0\r\n"); os.writeBytes("User-Agent: Foo\r\n"); os.writeBytes("Accept: */*\r\n\r\n"); DataInputStream is = new DataInputStream(s.getInputStream()); int status = new StatusLine(is.readLine()).getStatusCode(); if (status != 401) { return; } Header[] headers = HttpParser.parseHeaders(is); s.close(); byte[] b = createType1Message(); b = Base64.encodeBase64(b); s = new Socket("papasmurf", 80); os = new DataOutputStream(s.getOutputStream()); os.writeBytes("GET /protected/index.htm HTTP/1.0\r\n"); os.writeBytes("User-Agent: Foo\r\n"); os.writeBytes("Accept: */*\r\n"); os.writeBytes("Connection: Keep-Alive\r\n"); os.writeBytes("Authorization: NTLM "); os.write(b); os.writeBytes("\r\n\r\n"); is = new DataInputStream(s.getInputStream()); status = new StatusLine(is.readLine()).getStatusCode(); if (status != 401) { return; } headers = HttpParser.parseHeaders(is); String responseToken = null; int contentLen = 0; for (int i = 0; i < headers.length; i++) { Header h = headers[i]; if (h.getName().equals("WWW-Authenticate")) { String value = h.getValue(); System.out.println(value); responseToken = value.substring("NTLM ".length()); } else if (h.getName().equals("Content-Length")) { contentLen = Integer.parseInt(h.getValue()); } } for (int i = 0; i < contentLen; i++) { is.readByte(); } if (responseToken == null) { return; } byte[] intoken = Base64.decodeBase64(responseToken.getBytes()); b = createType3Message(intoken); b = Base64.encodeBase64(b); os.writeBytes("GET /protected/index.htm HTTP/1.0\r\n"); os.writeBytes("User-Agent: Foo\r\n"); os.writeBytes("Accept: */*\r\n"); os.writeBytes("Connection: Keep-Alive\r\n"); os.writeBytes("Authorization: NTLM "); os.write(b); os.writeBytes("\r\n\r\n"); is = new DataInputStream(s.getInputStream()); status = new StatusLine(is.readLine()).getStatusCode(); if (status != 200) { return; } headers = HttpParser.parseHeaders(is); for (int i = 0; i < headers.length; i++) { System.err.println(headers[i].toExternalForm()); } } catch (Exception e) { e.printStackTrace(); } } public static void main(String[] args) { HTTPAuthA a = new HTTPAuthA(); } public boolean SEC_SUCCESS(long ret) { if (ret >= 0) return true; return false; } public byte[] createType1Message() throws NTLMSecurityException { try { CredHandle credential = new CredHandle(); TimeStamp ptsExpiry = new TimeStamp(); System.out.println(credential.toString()); long ss = SSPI.AcquireCredentialsHandleA( null, new CString("NTLM"), new CULong(SSPI.SECPKG_CRED_OUTBOUND), null, null, null, null, credential, ptsExpiry); credential.dump(0); System.out.println(ptsExpiry.toString()); if (ss != NTStatus.STATUS_SUCCESS) { throw new NTLMSecurityException("Failed acquiring credentials handle"); } PSecPkgInfoA pskg = new PSecPkgInfoA(); ss = SSPI.QuerySecurityPackageInfoA(new CString("NTLM"), pskg); if (ss != NTStatus.STATUS_SUCCESS) { throw new NTLMSecurityException("Failed querying security package info"); } pskg.dump(0); SecPkgInfoA secpkginfo = (SecPkgInfoA) pskg.getSubject(); CBuffer buff = new CBuffer((int) secpkginfo.cbMaxToken.getValue()); SecBufferDesc OutBuffDesc = new SecBufferDesc(); SecBuffer OutSecBuff = new SecBuffer(); OutBuffDesc.ulVersion.setValue(0); OutBuffDesc.cBuffers.setValue(1); OutBuffDesc.pBuffers.setSubject(OutSecBuff); maxTokenSize = (int) secpkginfo.cbMaxToken.getValue(); OutSecBuff.cbBuffer.setValue(maxTokenSize); OutSecBuff.BufferType.setValue(SSPI.SECBUFFER_TOKEN); OutSecBuff.pvBuffer.setSubject(buff); securityContext = new CtxtHandle(); CULong ContextAttributes = new CULong(); ss = SSPI.InitializeSecurityContextA( credential, null, new CString("InetSvcs"), new CULong(0), new CULong(0), new CULong(SSPI.SECURITY_NATIVE_DREP), null, new CULong(0), securityContext, OutBuffDesc, ContextAttributes, ptsExpiry); if (!SEC_SUCCESS(ss)) { if (ss == WinError.SEC_E_LOGON_DENIED) { throw new NTLMSecurityException("Logon Denied"); } throw new NTLMSecurityException("Indeterminate exception"); } OutBuffDesc.dump(0); if ((ss == WinError.SEC_I_COMPLETE_NEEDED) || (ss == WinError.SEC_I_COMPLETE_AND_CONTINUE)) { ss = SSPI.CompleteAuthToken(securityContext, OutBuffDesc); if (!SEC_SUCCESS(ss)) { throw new NTLMSecurityException("Failed Completing Auth token"); } } long len = OutSecBuff.cbBuffer.getValue(); CBuffer buf = (CBuffer) OutSecBuff.pvBuffer.getSubject(); byte[] b = new byte[(int) len]; System.arraycopy(buf.getData(), 0, b, 0, (int) len); return b; } catch (CException e) { throw new NTLMSecurityException(e); } } byte[] createType3Message(byte[] serverTicket) throws NTLMSecurityException { try { SecBufferDesc OutBuffDesc = new SecBufferDesc(); SecBuffer OutSecBuff = new SecBuffer(); OutBuffDesc.ulVersion.setValue(0); OutBuffDesc.cBuffers.setValue(1); OutBuffDesc.pBuffers.setSubject(OutSecBuff); CBuffer buff = new CBuffer(maxTokenSize); OutSecBuff.cbBuffer.setValue(maxTokenSize); OutSecBuff.BufferType.setValue(SSPI.SECBUFFER_TOKEN); OutSecBuff.pvBuffer.setSubject(buff); SecBufferDesc InBuffDesc = new SecBufferDesc(); SecBuffer InSecBuff = new SecBuffer(); CBuffer pBuffIn = new CBuffer(maxTokenSize); pBuffIn.setData(serverTicket); InBuffDesc.ulVersion.setValue(0); InBuffDesc.cBuffers.setValue(1); InBuffDesc.pBuffers.setSubject(InSecBuff); InSecBuff.cbBuffer.setValue(serverTicket.length); InSecBuff.BufferType.setValue(SSPI.SECBUFFER_TOKEN); InSecBuff.pvBuffer.setSubject(pBuffIn); System.err.println("Second call to initsecuritycontext"); TimeStamp ptsExpiry = new TimeStamp(); CULong ContextAttributes = new CULong(); securityContext.dump(0); long ss = SSPI.InitializeSecurityContextA( null, securityContext, new CString("InetSvcs"), new CULong(0), new CULong(0), new CULong(SSPI.SECURITY_NATIVE_DREP), InBuffDesc, new CULong(0), securityContext, OutBuffDesc, ContextAttributes, ptsExpiry); if (!SEC_SUCCESS(ss)) { if (ss == WinError.SEC_E_LOGON_DENIED) { throw new NTLMSecurityException("Denied by server"); } throw new NTLMSecurityException("Denied by server"); } long len = OutSecBuff.cbBuffer.getValue(); CBuffer buf = (CBuffer) OutSecBuff.pvBuffer.getSubject(); byte[] b = new byte[(int) len]; System.arraycopy(buf.getData(), 0, b, 0, (int) len); return b; } catch (CException e) { throw new NTLMSecurityException(e); } } } --- NEW FILE: NTLMAuthenticator.java --- /* * Created on 24/07/2003 * */ package ctypes.java.ntlm.httpauth; import ctypes.java.CBuffer; import ctypes.java.CException; import ctypes.java.CString; import ctypes.java.CULong; import ctypes.java.win32.NTStatus; import ctypes.java.win32.WinError; import ctypes.java.win32.sspi.CredHandle; import ctypes.java.win32.sspi.CtxtHandle; import ctypes.java.win32.sspi.PSecPkgInfoA; import ctypes.java.win32.sspi.SSPI; import ctypes.java.win32.sspi.SecBuffer; import ctypes.java.win32.sspi.SecBufferDesc; import ctypes.java.win32.sspi.SecPkgInfoA; import ctypes.java.win32.sspi.TimeStamp; /** * @author Bradley Schatz * * Copyright 2003 Managed Data Security */ public class NTLMAuthenticator { int maxTokenSize = -1; CtxtHandle securityContext = null; public NTLMAuthenticator() { super(); } public byte[] createType1Message() throws NTLMSecurityException { try { CredHandle credential = new CredHandle(); TimeStamp ptsExpiry = new TimeStamp(); long ss = SSPI.AcquireCredentialsHandleA( null, new CString("NTLM"), new CULong(SSPI.SECPKG_CRED_OUTBOUND), null, null, null, null, credential, ptsExpiry); //credential.dump(0); if (ss != NTStatus.STATUS_SUCCESS) { throw new NTLMSecurityException("Failed acquiring credentials handle"); } PSecPkgInfoA pskg = new PSecPkgInfoA(); ss = SSPI.QuerySecurityPackageInfoA(new CString("NTLM"), pskg); if (ss != NTStatus.STATUS_SUCCESS) { throw new NTLMSecurityException("Failed querying security package info"); } pskg.dump(0); SecPkgInfoA secpkginfo = (SecPkgInfoA) pskg.getSubject(); maxTokenSize = (int) secpkginfo.cbMaxToken.getValue(); CBuffer buff = new CBuffer((int) maxTokenSize); SecBufferDesc OutBuffDesc = new SecBufferDesc(); SecBuffer OutSecBuff = new SecBuffer(); OutBuffDesc.ulVersion.setValue(0); OutBuffDesc.cBuffers.setValue(1); OutBuffDesc.pBuffers.setSubject(OutSecBuff); OutSecBuff.cbBuffer.setValue(maxTokenSize); OutSecBuff.BufferType.setValue(SSPI.SECBUFFER_TOKEN); OutSecBuff.pvBuffer.setSubject(buff); securityContext = new CtxtHandle(); CULong ContextAttributes = new CULong(); ss = SSPI.InitializeSecurityContextA( credential, null, new CString("InetSvcs"), new CULong(0), new CULong(0), new CULong(SSPI.SECURITY_NATIVE_DREP), null, new CULong(0), securityContext, OutBuffDesc, ContextAttributes, ptsExpiry); if (!SEC_SUCCESS(ss)) { if (ss == WinError.SEC_E_LOGON_DENIED) { throw new NTLMSecurityException("Logon Denied"); } throw new NTLMSecurityException("Indeterminate exception"); } if ((ss == WinError.SEC_I_COMPLETE_NEEDED) || (ss == WinError.SEC_I_COMPLETE_AND_CONTINUE)) { ss = SSPI.CompleteAuthToken(securityContext, OutBuffDesc); if (!SEC_SUCCESS(ss)) { throw new NTLMSecurityException("Failed Completing Auth token"); } } long len = OutSecBuff.cbBuffer.getValue(); CBuffer buf = (CBuffer) OutSecBuff.pvBuffer.getSubject(); byte[] b = new byte[(int) len]; System.arraycopy(buf.getData(), 0, b, 0, (int) len); return b; } catch (CException e) { throw new NTLMSecurityException(e); } } public byte[] createType3Message(byte[] serverTicket) throws NTLMSecurityException { try { SecBufferDesc OutBuffDesc = new SecBufferDesc(); SecBuffer OutSecBuff = new SecBuffer(); OutBuffDesc.ulVersion.setValue(0); OutBuffDesc.cBuffers.setValue(1); OutBuffDesc.pBuffers.setSubject(OutSecBuff); CBuffer buff = new CBuffer(maxTokenSize); OutSecBuff.cbBuffer.setValue(maxTokenSize); OutSecBuff.BufferType.setValue(SSPI.SECBUFFER_TOKEN); OutSecBuff.pvBuffer.setSubject(buff); SecBufferDesc InBuffDesc = new SecBufferDesc(); SecBuffer InSecBuff = new SecBuffer(); CBuffer pBuffIn = new CBuffer(maxTokenSize); pBuffIn.setData(serverTicket); InBuffDesc.ulVersion.setValue(0); InBuffDesc.cBuffers.setValue(1); InBuffDesc.pBuffers.setSubject(InSecBuff); InSecBuff.cbBuffer.setValue(serverTicket.length); InSecBuff.BufferType.setValue(SSPI.SECBUFFER_TOKEN); InSecBuff.pvBuffer.setSubject(pBuffIn); TimeStamp ptsExpiry = new TimeStamp(); CULong ContextAttributes = new CULong(); long ss = SSPI.InitializeSecurityContextA( null, securityContext, new CString("InetSvcs"), new CULong(0), new CULong(0), new CULong(SSPI.SECURITY_NATIVE_DREP), InBuffDesc, new CULong(0), securityContext, OutBuffDesc, ContextAttributes, ptsExpiry); if (!SEC_SUCCESS(ss)) { if (ss == WinError.SEC_E_LOGON_DENIED) { throw new NTLMSecurityException("Denied by server"); } throw new NTLMSecurityException("Denied by server"); } long len = OutSecBuff.cbBuffer.getValue(); CBuffer buf = (CBuffer) OutSecBuff.pvBuffer.getSubject(); byte[] b = new byte[(int) len]; System.arraycopy(buf.getData(), 0, b, 0, (int) len); return b; } catch (CException e) { throw new NTLMSecurityException(e); } } public boolean SEC_SUCCESS(long ret) { if (ret >= 0) return true; return false; } } --- NEW FILE: HTTPProxyAuth.java --- /* * Created on 22/07/2003 * */ package ctypes.java.ntlm.httpauth; import java.io.DataInputStream; import java.io.DataOutputStream; import java.net.Socket; import org.apache.commons.codec.binary.Base64; import org.apache.commons.httpclient.Header; import org.apache.commons.httpclient.HttpParser; import org.apache.commons.httpclient.StatusLine; import ctypes.java.CBuffer; import ctypes.java.CException; import ctypes.java.CString; import ctypes.java.CULong; import ctypes.java.win32.NTStatus; import ctypes.java.win32.WinError; import ctypes.java.win32.sspi.CredHandle; import ctypes.java.win32.sspi.CtxtHandle; import ctypes.java.win32.sspi.PSecPkgInfoA; import ctypes.java.win32.sspi.SSPI; import ctypes.java.win32.sspi.SecBuffer; import ctypes.java.win32.sspi.SecBufferDesc; import ctypes.java.win32.sspi.SecPkgInfoA; import ctypes.java.win32.sspi.TimeStamp; /** * @author Bradley Schatz * * Copyright 2003 Managed Data Security */ public class HTTPProxyAuth { int maxTokenSize = -1; CtxtHandle securityContext = null; public HTTPProxyAuth() { try { Socket s = new Socket("sbs1", 8080); DataOutputStream os = new DataOutputStream(s.getOutputStream()); os.writeBytes("GET http://slashdot.org/ HTTP/1.0\r\n"); os.writeBytes("Accept: */*\r\n"); os.writeBytes("User-Agent: Foo\r\n"); os.writeBytes("Pragma: no-cache\r\n"); os.writeBytes("Host: slashdot.org\r\n"); os.writeBytes("Proxy-Connection: Keep-Alive\r\n\r\n"); DataInputStream is = new DataInputStream(s.getInputStream()); int status = new StatusLine(is.readLine()).getStatusCode(); if (status != 407) { return; } boolean wantsNTLMAuth = false; int contentLen = 0; Header[] headers = HttpParser.parseHeaders(is); for (int i = 0; i < headers.length; i++) { Header h = headers[i]; if (h.getName().equals("Proxy-Authenticate")) { if (h.getValue().startsWith("NTLM")) { wantsNTLMAuth = true; } } else if (headers[i].getName().equals("Content-Length")) { contentLen = Integer.parseInt(headers[i].getValue()); } } for (int i = 0; i < contentLen; i++) { System.out.print(is.readByte()); } if (!wantsNTLMAuth) { return; } byte[] b = createType1Message(); b = Base64.encodeBase64(b); os.writeBytes("GET http://slashdot.org/ HTTP/1.0\r\n"); os.writeBytes("Accept: */*\r\n"); os.writeBytes("User-Agent: Foo\r\n"); os.writeBytes("Pragma: no-cache\r\n"); os.writeBytes("Host: slashdot.org\r\n"); os.writeBytes("Proxy-Connection: Keep-Alive\r\n"); os.writeBytes("Proxy-Authorization: NTLM "); os.write(b); os.writeBytes("\r\n\r\n"); is = new DataInputStream(s.getInputStream()); status = new StatusLine(is.readLine()).getStatusCode(); if (status != 407) { return; } headers = HttpParser.parseHeaders(is); String responseToken = null; contentLen = 0; for (int i = 0; i < headers.length; i++) { Header h = headers[i]; System.out.println(h.toExternalForm()); if (h.getName().equals("Proxy-Authenticate")) { String value = h.getValue(); System.out.println(value); responseToken = value.substring("NTLM ".length()); } else if (h.getName().equals("Content-Length")) { contentLen = Integer.parseInt(h.getValue()); } } for (int i = 0; i < contentLen; i++) { is.readByte(); } if (responseToken == null) { return; } byte[] intoken = Base64.decodeBase64(responseToken.getBytes()); b = createType3Message(intoken); b = Base64.encodeBase64(b); os.writeBytes("GET http://slashdot.org/ HTTP/1.0\r\n"); os.writeBytes("Accept: */*\r\n"); os.writeBytes("User-Agent: Foo\r\n"); os.writeBytes("Pragma: no-cache\r\n"); os.writeBytes("Host: slashdot.org\r\n"); os.writeBytes("Proxy-Connection: Keep-Alive\r\n"); os.writeBytes("Proxy-Authorization: NTLM "); os.write(b); os.writeBytes("\r\n\r\n"); is = new DataInputStream(s.getInputStream()); status = new StatusLine(is.readLine()).getStatusCode(); if (status != 200) { return; } contentLen = -1; headers = HttpParser.parseHeaders(is); for (int i = 0; i < headers.length; i++) { System.err.println(headers[i].toExternalForm()); if (headers[i].getName().equals("Content-Length")) { contentLen = Integer.parseInt(headers[i].getValue()); } } for (int i = 0; i < contentLen; i++) { System.out.print(is.readByte()); } } catch (Exception e) { e.printStackTrace(); } } public static void main(String[] args) { HTTPProxyAuth a = new HTTPProxyAuth(); } public boolean SEC_SUCCESS(long ret) { if (ret >= 0) return true; return false; } public byte[] createType1Message() throws NTLMSecurityException { try { CredHandle credential = new CredHandle(); TimeStamp ptsExpiry = new TimeStamp(); System.out.println(credential.toString()); long ss = SSPI.AcquireCredentialsHandleA( null, new CString("NTLM"), new CULong(SSPI.SECPKG_CRED_OUTBOUND), null, null, null, null, credential, ptsExpiry); credential.dump(0); System.out.println(ptsExpiry.toString()); if (ss != NTStatus.STATUS_SUCCESS) { throw new NTLMSecurityException("Failed acquiring credentials handle"); } PSecPkgInfoA pskg = new PSecPkgInfoA(); ss = SSPI.QuerySecurityPackageInfoA(new CString("NTLM"), pskg); if (ss != NTStatus.STATUS_SUCCESS) { throw new NTLMSecurityException("Failed querying security package info"); } pskg.dump(0); SecPkgInfoA secpkginfo = (SecPkgInfoA) pskg.getSubject(); CBuffer buff = new CBuffer((int) secpkginfo.cbMaxToken.getValue()); SecBufferDesc OutBuffDesc = new SecBufferDesc(); SecBuffer OutSecBuff = new SecBuffer(); OutBuffDesc.ulVersion.setValue(0); OutBuffDesc.cBuffers.setValue(1); OutBuffDesc.pBuffers.setSubject(OutSecBuff); maxTokenSize = (int) secpkginfo.cbMaxToken.getValue(); OutSecBuff.cbBuffer.setValue(maxTokenSize); OutSecBuff.BufferType.setValue(SSPI.SECBUFFER_TOKEN); OutSecBuff.pvBuffer.setSubject(buff); securityContext = new CtxtHandle(); CULong ContextAttributes = new CULong(); ss = SSPI.InitializeSecurityContextA( credential, null, new CString("InetSvcs"), new CULong(0), new CULong(0), new CULong(SSPI.SECURITY_NATIVE_DREP), null, new CULong(0), securityContext, OutBuffDesc, ContextAttributes, ptsExpiry); if (!SEC_SUCCESS(ss)) { if (ss == WinError.SEC_E_LOGON_DENIED) { throw new NTLMSecurityException("Logon Denied"); } throw new NTLMSecurityException("Indeterminate exception"); } OutBuffDesc.dump(0); if ((ss == WinError.SEC_I_COMPLETE_NEEDED) || (ss == WinError.SEC_I_COMPLETE_AND_CONTINUE)) { ss = SSPI.CompleteAuthToken(securityContext, OutBuffDesc); if (!SEC_SUCCESS(ss)) { throw new NTLMSecurityException("Failed Completing Auth token"); } } long len = OutSecBuff.cbBuffer.getValue(); CBuffer buf = (CBuffer) OutSecBuff.pvBuffer.getSubject(); byte[] b = new byte[(int) len]; System.arraycopy(buf.getData(), 0, b, 0, (int) len); return b; } catch (CException e) { throw new NTLMSecurityException(e); } } byte[] createType3Message(byte[] serverTicket) throws NTLMSecurityException { try { SecBufferDesc OutBuffDesc = new SecBufferDesc(); SecBuffer OutSecBuff = new SecBuffer(); OutBuffDesc.ulVersion.setValue(0); OutBuffDesc.cBuffers.setValue(1); OutBuffDesc.pBuffers.setSubject(OutSecBuff); CBuffer buff = new CBuffer(maxTokenSize); OutSecBuff.cbBuffer.setValue(maxTokenSize); OutSecBuff.BufferType.setValue(SSPI.SECBUFFER_TOKEN); OutSecBuff.pvBuffer.setSubject(buff); SecBufferDesc InBuffDesc = new SecBufferDesc(); SecBuffer InSecBuff = new SecBuffer(); CBuffer pBuffIn = new CBuffer(maxTokenSize); pBuffIn.setData(serverTicket); InBuffDesc.ulVersion.setValue(0); InBuffDesc.cBuffers.setValue(1); InBuffDesc.pBuffers.setSubject(InSecBuff); InSecBuff.cbBuffer.setValue(serverTicket.length); InSecBuff.BufferType.setValue(SSPI.SECBUFFER_TOKEN); InSecBuff.pvBuffer.setSubject(pBuffIn); System.err.println("Second call to initsecuritycontext"); TimeStamp ptsExpiry = new TimeStamp(); CULong ContextAttributes = new CULong(); securityContext.dump(0); long ss = SSPI.InitializeSecurityContextA( null, securityContext, new CString("InetSvcs"), new CULong(0), new CULong(0), new CULong(SSPI.SECURITY_NATIVE_DREP), InBuffDesc, new CULong(0), securityContext, OutBuffDesc, ContextAttributes, ptsExpiry); if (!SEC_SUCCESS(ss)) { if (ss == WinError.SEC_E_LOGON_DENIED) { throw new NTLMSecurityException("Denied by server"); } throw new NTLMSecurityException("Denied by server"); } long len = OutSecBuff.cbBuffer.getValue(); CBuffer buf = (CBuffer) OutSecBuff.pvBuffer.getSubject(); byte[] b = new byte[(int) len]; System.arraycopy(buf.getData(), 0, b, 0, (int) len); return b; } catch (CException e) { throw new NTLMSecurityException(e); } } } --- NEW FILE: HTTPAuth.java --- /* * Created on 22/07/2003 * */ package ctypes.java.ntlm.httpauth; import java.io.DataInputStream; import java.io.DataOutputStream; import java.net.Socket; import org.apache.commons.codec.binary.Base64; import org.apache.commons.httpclient.Header; import org.apache.commons.httpclient.HttpParser; import org.apache.commons.httpclient.StatusLine; import ctypes.java.win32.sspi.CtxtHandle; /** * @author Bradley Schatz * * Copyright 2003 Managed Data Security */ public class HTTPAuth { int maxTokenSize = -1; CtxtHandle securityContext = null; NTLMAuthenticator auth = new NTLMAuthenticator(); public HTTPAuth() { try { Socket s = new Socket("papasmurf", 80); DataOutputStream os = new DataOutputStream(s.getOutputStream()); os.writeBytes("GET /protected/index.htm HTTP/1.0\r\n"); os.writeBytes("User-Agent: Foo\r\n"); os.writeBytes("Accept: */*\r\n\r\n"); DataInputStream is = new DataInputStream(s.getInputStream()); int status = new StatusLine(is.readLine()).getStatusCode(); if (status != 401) { return; } Header[] headers = HttpParser.parseHeaders(is); s.close(); byte[] b = auth.createType1Message(); b = Base64.encodeBase64(b); s = new Socket("papasmurf", 80); os = new DataOutputStream(s.getOutputStream()); os.writeBytes("GET /protected/index.htm HTTP/1.0\r\n"); os.writeBytes("User-Agent: Foo\r\n"); os.writeBytes("Accept: */*\r\n"); os.writeBytes("Connection: Keep-Alive\r\n"); os.writeBytes("Authorization: NTLM "); os.write(b); os.writeBytes("\r\n\r\n"); is = new DataInputStream(s.getInputStream()); status = new StatusLine(is.readLine()).getStatusCode(); if (status != 401) { return; } headers = HttpParser.parseHeaders(is); String responseToken = null; int contentLen = 0; for (int i = 0; i < headers.length; i++) { Header h = headers[i]; if (h.getName().equals("WWW-Authenticate")) { String value = h.getValue(); System.out.println(value); responseToken = value.substring("NTLM ".length()); } else if (h.getName().equals("Content-Length")) { contentLen = Integer.parseInt(h.getValue()); } } for (int i = 0; i < contentLen; i++) { is.readByte(); } if (responseToken == null) { return; } byte[] intoken = Base64.decodeBase64(responseToken.getBytes()); b = auth.createType3Message(intoken); b = Base64.encodeBase64(b); os.writeBytes("GET /protected/index.htm HTTP/1.0\r\n"); os.writeBytes("User-Agent: Foo\r\n"); os.writeBytes("Accept: */*\r\n"); os.writeBytes("Connection: Keep-Alive\r\n"); os.writeBytes("Authorization: NTLM "); os.write(b); os.writeBytes("\r\n\r\n"); is = new DataInputStream(s.getInputStream()); status = new StatusLine(is.readLine()).getStatusCode(); if (status != 200) { return; } headers = HttpParser.parseHeaders(is); for (int i = 0; i < headers.length; i++) { System.err.println(headers[i].toExternalForm()); } } catch (Exception e) { e.printStackTrace(); } } public static void main(String[] args) { HTTPAuth a = new HTTPAuth(); } public boolean SEC_SUCCESS(long ret) { if (ret >= 0) return true; return false; } } |
From: Bradley L S. <bs...@us...> - 2004-08-29 01:21:06
|
Update of /cvsroot/ctypes/ctypes-java/src/examples/ctypes/java/ntlm/httpclient In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18108/src/examples/ctypes/java/ntlm/httpclient Added Files: NTLMSecurityException.java Test.java CredLessNTLMAuthenticaton.java ProxyNTLMAuthenticaton.java test.sh CredentiallessNTLMScheme.java NTLMAuthenticator.java Charset.java Log Message: --- NEW FILE: NTLMSecurityException.java --- /* * Created on 24/07/2003 * */ package ctypes.java.ntlm.httpclient; import ctypes.java.CException; /** * @author Bradley Schatz * * Copyright 2003 Managed Data Security */ public class NTLMSecurityException extends CException { /** * */ public NTLMSecurityException() { super(); // TODO Auto-generated constructor stub } /** * @param arg0 */ public NTLMSecurityException(String arg0) { super(arg0); // TODO Auto-generated constructor stub } /** * @param arg0 * @param arg1 */ public NTLMSecurityException(String arg0, Throwable arg1) { super(arg0, arg1); // TODO Auto-generated constructor stub } /** * @param arg0 */ public NTLMSecurityException(Throwable arg0) { super(arg0); // TODO Auto-generated constructor stub } } --- NEW FILE: NTLMAuthenticator.java --- /* * Created on 24/07/2003 * */ package ctypes.java.ntlm.httpclient; import ctypes.java.CBuffer; import ctypes.java.CException; import ctypes.java.CString; import ctypes.java.CULong; import ctypes.java.win32.NTStatus; import ctypes.java.win32.WinError; import ctypes.java.win32.sspi.CredHandle; import ctypes.java.win32.sspi.CtxtHandle; import ctypes.java.win32.sspi.PSecPkgInfoA; import ctypes.java.win32.sspi.SSPI; import ctypes.java.win32.sspi.SecBuffer; import ctypes.java.win32.sspi.SecBufferDesc; import ctypes.java.win32.sspi.SecPkgInfoA; import ctypes.java.win32.sspi.TimeStamp; /** * @author Bradley Schatz * * Copyright 2003 Managed Data Security */ public class NTLMAuthenticator { int maxTokenSize = -1; CtxtHandle securityContext = null; public NTLMAuthenticator() { super(); } public byte[] createType1Message() throws NTLMSecurityException { try { CredHandle credential = new CredHandle(); TimeStamp ptsExpiry = new TimeStamp(); long ss = SSPI.AcquireCredentialsHandleA( null, new CString("NTLM"), new CULong(SSPI.SECPKG_CRED_OUTBOUND), null, null, null, null, credential, ptsExpiry); if (ss != NTStatus.STATUS_SUCCESS) { throw new NTLMSecurityException("Failed acquiring credentials handle"); } PSecPkgInfoA pskg = new PSecPkgInfoA(); ss = SSPI.QuerySecurityPackageInfoA(new CString("NTLM"), pskg); if (ss != NTStatus.STATUS_SUCCESS) { throw new NTLMSecurityException("Failed querying security package info"); } SecPkgInfoA secpkginfo = (SecPkgInfoA) pskg.getSubject(); CBuffer buff = new CBuffer((int) secpkginfo.cbMaxToken.getValue()); SecBufferDesc OutBuffDesc = new SecBufferDesc(); SecBuffer OutSecBuff = new SecBuffer(); OutBuffDesc.ulVersion.setValue(0); OutBuffDesc.cBuffers.setValue(1); OutBuffDesc.pBuffers.setSubject(OutSecBuff); maxTokenSize = (int) secpkginfo.cbMaxToken.getValue(); OutSecBuff.cbBuffer.setValue(maxTokenSize); OutSecBuff.BufferType.setValue(SSPI.SECBUFFER_TOKEN); OutSecBuff.pvBuffer.setSubject(buff); securityContext = new CtxtHandle(); CULong ContextAttributes = new CULong(); ss = SSPI.InitializeSecurityContextA( credential, null, new CString("InetSvcs"), new CULong(0), new CULong(0), new CULong(SSPI.SECURITY_NATIVE_DREP), null, new CULong(0), securityContext, OutBuffDesc, ContextAttributes, ptsExpiry); if (!SEC_SUCCESS(ss)) { if (ss == WinError.SEC_E_LOGON_DENIED) { throw new NTLMSecurityException("Logon Denied"); } throw new NTLMSecurityException("Indeterminate exception"); } if ((ss == WinError.SEC_I_COMPLETE_NEEDED) || (ss == WinError.SEC_I_COMPLETE_AND_CONTINUE)) { ss = SSPI.CompleteAuthToken(securityContext, OutBuffDesc); if (!SEC_SUCCESS(ss)) { throw new NTLMSecurityException("Failed Completing Auth token"); } } long len = OutSecBuff.cbBuffer.getValue(); CBuffer buf = (CBuffer) OutSecBuff.pvBuffer.getSubject(); byte[] b = new byte[(int) len]; System.arraycopy(buf.getData(), 0, b, 0, (int) len); return b; } catch (CException e) { throw new NTLMSecurityException(e); } } public byte[] createType3Message(byte[] serverTicket) throws NTLMSecurityException { try { SecBufferDesc OutBuffDesc = new SecBufferDesc(); SecBuffer OutSecBuff = new SecBuffer(); OutBuffDesc.ulVersion.setValue(0); OutBuffDesc.cBuffers.setValue(1); OutBuffDesc.pBuffers.setSubject(OutSecBuff); CBuffer buff = new CBuffer(maxTokenSize); OutSecBuff.cbBuffer.setValue(maxTokenSize); OutSecBuff.BufferType.setValue(SSPI.SECBUFFER_TOKEN); OutSecBuff.pvBuffer.setSubject(buff); SecBufferDesc InBuffDesc = new SecBufferDesc(); SecBuffer InSecBuff = new SecBuffer(); CBuffer pBuffIn = new CBuffer(maxTokenSize); pBuffIn.setData(serverTicket); InBuffDesc.ulVersion.setValue(0); InBuffDesc.cBuffers.setValue(1); InBuffDesc.pBuffers.setSubject(InSecBuff); InSecBuff.cbBuffer.setValue(serverTicket.length); InSecBuff.BufferType.setValue(SSPI.SECBUFFER_TOKEN); InSecBuff.pvBuffer.setSubject(pBuffIn); TimeStamp ptsExpiry = new TimeStamp(); CULong ContextAttributes = new CULong(); long ss = SSPI.InitializeSecurityContextA( null, securityContext, new CString("InetSvcs"), new CULong(0), new CULong(0), new CULong(SSPI.SECURITY_NATIVE_DREP), InBuffDesc, new CULong(0), securityContext, OutBuffDesc, ContextAttributes, ptsExpiry); if (!SEC_SUCCESS(ss)) { if (ss == WinError.SEC_E_LOGON_DENIED) { throw new NTLMSecurityException("Denied by server"); } throw new NTLMSecurityException("Denied by server"); } long len = OutSecBuff.cbBuffer.getValue(); CBuffer buf = (CBuffer) OutSecBuff.pvBuffer.getSubject(); byte[] b = new byte[(int) len]; System.arraycopy(buf.getData(), 0, b, 0, (int) len); return b; } catch (CException e) { throw new NTLMSecurityException(e); } } public boolean SEC_SUCCESS(long ret) { if (ret >= 0) return true; return false; } } --- NEW FILE: CredLessNTLMAuthenticaton.java --- /* * $Header: /cvsroot/ctypes/ctypes-java/src/examples/ctypes/java/ntlm/httpclient/CredLessNTLMAuthenticaton.java,v 1.1 2004/08/29 01:20:51 bschatz Exp $ * $Revision: 1.1 $ * $Date: 2004/08/29 01:20:51 $ * ==================================================================== * * The Apache Software License, Version 1.1 * * Copyright (c) 1999-2003 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "HttpClient", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact ap...@ap.... * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. * * [Additional notices, if required by prior licensing conditions] * */ package ctypes.java.ntlm.httpclient; import org.apache.commons.httpclient.Header; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.NTCredentials; import org.apache.commons.httpclient.auth.HttpAuthenticator; import org.apache.commons.httpclient.methods.GetMethod; /** * A simple example that uses HttpClient to perform a GET using Basic * Authentication. Can be run standalone without parameters. * * You need to have JSSE on your classpath for JDK prior to 1.4 * * @author Michael Becke */ public class CredLessNTLMAuthenticaton { /** * Constructor for BasicAuthenticatonExample. */ public CredLessNTLMAuthenticaton() { } public static void main(String[] args) throws Exception { HttpClient client = new HttpClient(); // pass our credentials to HttpClient, they will only be used for // authenticating to servers with realm "realm", to authenticate agains // an arbitrary realm change this to null. //client.getState().setCredentials( // "www.verisign.com", // "realm", // new UsernamePasswordCredentials("username", "password") //); client.getState().setCredentials(null, new NTCredentials("", "", "", "")); HttpAuthenticator.setNTLMSchemeClass(CredentiallessNTLMScheme.class); // create a GET method that reads a file over HTTPS, we're assuming // that this file requires basic authentication using the realm above. GetMethod get = new GetMethod("http://papasmurf/protected/index.htm"); get.addRequestHeader(new Header("Connection", "Keep-Alive")); // Tell the GET method to automatically handle authentication. The // method will use any appropriate credentials to handle basic // authentication requests. Setting this value to false will cause // any request for authentication to return with a status of 401. // It will then be up to the client to handle the authentication. get.setDoAuthentication( true ); // execute the GET int status = client.executeMethod( get ); // print the status and response System.out.println(status + "\n" + get.getResponseBodyAsString()); // release any connection resources used by the method get.releaseConnection(); } } --- NEW FILE: CredentiallessNTLMScheme.java --- package ctypes.java.ntlm.httpclient; import org.apache.commons.codec.binary.Base64; import org.apache.commons.httpclient.Credentials; import org.apache.commons.httpclient.NTCredentials; import org.apache.commons.httpclient.auth.AuthChallengeParser; import org.apache.commons.httpclient.auth.AuthenticationException; import org.apache.commons.httpclient.auth.MalformedChallengeException; import org.apache.commons.httpclient.auth.NTLMScheme; /** * <p> * Microsoft proprietary NTLM authentication scheme. * </p> * * @author <a href="mailto:re...@ap...">Remy Maucherat</a> * @author Rodney Waldhoff * @author <a href="mailto:js...@ap...">Jeff Dever</a> * @author Ortwin Glück * @author Sean C. Sullivan * @author <a href="mailto:ad...@ep...">Adrian Sutton</a> * @author <a href="mailto:mb...@Ga...">Mike Bowler</a> * @author <a href="mailto:ol...@ur...">Oleg Kalnichevski</a> */ public class CredentiallessNTLMScheme extends NTLMScheme { private static NTLMAuthenticator ntlmAuthenticator = null; /** * Constructor for the NTLM authentication scheme. * * @param challenge The authentication challenge * * @throws MalformedChallengeException is thrown if the authentication challenge * is malformed */ public CredentiallessNTLMScheme(final String challenge) throws MalformedChallengeException { super(challenge); String s = AuthChallengeParser.extractScheme(challenge); if (!s.equalsIgnoreCase(getSchemeName())) { throw new MalformedChallengeException("Invalid NTLM challenge: " + challenge); } int i = challenge.indexOf(' '); if (i != -1) { s = challenge.substring(i, challenge.length()); this.ntlmchallenge = s.trim(); System.err.println(ntlmchallenge); } else { this.ntlmchallenge = ""; } } /** * Returns textual designation of the NTLM authentication scheme. * * @return <code>ntlm</code> */ public String getSchemeName() { return "ntlm"; } /** * The concept of an authentication realm is not supported by the NTLM * authentication scheme. Always returns <code>null</code>. * * @return <code>null</code> */ public String getRealm() { return null; } /** * Returns a String identifying the authentication challenge. This is * used, in combination with the host and port to determine if * authorization has already been attempted or not. Schemes which * require multiple requests to complete the authentication should * return a different value for each stage in the request. * * <p>Additionally, the ID should take into account any changes to the * authentication challenge and return a different value when appropriate. * For example when the realm changes in basic authentication it should be * considered a different authentication attempt and a different value should * be returned.</p> * * @return String a String identifying the authentication challenge. The * returned value may be null. */ public String getID() { return ntlmchallenge; } /** * Returns authentication parameter with the given name, if available. * * @param name The name of the parameter to be returned * * @return the parameter with the given name */ public String getParameter(String name) { if (name == null) { throw new IllegalArgumentException("Parameter name may not be null"); } return null; } /** * Create a NTLM authorization string for the given * challenge and NT credentials. * * @param challenge The challenge. * @param credentials {@link NTCredentials} * * @return a ntlm authorization string * @throws AuthenticationException is thrown if authentication fails */ public String authenticate(final Credentials credentials, final String challenge, final String scheme) throws AuthenticationException { String s = null; try { if (ntlmchallenge.equals("")) { // this is the first phase of the initilization ntlmAuthenticator = new NTLMAuthenticator(); byte[] response = ntlmAuthenticator.createType1Message(); s = new String(Base64.encodeBase64(response)); } else if (ntlmchallenge.length() > 0) { // we are on leg two of the authentication byte[] response = ntlmAuthenticator.createType3Message(Base64.decodeBase64(ntlmchallenge.getBytes())); s = new String(Base64.encodeBase64(response)); ntlmAuthenticator = null; } else { throw new AuthenticationException("Illegal State"); } } catch (NTLMSecurityException e) { throw new AuthenticationException(e.getMessage()); } return "NTLM " + s; } } --- NEW FILE: test.sh --- gcj --main=mds.httpclient.Test --classpath C:\src\jakarta-log4j-1.2.8\dist\lib\log4j-1.2.8.jar;C:\src\commons-httpclient-2.0-beta1\bin;C:\src\commons-httpclient-2.0-beta1\lib\commons-logging.jar;C:\src\commons-httpclient-2.0-beta1\lib\commons-logging-api.jar -o httptest.exe .\src\spike\mds\httpclient\Test.java C:\src\jakarta-log4j-1.2.8\dist\lib\log4j.a C:\src\commons-httpclient-2.0-beta1\dist\lib\httpclient.a C:\src\commons-logging-1.0.3-src\dist\lib\commons-logging.a --- NEW FILE: ProxyNTLMAuthenticaton.java --- /* * $Header: /cvsroot/ctypes/ctypes-java/src/examples/ctypes/java/ntlm/httpclient/ProxyNTLMAuthenticaton.java,v 1.1 2004/08/29 01:20:51 bschatz Exp $ * $Revision: 1.1 $ * $Date: 2004/08/29 01:20:51 $ * ==================================================================== * * The Apache Software License, Version 1.1 * * Copyright (c) 1999-2003 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "HttpClient", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact ap...@ap.... * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. * * [Additional notices, if required by prior licensing conditions] * */ package ctypes.java.ntlm.httpclient; import org.apache.commons.httpclient.Header; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.NTCredentials; import org.apache.commons.httpclient.auth.HttpAuthenticator; import org.apache.commons.httpclient.methods.GetMethod; /** * A simple example that uses HttpClient to perform a GET using Basic * Authentication. Can be run standalone without parameters. * * You need to have JSSE on your classpath for JDK prior to 1.4 * * @author Michael Becke */ public class ProxyNTLMAuthenticaton { /** * Constructor for BasicAuthenticatonExample. */ public ProxyNTLMAuthenticaton() { } public static void main(String[] args) throws Exception { HttpClient client = new HttpClient(); // pass our credentials to HttpClient, they will only be used for // authenticating to servers with realm "realm", to authenticate agains // an arbitrary realm change this to null. //client.getState().setCredentials( // "www.verisign.com", // "realm", // new UsernamePasswordCredentials("username", "password") //); client.getState().setProxyCredentials(null, new NTCredentials("", "", "", "")); HttpAuthenticator.setNTLMSchemeClass(CredentiallessNTLMScheme.class); client.getHostConfiguration().setProxy("192.168.0.1", 800); // create a GET method that reads a file over HTTPS, we're assuming // that this file requires basic authentication using the realm above. GetMethod get = new GetMethod("http://slashdot.org/"); get.addRequestHeader(new Header("Connection", "Keep-Alive")); // Tell the GET method to automatically handle authentication. The // method will use any appropriate credentials to handle basic // authentication requests. Setting this value to false will cause // any request for authentication to return with a status of 401. // It will then be up to the client to handle the authentication. get.setDoAuthentication( true ); // execute the GET int status = client.executeMethod( get ); // print the status and response System.out.println(status + "\n" + get.getResponseBodyAsString()); // release any connection resources used by the method get.releaseConnection(); } } --- NEW FILE: Test.java --- /* * Created on 19/06/2003 * * To change the template for this generated file go to * Window>Preferences>Java>Code Generation>Code and Comments */ package ctypes.java.ntlm.httpclient; import java.io.IOException; import org.apache.commons.httpclient.Header; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.HttpException; import org.apache.commons.httpclient.HttpMethod; import org.apache.commons.httpclient.URI; import org.apache.commons.httpclient.methods.GetMethod; public class Test { public static void main(String[] args) { //create a singular HttpClient object HttpClient client = new HttpClient(); HttpMethod method = null; String url = "http://www.yahoo.com/"; //create a method object String responseBody = null; try { try { URI.setDefaultProtocolCharset("ISO-8859-1"); } catch (Exception e) { } try { URI.setDefaultDocumentCharset("ISO-8859-1"); } catch (Exception e) { } method = new GetMethod(url); method.setFollowRedirects(true); method.setStrictMode(false); client.executeMethod(method); responseBody = method.getResponseBodyAsString(); } catch (HttpException he) { System.err.println("Http error connecting to '" + url + "'"); System.err.println(he.getMessage()); System.exit(-4); } catch (IOException ioe) { System.err.println("Unable to connect to '" + url + "'"); System.exit(-3); } //write out the request headers System.out.println("*** Request ***"); System.out.println("Request Path: " + method.getPath()); System.out.println("Request Query: " + method.getQueryString()); Header[] requestHeaders = method.getRequestHeaders(); for (int i = 0; i < requestHeaders.length; i++) { System.out.print(requestHeaders[i]); } //write out the response headers System.out.println("*** Response ***"); System.out.println("Status Line: " + method.getStatusLine()); Header[] responseHeaders = method.getResponseHeaders(); for (int i = 0; i < responseHeaders.length; i++) { System.out.print(responseHeaders[i]); } //write out the response body System.out.println("*** Response Body ***"); System.out.println(responseBody); //clean up the connection resources method.releaseConnection(); method.recycle(); System.exit(0); } } --- NEW FILE: Charset.java --- /* * Created on 9/07/2003 * */ package ctypes.java.ntlm.httpclient; /** * @author Bradley Schatz * * Copyright 2003 Managed Data Security */ public class Charset { public static void main(String[] args) { try{ System.out.println(new String("hello").getBytes("UTF16")); } catch (Exception e) { e.printStackTrace(); } } } |
From: Bradley L S. <bs...@us...> - 2004-08-29 01:21:06
|
Update of /cvsroot/ctypes/ctypes-java/src/examples/ctypes/java/ntlm In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18065/src/examples/ctypes/java/ntlm Log Message: Directory /cvsroot/ctypes/ctypes-java/src/examples/ctypes/java/ntlm added to the repository |
From: Bradley L S. <bs...@us...> - 2004-08-29 01:21:06
|
Update of /cvsroot/ctypes/ctypes-java/src/examples/ctypes/java/ntlm/httpauth In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18065/src/examples/ctypes/java/ntlm/httpauth Log Message: Directory /cvsroot/ctypes/ctypes-java/src/examples/ctypes/java/ntlm/httpauth added to the repository |
From: Bradley L S. <bs...@us...> - 2004-08-29 01:21:05
|
Update of /cvsroot/ctypes/ctypes-java/src/examples/ctypes/java/ntlm/httpclient In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18065/src/examples/ctypes/java/ntlm/httpclient Log Message: Directory /cvsroot/ctypes/ctypes-java/src/examples/ctypes/java/ntlm/httpclient added to the repository |
From: Bradley L S. <bs...@us...> - 2004-08-29 01:20:15
|
Update of /cvsroot/ctypes/ctypes-java/lib In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17884/lib Added Files: commons-httpclient.jar commons-codec-1.3.jar Log Message: --- NEW FILE: commons-codec-1.3.jar --- (This appears to be a binary file; contents omitted.) --- NEW FILE: commons-httpclient.jar --- (This appears to be a binary file; contents omitted.) |
From: Bradley L S. <bs...@us...> - 2004-08-29 01:20:15
|
Update of /cvsroot/ctypes/ctypes-java/src/examples/ctypes/java/examples/win32 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17884/src/examples/ctypes/java/examples/win32 Modified Files: Time.java Log Message: Index: Time.java =================================================================== RCS file: /cvsroot/ctypes/ctypes-java/src/examples/ctypes/java/examples/win32/Time.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Time.java 23 Mar 2004 06:37:34 -0000 1.1 --- Time.java 29 Aug 2004 01:20:05 -0000 1.2 *************** *** 23,30 **** package ctypes.java.examples.win32; ! import ctypes.java.CBuffer; import ctypes.java.CFunction; import ctypes.java.CInt; - import ctypes.java.CDLL; /** --- 23,29 ---- package ctypes.java.examples.win32; ! import ctypes.java.CDLL; import ctypes.java.CFunction; import ctypes.java.CInt; /** |
From: Bradley L S. <bs...@us...> - 2004-08-29 01:20:15
|
Update of /cvsroot/ctypes/ctypes-java/src/examples In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17884/src/examples Modified Files: README Log Message: Index: README =================================================================== RCS file: /cvsroot/ctypes/ctypes-java/src/examples/README,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** README 22 Mar 2004 05:55:38 -0000 1.1 --- README 29 Aug 2004 01:20:05 -0000 1.2 *************** *** 7,9 **** --- 7,19 ---- Simple usage of the printf function (Win32) + ctypes.java.ntlm.httpauth + Examples using local NTLM authentication over http to authenticate + access to a website, and a proxy. + + ctypes.java.ntlm.httpclient + Example integration of NTLM authentication into Jakarta commons-httpclient + + org.jawin.win32 & demos.petzold.chapt3 + Conversion of JAWIN example and support API to ctypes4j + More detailed usage may be read from the unit tests in the src/test tree. \ No newline at end of file |
From: Thomas H. <th...@us...> - 2004-08-27 19:33:45
|
Update of /cvsroot/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13589 Modified Files: .cvsignore Log Message: Ignore the test.output file which is created by the unit tests. Index: .cvsignore =================================================================== RCS file: /cvsroot/ctypes/ctypes/.cvsignore,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** .cvsignore 10 Jul 2003 19:47:00 -0000 1.5 --- .cvsignore 27 Aug 2004 19:33:35 -0000 1.6 *************** *** 2,5 **** --- 2,6 ---- *.h *.ilk + *.log *.pdb *.pyc *************** *** 11,16 **** _ctypes_d.pyd archive - dist build extensions ! *.log --- 12,17 ---- _ctypes_d.pyd archive build + dist extensions ! test.output |
From: Thomas H. <th...@us...> - 2004-08-27 19:30:31
|
Update of /cvsroot/ctypes/ctypes/comtypes/tools In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13102 Added Files: .cvsignore Log Message: Added .cvsignore files to the comtypes project. --- NEW FILE: .cvsignore --- *.pyo *.pyc |
From: Thomas H. <th...@us...> - 2004-08-27 19:30:11
|
Update of /cvsroot/ctypes/ctypes/comtypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12990 Added Files: .cvsignore Log Message: Added .cvsignore files to the comtypes project. --- NEW FILE: .cvsignore --- *.pyo *.pyc |
From: Thomas H. <th...@us...> - 2004-08-27 19:07:42
|
Update of /cvsroot/ctypes/ctypes/comtypes/tools In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9271/tools Log Message: Directory /cvsroot/ctypes/ctypes/comtypes/tools added to the repository |
From: Thomas H. <th...@us...> - 2004-08-27 19:07:21
|
Update of /cvsroot/ctypes/ctypes/comtypes/docs In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9222/docs Log Message: Directory /cvsroot/ctypes/ctypes/comtypes/docs added to the repository |
From: Thomas H. <th...@us...> - 2004-08-27 19:06:40
|
Update of /cvsroot/ctypes/ctypes/comtypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9113/comtypes Log Message: Directory /cvsroot/ctypes/ctypes/comtypes added to the repository |
From: Thomas H. <th...@us...> - 2004-08-27 19:05:02
|
Update of /cvsroot/ctypes/ctypes/unittests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8752 Modified Files: test_cfuncs.py Log Message: Comment that lots of these tests fail on Mac OS X. Index: test_cfuncs.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_cfuncs.py,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** test_cfuncs.py 27 Aug 2004 18:52:10 -0000 1.14 --- test_cfuncs.py 27 Aug 2004 19:04:52 -0000 1.15 *************** *** 1,2 **** --- 1,5 ---- + # A lot of failures in these tests on Mac OS X. + # Byte order related? + import unittest from ctypes import * |
From: Thomas H. <th...@us...> - 2004-08-27 18:52:20
|
Update of /cvsroot/ctypes/ctypes/unittests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6531 Modified Files: test_cfuncs.py Log Message: Separated tests. Index: test_cfuncs.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_cfuncs.py,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** test_cfuncs.py 27 Aug 2004 18:41:36 -0000 1.13 --- test_cfuncs.py 27 Aug 2004 18:52:10 -0000 1.14 *************** *** 12,15 **** --- 12,16 ---- if os.path.isfile(f): return f + return None # These two functions report the argument in the last call to one of *************** *** 30,33 **** --- 31,36 ---- self.failUnlessEqual(self.dll.tf_b(-126), -42) self.failUnlessEqual(S(), -126) + + def test_byte_plus(self): self.dll.tf_bb.restype = c_byte self.dll.tf_bb.argtypes = (c_byte, c_byte) *************** *** 40,43 **** --- 43,48 ---- self.failUnlessEqual(self.dll.tf_B(255), 85) self.failUnlessEqual(U(), 255) + + def test_ubyte_plus(self): self.dll.tf_bB.restype = c_ubyte self.dll.tf_bB.argtypes = (c_byte, c_ubyte) *************** *** 49,52 **** --- 54,59 ---- self.failUnlessEqual(self.dll.tf_h(-32766), -10922) self.failUnlessEqual(S(), -32766) + + def test_short_plus(self): self.dll.tf_bh.restype = c_short self.failUnlessEqual(self.dll.tf_bh(0, -32766), -10922) *************** *** 57,60 **** --- 64,69 ---- self.failUnlessEqual(self.dll.tf_H(65535), 21845) self.failUnlessEqual(U(), 65535) + + def test_ushort_plus(self): self.dll.tf_bH.restype = c_ushort self.failUnlessEqual(self.dll.tf_bH(0, 65535), 21845) *************** *** 65,68 **** --- 74,79 ---- self.failUnlessEqual(self.dll.tf_i(-2147483646), -715827882) self.failUnlessEqual(S(), -2147483646) + + def test_int_plus(self): self.dll.tf_bi.restype = c_int self.failUnlessEqual(self.dll.tf_bi(0, -2147483646), -715827882) *************** *** 73,76 **** --- 84,89 ---- self.failUnlessEqual(self.dll.tf_I(4294967295), 1431655765) self.failUnlessEqual(U(), 4294967295) + + def test_uint_plus(self): self.dll.tf_bI.restype = c_uint self.failUnlessEqual(self.dll.tf_bI(0, 4294967295), 1431655765) *************** *** 82,85 **** --- 95,100 ---- self.failUnlessEqual(self.dll.tf_l(-2147483646), -715827882) self.failUnlessEqual(S(), -2147483646) + + def test_long_plus(self): self.dll.tf_bl.restype = c_long self.dll.tf_bl.argtypes = (c_byte, c_long) *************** *** 91,94 **** --- 106,111 ---- self.failUnlessEqual(self.dll.tf_L(4294967295), 1431655765) self.failUnlessEqual(U(), 4294967295) + + def test_ulong_plus(self): self.dll.tf_bL.restype = c_ulong self.failUnlessEqual(self.dll.tf_bL(0, 4294967295), 1431655765) *************** *** 100,103 **** --- 117,122 ---- self.failUnlessEqual(self.dll.tf_q(-9223372036854775806), -3074457345618258602) self.failUnlessEqual(S(), -9223372036854775806) + + def test_longlong_plus(self): self.dll.tf_bq.restype = c_longlong self.dll.tf_bq.argtypes = (c_byte, c_longlong) *************** *** 110,113 **** --- 129,134 ---- self.failUnlessEqual(self.dll.tf_Q(18446744073709551615), 6148914691236517205) self.failUnlessEqual(U(), 18446744073709551615) + + def test_ulonglong_plus(self): self.dll.tf_bQ.restype = c_ulonglong self.dll.tf_bQ.argtypes = (c_byte, c_ulonglong) *************** *** 120,123 **** --- 141,146 ---- self.failUnlessEqual(self.dll.tf_f(-42.), -14.) self.failUnlessEqual(S(), -42) + + def test_float_plus(self): self.dll.tf_bf.restype = c_float self.dll.tf_bf.argtypes = (c_byte, c_float) *************** *** 130,133 **** --- 153,158 ---- self.failUnlessEqual(self.dll.tf_d(42.), 14.) self.failUnlessEqual(S(), 42) + + def test_double_plus(self): self.dll.tf_bd.restype = c_double self.dll.tf_bd.argtypes = (c_byte, c_double) |