Skip to content

Commit

Permalink
移除无用代码
Browse files Browse the repository at this point in the history
  • Loading branch information
rakeyang committed Oct 13, 2021
1 parent b2e247f commit 9a23f1f
Show file tree
Hide file tree
Showing 19 changed files with 30 additions and 1,143 deletions.
5 changes: 2 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,11 @@ let package = Package(
resources: [.copy("Cert")]),
.target(
name: "PracticeTLS",
dependencies: ["CocoaAsyncSocket", "Rainbow", "SecurityRSA", "CryptoSwift"]),
.target(name: "SecurityRSA"),
dependencies: ["CocoaAsyncSocket", "Rainbow", "CryptoSwift"]),
.target(name: "QUIC", dependencies: ["PracticeTLS"]),
.testTarget(
name: "PracticeTLSTests",
dependencies: ["PracticeTLS", "QUIC"]),
],
swiftLanguageVersions: [.version("5.0")]
swiftLanguageVersions: [.v5]
)
1 change: 0 additions & 1 deletion Sources/PracticeTLS/Encrypt/Certificates/ASN1Parser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
//

import Foundation
import SecurityRSA

enum ASN1TypeTag : UInt8
{
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion Sources/PracticeTLS/Logger/PracticeLog.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public struct LogFlag: OptionSet {
public static let all: LogFlag = [.error, .warning, .info, .debug, .verbose]
}

public var dynamicLogLevel: LogFlag = .info
public var dynamicLogLevel: LogFlag = .all

@inlinable
public func LogError(_ message: @autoclosure () -> String,
Expand Down
17 changes: 14 additions & 3 deletions Sources/PracticeTLS/TLS/TLS1_3.RecordLayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@
import Foundation
import CryptoKit
import CryptoSwift
import SecurityRSA

extension TLS1_3 {
static let ivLabel = [UInt8]("iv".utf8)
static let keyLabel = [UInt8]("key".utf8)

class RecordLayer: TLSRecordProtocol, CustomStringConvertible {
class RecordLayer: TLSRecordProtocol, CustomStringConvertible, CustomDebugStringConvertible {
var context: TLSConnection
var handshaked: Bool = false
var clientCipherChanged: Bool = false
Expand Down Expand Up @@ -64,6 +63,9 @@ extension TLS1_3 {
//线程步调不一致导致解密失败⚠️⚠️⚠️⚠️
sema.wait()
changeReadKey(with: handshakeState.clientTrafficSecret!)
if TLSSessionManager.shared.isDebug {
try? description.write(toFile: "\(NSHomeDirectory())/MasterSecretKey.log", atomically: true, encoding: .utf8)
}
TLSSessionManager.shared.delegate?.didHandshakeFinished(context)
} else {
context.sendMessage(msg: TLSAlert(alert: .badRecordMAC, alertLevel: .fatal))
Expand Down Expand Up @@ -233,6 +235,15 @@ extension TLS1_3 {
}

var description: String {
return """
CLIENT_HANDSHAKE_TRAFFIC_SECRET \(s.clientRandom.toHexString()) \(handshakeState.clientHandshakeTrafficSecret!.toHexString())
SERVER_HANDSHAKE_TRAFFIC_SECRET \(s.clientRandom.toHexString()) \(handshakeState.serverHandshakeTrafficSecret!.toHexString())
CLIENT_TRAFFIC_SECRET_0 \(s.clientRandom.toHexString()) \(handshakeState.clientTrafficSecret!.toHexString())
SERVER_TRAFFIC_SECRET_0 \(s.clientRandom.toHexString()) \(handshakeState.serverTrafficSecret!.toHexString())
"""
}

var debugDescription: String {
switch context.keyExchange {
case .rsa:
return "Unsupport"
Expand Down Expand Up @@ -323,7 +334,7 @@ extension TLS1_3 {
}

var description: String {
return "Key: \(p.key.toHexString() ) IV: \(p.iv.toHexString() ?? "")"
return "[sequence: \(p.sequenceNumber)] Key: \(p.key.toHexString() ) IV: \(p.iv.toHexString() )"
}
}
}
1 change: 0 additions & 1 deletion Sources/PracticeTLS/TLS/TLSCertificate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
//

import Foundation
import SecurityRSA

extension Bundle {
class func certBundle() -> Bundle {
Expand Down
1 change: 0 additions & 1 deletion Sources/PracticeTLS/TLS/TLSClientKeyExchange.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
//

import Foundation
import SecurityRSA

class EncryptedPreMasterSecret {
var encryptedPreMaster: [UInt8] = []
Expand Down
1 change: 0 additions & 1 deletion Sources/PracticeTLS/TLS/TLSConnection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import Foundation
import CocoaAsyncSocket
import CryptoSwift
import SecurityRSA

public let TLSClientFinishedLabel = [UInt8]("client finished".utf8)
public let TLSServerFinishedLabel = [UInt8]("server finished".utf8)
Expand Down
1 change: 0 additions & 1 deletion Sources/PracticeTLS/TLS/TLSEncryptedExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
//

import Foundation
import SecurityRSA

class TLSEncryptedExtensions: TLSHandshakeMessage {

Expand Down
1 change: 0 additions & 1 deletion Sources/PracticeTLS/TLS/TLSServerKeyExchange.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
//

import Foundation
import SecurityRSA

enum CurveType: UInt8 {
case named_curve = 0x03
Expand Down
4 changes: 3 additions & 1 deletion Sources/PracticeTLS/TLS/TLSSessionManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import Foundation
import CocoaAsyncSocket
import SecurityRSA

public protocol TLSConnectionDelegate {
/// TLS握手完成
Expand All @@ -18,6 +17,9 @@ public protocol TLSConnectionDelegate {

public class TLSSessionManager: NSObject {
public static var shared = TLSSessionManager()

public var isDebug: Bool = false

public var identity: Identity? = nil {
willSet {
if let pemIdentity = newValue as? PEMFileIdentity {
Expand Down
10 changes: 10 additions & 0 deletions Sources/PracticeTLS/TLS/TLSUtilities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,16 @@ public extension String {
return nil
}
}

var rsaCleanKey: String {
if contains("BEGIN") {
var arr = self.split(separator: "\n")
arr.removeFirst()
arr.removeLast()
return arr.joined()
}
return self
}
}

/// P_hash function as defined in RFC 2246, section 5, p. 11
Expand Down
220 changes: 0 additions & 220 deletions Sources/SecurityRSA/Asn1Parser.swift

This file was deleted.

Loading

0 comments on commit 9a23f1f

Please sign in to comment.