Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/sun/security/krb5/tools/KtabCheck.java
41154 views
1
/*
2
* Copyright (c) 2010, 2021, 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
import java.io.File;
25
import java.nio.file.Files;
26
import java.nio.file.Path;
27
import java.util.Arrays;
28
import java.util.HashSet;
29
import java.util.Set;
30
31
import jdk.test.lib.SecurityTools;
32
import sun.security.krb5.internal.ktab.KeyTab;
33
import sun.security.krb5.internal.ktab.KeyTabEntry;
34
35
/*
36
* @test
37
* @bug 6950546 8139348
38
* @summary "ktab -d name etype" to "ktab -d name [-e etype] [kvno | all | old]"
39
* @requires os.family == "windows"
40
* @library /test/lib
41
* @modules java.security.jgss/sun.security.krb5.internal.ktab
42
* java.security.jgss/sun.security.krb5
43
*/
44
public class KtabCheck {
45
46
private static final String KEYTAB = "ktab.tmp";
47
48
public static void main(String[] args) throws Exception {
49
50
Files.deleteIfExists(Path.of(KEYTAB));
51
52
// This test uses a krb5.conf file (onlythree.conf) in which
53
// only 3 etypes in the default_tkt_enctypes setting are enabled
54
// by default: aes128-cts(17), aes256-cts(18), and aes128-sha2(19).
55
56
ktab("-a me mine");
57
check(1,17,1,18,1,19);
58
ktab("-a me mine -n 0");
59
check(0,17,0,18,0,19);
60
ktab("-a me mine -n 1 -append");
61
check(0,17,0,18,0,19,1,17,1,18,1,19);
62
ktab("-a me mine -append");
63
check(0,17,0,18,0,19,1,17,1,18,1,19,2,17,2,18,2,19);
64
ktab("-a me mine");
65
check(3,17,3,18,3,19);
66
ktab("-a me mine -n 4 -append");
67
check(3,17,3,18,3,19,4,17,4,18,4,19);
68
ktab("-a me mine -n 5 -append");
69
check(3,17,3,18,3,19,4,17,4,18,4,19,5,17,5,18,5,19);
70
ktab("-a me mine -n 6 -append");
71
check(3,17,3,18,3,19,4,17,4,18,4,19,5,17,5,18,5,19,6,17,6,18,6,19);
72
ktab("-d me 3");
73
check(4,17,4,18,4,19,5,17,5,18,5,19,6,17,6,18,6,19);
74
ktab("-d me -e 17 6");
75
check(4,17,4,18,4,19,5,17,5,18,5,19,6,18,6,19);
76
ktab("-d me -e 19 6");
77
check(4,17,4,18,4,19,5,17,5,18,5,19,6,18);
78
ktab("-d me -e 17 5");
79
check(4,17,4,18,4,19,5,18,5,19,6,18);
80
ktab("-d me old");
81
check(4,17,5,19,6,18);
82
try {
83
ktab("-d me old");
84
throw new Exception("Should fail");
85
} catch (Exception e) {
86
// no-op
87
}
88
check(4,17,5,19,6,18);
89
ktab("-d me");
90
check();
91
}
92
93
static void ktab(String s) throws Exception {
94
File conf = new File(System.getProperty("test.src"), "onlythree.conf");
95
SecurityTools.ktab("-J-Djava.security.krb5.conf=" + conf
96
+ " -k " + KEYTAB + " -f " + s).shouldHaveExitValue(0);
97
}
98
99
/**
100
* Checks if a keytab contains exactly the keys (kvno and etype)
101
* @param args kvno etype...
102
*/
103
static void check(int... args) throws Exception {
104
System.out.println("Checking " + Arrays.toString(args));
105
KeyTab ktab = KeyTab.getInstance(KEYTAB);
106
Set<String> expected = new HashSet<>();
107
for (int i = 0; i < args.length; i += 2) {
108
expected.add(args[i] + ":" + args[i + 1]);
109
}
110
for (KeyTabEntry e: ktab.getEntries()) {
111
// KVNO and etype
112
String vne = e.getKey().getKeyVersionNumber() + ":" +
113
e.getKey().getEType();
114
if (!expected.contains(vne)) {
115
throw new Exception("No " + vne + " in expected");
116
}
117
expected.remove(vne);
118
}
119
if (!expected.isEmpty()) {
120
throw new Exception("Extra elements in expected");
121
}
122
}
123
}
124
125