Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/security/krb5/ccache/EmptyRealmCC.java
38853 views
/*1* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 804807326* @summary Cannot read ccache entry with a realm-less service name27* @compile -XDignore.symbol.file EmptyRealmCC.java28* @run main EmptyRealmCC29*/30import java.nio.file.Files;31import java.nio.file.Paths;3233import sun.security.krb5.internal.ccache.CredentialsCache;3435public class EmptyRealmCC {36public static void main(String[] args) throws Exception {37byte[] ccache = TimeInCCache.ccache;3839// The service name starts at 0x52:40//41// 0050: 00 00 00 02 00 00 00 0A 4D 41 58 49 2E 4C42// ----------- -----------43// 0060: 4F 43 41 4C 00 00 00 06 6B 72 62 74 67 74 00 0044// ----------- -----45// 0070: 00 0A 4D 41 58 49 2E 4C 4F 43 41 4C46// -----47//48// which contains 2 (the length of names), a 10-byte realm, a 6-byte49// name[0], and a 10-byte name[1].5051// We will empty the realm, and pack the realm string to another52// name (6-byte ".LOCAL"). Finally "krbtgt/[email protected]"53// becomes ".LOCAL/krbtgt/MAXI.LOCAL@".5455// length of names is now 356ccache[0x55] = 3;57// The empty realm58System.arraycopy(new byte[4], 0, ccache, 0x56, 4);59// Length of inserted name is 660System.arraycopy(new byte[]{0,0,0,6}, 0, ccache, 0x5A, 4);6162Files.write(Paths.get("tmpcc"), TimeInCCache.ccache);63if (CredentialsCache.getInstance("tmpcc").getCredsList() != null) {64throw new Exception("Nothing should be there");65}66}67}686970