author | weijun |
Wed, 03 Jul 2019 11:43:01 +0800 | |
changeset 55570 | 1e95931e7d8f |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
14342
8435a30053c1
7197491: update copyright year to match last edit in jdk8 jdk repository
alanb
parents:
14327
diff
changeset
|
2 |
* Copyright (c) 2000, 2012, 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 |
/* |
|
27 |
* |
|
28 |
* (C) Copyright IBM Corp. 1999 All Rights Reserved. |
|
29 |
* Copyright 1997 The Open Group Research Institute. All rights reserved. |
|
30 |
*/ |
|
31 |
||
32 |
package sun.security.krb5.internal.crypto; |
|
33 |
||
34 |
import sun.security.krb5.Config; |
|
35 |
import sun.security.krb5.Checksum; |
|
36 |
import sun.security.krb5.EncryptedData; |
|
37 |
import sun.security.krb5.KrbException; |
|
38 |
import sun.security.krb5.KrbCryptoException; |
|
39 |
import sun.security.krb5.internal.*; |
|
40 |
||
41 |
public abstract class CksumType { |
|
42 |
||
43 |
private static boolean DEBUG = Krb5.DEBUG; |
|
44 |
||
45 |
public static CksumType getInstance(int cksumTypeConst) |
|
46 |
throws KdcErrException { |
|
47 |
CksumType cksumType = null; |
|
48 |
String cksumTypeName = null; |
|
49 |
switch (cksumTypeConst) { |
|
50 |
case Checksum.CKSUMTYPE_CRC32: |
|
51 |
cksumType = new Crc32CksumType(); |
|
52 |
cksumTypeName = "sun.security.krb5.internal.crypto.Crc32CksumType"; |
|
53 |
break; |
|
54 |
case Checksum.CKSUMTYPE_DES_MAC: |
|
55 |
cksumType = new DesMacCksumType(); |
|
56 |
cksumTypeName = "sun.security.krb5.internal.crypto.DesMacCksumType"; |
|
57 |
break; |
|
58 |
case Checksum.CKSUMTYPE_DES_MAC_K: |
|
59 |
cksumType = new DesMacKCksumType(); |
|
60 |
cksumTypeName = |
|
61 |
"sun.security.krb5.internal.crypto.DesMacKCksumType"; |
|
62 |
break; |
|
63 |
case Checksum.CKSUMTYPE_RSA_MD5: |
|
64 |
cksumType = new RsaMd5CksumType(); |
|
65 |
cksumTypeName = "sun.security.krb5.internal.crypto.RsaMd5CksumType"; |
|
66 |
break; |
|
67 |
case Checksum.CKSUMTYPE_RSA_MD5_DES: |
|
68 |
cksumType = new RsaMd5DesCksumType(); |
|
69 |
cksumTypeName = |
|
70 |
"sun.security.krb5.internal.crypto.RsaMd5DesCksumType"; |
|
71 |
break; |
|
72 |
||
73 |
case Checksum.CKSUMTYPE_HMAC_SHA1_DES3_KD: |
|
74 |
cksumType = new HmacSha1Des3KdCksumType(); |
|
75 |
cksumTypeName = |
|
76 |
"sun.security.krb5.internal.crypto.HmacSha1Des3KdCksumType"; |
|
77 |
break; |
|
78 |
||
79 |
case Checksum.CKSUMTYPE_HMAC_SHA1_96_AES128: |
|
80 |
cksumType = new HmacSha1Aes128CksumType(); |
|
81 |
cksumTypeName = |
|
82 |
"sun.security.krb5.internal.crypto.HmacSha1Aes128CksumType"; |
|
83 |
break; |
|
84 |
case Checksum.CKSUMTYPE_HMAC_SHA1_96_AES256: |
|
85 |
cksumType = new HmacSha1Aes256CksumType(); |
|
86 |
cksumTypeName = |
|
87 |
"sun.security.krb5.internal.crypto.HmacSha1Aes256CksumType"; |
|
88 |
break; |
|
89 |
||
90 |
case Checksum.CKSUMTYPE_HMAC_MD5_ARCFOUR: |
|
91 |
cksumType = new HmacMd5ArcFourCksumType(); |
|
92 |
cksumTypeName = |
|
93 |
"sun.security.krb5.internal.crypto.HmacMd5ArcFourCksumType"; |
|
94 |
break; |
|
95 |
||
96 |
// currently we don't support MD4. |
|
97 |
case Checksum.CKSUMTYPE_RSA_MD4_DES_K: |
|
98 |
// cksumType = new RsaMd4DesKCksumType(); |
|
99 |
// cksumTypeName = |
|
100 |
// "sun.security.krb5.internal.crypto.RsaMd4DesKCksumType"; |
|
101 |
case Checksum.CKSUMTYPE_RSA_MD4: |
|
102 |
// cksumType = new RsaMd4CksumType(); |
|
103 |
// linux box support rsamd4, how to solve conflict? |
|
104 |
// cksumTypeName = |
|
105 |
// "sun.security.krb5.internal.crypto.RsaMd4CksumType"; |
|
106 |
case Checksum.CKSUMTYPE_RSA_MD4_DES: |
|
107 |
// cksumType = new RsaMd4DesCksumType(); |
|
108 |
// cksumTypeName = |
|
109 |
// "sun.security.krb5.internal.crypto.RsaMd4DesCksumType"; |
|
110 |
||
111 |
default: |
|
112 |
throw new KdcErrException(Krb5.KDC_ERR_SUMTYPE_NOSUPP); |
|
113 |
} |
|
114 |
if (DEBUG) { |
|
115 |
System.out.println(">>> CksumType: " + cksumTypeName); |
|
116 |
} |
|
117 |
return cksumType; |
|
118 |
} |
|
119 |
||
120 |
||
121 |
/** |
|
122 |
* Returns default checksum type. |
|
123 |
*/ |
|
124 |
public static CksumType getInstance() throws KdcErrException { |
|
125 |
// this method provided for Kerberos applications. |
|
126 |
int cksumType = Checksum.CKSUMTYPE_RSA_MD5; // default |
|
127 |
try { |
|
128 |
Config c = Config.getInstance(); |
|
14327 | 129 |
if ((cksumType = (Config.getType(c.get("libdefaults", |
130 |
"ap_req_checksum_type")))) == - 1) { |
|
131 |
if ((cksumType = Config.getType(c.get("libdefaults", |
|
132 |
"checksum_type"))) == -1) { |
|
2 | 133 |
cksumType = Checksum.CKSUMTYPE_RSA_MD5; // default |
134 |
} |
|
135 |
} |
|
136 |
} catch (KrbException e) { |
|
137 |
} |
|
138 |
return getInstance(cksumType); |
|
139 |
} |
|
140 |
||
141 |
public abstract int confounderSize(); |
|
142 |
||
143 |
public abstract int cksumType(); |
|
144 |
||
145 |
public abstract boolean isSafe(); |
|
146 |
||
147 |
public abstract int cksumSize(); |
|
148 |
||
149 |
public abstract int keyType(); |
|
150 |
||
151 |
public abstract int keySize(); |
|
152 |
||
153 |
public abstract byte[] calculateChecksum(byte[] data, int size) |
|
154 |
throws KrbCryptoException; |
|
155 |
||
156 |
public abstract byte[] calculateKeyedChecksum(byte[] data, int size, |
|
157 |
byte[] key, int usage) throws KrbCryptoException; |
|
158 |
||
55570
1e95931e7d8f
8226719: Kerberos login to Windows 2000 failed with "Inappropriate type of checksum in message"
weijun
parents:
47216
diff
changeset
|
159 |
public boolean verifyChecksum(byte[] data, byte[] checksum) |
1e95931e7d8f
8226719: Kerberos login to Windows 2000 failed with "Inappropriate type of checksum in message"
weijun
parents:
47216
diff
changeset
|
160 |
throws KrbCryptoException { |
1e95931e7d8f
8226719: Kerberos login to Windows 2000 failed with "Inappropriate type of checksum in message"
weijun
parents:
47216
diff
changeset
|
161 |
throw new UnsupportedOperationException("Not supported"); |
1e95931e7d8f
8226719: Kerberos login to Windows 2000 failed with "Inappropriate type of checksum in message"
weijun
parents:
47216
diff
changeset
|
162 |
} |
1e95931e7d8f
8226719: Kerberos login to Windows 2000 failed with "Inappropriate type of checksum in message"
weijun
parents:
47216
diff
changeset
|
163 |
|
2 | 164 |
public abstract boolean verifyKeyedChecksum(byte[] data, int size, |
165 |
byte[] key, byte[] checksum, int usage) throws KrbCryptoException; |
|
166 |
||
167 |
public static boolean isChecksumEqual(byte[] cksum1, byte[] cksum2) { |
|
168 |
if (cksum1 == cksum2) |
|
169 |
return true; |
|
170 |
if ((cksum1 == null && cksum2 != null) || |
|
171 |
(cksum1 != null && cksum2 == null)) |
|
172 |
return false; |
|
173 |
if (cksum1.length != cksum2.length) |
|
174 |
return false; |
|
175 |
for (int i = 0; i < cksum1.length; i++) |
|
176 |
if (cksum1[i] != cksum2[i]) |
|
177 |
return false; |
|
178 |
return true; |
|
179 |
} |
|
180 |
||
181 |
} |