Giter Club home page Giter Club logo

swiftrootcachallengeresolver's Introduction

RootCAChallengeResolver

A package to support use of URLSession to make SSL request where the service utilizes a self-signed certificate. Using RootCAChallengeResolver encourages less pervasive disabling of ATS.

As always, be careful of the endpoints you trust. They should ideally be endpoints your organization hosts.

For more information see Apple's documentation on Preventing Insecure Network Connections.

Swift Version iOS Version macOS Version tvOS Version watchOS Version GitHub license Maintained Release

Release Notes

This is not yet a production-ready release.

Version Description
0.4.0 Initial commit

Installation

To use RootCAChallengeResolver within your project see how to reference package using the Swift Package Manager or in Xcode. Once installed you can import RootCAChallengeResolver as appropriate.

Usage

The intent is for RootCAChallengeResolver to be used as a URLSession's delegate for the specific host your application has implicit trust in.

First create a new requests (details here are for show only)

let host = "cdn.example.com"
let endpoint = URL("https://\(host)/conf/2020-01-01.json")!
let request = URLRequest(url: endpoint)

Create a RootCAChallengeResolver and use as the delegate to a new URLSession

// (Optional) load an embedded cert to use for trust
let certUrl = Bundle.main.url(forResource: host, withExtension: "pem")
let certData = Data(contentsOf: certUrl)

// Use a `RootCAChallengeResolver` as the delegate for a `URLSession`
//
// `cert` is optional, and only need to be provided if you want to ensure more 
// stringent trust validation
let challengeDelegate = RootCAChallengeResolver(host: host, cert: certData)

// Use the `challengeDelegate` as the session delegate
let session = URLSession(configuration: .default, 
                         delegate: challengeDelegate, 
                         delegateQueue: .current ?? .main)

Perform a task, like a download

// Download the data
let task = session.downloadTask(with: request) { localUrl, response, error in
    ///...
}

task.resume()

URLSession Conveniences

URLSession has been extended with some convenience initializers

let host = "cdn.example.com"
let certUrl = Bundle.main.url(forResource: host, withExtension: "pem")
let certData = Data(contentsOf: certUrl)

// Create a session for a host and trust cert
let session = URLSession(configuration: .default, host: host, cert: certData)

..OR..

// Create a session for just a host
let session = URLSession(configuration: .default, host: host)

Unit Testing

Testing has not yet been implemented.

This package was extracted from another project and is yet to be fully self-serving.

swiftrootcachallengeresolver's People

Contributors

happycodelucky avatar paulbatessonos avatar

Stargazers

 avatar

Watchers

 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.