본문 바로가기

프로그래밍/코드 조각

SecKey compare

자체 생성한 사설 인증서 기반으로 서버간 통신시 서버 검증

public key 비교

let clientPublicKeys: [SecKey] = clientCertificates.compactMap { $0.publicKey }
let serverPublicKeys: [SecKey] = SSLCeritificate.publicKeys(for: trust)
for serverKey in serverPublicKeys as [AnyObject] {
	for clientKey in clientPublicKeys as [AnyObject] {
    	if serverKey.isEqual(clientKey) {
        	return true
        }
    }
 }
 return false

 certificate 비교

let clientSecCertificates = Set<SecCertificate>(clientCertificates.compactMap { $0.secCertificate })
let servierSecCertificates = Set<SecCertificate>(SSLCertificate.secCertificates(for: trust))

return serverSecCertificates.intersection(clientSecCertificates).count == serverSecCertificates.count