mirror of
https://gitee.com/willfree/min-dev-java.git
synced 2026-06-17 21:50:25 +08:00
更换日志模块,以适配安卓:由原来使用logback库更改为使用java原生库
This commit is contained in:
@@ -208,12 +208,22 @@
|
||||
<version>1.65</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 日志 -->
|
||||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-classic</artifactId>
|
||||
<version>1.2.3</version>
|
||||
</dependency>
|
||||
<!-- 日志 为了与安卓适配,本项目所有日志均采用java原生logging库-->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>org.slf4j</groupId>-->
|
||||
<!-- <artifactId>slf4j-api</artifactId>-->
|
||||
<!-- <version>1.7.5</version>-->
|
||||
<!-- </dependency>-->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>ch.qos.logback</groupId>-->
|
||||
<!-- <artifactId>logback-core</artifactId>-->
|
||||
<!-- <version>1.2.3</version>-->
|
||||
<!-- </dependency>-->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>ch.qos.logback</groupId>-->
|
||||
<!-- <artifactId>logback-classic</artifactId>-->
|
||||
<!-- <version>1.2.3</version>-->
|
||||
<!-- </dependency>-->
|
||||
|
||||
<!-- json -->
|
||||
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-core -->
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
package common;
|
||||
|
||||
/*
|
||||
* @Author: Wang Feng
|
||||
* @Description:
|
||||
* @Version: 1.0.0
|
||||
* @Date: 10:59 2021/3/24
|
||||
* @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
|
||||
*/
|
||||
public class LoggerException extends Exception {
|
||||
public LoggerException(String msg){
|
||||
super("Logger-"+msg);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,14 @@
|
||||
package common;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
//import org.slf4j.Logger;
|
||||
//import org.slf4j.LoggerFactory;
|
||||
import util.FileUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.logging.*;
|
||||
|
||||
/*
|
||||
* @Author: Wang Feng
|
||||
@@ -11,7 +18,129 @@ import org.slf4j.LoggerFactory;
|
||||
* @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
|
||||
*/
|
||||
public class LoggerHelper {
|
||||
public static final Logger logger= LoggerFactory.getLogger("[min-dev-java]");
|
||||
// 是否打开logger. true: 打开,记录日志;false: 关闭,使用sout输出信息
|
||||
public static boolean OpenLoggerFlag=false;
|
||||
// logger标签
|
||||
private static final String TAG = "min-dev-java";
|
||||
// logger
|
||||
private static final Logger logger=Logger.getLogger(TAG);
|
||||
|
||||
// 设置logger文件输出路径: ./log/${level}/${data}/${level}-log.log
|
||||
private static final String LogPath="./log";
|
||||
private static String getNowLogPath(String level){
|
||||
// 加入文件名
|
||||
return getNowLogDir(level)+"/"+level+"-log.log";
|
||||
}
|
||||
private static String getNowLogDir(String level){
|
||||
// log根目录
|
||||
String nowLogPath=LogPath;
|
||||
// level
|
||||
nowLogPath+="/"+level;
|
||||
// 日期目录
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
||||
nowLogPath+=("/"+sdf.format(new Date()));
|
||||
return nowLogPath;
|
||||
}
|
||||
private static void setLogPath(String level) throws LoggerException {
|
||||
try {
|
||||
// 生成日志文件夹及日志文件
|
||||
String dirPath=getNowLogDir(level);
|
||||
String filePath=getNowLogPath(level);
|
||||
FileUtil.confirmDirExistence(dirPath);
|
||||
FileUtil.confirmFileExistence(filePath);
|
||||
|
||||
FileHandler fileHandler=new FileHandler(filePath,true);
|
||||
logger.addHandler(fileHandler);
|
||||
}catch (IOException e){
|
||||
throw new LoggerException("setLogPath error: "+e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public static void severe(String msg){
|
||||
logMsg("severe",msg);
|
||||
}
|
||||
|
||||
public static void warning(String msg){
|
||||
logMsg("warning",msg);
|
||||
}
|
||||
|
||||
public static void info(String msg){
|
||||
logMsg("info",msg);
|
||||
}
|
||||
|
||||
public static void config(String msg){
|
||||
logMsg("config",msg);
|
||||
}
|
||||
|
||||
public static void fine(String msg){
|
||||
logMsg("fine",msg);
|
||||
}
|
||||
|
||||
public static void finer(String msg){
|
||||
logMsg("finer",msg);
|
||||
}
|
||||
|
||||
public static void finest(String msg){
|
||||
logMsg("finest",msg);
|
||||
}
|
||||
|
||||
private static void logMsg(String level,String msg){
|
||||
if(OpenLoggerFlag) {
|
||||
// 设置日志目录。如果失败,立即切换为关闭日志模式
|
||||
try {
|
||||
setLogPath(level);
|
||||
} catch (LoggerException e) {
|
||||
System.out.println(e.getMessage());
|
||||
OpenLoggerFlag = false;
|
||||
System.out.println("Close logger success.");
|
||||
logMsg(level,msg);
|
||||
}
|
||||
// 根据level不同,记录日志
|
||||
switch (level){
|
||||
case "severe":
|
||||
logger.severe(msg);
|
||||
break;
|
||||
case "warning":
|
||||
logger.warning(msg);
|
||||
break;
|
||||
case "info":
|
||||
logger.info(msg);
|
||||
break;
|
||||
case "config":
|
||||
logger.config(msg);
|
||||
break;
|
||||
case "fine":
|
||||
logger.fine(msg);
|
||||
break;
|
||||
case "finer":
|
||||
logger.finer(msg);
|
||||
break;
|
||||
case "finest":
|
||||
logger.finest(msg);
|
||||
break;
|
||||
}
|
||||
}else{
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
// 只打印信息到控制台
|
||||
System.out.println(sdf.format(new Date())+" "+level+" "+msg);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// public static void debug(){
|
||||
// logger.setLevel(Level.SEVERE);
|
||||
// logger.setLevel(Level.WARNING);
|
||||
// logger.setLevel(Level.INFO);
|
||||
// logger.setLevel(Level.CONFIG);
|
||||
// logger.setLevel(Level.FINE);
|
||||
// logger.setLevel(Level.FINER);
|
||||
// logger.setLevel(Level.FINEST);
|
||||
// }
|
||||
|
||||
// public static void main(String[] args){
|
||||
// logger.setLevel(Level.WARNING);
|
||||
// }
|
||||
// public static final Logger logger= LoggerFactory.getLogger("[min-dev-java]");
|
||||
// 使用示例:
|
||||
// LoggerHelper.logger.trace("Trace Level.");
|
||||
// LoggerHelper.logger.debug("Debug Level.");
|
||||
|
||||
@@ -85,7 +85,7 @@ public class LogicFaceICN extends LogicFace {
|
||||
IdentifierWrapper identifierWrapper=interest.minPacket.identifierField.getIdentifier(0);
|
||||
PITEntry pitEntry=this.getPitEntryAndDelete(identifierWrapper.getIdentifier());
|
||||
if(pitEntry == null) {
|
||||
LoggerHelper.logger.info("no match pit entry");
|
||||
LoggerHelper.info("no match pit entry");
|
||||
}
|
||||
OnInterestInterface oI=this.lookUpFib(identifierWrapper.getIdentifier());
|
||||
if(oI!=null){
|
||||
@@ -128,7 +128,7 @@ public class LogicFaceICN extends LogicFace {
|
||||
IdentifierWrapper identifierWrapper=data.minPacket.identifierField.getIdentifier(0);
|
||||
PITEntry pitEntry = this.getPitEntryAndDelete(identifierWrapper.getIdentifier());
|
||||
if(pitEntry==null){
|
||||
LoggerHelper.logger.info("no match pit entry");
|
||||
LoggerHelper.info("no match pit entry");
|
||||
return;
|
||||
}
|
||||
pitEntry.onDataInterface.onData(pitEntry.interest,data);
|
||||
@@ -151,7 +151,7 @@ public class LogicFaceICN extends LogicFace {
|
||||
IdentifierWrapper identifierWrapper=nack.interest.minPacket.identifierField.getIdentifier(0);
|
||||
PITEntry pitEntry = this.getPitEntryAndDelete(identifierWrapper.getIdentifier());
|
||||
if(pitEntry==null){
|
||||
LoggerHelper.logger.info("no match pit entry");
|
||||
LoggerHelper.info("no match pit entry");
|
||||
return;
|
||||
}
|
||||
pitEntry.onNackInterface.onNack(pitEntry.interest,nack);
|
||||
@@ -230,12 +230,12 @@ public class LogicFaceICN extends LogicFace {
|
||||
while (true) {
|
||||
MINPacket minPacket = this.receivePacket(-1);
|
||||
if(minPacket==null){
|
||||
LoggerHelper.logger.debug("LogicFaceICN.doReceivePacket: receivePacket null");
|
||||
LoggerHelper.info("LogicFaceICN.doReceivePacket: receivePacket null");
|
||||
return;
|
||||
}
|
||||
IdentifierWrapper identifier=minPacket.identifierField.getIdentifier(0);
|
||||
if(identifier==null){
|
||||
LoggerHelper.logger.debug("LogicFaceICN.doReceivePacket: minPacket getIdentifier null");
|
||||
LoggerHelper.info("LogicFaceICN.doReceivePacket: minPacket getIdentifier null");
|
||||
}
|
||||
switch (identifier.getTlvType().getVlIntValue2Int()){
|
||||
case TLV.TlvIdentifierContentInterest:
|
||||
@@ -341,7 +341,7 @@ public class LogicFaceICN extends LogicFace {
|
||||
|
||||
Identifier interestName=interest.getName();
|
||||
if(interestName==null){
|
||||
LoggerHelper.logger.debug("LogicFaceICN.expressInterest: minPacket getIdentifier null");
|
||||
LoggerHelper.info("LogicFaceICN.expressInterest: minPacket getIdentifier null");
|
||||
return;
|
||||
}
|
||||
PITEntry pitEntry = null;
|
||||
@@ -356,7 +356,7 @@ public class LogicFaceICN extends LogicFace {
|
||||
}
|
||||
|
||||
if(!this.sendInterest(interest)){
|
||||
LoggerHelper.logger.debug("LogicFaceICN.expressInterest: send Interest false");
|
||||
LoggerHelper.info("LogicFaceICN.expressInterest: send Interest false");
|
||||
}
|
||||
} catch (ComponentException e) {
|
||||
throw new LogicFaceException("LogicFaceICN.expressInterest: "+e.getMessage());
|
||||
@@ -376,7 +376,7 @@ public class LogicFaceICN extends LogicFace {
|
||||
return;
|
||||
}
|
||||
if(!this.sendData(data)){
|
||||
LoggerHelper.logger.debug("LogicFaceICN.putData: send Data false");
|
||||
LoggerHelper.info("LogicFaceICN.putData: send Data false");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ public class StreamTransport extends Transport implements ITransport{
|
||||
try {
|
||||
this.channel.close();
|
||||
} catch (IOException e) {
|
||||
LoggerHelper.logger.debug("StreamTransport.close: "+e.getMessage());
|
||||
LoggerHelper.info("StreamTransport.close: "+e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ public class StreamTransport extends Transport implements ITransport{
|
||||
while (writeLen< encodeBuf.length){
|
||||
int writeRet=this.channel.write(ByteBuffer.wrap(encodeBuf));
|
||||
if(writeRet<0){
|
||||
LoggerHelper.logger.error("send to tcp transport error");
|
||||
LoggerHelper.severe("send to tcp transport error");
|
||||
this.linkService.logicFace.shutDown();
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -35,12 +35,12 @@ public class Transport {
|
||||
try {
|
||||
Block block=new Block(buf,true);
|
||||
if(!block.isValid()){
|
||||
LoggerHelper.logger.error("recv packet from face invalid");
|
||||
LoggerHelper.severe("recv packet from face invalid");
|
||||
return null;
|
||||
}
|
||||
LpPacket lpPacket=new LpPacket();
|
||||
if(!lpPacket.wireDecode(block)){
|
||||
LoggerHelper.logger.error("parse to lpPacket error");
|
||||
LoggerHelper.severe("parse to lpPacket error");
|
||||
return null;
|
||||
}
|
||||
return lpPacket;
|
||||
|
||||
@@ -57,7 +57,7 @@ public class UdpTransport extends Transport implements ITransport{
|
||||
try {
|
||||
this.channel.close();
|
||||
} catch (IOException e) {
|
||||
LoggerHelper.logger.error(e.getMessage());
|
||||
LoggerHelper.info(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ public class UdpTransport extends Transport implements ITransport{
|
||||
if(encodeBuf.length<=0){
|
||||
return false;
|
||||
}
|
||||
LoggerHelper.logger.debug("start write to udp : "+this.remoteUdpAddr.toString());
|
||||
LoggerHelper.info("start write to udp : "+this.remoteUdpAddr.toString());
|
||||
int res=this.channel.write(ByteBuffer.wrap(encodeBuf));
|
||||
if(res<0){
|
||||
return false;
|
||||
@@ -105,7 +105,7 @@ public class UdpTransport extends Transport implements ITransport{
|
||||
// return null;
|
||||
// }
|
||||
// byte[] readBytes= ByteHelper.getLenBytes(bf.array(),0,readLen);
|
||||
LoggerHelper.logger.debug("recv from udp: "+this.remoteAddr);
|
||||
LoggerHelper.info("recv from udp: "+this.remoteAddr);
|
||||
LpPacket lpPacket=this.parseByteArray2LpPacket(readBytes);
|
||||
if(lpPacket==null){
|
||||
return null;
|
||||
|
||||
@@ -48,7 +48,7 @@ public class UnixStreamTransport extends StreamTransport{
|
||||
try {
|
||||
this.channel.close();
|
||||
} catch (IOException e) {
|
||||
LoggerHelper.logger.debug(e.getMessage());
|
||||
LoggerHelper.info(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -164,7 +164,7 @@ public class CommandExecutor {
|
||||
try {
|
||||
controlResponse = (ControlResponse) JSONHelper.parseJsonToClass(data.payload.getValue(), controlResponse);
|
||||
} catch (JSONHelperException e) {
|
||||
LoggerHelper.logger.error("parse mgmt_data fail!the err is: " + e.getMessage());
|
||||
LoggerHelper.severe("parse mgmt_data fail!the err is: " + e.getMessage());
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,9 +2,10 @@ package minsecurity.certificate.cert;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import common.LoggerHelper;
|
||||
import minsecurity.Common;
|
||||
import minsecurity.crypto.*;
|
||||
import org.slf4j.LoggerFactory;
|
||||
//import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.crypto.BadPaddingException;
|
||||
import javax.crypto.IllegalBlockSizeException;
|
||||
@@ -24,7 +25,7 @@ import java.util.Base64;
|
||||
* @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
|
||||
*/
|
||||
public class CertUtils {
|
||||
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(CertUtils.class);
|
||||
// private static final org.slf4j.Logger logger = LoggerFactory.getLogger(CertUtils.class);
|
||||
public static final int VERSION1 = 1;
|
||||
|
||||
/**
|
||||
@@ -205,7 +206,7 @@ public class CertUtils {
|
||||
certificate.setSignature(priv.sign(bytesOfCert));
|
||||
break;
|
||||
default:
|
||||
logger.debug("signAlgo: {}", certificate.getSignatureAlgorithm());
|
||||
LoggerHelper.info("signAlgo: {}"+certificate.getSignatureAlgorithm());
|
||||
throw new Exception("未定义的签名方法");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ package minsecurity.certificate.cert;
|
||||
|
||||
import minsecurity.crypto.PublicKeyInterface;
|
||||
import org.bouncycastle.pqc.math.linearalgebra.ByteUtils;
|
||||
import org.slf4j.LoggerFactory;
|
||||
//import org.slf4j.LoggerFactory;
|
||||
|
||||
|
||||
/*
|
||||
@@ -13,7 +13,7 @@ import org.slf4j.LoggerFactory;
|
||||
* @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
|
||||
*/
|
||||
public class Certificate {
|
||||
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(Certificate.class);
|
||||
// private static final org.slf4j.Logger logger = LoggerFactory.getLogger(Certificate.class);
|
||||
|
||||
private int version;
|
||||
private long serialNumber;
|
||||
|
||||
@@ -15,7 +15,7 @@ import org.bouncycastle.jce.spec.ECParameterSpec;
|
||||
import org.bouncycastle.math.ec.ECPoint;
|
||||
import org.bouncycastle.math.ec.custom.gm.SM2P256V1Curve;
|
||||
import org.bouncycastle.pqc.math.linearalgebra.ByteUtils;
|
||||
import org.slf4j.LoggerFactory;
|
||||
//import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.security.*;
|
||||
@@ -37,7 +37,7 @@ public class SM2Base {
|
||||
Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
|
||||
}
|
||||
|
||||
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(SM2Base.class);
|
||||
// private static final org.slf4j.Logger logger = LoggerFactory.getLogger(SM2Base.class);
|
||||
|
||||
/*
|
||||
* 以下为SM2推荐曲线参数
|
||||
|
||||
@@ -14,7 +14,7 @@ import org.bouncycastle.crypto.CryptoException;
|
||||
import org.bouncycastle.crypto.InvalidCipherTextException;
|
||||
import org.bouncycastle.jcajce.provider.digest.SM3;
|
||||
import org.bouncycastle.pqc.math.linearalgebra.ByteUtils;
|
||||
import org.slf4j.LoggerFactory;
|
||||
//import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.crypto.BadPaddingException;
|
||||
import javax.crypto.IllegalBlockSizeException;
|
||||
@@ -37,7 +37,7 @@ import java.util.Base64;
|
||||
* @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
|
||||
*/
|
||||
public class Identity {
|
||||
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(Identity.class);
|
||||
// private static final org.slf4j.Logger logger = LoggerFactory.getLogger(Identity.class);
|
||||
private String Name;
|
||||
private KeyParam KeyParam;
|
||||
private PrivateKeyInterface Prikey;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package util;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.RandomAccessFile;
|
||||
|
||||
@@ -30,4 +31,37 @@ public class FileUtil {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 确认某个需要存在的文件夹存在:不存在则自动创建之,返回false;否则返回true
|
||||
* @return
|
||||
*/
|
||||
public static boolean confirmDirExistence(String fileName){
|
||||
File file =new File(fileName);
|
||||
boolean flag=true;
|
||||
if(!file.exists()) {
|
||||
file.mkdirs();
|
||||
flag=false;
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
|
||||
/**
|
||||
* 确认某个需要存在的文件存在:不存在则自动创建之,返回false;否则返回true
|
||||
* @return
|
||||
*/
|
||||
public static boolean confirmFileExistence(String fileName){
|
||||
File file =new File(fileName);
|
||||
boolean flag=true;
|
||||
try {
|
||||
if(!file.exists()) {
|
||||
file.createNewFile();
|
||||
flag=false;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
flag=false;
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,11 +12,19 @@ import org.junit.Test;
|
||||
public class LoggerHelperTest {
|
||||
@Test
|
||||
public void testLogger(){
|
||||
System.out.println(LoggerHelper.logger.getName());
|
||||
LoggerHelper.logger.trace("Trace Level.");
|
||||
LoggerHelper.logger.debug("Debug Level.");
|
||||
LoggerHelper.logger.info("Info Level.");
|
||||
LoggerHelper.logger.warn("Warn Level.");
|
||||
LoggerHelper.logger.error("Error Level.");
|
||||
// LoggerHelper.info("testabc");
|
||||
LoggerHelper.severe("hhhhh");
|
||||
LoggerHelper.OpenLoggerFlag=false;
|
||||
LoggerHelper.severe("xixixix");
|
||||
// LoggerHelper.fine("xixixix");
|
||||
// LoggerHelper.OpenLoggerFlag=false;
|
||||
// LoggerHelper.warning("sssss");
|
||||
|
||||
// System.out.println(LoggerHelper.logger.getName());
|
||||
// LoggerHelper.logger.trace("Trace Level.");
|
||||
// LoggerHelper.logger.debug("Debug Level.");
|
||||
// LoggerHelper.logger.info("Info Level.");
|
||||
// LoggerHelper.logger.warn("Warn Level.");
|
||||
// LoggerHelper.logger.error("Error Level.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
package encoding;
|
||||
|
||||
|
||||
import common.LoggerHelper;
|
||||
import minsecurity.crypto.TestSM2;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.slf4j.LoggerFactory;
|
||||
//import org.slf4j.LoggerFactory;
|
||||
import util.ByteHelper;
|
||||
|
||||
import java.math.BigInteger;
|
||||
@@ -20,7 +21,7 @@ import static org.junit.Assert.*;
|
||||
*/
|
||||
|
||||
public class VlIntTest {
|
||||
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(VlIntTest.class);
|
||||
// private static final org.slf4j.Logger logger = LoggerFactory.getLogger(VlIntTest.class);
|
||||
|
||||
// 测试
|
||||
public static void main(String[] args){
|
||||
@@ -198,9 +199,9 @@ public class VlIntTest {
|
||||
VlInt vlInt1 = new VlInt(a1);
|
||||
VlInt vlInt2 = new VlInt(a2);
|
||||
VlInt vlInt3 = new VlInt(l);
|
||||
logger.debug(vlInt1.toString());
|
||||
logger.debug(vlInt2.toString());
|
||||
logger.debug(vlInt3.toString());
|
||||
LoggerHelper.info(vlInt1.toString());
|
||||
LoggerHelper.info(vlInt2.toString());
|
||||
LoggerHelper.info(vlInt3.toString());
|
||||
|
||||
assertEquals(vlInt2.subtract(vlInt1),s1);
|
||||
assertEquals(vlInt1.subtract(vlInt2),s2); //差为负数
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package minsecurity.certificate.cert;
|
||||
|
||||
import common.LoggerHelper;
|
||||
import minsecurity.Common;
|
||||
import minsecurity.crypto.sm2.SM2Base;
|
||||
import minsecurity.crypto.sm2.SM2PrivateKey;
|
||||
@@ -9,7 +10,7 @@ import org.bouncycastle.crypto.params.ECPrivateKeyParameters;
|
||||
import org.bouncycastle.crypto.params.ECPublicKeyParameters;
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.*;
|
||||
import org.slf4j.LoggerFactory;
|
||||
//import org.slf4j.LoggerFactory;
|
||||
|
||||
/*
|
||||
* @Author: hongyu guo
|
||||
@@ -19,7 +20,7 @@ import org.slf4j.LoggerFactory;
|
||||
* @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
|
||||
*/
|
||||
public class TestCert {
|
||||
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(TestCert.class);
|
||||
// private static final org.slf4j.Logger logger = LoggerFactory.getLogger(TestCert.class);
|
||||
@Test
|
||||
public void testCertSignAndVerify() throws Exception {
|
||||
AsymmetricCipherKeyPair keyPair = SM2Base.generateKeyPairParameter();
|
||||
@@ -88,12 +89,12 @@ public class TestCert {
|
||||
|
||||
String pem = CertUtils.toPem(certificate,null,0);
|
||||
Certificate certFromPem = CertUtils.fromPem(pem, null,0);
|
||||
logger.debug(certFromPem.toString());
|
||||
LoggerHelper.info(certFromPem.toString());
|
||||
assertTrue(CertUtils.verifyCert(certFromPem,certFromPem));
|
||||
|
||||
String pem2 = CertUtils.toPem(certificate, new byte[]{1,2,3,4,5,6,7,8},Common.SM4ECB);
|
||||
Certificate certFromPem2 = CertUtils.fromPem(pem2, new byte[]{1,2,3,4,5,6,7,8},Common.SM4ECB);
|
||||
logger.debug(certFromPem2.toString());
|
||||
LoggerHelper.info(certFromPem2.toString());
|
||||
assertTrue(CertUtils.verifyCert(certFromPem2,certFromPem2));
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package minsecurity.certificate.x509;
|
||||
|
||||
import common.LoggerHelper;
|
||||
import minsecurity.Common;
|
||||
import minsecurity.certificate.X509.X509CertMaker;
|
||||
import minsecurity.certificate.X509.X509CertUtil;
|
||||
@@ -10,7 +11,7 @@ import org.bouncycastle.util.io.pem.PemObject;
|
||||
import org.bouncycastle.util.io.pem.PemWriter;
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.*;
|
||||
import org.slf4j.LoggerFactory;
|
||||
//import org.slf4j.LoggerFactory;
|
||||
import util.FileUtil;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
@@ -43,7 +44,7 @@ public class TestX509 {
|
||||
static {
|
||||
Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
|
||||
}
|
||||
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(TestX509.class);
|
||||
// private static final org.slf4j.Logger logger = LoggerFactory.getLogger(TestX509.class);
|
||||
private static final Provider BC = new BouncyCastleProvider();
|
||||
|
||||
@Test
|
||||
@@ -71,11 +72,11 @@ public class TestX509 {
|
||||
PrivateKey privateKey = keyFac.generatePrivate(keySpec);
|
||||
KeyPair rootKeyPair = new KeyPair(publicKey, privateKey);
|
||||
|
||||
logger.debug("origin: {}", ByteUtils.toHexString(rootKP.getPrivate().getEncoded()));
|
||||
logger.debug("rebuild:{}", ByteUtils.toHexString(rootKeyPair.getPrivate().getEncoded()));
|
||||
LoggerHelper.info("origin: {}"+ ByteUtils.toHexString(rootKP.getPrivate().getEncoded()));
|
||||
LoggerHelper.info("rebuild:{}"+ ByteUtils.toHexString(rootKeyPair.getPrivate().getEncoded()));
|
||||
|
||||
logger.debug("origin: {}", ByteUtils.toHexString(rootKP.getPublic().getEncoded()));
|
||||
logger.debug("rebuild:{}", ByteUtils.toHexString(rootKeyPair.getPublic().getEncoded()));
|
||||
LoggerHelper.info("origin: {}"+ ByteUtils.toHexString(rootKP.getPublic().getEncoded()));
|
||||
LoggerHelper.info("rebuild:{}"+ ByteUtils.toHexString(rootKeyPair.getPublic().getEncoded()));
|
||||
|
||||
KeyPair subKeyPair = SM2Base.generateKeyPair();
|
||||
X509Certificate subCert =
|
||||
@@ -118,6 +119,6 @@ public class TestX509 {
|
||||
PemWriter pemWriter = new PemWriter(sw);
|
||||
pemWriter.writeObject(pemCSR);
|
||||
pemWriter.close();
|
||||
logger.debug(sw.toString());
|
||||
LoggerHelper.info(sw.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package minsecurity.crypto;
|
||||
|
||||
import common.LoggerHelper;
|
||||
import minsecurity.crypto.sm2.SM2Base;
|
||||
import minsecurity.crypto.sm2.SM2PrivateKey;
|
||||
import minsecurity.crypto.sm2.SM2PublicKey;
|
||||
@@ -11,7 +12,7 @@ import org.bouncycastle.crypto.params.ECPublicKeyParameters;
|
||||
import org.bouncycastle.pqc.math.linearalgebra.ByteUtils;
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.*;
|
||||
import org.slf4j.LoggerFactory;
|
||||
//import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.ArrayList;
|
||||
@@ -25,7 +26,7 @@ import java.util.List;
|
||||
* @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
|
||||
*/
|
||||
public class TestSM2 {
|
||||
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(TestSM2.class);
|
||||
// private static final org.slf4j.Logger logger = LoggerFactory.getLogger(TestSM2.class);
|
||||
@Test
|
||||
public void testSetGet() throws InvalidCipherTextException {
|
||||
AsymmetricCipherKeyPair keyPair = SM2Base.generateKeyPairParameter();
|
||||
@@ -34,7 +35,7 @@ public class TestSM2 {
|
||||
byte[] d = priKey.getD().toByteArray();
|
||||
byte[] x = pubKey.getQ().getAffineXCoord().getEncoded();
|
||||
byte[] y = pubKey.getQ().getAffineYCoord().getEncoded();
|
||||
logger.debug("d.len = {}, x.len = {}, y.len = {}",d.length, x.length, y.length);
|
||||
LoggerHelper.info("d.len = {}, x.len = {}, y.len = {}"+d.length+ x.length+ y.length);
|
||||
// BigInteger bigInteger = priKey.getD();
|
||||
SM2PrivateKey sm2PrivateKey = new SM2PrivateKey();
|
||||
SM2PublicKey sm2PublicKey = new SM2PublicKey();
|
||||
@@ -69,7 +70,7 @@ public class TestSM2 {
|
||||
// d = Arrays.copyOf(d,32);
|
||||
byte[] x = pubKey.getQ().getAffineXCoord().getEncoded();
|
||||
byte[] y = pubKey.getQ().getAffineYCoord().getEncoded();
|
||||
logger.debug("d.len = {}, x.len = {}, y.len = {}",d.length, x.length, y.length);
|
||||
LoggerHelper.info("d.len = {}, x.len = {}, y.len = {}"+d.length+ x.length+ y.length);
|
||||
// BigInteger bigInteger = priKey.getD();
|
||||
SM2PrivateKey sm2PrivateKey = new SM2PrivateKey(d);
|
||||
SM2PublicKey sm2PublicKey = new SM2PublicKey(x,y);
|
||||
@@ -90,7 +91,7 @@ public class TestSM2 {
|
||||
// d = Arrays.copyOf(d,32);
|
||||
byte[] x = pubKey.getQ().getAffineXCoord().getEncoded();
|
||||
byte[] y = pubKey.getQ().getAffineYCoord().getEncoded();
|
||||
logger.debug("d.len = {}, x.len = {}, y.len = {}",d.length, x.length, y.length);
|
||||
LoggerHelper.info("d.len = {}, x.len = {}, y.len = {}"+d.length+ x.length+ y.length);
|
||||
|
||||
// BigInteger bigInteger = priKey.getD();
|
||||
SM2PrivateKey sm2PrivateKey = new SM2PrivateKey(d);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package minsecurity.identity;
|
||||
|
||||
import common.LoggerHelper;
|
||||
import minsecurity.Common;
|
||||
import minsecurity.certificate.cert.CertUtils;
|
||||
import minsecurity.certificate.cert.Certificate;
|
||||
@@ -14,7 +15,7 @@ import org.bouncycastle.crypto.params.ECPublicKeyParameters;
|
||||
import org.bouncycastle.pqc.math.linearalgebra.ByteUtils;
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.*;
|
||||
import org.slf4j.LoggerFactory;
|
||||
//import org.slf4j.LoggerFactory;
|
||||
|
||||
/*
|
||||
* @Author: hongyu guo
|
||||
@@ -24,7 +25,7 @@ import org.slf4j.LoggerFactory;
|
||||
* @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
|
||||
*/
|
||||
public class TestIdentity {
|
||||
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(TestIdentity.class);
|
||||
// private static final org.slf4j.Logger logger = LoggerFactory.getLogger(TestIdentity.class);
|
||||
|
||||
/**
|
||||
* 随机生成身份数据
|
||||
@@ -72,7 +73,7 @@ public class TestIdentity {
|
||||
// d = Arrays.copyOf(d,32);
|
||||
byte[] x = pubKey.getQ().getAffineXCoord().getEncoded();
|
||||
byte[] y = pubKey.getQ().getAffineYCoord().getEncoded();
|
||||
logger.debug("d.len = {}, x.len = {}, y.len = {}",d.length, x.length, y.length);
|
||||
LoggerHelper.info("d.len = {}, x.len = {}, y.len = {}"+d.length+ x.length+ y.length);
|
||||
|
||||
// BigInteger bigInteger = priKey.getD();
|
||||
SM2PrivateKey sm2PrivateKey = new SM2PrivateKey(d);
|
||||
@@ -90,7 +91,7 @@ public class TestIdentity {
|
||||
// test sign and verify
|
||||
byte[] signature = identity.sign(text.getBytes());
|
||||
boolean flag = identity.verify(text.getBytes(), signature);
|
||||
logger.debug("identity verify: {}", flag);
|
||||
LoggerHelper.info("identity verify: {}"+flag);
|
||||
assertTrue(flag);
|
||||
|
||||
|
||||
@@ -111,6 +112,6 @@ public class TestIdentity {
|
||||
assertEquals(ByteUtils.toHexString(identity.getPrikey().getBytes()), ByteUtils.toHexString(idFromBytes.getPrikey().getBytes()));
|
||||
assertEquals(ByteUtils.toHexString(identity.getPubkey().getBytes()), ByteUtils.toHexString(idFromBytes.getPubkey().getBytes()));
|
||||
|
||||
logger.debug(identity.getPrikey().getBytes().length + " " + identity.getPubkey().getBytes().length);
|
||||
LoggerHelper.info(identity.getPrikey().getBytes().length + " " + identity.getPubkey().getBytes().length);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package minsecurity.identity;
|
||||
|
||||
|
||||
import common.LoggerHelper;
|
||||
import minsecurity.Common;
|
||||
import minsecurity.certificate.cert.CertUtils;
|
||||
import minsecurity.certificate.cert.Certificate;
|
||||
@@ -20,8 +21,8 @@ import org.junit.Test;
|
||||
//import org.mapdb.DB;
|
||||
//import org.mapdb.DBMaker;
|
||||
//import org.mapdb.Serializer;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
//import org.slf4j.Logger;
|
||||
//import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
@@ -34,7 +35,7 @@ import java.util.concurrent.ConcurrentMap;
|
||||
* @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
|
||||
*/
|
||||
public class TestPersist {
|
||||
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(TestIdentity.class);
|
||||
// private static final org.slf4j.Logger logger = LoggerFactory.getLogger(TestIdentity.class);
|
||||
|
||||
/**
|
||||
* 随机生成身份数据
|
||||
@@ -90,14 +91,14 @@ public class TestPersist {
|
||||
// 获取数据库中所有数据
|
||||
List<Identity> identities = Persist.getAllIdentityFromStorage("");
|
||||
for (Identity i:
|
||||
identities) {
|
||||
logger.debug("当前用户:"+i.getName());
|
||||
identities) {
|
||||
LoggerHelper.info("当前用户:"+i.getName());
|
||||
// 测试 getIdentityByNameFromStorage
|
||||
Identity id = Persist.getIdentityByNameFromStorage(i.getName(), "");
|
||||
logger.debug("查询用户:"+id.getName());
|
||||
LoggerHelper.info("查询用户:"+id.getName());
|
||||
}
|
||||
}catch (Exception ex){
|
||||
logger.debug(String.format("测试失败:%s", ex.getMessage()));
|
||||
LoggerHelper.info(String.format("测试失败:%s", ex.getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -118,12 +119,12 @@ public class TestPersist {
|
||||
List<Identity> identities = Persist.getAllIdentityFromStorage("");
|
||||
for (Identity i:
|
||||
identities) {
|
||||
logger.debug(i.getName());
|
||||
LoggerHelper.info(i.getName());
|
||||
Identity id = Persist.getIdentityByNameFromStorage(i.getName(), "");
|
||||
logger.debug("查询用户:"+id.getName());
|
||||
LoggerHelper.info("查询用户:"+id.getName());
|
||||
}
|
||||
}catch (Exception ex){
|
||||
logger.debug(String.format("测试失败:%s", ex.getMessage()));
|
||||
LoggerHelper.info(String.format("测试失败:%s", ex.getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -140,13 +141,13 @@ public class TestPersist {
|
||||
List<Identity> identities = Persist.getAllIdentityFromStorage("");
|
||||
for (Identity i:
|
||||
identities) {
|
||||
logger.debug(String.format("为 %s 设置默认身份", i.getName()));
|
||||
LoggerHelper.info(String.format("为 %s 设置默认身份", i.getName()));
|
||||
Persist.setDefaultIdentityByNameInStorage(i.getName());
|
||||
Identity did = Persist.getDefaultIdentityFromStorage("");
|
||||
logger.debug(String.format("当前默认身份 %s", did.getName()));
|
||||
LoggerHelper.info(String.format("当前默认身份 %s", did.getName()));
|
||||
}
|
||||
}catch (Exception ex){
|
||||
logger.debug(String.format("测试失败:%s", ex.getMessage()));
|
||||
LoggerHelper.info(String.format("测试失败:%s", ex.getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -163,14 +164,14 @@ public class TestPersist {
|
||||
List<Identity> identities = Persist.getAllIdentityFromStorage("");
|
||||
for (Identity i:
|
||||
identities) {
|
||||
logger.debug(String.format("为 %s 设置默认身份", i.getName()));
|
||||
LoggerHelper.info(String.format("为 %s 设置默认身份", i.getName()));
|
||||
Persist.setDefaultIdentityByNameInStorage(null);
|
||||
Persist.setDefaultIdentityByNameInStorage("");
|
||||
Identity did = Persist.getDefaultIdentityFromStorage("");
|
||||
logger.debug(String.format("当前默认身份 %s", did.getName()));
|
||||
LoggerHelper.info(String.format("当前默认身份 %s", did.getName()));
|
||||
}
|
||||
}catch (Exception ex){
|
||||
logger.debug(String.format("测试失败:%s", ex.getMessage()));
|
||||
LoggerHelper.info(String.format("测试失败:%s", ex.getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -187,13 +188,13 @@ public class TestPersist {
|
||||
List<Identity> identities = Persist.getAllIdentityFromStorage("");
|
||||
for (Identity i:
|
||||
identities) {
|
||||
logger.debug(String.format("删除名称为 %s 的用户", i.getName()));
|
||||
LoggerHelper.info(String.format("删除名称为 %s 的用户", i.getName()));
|
||||
Persist.deleteIdentityByNameFromStorage(i.getName());
|
||||
Identity did = Persist.getIdentityByNameFromStorage(i.getName(), "");
|
||||
logger.debug(String.format("查询 %s 结果: %s", i.getName(), did));
|
||||
LoggerHelper.info(String.format("查询 %s 结果: %s", i.getName(), did));
|
||||
}
|
||||
}catch (Exception ex){
|
||||
logger.debug(String.format("测试失败:%s", ex.getMessage()));
|
||||
LoggerHelper.info(String.format("测试失败:%s", ex.getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -210,11 +211,11 @@ public class TestPersist {
|
||||
List<Identity> identities = Persist.getAllIdentityFromStorage("");
|
||||
for (Identity i:
|
||||
identities) {
|
||||
logger.debug(String.format("删除名称为 %s 的用户", null));
|
||||
LoggerHelper.info(String.format("删除名称为 %s 的用户", null));
|
||||
Persist.deleteIdentityByNameFromStorage(null);
|
||||
}
|
||||
}catch (Exception ex){
|
||||
logger.debug(String.format("测试失败:%s", ex.getMessage()));
|
||||
LoggerHelper.info(String.format("测试失败:%s", ex.getMessage()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package security;
|
||||
|
||||
import common.LoggerHelper;
|
||||
import minsecurity.Common;
|
||||
import minsecurity.certificate.cert.CertUtils;
|
||||
import minsecurity.certificate.cert.Certificate;
|
||||
@@ -9,14 +10,14 @@ import minsecurity.identity.KeyParam;
|
||||
import minsecurity.identity.TestIdentity;
|
||||
import minsecurity.identity.persist.sqlite.Sqlite;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.LoggerFactory;
|
||||
//import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
public class IdentifyManagerTest {
|
||||
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(TestIdentity.class);
|
||||
// private static final org.slf4j.Logger logger = LoggerFactory.getLogger(TestIdentity.class);
|
||||
/**
|
||||
* 随机生成身份数据
|
||||
* @return Identity
|
||||
@@ -59,11 +60,11 @@ public class IdentifyManagerTest {
|
||||
// 打开数据库
|
||||
// Sqlite.getInstance().openDefault();
|
||||
IdentifyManager manager = new IdentifyManager();
|
||||
logger.debug(String.format("默认身份:%s", manager.getDefaultIdentity().getName()));
|
||||
logger.debug(String.format("身份数量:%d", manager.getIdentifies().size()));
|
||||
logger.debug(String.format("私钥加密算法:%d", manager.getPrivateKeyEncryptionAlgorithm()));
|
||||
LoggerHelper.info(String.format("默认身份:%s", manager.getDefaultIdentity().getName()));
|
||||
LoggerHelper.info(String.format("身份数量:%d", manager.getIdentifies().size()));
|
||||
LoggerHelper.info(String.format("私钥加密算法:%d", manager.getPrivateKeyEncryptionAlgorithm()));
|
||||
}catch (Exception ex){
|
||||
logger.debug(ex.getMessage());
|
||||
LoggerHelper.info(ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,11 +76,11 @@ public class IdentifyManagerTest {
|
||||
Set<String> keySet = hashMap.keySet();
|
||||
// 查询所有manager中的用户
|
||||
for (String s:
|
||||
keySet) {
|
||||
logger.debug(String.format("查询身份:%s,结果身份:%s", s, manager.getIdentityByName(s).getName()));
|
||||
keySet) {
|
||||
LoggerHelper.info(String.format("查询身份:%s,结果身份:%s", s, manager.getIdentityByName(s).getName()));
|
||||
}
|
||||
}catch (Exception ex){
|
||||
logger.debug(ex.getMessage());
|
||||
LoggerHelper.info(ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,21 +88,21 @@ public class IdentifyManagerTest {
|
||||
public void testGetIdentityByName2(){
|
||||
try{
|
||||
IdentifyManager manager = new IdentifyManager();
|
||||
logger.debug(String.format("身份数量:%d", manager.getIdentifies().size()));
|
||||
LoggerHelper.info(String.format("身份数量:%d", manager.getIdentifies().size()));
|
||||
ConcurrentMap<String, Identity> hashMap = manager.getIdentifies();
|
||||
Set<String> keySet = hashMap.keySet();
|
||||
for (String s:
|
||||
keySet) {
|
||||
// 查询不存在的名称 返回null
|
||||
String sSet = s + "test";
|
||||
logger.debug(String.format("查询身份:%s,结果身份:%s", sSet, manager.getIdentityByName(sSet)));
|
||||
LoggerHelper.info(String.format("查询身份:%s,结果身份:%s", sSet, manager.getIdentityByName(sSet)));
|
||||
// 查询null 抛出异常 已改为返回null
|
||||
sSet = null;
|
||||
logger.debug(String.format("查询身份:%s,结果身份:%s", sSet, manager.getIdentityByName(sSet)));
|
||||
LoggerHelper.info(String.format("查询身份:%s,结果身份:%s", sSet, manager.getIdentityByName(sSet)));
|
||||
}
|
||||
logger.debug(String.format("身份数量:%d", manager.getIdentifies().size()));
|
||||
LoggerHelper.info(String.format("身份数量:%d", manager.getIdentifies().size()));
|
||||
}catch (Exception ex){
|
||||
logger.debug(ex.getMessage());
|
||||
LoggerHelper.info(ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,21 +110,21 @@ public class IdentifyManagerTest {
|
||||
public void testDeleteIdentityByName2(){
|
||||
try{
|
||||
IdentifyManager manager = new IdentifyManager();
|
||||
logger.debug(String.format("身份数量:%d", manager.getIdentifies().size()));
|
||||
LoggerHelper.info(String.format("身份数量:%d", manager.getIdentifies().size()));
|
||||
ConcurrentMap<String, Identity> hashMap = manager.getIdentifies();
|
||||
Set<String> keySet = hashMap.keySet();
|
||||
for (String s:
|
||||
keySet) {
|
||||
// 删除不存在的名称 返回false
|
||||
String sSet = s + "test";
|
||||
logger.debug(String.format("删除身份:%s,结果:%s", sSet, manager.deleteIdentityByName(sSet, true)));
|
||||
LoggerHelper.info(String.format("删除身份:%s,结果:%s", sSet, manager.deleteIdentityByName(sSet, true)));
|
||||
// 查询null 抛出异常 已改为返回false
|
||||
sSet = null;
|
||||
logger.debug(String.format("删除身份:%s,结果:%s", sSet, manager.deleteIdentityByName(sSet, true)));
|
||||
LoggerHelper.info(String.format("删除身份:%s,结果:%s", sSet, manager.deleteIdentityByName(sSet, true)));
|
||||
}
|
||||
logger.debug(String.format("身份数量:%d", manager.getIdentifies().size()));
|
||||
LoggerHelper.info(String.format("身份数量:%d", manager.getIdentifies().size()));
|
||||
}catch (Exception ex){
|
||||
logger.debug(ex.getMessage());
|
||||
LoggerHelper.info(ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -131,18 +132,18 @@ public class IdentifyManagerTest {
|
||||
public void testDeleteIdentityByName(){
|
||||
try{
|
||||
IdentifyManager manager = new IdentifyManager();
|
||||
logger.debug(String.format("身份数量:%d", manager.getIdentifies().size()));
|
||||
LoggerHelper.info(String.format("身份数量:%d", manager.getIdentifies().size()));
|
||||
ConcurrentMap<String, Identity> hashMap = manager.getIdentifies();
|
||||
Set<String> keySet = hashMap.keySet();
|
||||
// 删除所有manager中的用户
|
||||
for (String s:
|
||||
keySet) {
|
||||
logger.debug(String.format("删除身份:%s,结果:%s", s, manager.deleteIdentityByName(s, true)));
|
||||
logger.debug(String.format("查询身份:%s,结果身份:%s", s, manager.getIdentityByName(s)));
|
||||
LoggerHelper.info(String.format("删除身份:%s,结果:%s", s, manager.deleteIdentityByName(s, true)));
|
||||
LoggerHelper.info(String.format("查询身份:%s,结果身份:%s", s, manager.getIdentityByName(s)));
|
||||
}
|
||||
logger.debug(String.format("身份数量:%d", manager.getIdentifies().size()));
|
||||
LoggerHelper.info(String.format("身份数量:%d", manager.getIdentifies().size()));
|
||||
}catch (Exception ex){
|
||||
logger.debug(ex.getMessage());
|
||||
LoggerHelper.info(ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -150,16 +151,16 @@ public class IdentifyManagerTest {
|
||||
public void testSaveIdentity(){
|
||||
try{
|
||||
IdentifyManager manager = new IdentifyManager();
|
||||
logger.debug(String.format("身份数量:%d", manager.getIdentifies().size()));
|
||||
LoggerHelper.info(String.format("身份数量:%d", manager.getIdentifies().size()));
|
||||
// 随机生成身份并保存 重复五次
|
||||
for (int i = 0; i < 5; i++) {
|
||||
Identity id = createRandomIdentity();
|
||||
// todo 确认是否需要强制覆盖?
|
||||
logger.debug(String.format("保存身份:%s,结果:%s", id.getName(), manager.saveIdentity(id, true, true)));
|
||||
LoggerHelper.info(String.format("保存身份:%s,结果:%s", id.getName(), manager.saveIdentity(id, true, true)));
|
||||
}
|
||||
logger.debug(String.format("身份数量:%d", manager.getIdentifies().size()));
|
||||
LoggerHelper.info(String.format("身份数量:%d", manager.getIdentifies().size()));
|
||||
}catch (Exception ex){
|
||||
logger.debug(ex.getMessage());
|
||||
LoggerHelper.info(ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -167,15 +168,15 @@ public class IdentifyManagerTest {
|
||||
public void testSaveIdentity2(){
|
||||
try{
|
||||
IdentifyManager manager = new IdentifyManager();
|
||||
logger.debug(String.format("身份数量:%d", manager.getIdentifies().size()));
|
||||
LoggerHelper.info(String.format("身份数量:%d", manager.getIdentifies().size()));
|
||||
// 插入 null 重复五次
|
||||
for (int i = 0; i < 5; i++) {
|
||||
Identity id = null;
|
||||
logger.debug(String.format("保存身份:%s,结果:%s", id, manager.saveIdentity(id, true, true)));
|
||||
LoggerHelper.info(String.format("保存身份:%s,结果:%s", id, manager.saveIdentity(id, true, true)));
|
||||
}
|
||||
logger.debug(String.format("身份数量:%d", manager.getIdentifies().size()));
|
||||
LoggerHelper.info(String.format("身份数量:%d", manager.getIdentifies().size()));
|
||||
}catch (Exception ex){
|
||||
logger.debug(ex.getMessage());
|
||||
LoggerHelper.info(ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -183,7 +184,7 @@ public class IdentifyManagerTest {
|
||||
public void testCreateIdentityByNameAndKeyParam(){
|
||||
try{
|
||||
IdentifyManager manager = new IdentifyManager();
|
||||
logger.debug(String.format("身份数量:%d", manager.getIdentifies().size()));
|
||||
LoggerHelper.info(String.format("身份数量:%d", manager.getIdentifies().size()));
|
||||
// 随机生成名称并保存 重复五次
|
||||
for (int i = 0; i < 5; i++) {
|
||||
String s = "wzq"+Math.random();
|
||||
@@ -191,11 +192,11 @@ public class IdentifyManagerTest {
|
||||
keyParam.PublicKeyAlgorithm = 0;
|
||||
keyParam.SignatureAlgorithm = 0;
|
||||
// todo 确认身份在没有证书的情况下能否存储
|
||||
logger.debug(String.format("保存身份:%s,结果:%s", s, manager.createIdentityByNameAndKeyParam(s, keyParam, "1234", true)));
|
||||
LoggerHelper.info(String.format("保存身份:%s,结果:%s", s, manager.createIdentityByNameAndKeyParam(s, keyParam, "1234", true)));
|
||||
}
|
||||
logger.debug(String.format("身份数量:%d", manager.getIdentifies().size()));
|
||||
LoggerHelper.info(String.format("身份数量:%d", manager.getIdentifies().size()));
|
||||
}catch (Exception ex){
|
||||
logger.debug(ex.getMessage());
|
||||
LoggerHelper.info(ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -203,15 +204,15 @@ public class IdentifyManagerTest {
|
||||
public void testCreateIdentityByName(){
|
||||
try{
|
||||
IdentifyManager manager = new IdentifyManager();
|
||||
logger.debug(String.format("身份数量:%d", manager.getIdentifies().size()));
|
||||
LoggerHelper.info(String.format("身份数量:%d", manager.getIdentifies().size()));
|
||||
// 随机生成名称并保存 重复五次
|
||||
for (int i = 0; i < 5; i++) {
|
||||
String s = "wzq"+Math.random();
|
||||
logger.debug(String.format("保存身份:%s,结果:%s", s, manager.createIdentityByName(s, "1234", true)));
|
||||
LoggerHelper.info(String.format("保存身份:%s,结果:%s", s, manager.createIdentityByName(s, "1234", true)));
|
||||
}
|
||||
logger.debug(String.format("身份数量:%d", manager.getIdentifies().size()));
|
||||
LoggerHelper.info(String.format("身份数量:%d", manager.getIdentifies().size()));
|
||||
}catch (Exception ex){
|
||||
logger.debug(ex.getMessage());
|
||||
LoggerHelper.info(ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -219,16 +220,16 @@ public class IdentifyManagerTest {
|
||||
public void testCreateIdentityByName2(){
|
||||
try{
|
||||
IdentifyManager manager = new IdentifyManager();
|
||||
logger.debug(String.format("身份数量:%d", manager.getIdentifies().size()));
|
||||
LoggerHelper.info(String.format("身份数量:%d", manager.getIdentifies().size()));
|
||||
// 保存null 重复五次
|
||||
for (int i = 0; i < 5; i++) {
|
||||
String s = null;
|
||||
// 保存失败 返回null
|
||||
logger.debug(String.format("保存身份:%s,结果:%s", s, manager.createIdentityByName(s, "1234", true)));
|
||||
LoggerHelper.info(String.format("保存身份:%s,结果:%s", s, manager.createIdentityByName(s, "1234", true)));
|
||||
}
|
||||
logger.debug(String.format("身份数量:%d", manager.getIdentifies().size()));
|
||||
LoggerHelper.info(String.format("身份数量:%d", manager.getIdentifies().size()));
|
||||
}catch (Exception ex){
|
||||
logger.debug(ex.getMessage());
|
||||
LoggerHelper.info(ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -236,16 +237,16 @@ public class IdentifyManagerTest {
|
||||
public void testCreateIdentityByNameAndKeyParam2(){
|
||||
try{
|
||||
IdentifyManager manager = new IdentifyManager();
|
||||
logger.debug(String.format("身份数量:%d", manager.getIdentifies().size()));
|
||||
LoggerHelper.info(String.format("身份数量:%d", manager.getIdentifies().size()));
|
||||
// 保存null 重复五次
|
||||
for (int i = 0; i < 5; i++) {
|
||||
String s = null;
|
||||
// 不会插入 返回null
|
||||
logger.debug(String.format("保存身份:%s,结果:%s", s, manager.createIdentityByName(s, "1234", true)));
|
||||
LoggerHelper.info(String.format("保存身份:%s,结果:%s", s, manager.createIdentityByName(s, "1234", true)));
|
||||
}
|
||||
logger.debug(String.format("身份数量:%d", manager.getIdentifies().size()));
|
||||
LoggerHelper.info(String.format("身份数量:%d", manager.getIdentifies().size()));
|
||||
}catch (Exception ex){
|
||||
logger.debug(ex.getMessage());
|
||||
LoggerHelper.info(ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -253,18 +254,18 @@ public class IdentifyManagerTest {
|
||||
public void testSetDefaultIdentity(){
|
||||
try{
|
||||
IdentifyManager manager = new IdentifyManager();
|
||||
logger.debug(String.format("身份数量:%d", manager.getIdentifies().size()));
|
||||
LoggerHelper.info(String.format("身份数量:%d", manager.getIdentifies().size()));
|
||||
ConcurrentMap<String, Identity> hashMap = manager.getIdentifies();
|
||||
Set<String> keySet = hashMap.keySet();
|
||||
// 轮流设置默认身份
|
||||
for (String s:
|
||||
keySet) {
|
||||
logger.debug(String.format("设置身份:%s,结果:%s", s, manager.setDefaultIdentity(manager.getIdentifies().get(s), true)));
|
||||
logger.debug(String.format("查询默认身份:%s", manager.getDefaultIdentity()));
|
||||
LoggerHelper.info(String.format("设置身份:%s,结果:%s", s, manager.setDefaultIdentity(manager.getIdentifies().get(s), true)));
|
||||
LoggerHelper.info(String.format("查询默认身份:%s", manager.getDefaultIdentity()));
|
||||
}
|
||||
logger.debug(String.format("身份数量:%d", manager.getIdentifies().size()));
|
||||
LoggerHelper.info(String.format("身份数量:%d", manager.getIdentifies().size()));
|
||||
}catch (Exception ex){
|
||||
logger.debug(ex.getMessage());
|
||||
LoggerHelper.info(ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -272,7 +273,7 @@ public class IdentifyManagerTest {
|
||||
public void testSetDefaultIdentity2(){
|
||||
try{
|
||||
IdentifyManager manager = new IdentifyManager();
|
||||
logger.debug(String.format("身份数量:%d", manager.getIdentifies().size()));
|
||||
LoggerHelper.info(String.format("身份数量:%d", manager.getIdentifies().size()));
|
||||
ConcurrentMap<String, Identity> hashMap = manager.getIdentifies();
|
||||
Set<String> keySet = hashMap.keySet();
|
||||
// 轮流设置默认身份 设置的身份原本不存在
|
||||
@@ -281,12 +282,12 @@ public class IdentifyManagerTest {
|
||||
Identity id = manager.getIdentifies().get(s);
|
||||
String sNew = s + "test";
|
||||
id.setName(sNew);
|
||||
logger.debug(String.format("设置身份:%s,结果:%s", sNew, manager.setDefaultIdentity(id, true)));
|
||||
logger.debug(String.format("查询默认身份:%s", manager.getDefaultIdentity()));
|
||||
LoggerHelper.info(String.format("设置身份:%s,结果:%s", sNew, manager.setDefaultIdentity(id, true)));
|
||||
LoggerHelper.info(String.format("查询默认身份:%s", manager.getDefaultIdentity()));
|
||||
}
|
||||
logger.debug(String.format("身份数量:%d", manager.getIdentifies().size()));
|
||||
LoggerHelper.info(String.format("身份数量:%d", manager.getIdentifies().size()));
|
||||
}catch (Exception ex){
|
||||
logger.debug(ex.getMessage());
|
||||
LoggerHelper.info(ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -294,19 +295,19 @@ public class IdentifyManagerTest {
|
||||
public void testExistIdentity(){
|
||||
try{
|
||||
IdentifyManager manager = new IdentifyManager();
|
||||
logger.debug(String.format("身份数量:%d", manager.getIdentifies().size()));
|
||||
LoggerHelper.info(String.format("身份数量:%d", manager.getIdentifies().size()));
|
||||
ConcurrentMap<String, Identity> hashMap = manager.getIdentifies();
|
||||
Set<String> keySet = hashMap.keySet();
|
||||
// 正常查询身份是否存在
|
||||
for (String s:
|
||||
keySet) {
|
||||
String sSet = "test" + s;
|
||||
logger.debug(String.format("查询身份:%s 是否存在, 结果:%s", s, manager.existIdentity(s)));
|
||||
logger.debug(String.format("查询身份:%s 是否存在, 结果:%s", sSet, manager.existIdentity(sSet)));
|
||||
LoggerHelper.info(String.format("查询身份:%s 是否存在, 结果:%s", s, manager.existIdentity(s)));
|
||||
LoggerHelper.info(String.format("查询身份:%s 是否存在, 结果:%s", sSet, manager.existIdentity(sSet)));
|
||||
}
|
||||
logger.debug(String.format("身份数量:%d", manager.getIdentifies().size()));
|
||||
LoggerHelper.info(String.format("身份数量:%d", manager.getIdentifies().size()));
|
||||
}catch (Exception ex){
|
||||
logger.debug(ex.getMessage());
|
||||
LoggerHelper.info(ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -314,17 +315,17 @@ public class IdentifyManagerTest {
|
||||
public void testExistIdentity2(){
|
||||
try{
|
||||
IdentifyManager manager = new IdentifyManager();
|
||||
logger.debug(String.format("身份数量:%d", manager.getIdentifies().size()));
|
||||
LoggerHelper.info(String.format("身份数量:%d", manager.getIdentifies().size()));
|
||||
ConcurrentMap<String, Identity> hashMap = manager.getIdentifies();
|
||||
Set<String> keySet = hashMap.keySet();
|
||||
// 查询 null 是否存在
|
||||
for (String s:
|
||||
keySet) {
|
||||
logger.debug(String.format("查询身份:%s 是否存在, 结果:%s", null, manager.existIdentity(null)));
|
||||
LoggerHelper.info(String.format("查询身份:%s 是否存在, 结果:%s", null, manager.existIdentity(null)));
|
||||
}
|
||||
logger.debug(String.format("身份数量:%d", manager.getIdentifies().size()));
|
||||
LoggerHelper.info(String.format("身份数量:%d", manager.getIdentifies().size()));
|
||||
}catch (Exception ex){
|
||||
logger.debug(ex.getMessage());
|
||||
LoggerHelper.info(ex.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package security;
|
||||
|
||||
import common.LoggerHelper;
|
||||
import component.Identifier;
|
||||
import component.TTL;
|
||||
import encoding.TLV;
|
||||
@@ -14,7 +15,7 @@ import minsecurity.identity.TestIdentity;
|
||||
//import org.checkerframework.checker.units.qual.C;
|
||||
//import org.checkerframework.checker.units.qual.K;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.LoggerFactory;
|
||||
//import org.slf4j.LoggerFactory;
|
||||
import packet.CPacket;
|
||||
import packet.Data;
|
||||
import packet.Interest;
|
||||
@@ -24,7 +25,7 @@ import java.util.HashMap;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class KeyChainTest {
|
||||
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(TestIdentity.class);
|
||||
// private static final org.slf4j.Logger logger = LoggerFactory.getLogger(TestIdentity.class);
|
||||
/**
|
||||
* 随机生成身份数据
|
||||
* @return Identity
|
||||
@@ -72,7 +73,7 @@ public class KeyChainTest {
|
||||
ConcurrentHashMap<String, Identity> identityHashMap = new ConcurrentHashMap<>();
|
||||
identityHashMap.put("/wzq", identity);
|
||||
|
||||
logger.debug(String.format("身份数量:%d", keyChain.getIdentifyManager().getIdentifies().size()));
|
||||
LoggerHelper.info(String.format("身份数量:%d", keyChain.getIdentifyManager().getIdentifies().size()));
|
||||
keyChain.getIdentifyManager().setIdentifies(identityHashMap);
|
||||
keyChain.getIdentifyManager().setDefaultIdentity(identity);
|
||||
|
||||
@@ -80,7 +81,7 @@ public class KeyChainTest {
|
||||
Identity identity1 = keyChain.getIdentifyManager().createIdentityByName("/wzq1", passwd, false);
|
||||
identity1.unLock(passwd, Common.SM4ECB);
|
||||
System.out.println(identity1.getPrikey());
|
||||
logger.debug(String.format("身份数量:%d", keyChain.getIdentifyManager().getIdentifies().size()));
|
||||
LoggerHelper.info(String.format("身份数量:%d", keyChain.getIdentifyManager().getIdentifies().size()));
|
||||
}catch (Exception ex){
|
||||
System.out.println(ex.getMessage());
|
||||
}
|
||||
@@ -96,7 +97,7 @@ public class KeyChainTest {
|
||||
// 输入密码用于解锁身份
|
||||
keyChain.setCurrentIdentity(keyChain.getIdentifyManager().getDefaultIdentity(), "0123456789abcdef");
|
||||
}catch (Exception ex){
|
||||
logger.debug(ex.getMessage());
|
||||
LoggerHelper.info(ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -131,7 +132,7 @@ public class KeyChainTest {
|
||||
keyChain.signInterest(interest);
|
||||
keyChain.verifyInterest(interest);
|
||||
}catch (Exception ex){
|
||||
logger.debug(ex.getMessage());
|
||||
LoggerHelper.info(ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -167,7 +168,7 @@ public class KeyChainTest {
|
||||
keyChain.signInterest(interest);
|
||||
keyChain.verifyInterest(interest);
|
||||
}catch (Exception ex){
|
||||
logger.debug(ex.getMessage());
|
||||
LoggerHelper.info(ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -196,7 +197,7 @@ public class KeyChainTest {
|
||||
keyChain.signCPacket(cPacket);
|
||||
keyChain.verifyCPacket(cPacket);
|
||||
}catch (Exception ex){
|
||||
logger.debug(ex.getMessage());
|
||||
LoggerHelper.info(ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -225,7 +226,7 @@ public class KeyChainTest {
|
||||
keyChain.signCPacket(cPacket);
|
||||
keyChain.verifyCPacket(cPacket);
|
||||
}catch (Exception ex){
|
||||
logger.debug(ex.getMessage());
|
||||
LoggerHelper.info(ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -250,7 +251,7 @@ public class KeyChainTest {
|
||||
keyChain.signData(data);
|
||||
keyChain.verifyData(data);
|
||||
}catch (Exception ex){
|
||||
logger.debug(ex.getMessage());
|
||||
LoggerHelper.info(ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -275,7 +276,7 @@ public class KeyChainTest {
|
||||
keyChain.signData(data);
|
||||
keyChain.verifyData(data);
|
||||
}catch (Exception ex){
|
||||
logger.debug(ex.getMessage());
|
||||
LoggerHelper.info(ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -291,12 +292,12 @@ public class KeyChainTest {
|
||||
// 输入密码用于解锁身份
|
||||
keyChain.setCurrentIdentity(keyChain.getIdentifyManager().getDefaultIdentity(), "0123456789abcdef");
|
||||
// 正常导入导出 通过
|
||||
logger.debug(String.format("身份数量:%d", keyChain.getIdentifyManager().getIdentifies().size()));
|
||||
LoggerHelper.info(String.format("身份数量:%d", keyChain.getIdentifyManager().getIdentifies().size()));
|
||||
SafeBag bag = keyChain.exportSafeBag(id2, "1234");
|
||||
keyChain.importSafeBag(bag, "1234", true);
|
||||
logger.debug(String.format("身份数量:%d", keyChain.getIdentifyManager().getIdentifies().size()));
|
||||
LoggerHelper.info(String.format("身份数量:%d", keyChain.getIdentifyManager().getIdentifies().size()));
|
||||
}catch (Exception ex){
|
||||
logger.debug(ex.getMessage());
|
||||
LoggerHelper.info(ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -312,12 +313,12 @@ public class KeyChainTest {
|
||||
// 输入密码用于解锁身份
|
||||
keyChain.setCurrentIdentity(keyChain.getIdentifyManager().getDefaultIdentity(), "0123456789abcdef");
|
||||
// 导入null 抛出异常
|
||||
logger.debug(String.format("身份数量:%d", keyChain.getIdentifyManager().getIdentifies().size()));
|
||||
LoggerHelper.info(String.format("身份数量:%d", keyChain.getIdentifyManager().getIdentifies().size()));
|
||||
SafeBag bag = keyChain.exportSafeBag(null, "1234");
|
||||
keyChain.importSafeBag(bag, "1234", true);
|
||||
logger.debug(String.format("身份数量:%d", keyChain.getIdentifyManager().getIdentifies().size()));
|
||||
LoggerHelper.info(String.format("身份数量:%d", keyChain.getIdentifyManager().getIdentifies().size()));
|
||||
}catch (Exception ex){
|
||||
logger.debug(ex.getMessage());
|
||||
LoggerHelper.info(ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -332,12 +333,12 @@ public class KeyChainTest {
|
||||
// 输入密码用于解锁身份
|
||||
keyChain.setCurrentIdentity(keyChain.getIdentifyManager().getDefaultIdentity(), "0123456789abcdef");
|
||||
// 导入空Identity 抛出异常
|
||||
logger.debug(String.format("身份数量:%d", keyChain.getIdentifyManager().getIdentifies().size()));
|
||||
LoggerHelper.info(String.format("身份数量:%d", keyChain.getIdentifyManager().getIdentifies().size()));
|
||||
SafeBag bag = keyChain.exportSafeBag(null, "1234");
|
||||
keyChain.importSafeBag(bag, "1234", true);
|
||||
logger.debug(String.format("身份数量:%d", keyChain.getIdentifyManager().getIdentifies().size()));
|
||||
LoggerHelper.info(String.format("身份数量:%d", keyChain.getIdentifyManager().getIdentifies().size()));
|
||||
}catch (Exception ex){
|
||||
logger.debug(ex.getMessage());
|
||||
LoggerHelper.info(ex.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user