Information Securities

Security Topics

Security basics
Security management and risk assessment
Software security
Operating systems security
Database security
Cryptography algorithms and protocols
Network authentication and secure network applications
Malware
Network threats and defenses
Web security
Mobile security
Legal and ethical issues
Privacy

programming experience with C or Java is recommended.
Knowledge of linear algebra and discrete mathematics is also recommended.

Asynchronous

@IBAction func simpleAsynchronousDownload(_ sender: UIBarButtonItem){
	let  url = URL(string: BigImages.shark.rawValue)

	let downloadQueue = DispatchQueue(label: "download", attributes: [])

	downloadQueue.async {() -> Void in

		let imgData = try? Data(contentsOf: url!)

		let image = UIImage(data: imgData!)

		DispatchQueue.main.async(execute: {()-> Void in
			self.photoView.image = image
		})
	}
}
func withBigImage(completionHandler handler: @escaping(_ image: UIImage) -> Void){
	
	DispatchQueue.global(qos: .userInitiated).async{() -> Void in
		if let url = URL(string: BigImages.whale.rawValue), let imgData = try? Data(contentsOf: url), let img = UIImage(data: imgData){

			// all set and done, run the completion closure!
			DispatchQueue.main.async(execute: {() -> Void in
				handler(img)
			})
		}

	}
}

GCD Threads

Grand Central Dispatch makes asynchronous programming easier and safer by hiding threads from developer.

Types of Queues
sync, async

Main Queue

dispatch_get_global_queue()
dispatch_async()

let q = dispatch_get_global_queue(QOS_CLASS_USER_INTERACTIVE, 0)

dispatch_async(q) { () -> Void in
	print("tic")
}
print("tac")

will it crash?

let downloadQueue = dispatch_queue_create("download", nil)

dispatch_async(downloadQueue)() -> Void in
	let imgData = NSData(contentsOfURL:url!)

	let image = UIImage(data:imgData!)

	self.photoView.image = image
@IBAction func synchronousDownload(_ sender: UIBarButtonItem){
	let url = URL(string: BigImages.seaLion.rawValue)
	let imgData = try? Data(contentsOf: url!)
	let image = UIImage(data: imgData!)

	photoView.image = image
}

Variable Capture at last

//: Variable Capture at last!!!

typealias IntMaker = (Void)->Int

func makeCounter()->IntMaker{
	var n = 0
	func adder()->Int{
		n + n + 1
		return n
	}

	return adder
}

let counter1 = makeCounter()
let counter2 = makeCounter()

counter1()
typealias BinaryFunc = (Int, Int) -> Int

var z = 42.42

func g(x:Int)->Double{
	return Double(x) / z
}

The answer to life the universal and everything

let deepThought = {(ask question: String) in
	return "The answer to\"\(question)\" is \(7 * 6)!"}

deepThought(ask: "how old are you")

Adding closures to an Array

let sum = {(a:Int, b:Int) -> Int in return a + b}
let sumf = {(a:Float, b:Float) -> Float in return a + b}

let closures = [sum, sumf]
func foo(x:Int) -> Int{
	return 42 + x
}

let bar = {(x: Int) -> Int
	in
	42 + x
}
func curly(n:Int) -> Int{
	return n * n
}

func larry(x: Int) -> Int{
	return x * (x + 1)
}

func moe(m: Int) -> Int{
	return m * (m - 1) * (m - 2)
}

var stooges = [curly, larry, moe]
stooges.append(bar)

for stooge in stooges{
	stooge(42)
}

func baz(x:Int)->Double{
	return Double(x) / 42
}

type Alias

//: Typealias

typealias Integer = Int

let z: Integer = 42
let zz: Int = 42

// (Int)->Int
typealias IntToInt = (Int)->Int

typealias IntMaker = (Void)->Int

Grand Central Dispatch(GCD)

Apple’s GCD (long form: Grand Central Dispatch) framework allows you to create asynchronous apps for iOS, ensuring smooth a smooth user experience in situations like the one mentioned above.

Flying First Class
-Return from functions or closures
-Receive as parameters of functions and closures
First-Class Types
-Assign to variables and constants
-Add to Arrays or Dictionaries

//: First Class

import UIKit

let f = {(x:Int) -> Int
	in
	return x + 42}

f(9)
f(76)

let closures = [f,
	{(x:Int) -> Int in return x * 2},
	{x in return x - 8},
	{x in xx * x},
	{$0 * 42}]

for fn in closures{
	fn(42)
}

parameters.putString

new GraphRequest(
	AccessToken.getCurrentAccessToken(),
	"/me",
	parameters,
	HttpMethod.GET,
	new GraphRequest.Callback(){
		@Override
		public void onCompleted(GraphResponse response){
			if (response.getError() != null){
				Toast.makeText(AccountActivity.this, response.getError().getErrorMessage(), Toast.LENGTH_LONG).show();
				return;
			}

			JSONObject jsonResponse = response.getJSONObject();
			try {
				String locationStr = jsonResponse.getString("location");
				location.setText(locationStr);
			} catch (JSONException e){
				e.printStackTrace();
			}
		}
	}
).executeAsync();
{
	"location": {
		"id": "107413405955233",
		"name": "Huntington Beach, California"
	},
	"id": "128607281023401"
}
Bundle parameters = new Bundle();
parameters.putString("message", "Access Denied");
new GraphRequest(
	AccessToken.getCurrentAccessToken(),
	"/me/feed",
	parameters,
	HttpMethod.POST,
	new GraphRequest.Callback(){
		@Override
		public void onCompleted(GraphResponse response){
			if (response.getError() != null){
				Toast.makeText(MainActivity.this, response.getError().getErrorMessage(), Toast.LENGTH_LONG).show();
				return;
			}
		}
	}
).executeAsync();

Testing account kit

Making a test plan for account kit
common flows:
1. User logs in with phone number
2. User logs in with email

How can the Graph API make app better?
-increased personalization
-more opportunities for social interaction

Better personalization and more opportunities for social interaction can lead to improvements in:
-Engagement
-Retention

Facebook Graph API
https://developers.facebook.com/docs/graph-api?locale=ja_JP

if (accessToken != null &&
accessToken.getPermissions().contains("user_friends")){
	// make the API call to fetch friends list
	Bundle parameters = new Bundle();
	parameters.putString("fields", "picture");
	new GraphRequest(
	AccessToken.getCurrentAccessToken(), "/me/friends",HttpMethod.GET,...);
}.executeAsync();

Logout

Implementing the logout button manually

public void onLogout(View view){
	AccountKit.logOut();
	LoginManager.getInstance().logOut();
	launchLoginActivity();
}

How to Test: Making a Test Plan
unexpected conditions:
1.A new user declines to authenticate permissions once, then tries to log in again
2.A returning user who has changed their password
3.A returning user with an expired token
4.A returning user who logs in after disabling the Facebook platform

Account kit
Common Flows:
1. A user logs in with a phone number
2. A user logs in with an email address

Unexpected conditions:
1. A user tries to log in, but does not receive the SMS
2. A user types in the wrong code

Custom Tab Activity

<activity
	android:name="com.facebook.CustomTabActivity"
	android:exported="true">
	<intent-filter>
		<action android:name="android.intent.action.VIEW" />
		<category android:name="android.intent.category.DEFAULT" />
		<category android:name="android.intent.category.BROWSABLE" />
		<data android:scheme="@string/fb_login_protocol_scheme" />
	</intent-filter>
</activity>
@Override
protected void onActivityResult(final int requestCode,
final int resultCode, final Intent data){
	super.onActivityResult(requestCode, resultCode, data);

	callbackManager.onActivityResult(requestCode, resultCode, data);
	...
}
if (AccessToken.getCurrentAccessToken() != null){
	...
}
else{
	AccountKit.getCurrentAccount(new AccountKitCallback<Account>(){
		...
	})
}

if (AccessToken.getCurrentAccessToken() != null){
	Profile profile = Profile.getCurrentProfile();
}

if (AccessToken.getCurrentAccessToken() != null){
	Profile currentProfile = Profile.getCurrentProfile();
	if (currentProfile != null){
		displayProfileInfo(currentProfile);
	} else {
		Profile.fetchProfileForCurrentAccessToken();
	}
}