Skip to content

Commit

Permalink
Clutch: Initial public release.
Browse files Browse the repository at this point in the history
  • Loading branch information
Juha Salo committed Aug 25, 2015
0 parents commit d6746c6
Show file tree
Hide file tree
Showing 97 changed files with 8,216 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.pbxproj binary merge=union
43 changes: 43 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Xcode
#
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore

## Build generated
build/
DerivedData

## Various settings
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata

## Other
*.xccheckout
*.moved-aside
*.xcuserstate
*.xcscmblueprint

## Obj-C/Swift specific
*.hmap
*.ipa

# CocoaPods
#
# We recommend against adding the Pods directory to your .gitignore. However
# you should judge for yourself, the pros and cons are mentioned at:
# http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control
#
# Pods/

# Carthage
#
# Add this line if you want to avoid checking in source code from Carthage dependencies.
Carthage/Checkouts

Carthage/Build
Empty file added .gitmodules
Empty file.
3 changes: 3 additions & 0 deletions Cartfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
github "Alamofire/Alamofire" >= 1.2
github "SwiftyJSON/SwiftyJSON" >= 2.2.1
github "pyrtsa/CryptoSwift" "device-tests"
2 changes: 2 additions & 0 deletions Cartfile.private
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
github "Quick/Quick" "6c7b90f27c46e2317f56c86a8d82e5881e4015b0" # master branch
github "Quick/Nimble" "b89db8654c5f134d4f68e706b6da4a5581cb2001" # master branch
5 changes: 5 additions & 0 deletions Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
github "Alamofire/Alamofire" "1.3.1"
github "pyrtsa/CryptoSwift" "e28bd0961a4448d3c071b91a029736d5d60deec9"
github "Quick/Nimble" "b89db8654c5f134d4f68e706b6da4a5581cb2001"
github "Quick/Quick" "6c7b90f27c46e2317f56c86a8d82e5881e4015b0"
github "SwiftyJSON/SwiftyJSON" "2.2.1"
24 changes: 24 additions & 0 deletions Clutch.podspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Pod::Spec.new do |s|

s.name = "Clutch"
s.version = "0.1" # TODO change
s.summary = "Solinor Payment Highway framework for iOS."
s.description = <<-DESC
Solinor Payment Highway framework for iOS.
DESC
s.homepage = "https://paymenthighway.fi"
s.license = { :type => "MIT", :file => "LICENSE" }
s.author = { "Juha Salo" => "[email protected]" }
s.platform = :ios, "8.0"
s.source = { :git => "https://github.com/solinor/paymenthighway-ios-sdk.git", :tag => "pod-proto" } # TODO change tag
s.requires_arc = true

s.resources = ["Clutch/*.{storyboard,lproj,xcassets,png}", "Clutch/IQKeybordManagerSwift/Resources/IQKeyboardManager.bundle/*.png"]
s.source_files = "Clutch", "Clutch/**/*.{h,swift}"
s.frameworks = "Foundation", "UIKit"

s.dependency "Alamofire", "~> 1.2.0"
s.dependency "SwiftyJSON", "~> 2.2.0"
s.dependency "CryptoSwift"

end
1,332 changes: 1,332 additions & 0 deletions Clutch.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions Clutch.xcodeproj/project.xcworkspace/contents.xcworkspacedata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

110 changes: 110 additions & 0 deletions Clutch.xcodeproj/xcshareddata/xcschemes/Clutch.xcscheme
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0630"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "03788D441AC978DD007FC30F"
BuildableName = "Clutch.framework"
BlueprintName = "Clutch"
ReferencedContainer = "container:Clutch.xcodeproj">
</BuildableReference>
</BuildActionEntry>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "NO"
buildForProfiling = "NO"
buildForArchiving = "NO"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "03788D4F1AC978DD007FC30F"
BuildableName = "ClutchTests.xctest"
BlueprintName = "ClutchTests"
ReferencedContainer = "container:Clutch.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
buildConfiguration = "Debug">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "03788D4F1AC978DD007FC30F"
BuildableName = "ClutchTests.xctest"
BlueprintName = "ClutchTests"
ReferencedContainer = "container:Clutch.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "03788D441AC978DD007FC30F"
BuildableName = "Clutch.framework"
BlueprintName = "Clutch"
ReferencedContainer = "container:Clutch.xcodeproj">
</BuildableReference>
</MacroExpansion>
</TestAction>
<LaunchAction
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
buildConfiguration = "Debug"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
allowLocationSimulation = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "03788D441AC978DD007FC30F"
BuildableName = "Clutch.framework"
BlueprintName = "Clutch"
ReferencedContainer = "container:Clutch.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
buildConfiguration = "Release"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "03788D441AC978DD007FC30F"
BuildableName = "Clutch.framework"
BlueprintName = "Clutch"
ReferencedContainer = "container:Clutch.xcodeproj">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
16 changes: 16 additions & 0 deletions Clutch/Base.lproj/Localizable.strings
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/* The text shown on the 'add card' button */
"AddCardButtonTitle" = "Add card";

/* The text shown above the expiry date field */
"CreditCardExpiryDate" = "Expiry date";

/* The text shown above the credit card number field */
"CreditCardNumber" = "Card number";

/* The text shown above the security code field */
"CreditCardSecurityCode" = "Security code";

/* The initial value for add card form status label */
"FillOutFormBelow" = "Fill out the form";

"MM/YY" = "MM/YY";
17 changes: 17 additions & 0 deletions Clutch/Clutch.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// Clutch.h
// Clutch
//
// Created by Nico Hämäläinen on 30/03/15.
// Copyright (c) 2015 Solinor Oy. All rights reserved.
//

#import <UIKit/UIKit.h>

//! Project version number for Clutch.
FOUNDATION_EXPORT double ClutchVersionNumber;

//! Project version string for Clutch.
FOUNDATION_EXPORT const unsigned char ClutchVersionString[];

// In this header, you should import all the public headers of your framework using statements like #import <Clutch/PublicHeader.h>
83 changes: 83 additions & 0 deletions Clutch/Crypto.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
//
// Crypto.swift
//
// Created by ZERO on 14/10/25.
// Copyright (c) 2014年 ZERO. All rights reserved.
//

import Foundation
import UIKit
import CryptoSwift

public func getRequestId() -> String {
return NSUUID().UUIDString.lowercaseString
}

/// Returns Optional SecKeyRef from given certificate in DER-format.
///
/// :param: DER-formatted certificate
/// :returns: SecKeyRef or Nil.
private func loadDER(publicKeyFileContent: NSData) -> SecKeyRef? {
let certificate = SecCertificateCreateWithData(kCFAllocatorDefault, publicKeyFileContent as CFData).takeUnretainedValue()
let policy = SecPolicyCreateBasicX509().takeUnretainedValue();
var unmanagedTrust : Unmanaged<SecTrust>? = nil
let status = SecTrustCreateWithCertificates(certificate, policy, &unmanagedTrust)
if (status != 0) {
println("SecTrustCreateWithCertificates fail. Error Code: \(status)");
return nil
}
let trust = unmanagedTrust!.takeUnretainedValue()
let evaluateStatus = SecTrustEvaluate(trust, nil)
if (evaluateStatus != 0) {
println("SecTrustEvaluate fail. Error Code: \(evaluateStatus)");
return nil
}
return SecTrustCopyPublicKey(trust).takeUnretainedValue();
}

private func encryptWithData(content :NSData, publicKey :SecKeyRef) -> NSData? {

let blockSize = Int(SecKeyGetBlockSize(publicKey) - 11)
var encryptedData = NSMutableData()
let blockCount = Int(ceil(Double(content.length) / Double(blockSize)))

for i in 0..<blockCount {
var cipherLen = SecKeyGetBlockSize(publicKey)
var cipher = [UInt8](count: Int(cipherLen), repeatedValue: 0)
let bufferSize = min(blockSize,(content.length - i * blockSize))
var buffer = content.subdataWithRange(NSMakeRange(i*blockSize, bufferSize))
let status = SecKeyEncrypt(publicKey, SecPadding(kSecPaddingOAEP), UnsafePointer<UInt8>(buffer.bytes), buffer.length, &cipher, &cipherLen)
if (status == noErr){
encryptedData.appendBytes(cipher, length: Int(cipherLen))
}else{
println("SecKeyEncrypt fail. Error Code: \(status)")
return nil
}
}
return encryptedData
}

public func encryptWithRsaAes(data: String, certificateBase64Der: String) -> (encryptedBase64Message: String, encryptedBase64Key: String, iv: String)?
{
let keyAes = Cipher.randomIV(AES.blockSize)
let iv = Cipher.randomIV(AES.blockSize)

if let encryptedData = CryptoSwift.AES(key: keyAes, iv: iv, blockMode: CryptoSwift.CipherBlockMode.CBC)?.encrypt([UInt8](data.utf8), padding: PKCS7())
{
if let publicKey = loadDER(NSData(base64EncodedString: certificateBase64Der, options: .allZeros)!)
{
if let encryptedKey = encryptWithData(NSData(bytes: keyAes, length: keyAes.count), publicKey)
{
let encryptedBase64Message = NSData(bytes: encryptedData, length: encryptedData.count).base64EncodedStringWithOptions(.allZeros)

let encryptedBase64Key = encryptedKey.base64EncodedStringWithOptions(.allZeros)

let base64Iv = NSData(bytes: iv, length: iv.count).base64EncodedStringWithOptions(.allZeros)

return (encryptedBase64Message, encryptedBase64Key, base64Iv)
}
}
}
return nil
}

22 changes: 22 additions & 0 deletions Clutch/DefaultTheme.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CloseButtonBackgroundColor</key>
<string>0x8ba7cf</string>
<key>CloseButtonShadowColor</key>
<string>0x0873c0</string>
<key>FormLabelTextColor</key>
<string>0x1d4e9b</string>
<key>FormInputBorderColor</key>
<string>0x1d4e9b</string>
<key>FormInputIconColor</key>
<string>0x1d4e9b</string>
<key>FormBackgroundColor</key>
<string>0xeef7fd</string>
<key>FormButtonBackgroundColor</key>
<string>0x47a3e3</string>
<key>FormButtonShadowColor</key>
<string>0x0873c0</string>
</dict>
</plist>
Loading

0 comments on commit d6746c6

Please sign in to comment.