Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
xx messenger iOS
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mobile
iOS
xx messenger iOS
Commits
be401c31
Commit
be401c31
authored
2 years ago
by
Dariusz Rybicki
Browse files
Options
Downloads
Patches
Plain Diff
Update cert pinning implementation
Use binary certificate (der)
parent
79409e8a
No related branches found
No related tags found
3 merge requests
!71
Releasing v1.1.5 (214)
,
!69
Implemented filtering for banned/blocked users and reporting
,
!67
v1.1.5 b(203)
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Sources/ReportingFeature/SendReport.swift
+23
-21
23 additions, 21 deletions
Sources/ReportingFeature/SendReport.swift
with
23 additions
and
21 deletions
Sources/ReportingFeature/SendReport.swift
+
23
−
21
View file @
be401c31
...
...
@@ -51,30 +51,32 @@ private final class SessionDelegate: NSObject, URLSessionDelegate {
didReceive
challenge
:
URLAuthenticationChallenge
,
completionHandler
:
@escaping
(
URLSession
.
AuthChallengeDisposition
,
URLCredential
?)
->
Void
)
{
let
authenticationMethod
=
challenge
.
protectionSpace
.
authenticationMethod
if
authenticationMethod
==
NSURLAuthenticationMethodServerTrust
,
let
serverTrust
=
challenge
.
protectionSpace
.
serverTrust
,
handleServerTrustChallenge
(
serverTrust
)
{
completionHandler
(
.
useCredential
,
URLCredential
(
trust
:
serverTrust
))
return
let
authMethod
=
challenge
.
protectionSpace
.
authenticationMethod
guard
authMethod
==
NSURLAuthenticationMethodServerTrust
else
{
return
completionHandler
(
.
cancelAuthenticationChallenge
,
nil
)
}
completionHandler
(
.
cancelAuthenticationChallenge
,
nil
)
}
}
private
func
handleServerTrustChallenge
(
_
serverTrust
:
SecTrust
)
->
Bool
{
guard
let
serverCert
=
SecTrustGetCertificateAtIndex
(
serverTrust
,
0
)
else
{
return
false
}
guard
let
serverTrust
=
challenge
.
protectionSpace
.
serverTrust
else
{
return
completionHandler
(
.
cancelAuthenticationChallenge
,
nil
)
}
let
serverCertCFData
=
SecCertificateCopyData
(
serverCert
)
let
serverCertNSData
=
NSData
(
bytes
:
CFDataGetBytePtr
(
serverCertCFData
),
length
:
CFDataGetLength
(
serverCertCFData
)
)
guard
let
serverCert
=
SecTrustGetCertificateAtIndex
(
serverTrust
,
0
)
else
{
return
completionHandler
(
.
cancelAuthenticationChallenge
,
nil
)
}
let
serverCertCFData
=
SecCertificateCopyData
(
serverCert
)
let
serverCertData
=
Data
(
bytes
:
CFDataGetBytePtr
(
serverCertCFData
),
count
:
CFDataGetLength
(
serverCertCFData
)
)
let
localCert
Path
=
Bundle
.
module
.
path
(
forResource
:
"report_cert"
,
ofType
:
"crt
"
)
!
let
localCert
NS
Data
=
NS
Data
(
contentsOf
File
:
localCert
Path
)
!
let
localCert
URL
=
Bundle
.
module
.
url
(
forResource
:
"report_cert"
,
withExtension
:
"der
"
)
!
let
localCertData
=
try!
Data
(
contentsOf
:
localCert
URL
)
return
serverCertNSData
.
isEqual
(
to
:
localCertNSData
as
Data
)
guard
serverCertData
==
localCertData
else
{
return
completionHandler
(
.
cancelAuthenticationChallenge
,
nil
)
}
completionHandler
(
.
useCredential
,
URLCredential
(
trust
:
serverTrust
))
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment