Swiftpack.co -  happycodelucky/SwiftRootCAChallengeResolver as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
happycodelucky/SwiftRootCAChallengeResolver
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 ATS
.package(url: "https://github.com/happycodelucky/SwiftRootCAChallengeResolver.git", from: "v0.4.1")

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.

GitHub

link
Stars: 0
Last commit: 34 weeks ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Release Notes

Preview Release
1 year ago

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API