securityAdded

This commit is contained in:
Dawid Kubicki 2018-11-20 11:29:34 +01:00
parent b6c655cf1c
commit 8c57095046
6 changed files with 58 additions and 14 deletions

View File

@ -7,7 +7,7 @@
<key>Friendvatars.xcscheme_^#shared#^_</key> <key>Friendvatars.xcscheme_^#shared#^_</key>
<dict> <dict>
<key>orderHint</key> <key>orderHint</key>
<integer>2</integer> <integer>3</integer>
</dict> </dict>
</dict> </dict>
</dict> </dict>

View File

@ -1,6 +1,7 @@
import Foundation import Foundation
import CryptoSwift import CryptoSwift
final class AuthController { final class AuthController {
static let serviceName = "FriendvatarsService" static let serviceName = "FriendvatarsService"
@ -18,7 +19,36 @@ final class AuthController {
} }
} }
static func random(length: Int = 20) -> String {
let base = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
var randomString: String = ""
for _ in 0..<length {
let randomValue = arc4random_uniform(UInt32(base.count))
randomString += "\(base[base.index(base.startIndex, offsetBy: Int(randomValue))])"
}
return randomString
}
class func passwordHash(from email: String, password: String) -> String { class func passwordHash(from email: String, password: String) -> String {
func random(length: Int = 20) -> String {
let base = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
var randomString: String = ""
for _ in 0..<length {
let randomValue = arc4random_uniform(UInt32(base.count))
randomString += "\(base[base.index(base.startIndex, offsetBy: Int(randomValue))])"
}
return randomString
}
let randomSalt = random()
print(randomSalt)
let salt = "x4vV8bGgqqmQwgCoyXFQj+(o.nUNQhVP7ND" let salt = "x4vV8bGgqqmQwgCoyXFQj+(o.nUNQhVP7ND"
return "\(password).\(email).\(salt)".sha256() return "\(password).\(email).\(salt)".sha256()
} }

View File

@ -9,6 +9,17 @@
import UIKit import UIKit
import KeychainAccess import KeychainAccess
func randomSecret(length: Int = 10) -> String {
let base = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
var randomString: String = ""
for _ in 0..<length {
let randomValue = arc4random_uniform(UInt32(base.count))
randomString += "\(base[base.index(base.startIndex, offsetBy: Int(randomValue))])"
}
return randomString.sha1()
}
class NoteBiometricViewController: UIViewController { class NoteBiometricViewController: UIViewController {
@IBAction func isSignOut(_ sender: Any) { @IBAction func isSignOut(_ sender: Any) {
@ -31,13 +42,17 @@ class NoteBiometricViewController: UIViewController {
print("Nie ma możliwości użycia biometrycznego uwierzytelniania") print("Nie ma możliwości użycia biometrycznego uwierzytelniania")
} }
} }
let secret = randomSecret()
@IBAction func storeSecret(_ sender: Any) { @IBAction func storeSecret(_ sender: Any) {
DispatchQueue.global().async { DispatchQueue.global().async {
do { do {
try self.keychain try self.keychain
.accessibility(.whenPasscodeSetThisDeviceOnly, authenticationPolicy: .userPresence) .accessibility(.whenPasscodeSetThisDeviceOnly, authenticationPolicy: .userPresence)
.set(self.txtSecret.text!, key: "secret") .set(self.txtSecret.text!, key: self.secret)
} catch let error { } catch let error {
print(error) print(error)
} }
@ -49,7 +64,7 @@ class NoteBiometricViewController: UIViewController {
do { do {
let secret = try self.keychain let secret = try self.keychain
.authenticationPrompt("Zaloguj się biometrycznie, aby zobaczyć notatkę") .authenticationPrompt("Zaloguj się biometrycznie, aby zobaczyć notatkę")
.get("secret") .get(self.secret)
self.lblSecret.text = "Twoja ukryta notatka to: \(secret!)" self.lblSecret.text = "Twoja ukryta notatka to: \(secret!)"
} catch let error { } catch let error {
print(error) print(error)

View File

@ -54,11 +54,11 @@
<action selector="getSecret:" destination="-1" eventType="touchUpInside" id="Ort-po-DdF"/> <action selector="getSecret:" destination="-1" eventType="touchUpInside" id="Ort-po-DdF"/>
</connections> </connections>
</button> </button>
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="NRj-yT-SM7"> <imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" image="TouchID" translatesAutoresizingMaskIntoConstraints="NO" id="NRj-yT-SM7">
<rect key="frame" x="123" y="391" width="128" height="128"/> <rect key="frame" x="123" y="391" width="128" height="128"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/> <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
</imageView> </imageView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="Lbael" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="UoU-LQ-ogi"> <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="UoU-LQ-ogi">
<rect key="frame" x="53" y="323" width="280" height="21"/> <rect key="frame" x="53" y="323" width="280" height="21"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/> <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/> <fontDescription key="fontDescription" type="system" pointSize="17"/>
@ -66,9 +66,12 @@
<nil key="highlightedColor"/> <nil key="highlightedColor"/>
</label> </label>
</subviews> </subviews>
<color key="backgroundColor" cocoaTouchSystemColor="viewFlipsideBackgroundColor"/> <color key="backgroundColor" cocoaTouchSystemColor="groupTableViewBackgroundColor"/>
<viewLayoutGuide key="safeArea" id="fnl-2z-Ty3"/> <viewLayoutGuide key="safeArea" id="fnl-2z-Ty3"/>
<point key="canvasLocation" x="53.600000000000001" y="48.125937031484263"/> <point key="canvasLocation" x="53.600000000000001" y="48.125937031484263"/>
</view> </view>
</objects> </objects>
<resources>
<image name="TouchID" width="512" height="512"/>
</resources>
</document> </document>

View File

@ -8,9 +8,6 @@
<dict> <dict>
<key>isShown</key> <key>isShown</key>
<false/> <false/>
</dict>
<key>CryptoSwift.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key> <key>orderHint</key>
<integer>0</integer> <integer>0</integer>
</dict> </dict>
@ -18,16 +15,15 @@
<dict> <dict>
<key>isShown</key> <key>isShown</key>
<false/> <false/>
<key>orderHint</key>
<integer>1</integer>
</dict> </dict>
<key>Pods-Friendvatars.xcscheme</key> <key>Pods-Friendvatars.xcscheme</key>
<dict> <dict>
<key>isShown</key> <key>isShown</key>
<false/> <false/>
</dict>
<key>Pods-Friendvatars.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key> <key>orderHint</key>
<integer>1</integer> <integer>2</integer>
</dict> </dict>
</dict> </dict>
<key>SuppressBuildableAutocreation</key> <key>SuppressBuildableAutocreation</key>