Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/com/sun/security/sasl/digest/HasInitialResponse.java
41154 views
1
/*
2
* Copyright (c) 2019, 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 6682540
27
* @summary Incorrect SASL DIGEST-MD5 behavior
28
*/
29
30
import javax.security.auth.callback.CallbackHandler;
31
import javax.security.sasl.Sasl;
32
import javax.security.sasl.SaslClient;
33
import javax.security.sasl.SaslException;
34
import javax.security.sasl.SaslServer;
35
import java.nio.charset.StandardCharsets;
36
37
public class HasInitialResponse {
38
39
private static final String MECH = "DIGEST-MD5";
40
private static final String SERVER_FQDN = "machineX.imc.org";
41
private static final String PROTOCOL = "jmx";
42
43
private static final byte[] EMPTY = new byte[0];
44
45
public static void main(String[] args) throws Exception {
46
47
CallbackHandler clntCbh = new ClientCallbackHandler(true);
48
CallbackHandler srvCbh = new PropertiesFileCallbackHandler(
49
"pw.properties", "names.properties", null);
50
51
// Get an existing SaslClient as base of our own client
52
SaslClient base = Sasl.createSaslClient(
53
new String[]{MECH}, null, PROTOCOL, SERVER_FQDN,
54
null, clntCbh);
55
56
// Our own client that has initial response
57
SaslClient clnt = new MyDigestMD5Client(base);
58
59
SaslServer srv = Sasl.createSaslServer(MECH, PROTOCOL, SERVER_FQDN,
60
null, srvCbh);
61
62
// The usual loop
63
byte[] response = clnt.hasInitialResponse()
64
? clnt.evaluateChallenge(EMPTY) : EMPTY;
65
byte[] challenge;
66
67
while (!clnt.isComplete() || !srv.isComplete()) {
68
challenge = srv.evaluateResponse(response);
69
70
if (challenge != null) {
71
response = clnt.evaluateChallenge(challenge);
72
}
73
}
74
75
if (clnt.isComplete() && srv.isComplete()) {
76
System.out.println("SUCCESS");
77
System.out.println("authzid is " + srv.getAuthorizationID());
78
} else {
79
throw new IllegalStateException(
80
"FAILURE: mismatched state:" +
81
" client complete? " + clnt.isComplete() +
82
" server complete? " + srv.isComplete());
83
}
84
85
clnt.dispose();
86
srv.dispose();
87
}
88
89
public static class MyDigestMD5Client implements SaslClient {
90
91
final SaslClient base;
92
boolean first = true;
93
94
public MyDigestMD5Client(SaslClient base) {
95
this.base = base;
96
}
97
98
@Override
99
public String getMechanismName() {
100
return base.getMechanismName();
101
}
102
103
@Override
104
public boolean hasInitialResponse() {
105
return true; // I have initial response
106
}
107
108
@Override
109
public byte[] evaluateChallenge(byte[] challenge) throws SaslException {
110
if (first) {
111
first = false;
112
if (challenge.length == 0) {
113
return "hello".getBytes(StandardCharsets.UTF_8);
114
} else {
115
throw new SaslException("Non-empty challenge");
116
}
117
} else {
118
return base.evaluateChallenge(challenge);
119
}
120
}
121
122
@Override
123
public boolean isComplete() {
124
return base.isComplete();
125
}
126
127
@Override
128
public byte[] unwrap(byte[] incoming, int offset, int len)
129
throws SaslException {
130
return base.unwrap(incoming, offset, len);
131
}
132
133
@Override
134
public byte[] wrap(byte[] outgoing, int offset, int len)
135
throws SaslException {
136
return base.wrap(outgoing, offset, len);
137
}
138
139
@Override
140
public Object getNegotiatedProperty(String propName) {
141
return base.getNegotiatedProperty(propName);
142
}
143
144
@Override
145
public void dispose() throws SaslException {
146
base.dispose();
147
}
148
}
149
}
150
151