Permalink
Show file tree
Hide file tree
35 changes: 23 additions & 12 deletions
35
FirefoxPrivateNetworkVPN/Networking/GuardianURLRequest.swift
9 changes: 5 additions & 4 deletions
9
FirefoxPrivateNetworkVPN/Networking/GuardianURLRequestPath.swift
105 changes: 49 additions & 56 deletions
105
FirefoxPrivateNetworkVPN/ViewControllers/LoginViewController.swift
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
PGAND-410 Resolve oauth session fixation on iOS (#272)
* update login flow with PKCE * fix MockGuardianAPI
- Loading branch information
1 parent
ee7e380
commit 4309f5c
Showing
11 changed files
with
166 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
FirefoxPrivateNetworkVPN/Utilities/PKCECodeGenerator.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| // | ||
| // PKCECodeGenerator | ||
| // FirefoxPrivateNetworkVPN | ||
| // | ||
| // This Source Code Form is subject to the terms of the Mozilla Public | ||
| // License, v. 2.0. If a copy of the MPL was not distributed with this | ||
| // file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
| // | ||
| // Copyright © 2020 Mozilla Corporation. | ||
| // | ||
| import Foundation | ||
|
|
||
| struct PKCECodeGenerator { | ||
| static var generateCode: (codeChallenge: String, codeVerifier: String) { | ||
| let codeVerifier = generateCodeVerifier() | ||
| let codeChallenge = base64UrlEncode(sha256(string: codeVerifier)) | ||
| return (codeChallenge, codeVerifier) | ||
| } | ||
|
|
||
| private static func generateCodeVerifier() -> String { | ||
| var buffer = [UInt8](repeating: 0, count: 32) | ||
| _ = SecRandomCopyBytes(kSecRandomDefault, buffer.count, &buffer) | ||
| return base64UrlEncode(Data(buffer)) | ||
| } | ||
|
|
||
| private static func base64UrlEncode(_ data: Data?) -> String { | ||
| guard let data = data else { return "" } | ||
| return data.base64EncodedString() | ||
| .replacingOccurrences(of: "+", with: "-") | ||
| .replacingOccurrences(of: "/", with: "_") | ||
| } | ||
|
|
||
| private static func sha256(string: String) -> Data? { | ||
| guard let data = string.data(using: .utf8) else { return nil } | ||
| var hash = [UInt8](repeating: 0, count: Int(CC_SHA256_DIGEST_LENGTH)) | ||
| data.withUnsafeBytes { | ||
| _ = CC_SHA256($0.baseAddress, CC_LONG(data.count), &hash) | ||
| } | ||
| return Data(hash) | ||
| } | ||
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.