@@ -42,16 +42,14 @@ func isTls12(forConnection connection: ObservedConnection) -> Bool
4242 NSLog ( " TLS response not found \( outPacket as! NSData ) " )
4343 return false
4444 }
45-
46- NSLog ( " Found TLS: \( requestRange) \( responseRange) \( outPacket. count) " )
47-
45+
4846 return true
4947}
5048
5149func processTls12( _ connection: ObservedConnection ) {
52- NSLog ( " Processing TLS " )
5350 let outPacketHash : RMap < String , Data > = RMap ( key: connection. outgoingKey)
54-
51+ let tlsCommonNameSet : RSortedSet < String > = RSortedSet ( key: connection. outgoingTlsCommonNameKey)
52+
5553 // Get the out packet that corresponds with this connection ID
5654 guard let outPacket: Data = outPacketHash [ connection. connectionID]
5755 else
@@ -62,7 +60,7 @@ func processTls12(_ connection: ObservedConnection) {
6260
6361 let maybeBegin = findCommonNameStart ( outPacket)
6462 guard let begin = maybeBegin else {
65- NSLog ( " No common name beginning found \( outPacket as! NSData ) " )
63+ NSLog ( " No common name beginning found " )
6664 NSLog ( " \( connection. outgoingKey) \( connection. connectionID) \( outPacket. count) " )
6765 return
6866 }
@@ -73,9 +71,11 @@ func processTls12(_ connection: ObservedConnection) {
7371 return
7472 }
7573
76- let commonData = extract ( outPacket, begin+ commonNameStart. count, end)
74+ let commonData = extract ( outPacket, begin+ commonNameStart. count, end- 1 )
7775 let commonName = commonData. string
78- NSLog ( " Found TLS 1.2 common name: \( commonName) " )
76+ NSLog ( " Found TLS 1.2 common name: \( commonName) \( commonName. count) \( begin) \( end) " )
77+
78+ let _ = tlsCommonNameSet. incrementScore ( ofField: commonName, byIncrement: 1 )
7979}
8080
8181private func findCommonNameStart( _ outPacket: Data ) -> Int ? {
@@ -84,7 +84,12 @@ private func findCommonNameStart(_ outPacket: Data) -> Int? {
8484 return nil
8585 }
8686
87- return range. lowerBound
87+ let maybeNextRange = outPacket. range ( of: commonNameStart, options: [ ] , in: range. upperBound..< outPacket. count)
88+ guard let nextRange = maybeNextRange else {
89+ return nil
90+ }
91+
92+ return nextRange. lowerBound
8893}
8994
9095private func findCommonNameEnd( _ outPacket: Data , _ begin: Int ) -> Int ? {
0 commit comments