Path: blob/master/test/jdk/sun/security/krb5/ccache/EmptyRealmCC.java
41155 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* @modules java.security.jgss/sun.security.krb528* java.security.jgss/sun.security.krb5.internal.ccache29* @compile -XDignore.symbol.file EmptyRealmCC.java30* @run main EmptyRealmCC31*/32import java.nio.file.Files;33import java.nio.file.Paths;3435import sun.security.krb5.internal.ccache.CredentialsCache;3637public class EmptyRealmCC {38public static void main(String[] args) throws Exception {39byte[] ccache = TimeInCCache.ccache;4041// The service name starts at 0x52:42//43// 0050: 00 00 00 02 00 00 00 0A 4D 41 58 49 2E 4C44// ----------- -----------45// 0060: 4F 43 41 4C 00 00 00 06 6B 72 62 74 67 74 00 0046// ----------- -----47// 0070: 00 0A 4D 41 58 49 2E 4C 4F 43 41 4C48// -----49//50// which contains 2 (the length of names), a 10-byte realm, a 6-byte51// name[0], and a 10-byte name[1].5253// We will empty the realm, and pack the realm string to another54// name (6-byte ".LOCAL"). Finally "krbtgt/[email protected]"55// becomes ".LOCAL/krbtgt/MAXI.LOCAL@".5657// length of names is now 358ccache[0x55] = 3;59// The empty realm60System.arraycopy(new byte[4], 0, ccache, 0x56, 4);61// Length of inserted name is 662System.arraycopy(new byte[]{0,0,0,6}, 0, ccache, 0x5A, 4);6364Files.write(Paths.get("tmpcc"), TimeInCCache.ccache);65if (CredentialsCache.getInstance("tmpcc").getCredsList() != null) {66throw new Exception("Nothing should be there");67}68}69}707172