author | weijun |
Tue, 14 Aug 2018 22:39:34 +0800 | |
changeset 51398 | 3c389a284345 |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
51398
3c389a284345
8209416: Refactoring GetPropertyAction calls in security libs
weijun
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 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 |
* |
|
5506 | 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. |
|
2 | 24 |
*/ |
25 |
||
26 |
package sun.security.jgss.krb5; |
|
27 |
||
28 |
import org.ietf.jgss.*; |
|
29 |
import java.io.InputStream; |
|
30 |
import java.io.IOException; |
|
18536 | 31 |
|
32 |
import sun.security.action.GetBooleanAction; |
|
2 | 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) |
|
18536 | 45 |
throws KrbException, IOException, GSSException { |
2 | 46 |
|
51398
3c389a284345
8209416: Refactoring GetPropertyAction calls in security libs
weijun
parents:
47216
diff
changeset
|
47 |
boolean useSubkey = GetBooleanAction |
3c389a284345
8209416: Refactoring GetPropertyAction calls in security libs
weijun
parents:
47216
diff
changeset
|
48 |
.privilegedGetProperty("sun.security.krb5.acceptor.subkey"); |
2 | 49 |
|
50 |
boolean useSequenceNumber = true; |
|
51 |
||
18536 | 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); |
|
2 | 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) { |
|
10697
ecee258b7d87
7077646: gssapi wrap for CFX per-message tokens always set FLAG_ACCEPTOR_SUBKEY
weijun
parents:
5506
diff
changeset
|
93 |
context.setKey(Krb5Context.ACCEPTOR_SUBKEY, subKey); |
2 | 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 |
} |