Skip to content

Tech

Breaking WPA2

The weaknesses are in the Wi-Fi standard itself, and not in individual products or implementations. Therefore, any correct implementation of WPA2 is likely affected. To prevent the attack, users must update affected products as soon as security updates become available. Note that if your device supports Wi-Fi, it is most likely affected. During our initial research, we discovered ourselves that Android, Linux, Apple, Windows, OpenBSD, MediaTek, Linksys, and others, are all affected by some variant of the attacks.

Read more

Swift on Docker, First Try

First, you need Docker. For Mac user, it is pretty simple to install it (as usual πŸ˜›) — download the dmg file and run it to kick start the installation process.

The one-line command to kick start your docker:

16:13:10 ~/Code/Docker/server docker run -itv $(pwd):/projects --name projects -w /projects -p 8089:8089 -p 8090:8090 -p 5984:5984 twostraws/server-side-swift /bin/bash

 

Basically, it will:

  • create a directory to keep all files related to your server-side projects (e.g. ~/Code/Docker/server)
  • cd into the directory and run above command to create a “projects” folder, bind local port 8090 to docker’s port 8090, 8089 to 8089 etc, and downloads extra resource from twostraws/server-side-swift

Once your docker is setup and up and running:

16:27:26 ~ docker ps
CONTAINER ID        IMAGE                         COMMAND             CREATED             STATUS              PORTS                                                      NAMES
65456a05018e        twostraws/server-side-swift   "/bin/bash"         5 minutes ago       Up 5 minutes        0.0.0.0:5984->5984/tcp, 0.0.0.0:8089-8090->8089-8090/tcp   projects
16:27:27 ~

 

Now, you can continue to create your first Swift server-side project.

Either outside the docker prompt (the virtualized Linux box you have just installed) or your local Mac terminal, create your first project, for example:

18:38:06 ~/Code/Docker/server/hello_world pwd
/Users/choonsiong/Code/Docker/server/hello_world
18:38:07 ~/Code/Docker/server/hello_world

 

Then run following command:

swift package init --type executable

 

Wait for a while, and run this command:

swift build

 

You should have your first “Hello, World!” project built πŸ˜‰ Try following command to see the message display on your console:

.build/debug/hello_world

 

Alright, let’s continue to bring Kitura online! It is going to be quick, so pay attention πŸ™‚

First your Package.swift file like this:

import PackageDescription

let package = Package(
    name: "hello_world",
    dependencies: [
    .Package(url: "https://github.com/IBM-Swift/Kitura.git", majorVersion: 1),
    .Package(url: "https://github.com/IBM-Swift/HeliumLogger.git", majorVersion: 1),
    .Package(url: "https://github.com/IBM-Swift/Kitura-StencilTemplateEngine.git", majorVersion: 1)
    ]
)

 

Run swift build again to download all the dependencies from github. Then edit your main.swift file:

import Kitura

let router = Router()

Kitura.addHTTPServer(onPort: 8090, with: router)
Kitura.run()

 

Build and run again, swift build follow by .build/debug/hello_world

Example:

root@65456a05018e:/projects/hello_world# uname -a
Linux 65456a05018e 4.9.49-moby #1 SMP Wed Sep 27 23:17:17 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
root@65456a05018e:/projects/hello_world# 
root@65456a05018e:/projects/hello_world# swift build
Updating https://github.com/IBM-Swift/Kitura.git
Updating https://github.com/IBM-Swift/HeliumLogger.git
Updating https://github.com/IBM-Swift/Kitura-StencilTemplateEngine.git
Updating https://github.com/IBM-Swift/SwiftyJSON.git
Updating https://github.com/kylef/PathKit.git
Updating https://github.com/kylef/Spectre.git
...
...
...
(skipped)
/projects/hello_world/.build/checkouts/Spectre.git--7655155069707042687/Sources/Expectation.swift:98:57: note: conformance constraint 'Key': 'Equatable' inferred from type here
public func == <Key: Equatable, Value: Equatable> (lhs: Expectation<[Key: Value]>, rhs: [Key: Value]) throws {
                                                        ^
Compile Swift Module 'Socket' (3 sources)
Compile Swift Module 'LoggerAPI' (1 sources)
Compile Swift Module 'KituraTemplateEngine' (1 sources)
Compile CHTTPParser utils.c
Compile CHTTPParser http_parser.c
Compile Swift Module 'Signals' (1 sources)
Compile Swift Module 'PathKit' (1 sources)
Compile Swift Module 'HeliumLogger' (2 sources)
Compile Swift Module 'SSLService' (1 sources)
Compile Swift Module 'Stencil' (19 sources)
Compile Swift Module 'KituraStencil' (1 sources)
Compile Swift Module 'KituraNet' (36 sources)
Compile Swift Module 'Kitura' (44 sources)
Compile Swift Module 'hello_world' (1 sources)
Linking ./.build/x86_64-unknown-linux/debug/hello_world
root@65456a05018e:/projects/hello_world# .build/debug/
CHTTPParser.build/          KituraNet.build/            LoggerAPI.build/            SSLService.build/           Spectre.build/              hello_world                 
HeliumLogger.build/         KituraStencil.build/        ModuleCache/                Signals.build/              Stencil.build/              hello_world.build/          
Kitura.build/               KituraTemplateEngine.build/ PathKit.build/              Socket.build/               SwiftyJSON.build/           
root@65456a05018e:/projects/hello_world# .build/debug/hello_world

 

Let’s try to telnet to localhost 8090,

18:25:12 ~/Code telnet localhost 8090
Trying ::1...
Connected to localhost.
Escape character is '^]'.

and guess what? It is up πŸ™‚

Now, what else? Of course open our browser to see the Welcome page πŸ˜ƒ

Another example of creating the Swift project directory inside docker:

root@65456a05018e:/projects# uptime
 12:28:03 up 2 days, 17:55,  0 users,  load average: 0.00, 0.04, 0.03
root@65456a05018e:/projects# uname -a
Linux 65456a05018e 4.9.49-moby #1 SMP Wed Sep 27 23:17:17 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
root@65456a05018e:/projects# 
root@65456a05018e:/projects# pwd
/projects
root@65456a05018e:/projects# ls -l
total 0
drwxr-xr-x  9 root root 288 Oct 14 11:10 first_page
drwxr-xr-x 10 root root 320 Oct 14 10:23 hello_world
root@65456a05018e:/projects# 
root@65456a05018e:/projects# mkdir million_hairs
root@65456a05018e:/projects# 
root@65456a05018e:/projects# cd million_hairs/
root@65456a05018e:/projects/million_hairs# 
root@65456a05018e:/projects/million_hairs# pwd
/projects/million_hairs
root@65456a05018e:/projects/million_hairs# ls -l
total 0
root@65456a05018e:/projects/million_hairs# 
root@65456a05018e:/projects/million_hairs# swift package init --type executable
Creating executable package: million_hairs
Creating Package.swift
Creating README.md
Creating .gitignore
Creating Sources/
Creating Sources/million_hairs/main.swift
Creating Tests/
root@65456a05018e:/projects/million_hairs# 
root@65456a05018e:/projects/million_hairs# ls -l
total 8
-rw-r--r-- 1 root root 704 Oct 14 12:28 Package.swift
-rw-r--r-- 1 root root  48 Oct 14 12:28 README.md
drwxr-xr-x 3 root root  96 Oct 14 12:28 Sources
drwxr-xr-x 2 root root  64 Oct 14 12:28 Tests
root@65456a05018e:/projects/million_hairs# 
root@65456a05018e:/projects/million_hairs# swift build
Compile Swift Module 'million_hairs' (1 sources)
Linking ./.build/x86_64-unknown-linux/debug/million_hairs
root@65456a05018e:/projects/million_hairs# 
root@65456a05018e:/projects/million_hairs# .build/debug/million_hairs
Hello, world!
root@65456a05018e:/projects/million_hairs# 
root@65456a05018e:/projects/million_hairs#

 

Update Package.swift file to include dependencies for running Kitura, then run swift build:

root@65456a05018e:/projects/million_hairs# ls -l
total 8
-rw-r--r-- 1 root root 361 Oct 14 12:33 Package.swift
-rw-r--r-- 1 root root  48 Oct 14 12:28 README.md
drwxr-xr-x 3 root root  96 Oct 14 12:28 Sources
drwxr-xr-x 2 root root  64 Oct 14 12:28 Tests
root@65456a05018e:/projects/million_hairs# 
root@65456a05018e:/projects/million_hairs# cat Package.swift 
import PackageDescription

let package = Package(
    name: "hello_world",
    dependencies: [
    .Package(url: "https://github.com/IBM-Swift/Kitura.git", majorVersion: 1),
    .Package(url: "https://github.com/IBM-Swift/HeliumLogger.git", majorVersion: 1),
    .Package(url: "https://github.com/IBM-Swift/Kitura-StencilTemplateEngine.git", majorVersion: 1)
    ]
)
root@65456a05018e:/projects/million_hairs# 
root@65456a05018e:/projects/million_hairs#

 

Output from swift build (not that long, really):

root@65456a05018e:/projects/million_hairs# swift build
Fetching https://github.com/IBM-Swift/HeliumLogger.git
Fetching https://github.com/IBM-Swift/Kitura.git
Fetching https://github.com/IBM-Swift/Kitura-StencilTemplateEngine.git
Fetching https://github.com/IBM-Swift/Kitura-net.git
Fetching https://github.com/IBM-Swift/SwiftyJSON.git
Fetching https://github.com/IBM-Swift/Kitura-TemplateEngine.git
Fetching https://github.com/IBM-Swift/LoggerAPI.git
Fetching https://github.com/IBM-Swift/BlueSocket.git
Fetching https://github.com/IBM-Swift/CCurl.git
Fetching https://github.com/IBM-Swift/BlueSSLService.git
Fetching https://github.com/IBM-Swift/CEpoll.git
Fetching https://github.com/IBM-Swift/BlueSignals.git
Fetching https://github.com/IBM-Swift/OpenSSL.git
Fetching https://github.com/kylef/Stencil
Fetching https://github.com/kylef/PathKit.git
Fetching https://github.com/kylef/Spectre.git
Cloning https://github.com/IBM-Swift/BlueSocket.git
Resolving https://github.com/IBM-Swift/BlueSocket.git at 0.12.74
Cloning https://github.com/IBM-Swift/BlueSSLService.git
Resolving https://github.com/IBM-Swift/BlueSSLService.git at 0.12.62
Cloning https://github.com/kylef/PathKit.git
Resolving https://github.com/kylef/PathKit.git at 0.8.0
Cloning https://github.com/IBM-Swift/Kitura.git
Resolving https://github.com/IBM-Swift/Kitura.git at 1.7.9
Cloning https://github.com/IBM-Swift/Kitura-StencilTemplateEngine.git
Resolving https://github.com/IBM-Swift/Kitura-StencilTemplateEngine.git at 1.8.3
Cloning https://github.com/kylef/Spectre.git
Resolving https://github.com/kylef/Spectre.git at 0.7.2
Cloning https://github.com/IBM-Swift/BlueSignals.git
Resolving https://github.com/IBM-Swift/BlueSignals.git at 0.9.50
Cloning https://github.com/IBM-Swift/CEpoll.git
Resolving https://github.com/IBM-Swift/CEpoll.git at 0.1.1
Cloning https://github.com/IBM-Swift/Kitura-net.git
Resolving https://github.com/IBM-Swift/Kitura-net.git at 1.7.17
Cloning https://github.com/IBM-Swift/CCurl.git
Resolving https://github.com/IBM-Swift/CCurl.git at 0.4.1
Cloning https://github.com/IBM-Swift/SwiftyJSON.git
Resolving https://github.com/IBM-Swift/SwiftyJSON.git at 17.0.0
Cloning https://github.com/IBM-Swift/Kitura-TemplateEngine.git
Resolving https://github.com/IBM-Swift/Kitura-TemplateEngine.git at 1.7.2
Cloning https://github.com/IBM-Swift/HeliumLogger.git
Resolving https://github.com/IBM-Swift/HeliumLogger.git at 1.7.1
Cloning https://github.com/kylef/Stencil
Resolving https://github.com/kylef/Stencil at 0.9.0
Cloning https://github.com/IBM-Swift/LoggerAPI.git
Resolving https://github.com/IBM-Swift/LoggerAPI.git at 1.7.1
Cloning https://github.com/IBM-Swift/OpenSSL.git
Resolving https://github.com/IBM-Swift/OpenSSL.git at 0.3.7
Compile CHTTPParser http_parser.c
Compile CHTTPParser utils.c
Compile Swift Module 'SwiftyJSON' (2 sources)
Compile Swift Module 'Spectre' (8 sources)
/projects/million_hairs/.build/checkouts/Spectre.git-2114260410779179812/Sources/Expectation.swift:98:22: warning: redundant conformance constraint 'Key': 'Equatable'
public func == <Key: Equatable, Value: Equatable> (lhs: Expectation<[Key: Value]>, rhs: [Key: Value]) throws {
                     ^
/projects/million_hairs/.build/checkouts/Spectre.git-2114260410779179812/Sources/Expectation.swift:98:57: note: conformance constraint 'Key': 'Equatable' inferred from type here
public func == <Key: Equatable, Value: Equatable> (lhs: Expectation<[Key: Value]>, rhs: [Key: Value]) throws {
                                                        ^
/projects/million_hairs/.build/checkouts/Spectre.git-2114260410779179812/Sources/Expectation.swift:108:22: warning: redundant conformance constraint 'Key': 'Equatable'
public func != <Key: Equatable, Value: Equatable> (lhs: Expectation<[Key: Value]>, rhs: [Key: Value]) throws {
                     ^
/projects/million_hairs/.build/checkouts/Spectre.git-2114260410779179812/Sources/Expectation.swift:108:57: note: conformance constraint 'Key': 'Equatable' inferred from type here
public func != <Key: Equatable, Value: Equatable> (lhs: Expectation<[Key: Value]>, rhs: [Key: Value]) throws {
                                                        ^
/projects/million_hairs/.build/checkouts/Spectre.git-2114260410779179812/Sources/Expectation.swift:98:22: warning: redundant conformance constraint 'Key': 'Equatable'
public func == <Key: Equatable, Value: Equatable> (lhs: Expectation<[Key: Value]>, rhs: [Key: Value]) throws {
                     ^
/projects/million_hairs/.build/checkouts/Spectre.git-2114260410779179812/Sources/Expectation.swift:98:57: note: conformance constraint 'Key': 'Equatable' inferred from type here
public func == <Key: Equatable, Value: Equatable> (lhs: Expectation<[Key: Value]>, rhs: [Key: Value]) throws {
                                                        ^
Compile Swift Module 'KituraTemplateEngine' (1 sources)
Compile Swift Module 'Signals' (1 sources)
Compile Swift Module 'Socket' (3 sources)
Compile Swift Module 'LoggerAPI' (1 sources)
Compile Swift Module 'PathKit' (1 sources)
Compile Swift Module 'HeliumLogger' (2 sources)
Compile Swift Module 'Stencil' (19 sources)
Compile Swift Module 'SSLService' (1 sources)
Compile Swift Module 'KituraStencil' (1 sources)
Compile Swift Module 'KituraNet' (36 sources)
Compile Swift Module 'Kitura' (44 sources)
Compile Swift Module 'million_hairs' (1 sources)
Linking ./.build/x86_64-unknown-linux/debug/million_hairs
root@65456a05018e:/projects/million_hairs#

 

And modify main.swift file and run .build/debug/million_hairs (for example):

root@65456a05018e:/projects/million_hairs# cat Sources/million_hairs/main.swift 
import Kitura
import LoggerAPI
import HeliumLogger

HeliumLogger.use()
let router = Router()

router.all("/") {
  request, response, next in
  response.send("Hello, Kitura!")
  next()
}

router.all("/") {
  request, response, next in
  response.send("Hello, Swift and Kitura!")
  next()
}

Kitura.addHTTPServer(onPort: 8090, with: router)
Kitura.run()root@65456a05018e:/projects/million_hairs# 
root@65456a05018e:/projects/million_hairs#
root@65456a05018e:/projects/million_hairs# .build/debug/million_hairs
[2017-10-14T12:42:13.551Z] [VERBOSE] [Router.swift:74 init(mergeParameters:)] Router initialized
[2017-10-14T12:42:13.572Z] [VERBOSE] [Kitura.swift:77 run()] Starting Kitura framework...
[2017-10-14T12:42:13.572Z] [VERBOSE] [Kitura.swift:87 start()] Starting an HTTP Server on port 8090...
[2017-10-14T12:42:13.591Z] [INFO] [HTTPServer.swift:120 listen(on:)] Listening on port 8090

 

Open your favorite web browser, go to http://localhost:8090 and you will below message display in your browser window:

Alright, have fun.