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/MicToken.java
41161 views
1
/*
2
* Copyright (c) 2000, 2006, 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.OutputStream;
31
import java.io.IOException;
32
import java.io.ByteArrayInputStream;
33
import java.io.ByteArrayOutputStream;
34
35
class MicToken extends MessageToken {
36
37
public MicToken(Krb5Context context,
38
byte[] tokenBytes, int tokenOffset, int tokenLen,
39
MessageProp prop) throws GSSException {
40
super(Krb5Token.MIC_ID, context,
41
tokenBytes, tokenOffset, tokenLen, prop);
42
}
43
44
public MicToken(Krb5Context context,
45
InputStream is, MessageProp prop)
46
throws GSSException {
47
super(Krb5Token.MIC_ID, context, is, prop);
48
}
49
50
public void verify(byte[] data, int offset, int len) throws GSSException {
51
if (!verifySignAndSeqNumber(null, data, offset, len, null))
52
throw new GSSException(GSSException.BAD_MIC, -1,
53
"Corrupt checksum or sequence number in MIC token");
54
}
55
56
public void verify(InputStream data) throws GSSException {
57
byte[] dataBytes = null;
58
try {
59
dataBytes = new byte[data.available()];
60
data.read(dataBytes);
61
} catch (IOException e) {
62
// Error reading application data
63
throw new GSSException(GSSException.BAD_MIC, -1,
64
"Corrupt checksum or sequence number in MIC token");
65
}
66
verify(dataBytes, 0, dataBytes.length);
67
}
68
69
public MicToken(Krb5Context context, MessageProp prop,
70
byte[] data, int pos, int len)
71
throws GSSException {
72
super(Krb5Token.MIC_ID, context);
73
74
// debug("Application data to MicToken verify is [" +
75
// getHexBytes(data, pos, len) + "]\n");
76
if (prop == null) prop = new MessageProp(0, false);
77
genSignAndSeqNumber(prop, null, data, pos, len, null);
78
}
79
80
public MicToken(Krb5Context context, MessageProp prop,
81
InputStream data)
82
throws GSSException, IOException {
83
super(Krb5Token.MIC_ID, context);
84
byte[] dataBytes = new byte[data.available()];
85
data.read(dataBytes);
86
87
//debug("Application data to MicToken cons is [" +
88
// getHexBytes(dataBytes) + "]\n");
89
if (prop == null) prop = new MessageProp(0, false);
90
genSignAndSeqNumber(prop, null, dataBytes, 0, dataBytes.length, null);
91
}
92
93
protected int getSealAlg(boolean confRequested, int qop) {
94
return (SEAL_ALG_NONE);
95
}
96
97
public int encode(byte[] outToken, int offset)
98
throws IOException, GSSException {
99
// Token is small
100
ByteArrayOutputStream bos = new ByteArrayOutputStream();
101
super.encode(bos);
102
byte[] token = bos.toByteArray();
103
System.arraycopy(token, 0, outToken, offset, token.length);
104
return token.length;
105
}
106
107
public byte[] encode() throws IOException, GSSException{
108
// XXX Fine tune this initial size
109
ByteArrayOutputStream bos = new ByteArrayOutputStream(50);
110
encode(bos);
111
return bos.toByteArray();
112
}
113
114
}
115
116