Skip to content

Commit

Permalink
证书读取逻辑调整
Browse files Browse the repository at this point in the history
  • Loading branch information
rakeyang committed Oct 12, 2021
1 parent ec43679 commit b2e247f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
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 = .debug
public var dynamicLogLevel: LogFlag = .info

@inlinable
public func LogError(_ message: @autoclosure () -> String,
Expand Down
5 changes: 4 additions & 1 deletion Sources/PracticeTLS/TLS/PEMFileIdentity.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ import Foundation
public class PEMFileIdentity
{
public var certificateChain: [X509.Certificate]
public var publicPEM: String
public var privatePEM: String

public init?(certificateFile: String, privateKeyFile: String)
{

publicPEM = certificateFile
privatePEM = privateKeyFile
certificateChain = []
for (section, object) in ASN1Parser.sectionsFromPEMFile(certificateFile) {
switch section {
Expand Down
5 changes: 2 additions & 3 deletions Sources/PracticeTLS/TLS/TLSSessionManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ public class TLSSessionManager: NSObject {
public static var shared = TLSSessionManager()
public var identity: Identity? = nil {
willSet {
if let cert = newValue?.certificateChain.last {

try? RSAEncryptor.shared.setup(publicPEM: String(contentsOfFile: Bundle.certBundle().path(forResource: "Cert/public.pem", ofType: nil)!), privatePEM: String(contentsOfFile: Bundle.certBundle().path(forResource: "Cert/private.pem", ofType: nil)!))
if let pemIdentity = newValue as? PEMFileIdentity {
try? RSAEncryptor.shared.setup(publicPEM: String(contentsOfFile: pemIdentity.publicPEM), privatePEM: String(contentsOfFile: pemIdentity.privatePEM))
}
}
}
Expand Down

0 comments on commit b2e247f

Please sign in to comment.