Wednesday, March 01, 2017

How to make java point to right version of java on your Mac ?

A usual problem on mac where the even after upgrading or installing the latest version of Java, when queried in command line for java version it still refers to the old version of java. something like below:

$ java -version
java version "1.7.0_79"
Java(TM) SE Runtime Environment (build 1.7.0_79-b15)

Java HotSpot(TM) 64-Bit Server VM (build 24.79-b02, mixed mode)

This is because the /usr/bin/java is pointing to  /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java on the system.  

$ ls -la `which java`
/usr/bin/java -> /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java

This is because Oracle's installer puts java inside the /Library/Internet Plug-Ins/JavaAppletPlugin.plugin. And it doesn't overwrite /usr/bin/java. So to fix this we have remove the existing soft link to old java and point it to new java binary. which can be done by performing following steps.

$ sudo rm /usr/bin/java

$ sudo ln -s /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java /usr/bin/java

$ java -version
java version "1.8.0_121"
Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)

Friday, February 24, 2017

How to fix broken python module easy_install on mac ?

           Easy Install is a python module (easy_install) bundled with setuptools that lets you automatically download, build, install, and manage Python packages. Sometimes due wrong installations easy_install might get corrupted and fail to install any package afterwords. You might see errors like below when you try to install any modules

Traceback (most recent call last):
  File "/usr/local/bin/easy_install", line 7, in
    from setuptools.command.easy_install import main
  File "/Library/Python/2.7/site-packages/setuptools/", line 12, in
    import setuptools.version
  File "/Library/Python/2.7/site-packages/setuptools/", line 1, in
    import pkg_resources
  File "/Library/Python/2.7/site-packages/pkg_resources/", line 72, in
    import packaging.requirements
  File "/Library/Python/2.7/site-packages/packaging/", line 59, in
    MARKER_EXPR = originalTextFor(MARKER_EXPR())("marker")

TypeError: __call__() takes exactly 2 arguments (1 given)

To fix broken easy_install follow below steps on Mac.

1. Remove old easy_install related scripts from system.

sudo rm -f /usr/bin/easy_install*
sudo rm -f /usr/local/bin/easy_install*

2. Download and run

curl -O
sudo python
sudo rm

3. Now try installing any python package of your choice.

Wednesday, December 07, 2016

Calculating hash(md5, sha1...) of a hex string in Python

To calculate hash of hex string in python:

In [1]: import hashlib

In [2]: import binascii

In [3]: hex_string = '3082010a0282010100c3dfee03290fb01e3a4887c5ce0630dcdd8495bfb568b1f61cb8fa8294545b74f06facd215933c53babdd4d066dcb2a713740b9a018c8e0d5fbe1c2a7c793d317c69590c6a34cb1758fd1ff00f36d757c97371d08e9e9efcad1bf6fc8a0c03972296870ad825fa81000fee7aa79c2bcfab0e92d67d3d429d9a25cd6087e3139b17ce1809a6bf83d5ef40ff8e4532412adc15c63eff4eadd264860cb61b381e4f0e8a9e19cf7e39fefdfe9904b1aafe54f12289b930e341dd12b5a41eca1ae9d3556e6c7860a162652a31e256a7fa5720b4cbeb32fa65b67eb0610c6857dfe775d71de5aeb041d7ea0a7c5f335d678280b30dd014e16b37290c4c56d20df737850203010001'

In [4]: hashlib.md5(binascii.unhexlify(hex_string)).hexdigest()
Out[4]: '0c6f3dd3d5d896e0f3f49dfae0437ba1'

In [6]: hashlib.sha1(binascii.unhexlify(hex_string)).hexdigest()
Out[6]: 'fc6d7e7925e18c5bed6314ea112a230948cfde75'

In [7]: hashlib.sha256(binascii.unhexlify(hex_string)).hexdigest()
Out[7]: '73a1b42ca158112e233cd42b0352355ca1ab8cafc2475c2e888285275dbf4ab1'

In [8]: hashlib.sha512(binascii.unhexlify(hex_string)).hexdigest()
Out[8]: '500228880eb22d53cd4cc1c7b42930fef37a4034299b49198bb52cb3ab4bdca3643d952aba662b1b60df723a273af6903bf2bebe9327b0cd53548e3d9a4348f5'

Friday, November 18, 2016

How to extract signing certificates from macOS binary files

Code signing is a macOS security technology that you use to certify that an app was created by you. Once an app is signed, the system can detect any change to the app—whether the change is introduced accidentally or by malicious code. As Apple Developer site says ( click here for more details on code signing) :

code signing allows the operating system to:
  • Ensure that a piece of code has not been altered since it was signed. The system can detect even the smallest change, whether it was intentional (by a malicious attacker, for example) or accidental (as when a file gets corrupted). When a code signature is intact, the system can be sure the code is as the signer intended.
  • Identify code as coming from a specific source (a developer or signer). The code signature includes cryptographic information that unambiguously points to a particular author.
  • Determine whether code is trustworthy for a specific purpose. Among other things, a developer can use a code signature to state that an updated version of an app should be considered by the 
    system to be the same app as the previous version.

We can extract the signing certificates from the macOS binary files using codesign tool.  Run the following command on any macOS binary , dylib or .app to extract the signing certificate from the file.

Steps :

1. Change to tmp directory.
    $ cd  /tmp

2. Run codesign command on the binary or .app to extract signing certificate.
    $codesign -dvvvv --extract-certificates /Applications/

    This extracts all the signing certificates from the file and creates 3 files named codesign0, codesign1 and codesign2.  Codesign0 is usually the leaf (signing) certificate, and as many files are written as there are certificates in the signature. The files are in ASN.1 (DER) form. 

To view the contents of the certificates:

To see the details of the certificates which were extracted in DER form, we have use openssl tool. Run the following command to view the contents of certificate

$ openssl x509 -inform DER -in codesign0 -text

The output looks like below:

        Version: 3 (0x2)
        Serial Number:
        Signature Algorithm: sha1WithRSAEncryption
        Issuer: C=US, O=Apple Inc., OU=Apple Certification Authority, CN=Apple Code Signing Certification Authority
            Not Before: Apr 12 22:34:35 2013 GMT
            Not After : Apr 12 22:34:35 2021 GMT
        Subject: C=US, O=Apple Inc., OU=Apple Software, CN=Software Signing
        Subject Public Key Info:
            Public Key Algorithm: rsaEncryption
            RSA Public Key: (2048 bit)
                Modulus (2048 bit):


Friday, August 26, 2016

How to fix "This copy of the Install OS X Mavericks application can't be verified. It may have been corrupted or tampered with during downloading." message and install Mavericks or older operating system versions of OS X on VmWare Fusion application

It is very annoying to see  the message "This copy of the Install OS X Mavericks application can't be verified. It may have been corrupted or tampered with during downloading."  when you try to install old releases of Apple OS X operating systems such as Mountain Lion, Mavericks, Yosemite etc. If you are trying to install OS X Mavericks as virtual machine in VMWare fusion or in physical system, then follow below steps to successfully install the operating system.

In VMWARE Fusion.

  1. Create a OSX Mavericks VM by attaching OSX Mavericks Installer to the virtual machine.
  2. Do not Poweron the virtual machine. If powered on automatically after 1st step above then poweroff the VM.
  3. Open Virtual Machine Settings, Goto Advanced Section.
  4. Un check "Synchronize Time" setting.
  5. Start the Virtual Machine to install the OSX Mavericks.
  6. In the OSX Installer app , Launch
  7. Set the system date to old date as date 102613152013 (Oct/26/2013 13:15).
  8. Quit the Terminal application.
  9. Continue with the installation.

In Physical System:

Prior starting the installation change the system date to old date as said above using terminal app launched from OS X Installer application.