Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/java.security.jgss/share/classes/sun/security/jgss/krb5/AcceptSecContextToken.java
41161 views
1
/*
2
* Copyright (c) 2000, 2018, 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. Oracle designates this
8
* particular file as subject to the "Classpath" exception as provided
9
* by Oracle in the LICENSE file that accompanied this code.
10
*
11
* This code is distributed in the hope that it will be useful, but WITHOUT
12
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14
* version 2 for more details (a copy is included in the LICENSE file that
15
* accompanied this code).
16
*
17
* You should have received a copy of the GNU General Public License version
18
* 2 along with this work; if not, write to the Free Software Foundation,
19
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20
*
21
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22
* or visit www.oracle.com if you need additional information or have any
23
* questions.
24
*/
25
26
package sun.security.jgss.krb5;
27
28
import org.ietf.jgss.*;
29
import java.io.InputStream;
30
import java.io.IOException;
31
32
import sun.security.action.GetBooleanAction;
33
import sun.security.krb5.*;
34
35
class AcceptSecContextToken extends InitialToken {
36
37
private KrbApRep apRep = null;
38
39
/**
40
* Creates an AcceptSecContextToken for the context acceptor to send to
41
* the context initiator.
42
*/
43
public AcceptSecContextToken(Krb5Context context,
44
KrbApReq apReq)
45
throws KrbException, IOException, GSSException {
46
47
boolean useSubkey = GetBooleanAction
48
.privilegedGetProperty("sun.security.krb5.acceptor.subkey");
49
50
boolean useSequenceNumber = true;
51
52
EncryptionKey subKey = null;
53
if (useSubkey) {
54
subKey = new EncryptionKey(apReq.getCreds().getSessionKey());
55
context.setKey(Krb5Context.ACCEPTOR_SUBKEY, subKey);
56
}
57
apRep = new KrbApRep(apReq, useSequenceNumber, subKey);
58
59
context.resetMySequenceNumber(apRep.getSeqNumber().intValue());
60
61
/*
62
* Note: The acceptor side context key was set when the
63
* InitSecContextToken was received.
64
*/
65
}
66
67
/**
68
* Creates an AcceptSecContextToken at the context initiator's side
69
* using the bytes received from the acceptor.
70
*/
71
public AcceptSecContextToken(Krb5Context context,
72
Credentials serviceCreds, KrbApReq apReq,
73
InputStream is)
74
throws IOException, GSSException, KrbException {
75
76
int tokenId = ((is.read()<<8) | is.read());
77
78
if (tokenId != Krb5Token.AP_REP_ID)
79
throw new GSSException(GSSException.DEFECTIVE_TOKEN, -1,
80
"AP_REP token id does not match!");
81
82
byte[] apRepBytes =
83
new sun.security.util.DerValue(is).toByteArray();
84
85
KrbApRep apRep = new KrbApRep(apRepBytes, serviceCreds, apReq);
86
87
/*
88
* Allow the context acceptor to set a subkey if desired, even
89
* though our context acceptor will not do so.
90
*/
91
EncryptionKey subKey = apRep.getSubKey();
92
if (subKey != null) {
93
context.setKey(Krb5Context.ACCEPTOR_SUBKEY, subKey);
94
/*
95
System.out.println("\n\nSub-Session key from AP-REP is: " +
96
getHexBytes(subKey.getBytes()) + "\n");
97
*/
98
}
99
100
Integer apRepSeqNumber = apRep.getSeqNumber();
101
int peerSeqNumber = (apRepSeqNumber != null ?
102
apRepSeqNumber.intValue() :
103
0);
104
context.resetPeerSequenceNumber(peerSeqNumber);
105
}
106
107
public final byte[] encode() throws IOException {
108
byte[] apRepBytes = apRep.getMessage();
109
byte[] retVal = new byte[2 + apRepBytes.length];
110
writeInt(Krb5Token.AP_REP_ID, retVal, 0);
111
System.arraycopy(apRepBytes, 0, retVal, 2, apRepBytes.length);
112
return retVal;
113
}
114
}
115
116