mirror of
https://gh-proxy.org/https://github.com/klinsmaya/IDIS-SDK.git
synced 2026-11-08 00:57:56 +08:00
[opt]注释完善
This commit is contained in:
@@ -107,6 +107,8 @@ public class IdentifierException extends Exception {
|
||||
return "IDENTIFIER_ENGINE_ERROR";
|
||||
case ExceptionCommon.TIME_PARSE_ERROR:
|
||||
return "TIME_PARSE_ERROR";
|
||||
case ExceptionCommon.UNKNOWN_HOSTNAME_ERROR:
|
||||
return "UNKNOWN_HOSTNAME_ERROR";
|
||||
default:
|
||||
return "UNKNOWN_ERROR(" + excpCode + ")";
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ public class IdentifierResolveEngine {
|
||||
return siteInfo;
|
||||
}
|
||||
|
||||
private void initSiteInfo(String ip, int port, String protocol) {
|
||||
private void initSiteInfo(String ip, int port, String protocol) throws IdentifierException {
|
||||
byte iPro = IdisCommunicationItems.TS_IDF_TCP;
|
||||
if (protocol == null || protocol.equalsIgnoreCase("tcp"))
|
||||
iPro = IdisCommunicationItems.TS_IDF_TCP;
|
||||
|
||||
@@ -167,20 +167,20 @@ public class SignatureInfo {
|
||||
if(value == null)
|
||||
return null;
|
||||
IdentifierValuesDigest result = new IdentifierValuesDigest();
|
||||
byte[] encodedHandleValue = MsgBytesConvertor.convertIdentifierValueToByte(value);
|
||||
byte[] encodedIV = MsgBytesConvertor.convertIdentifierValueToByte(value);
|
||||
|
||||
try {
|
||||
byte[] forDig = new byte[encodedHandleValue.length - VALUE_DIGEST_OFFSET];
|
||||
System.arraycopy(encodedHandleValue, VALUE_DIGEST_OFFSET, forDig, 0, encodedHandleValue.length - VALUE_DIGEST_OFFSET);
|
||||
System.out.println("[digestWithSM3]index=" + value.getIndex() + "的HandleValue的16进制数据:" + Util.bytesToHexString(forDig));
|
||||
byte[] forDig = new byte[encodedIV.length - VALUE_DIGEST_OFFSET];
|
||||
System.arraycopy(encodedIV, VALUE_DIGEST_OFFSET, forDig, 0, encodedIV.length - VALUE_DIGEST_OFFSET);
|
||||
System.out.println("[digestWithSM3]index=" + value.getIndex() + "的IdentifierValue的16进制数据:" + Util.bytesToHexString(forDig));
|
||||
byte[] digest = sm3.hash(forDig);
|
||||
System.out.println("[digestWithSM3]index=" + value.getIndex() + "的HandleValue做sm3摘要后的16进制数据:" + Util.bytesToHexString(digest));
|
||||
System.out.println("[digestWithSM3]index=" + value.getIndex() + "的IdentifierValue做sm3摘要后的16进制数据:" + Util.bytesToHexString(digest));
|
||||
result.digest = Base64.encodeBase64String(digest);
|
||||
System.out.println("[digestWithSM3]index=" + value.getIndex() + "的HandleValue做sm3摘要后再做base64编码:" + result.digest);
|
||||
System.out.println("[digestWithSM3]index=" + value.getIndex() + "的IdentifierValue做sm3摘要后再做base64编码:" + result.digest);
|
||||
result.index = value.getIndex();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
System.out.println("Failed:handle value do digest wiht SM3!");
|
||||
System.out.println("Failed:IdentifierValue do digest with SM3!");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,22 @@
|
||||
package cn.ac.caict.iiiiot.idisc.security;
|
||||
|
||||
/*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*© COPYRIGHT 2019 Corporation for Institute of Industrial Internet & Internet of Things (IIIIT);
|
||||
* All rights reserved.
|
||||
* http://www.caict.ac.cn
|
||||
* https://www.citln.cn/
|
||||
*/
|
||||
import java.security.PublicKey;
|
||||
import java.util.List;
|
||||
|
||||
@@ -13,13 +30,13 @@ public class Claims {
|
||||
public PublicKey publicKey;
|
||||
// 颁发者,格式为“index:identifier”,如“100:88.123”
|
||||
public String iss;
|
||||
// 受发者即主体,格式为“index:identifier”,如“100:88.123”
|
||||
// 受发者即主体,格式为“index:identifier”,如“100:88.123”如果是签名则不需要有index,“88.123”即可
|
||||
public String sub;
|
||||
// 过期时间,2年过期时间这样计算:System.currentTimeMillis() / 1000L + (oneYearInSeconds * 2)
|
||||
public Long exp;
|
||||
// 开始日期
|
||||
// 生效时间
|
||||
public Long nbf;
|
||||
// 发行时间
|
||||
// 颁发时间
|
||||
public Long iat;
|
||||
|
||||
public boolean isDateInRange(long nowInSeconds) {
|
||||
|
||||
@@ -1,12 +1,3 @@
|
||||
/**********************************************************************\
|
||||
© COPYRIGHT 2015 Corporation for National Research Initiatives (CNRI);
|
||||
All rights reserved.
|
||||
|
||||
The HANDLE.NET software is made available subject to the
|
||||
Handle.Net Public License Agreement, which may be obtained at
|
||||
http://hdl.handle.net/20.1000/103 or hdl:20.1000/103
|
||||
\**********************************************************************/
|
||||
|
||||
package cn.ac.caict.iiiiot.idisc.security;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -1,5 +1,22 @@
|
||||
package cn.ac.caict.iiiiot.idisc.security;
|
||||
|
||||
/*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*© COPYRIGHT 2019 Corporation for Institute of Industrial Internet & Internet of Things (IIIIT);
|
||||
* All rights reserved.
|
||||
* http://www.caict.ac.cn
|
||||
* https://www.citln.cn/
|
||||
*/
|
||||
import java.security.PublicKey;
|
||||
|
||||
public class EC_Custom_PublicKey implements PublicKey{
|
||||
|
||||
+18
-1
@@ -1,5 +1,22 @@
|
||||
package cn.ac.caict.iiiiot.idisc.security;
|
||||
|
||||
/*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*© COPYRIGHT 2019 Corporation for Institute of Industrial Internet & Internet of Things (IIIIT);
|
||||
* All rights reserved.
|
||||
* http://www.caict.ac.cn
|
||||
* https://www.citln.cn/
|
||||
*/
|
||||
public class IdentifierValuesDigest {
|
||||
// 标识值对应的索引值
|
||||
public int index;
|
||||
|
||||
+18
-1
@@ -1,5 +1,22 @@
|
||||
package cn.ac.caict.iiiiot.idisc.security;
|
||||
|
||||
/*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*© COPYRIGHT 2019 Corporation for Institute of Industrial Internet & Internet of Things (IIIIT);
|
||||
* All rights reserved.
|
||||
* http://www.caict.ac.cn
|
||||
* https://www.citln.cn/
|
||||
*/
|
||||
import java.util.List;
|
||||
|
||||
public class IdentifierValuesDigests {
|
||||
|
||||
+18
-1
@@ -1,5 +1,22 @@
|
||||
package cn.ac.caict.iiiiot.idisc.security;
|
||||
|
||||
/*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*© COPYRIGHT 2019 Corporation for Institute of Industrial Internet & Internet of Things (IIIIT);
|
||||
* All rights reserved.
|
||||
* http://www.caict.ac.cn
|
||||
* https://www.citln.cn/
|
||||
*/
|
||||
import java.util.List;
|
||||
|
||||
public class SignatureJsonStruction {
|
||||
|
||||
@@ -1,5 +1,22 @@
|
||||
package cn.ac.caict.iiiiot.idisc.security;
|
||||
|
||||
/*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*© COPYRIGHT 2019 Corporation for Institute of Industrial Internet & Internet of Things (IIIIT);
|
||||
* All rights reserved.
|
||||
* http://www.caict.ac.cn
|
||||
* https://www.citln.cn/
|
||||
*/
|
||||
public interface SignatureStruct {
|
||||
public byte[] getSignatureBytes();
|
||||
public String getSignatureString();
|
||||
|
||||
@@ -1,5 +1,22 @@
|
||||
package cn.ac.caict.iiiiot.idisc.security;
|
||||
|
||||
/*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*© COPYRIGHT 2019 Corporation for Institute of Industrial Internet & Internet of Things (IIIIT);
|
||||
* All rights reserved.
|
||||
* http://www.caict.ac.cn
|
||||
* https://www.citln.cn/
|
||||
*/
|
||||
import java.math.BigInteger;
|
||||
import java.security.PrivateKey;
|
||||
import java.security.Signature;
|
||||
|
||||
@@ -36,6 +36,8 @@ public class ExceptionCommon {
|
||||
public static final int JWT_PARSE_ERROR = -9;
|
||||
// 时间解析错误
|
||||
public static final int TIME_PARSE_ERROR = -10;
|
||||
// 未知主机名错误
|
||||
public static final int UNKNOWN_HOSTNAME_ERROR = -11;
|
||||
// 无效value
|
||||
public static final int EXCEPTIONCODE_INVALID_VALUE = 0;
|
||||
// 内部错误
|
||||
|
||||
@@ -11,6 +11,7 @@ import java.io.StringReader;
|
||||
import java.math.BigInteger;
|
||||
import java.net.Inet4Address;
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.security.AlgorithmParameters;
|
||||
import java.security.Key;
|
||||
import java.security.KeyFactory;
|
||||
@@ -576,8 +577,11 @@ public abstract class Util {
|
||||
|
||||
/**
|
||||
* 字节数组连接
|
||||
* @param first 第一组字节
|
||||
* @param second 第二组字节
|
||||
*
|
||||
* @param first
|
||||
* 第一组字节
|
||||
* @param second
|
||||
* 第二组字节
|
||||
* @return 第一组和第二组连接后的结果字节数组
|
||||
*/
|
||||
public static byte[] concat(byte[] first, byte[] second) {
|
||||
@@ -644,7 +648,8 @@ public abstract class Util {
|
||||
offset += Common.FOUR_SIZE + p.length;
|
||||
byte[] g = BaseConvertor.readByteArray(pkBuf, offset);
|
||||
offset += Common.FOUR_SIZE + g.length;
|
||||
DHPublicKeySpec keySpec = new DHPublicKeySpec(new BigInteger(1, y), new BigInteger(1, p),new BigInteger(1, g));
|
||||
DHPublicKeySpec keySpec = new DHPublicKeySpec(new BigInteger(1, y), new BigInteger(1, p),
|
||||
new BigInteger(1, g));
|
||||
try {
|
||||
KeyFactory dhKeyFactory = KeyFactory.getInstance("DiffieHellman");
|
||||
return dhKeyFactory.generatePublic(keySpec);
|
||||
@@ -872,7 +877,7 @@ public abstract class Util {
|
||||
}
|
||||
return getPublicKeyFromBytes(buf, 0);
|
||||
}
|
||||
|
||||
|
||||
private static PublicKey getPublicKeyKeyFromPemFile(File pubKeyFile) {
|
||||
InputStream in;
|
||||
try {
|
||||
@@ -938,7 +943,7 @@ public abstract class Util {
|
||||
} catch (InvalidKeySpecException e) {
|
||||
try {
|
||||
return SecureUtil.generatePublicKey("SM2", bytes);
|
||||
} catch(Exception ex) {
|
||||
} catch (Exception ex) {
|
||||
throw new Exception("RSA和DSA、SM2格式的公钥生成器都无法生成公钥", e);
|
||||
}
|
||||
}
|
||||
@@ -1090,12 +1095,12 @@ public abstract class Util {
|
||||
} catch (InvalidKeySpecException e) {
|
||||
try {
|
||||
return SecureUtil.generatePrivateKey("SM2", bytes);
|
||||
} catch(Exception ex) {
|
||||
} catch (Exception ex) {
|
||||
throw new Exception("DSA和RSA、SM2都无法解析", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static String getSigAlgFromSignKeyType(byte[] hashAlg, String sigKeyType) throws IdentifierException {
|
||||
if (Util.equalsBytes(hashAlg, Common.HASH_ALG_SHA1)
|
||||
|| Util.equalsBytes(hashAlg, Common.HASH_ALG_SHA1_ALTERNATE))
|
||||
@@ -1149,18 +1154,28 @@ public abstract class Util {
|
||||
return buf;
|
||||
}
|
||||
|
||||
public static final byte[] convertIPStr2Bytes(String ip) {
|
||||
public static final byte[] convertIPStr2Bytes(String ip) throws IdentifierException {
|
||||
byte[] ipBytes;
|
||||
if (Util.isIPV4(ip)) {
|
||||
String[] st = ip.split("\\.");
|
||||
ipBytes = new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (byte) Integer.parseInt(st[0]),
|
||||
(byte) Integer.parseInt(st[1]), (byte) Integer.parseInt(st[2]), (byte) Integer.parseInt(st[3]) };
|
||||
} else {
|
||||
ipBytes = Util.encodeString(ip);
|
||||
InetAddress addr;
|
||||
try {
|
||||
addr = InetAddress.getByName(ip);
|
||||
} catch (UnknownHostException e) {
|
||||
throw new IdentifierException(ExceptionCommon.UNKNOWN_HOSTNAME_ERROR);
|
||||
}
|
||||
byte addr1[] = addr.getAddress();
|
||||
ipBytes = new byte[Common.IP_ADDRESS_SIZE_SIXTEEN];
|
||||
for (int i = 0; i < Common.IP_ADDRESS_SIZE_SIXTEEN; i++)
|
||||
ipBytes[i] = (byte) 0;
|
||||
System.arraycopy(addr1, 0, ipBytes, ipBytes.length - addr1.length, addr1.length);
|
||||
}
|
||||
return ipBytes;
|
||||
}
|
||||
|
||||
|
||||
public static byte[] reverseOrderArray(byte[] arr) {
|
||||
// 定义一个反序后的数组
|
||||
byte[] desArr = new byte[arr.length];
|
||||
@@ -1172,7 +1187,7 @@ public abstract class Util {
|
||||
// 返回倒序后的数组
|
||||
return desArr;
|
||||
}
|
||||
|
||||
|
||||
public static byte[] toBytes(String str) {
|
||||
if (str == null || str.trim().equals("")) {
|
||||
return new byte[0];
|
||||
@@ -1186,7 +1201,7 @@ public abstract class Util {
|
||||
|
||||
return bytes;
|
||||
}
|
||||
|
||||
|
||||
public static byte[] getBytesWithout00(byte[] origin) {
|
||||
byte[] result = origin;
|
||||
if (origin[0] == 0) {
|
||||
@@ -1195,14 +1210,14 @@ public abstract class Util {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 字节数组拼接
|
||||
*
|
||||
* @param params
|
||||
* @return
|
||||
*/
|
||||
public static byte[] join(byte[]...params) {
|
||||
public static byte[] join(byte[]... params) {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
byte[] res = null;
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user