当前位置:网站首页>Self built CA center to issue certificates for different applications of the company
Self built CA center to issue certificates for different applications of the company
2022-04-22 20:13:00 【bglmmz】
WINDOWS 7, JDK 1.7
First of all, it's generating 2 A catalog , One store CA Central root certificate , Another store CA Application certificate issued
D:\CA
D:\CA\appserver
Get into D;\CA Catalog
1. Generate CA Root certificate Library
keytool -genkey -alias CA -keypass CA123 -keyalg RSA -validity 36500 -keystore .\CA.keystore -storepass CASTORE123 -dname "CN=My CA, C=CN"
Be careful ,dname As needed , Fill in other items by yourself .
2. export CA Root certificate ( It's actually a self signing process , Not too low version keytool -selfcert The order has been abandoned )
keytool -exportcert -alias CA -file CA.cer -keystore CA.keystore -storepass CASTORE123
Get into D:\CA\appserver Catalog
3. Generate appserver Certificate Library
keytool -genkey -alias appserver -keypass APPSERVER123 -keyalg RSA -validity 3650 -keystore .\appserver.keystore -storepass APPSERVERSTORE123 -dname "CN=app.myname.com, OU=My company name, O=My company name, C=CN"
4. Generate request CA Signed document
keytool -certreq -alias appserver -keystore .\appserver.keystore -storepass APPSERVERSTORE123 -file appserver.certreq
5. use CA The root certificate is appserver Certificate signature
keytool -gencert -infile appserver.certreq -outfile appserver.cer -validity 3650 -alias CA -keypass CA123 -keystore ..\CA.keystore -storepass CASTORE123
6. hold CA Root certificate import appserver Certificate Library
keytool -importcert -alias CA -file ../CA.cer -keystore appserver.keystore -storepass APPSERVERSTORE123
Tips : Do you trust this certificate ? [ no ]:
Keyboard entry :y
Tips : Certificate added to keystore
7. Import CA Issued certificate to appserver Certificate Library ( It's actually updating the certificate , Before updating the issued certificate , Be sure to put the corresponding CA certificate , Import in appserver Certificate Library file )
keytool -importcert -alias appserver -file appserver.cer -keystore appserver.keystore -storepass APPSERVERSTORE123
Then put what you get appserver.keystore Configuration to tomcat in , such , Browse on the browser tomcat Application , You can see that the certificate issuer is :My CA, And the user is :app.myname.com. also , Two certificates also form a certificate chain ( This can be found in the certificate path ), It looks more decent .
stay android In the development of client , Need to use BKS Type certificate Library ( The above is JKS Type certificate Library ), The above tomcat Deployed Services , How to be in android China visit ?
Suppose the above has been executed , Got the application Certificate appserver.cer, Then do this next .
1. Download required bcprov-jdk15on-146.jar, And on the D:\CA\appserver Under the table of contents , Download address [url]http://www.bouncycastle.org/download/bcprov-jdk15on-146.jar[/url], Pay attention to the version number .
2. Get into D:\CA\appserver Catalog , Enter the following command :
keytool -import -alias appserver -file .\appserver.cer -keystore .\appserver.bks -storetype BKS -storepass bks123 -providerClass org.bouncycastle.jce.provider.BouncyCastleProvider -providerpath .\bcprov-jdk15on-146.jar
So you get BKS Certificate , hand android Just develop students .
android development environment :
android studio 1.5
Android API 23
OkHttp 3.0.1
Take what you get appserver.bks, Put in :src/assets Under the path , Of course, it can also be placed in other paths than the following , As long as it's easy to read .
The sample code is as follows :
[quote]
private void byOkHttps(String url, String json) throws Exception {
// Read bks Certificate Library
KeyStore keyStore = readKeyStore();
// initialization SSLContext
SSLContext sslContext = SSLContext.getInstance("TLS");
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
trustManagerFactory.init(keyStore);
KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
keyManagerFactory.init(keyStore, "bks123".toCharArray());
sslContext.init(keyManagerFactory.getKeyManagers(), trustManagerFactory.getTrustManagers(), new SecureRandom());
// initialization OkHttpClient
OkHttpClient client= new OkHttpClient.Builder()
.sslSocketFactory(sslContext.getSocketFactory())
.build();
//jons Request data
RequestBody body = RequestBody.create(JSON, json);
Request request = new Request.Builder()
.url(url)
.post(body)
.headers(getHeaders())
.build();
client.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
e.printStackTrace();
}
@Override
public void onResponse(Call call, Response response) throws IOException {
//NOT UI Thread
if (response.isSuccessful()) {
Log.d("RESPONSE:", response.body().string());
} else {
throw new IOException("Unexpected code " + response);
}
}
});
}
private KeyStore readKeyStore() throws Exception {
KeyStore ks = KeyStore.getInstance("BKS");
char[] password = "bks123".toCharArray();
java.io.InputStream is = null;
try {
is = getAssets().open("appserver.bks");
ks.load(is, password);
} finally {
if (is != null) {
is.close();
}
}
return ks;
}
[/quote]
Postscript :
1. It's generating BKS Certificate library error , At first I downloaded bcprov-jdk15on-154.jar, It can also be used. , But it needs to be in android Make some changes in development ,
1. To put bcprov-jdk15on-154.jar Introduced to the android In the project
2. Modify the above readKeyStore Code
private KeyStore readKeyStore() throws Exception {
KeyStore ks = KeyStore.getInstance("BKS", new BouncyCastleProvider());
char[] password = "bks123".toCharArray();
java.io.InputStream is = null;
try {
is = getAssets().open("appserver.bks");
ks.load(is, password);
} finally {
if (is != null) {
is.close();
}
}
return ks;
}
2. When used HTTPS When accessing an application server with a certificate deployed , Sometimes with IP Visiting , For example, when accessing the intranet test server , I don't usually use domain names , It's direct use IP To visit , At this time, something like hostname wrong Error of , This is actually caused by a problem with our certificate , The solution is to generate the certificate at the earliest / In the step of issuing the certificate :
3. Generate appserver Certificate Library
keytool -genkey, This order adds :-ext san=ip:192.168.1.123
5. use CA The root certificate is appserver Certificate signature
keytool -gencert, This order adds :-ext san=ip:192.168.1.123
Don't use the so-called method of trusting all domains introduced on the Internet , It's not safe .
版权声明
本文为[bglmmz]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204221916328213.html
边栏推荐
- [recent function update] seamless experience free demo!
- How can I apply for new shares? Is it safe to apply for new shares?
- [Chongqing Guangdong education] Nanyang Institute of Technology English rambling Chinese culture reference materials
- An error occurs when starting Kingbase stand-alone service: invalid value for parmeter "bindpuplist": "0-95"
- sys_ctl启动kingbase单机服务时报错:could not bind IPv4 address “0.0.0.0“: Address already in use
- 工作光靠努力是不够的!还有这个...
- Pytorch deep learning practice 09 multi classification questions
- ZTNA (Zero Trust Network Access)
- 手写一个网关服务,理解更透彻!
- What if I don't understand? Google's 540 billion parameter new model can explain the laugh point and guess the movie through Emoji expression
猜你喜欢

See how big websites play the secret of website acceleration (CDN)

网络隧道技术

MarkDown 学习

Why puddingswap may be a strong dark horse in the field of gamefi?

Write a gateway service, understand more thoroughly!

Network tunneling technology

高级ipc - dbus详解

calico官网网络拓扑实现:基于eNSP与VMVare

Acrobat Pro DC tutorial, how to use password to protect PDF files?

Selenium automatic pop-up processing
随机推荐
Alicloud installs ffmpeg
使用rpmbuild打包php
解决金仓数据库KingbaseES对pg模式的单机数据库插入数据时,出现日志打印的问题
金仓数据库KingbaseES之null和“ ”的区别
重保战场的“排头兵”,“互联网宙斯盾”如何为城市高效布防?
Embedded Web project (I) -- introduction of web server
Activity Result API 使用与源码分析
[H5] wechat H5 page production
Lithography giant ASML broke the news: the chip is too short, and they are starting to dismantle the washing machine!
Micro diary: Those seemingly insignificant details and experiences
Pytorch deep learning practice 09 multi classification questions
Acrobat Pro DC 教程,如何使用密码保护 PDF 文件?
firewalld dbus接口使用指南
Obtain the real IP address of the client after envoy proxy
Why is x16 slower than X8?
Review of SSM framework
Biography: Ali Dharma Institute layoffs 30%! Internal staff: rumors! Netizen: why not cut 29.99%...
如何提高PHP编程的效率?
Internet News: Lenovo announced the new progress of ESG; Excellent sound and painting of Jimi h3s and z6x Pro were highly praised; Little red book responded to "layoffs of 20%"
Advanced IPC - DBUS details