12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /** 25 * @test 26 * @bug 8035807 27 * @summary Confirm that old and new Base64 encodings are compatible. 28 * @modules java.base/sun.misc 29 */ 30 31 import java.io.*; 32 import java.util.*; 33 import javax.naming.*; 34 import javax.naming.directory.*; 35 36 import sun.misc.BASE64Decoder; 37 38 /* 39 * RFC 2713 specifies an encoding for Java objects stored in an LDAP directory. 40 * Section 3.6 specifies how a binary-valued JNDI RefAddr object is encoded 41 * in the value of a javaReferenceAttribute LDAP attribute: first the RefAddr 42 * object is serialized and then it is encoded using Base64. 43 * 44 * Since JDK 9, the JNDI/LDAP provider uses the public Base64 encoder which 45 * adheres strictly to the MIME encoding rules. The encoder inserts '\r\n' 46 * as the line separator at intervals of 76 characters. Previously the 47 * JNDI/LDAP provider used a private Base64 encoder which inserted '\n' 48 * as the line separator. It is a compatible change. 49 * 50 * This test demonstrates that there is no compatability problem when 51 * encoding and decoding using either Base64 coder: 52 * 53 * encode with s.m.BASE64Encoder, decode with s.m.BASE64Decoder => OK 54 * encode with s.m.BASE64Encoder, decode with j.u.Base64.Decoder => OK 55 * encode with j.u.Base64.Encoder, decode with s.m.BASE64Decoder => OK 56 * encode with j.u.Base64.Encoder, decode with j.u.Base64.Decoder => OK 57 * 58 * 59 * NOTE: The two Base64 encodings used in this test were captured from 60 * LDAP protocol exchanges during attempts by the JNDI/LDAP provider 61 * to store a JNDI Reference test object. 62 */ 63 64 public class Base64Test { 65 /* 66 * The old Base64 encoding uses '\n' as the line separator at 76 character 67 * intervals: 68 * 69 * 0000: 72 4F 30 41 42 58 4E 79 41 42 70 71 59 58 5A 68 rO0ABXNyABpqYXZh 70 * 0010: 65 43 35 75 59 57 31 70 62 6D 63 75 51 6D 6C 75 eC5uYW1pbmcuQmlu 71 * 0020: 59 58 4A 35 55 6D 56 6D 51 57 52 6B 63 74 43 61 YXJ5UmVmQWRkctCa 72 * 0030: 6B 37 4C 65 73 34 68 48 41 67 41 42 57 77 41 44 k7Les4hHAgABWwAD 73 * 0040: 59 6E 56 6D 64 41 41 43 57 30 4A 34 0A 63 67 41 YnVmdAACW0J4.cgA < 74 * 0050: 55 61 6D 46 32 59 58 67 75 62 6D 46 74 61 57 35 UamF2YXgubmFtaW5 75 * 0060: 6E 4C 6C 4A 6C 5A 6B 46 6B 5A 48 4C 72 6F 41 65 nLlJlZkFkZHLroAe 76 * 0070: 61 41 6A 69 76 53 67 49 41 41 55 77 41 43 47 46 aAjivSgIAAUwACGF 131 */ 132 private static final RefAddr BINARY_REF_ADDR = 133 new BinaryRefAddr("test", new byte[] { 134 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 135 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 136 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 137 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 138 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 139 0x3C, 0x3D, 0x3E, 0x3F, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 140 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, 0x51, 0x52, 0x53, 141 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F, 142 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x6B, 143 0x6C, 0x6D, 0x6E, 0x6F, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 144 0x78, 0x79, 0x7A, 0x7B, 0x7C, 0x7D, 0x7E, 0x7F 145 }); 146 147 public static void main(String[] args) throws Exception { 148 149 System.out.println("\nOriginal RefAddr object:\n" + BINARY_REF_ADDR); 150 System.out.println("Old Base64 encoded serialized RefAddr object:\n" + 151 OLD_ENCODING); 152 System.out.println("Decode using old Base64 decoder..."); 153 deserialize(new BASE64Decoder().decodeBuffer(OLD_ENCODING)); 154 155 System.out.println("----"); 156 157 System.out.println("\nOriginal RefAddr object:\n" + BINARY_REF_ADDR); 158 System.out.println("Old Base64 encoded serialized RefAddr object:\n" + 159 OLD_ENCODING); 160 System.out.println("Decode using new Base64 decoder..."); 161 deserialize(new BASE64Decoder().decodeBuffer(OLD_ENCODING)); 162 163 System.out.println("----"); 164 165 System.out.println("\nOriginal RefAddr object:\n" + BINARY_REF_ADDR); 166 System.out.println("New Base64 encoded serialized RefAddr object:\n" + 167 NEW_ENCODING + "\n"); 168 System.out.println("Decode using old Base64 decoder..."); 169 deserialize(new BASE64Decoder().decodeBuffer(OLD_ENCODING)); 170 171 System.out.println("----"); 172 173 System.out.println("\nOriginal RefAddr object:\n" + BINARY_REF_ADDR); 174 System.out.println("New Base64 encoded serialized RefAddr object:\n" + 175 NEW_ENCODING + "\n"); 176 System.out.println("Decode using new Base64 decoder..."); 177 deserialize(Base64.getMimeDecoder().decode(NEW_ENCODING)); 178 179 System.out.println("----"); 180 } 181 182 /* 183 * Deserialize the decoded Base64 bytes to recover the BinaryRefAddr object. 184 */ 185 private static void deserialize(byte[] bytes) throws Exception { 186 187 //System.out.println("\nSerialized RefAddr object: "); 188 //System.out.println(new sun.misc.HexDumpEncoder().encode(bytes)); 189 | 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /** 25 * @test 26 * @bug 8035807 27 * @summary Confirm that old and new Base64 encodings are compatible. 28 * @modules java.base/sun.misc 29 */ 30 31 import java.io.*; 32 import java.lang.reflect.Method; 33 import java.util.*; 34 import javax.naming.*; 35 import javax.naming.directory.*; 36 37 /* 38 * RFC 2713 specifies an encoding for Java objects stored in an LDAP directory. 39 * Section 3.6 specifies how a binary-valued JNDI RefAddr object is encoded 40 * in the value of a javaReferenceAttribute LDAP attribute: first the RefAddr 41 * object is serialized and then it is encoded using Base64. 42 * 43 * Since JDK 9, the JNDI/LDAP provider uses the public Base64 encoder which 44 * adheres strictly to the MIME encoding rules. The encoder inserts '\r\n' 45 * as the line separator at intervals of 76 characters. Previously the 46 * JNDI/LDAP provider used a private Base64 encoder which inserted '\n' 47 * as the line separator. It is a compatible change. 48 * 49 * This test demonstrates that there is no compatability problem when 50 * decoding using the new Base64 coder: 51 * 52 * encoded bytes captured from s.m.BASE64Encoder, decode with j.u.Base64.Decoder => OK 53 * encoded bytes captured from j.u.Base64.Encoder, decode with j.u.Base64.Decoder => OK 54 * 55 * 56 * NOTE: The two Base64 encodings used in this test were captured from 57 * LDAP protocol exchanges during attempts by the JNDI/LDAP provider 58 * to store a JNDI Reference test object. 59 */ 60 61 public class Base64Test { 62 /* 63 * The old Base64 encoding uses '\n' as the line separator at 76 character 64 * intervals: 65 * 66 * 0000: 72 4F 30 41 42 58 4E 79 41 42 70 71 59 58 5A 68 rO0ABXNyABpqYXZh 67 * 0010: 65 43 35 75 59 57 31 70 62 6D 63 75 51 6D 6C 75 eC5uYW1pbmcuQmlu 68 * 0020: 59 58 4A 35 55 6D 56 6D 51 57 52 6B 63 74 43 61 YXJ5UmVmQWRkctCa 69 * 0030: 6B 37 4C 65 73 34 68 48 41 67 41 42 57 77 41 44 k7Les4hHAgABWwAD 70 * 0040: 59 6E 56 6D 64 41 41 43 57 30 4A 34 0A 63 67 41 YnVmdAACW0J4.cgA < 71 * 0050: 55 61 6D 46 32 59 58 67 75 62 6D 46 74 61 57 35 UamF2YXgubmFtaW5 72 * 0060: 6E 4C 6C 4A 6C 5A 6B 46 6B 5A 48 4C 72 6F 41 65 nLlJlZkFkZHLroAe 73 * 0070: 61 41 6A 69 76 53 67 49 41 41 55 77 41 43 47 46 aAjivSgIAAUwACGF 128 */ 129 private static final RefAddr BINARY_REF_ADDR = 130 new BinaryRefAddr("test", new byte[] { 131 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 132 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 133 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 134 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 135 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 136 0x3C, 0x3D, 0x3E, 0x3F, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 137 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, 0x51, 0x52, 0x53, 138 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F, 139 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x6B, 140 0x6C, 0x6D, 0x6E, 0x6F, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 141 0x78, 0x79, 0x7A, 0x7B, 0x7C, 0x7D, 0x7E, 0x7F 142 }); 143 144 public static void main(String[] args) throws Exception { 145 146 System.out.println("\nOriginal RefAddr object:\n" + BINARY_REF_ADDR); 147 System.out.println("Old Base64 encoded serialized RefAddr object:\n" + 148 OLD_ENCODING + "\n"); 149 System.out.println("Decode using new Base64 decoder..."); 150 deserialize(Base64.getMimeDecoder().decode(OLD_ENCODING)); 151 152 System.out.println("----"); 153 154 System.out.println("\nOriginal RefAddr object:\n" + BINARY_REF_ADDR); 155 System.out.println("New Base64 encoded serialized RefAddr object:\n" + 156 NEW_ENCODING + "\n"); 157 System.out.println("Decode using new Base64 decoder..."); 158 deserialize(Base64.getMimeDecoder().decode(NEW_ENCODING)); 159 160 System.out.println("----"); 161 } 162 163 /* 164 * Deserialize the decoded Base64 bytes to recover the BinaryRefAddr object. 165 */ 166 private static void deserialize(byte[] bytes) throws Exception { 167 168 //System.out.println("\nSerialized RefAddr object: "); 169 //System.out.println(new sun.misc.HexDumpEncoder().encode(bytes)); 170 |