Skip to content

Commit

Permalink
Keychain Browser (#19)
Browse files Browse the repository at this point in the history
* Keychain Browser

* Update from kSecClassInternetPassword

* Fix view borders bug

* Read password function

* no message

* no message

* no message

* no message

* Improve Password unwrapping

* Improve Password decoding

* Test new implementation

* no message

* no message

* no message

* MOck data

* More mock

* Test mock

* Make build

* no message

* no message

* no message

* Stash

* Revise keychain implementation

* no message

* no message

* no message

* no message

* no message

* Fix toggle bug

* no message

* no message

* no message

* no message

* no message
  • Loading branch information
bstillitano authored Sep 20, 2021
1 parent 7b4676a commit bfc7139
Show file tree
Hide file tree
Showing 16 changed files with 682 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
CA9F8FCF25DE0B5F000FA677 /* BlueViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CA9F8FCE25DE0B5F000FA677 /* BlueViewController.swift */; };
CA9F8FD425DE0EFF000FA677 /* Button.swift in Sources */ = {isa = PBXBuildFile; fileRef = CA9F8FD325DE0EFF000FA677 /* Button.swift */; };
CA9F8FD925DE0F6D000FA677 /* ButtonPreviews.swift in Sources */ = {isa = PBXBuildFile; fileRef = CA9F8FD825DE0F6D000FA677 /* ButtonPreviews.swift */; };
CABAC83926F7542000BA8CFD /* Keychain.swift in Sources */ = {isa = PBXBuildFile; fileRef = CABAC83826F7542000BA8CFD /* Keychain.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -62,6 +63,7 @@
CA9F8FD825DE0F6D000FA677 /* ButtonPreviews.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ButtonPreviews.swift; sourceTree = "<group>"; };
CA9F908025DFEA66000FA677 /* Scyther Playground.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = "Scyther Playground.entitlements"; sourceTree = "<group>"; };
CAB7FAE225E3C9B300B5C7CA /* Scyther Playground-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Scyther Playground-Bridging-Header.h"; sourceTree = "<group>"; };
CABAC83826F7542000BA8CFD /* Keychain.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Keychain.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -121,6 +123,7 @@
CA9F8FCE25DE0B5F000FA677 /* BlueViewController.swift */,
CA9F8FD325DE0EFF000FA677 /* Button.swift */,
CA9F8FD825DE0F6D000FA677 /* ButtonPreviews.swift */,
CABAC83826F7542000BA8CFD /* Keychain.swift */,
CA9F8FC125DE08E5000FA677 /* Environments.swift */,
CA73FCED25D690D2007FA627 /* Main.storyboard */,
CA73FCF025D690D2007FA627 /* Assets.xcassets */,
Expand Down Expand Up @@ -291,6 +294,7 @@
CA9F8FC725DE0A88000FA677 /* RedViewController.swift in Sources */,
CA73FCEC25D690D2007FA627 /* ViewController.swift in Sources */,
CA9F8FC225DE08E5000FA677 /* Environments.swift in Sources */,
CABAC83926F7542000BA8CFD /* Keychain.swift in Sources */,
CA73FCE825D690D2007FA627 /* AppDelegate.swift in Sources */,
CA9F8FCF25DE0B5F000FA677 /* BlueViewController.swift in Sources */,
CA73FCEA25D690D2007FA627 /* SceneDelegate.swift in Sources */,
Expand Down Expand Up @@ -635,7 +639,7 @@
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/bstillitano/Scyther.git";
requirement = {
branch = "bugfix/view-frames-on-load";
branch = "feature/keychain-browser";
kind = branch;
};
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"package": "Scyther",
"repositoryURL": "https://github.com/bstillitano/Scyther.git",
"state": {
"branch": "bugfix/view-frames-on-load",
"revision": "b6735940ae82ddca29930a4dbcc1f8fff8d32199",
"branch": "feature/keychain-browser",
"revision": "cd430860b96cb7f0e3efb7f648462a830408a32c",
"version": null
}
},
Expand Down
8 changes: 8 additions & 0 deletions Scyther Playground/Scyther Playground/Keychain.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//
// Keychain.swift
// Scyther Playground
//
// Created by Brandon Stillitano on 19/9/21.
//

import Foundation
135 changes: 93 additions & 42 deletions Scyther Playground/Scyther Playground/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// Created by Brandon Stillitano on 12/2/21.
//

import Security
import Scyther
import UIKit

Expand All @@ -19,48 +20,6 @@ class ViewController: UIViewController {
//Setup Interface
setupUI()
setupConstraints()

//Setup Data
if let cookie = HTTPCookie(properties: [
.domain: ".test.scyther.com",
.path: "/",
.name: "ScytherCookie",
.value: "K324klj23KLJKH223423CookieValueDSFLJ234",
.secure: "FALSE",
.discard: "TRUE"
]) {
HTTPCookieStorage.shared.setCookie(cookie)
}
if let cookie = HTTPCookie(properties: [
.domain: ".test.scyther.com",
.path: "/",
.name: "ScytherCookie2",
.value: "K324klj23KLJKH223423CookieValueDSFLJ234",
.secure: "FALSE",
.discard: "TRUE"
]) {
HTTPCookieStorage.shared.setCookie(cookie)
}
if let cookie = HTTPCookie(properties: [
.domain: ".test.scyther.com",
.path: "/",
.name: "ScytherCookie3",
.value: "K324klj23KLJKH223423CookieValueDSFLJ234",
.secure: "FALSE",
.discard: "TRUE"
]) {
HTTPCookieStorage.shared.setCookie(cookie)
}
if let cookie = HTTPCookie(properties: [
.domain: ".test.scyther.com",
.path: "/",
.name: "ScytherCookie4",
.value: "K324klj23KLJKH223423CookieValueDSFLJ234",
.secure: "FALSE",
.discard: "TRUE"
]) {
HTTPCookieStorage.shared.setCookie(cookie)
}
setupData()
}

Expand Down Expand Up @@ -112,11 +71,103 @@ extension ViewController: UITableViewDataSource {

extension ViewController {
func setupData() {
setupCookies()
setupKeychain()
setupFlags()
setupEnvironments()
setupDeveloperTools()
}

func setupCookies() {
if let cookie = HTTPCookie(properties: [
.domain: ".test.scyther.com",
.path: "/",
.name: "ScytherCookie",
.value: "K324klj23KLJKH223423CookieValueDSFLJ234",
.secure: "FALSE",
.discard: "TRUE"
]) {
HTTPCookieStorage.shared.setCookie(cookie)
}
if let cookie = HTTPCookie(properties: [
.domain: ".test.scyther.com",
.path: "/",
.name: "ScytherCookie2",
.value: "K324klj23KLJKH223423CookieValueDSFLJ234",
.secure: "FALSE",
.discard: "TRUE"
]) {
HTTPCookieStorage.shared.setCookie(cookie)
}
if let cookie = HTTPCookie(properties: [
.domain: ".test.scyther.com",
.path: "/",
.name: "ScytherCookie3",
.value: "K324klj23KLJKH223423CookieValueDSFLJ234",
.secure: "FALSE",
.discard: "TRUE"
]) {
HTTPCookieStorage.shared.setCookie(cookie)
}
if let cookie = HTTPCookie(properties: [
.domain: ".test.scyther.com",
.path: "/",
.name: "ScytherCookie4",
.value: "K324klj23KLJKH223423CookieValueDSFLJ234",
.secure: "FALSE",
.discard: "TRUE"
]) {
HTTPCookieStorage.shared.setCookie(cookie)
}
}

func setupKeychain() {
//Clear Existing Keychain Items
let secItemClasses = [
kSecClassGenericPassword,
kSecClassInternetPassword,
kSecClassCertificate,
kSecClassKey,
kSecClassIdentity
]
for secItemClass in secItemClasses {
let dictionary = [kSecClass as String: secItemClass]
SecItemDelete(dictionary as CFDictionary)
}

//Setup Generic Keychain
for i in 0...12 {
let username = "john"
let password = "69420".data(using: .utf8)!
let attributes: [String: Any] = [
kSecClass as String: kSecClassGenericPassword,
kSecAttrAccount as String: "\(username)+\(i)",
kSecValueData as String: password
]
if SecItemAdd(attributes as CFDictionary, nil) == noErr {
print("User saved successfully in the keychain")
} else {
print("Something went wrong trying to save the user in the keychain")
}
}

//Setup Internet Keychain
for i in 0...12 {
let username = "internet-boi"
let password = "1337-h4x0r".data(using: .utf8)!
let attributes: [String: Any] = [
kSecClass as String: kSecClassInternetPassword,
kSecAttrAccount as String: "\(username)+\(i)",
kSecValueData as String: password
]
if SecItemAdd(attributes as CFDictionary, nil) == noErr {
print("User saved successfully in the keychain")
} else {
print("Something went wrong trying to save the user in the keychain")
}
}
}

func setupFlags() {
var flags: [String: Bool] = [:]
flags["logging"] = true
Expand Down
25 changes: 25 additions & 0 deletions Sources/Scyther/Extensions/NSDictionary+Extensions.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// File.swift
//
//
// Created by Brandon Stillitano on 20/9/21.
//

import Foundation

extension NSDictionary {
var swiftDictionary: Dictionary<String, Any> {
var swiftDictionary = Dictionary<String, Any>()

for key: Any in self.allKeys {
guard let stringKey = key as? String else {
continue
}
if let keyValue = self.value(forKey: stringKey) {
swiftDictionary[stringKey] = keyValue
}
}

return swiftDictionary
}
}
Loading

0 comments on commit bfc7139

Please sign in to comment.