[kaffe] CVS kaffe (robilad): Resynced with GNU inetlib: small fixes for ftp & http handlers and a comsat hand
Kaffe CVS
cvs-commits at kaffe.org
Sun Oct 10 11:14:28 PDT 2004
PatchSet 5263
Date: 2004/10/10 17:57:28
Author: robilad
Branch: HEAD
Tag: (none)
Log:
Resynced with GNU inetlib: small fixes for ftp & http handlers and a comsat handler
2004-10-10 Dalibor Topic <robilad at kaffe.org>
* libraries/javalib/Makefile.am,
libraries/javalib/Makefile.in,
libraries/javalib/all.files:
Regenerated.
* libraries/javalib/gnu/inet/comsat/ComsatClient.java,
libraries/javalib/gnu/inet/comsat/ComsatInfo.java:
New files, taken from GNU inetlib.
* libraries/javalib/gnu/inet/ftp/FTPConnection.java,
libraries/javalib/gnu/inet/ftp/package.html,
libraries/javalib/gnu/inet/http/ChunkedInputStream.java:
Resynced with GNU inetlib.
2004-10-05 Chris Burdess <dog at bluezoo.org>
* ChunkedInputStream.java: Permit EOF before CRLF.
* FTPConnection.java: Implement FTP/TLS.
* comsat: Experimental comsat client.
Members:
ChangeLog:1.2816->1.2817
libraries/javalib/Makefile.am:1.248->1.249
libraries/javalib/Makefile.in:1.328->1.329
libraries/javalib/all.files:1.36->1.37
libraries/javalib/gnu/inet/comsat/ComsatClient.java:INITIAL->1.1
libraries/javalib/gnu/inet/comsat/ComsatInfo.java:INITIAL->1.1
libraries/javalib/gnu/inet/ftp/FTPConnection.java:1.5->1.6
libraries/javalib/gnu/inet/ftp/package.html:1.1->1.2
libraries/javalib/gnu/inet/http/ChunkedInputStream.java:1.3->1.4
Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.2816 kaffe/ChangeLog:1.2817
--- kaffe/ChangeLog:1.2816 Sun Oct 10 16:28:43 2004
+++ kaffe/ChangeLog Sun Oct 10 17:57:28 2004
@@ -1,5 +1,27 @@
2004-10-10 Dalibor Topic <robilad at kaffe.org>
+ * libraries/javalib/Makefile.am,
+ libraries/javalib/Makefile.in,
+ libraries/javalib/all.files:
+ Regenerated.
+
+ * libraries/javalib/gnu/inet/comsat/ComsatClient.java,
+ libraries/javalib/gnu/inet/comsat/ComsatInfo.java:
+ New files, taken from GNU inetlib.
+
+ * libraries/javalib/gnu/inet/ftp/FTPConnection.java,
+ libraries/javalib/gnu/inet/ftp/package.html,
+ libraries/javalib/gnu/inet/http/ChunkedInputStream.java:
+ Resynced with GNU inetlib.
+
+ 2004-10-05 Chris Burdess <dog at bluezoo.org>
+
+ * ChunkedInputStream.java: Permit EOF before CRLF.
+ * FTPConnection.java: Implement FTP/TLS.
+ * comsat: Experimental comsat client.
+
+2004-10-10 Dalibor Topic <robilad at kaffe.org>
+
* libraries/clib/awt/classpath-gtk/gtk-peer/gdkfont.h,
libraries/clib/awt/classpath-gtk/gtk-peer/gnu_java_awt_peer_gtk_GdkTextLayout.c:
Resynced with GNU Classpath.
Index: kaffe/libraries/javalib/Makefile.am
diff -u kaffe/libraries/javalib/Makefile.am:1.248 kaffe/libraries/javalib/Makefile.am:1.249
--- kaffe/libraries/javalib/Makefile.am:1.248 Sun Oct 10 14:28:19 2004
+++ kaffe/libraries/javalib/Makefile.am Sun Oct 10 17:57:34 2004
@@ -101,6 +101,7 @@
$(gnu_crypto_tool_keytool_SRCS) \
$(gnu_crypto_util_SRCS) \
$(gnu_getopt_SRCS) \
+ $(gnu_inet_comsat_SRCS) \
$(gnu_inet_finger_SRCS) \
$(gnu_inet_ftp_SRCS) \
$(gnu_inet_gopher_SRCS) \
@@ -784,6 +785,9 @@
gnu_getopt_SRCS = \
gnu/getopt/Getopt.java \
gnu/getopt/LongOpt.java
+gnu_inet_comsat_SRCS = \
+ gnu/inet/comsat/ComsatClient.java \
+ gnu/inet/comsat/ComsatInfo.java
gnu_inet_finger_SRCS = \
gnu/inet/finger/FingerConnection.java \
gnu/inet/finger/FingerURLConnection.java \
Index: kaffe/libraries/javalib/Makefile.in
diff -u kaffe/libraries/javalib/Makefile.in:1.328 kaffe/libraries/javalib/Makefile.in:1.329
--- kaffe/libraries/javalib/Makefile.in:1.328 Sun Oct 10 14:28:19 2004
+++ kaffe/libraries/javalib/Makefile.in Sun Oct 10 17:57:35 2004
@@ -442,6 +442,7 @@
$(gnu_crypto_tool_keytool_SRCS) \
$(gnu_crypto_util_SRCS) \
$(gnu_getopt_SRCS) \
+ $(gnu_inet_comsat_SRCS) \
$(gnu_inet_finger_SRCS) \
$(gnu_inet_ftp_SRCS) \
$(gnu_inet_gopher_SRCS) \
@@ -1172,6 +1173,10 @@
gnu_getopt_SRCS = \
gnu/getopt/Getopt.java \
gnu/getopt/LongOpt.java
+
+gnu_inet_comsat_SRCS = \
+ gnu/inet/comsat/ComsatClient.java \
+ gnu/inet/comsat/ComsatInfo.java
gnu_inet_finger_SRCS = \
gnu/inet/finger/FingerConnection.java \
Index: kaffe/libraries/javalib/all.files
diff -u kaffe/libraries/javalib/all.files:1.36 kaffe/libraries/javalib/all.files:1.37
--- kaffe/libraries/javalib/all.files:1.36 Sun Oct 10 14:28:20 2004
+++ kaffe/libraries/javalib/all.files Sun Oct 10 17:57:37 2004
@@ -419,6 +419,8 @@
gnu/crypto/util/Util.java
gnu/getopt/Getopt.java
gnu/getopt/LongOpt.java
+gnu/inet/comsat/ComsatClient.java
+gnu/inet/comsat/ComsatInfo.java
gnu/inet/finger/FingerConnection.java
gnu/inet/finger/FingerURLConnection.java
gnu/inet/finger/Handler.java
===================================================================
Checking out kaffe/libraries/javalib/gnu/inet/comsat/ComsatClient.java
RCS: /home/cvs/kaffe/kaffe/libraries/javalib/gnu/inet/comsat/ComsatClient.java,v
VERS: 1.1
***************
--- /dev/null Sun Aug 4 19:57:58 2002
+++ kaffe/libraries/javalib/gnu/inet/comsat/ComsatClient.java Sun Oct 10 18:14:27 2004
@@ -0,0 +1,138 @@
+/*
+ * $Id: ComsatClient.java,v 1.1 2004/10/10 17:57:38 robilad Exp $
+ * Copyright (C) 2004 The Free Software Foundation
+ *
+ * This file is part of GNU inetlib, a library.
+ *
+ * GNU inetlib is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * GNU inetlib is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * As a special exception, if you link this library with other files to
+ * produce an executable, this library does not by itself cause the
+ * resulting executable to be covered by the GNU General Public License.
+ * This exception does not however invalidate any other reasons why the
+ * executable file might be covered by the GNU General Public License.
+ */
+
+package gnu.inet.comsat;
+
+import java.io.IOException;
+import java.net.DatagramPacket;
+import java.net.DatagramSocket;
+import java.util.StringTokenizer;
+
+/**
+ * Simple comsat client.
+ *
+ * @author <a href='mailto:dog at gnu.org'>Chris Burdess</a>
+ */
+public class ComsatClient
+{
+
+ /**
+ * The default comsat port.
+ */
+ public static final int DEFAULT_PORT = 512;
+
+ protected DatagramSocket socket;
+
+ public ComsatClient ()
+ throws IOException
+ {
+ this (DEFAULT_PORT, 0);
+ }
+
+ public ComsatClient (int port, int timeout)
+ throws IOException
+ {
+ if (port < 0)
+ {
+ port = DEFAULT_PORT;
+ }
+
+ socket = new DatagramSocket (port);
+ if (timeout > 0)
+ {
+ socket.setSoTimeout (timeout);
+ }
+ socket.setReceiveBufferSize (1024);
+ }
+
+ public void close ()
+ throws IOException
+ {
+ socket.close ();
+ }
+
+ public ComsatInfo read ()
+ throws IOException
+ {
+ byte[] buf = new byte[socket.getReceiveBufferSize ()];
+ int len = buf.length;
+ DatagramPacket packet = new DatagramPacket (buf, len);
+ socket.receive (packet);
+ buf = packet.getData ();
+ len = packet.getLength ();
+ String data = new String (buf, 0, len, "ISO-8859-1");
+
+ ComsatInfo info = new ComsatInfo ();
+ StringTokenizer st = new StringTokenizer (data, "\n");
+ String mailbox = st.nextToken ();
+ info.setMailbox (mailbox);
+ boolean inBody = false;
+ String lastHeader = null;
+ while (st.hasMoreTokens ())
+ {
+ String line = st.nextToken ();
+ if (inBody)
+ {
+ String body = info.getBody ();
+ if (body == null)
+ {
+ body = line;
+ }
+ else
+ {
+ body += "\n" + line;
+ }
+ info.setBody (body);
+ }
+ else
+ {
+ if (line.length () == 0)
+ {
+ inBody = true;
+ }
+ else
+ {
+ int ci = line.indexOf (':');
+ if (ci != -1)
+ {
+ lastHeader = line.substring (0, ci);
+ info.setHeader (lastHeader,
+ line.substring (ci + 1).trim ());
+ }
+ else
+ {
+ String val = info.getHeader (lastHeader);
+ val += "\n" + line;
+ info.setHeader (lastHeader, val);
+ }
+ }
+ }
+ }
+ return info;
+ }
+
+}
===================================================================
Checking out kaffe/libraries/javalib/gnu/inet/comsat/ComsatInfo.java
RCS: /home/cvs/kaffe/kaffe/libraries/javalib/gnu/inet/comsat/ComsatInfo.java,v
VERS: 1.1
***************
--- /dev/null Sun Aug 4 19:57:58 2002
+++ kaffe/libraries/javalib/gnu/inet/comsat/ComsatInfo.java Sun Oct 10 18:14:28 2004
@@ -0,0 +1,92 @@
+/*
+ * $Id: ComsatInfo.java,v 1.1 2004/10/10 17:57:38 robilad Exp $
+ * Copyright (C) 2004 The Free Software Foundation
+ *
+ * This file is part of GNU inetlib, a library.
+ *
+ * GNU inetlib is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * GNU inetlib is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * As a special exception, if you link this library with other files to
+ * produce an executable, this library does not by itself cause the
+ * resulting executable to be covered by the GNU General Public License.
+ * This exception does not however invalidate any other reasons why the
+ * executable file might be covered by the GNU General Public License.
+ */
+
+package gnu.inet.comsat;
+
+import java.util.Iterator;
+import java.util.Map;
+import java.util.TreeMap;
+
+/**
+ * A comsat notification message.
+ *
+ * @author <a href='mailto:dog at gnu.org'>Chris Burdess</a>
+ */
+public class ComsatInfo
+{
+
+ /**
+ * The mailbox in which the new message appeared.
+ */
+ protected String mailbox;
+
+ /**
+ * The message headers.
+ */
+ protected Map headers;
+
+ /**
+ * The first few lines of the message body.
+ */
+ protected String body;
+
+ public String getMailbox ()
+ {
+ return mailbox;
+ }
+
+ protected void setMailbox (String mailbox)
+ {
+ this.mailbox = mailbox;
+ }
+
+ public String getHeader (String key)
+ {
+ return (String) headers.get (key);
+ }
+
+ public Iterator getHeaderNames ()
+ {
+ return headers.keySet ().iterator ();
+ }
+
+ protected void setHeader (String key, String value)
+ {
+ headers.put (key, value);
+ }
+
+ public String getBody ()
+ {
+ return body;
+ }
+
+ protected void setBody (String body)
+ {
+ this.body = body;
+ }
+
+}
Index: kaffe/libraries/javalib/gnu/inet/ftp/FTPConnection.java
diff -u kaffe/libraries/javalib/gnu/inet/ftp/FTPConnection.java:1.5 kaffe/libraries/javalib/gnu/inet/ftp/FTPConnection.java:1.6
--- kaffe/libraries/javalib/gnu/inet/ftp/FTPConnection.java:1.5 Mon Oct 4 19:33:56 2004
+++ kaffe/libraries/javalib/gnu/inet/ftp/FTPConnection.java Sun Oct 10 17:57:38 2004
@@ -1,5 +1,5 @@
/*
- * $Id: FTPConnection.java,v 1.5 2004/10/04 19:33:56 robilad Exp $
+ * $Id: FTPConnection.java,v 1.6 2004/10/10 17:57:38 robilad Exp $
* Copyright (C) 2003 The Free Software Foundation
*
* This file is part of GNU inetlib, a library.
@@ -38,10 +38,18 @@
import java.net.ProtocolException;
import java.net.Socket;
import java.net.UnknownHostException;
+import java.security.GeneralSecurityException;
import java.util.ArrayList;
import java.util.List;
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.SSLSocket;
+import javax.net.ssl.SSLSocketFactory;
+import javax.net.ssl.TrustManager;
+
import gnu.inet.util.CRLFInputStream;
+import gnu.inet.util.CRLFOutputStream;
+import gnu.inet.util.EmptyX509TrustManager;
import gnu.inet.util.LineInputStream;
/**
@@ -54,7 +62,7 @@
* </ul>
*
* @author <a href='mailto:dog at gnu.org'>Chris Burdess</a>
- * @version $Revision: 1.5 $ $Date: 2004/10/04 19:33:56 $
+ * @version $Revision: 1.6 $ $Date: 2004/10/10 17:57:38 $
*/
public class FTPConnection
{
@@ -105,6 +113,12 @@
protected static final String STAT = "STAT";
protected static final String HELP = "HELP";
protected static final String NOOP = "NOOP";
+
+ protected static final String AUTH = "AUTH";
+ protected static final String PBSZ = "PBSZ";
+ protected static final String PROT = "PROT";
+ protected static final String CCC = "CCC";
+ protected static final String TLS = "TLS";
public static final int TYPE_ASCII = 1;
public static final int TYPE_EBCDIC = 2;
@@ -120,7 +134,6 @@
// -- Telnet constants --
private static final String US_ASCII = "US-ASCII";
- private static final byte[] CRLF = { 0x0d, 0x0a };
/**
* The socket used to communicate with the server.
@@ -135,7 +148,7 @@
/**
* The socket output stream.
*/
- protected OutputStream out;
+ protected CRLFOutputStream out;
/**
* The timeout when attempting to connect a socket.
@@ -239,7 +252,8 @@
in = new CRLFInputStream (in);
this.in = new LineInputStream (in);
OutputStream out = socket.getOutputStream ();
- this.out = new BufferedOutputStream (out);
+ out = new BufferedOutputStream (out);
+ this.out = new CRLFOutputStream (out);
// Read greeting
FTPResponse response = getResponse ();
@@ -293,6 +307,109 @@
throw new FTPException (response);
}
}
+
+ /**
+ * Negotiates TLS over the current connection.
+ * See IETF draft-murray-auth-ftp-ssl-15.txt for details.
+ * @param confidential whether to provide confidentiality for the
+ * connection
+ */
+ public boolean starttls (boolean confidential)
+ throws IOException
+ {
+ return starttls (confidential, new EmptyX509TrustManager ());
+ }
+
+ /**
+ * Negotiates TLS over the current connection.
+ * See IETF draft-murray-auth-ftp-ssl-15.txt for details.
+ * @param confidential whether to provide confidentiality for the
+ * connection
+ * @param tm the trust manager used to validate the server certificate.
+ */
+ public boolean starttls (boolean confidential, TrustManager tm)
+ throws IOException
+ {
+ try
+ {
+ // Use SSLSocketFactory to negotiate a TLS session and wrap the
+ // current socket.
+ SSLContext context = SSLContext.getInstance ("TLS");
+ // We don't require strong validation of the server certificate
+ TrustManager[] trust = new TrustManager[] { tm };
+ context.init (null, trust, null);
+ SSLSocketFactory factory = context.getSocketFactory ();
+
+ send (AUTH + ' ' + TLS);
+ FTPResponse response = getResponse ();
+ switch (response.getCode ())
+ {
+ case 500:
+ case 502:
+ case 504:
+ case 534:
+ case 431:
+ return false;
+ case 234:
+ break;
+ default:
+ throw new FTPException (response);
+ }
+
+ String hostname = socket.getInetAddress ().getHostName ();
+ int port = socket.getPort ();
+ SSLSocket ss =
+ (SSLSocket) factory.createSocket (socket, hostname, port, true);
+ String[] protocols = { "TLSv1", "SSLv3" };
+ ss.setEnabledProtocols (protocols);
+ ss.setUseClientMode (true);
+ ss.startHandshake ();
+
+ // PBSZ:PROT sequence
+ send (PBSZ + ' ' + Integer.MAX_VALUE);
+ response = getResponse ();
+ switch (response.getCode ())
+ {
+ case 501: // syntax error
+ case 503: // not authenticated
+ return false;
+ case 200:
+ break;
+ default:
+ throw new FTPException (response);
+ }
+ send (PROT + ' ' + (confidential ? 'P' : 'C'));
+ response = getResponse ();
+ switch (response.getCode ())
+ {
+ case 503: // not authenticated
+ case 504: // invalid level
+ case 536: // level not supported
+ return false;
+ case 200:
+ break;
+ default:
+ throw new FTPException (response);
+ }
+
+ if (confidential)
+ {
+ // Set up streams
+ InputStream in = ss.getInputStream ();
+ in = new BufferedInputStream (in);
+ in = new CRLFInputStream (in);
+ this.in = new LineInputStream (in);
+ OutputStream out = ss.getOutputStream ();
+ out = new BufferedOutputStream (out);
+ this.out = new CRLFOutputStream (out);
+ }
+ return true;
+ }
+ catch (GeneralSecurityException e)
+ {
+ return false;
+ }
+ }
/**
* Changes directory to the specified path.
@@ -1104,7 +1221,7 @@
{
byte[] data = cmd.getBytes (US_ASCII);
out.write (data);
- out.write (CRLF);
+ out.writeln ();
out.flush ();
}
Index: kaffe/libraries/javalib/gnu/inet/ftp/package.html
diff -u kaffe/libraries/javalib/gnu/inet/ftp/package.html:1.1 kaffe/libraries/javalib/gnu/inet/ftp/package.html:1.2
--- kaffe/libraries/javalib/gnu/inet/ftp/package.html:1.1 Sun Jul 25 22:46:18 2004
+++ kaffe/libraries/javalib/gnu/inet/ftp/package.html Sun Oct 10 17:57:39 2004
@@ -10,4 +10,9 @@
concurrent stream (input or output) is supported.
</p>
+<p>
+The control connection to the server can be protected using TLS
+(the starttls method).
+</p>
+
</body>
Index: kaffe/libraries/javalib/gnu/inet/http/ChunkedInputStream.java
diff -u kaffe/libraries/javalib/gnu/inet/http/ChunkedInputStream.java:1.3 kaffe/libraries/javalib/gnu/inet/http/ChunkedInputStream.java:1.4
--- kaffe/libraries/javalib/gnu/inet/http/ChunkedInputStream.java:1.3 Mon Oct 4 19:33:58 2004
+++ kaffe/libraries/javalib/gnu/inet/http/ChunkedInputStream.java Sun Oct 10 17:57:41 2004
@@ -1,5 +1,5 @@
/*
- * $Id: ChunkedInputStream.java,v 1.3 2004/10/04 19:33:58 robilad Exp $
+ * $Id: ChunkedInputStream.java,v 1.4 2004/10/10 17:57:41 robilad Exp $
* Copyright (C) 2004 The Free Software Foundation
*
* This file is part of GNU inetlib, a library.
@@ -141,6 +141,12 @@
// Read CRLF
int c1 = in.read ();
int c2 = in.read ();
+ if (c1 == -1 && c2 == -1)
+ {
+ // EOF before CRLF: bad, but ignore
+ eof = true;
+ return -1;
+ }
if (c1 != 0x0d || c2 != 0x0a)
{
throw new ProtocolException ("expecting CRLF: " + c1 + "," + c2);
More information about the kaffe
mailing list