Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:omise/omise-ios into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
vault087 committed May 15, 2024
2 parents 1702689 + b31664e commit 415cdd5
Show file tree
Hide file tree
Showing 49 changed files with 1,938 additions and 123 deletions.
2 changes: 1 addition & 1 deletion ExampleApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/omise/omise-ios.git";
requirement = {
branch = "feature/MIT-1904";
branch = "feature/MIT-2470";
kind = branch;
};
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,17 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/omise/omise-ios.git",
"state" : {
"branch" : "feature/MIT-1904",
"revision" : "0ed8ce39701b08433a2d5c0a678e95edd8b2b8ef"
"branch" : "feature/MIT-2470",
"revision" : "4f1bbf9a0f0828c7531664276fc244fd8433a869"
}
},
{
"identity" : "spm",
"kind" : "remoteSourceControl",
"location" : "https://github.com/ios-3ds-sdk/SPM",
"state" : {
"revision" : "a4e55d7f10294ea81abd1db393ae05606a5efa46",
"version" : "2.4.0"
}
}
],
Expand Down
4 changes: 0 additions & 4 deletions ExampleApp/Config.local.plist
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,5 @@
<dict>
<key>publicKey</key>
<string>pkey_</string>
<key>devVaultBaseURL</key>
<string></string>
<key>devApiBaseURL</key>
<string></string>
</dict>
</plist>
15 changes: 7 additions & 8 deletions ExampleApp/Views/ProductDetailViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,11 @@ class ProductDetailViewController: BaseViewController {
let text = textField.text,
let url = URL(string: text) else { return }

let deeplinkRedirectURLPattern = AppDeeplink.threeDSChallenge.urlString
let webRedirectURLPattern = "https://exampleapp.opn.ooo"
self.omiseSDK.presentAuthorizingPayment(
from: self,
authorizeURL: url,
returnURLs: [deeplinkRedirectURLPattern, webRedirectURLPattern],
expectedReturnURLStrings: ["https://omise.co"],
threeDSRequestorAppURLString: AppDeeplink.threeDSChallenge.urlString,
delegate: self
)
})
Expand All @@ -70,13 +69,13 @@ class ProductDetailViewController: BaseViewController {

// MARK: - Authorizing Payment View Controller Delegate

extension ProductDetailViewController: AuthorizingPaymentViewControllerDelegate {
func authorizingPaymentViewController(_ viewController: AuthorizingPaymentViewController, didCompleteAuthorizingPaymentWithRedirectedURL redirectedURL: URL) {
print("Payment is authorized with redirect url `\(redirectedURL)`")
extension ProductDetailViewController: AuthorizingPaymentDelegate {
func authorizingPaymentDidComplete(with redirectedURL: URL?) {
print("Payment is authorized with redirect url `\(String(describing: redirectedURL))`")
omiseSDK.dismiss()
}

func authorizingPaymentViewControllerDidCancel(_ viewController: AuthorizingPaymentViewController) {
func authorizingPaymentDidCancel() {
print("Payment is not authorized")
omiseSDK.dismiss()
}
}
Expand Down
98 changes: 98 additions & 0 deletions OmiseSDK/Sources/3DS/Crypto/CryptData.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import Foundation
import CommonCrypto

enum CryptoError: Error {
case invalidKeyLength
case creationError(Int)
case updateError(Int)
case finalError(Int)
}

// swiftlint:disable:next function_parameter_count function_body_length
func cryptData(
_ dataIn: Data,
operation: CCOperation, // kCCEncrypt, kCCDecrypt
mode: CCMode, // kCCModeECB, kCCModeCBC, etc.
algorithm: CCAlgorithm, // kCCAlgorithmAES, kCCAlgorithmDES, etc.
padding: CCPadding, // ccNoPadding, ccPKCS7Padding
keyLength: size_t,
iv: Data?,
key: Data
) throws -> Data {
guard key.count == keyLength else {
throw CryptoError.invalidKeyLength
}

var cryptor: CCCryptorRef?
var status = CCCryptorCreateWithMode(operation,
mode,
algorithm,
padding,
iv?.withUnsafeBytes { $0.baseAddress },
key.withUnsafeBytes { $0.baseAddress },
keyLength,
nil,
0,
0, // tweak XTS mode, numRounds
0, // CCModeOptions
&cryptor)

if status != kCCSuccess {
throw CryptoError.creationError(Int(status))
}

guard let cryptor = cryptor else {
throw CryptoError.creationError(Int(status))
}

defer {
CCCryptorRelease(cryptor)
}

let dataOutLength = CCCryptorGetOutputLength(cryptor, dataIn.count, true)
var dataOut = Data(count: dataOutLength)
var dataOutMoved = 0

status = dataOut.withUnsafeMutableBytes { dataOutPointer in
dataIn.withUnsafeBytes { dataInPointer -> CCCryptorStatus in
guard let dataInPointerBaseAddress = dataInPointer.baseAddress,
let dataOutPointerBaseAddress = dataOutPointer.baseAddress else {
return Int32(kCCParamError)
}
return CCCryptorUpdate(
cryptor,
dataInPointerBaseAddress,
dataIn.count,
dataOutPointerBaseAddress,
dataOutLength,
&dataOutMoved
)
}
}

if status != kCCSuccess {
throw CryptoError.updateError(Int(status))
}

var dataOutMovedFinal = 0
status = dataOut.withUnsafeMutableBytes { dataOutPointer in
guard let dataOutPointerBaseAddress = dataOutPointer.baseAddress else {
return Int32(kCCParamError)
}

return CCCryptorFinal(
cryptor,
dataOutPointerBaseAddress.advanced(by: dataOutMoved),
dataOutLength - dataOutMoved,
&dataOutMovedFinal
)
}

if status != kCCSuccess {
throw CryptoError.finalError(Int(status))
}

dataOut.count = dataOutMoved + dataOutMovedFinal

return dataOut
}
10 changes: 10 additions & 0 deletions OmiseSDK/Sources/3DS/Crypto/String+PemCert.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import Foundation

extension String {
var pemCertificate: String {
self
.replacingOccurrences(of: "-----BEGIN CERTIFICATE-----", with: "")
.replacingOccurrences(of: "-----END CERTIFICATE-----", with: "")
.replacingOccurrences(of: "\r\n", with: "")
}
}
15 changes: 15 additions & 0 deletions OmiseSDK/Sources/3DS/Crypto/String+sha512.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import Foundation
import CommonCrypto

extension String {
public var sha512: Data {
let data = Data(self.utf8)
var hash = [UInt8](repeating: 0, count: Int(CC_SHA512_DIGEST_LENGTH))

data.withUnsafeBytes {
_ = CC_SHA512($0.baseAddress, CC_LONG(data.count), &hash)
}

return Data(hash)
}
}
24 changes: 24 additions & 0 deletions OmiseSDK/Sources/3DS/NetceteraConfig.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import Foundation

public struct NetceteraConfig {
public let id: String
public let deviceInfoEncryptionAlg: String
public let deviceInfoEncryptionEnc: String
public let deviceInfoEncryptionCertPem: String
public let directoryServerId: String
public let key: String
public let messageVersion: String
}

extension NetceteraConfig: Decodable {
/// Mapping keys to encode/decode JSON string
private enum CodingKeys: String, CodingKey {
case id = "identifier"
case deviceInfoEncryptionAlg = "device_info_encryption_alg"
case deviceInfoEncryptionEnc = "device_info_encryption_enc"
case deviceInfoEncryptionCertPem = "device_info_encryption_cert_pem"
case directoryServerId = "directory_server_id"
case key
case messageVersion = "message_version"
}
}
Loading

0 comments on commit 415cdd5

Please sign in to comment.