A standalone library project for certificate pinning on Android.

Related tags

UI/UX AndroidPinning
Overview

Android Pinning

AndroidPinning is a standalone Android library project that facilitates certificate pinning for SSL connections from Android apps, in order to minimize dependence on Certificate Authorities.

CA signatures are necessary for general purpose network communication tools: things like web browsers, which connect to arbitrary network endpoints and have no advance knowledge of what the SSL certificates for those endpoint should look like.

Most mobile apps are not general purpose communication tools. Instead, they typically connect directly to a narrow set of backend services that the app's author either controls, or can predict ahead of time.

This creates an opportunity for app developers to sidestep the security problems inherent with Certificate Authorities. The best way is to throw CA certificates out the window entirely by signing your own endpoint certificates with your own offline signing certificate, which you then distribute with your app. See this blog post for examples of the no-CA technique.

Sometimes, however, that's not possible, and you need to continue using CA certificates for one reason or another. Perhaps the API endpoint is shared with a web browser's endpoint, for instance.

In that case, it's necessary to employ "pinning," which is simply the act of verifying that the certificate chain looks the way you know it should, even if it's signed by a CA. This prevents other CAs from being able to effectively create forged certificates for your domain, as with the many Comodo breaches, the DigiNotar breach, and the TurkTrust breach.

This library is designed to make pinning easier on Android. It's structured as an Android library project, so you can simply link it to your own project and begin.

Using AndroidPinning

If you're using gradle to build your project, you can include the AndroidPinning artifact by adding a dependency:

   dependencies {
       compile 'org.thoughtcrime.ssl.pinning:AndroidPinning:1.0.0'
   }

Examples

Using a simple HttpsURLConnection with a PinningTrustManager:

// Define an array of pins.  One of these must be present
// in the certificate chain you receive.  A pin is a hex-encoded
// hash of a X.509 certificate's SubjectPublicKeyInfo. A pin can
// be generated using the provided pin.py script:
// python ./tools/pin.py certificate_file.pem
String[] pins                 = new String[] {"f30012bbc18c231ac1a44b788e410ce754182513"};
URL url                       = new URL("https://www.google.com");
HttpsURLConnection connection = PinningHelper.getPinnedHttpsURLConnection(context, pins, url);

return connection.getInputStream();

Using a simple HttpClient with a PinningTrustManager:

String[] pins         = new String[] {"f30012bbc18c231ac1a44b788e410ce754182513"};
HttpClient httpClient = PinningHelper.getPinnedHttpClient(context, pins);

HttpResponse response = httpClient.execute(new HttpGet("https://www.google.com/"));

It's also possible to work with PinningTrustManager and PinningSSLSocketFactory more directly:

String[] pins                 = new String[] {"40c5401d6f8cbaf08b00edefb1ee87d005b3b9cd"};
SchemeRegistry schemeRegistry = new SchemeRegistry();
schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
schemeRegistry.register(new Scheme("https", new PinningSSLSocketFactory(getContext() ,pins, 0), 443));

HttpParams httpParams                     = new BasicHttpParams();
ClientConnectionManager connectionManager = new ThreadSafeClientConnManager(httpParams, schemeRegistry);
DefaultHttpClient httpClient              = new DefaultHttpClient(connectionManager, httpParams);

HttpResponse response = httpClient.execute(new HttpGet("https://www.google.com/"));

Issues

Have a bug? Please create an issue here on GitHub!

https://github.com/moxie0/AndroidPinning/issues

License

Copyright 2011-2013 Moxie Marlinspike

Licensed under the GPLv3: http://www.gnu.org/licenses/gpl-3.0.html

Please contact me if this license doesn't work for you.

Comments
  • SHA-256 support

    SHA-256 support

    Seeing as SHA-1 is currently being deprecated by Google as well as most CAs due to collision weaknesses, I think it's wise to upgrade the pins to SHA-256, especially as this library is used by many security-conscious applications.

    opened by knoy 4
  • Add helper method for getting pinned SSLSocketFactory

    Add helper method for getting pinned SSLSocketFactory

    Some libraries like Google's Volley allow constructing HTTP clients with custom SSLSocketFactory's, so instead of copy pasting some SSLSocketFactory construction boiler-plate code, I thought I'd try to DRY things up by creating this helper method.

    opened by matthewmichihara 3
  • GPL vs. LGPL?

    GPL vs. LGPL?

    Noticed that this is a library but the published license is GPL vs. LGPL. But that makes it unusable in commercial software or even many/most free mobile apps because GPL mandates the entire application be GPL in order to use GPL libraries. https://www.gnu.org/licenses/gpl-faq.html#IfLibraryIsGPL

    Any possibility to change the license to LGPL to ensure contributions to the code remain public and free, but that the implementation can be used broadly?

    opened by jaxley 1
  • Lowering minSDK from 8 to 5.

    Lowering minSDK from 8 to 5.

    Running lint shows no dependencies on minSDKVersion 8. Lowering the minSDK to 5 allows bundling this library with a greater number of applications.

    Specifically the maintainers of the Fdroid client were hesitant to merge a pull req I wrote to bundle AndroidPinning because their client has a minSDK of 5 versus the AndroidPinning minSDK of 8.

    Thanks! Big fan of the library <3

    opened by cpu 1
  • AndroidPinning License

    AndroidPinning License

    Hi my friend,

    I'm currently working on Android projects and I think AndroidPinning is a good fit for my situation.

    However the current license (GPLv3) prevents me to use AndroidPinning on anything, but only on fully opensource + GPL'd Android apps. Would it be possible to change AndroidPinning's license to a lesser restrictive one like BSD, MIT, ALv2, EPL…?

    opened by abstractj 1
  • FileNotFoundException: /system/etc/security/cacerts.bks in ICS

    FileNotFoundException: /system/etc/security/cacerts.bks in ICS

    It seems that Android 4.0.3 uses a different system trust store. As a result, code that works on 2.x fails on 4.0.

    root@android:/ # ls /system/etc/security cacerts otacerts.zip

    root@android:/ # ls /system/etc/security/cacerts 00673b5b.0 03e16f6c.0 08aef7bb.0 ...

    02-15 13:31:54.437: E/AndroidRuntime(824): java.lang.AssertionError: java.io.FileNotFoundException: /system/etc/security/cacerts.bks: open failed: ENOENT (No such file or directory) 02-15 13:31:54.437: E/AndroidRuntime(824): at org.thoughtcrime.ssl.pinning.PinningTrustManager$SystemKeyStore.getTrustStore(PinningTrustManager.java:246) 02-15 13:31:54.437: E/AndroidRuntime(824): at org.thoughtcrime.ssl.pinning.PinningTrustManager$SystemKeyStore.getPkixParameters(PinningTrustManager.java:209) 02-15 13:31:54.437: E/AndroidRuntime(824): at org.thoughtcrime.ssl.pinning.PinningTrustManager$SystemKeyStore.(PinningTrustManager.java:185) 02-15 13:31:54.437: E/AndroidRuntime(824): at org.thoughtcrime.ssl.pinning.PinningTrustManager.(PinningTrustManager.java:102) ...

    opened by tomwhipple 1
  • How does one obtain Google's X.509 certificate?

    How does one obtain Google's X.509 certificate?

    The readme sample using google pins doesn't validate for me. Looking through stackoverflow I found the following shell script which uses openssl to obtain the certificate of a server:

    #!/bin/sh
    # Based on http://blog.crazybob.org/2010/02/android-trusting-ssl-certificates.html
    
    SERVER=www.google.com:443
    echo | openssl s_client -connect ${SERVER} 2>&1 | \
         sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > mycert.pem &&
         cat mycert.pem &&
         echo "Generated pem file"
    

    Running this generates a file which used with the pin.py tool outputs:

    Calculating PIN for certificate: C=US, ST=California, L=Mountain View, O=Google Inc, CN=www.google.com
    Pin Value: 6a42217ac7419912ff661867525e5a059a526325
    

    However when I paste the pin value into the readme HttpsURLConnection sample I get an exception javax.net.ssl.SSLHandshakeException: No valid pins found in chain!. Which seems to indicate I'm not getting correctly the certificate. How should I retrieve the cert from google and other public websites?

    opened by vectorialgradha 0
  • build.gradle error

    build.gradle error

    I imported the project in android application. I get the following error in the build.gradle:

    Error:(54, 0) No such property: sonatypeRepo for class: org.gradle.api.publication.maven.internal.ant.DefaultGroovyMavenDeployer

    opened by a2t2 0
  • aild => aidl?

    aild => aidl?

    I was playing around with trying to add this as a library project to a gradle based Android app I'm making and was running into some errors. I eventually stumbled upon this line: https://github.com/moxie0/AndroidPinning/blob/master/build.gradle#L27

    Changing the name of the source set 'aild' to 'aidl' made some of my problems go away, but is that custom source set location necessary? I don't see any use of aidl in the app. Same with renderscript and assets.

    opened by matthewmichihara 0
  • Can't Find Your Email - So Contacting via Github Issue lol

    Can't Find Your Email - So Contacting via Github Issue lol

    My name is Davy Yue, and I am the Founder + CEO of LifeEverlasting, an innovative technology enabling a user to interact with anyone from history. See our pitch slide deck below, and note the one-minute promotional video on the second slide: ​ https://docs.google.com/presentation/d/1OMQ7LMTXqql0Jy1pdslMyeANcjQWcaTch-0zHBjVFzc/edit?usp=sharing ​ My team and I at LifeEverlasting are currently looking for seed & angel investors, as well as venture capitalists to fund our development process as we push for the first-ever beta release date May 18th, 2018 at 3:00 pm CST as well as the second beta date in the slide deck. We are also looking to work with security professionals, since a significant amount of data would be collected to fuel the neural network and machine-learning process.

    I would love to schedule a video or phone call with you to discuss further your possible involvement in LifeEverlasting, an innovative startup breaking new ground in helping establish people's long-living legacy after their physical passing.

    Please let me know what you think. Looking forward to talking soon!

    Best,

    Davy Yue

    opened by DavyYue 0
  • insecure pinning

    insecure pinning

    https://github.com/moxie0/AndroidPinning/blob/master/src/org/thoughtcrime/ssl/pinning/PinningTrustManager.java#L176

    The chain you get is the chain given by the peer = web server. It can contain any number of certificates that have nothing to do with the trust chain created internally by checkSystemTrust().

    CertificateChainCleaner.java tries to fix that but it does not validate any signatures. So adding invalid certificates can create a second trust chain to circumvent the pinning.

    checkPinTrust() returns true if the parameter contains any certificate that matches the pin. By attaching any trusted, correctly pinned certificate to the TLS-response the entire pinning can be circumvented.

    See https://www.cigital.com/blog/ineffective-certificate-pinning-implementations/ for a more detailed explanation of your security flaw.

    opened by MarcusWolschon 0
  • Use of BKS

    Use of BKS

    Noticed there is code to read certificates from raw folder. Is the file a single bks file with multiple aliases? Any chance for an example of how to use?

    opened by george-vlahakis 0
  • Add domain to compare each PIN against

    Add domain to compare each PIN against

    Allow the caller to specify which domain(s?) a pin should apply to. This would allow pinning to be set process-wide using HttpsURLConnection.setDefaultSSLSocketFactory() so that all HttpsURLConnections made by the app, including third-party libraries, could be pinned at the caller's request.

    opened by molexx 0
  • Support SHA2

    Support SHA2

    I am trying to do cert pinning for SHA2 cert on my server. My app stopped working as the server got upgraded with SHA2 and I am trying to use this library but keeps getting SSL javax.net.ssl.SSLPeerUnverifiedException: No peer certificate at com.android.org.conscrypt.SSLSessionImpl.getPeerCertificates(SSLSessionImpl.java:146)

    Any idea?

    opened by nehalshah50 0
  • Dependencies deprecated in API 22

    Dependencies deprecated in API 22

    AndroidPinning relies on Apache framework: https://github.com/moxie0/AndroidPinning/blob/master/src/org/thoughtcrime/ssl/pinning/util/PinningHelper.java#L58-L62

    Which got deprecated in API 22 (Android 5.1): https://developer.android.com/about/versions/android-5.1.html#http http://developer.android.com/reference/org/apache/http/params/HttpParams.html

    This makes org.thoughtcrime.ssl.pinning.util.PinningHelper.getPinnedHttpClient() deprecated.

    opened by pandasauce 0
A file/directory-picker for android. Implemented as a library project.

Note: avoid using as SD-card file picker on Kitkat+ In Kitkat or above, use Android's built-in file-picker instead. Google has restricted the ability

Jonas Kalderstam 711 Dec 27, 2022
Library and example project on how to use the UITableView component

UITableView for Android Usage Installation Android Studio Paste or clone this library into the /libs folder, in the root directory of your project. Cr

Thiago Locatelli 679 Nov 11, 2022
Graduation project of "Android Bootcamp Turkey"

Spending Tracking Mobile App Screenshots ENG Description This application allows you to record your bills, rent and all other expenses in 4 different

Yasin Tohan 6 Jun 1, 2021
Android Bootcamp Turkey Final Project

Expenses App Features Splash Screen OnBoarding Screen Change Icon Room Database Navigation View Binding / Data Binding Retrofit RecyclerView Currency

Sinan Türkoğlu 6 Aug 30, 2022
This is a sample Android Studio project that shows the necessary code to create a note list widget, And it's an implementation of a lesson on the Pluralsight platform, but with some code improvements

NoteKeeper-Custom-Widgets This is a sample Android Studio project that shows the necessary code to create a note list widget, And it's an implementati

Ibrahim Mushtaha 3 Oct 29, 2022
This project has been superseded by SuperSLiM, a layout manager for RecyclerView. I strongly recommend using SuperSLiM and not StickyGridHeaders.

StickyGridHeaders Replacement project at SuperSLiM This repository is abandoned and will no longer see any development or support. The replacement Sup

Tonic Artos 1.5k Nov 15, 2022
Hackathon Project

Notify Playstore Link Events Problem Statement : Whenever we try to attend events like interviews, exams, marriage, trips, catching a flight, train. T

Mausam Singh 5 Feb 1, 2022
Simple project where it is possible to calculate the average fuel when refueling

Aplicativo simples onde é calculado qual combustível é mais vantajoso ao abastec

Wesley V N De L Torres 0 Jan 23, 2022
Project of PDP UOC's subject

PDP Häagen-Dazs Backend -> MacadamiaNut Tech Stack Macadamia Nut has been written using Kotlin ver 1.6.0, and uses Spring Boot as framework. For DataB

Ivan Moll 1 Jan 16, 2022
Ms-goals - Project developed using Kotlin and Spring

Goals microservice Kotlin + Spring CRUD application. You can find the following

Gabriel Babler 0 Jan 28, 2022
This project created just for help developer who want to and ability of read VISA, UNION PAY, HUMO, ATTO and some other cards data read.

If you enjoy my content, please consider supporting what I do. Thank you. By me a Coffee To get a Git project into your build: Step 1. Add the JitPack

Fozilbek Imomov 1 Oct 15, 2022
A new canvas drawing library for Android. Aims to be the Fabric.js for Android. Supports text, images, and hand/stylus drawing input. The library has a website and API docs, check it out

FabricView - A new canvas drawing library for Android. The library was born as part of a project in SD Hacks (www.sdhacks.io) on October 3rd. It is cu

Antwan Gaggi 1k Dec 13, 2022
Android StackBlur is a library that can perform a blurry effect on a Bitmap based on a gradient or radius, and return the result. The library is based on the code of Mario Klingemann.

Android StackBlur Android StackBlur is a library that can perform a blurry effect on a Bitmap based on a gradient or radius, and return the result. Th

Enrique López Mañas 3.6k Dec 29, 2022
Android library providing bread crumbs to the support library fragments.

Hansel And Gretel Android library providing bread crumbs for compatibility fragments. Usage For a working implementation of this project see the sampl

Jake Wharton 163 Nov 25, 2022
Android library used to create an awesome Android UI based on a draggable element similar to the last YouTube graphic component.

Draggable Panel DEPRECATED. This project is not maintained anymore. Draggable Panel is an Android library created to build a draggable user interface

Pedro Vicente Gómez Sánchez 3k Dec 6, 2022
TourGuide is an Android library that aims to provide an easy way to add pointers with animations over a desired Android View

TourGuide TourGuide is an Android library. It lets you add pointer, overlay and tooltip easily, guiding users on how to use your app. Refer to the exa

Tan Jun Rong 2.6k Jan 5, 2023
Bubbles for Android is an Android library to provide chat heads capabilities on your apps. With a fast way to integrate with your development.

Bubbles for Android Bubbles for Android is an Android library to provide chat heads capabilities on your apps. With a fast way to integrate with your

Txus Ballesteros 1.5k Jan 2, 2023
Wizard Pager is a library that provides an example implementation of a Wizard UI on Android, it's based of Roman Nurik's wizard pager (https://github.com/romannurik/android-wizardpager)

Wizard Pager Wizard Pager is a library that provides an example implementation of a Wizard UI on Android, it's based of Roman Nurik's wizard pager (ht

Julián Suárez 520 Nov 11, 2022
Make your native android Toasts Fancy. A library that takes the standard Android toast to the next level with a variety of styling options. Style your toast from code.

FancyToast-Android Prerequisites Add this in your root build.gradle file (not your module build.gradle file): allprojects { repositories { ... ma

Shashank Singhal 1.2k Dec 26, 2022