View publicKeyHexModulus
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func publicKeyHexModulus(key: SecKeyRef) -> String { | |
let s = String(format: "\(key)") | |
let r1 = s.rangeOfString("modulus: ")! | |
let r2 = Range<String.Index>(start: advance(r1.startIndex, count(r1)), end: advance(r1.endIndex, (SecKeyGetBlockSize(key) * 2))) | |
return s.substringWithRange(r2) | |
} |
View gist:d9dbc320d5de347c2a85
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func connection(connection: NSURLConnection, didReceiveAuthenticationChallenge challenge: NSURLAuthenticationChallenge) { | |
if(challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodServerTrust) { | |
var localTrust: Unmanaged<SecTrust>? | |
let serverTrust = challenge.protectionSpace.serverTrust! | |
let serverPublicKey = SecTrustCopyPublicKey(serverTrust).takeRetainedValue(); | |
let certificateData = NSData(contentsOfFile: NSBundle.mainBundle().pathForResource("pinning-certificate", ofType: "der")!) | |
let localCertificate = SecCertificateCreateWithData(kCFAllocatorDefault, certificateData).takeRetainedValue(); | |
let policy = SecPolicyCreateBasicX509().takeRetainedValue() | |
if SecTrustCreateWithCertificates(localCertificate, policy, &localTrust) == errSecSuccess { |
View Makefile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.PHONY: all clean osx ios | |
export CFLAGS LDFLAGS | |
OSX_SDK_VERSION = 10.9 | |
OSX_MIN_VERSION = 10.9 | |
OSX_ARCH = MacOSX-x86_64 | |
OSX_TARGET = $(patsubst %,build/%/lib/libsodium.a,$(OSX_ARCH)) | |
IOS_SDK_VERSION = 7.1 | |
IOS_MIN_VERSION = 7.1 | |
IOS_ARCH = iPhoneSimulator-i386 iPhoneSimulator-x86_64 iPhoneOS-armv7 iPhoneOS-armv7s iPhoneOS-arm64 |