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