Giter VIP home page Giter VIP logo

rnpinnedcertvalidator's Introduction

RNPinnedCertValidator

RNPinnedCertValidator simplifies validating "pinned" SSL certificates. A pinned certificate means that your app only trusts a specific list of certificates rather than the entire trusted root store for the device. This improves security by limiting the number of trusted certificates, and frustrates attacks that modify the trusted root store.

Usage

  1. Put your trusted certificate in your bundle.
  2. Create a validator with -initWithCertificatePath:.

If using NSURLConnection (iOS6 or earlier)

  1. Create an NSURLConnection with your object as a delegate.
  2. In -connection:willSendRequestForAuthenticationChallenge:, call [validator validateChallenge:challenge].
- (void)connection:(NSURLConnection *)connection 
willSendRequestForAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {
  RNPinnedCertValidator *validator = [[RNPinnedCertValidator alloc] initWithCertificatePath:kPathToCerFile];
  [validator validateChallenge:challenge];
}

If using NSURLSession (iOS7 or later)

  1. Create an NSURLSession with your object as a delegate.
  2. In URLSession:didReceiveChallenge:completionHandler:, call [validator validateChallenge:challenge completionHandler:completionHandler] passing the completion handler through.
- (void)URLSession:(NSURLSession *)session didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge
                                             completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition disposition, NSURLCredential *credential))completionHandler {
  RNPinnedCertValidator *validator = [[RNPinnedCertValidator alloc] initWithCertificatePath:kPathToCerFile];
  [validator validateChallenge:challenge completionHandler:completionHandler];
}

If you don't have your certificate in a handy file, pull it from your server:

openssl s_client -connect myserver:443 </dev/null 2>/dev/null | openssl x509 -outform DER > myserver.cer

See the PinnedCertExample project for an example that includes a UIWebView.

rnpinnedcertvalidator's People

Contributors

rnapier avatar cpatterson avatar gchilds avatar

Watchers

Ben Baron avatar Richard Burton avatar James Cloos avatar Jin avatar Pedro Gomes avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.