Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/com/sun/security/sasl/Cram.java
41152 views
1
/*
2
* Copyright (c) 2003, 2016, 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 4634892
27
* @modules jdk.security.auth
28
* @summary Ensure that authentication via CRAM-MD5 works.
29
*/
30
31
/*
32
* Can set logging to FINEST to view exchange.
33
*/
34
import javax.security.auth.callback.CallbackHandler;
35
import javax.security.sasl.Sasl;
36
import javax.security.sasl.SaslClient;
37
import javax.security.sasl.SaslServer;
38
39
public class Cram {
40
private static final String MECH = "CRAM-MD5";
41
private static final String SERVER_FQDN = "machineX.imc.org";
42
private static final String PROTOCOL = "jmx";
43
44
private static final byte[] EMPTY = new byte[0];
45
private static boolean auto;
46
private static boolean verbose = false;
47
private static String pwfile, namesfile;
48
49
public static void main(String[] args) throws Exception {
50
if (args.length == 0) {
51
pwfile = "pw.properties";
52
namesfile = "names.properties";
53
auto = true;
54
} else {
55
int i = 0;
56
if (args[i].equals("-m")) {
57
i++;
58
auto = false;
59
}
60
if (args.length > i) {
61
pwfile = args[i++];
62
63
if (args.length > i) {
64
namesfile = args[i++];
65
}
66
} else {
67
pwfile = "pw.properties";
68
namesfile = "names.properties";
69
}
70
}
71
72
CallbackHandler clntCbh = new ClientCallbackHandler(auto);
73
74
CallbackHandler srvCbh =
75
new PropertiesFileCallbackHandler(pwfile, namesfile, null);
76
77
SaslClient clnt = Sasl.createSaslClient(
78
new String[]{MECH}, null, PROTOCOL, SERVER_FQDN, null, clntCbh);
79
80
SaslServer srv = Sasl.createSaslServer(MECH, PROTOCOL, SERVER_FQDN, null,
81
srvCbh);
82
83
if (clnt == null) {
84
throw new IllegalStateException(
85
"Unable to find client impl for " + MECH);
86
}
87
if (srv == null) {
88
throw new IllegalStateException(
89
"Unable to find server impl for " + MECH);
90
}
91
92
byte[] response = (clnt.hasInitialResponse()?
93
clnt.evaluateChallenge(EMPTY) : EMPTY);
94
byte[] challenge;
95
96
while (!clnt.isComplete() || !srv.isComplete()) {
97
challenge = srv.evaluateResponse(response);
98
99
if (challenge != null) {
100
response = clnt.evaluateChallenge(challenge);
101
}
102
}
103
104
if (clnt.isComplete() && srv.isComplete()) {
105
if (verbose) {
106
System.out.println("SUCCESS");
107
System.out.println("authzid is " + srv.getAuthorizationID());
108
}
109
} else {
110
throw new IllegalStateException("FAILURE: mismatched state:" +
111
" client complete? " + clnt.isComplete() +
112
" server complete? " + srv.isComplete());
113
}
114
}
115
}
116
117