Tuesday, December 31, 2019

Cannot Get Mail. The mail server imap.gmail.com is not responding in iPhone

I was trying to send an email to a friend and saw this message popped up on my iPhone screen.

Cannot Get Mail. The mail server imap.gmail.com is not responding. Verify that you have entered the correct account info in Mail settings.

The problem was due to that I had changed the password of my email account and the iPhone cannot connect to my email server with the old password.

To fix the problem, all you need to do is to open the Settings -> Passwords & Accounts -> Your email account, and it will ask you to enter your password.

If that does not work for you, simply remove the email account and re-add it to your iPhone.

-----------------------------------------------------------------------------------------------------------------
Watch the blessing and loving online channel: SupremeMasterTV live




If you have ever asked yourself these questions, this is the book for you. What is the meaning of life? Why do people suffer? What is in control of my life? Why is life the way it is? How can I stop suffering and be happy? How can I have a successful life? How can I have a life I like to have? How can I be the person I like to be? How can I be wiser and smarter? How can I have good and harmonious relations with others? Why do people meditate to achieve enlightenment? What is the true meaning of spiritual practice? Why all beings are one? Read the book for free here.

Thursday, December 12, 2019

NetBeans: java.nio.file.AccessDeniedException thrown when copying jars to your library

After you have your coding done, you do a Clean and Build, and you see the following error message in your Output pane.

Copy libraries to C:\MyProjects\lib.
Attempt to copy C:\dynamicreports-3.2.0\lib\xalan-2.7.1.jar to C:\MyProjects\lib\xalan-2.7.1.jar using NIO Channels failed due to 'C:\MyProjects\lib\xalan-2.7.1.jar'.  Falling back to streams.
C:\MyProjects\nbproject\build-impl.xml:1212: The following error occurred while executing this line:
C:\MyProjects\nbproject\build-impl.xml:1035:
java.nio.file.AccessDeniedException: C:\MyProjects\lib\xalan-2.7.1.jar
at sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:83)
at sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:97)
at sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:102)
at sun.nio.fs.WindowsFileSystemProvider.newByteChannel(WindowsFileSystemProvider.java:230)
at java.nio.file.spi.FileSystemProvider.newOutputStream(FileSystemProvider.java:434)
at java.nio.file.Files.newOutputStream(Files.java:216)
at org.apache.tools.ant.util.FileUtils.newOutputStream(FileUtils.java:1721)
at org.apache.tools.ant.types.resources.FileResource.getOutputStream(FileResource.java:267)
at org.apache.tools.ant.types.resources.FileResource.getOutputStream(FileResource.java:241)
at org.apache.tools.ant.util.ResourceUtils.getOutputStream(ResourceUtils.java:791)
at org.apache.tools.ant.util.ResourceUtils.copyUsingStreams(ResourceUtils.java:765)
at org.apache.tools.ant.util.ResourceUtils.copyResource(ResourceUtils.java:435)
at org.apache.tools.ant.util.FileUtils.copyFile(FileUtils.java:565)
at org.apache.tools.ant.util.FileUtils.copyFile(FileUtils.java:525)
at org.apache.tools.ant.util.FileUtils.copyFile(FileUtils.java:486)
at org.apache.tools.ant.util.FileUtils.copyFile(FileUtils.java:449)
at org.apache.tools.ant.util.FileUtils.copyFile(FileUtils.java:415)
at org.apache.tools.ant.util.FileUtils.copyFile(FileUtils.java:390)
at org.apache.tools.ant.util.FileUtils.copyFile(FileUtils.java:328)
at org.netbeans.modules.java.j2seproject.copylibstask.CopyLibs.execute(CopyLibs.java:218)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
at sun.reflect.GeneratedMethodAccessor172.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:99)
at org.apache.tools.ant.Task.perform(Task.java:350)
at java.util.Vector.forEach(Vector.java:1275)
at org.apache.tools.ant.taskdefs.Sequential.execute(Sequential.java:67)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
at sun.reflect.GeneratedMethodAccessor172.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:99)
at org.apache.tools.ant.Task.perform(Task.java:350)
at org.apache.tools.ant.taskdefs.MacroInstance.execute(MacroInstance.java:391)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
at sun.reflect.GeneratedMethodAccessor172.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:99)
at org.apache.tools.ant.Task.perform(Task.java:350)
at org.apache.tools.ant.Target.execute(Target.java:449)
at org.apache.tools.ant.Target.performTasks(Target.java:470)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1388)
at org.apache.tools.ant.Project.executeTarget(Project.java:1361)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
at org.apache.tools.ant.module.bridge.impl.BridgeImpl.run(BridgeImpl.java:261)
at org.apache.tools.ant.module.run.TargetExecutor.run(TargetExecutor.java:574)
at org.netbeans.core.execution.RunClassThread.run(RunClassThread.java:128)

To fix this problem, do one of the following.

1. Change the accessibility of your library folder.
     Right-click on the folder and select Properties. In the pop-up window, select the Security tab.               Select each group of users, click the Edit button to change their permission to access this folder.
2. Run your NetBeans as Administrator.
    Righ-click on your NetBeans icon and select Run as administrator.
3. Remove all the unused jar files from the lib directory.

-----------------------------------------------------------------------------------------------------------------
Watch the blessing and loving online channel: SupremeMasterTV live




If you have ever asked yourself these questions, this is the book for you. What is the meaning of life? Why do people suffer? What is in control of my life? Why is life the way it is? How can I stop suffering and be happy? How can I have a successful life? How can I have a life I like to have? How can I be the person I like to be? How can I be wiser and smarter? How can I have good and harmonious relations with others? Why do people meditate to achieve enlightenment? What is the true meaning of spiritual practice? Why all beings are one? Read the book for free here.

Tuesday, December 10, 2019

NetBeans: warning: [options] bootstrap class path not set in conjunction with -source 1.7

When you do a Clean and Build, you see this message in the Output window:

Compiling 1 source file to C:\MyProjects\MyJava\build\classes
warning: [options] bootstrap class path not set in conjunction with -source 1.7
1 warning

This means that you are using a Java version as sources in this project, which is different from the Java Platform of your NetBean.

To remove the warning:

1. Right-click on the project in the Porjects window and select Properties.

2. Select Libraries from the Categories in the popup window, look for what is set as your Java Platform on the top of the right-side panel.

3. Select Sources under the Categories.

4. In the right-side panel, set the Source/Binary Format to the Java version used by your Java Platform.

5. Click the OK button and recompile your project.



-----------------------------------------------------------------------------------------------------------------
Watch the blessing and loving online channel: SupremeMasterTV live




If you have ever asked yourself these questions, this is the book for you. What is the meaning of life? Why do people suffer? What is in control of my life? Why is life the way it is? How can I stop suffering and be happy? How can I have a successful life? How can I have a life I like to have? How can I be the person I like to be? How can I be wiser and smarter? How can I have good and harmonious relations with others? Why do people meditate to achieve enlightenment? What is the true meaning of spiritual practice? Why all beings are one? Read the book for free here.

Thursday, December 5, 2019

javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated

javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated
        at sun.security.ssl.SSLSessionImpl.getPeerCertificates(SSLSessionImpl.java:450)


This exception happens when the client cannot validate the certificate sent by the server during handshaking.


To fix this problem

1. If you are using a self-signed certificate, get the certificate from the server and click HERE to see the steps and sample code to make it work. If a certificate is not issued by any of the Certificate Authorities (CA), it is a self-signed certificate.

2. Check if your certificate is expired.

3. The client is using an old encryption protocol that is not supported by the server. You can force the client to use the TLSv1.2 protocol.

      SSLContext sc = SSLContext.getInstance("TLSv1.2");

-----------------------------------------------------------------------------------------------------------------
Watch the blessing and loving online channel: SupremeMasterTV live




If you have ever asked yourself these questions, this is the book for you. What is the meaning of life? Why do people suffer? What is in control of my life? Why is life the way it is? How can I stop suffering and be happy? How can I have a successful life? How can I have a life I like to have? How can I be the person I like to be? How can I be wiser and smarter? How can I have good and harmonious relations with others? Why do people meditate to achieve enlightenment? What is the true meaning of spiritual practice? Why all beings are one? Read the book for free here.



javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake

javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake
        at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:994)
        at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1367)
        at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1395)
        at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1379)
     
Caused by: java.io.EOFException: SSL peer shut down incorrectly
        at sun.security.ssl.InputRecord.read(InputRecord.java:505)
        at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:975)


This exception happens when the client cannot validate the certificate sent by the server during handshaking.

To fix this problem, get the certificate from the server and click HERE to see the steps and sample code to make it work.

-----------------------------------------------------------------------------------------------------------------
Watch the blessing and loving online channel: SupremeMasterTV live




If you have ever asked yourself these questions, this is the book for you. What is the meaning of life? Why do people suffer? What is in control of my life? Why is life the way it is? How can I stop suffering and be happy? How can I have a successful life? How can I have a life I like to have? How can I be the person I like to be? How can I be wiser and smarter? How can I have good and harmonious relations with others? Why do people meditate to achieve enlightenment? What is the true meaning of spiritual practice? Why all beings are one? Read the book for free here.

java.net.ConnectException: Connection refused (Connection refused)

java.net.ConnectException: Connection refused (Connection refused)
        at java.net.PlainSocketImpl.socketConnect(Native Method)
        at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
        at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
        at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
        at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
        at java.net.Socket.connect(Socket.java:607)
        at java.net.Socket.connect(Socket.java:556)
        at java.net.Socket.<init>(Socket.java:452)
        at java.net.Socket.<init>(Socket.java:262)


This error occurs when the client cannot reach the server.

1. The server is down.
2. You are using a wrong IP address.
3. The server is not listening on the port.
4. Firewall or proxy blocks the connection.

-----------------------------------------------------------------------------------------------------------------
Watch the blessing and loving online channel: SupremeMasterTV live




If you have ever asked yourself these questions, this is the book for you. What is the meaning of life? Why do people suffer? What is in control of my life? Why is life the way it is? How can I stop suffering and be happy? How can I have a successful life? How can I have a life I like to have? How can I be the person I like to be? How can I be wiser and smarter? How can I have good and harmonious relations with others? Why do people meditate to achieve enlightenment? What is the true meaning of spiritual practice? Why all beings are one? Read the book for free here.



SSL/TLS handshake and Java



SSL (Secure Socket Layer) was first released in 1999. It was deprecated since Java 8u31 and renamed to TLS (Transaction Layer Security) due to its deficiency in handling padding attacks, it checks only the padding length but not the value.

TLS has two subprotocols: Handshake and Record Protocol.

The Handshake process establishes the common cryptographic parameters such as the encryption protocol and cipher to be used by both the server and the client.

The Record Protocol defines the rule for breaking down the data into blocks (packets), encrypt and decrypt them.

During  handshaking, thclient sends to the server the protocol and ciphers it supports. The server then chooses the protocol and the cipher to be used. The server has a list of supported ciphers and chooses the first one in priority supported by the client. If there is no cipher in common, the handshake fails. The protocol and cipher are suggested by client but chosen by the server.

An SSL/TLS connection succeeds only if the client trusts the server. After the protocol and cipher are chosen, the server sends the client its certificate. The client will trust the server only if it can trace the certificate to a root certificate, which is known as chain validation. 

Then, the server and the client exchange their public keys and generate the session key or master key. If the ending messages of the handshaking are successfully encrypted and decrypted by both sides, the handshaking is complete.

Since Java 8u151, the Java Cryptography extension, JCE, is bundled in the JDK. Java JCE is a framework for encryption, key generation, key agreement and message authentication code (MAC). 

From Java 8 onward, the default encryption protocol version is TLSv1.2 which is backward compatible. 

-----------------------------------------------------------------------------------------------------------------
Watch the blessing and loving online channel: SupremeMasterTV live




If you have ever asked yourself these questions, this is the book for you. What is the meaning of life? Why do people suffer? What is in control of my life? Why is life the way it is? How can I stop suffering and be happy? How can I have a successful life? How can I have a life I like to have? How can I be the person I like to be? How can I be wiser and smarter? How can I have good and harmonious relations with others? Why do people meditate to achieve enlightenment? What is the true meaning of spiritual practice? Why all beings are one? Read the book for free here.




Wednesday, December 4, 2019

SSL/TLS: Use a self-signed certificate in Java client for secure socket connection

A certificate not issued by any known Certificate Authorities (CA) but rather by the server hosting the certificate is a self-signed certificate. The root certificate for such a self-signed certificate is absent in the client's certificate store, which causes the chain validation failure.

After receiving your self-signed certificate mycert.crt, follow these steps to create your java client.

1. Import the self-signed certificate into your java truststore.

Your java truststore, cacerts, is located in $JAVA_HOME/jre/lib/security. Copy the cacerts to the location you want it to be. The password of the truststore is changeit

The cacerts bundled with the java JDK contains the root certificates for Certificate Authorities (CA) that issue certificates such as GoDaddy, Verisign, Network Solutions, and others. We will need these root certificates to establish the trust between the client and the server.

Open the Command Prompt and use the following command to import the mycert.crt into the cacerts truststore.

       keytool -import -v -trustcacerts -file mycert.crt -alias mycert -keystore cacerts
 
       Enter keystore password: changeit
     
       . . . . . .

       Trust this certificate? [no]: yes
       Certificate was added to keystore
       [Storing cacerts]

2. Create the java client using the truststore

public class TLSClient {

    public static void main(String[] args) throws IOException, KeyStoreException, NoSuchAlgorithmException, CertificateException, UnrecoverableKeyException, KeyManagementException {

        System.setProperty("javax.net.ssl.trustStore", "cacerts");
        System.setProperty("javax.net.ssl.keyStorePassword", "changeit");

        out.println("Load the keystore...");
        KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());

        try (FileInputStream readCert = new FileInputStream("./cacerts")) {
            ks.load(readCert, "changeit".toCharArray());
        }

        out.println("Initialize the KeyManagerFactory...");
        KeyManagerFactory kmf = KeyManagerFactory.getInstance(
                KeyManagerFactory.getDefaultAlgorithm());
        kmf.init(ks, "changeit".toCharArray());

        out.println("Create a trust manager...");
        TrustManagerFactory tmf = TrustManagerFactory.getInstance(
               TrustManagerFactory.getDefaultAlgorithm());
        tmf.init(ks);

        //Initialize the SSLContext
        out.println("Get the SSLContext...");
        SSLContext sc = SSLContext.getInstance("TLS");

        out.println("Initialize the SSLContext...");
        sc.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);

        out.println("create socket...");
        SSLSocketFactory factory = sc.getSocketFactory();
        try(SSLSocket clientSocket = (SSLSocket) factory.createSocket(getByName("<server IP address>"), <server port>)){

            //debug
            SSLSession session = clientSocket.getSession();
            Certificate[] cchain = session.getPeerCertificates();
            out.println("The Certificates used by peer");
            for (Certificate cchain1 : cchain) {
                out.println(((X509Certificate) cchain1).getSubjectDN());
            }
            out.println("Peer host is " + session.getPeerHost());
            out.println("Cipher is " + session.getCipherSuite());
            out.println("Protocol is " + session.getProtocol());
            out.println("ID is " + new BigInteger(session.getId()));
            out.println("Session created in " + session.getCreationTime());
            out.println("Session accessed in " + session.getLastAccessedTime());
            //finish debug

            out.println("Sucessfully connected!!!");
            //Use the clientSocket to communicate with the server now
        }
    }
}

If the code executes fine, it prints the output below:

Load the keystore...
Initialize the KeyManagerFactory...
Create a trust manager...
Get the SSLContext...
Initialize the SSLContext...
create socket...
The Certificates used by peer
O=Default Company Ltd, L=Default City, C=XX
Peer host is <server IP address>
Cipher is TLS_RSA_WITH_AES_256_CBC_SHA256
Protocol is TLSv1.2
ID is -20222101607659081628530787401436194355856927161855171792439103526019628250528
Session created in 1575480427055
Session accessed in 1575480427235
Sucessfully connected!!!
           
-----------------------------------------------------------------------------------------------------------------
Watch the blessing and loving online channel: SupremeMasterTV live




If you have ever asked yourself these questions, this is the book for you. What is the meaning of life? Why do people suffer? What is in control of my life? Why is life the way it is? How can I stop suffering and be happy? How can I have a successful life? How can I have a life I like to have? How can I be the person I like to be? How can I be wiser and smarter? How can I have good and harmonious relations with others? Why do people meditate to achieve enlightenment? What is the true meaning of spiritual practice? Why all beings are one? Read the book for free here.