Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SSL Pinning #109

Closed
colinmcardell opened this issue Apr 5, 2016 · 5 comments
Closed

SSL Pinning #109

colinmcardell opened this issue Apr 5, 2016 · 5 comments

Comments

@colinmcardell
Copy link
Contributor

Nice work on SPTDataLoader. I'm curious what thoughts around SSL Pinning might be.

I'm likely to hack something together on a fork the moment, but I would like to contribute back something that is usable for others.

Any opinions?

@8W9aG
Copy link
Contributor

8W9aG commented Apr 5, 2016

We have tentatively discussed this before, and it's great its come up. I think a good way to approach this would be the following:

  • Add an argument into the initialiser for SPTDataLoaderService that feeds in a collection of supported hosts and the file URL of the certificate with the public key, it would be cool if this somehow supported wildcards in the host name. I think the service should manage certificate verification as I can't imagine a use case where someone would want to only pin a certificate in the factory or view level (e.g. it seems like an app wide problem), and the service has direct access to the NSURLSession delegates.
  • Use Apples security frameworks rather than OpenSSL directly.
  • Conform to areAllCertificatesAllowed to disable the SSL pinning logic.

If you want to get started I think this was quite a nice implementation to begin with: http://stackoverflow.com/a/29234388

@colinmcardell
Copy link
Contributor Author

@8W9aG I dig it.

I took a first pass at something here:
colinmcardell@4eb083b

I ended up creating an object to handle to validation process and added a setter on SPTDataLoaderService instead of modifying the initializer. I figured this would be easier that changing the initialization method signature. Also, easier on testing.

Currently the object SPTDataLoaderAuthChallengePolicy (name to be solidified, update: SPTDataLoaderServerTrustPolicy... still working on it. :) ) can be created with params for hosts + certs, then set on a service. When set, NSURLSessionDataDelegate calls for auth challenge within the service will attempt to validated the challenge against the provided host and certs.

Currently the object doesn't support wildcards for the host.

I did my reading when implementing as well as referenced a number of implementations elsewhere. The stack overflow link you referenced was a great starting point as well.

References:

@8W9aG
Copy link
Contributor

8W9aG commented Apr 6, 2016

👍 Looks like an incredibly good first pass, definitely on the right track

@colinmcardell
Copy link
Contributor Author

Thanks and great!

I added simple support for wildcards in the hosts string through a predicate filter. Also, squashed down the work on that branch. I will make a PR and any discussion around changes can happen in the comments there.

@rastersize
Copy link
Contributor

Closing this as #110 was merged. Big thanks @colinmcardell 😃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants