²diff -Nru /home/ftp/pub/apache.org/jakarta-tomcat-connectors/jk/src/java/org/apache/ajp/Ajp13.java /home/ftp/pub/apache.org/jakarta-tomcat-connectors/jk/src/java/org/apache/ajp/Ajp13.java --- /home/ftp/pub/apache.org/jakarta-tomcat-connectors/jk/src/java/org/apache/ajp/Ajp13.java Wed May 30 03:34:09 2001 +++ /home/ftp/pub/apache.org/jakarta-tomcat-connectors/jk/src/java/org/apache/ajp/Ajp13.java Tue Jun 5 16:43:46 2001 @@ -89,6 +89,7 @@ * @author Dan Milstein [danmil@shore.net] * @author Keith Wannamaker [Keith@Wannamaker.org] * @author Kevin Seguin [seguin@apache.org] + * @author Henri Gomez [hgomez@slib.fr] */ public class Ajp13 { @@ -138,6 +139,9 @@ // Terminates list of attributes public static final byte SC_A_ARE_DONE = (byte)0xFF; + // Indicate that SSL info was found in Extra Decode + public static final int DECODED_SSL_INFO = 0x0001; + // Translates integer codes to names of HTTP methods public static final String []methodTransArray = { "OPTIONS", @@ -198,11 +202,11 @@ InputStream in; // Buffer used of output body and headers - Ajp13Packet outBuf = new Ajp13Packet( MAX_PACKET_SIZE ); + Ajp13Packet outBuf; // Buffer used for input body - Ajp13Packet inBuf = new Ajp13Packet( MAX_PACKET_SIZE ); + Ajp13Packet inBuf; // Buffer used for request head ( and headers ) - Ajp13Packet hBuf=new Ajp13Packet( MAX_PACKET_SIZE ); + Ajp13Packet hBuf; // Holds incoming reads of request body data (*not* header data) byte []bodyBuff = new byte[MAX_READ_SIZE]; @@ -227,6 +231,12 @@ } } + public Ajp13() { + outBuf = new Ajp13Packet( MAX_PACKET_SIZE ); + inBuf = new Ajp13Packet( MAX_PACKET_SIZE ); + hBuf = new Ajp13Packet( MAX_PACKET_SIZE ); + } + public void recycle() { if (debug > 0) { logger.log("recycle()"); @@ -251,6 +261,10 @@ pos = 0; } + public int decodeExtra(byte ac, Ajp13Packet msg, AjpRequest req) { + return (500); + } + /** * Read a new packet from the web server and decode it. If it's a * forwarded request, store its properties in the passed-in AjpRequest @@ -409,8 +423,17 @@ msg.getString()); break; + // Second chance to decode unknown attributes + // AJP14 will use it :) default: - return 500; // Error + int dcd = decodeExtra(attributeCode, msg, req); + if (dcd < 0) + return 500; // Error + + if ((dcd & DECODED_SSL_INFO) != 0) + isSSL = true; + + break; } } diff -Nru /home/ftp/pub/apache.org/jakarta-tomcat-connectors/jk/src/java/org/apache/ajp/Ajp13Packet.java /home/ftp/pub/apache.org/jakarta-tomcat-connectors/jk/src/java/org/apache/ajp/Ajp13Packet.java --- /home/ftp/pub/apache.org/jakarta-tomcat-connectors/jk/src/java/org/apache/ajp/Ajp13Packet.java Wed May 30 03:34:10 2001 +++ /home/ftp/pub/apache.org/jakarta-tomcat-connectors/jk/src/java/org/apache/ajp/Ajp13Packet.java Tue Jun 5 16:45:36 2001 @@ -69,10 +69,17 @@ * garbage. Understands the format of data types for these packets. * Can be used (somewhat confusingly) for both incoming and outgoing * packets. + * + * @author Dan Milstein [danmil@shore.net] + * @author Keith Wannamaker [Keith@Wannamaker.org] + * @author Kevin Seguin [seguin@apache.org] + * @author Henri Gomez [hgomez@slib.fr] */ public class Ajp13Packet { public static final String DEFAULT_CHAR_ENCODING = "8859_1"; + public static final int AJP13_WS_HEADER = 0x1234; + public static final int AJP13_SW_HEADER = 0x4142; // 'AB' /** * encoding to use when converting byte[] <-> string @@ -179,7 +186,7 @@ int mark = getInt(); len = getInt(); - if( mark != 0x1234 ) { + if( mark != AJP13_WS_HEADER ) { // XXX Logging System.out.println("BAD packet " + mark); dump( "In: " ); @@ -196,8 +203,8 @@ public void reset() { len = 4; pos = 4; - buff[0] = (byte)'A'; - buff[1] = (byte)'B'; + buff[0] = (byte)(AJP13_WS_HEADER >> 8); + buff[1] = (byte)(AJP13_WS_HEADER & 0xFF); } /** diff -Nru /home/ftp/pub/apache.org/jakarta-tomcat-connectors/jk/src/java/org/apache/ajp/Ajp14.java /home/ftp/pub/apache.org/jakarta-tomcat-connectors/jk/src/java/org/apache/ajp/Ajp14.java --- /home/ftp/pub/apache.org/jakarta-tomcat-connectors/jk/src/java/org/apache/ajp/Ajp14.java Thu Jan 1 01:00:00 1970 +++ /home/ftp/pub/apache.org/jakarta-tomcat-connectors/jk/src/java/org/apache/ajp/Ajp14.java Tue Jun 5 16:44:17 2001 @@ -0,0 +1,117 @@ +/* + * ==================================================================== + * + * The Apache Software License, Version 1.1 + * + * Copyright (c) 1999 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", "Tomcat", 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 apache@apache.org. + * + * 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 + * . + * + * [Additional notices, if required by prior licensing conditions] + * + */ + +package org.apache.ajp; + +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.Socket; +import java.util.Enumeration; + +import org.apache.tomcat.util.buf.MessageBytes; +import org.apache.tomcat.util.buf.ByteChunk; +import org.apache.tomcat.util.http.MimeHeaders; +import org.apache.tomcat.util.http.HttpMessages; + +/** + * Represents a single, persistent connection between the web server and + * the servlet container. Uses the Apache JServ Protocol version 1.3 for + * communication. Because this protocal does not multiplex requests, this + * connection can only be associated with a single request-handling cycle + * at a time.

+ * + * This class contains knowledge about how an individual packet is laid out + * (via the Ajp14Packet class), and also about the + * stages of communicaton between the server and the servlet container. It + * translates from Tomcat's internal servlet support methods + * (e.g. doWrite) to the correct packets to send to the web server. + * + * @see Ajp14Interceptor + * + * @author Dan Milstein [danmil@shore.net] + * @author Keith Wannamaker [Keith@Wannamaker.org] + * @author Kevin Seguin [seguin@apache.org] + * @author Henri Gomez [hgomez@slib.fr] + */ +public class Ajp14 extends Ajp13 { + + // SSL_KEY_SIZE as required by Servlet 2.3 API + public static final byte SC_A_SSL_KEY_SIZE = 11; + + public Ajp14() { + outBuf = new Ajp14Packet( MAX_PACKET_SIZE ); + inBuf = new Ajp14Packet( MAX_PACKET_SIZE ); + hBuf = new Ajp14Packet( MAX_PACKET_SIZE ); + } + + public int decodeExtra(byte ac, Ajp13Packet msg, AjpRequest req) { + switch (ac) { + + case SC_A_SSL_KEY_SIZE : // Servlet API 2.3 (at least Proposed Final Draft 2) require key_size + req.setAttribute("javax.servlet.request.key_size", + Integer.toString(msg.getInt())); + return DECODED_SSL_INFO; + + default: + return 500; // Error + } + } +} diff -Nru /home/ftp/pub/apache.org/jakarta-tomcat-connectors/jk/src/java/org/apache/ajp/Ajp14Packet.java /home/ftp/pub/apache.org/jakarta-tomcat-connectors/jk/src/java/org/apache/ajp/Ajp14Packet.java --- /home/ftp/pub/apache.org/jakarta-tomcat-connectors/jk/src/java/org/apache/ajp/Ajp14Packet.java Thu Jan 1 01:00:00 1970 +++ /home/ftp/pub/apache.org/jakarta-tomcat-connectors/jk/src/java/org/apache/ajp/Ajp14Packet.java Tue Jun 5 16:46:05 2001 @@ -0,0 +1,131 @@ +/* + * ==================================================================== + * + * The Apache Software License, Version 1.1 + * + * Copyright (c) 1999 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", "Tomcat", 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 apache@apache.org. + * + * 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 + * . + * + * [Additional notices, if required by prior licensing conditions] + * + */ +package org.apache.ajp; + +import java.io.UnsupportedEncodingException; + +import org.apache.tomcat.util.buf.MessageBytes; +import org.apache.tomcat.util.http.MimeHeaders; + +/** + * A single packet for communication between the web server and the + * container. Designed to be reused many times with no creation of + * garbage. Understands the format of data types for these packets. + * Can be used (somewhat confusingly) for both incoming and outgoing + * packets. + * + * @author Kevin Seguin [seguin@apache.org] + * @author Henri Gomez [hgomez@slib.fr] + */ +public class Ajp14Packet extends Ajp13Packet { + + public static final String DEFAULT_CHAR_ENCODING = "8859_1"; + public static final int AJP14_WS_HEADER = 0x1235; + public static final int AJP14_SW_HEADER = 0x4143; // 'AC' + + /** + * Create a new packet with an internal buffer of given size. + * @param size packet size + */ + public Ajp14Packet( int size ) { + super(size); + } + + /** + * Create a new packet with given bytes + * @param b this packet's bytes. + */ + public Ajp14Packet( byte b[] ) { + super(b); + } + + /** + * Parse the packet header for a packet sent from the web server to + * the container. Set the read position to immediately after + * the header. + * + * @return The length of the packet payload, as encoded in the + * header, or -1 if the packet doesn't have a valid header. + */ + public int checkIn() { + pos = 0; + int mark = getInt(); + len = getInt(); + + if( mark != AJP14_WS_HEADER ) { + // XXX Logging + System.out.println("BAD packet " + mark); + dump( "In: " ); + return -1; + } + return len; + } + + /** + * Prepare this packet for accumulating a message from the container to + * the web server. Set the write position to just after the header + * (but leave the length unwritten, because it is as yet unknown). + */ + public void reset() { + len = 4; + pos = 4; + buff[0] = (byte)(AJP14_SW_HEADER >> 8); + buff[1] = (byte)(AJP14_SW_HEADER & 0xFF); + } +} diff -Nru /home/ftp/pub/apache.org/jakarta-tomcat-connectors/jk/src/java/org/apache/ajp/test/TestAjp13.java /home/ftp/pub/apache.org/jakarta-tomcat-connectors/jk/src/java/org/apache/ajp/test/TestAjp13.java --- /home/ftp/pub/apache.org/jakarta-tomcat-connectors/jk/src/java/org/apache/ajp/test/TestAjp13.java Mon Jun 4 00:11:32 2001 +++ /home/ftp/pub/apache.org/jakarta-tomcat-connectors/jk/src/java/org/apache/ajp/test/TestAjp13.java Tue Jun 5 16:33:25 2001 @@ -41,7 +41,7 @@ Socket s = new Socket("localhost", 8009); Ajp13Packet p = new Ajp13Packet(Ajp13.MAX_PACKET_SIZE); - p.appendInt(0x1234); + p.appendInt(Ajp13Packet.AJP13_WS_HEADER); p.appendInt(0); p.setByteOff(4); p.appendByte(Ajp13.JK_AJP13_FORWARD_REQUEST); @@ -80,9 +80,9 @@ // first 2 bytes should be AB b1 = is.read(); - assertTrue("byte 1 was " + (char)b1, b1 == (int)'A'); + assertTrue("byte 1 was " + (char)b1, b1 == (int)(Ajp13Packet.AJP13_SW_HEADER >> 8)); b2 = is.read(); - assertTrue("byte 2 was " + (char)b2, b2 == (int)'B'); + assertTrue("byte 2 was " + (char)b2, b2 == (int)(Ajp13Packet.AJP13_SW_HEADER & 0xFF)); println("b1 = " + (char)b1 + "; b2 = " + (char)b2);