Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/com/sun/security/sasl/digest/AuthRealmChoices.java
41154 views
1
/*
2
* Copyright (c) 2013, 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
/*
25
* @test
26
* @bug 8013855
27
* @run main AuthRealmChoices 1
28
* @run main AuthRealmChoices 2
29
* @summary DigestMD5Client has not checked RealmChoiceCallback value
30
*/
31
32
import java.io.IOException;
33
import java.util.HashMap;
34
import java.util.Map;
35
import javax.security.auth.callback.Callback;
36
import javax.security.auth.callback.CallbackHandler;
37
import javax.security.auth.callback.UnsupportedCallbackException;
38
import javax.security.sasl.*;
39
40
public class AuthRealmChoices {
41
private static final String MECH = "DIGEST-MD5";
42
private static final String SERVER_FQDN = "machineX.imc.org";
43
private static final String PROTOCOL = "jmx";
44
45
private static final byte[] EMPTY = new byte[0];
46
47
public static void main(String[] args) throws Exception {
48
49
Map props = new HashMap();
50
props.put("com.sun.security.sasl.digest.realm",
51
"IMC.ORG foo.bar machineX");
52
53
SaslClient clnt = Sasl.createSaslClient(
54
new String[]{MECH}, null, PROTOCOL, SERVER_FQDN, null,
55
new CallbackHandler() {
56
@Override
57
public void handle(Callback[] callbacks)
58
throws IOException, UnsupportedCallbackException {
59
for (Callback cb: callbacks) {
60
if (cb instanceof RealmChoiceCallback) {
61
// Two tests:
62
// 1. Set an index out of bound
63
// 2. No index set at all
64
if (args[0].equals("1")) {
65
((RealmChoiceCallback)cb).setSelectedIndex(10);
66
}
67
}
68
}
69
}
70
});
71
72
SaslServer srv = Sasl.createSaslServer(MECH, PROTOCOL, SERVER_FQDN, props,
73
new CallbackHandler() {
74
@Override
75
public void handle(Callback[] callbacks)
76
throws IOException, UnsupportedCallbackException {
77
for (Callback cb: callbacks) {
78
System.out.println(cb);
79
}
80
}
81
});
82
83
byte[] challenge = srv.evaluateResponse(EMPTY);
84
85
try {
86
clnt.evaluateChallenge(challenge);
87
throw new Exception();
88
} catch (SaslException se) {
89
System.out.println(se);
90
}
91
}
92
}
93
94