-
Notifications
You must be signed in to change notification settings - Fork 253
增加平台证书管理器 #88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
增加平台证书管理器 #88
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
9d8c447
修正下载新证书用旧证书验签失败问题
lianup 791364b
代码格式化、加密信息时使用最新证书
lianup 6df5f5e
增加平台证书管理器
lianup 154a4ba
完善平台证书管理器、测试用例
lianup 26c7281
Merge pull request #1 from lianup/add_cert_manager
lianup 829ffe7
修正review建议
lianup ed479b0
抽离构造函数中的业务逻辑
lianup 97fa620
修改函数访问控制符;增加公共函数参数校验;完善注释
lianup 0acc959
完善参数校验;完善 getLatestCertificate 方法;修改 README 和版本号
lianup 7bd1407
修改版本号
lianup 78647de
根据review建议修改
lianup 7ecdc54
对 updateCertificates 操作加锁
lianup 99aebc2
去掉多余的this;完善README
lianup 86d11c0
根据review建议修改
lianup 8a4353e
修改ScheduleUpdateCertificatesVerifier命名;更新README
lianup 37e254e
完善README和注释
lianup a864030
完善README
lianup ff1e5c2
完善README
lianup 6c239d1
优化README
lianup 1f736ad
优化注释和README
lianup 5f93925
完善注释
lianup 1e14b82
完善注释
lianup 4203017
完善注释
lianup File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
...va/com/wechat/pay/contrib/apache/httpclient/auth/ScheduledUpdateCertificatesVerifier.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| package com.wechat.pay.contrib.apache.httpclient.auth; | ||
|
|
||
| import com.wechat.pay.contrib.apache.httpclient.Credentials; | ||
| import com.wechat.pay.contrib.apache.httpclient.cert.CertManagerSingleton; | ||
| import java.security.cert.X509Certificate; | ||
| import java.util.concurrent.locks.ReentrantLock; | ||
|
|
||
| /** | ||
| * 在原有CertificatesVerifier基础上,增加定时更新证书功能(默认1小时) | ||
| * | ||
| * @author lianup | ||
| * @since 0.3.0 | ||
| */ | ||
| public class ScheduledUpdateCertificatesVerifier implements Verifier { | ||
|
|
||
| protected static final int UPDATE_INTERVAL_MINUTE = 60; | ||
| private final ReentrantLock lock; | ||
| private final CertManagerSingleton certManagerSingleton; | ||
| private final CertificatesVerifier verifier; | ||
|
|
||
| public ScheduledUpdateCertificatesVerifier(Credentials credentials, byte[] apiv3Key) { | ||
| lock = new ReentrantLock(); | ||
| certManagerSingleton = CertManagerSingleton.getInstance(); | ||
| initCertManager(credentials, apiv3Key); | ||
| verifier = new CertificatesVerifier(certManagerSingleton.getCertificates()); | ||
| } | ||
|
|
||
| public void initCertManager(Credentials credentials, byte[] apiv3Key) { | ||
| if (credentials == null || apiv3Key.length == 0) { | ||
| throw new IllegalArgumentException("credentials或apiv3Key为空"); | ||
| } | ||
| certManagerSingleton.init(credentials, apiv3Key, UPDATE_INTERVAL_MINUTE); | ||
| } | ||
|
|
||
| @Override | ||
| public X509Certificate getLatestCertificate() { | ||
| return certManagerSingleton.getLatestCertificate(); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean verify(String serialNumber, byte[] message, String signature) { | ||
| if (serialNumber.isEmpty() || message.length == 0 || signature.isEmpty()) { | ||
| throw new IllegalArgumentException("serialNumber或message或signature为空"); | ||
| } | ||
| if (lock.tryLock()) { | ||
| try { | ||
| verifier.updateCertificates(certManagerSingleton.getCertificates()); | ||
| } finally { | ||
| lock.unlock(); | ||
| } | ||
| } | ||
| return verifier.verify(serialNumber, message, signature); | ||
| } | ||
|
|
||
| /** | ||
| * 该方法已废弃,请勿使用 | ||
| * | ||
| * @return null | ||
| */ | ||
| @Deprecated | ||
| @Override | ||
| public X509Certificate getValidCertificate() { | ||
| return null; | ||
| } | ||
|
|
||
|
|
||
| /** | ||
| * 停止定时更新,停止后无法再重新启动 | ||
| */ | ||
| public void stopScheduledUpdate() { | ||
| certManagerSingleton.close(); | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.