Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/sun/security/krb5/ktab/BufferBoundary.java
41155 views
1
/*
2
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
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
* @test
25
* @bug 8201867
26
* @summary Kerberos keytabs with holes in certain places are parsed incorrectly
27
* @modules java.security.jgss/sun.security.krb5
28
* java.security.jgss/sun.security.krb5.internal.ktab
29
* @run main/othervm BufferBoundary
30
*/
31
32
import sun.security.krb5.PrincipalName;
33
import sun.security.krb5.internal.ktab.KeyTab;
34
import sun.security.krb5.internal.ktab.KeyTabEntry;
35
import sun.security.krb5.internal.ktab.KeyTabInputStream;
36
import sun.security.krb5.internal.ktab.KeyTabOutputStream;
37
38
import java.io.FileInputStream;
39
import java.io.FileOutputStream;
40
import java.io.IOException;
41
import java.nio.file.Files;
42
import java.nio.file.Paths;
43
import java.util.List;
44
45
public class BufferBoundary {
46
public static void main(String[] args) throws Exception {
47
48
// We force using one etype so the output is determined
49
Files.write(Paths.get("krb5.conf"), List.of(
50
"[libdefaults]",
51
"default_tkt_enctypes = aes128-cts"
52
));
53
System.setProperty("java.security.krb5.conf", "krb5.conf");
54
55
KeyTab kt = KeyTab.create("ktab");
56
int num = 0;
57
while (true) {
58
num++;
59
PrincipalName pn = new PrincipalName(
60
String.format("user%03d@REALM", num));
61
kt.addEntry(pn, "password".toCharArray(), num, true);
62
int length = 2;
63
for (KeyTabEntry e : kt.getEntries()) {
64
length += e.entryLength() + 4;
65
}
66
// Create enough big keytab
67
if (length > 8400) {
68
break;
69
}
70
}
71
kt.save();
72
73
int count = 0;
74
boolean written = false;
75
try (KeyTabInputStream kin
76
= new KeyTabInputStream(new FileInputStream("ktab"));
77
KeyTabOutputStream kout
78
= new KeyTabOutputStream(new FileOutputStream("ktab2"))) {
79
kout.write(kin.readNBytes(2)); // version
80
count += 2;
81
while (true) {
82
int len;
83
84
try {
85
len = kin.read(4);
86
} catch (IOException e) {
87
break; // reach end
88
}
89
count += 4;
90
byte[] data = kin.readNBytes(len);
91
count += len;
92
if (count < 8192 || written) {
93
kout.write32(len);
94
kout.write(data);
95
} else {
96
// Create a hole on the 8192 boundary
97
kout.write32(-len);
98
kout.write(new byte[len]);
99
written = true;
100
}
101
}
102
}
103
104
kt = KeyTab.getInstance("ktab2");
105
if (!kt.isValid()) {
106
throw new Exception("Should be valid");
107
}
108
if (kt.getEntries().length != num - 1) {
109
throw new Exception("Should have " + (num - 1) + " entries");
110
}
111
}
112
}
113
114