PP商业软件授权平台可以帮助软件工程师实现这样的功能:比如相同的一份程序,A、B、C三客户获得的是不同类型和级别的授权码,A客户只能在2颗及以下CPU、16G及以下内存、1TB及以下硬盘的Linux服务器上运行小部分功能,B客户则没有任何平台和硬件限制,但主要功能只能使用5天,C客户则是无任何限制的全功能永久授权。这些功能不依赖硬件和实时网络。软件工程师花2个小时接入2个函数就可以,而且是全免费的!
基本步骤只要三步:
1. 注册PP商业软件授权平台的开发端账号
2. 登录系统并创建软件项目和授权码
3. 参照示例代码将相应的终端开发包接入自己的程序之中,只有2个函数
特别说明:需要对终端开发包的JAR文件检查数字签名,防止JAR包被替换,这里对大宝CA表示感谢,感谢大宝CA免费提供的JAR包代码签名证书。
示例代码下载地址:https://download.csdn.net/download/pplic/10974707
JAR代码签名核心代码:
private static Certificate[] verifyJarSign(JarFile jar)
{
Set
try
{
Enumeration
while (entries.hasMoreElements())
{
JarEntry entry = entries.nextElement();
if (entry.isDirectory() == true)
{
continue;
}
String name = entry.getName().toUpperCase(Locale.ENGLISH);
try
{
byte[] buffer = new byte[8192];
InputStream is = jar.getInputStream(entry);
while ((is.read(buffer, 0, buffer.length)) != -1)
{
// We just read. This will throw a SecurityException
// if a signature/digest check fails.
}
is.close();
Certificate[] certs = entry.getCertificates();
if (certs == null || certs.length < 1)
{
if (name.endsWith("MANIFEST.MF") == false && name.endsWith("PPLIC.RSA") == false && name.endsWith("PPLIC.SF") == false)
{
return null;
}
}
else
{
for (int i = 0; i < certs.length; i++)
{
certSet.add(certs[i]);
}
}
}
catch (SecurityException se)
{
se.printStackTrace();
return null;
}
}
Certificate[] certArrays = new Certificate[certSet.size()];
return certSet.toArray(certArrays);
}
catch(Exception ex)
{
ex.printStackTrace();
return null;
}
}
private static boolean verifyJNISign()
{
String jarFilePath = PPLicAuthClientCore.class.getProtectionDomain().getCodeSource().getLocation().getPath();
try
{
JarFile jar = new JarFile(jarFilePath, true);
Certificate[] certs = verifyJarSign(jar);
String pplicCaCertCN = "CN=PPLIC.com CA, O=www.PPLIC.com, ST=BEIJING, C=CN";
if (certs == null || certs.length != 3)
{
// www.DoubleCA的根证书
// PPLIC的二级CA证书
// PPLIC的代码签名证书
System.out.println("PPLIC的代码签名证书有3个,JNI库文件校验不通过");
return false;
}
else
{
// 验证证书
CertificateFactory cf = CertificateFactory.getInstance("X.509");
X509Certificate rootCert = (X509Certificate)cf.generateCertificate(new FileInputStream("resources/DoubleCA.com ROOT CA.cer"));
X509Certificate pplicCaCert = null;
X509Certificate pplicSignCert = null;
for (int i = 0; i < certs.length; i++)
{
X509Certificate cert = (X509Certificate)certs[i];
if (cert.getSubjectDN().equals(rootCert.getSubjectDN()))
{
// 根证书
if (cert.getSerialNumber().equals(rootCert.getSerialNumber()) == false || Arrays.equals(cert.getEncoded(), rootCert.getEncoded()) == false)
{
// 根证书校验失败
System.out.println("www.DoubleCA.com的根证书校验失败");
return false;
}
System.out.println(rootCert.getSubjectDN().getName() + " 通过校验");
}
else if (cert.getIssuerDN().equals(rootCert.getSubjectDN()))
{
// pplic的CA证书校验
pplicCaCert = cert;
pplicCaCert.verify(rootCert.getPublicKey());
if (pplicCaCertCN.equals(pplicCaCert.getSubjectDN().getName()) == false)
{
// 主题不匹配
System.out.println("不是PPLIC的二级CA证书");
return false;
}
System.out.println(pplicCaCert.getSubjectDN().getName() + " 通过校验");
if (pplicSignCert != null)
{
// pplic的jar代码签名证书校验
pplicSignCert.verify(pplicCaCert.getPublicKey());
System.out.println(pplicSignCert.getSubjectDN().getName() + " 通过校验");
}
}
else
{
// pplic的jar代码签名证书校验
pplicSignCert = cert;
if (pplicCaCert != null)
{
pplicSignCert.verify(pplicCaCert.getPublicKey());
System.out.println(pplicSignCert.getSubjectDN().getName() + " 通过校验");
}
}
}
return true;
}
}
catch(Exception ex)
{
// 异常,证书校验失败
System.out.println("证书校验失败");
ex.printStackTrace();
return false;
}
}
示例代码运行结果:
CN=PPLIC.com CA, O=www.PPLIC.com, ST=BEIJING, C=CN 通过校验
CN=PPLIC Code Signing, O=www.PPLIC.com, ST=BEIJING, C=CN 通过校验
CN=DoubleCA.com ROOT CA, O=www.DoubleCA.com, ST=BEIJING, C=CN 通过校验
JNI库文件代码验证通过
PP授权库版本号:1.0.0
授权请求数据编码:
AVsHeKoBwI0AMIGKAiEAgRe2I5A43EbIttem2tmZARoDP1+49rYmmUAhQvbiVnY
CIQCAKUW46pyzRBI/nzwil41ZuYLuBE86qZBbtyOks8cSMgQg0zV7+oNbc2Avzh
Xist9lZeC2UIgsujP2i66sqGzj0e8EIJZeEoHlZBdmkd3JEhR+9uxrfgwm/FIic
O2P1SEMS7gpwTABbhUyRX4CsZJevRA5gW3OHlGrSBBpB4/Ro606Qgg1Xfb4ApLF
Oqv6tKI0ZOOcXBfkpqrux58IV/6Zc/gFUFlf6XK+K29lbA/bMTdgMs6dzbr1SrI
q5ROUPVWglR5DpyNtKL62o8hrBIHfjLJVnLn33g7tgbbFL5fWvVZcGzQqzD84SE
dm6JsYYWQO/+KT+WyRmV0TQE/bo7Q8fCwotUM0rNZF1wW1KBotE1RpAm/bY5KxN
HT1dbLpXzOZsSziL8hd3k8EMwP/sEvq54NP7So2hSfyUMez5awVgQZQFyGXgb+k
7ulE5fjFNjTeULpjKPY6lARkWPef+NTyl+N5AImYOJ+jF8lok8Lyfx4lW6Gk9SZ
TbiKw2JQPBpa9zIkDUaF94h0BW4oV0mZuHxJyX7YfdA==
请输入软件项目编号:
66-571092B5DE344F81B7F238B362428231
请输入授权数据:
AYN/mbqeGRM9wAABYm0IoyUoxlMi+xXZAm6ffJv20H9Bd5OopSri96G2por46sWTakHHrmx6nLFp1o9Bw/Iid0ofQBLiWZt5Iyj8A+F/BlFQjn8sw/AJzDzvgDx0fVBP57Cftl+4LtsJ+pNpb56DZvujDfwNXHmBddmN5OBvtjs/IagW6/Eo4FV9QmQAHYOWbgk/quCoziCA8uduhQIOOhoYXSUtKSj/QNF5mukA4urHomC63jPP2DpdwzXHy9lgKgmOsrJ/1PhkOaEj0/3QaWiRfbVBQgX7U1kJE5jZB9hdC/2GU5BQTVG5EuL7eaGDX79Cowyr8VstwOfAECusGka8krgompWfzU5MsMIwAY/K3jEUCruM5Bm/gPKKR05NUXU+oxJgs5SY2munEzjlgWOm82gOoVnpRcu65LMIWyK3cndD/IElNRHx8NWKxTYxzKSHkIQfUMplE8N+8FcSwgoZ3FMJZKoseGFSam363wJeNDvSnwkVqhb2kcjY1AmmrZ3RczrDjxniXMbafGoqFEUlYSlQybjYUnDw0KCIhSLm0RY3TL9I56BEzVMfBzQRluCPTflo9gt0Jm7QTuhAf19njHrvg8Fn9YK3UdHpidMfelT9blpeEIkr2hJ036JAfT9rek+5WPVXSlvVGvUX1hJV7FLXAI7y7I6YxTPGA42HAb70i+9Gvozn5YL4E3FWQDa1kBCBxGZSaAmEJ9frQ3MsDg6KtxBGXM4P+Df9DAzZY7EAomJbfWqcAhANM9s=
授权级别验证成功,授权级别:10000
授权时间验证成功,授权有效期至[2019年03月28日 13时],还有[29]天[22]小时