Just Sharing Knowledge on Robotics, Electronics and Programming

Showing posts with label Java. Show all posts
Showing posts with label Java. Show all posts

Saturday, June 27, 2020

Java Keystore Problem: Trustore with Subject CN is Not Ca Certificate


Detailed Step by Step instructions I followed to achieve this

 SSource : StackOverflow =>
Vipul
  • Download bouncycastle JAR from http://repo2.maven.org/maven2/org/bouncycastle/bcprov-ext-jdk15on/1.46/bcprov-ext-jdk15on-1.46.jar or take it from the "doc" folder.
  • Configure BouncyCastle for PC using one of the below methods.
    • Adding the BC Provider Statically (Recommended)
      • Copy the bcprov-ext-jdk15on-1.46.jar to each
        • D:\tools\jdk1.5.0_09\jre\lib\ext (JDK (bundled JRE)
        • D:\tools\jre1.5.0_09\lib\ext (JRE)
        • C:\ (location to be used in env variable)
      • Modify the java.security file under
        • D:\tools\jdk1.5.0_09\jre\lib\security
        • D:\tools\jre1.5.0_09\lib\security
        • and add the following entry
          • security.provider.7=org.bouncycastle.jce.provider.BouncyCastleProvider
      • Add the following environment variable in "User Variables" section
        • CLASSPATH=%CLASSPATH%;c:\bcprov-ext-jdk15on-1.46.jar
    • Add bcprov-ext-jdk15on-1.46.jar to CLASSPATH of your project and Add the following line in your code
      • Security.addProvider(new BouncyCastleProvider());
  • Generate the Keystore using Bouncy Castle
    • Run the following command
      • keytool -genkey -alias myproject -keystore C:/myproject.keystore -storepass myproject -storetype BKS -provider org.bouncycastle.jce.provider.BouncyCastleProvider
    • This generates the file C:\myproject.keystore
    • Run the following command to check if it is properly generated or not
      • keytool -list -keystore C:\myproject.keystore -storetype BKS
  • Configure BouncyCastle for TOMCAT
    • Open D:\tools\apache-tomcat-6.0.35\conf\server.xml and add the following entry
      • <Connector port="8443" keystorePass="myproject" alias="myproject" keystore="c:/myproject.keystore" keystoreType="BKS" SSLEnabled="true" clientAuth="false" protocol="HTTP/1.1" scheme="https" secure="true" sslProtocol="TLS" sslImplementationName="org.bouncycastle.jce.provider.BouncyCastleProvider"/>
    • Restart the server after these changes.
  • Configure BouncyCastle for Android Client
    • No need to configure since Android supports Bouncy Castle Version 1.46 internally in the provided "android.jar".
    • Just implement your version of HTTP Client (MyHttpClient.java can be found below) and set the following in code
      • SSLSocketFactory.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
    • If you don't do this, it gives an exception as below
      • javax.net.ssl.SSLException: hostname in certificate didn't match: <192.168.104.66> !=
    • In production mode, change the above code to
      • SSLSocketFactory.setHostnameVerifier(SSLSocketFactory.STRICT_HOSTNAME_VERIFIER);

Saturday, March 7, 2020

Instalation and Configuration Minio Storage Server in Linux Ubuntu 18.04




1. Download minio
wget https://dl.min.io/server/minio/release/linux-amd64/minio
2. Install Minio
 chmod +x minio
./minio server /data
3. Change Credential
export MINIO_ACCESS_KEY=YQWERTYU12RHJW2YJASD
export MINIO_SECRET_KEY= xH+Qwerty+ASDF+HDd7DRNOFvl7sL8ASDFjwZXCg
4. Run server
./minio server /data
5. Monit Configuration

  check process minio
        matching minio
        start program = "/bin/bash -c '/root/minio.py start'"
        stop program = "/bin/bash -c '/root/minio.py stop'"
        if cpu usage > 95% for 10 cycles then restart 
6.  Python minio.py
#!/usr/bin/python2
import sys
import os
action = sys.argv[1]
if action == 'start':
    os.system("export MINIO_ACCESS_KEY=YQWERTYU12RHJW2YJASD \n export MINIO_SECRET_KEY=xH+Qwerty+ASDF+HDd7DRNOFvl7sL8ASDFjwZXCg \n /root/minio server /data")
if action == 'stop':
    os.system("kill -9 $(pgrep minio)")


7. Change permision of minio.py file
chmod +x minio.py

8. Restart Monit
 systemctl restart monit

9. Status Monit Check
 systemctl status monit

Install Java 13 Oracle


1.
sudo apt-get update
sudo apt-get install oracle-java13-installer
Check the result via command: java --version