keyChain & identity添加部分注释

This commit is contained in:
ghy
2021-03-12 21:30:09 +08:00
parent dbeb27abe7
commit d36723b068
14 changed files with 383 additions and 47 deletions
+89
View File
@@ -0,0 +1,89 @@
package security;
import minsecurity.identity.Identity;
import minsecurity.identity.IdentityException;
import org.checkerframework.checker.units.qual.K;
/*
* @Author: hongyu guo
* @Description: 用于给网络包签名和验签
* @Version: 1.0.0
* @Date: 15:49 2021/03/11
* @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
*/
public class KeyChain {
private IdentifyManager identifyManager;
private Identity currentIdentity;
/**
* 指定当前使用默认的网络身份
* @param
* @return
* @author hongyu guo
* @date 2021/3/11
**/
public KeyChain(){
identifyManager = new IdentifyManager();
currentIdentity = identifyManager.getDefaultIdentity();
// TODO: 考虑是否需要在没有默认身份的时候创建一个缺省的本地网络身份
}
/**
* 设置当前使用的网络身份
* @param identity
* @param passwd 如果passwd不为null 且不为空字符串, 则使用该passwd对identity进行解密
* @return void
* @author hongyu guo
* @date 2021/3/11
**/
public void setCurrentIdentity(Identity identity, String passwd) {
try {
if(passwd != null && !passwd.equals(""))
identity.unLock(passwd, identifyManager.getPrivateKeyEncryptionAlgorithm());
} catch (IdentityException e) {
e.printStackTrace();
}
}
/**
* 为一个网络身份申请证书
* @param identity
* @param force
* @return void
* @author hongyu guo
* @date 2021/3/11
**/
public void generateCertificationForIdentity(Identity identity, boolean force) {
// TODO: 这边应该发起网络通信,向 MIS 请求给这个网络身份签发一个证书,留待 MIR 完成后进行补充
}
/**
* 检查一个网络身份是否可用
*
* 1. 首先检查 identity 是否为空;
* 2. 接着检查 identity 是否包含私钥;
* 3. 接着检查 identify 是否被锁定
* @param identity
* @return void
* @author hongyu guo
* @date 2021/3/11
**/
public void checkIdentifyCanUseToSign(Identity identity) throws KeyChainException {
if(identity == null)
throw new KeyChainException("identity is null");
if(!identity.hasPrivateKey()){
throw new KeyChainException("Identify not have Private key, so can't use to sign!");
}
if(identity.isLocked()){
throw new KeyChainException("Identify is locked, so can't use to sign");
}
}
// TODO: packet类暂未完成
// public void getIdentifierAndReadOnlyValueFromPacket(){
//
// }
}