Tuesday, 26 June 2018

APK - Manifest Data Retrieval in Java using APK parser

1) Pom Dependency
<dependency>
    <groupId>net.dongliu</groupId>
    <artifactId>apk-parser</artifactId>
    <version>2.6.1</version>
</dependency>

Main Application

import java.io.File;
import java.io.IOException;

import net.dongliu.apk.parser.ApkFile;
import net.dongliu.apk.parser.ApkParser;

public class APKParser {
public static void main(String[] args) throws IOException {
// File Path from Mac 
ApkFile apk = new ApkFile(new File("/Users/sanal/desktop/myapk.apk"));
System.out.println(apk.getApkMeta());
}


}

Sample output

packageName: com.dreamz
label: My App
icon: imagepath/image
versionName: 1.0.0
versionCode: 1
minSdkVersion: 21
targetSdkVersion: 25

maxSdkVersion: null

Tuesday, 19 June 2018

Etag Implementation for Web Api - Caching


Below the details to use the ETag feature from API - Backend Implementation.

Example :- 
1) Request 1 Login and request a getSomethingService  call . you
    will recieve an Etag with value in the response header .

2) Copy the response header for the next request

3) Request 2 add "If-None-Match" request header attribute to service
    request and put the saved value from request 1
                
4) if the response is same , you would get a 304 not

    modified response code.




Thursday, 7 June 2018

SSL - Keytool commands for JDK certificate cacert

Add single Certificate to local JDK on linux servers
keytool -import -trustcacerts -keystore /filepath/java/jre/lib/security/cacerts -storepass changeit -noprompt -alias aliasName -file /certificateFilePath/certifcate.cer

Add a single cert on windows
keytool -importcert -trustcacerts -storepass changeit -noprompt -alias aliasName -file C:\Users\u6071754\Desktop\ofv_cert.cer


Add keystore
keytool -importkeystore -trustcacerts -keystore /filepath/java/jre/lib/security/cacerts -storepass changeit -noprompt -alias aliasName -srckeystore /keyStorePath/KeyStore.jks

Delete Certificate
keytool -delete -v -keystore /filepath/java/jre/lib/security/cacerts -alias aliasName

List All Certificates
keytool -list -v -keystore /filepath/java/jre/lib/security/cacerts > cert.txt 

Cacert pwd is changeit


Command for importing Certificates to Keystore UNIX/Windows:-

Installing Certificate:-
<java installation directory>/bin/keytool -import -noprompt -trustcacerts -alias certificate –file certificate.cer -keystore DemoIdentity.jks -storepass DemoIdentityKeyStorePassPhrase


Viewing Certificates within Keystore:-
<java installation directory>/bin/keytool -list –v -keystore cacerts -storepass changeit

Deleting Certificate
keytool -delete -alias "mykey" -keystore ..\lib\security\cacerts

Locate the keytool from the java installation bin folder.
-alias :- Name with which the certificate is saved to the keystore
-storepass :- password for the keystore to which the new certificate is added.

The default java keystore is the cacerts file located under
<Java installation folder>/jre/lib/security/cacerts
Default password for the cacerts file is ”changeit”.

For Weblogic the keystore files used is DemoIdentity Keystore.
Password for the keystore :- DemoIdentityKeyStorePassPhrase

Add the certificates to the above files, for applications that can directly use the default certificates (Webservices etc) ie, the internal implementation uses the default providers to fetch the certificates directly from the JVM.

For other applications, like LDAP, Webservices that require certificates to be added along with the Request Body etc, Code level implementation has to be done. 

Using Keystores in Java Application:-

Implementation using SSLSocket Factory:-

Create a keystore with the files provided (Using 3rdParty Tools like KeyStore Explorer etc).
Files provided may include the server, Intermediate and Root Certificate. Add all the files to a single keystore. 
Provide a password while creating the  Keystore and the file will have the .jks extension.

Provide the generated keystore to the SSLSocketFactroy.


Refer the below file for Implemetation of SSLSocketFactory to use the Keystore for an LDAP service. The SocketFactory is then set to the LDAP configuration during Authentication.

AWS Certificate Manager - Import Certificate

How to import a certificate. Use Key Store Explorer to open the cert and export keypair in PEM format  This will save a file cert.pem. Make ...