Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Man in the Middle? - No, thank you!

Man in the Middle? - No, thank you!

Many developers in encrypt confidential data on the way to the backend using SSL and have a false sense of security.

While SSL is suitable as a tool to ensure the confidentiality and integrity of data, it must be understood and used correctly. A publication of the University of Texas and Stanford University from October 2012 shows that some serious vulnerabilities can be overlooked, even when using renowned libraries and software packages.

Using an example iOS application the talk shows how attackers can take possession of supposedly safely transmitted data, and how this can be prevented effectively by means of SSL Certificate pinning.

First a few SSL basics and relevant attack vectors are explained, then ways to counteract them. While the example is based on iOS, the concepts can be applied to Android and other platforms, as well.

Daniel Schneller

June 26, 2013
Tweet

More Decks by Daniel Schneller

Other Decks in Programming

Transcript

  1. Reference$CerZficates SecTrustResultType evaluationResult; OSStatus status = SecTrustEvaluate(srvTrust, &evaluationResult); if (status

    == errSecSuccess) { if (evaluationResult == kSecTrustResultUnspecified) { // ... } } •Step$1:$$Validate$Chain\of\Trust
  2. Reference$CerZficates SecTrustResultType evaluationResult; OSStatus status = SecTrustEvaluate(srvTrust, &evaluationResult); if (status

    == errSecSuccess) { if (evaluationResult == kSecTrustResultUnspecified) { // ... } } •Step$1:$$Validate$Chain\of\Trust
  3. NSString *refPath = [[NSBundle mainBundle] pathForResource:@"reference" ofType:@"der"]; NSData *refCertData =

    [[NSData alloc] initWithContentsOfFile:refPath]; Reference$CerZficates •Step$2:$Load$Reference$CerZficate
  4. NSString *refPath = [[NSBundle mainBundle] pathForResource:@"reference" ofType:@"der"]; NSData *refCertData =

    [[NSData alloc] initWithContentsOfFile:refPath]; Reference$CerZficates •Step$2:$Load$Reference$CerZficate
  5. Reference$CerZficates BOOL found = NO; CFIndex crtCount = SecTrustGetCertificateCount(srvTrust); for

    (CFIndex j = 0; j < crtCount && !found; j++) { SecCertificateRef cert = SecTrustGetCertificateAtIndex(srvTrust, j); NSData* certData = CFBridgingRelease(SecCertificateCopyData(cert)); found = [refCertData isEqualToData:certData]; } •Step$3:$Compare$cerZficates
  6. Reference$CerZficates BOOL found = NO; CFIndex crtCount = SecTrustGetCertificateCount(srvTrust); for

    (CFIndex j = 0; j < crtCount && !found; j++) { SecCertificateRef cert = SecTrustGetCertificateAtIndex(srvTrust, j); NSData* certData = CFBridgingRelease(SecCertificateCopyData(cert)); found = [refCertData isEqualToData:certData]; } •Step$3:$Compare$cerZficates
  7. Reference$CerZficates •Step$3:$Compare$cerZficates BOOL found = NO; CFIndex crtCount = SecTrustGetCertificateCount(srvTrust);

    for (CFIndex j = 0; j < crtCount && !found; j++) { SecCertificateRef cert = SecTrustGetCertificateAtIndex(srvTrust, j); NSData* certData = CFBridgingRelease(SecCertificateCopyData(cert)); found = [refCertData isEqualToData:certData]; }
  8. Reference$CerZficates •Step$3:$Compare$cerZficates BOOL found = NO; CFIndex crtCount = SecTrustGetCertificateCount(srvTrust);

    for (CFIndex j = 0; j < crtCount && !found; j++) { SecCertificateRef cert = SecTrustGetCertificateAtIndex(srvTrust, j); NSData* certData = CFBridgingRelease(SecCertificateCopyData(cert)); found = [refCertData isEqualToData:certData]; }
  9. Reference$CerZficates •Step$3:$Compare$cerZficates BOOL found = NO; CFIndex crtCount = SecTrustGetCertificateCount(srvTrust);

    for (CFIndex j = 0; j < crtCount && !found; j++) { SecCertificateRef cert = SecTrustGetCertificateAtIndex(srvTrust, j); NSData* certData = CFBridgingRelease(SecCertificateCopyData(cert)); found = [refCertData isEqualToData:certData]; }
  10. Reference$CerZficates •Step$3:$Compare$cerZficates BOOL found = NO; CFIndex crtCount = SecTrustGetCertificateCount(srvTrust);

    for (CFIndex j = 0; j < crtCount && !found; j++) { SecCertificateRef cert = SecTrustGetCertificateAtIndex(srvTrust, j); NSData* certData = CFBridgingRelease(SecCertificateCopyData(cert)); found = [refCertData isEqualToData:certData]; }
  11. Reference$CerZficates •Step$3:$Compare$cerZficates BOOL found = NO; CFIndex crtCount = SecTrustGetCertificateCount(srvTrust);

    for (CFIndex j = 0; j < crtCount && !found; j++) { SecCertificateRef cert = SecTrustGetCertificateAtIndex(srvTrust, j); NSData* certData = CFBridgingRelease(SecCertificateCopyData(cert)); found = [refCertData isEqualToData:certData]; }
  12. FingerprinZng$ $Client$App $Server == 1122 3344 5566 7788 9900 AABB

    CCDD EEFF 9988 7766 SHA-1 Hash 1122 3344 5566 7788 9900 AABB CCDD EEFF 9988 7766
  13. FingerprinZng static NSString* const kReferenceFP = @"AC .... DC"; BOOL

    found = NO; CFIndex crtCount = SecTrustGetCertificateCount(srvTrust); for (CFIndex j = 0; j < crtCount && !found; j++) { SecCertificateRef cert = SecTrustGetCertificateAtIndex(srvTrust, j); NSData* certData = CFBridgingRelease(SecCertificateCopyData(cert)); NSString* fingerprint = [self sha1:certData]; found = [kReferenceFP isEqualToString:fingerprint] } •Schrie$2:$Fingerprint$berechnen
  14. FingerprinZng static NSString* const kReferenceFP = @"AC .... DC"; BOOL

    found = NO; CFIndex crtCount = SecTrustGetCertificateCount(srvTrust); for (CFIndex j = 0; j < crtCount && !found; j++) { SecCertificateRef cert = SecTrustGetCertificateAtIndex(srvTrust, j); NSData* certData = CFBridgingRelease(SecCertificateCopyData(cert)); NSString* fingerprint = [self sha1:certData]; found = [kReferenceFP isEqualToString:fingerprint] } •Schrie$2:$Fingerprint$berechnen
  15. FingerprinZng •Schrie$2:$Fingerprint$berechnen static NSString* const kReferenceFP = @"AC .... DC";

    BOOL found = NO; CFIndex crtCount = SecTrustGetCertificateCount(srvTrust); for (CFIndex j = 0; j < crtCount && !found; j++) { SecCertificateRef cert = SecTrustGetCertificateAtIndex(srvTrust, j); NSData* certData = CFBridgingRelease(SecCertificateCopyData(cert)); NSString* fingerprint = [self sha1:certData]; found = [kReferenceFP isEqualToString:fingerprint] }
  16. FingerprinZng •Schrie$2:$Fingerprint$berechnen static NSString* const kReferenceFP = @"AC .... DC";

    BOOL found = NO; CFIndex crtCount = SecTrustGetCertificateCount(srvTrust); for (CFIndex j = 0; j < crtCount && !found; j++) { SecCertificateRef cert = SecTrustGetCertificateAtIndex(srvTrust, j); NSData* certData = CFBridgingRelease(SecCertificateCopyData(cert)); NSString* fingerprint = [self sha1:certData]; found = [kReferenceFP isEqualToString:fingerprint] }
  17. FingerprinZng •Schrie$2:$Fingerprint$berechnen static NSString* const kReferenceFP = @"AC .... DC";

    BOOL found = NO; CFIndex crtCount = SecTrustGetCertificateCount(srvTrust); for (CFIndex j = 0; j < crtCount && !found; j++) { SecCertificateRef cert = SecTrustGetCertificateAtIndex(srvTrust, j); NSData* certData = CFBridgingRelease(SecCertificateCopyData(cert)); NSString* fingerprint = [self sha1:certData]; found = [kReferenceFP isEqualToString:fingerprint] }
  18. FingerprinZng •Schrie$2:$Fingerprint$berechnen static NSString* const kReferenceFP = @"AC .... DC";

    BOOL found = NO; CFIndex crtCount = SecTrustGetCertificateCount(srvTrust); for (CFIndex j = 0; j < crtCount && !found; j++) { SecCertificateRef cert = SecTrustGetCertificateAtIndex(srvTrust, j); NSData* certData = CFBridgingRelease(SecCertificateCopyData(cert)); NSString* fingerprint = [self sha1:certData]; found = [kReferenceFP isEqualToString:fingerprint] }
  19. FingerprinZng •Schrie$2:$Fingerprint$berechnen static NSString* const kReferenceFP = @"AC .... DC";

    BOOL found = NO; CFIndex crtCount = SecTrustGetCertificateCount(srvTrust); for (CFIndex j = 0; j < crtCount && !found; j++) { SecCertificateRef cert = SecTrustGetCertificateAtIndex(srvTrust, j); NSData* certData = CFBridgingRelease(SecCertificateCopyData(cert)); NSString* fingerprint = [self sha1:certData]; found = [kReferenceFP isEqualToString:fingerprint] }
  20. FingerprinZng •Schrie$2:$Fingerprint$berechnen static NSString* const kReferenceFP = @"AC .... DC";

    BOOL found = NO; CFIndex crtCount = SecTrustGetCertificateCount(srvTrust); for (CFIndex j = 0; j < crtCount && !found; j++) { SecCertificateRef cert = SecTrustGetCertificateAtIndex(srvTrust, j); NSData* certData = CFBridgingRelease(SecCertificateCopyData(cert)); NSString* fingerprint = [self sha1:certData]; found = [kReferenceFP isEqualToString:fingerprint] }
  21. FingerprinZng •Schrie$2:$Fingerprint$berechnen static NSString* const kReferenceFP = @"AC .... DC";

    BOOL found = NO; CFIndex crtCount = SecTrustGetCertificateCount(srvTrust); for (CFIndex j = 0; j < crtCount && !found; j++) { SecCertificateRef cert = SecTrustGetCertificateAtIndex(srvTrust, j); NSData* certData = CFBridgingRelease(SecCertificateCopyData(cert)); NSString* fingerprint = [self sha1:certData]; found = [kReferenceFP isEqualToString:fingerprint] }