Coder Social home page Coder Social logo

ae-sakon / rxswiftconnect Goto Github PK

View Code? Open in Web Editor NEW
5.0 2.0 3.0 6.67 MB

RxSwiftConnect, also known as Retrofit for iOS, is a framework that serves as a protection against Man-in-the-Middle Attack (MITM). After years of trials and tests, working with ReactiveX.io and Quicktype.io, RxSwiftConnect was finally born.

License: Apache License 2.0

Ruby 5.38% Swift 93.32% Objective-C 1.29%

rxswiftconnect's Introduction

RxSwiftConnect

RxSwiftConnect, also known as Retrofit for iOS, is a framework that serves as a protection against Man-in-the-Middle Attack (MITM). According to https://us.norton.com/, a man-in-the-middle attack is like eavesdropping. It is an attack where the attacker secretly relays and possibly alters the communications between two parties who believe they are directly communicating with each other (Wikipedia). After years of trials and tests, working with ReactiveX.io and Quicktype.io, RxSwiftConnect was finally born.

Support RxSwift 5

pod 'RxSwiftConnect', '~> 4.0'

Shown below are sample project results;


How to coding and use RxSwiftConnect Framework?
1. Set End Point
let beseUrl = "https://jsonplaceholder.typicode.com"
  1. Set URL API Service
func getOtherUser() -> O<R<OtherUser,E>> {
  return requester.get(path: "posts")
}
  1. Create Model for receive result's data from API Service, uses https://quicktype.io to Auto-Generate Code, as illustrated below.
import Foundation

struct OtherUserElement: Codable {
    let userID, id: Int
    let title, body: String

    enum CodingKeys: String, CodingKey {
        case userID = "userId"
        case id, title, body
    }
}

typealias OtherUser = [OtherUserElement]
  1. Finish and RUN!!
apiOther.getOtherUser()
.observeOn(MainScheduler.instance)
.subscribe(onNext:{ r in

    guard let result = r.value else{
        return self.alertPopup(initMessage: r.error!.errorFriendlyEn!)
    }
    result.forEach {
        print("User ID: \($0.id), User Title: \($0.title)")
    }
},onError:{ e in
    self.alertPopup(initMessage: "Application Error")
}).disposed(by: stepBag)

RxSwiftConnect included Handle error, as illustrated below.

               


Instruction gennerates Model vai Quicktype.io there're two solution, the best solution Model by JSON Schema if your team are developing API Server by C# easy to Generate JSON Schema following link https://blog.quicktype.io/swift-types-from-csharp it help iOS Developer enhancement mirror Model from API Server and avoid error from object null and error from complex JSON Structure, as illustrated below.
1. Copy example JSON Schema from bellow.
{
  "definitions": {
    "BannerInfo": {
      "type": [
        "object",
        "null"
      ],
      "properties": {
        "Image": {
          "type": [
            "string",
            "null"
          ]
        },
        "IdentityType": {
          "type": "integer"
        },
        "BannerType": {
          "type": [
            "string",
            "null"
          ]
        },
        "PopUpText": {
          "type": [
            "string",
            "null"
          ]
        }
      },
      "required": [
        "Image",
        "IdentityType",
        "BannerType",
        "PopUpText"
      ]
    }
  },
  "type": "object",
  "properties": {
    "Result": {
      "type": [
        "array",
        "null"
      ],
      "items": {
        "$ref": "#/definitions/BannerInfo"
      }
    }
  },
  "required": [
    "Result"
  ]
}

2. Paste JSON Schema on https://app.quicktype.io and changed Source type to "JSON Schema".


Or Basic Solution create Model by JSON Data, as illustrated below.
1. Go directly to https://jsonplaceholder.typicode.com/posts .

2. Copy result's response and post on https://app.quicktype.io .

RxSwiftConnect serves as a defense against Man-in-the-Middle Attack (MITM) between API Server and iOS Mobile Application. An installed SSL on API Server doesn't guarantee non- vulnerability of your data and privacy online. Attacker or hacker may be able to track your data on network communication by using Burp, a software provided by PortSwigger. MITM is named as one of the top ten most common types of cyber attacks as highted by OWASP https://www.owasp.org/index.php/Mobile_Top_10_2016-Top_10 . Below are images of the installation and setting- up of RxSwiftConnect.
1. Run mmc on Window Server it will be showed popup below.

2. Choose "Computer Account".

3. Choose "Certificates" and click "OK" button.

4. Looking for correct ceftificated which related with domain API and export SSL from Window Server.

5. Choose export private key.

6. Choose PKCS and also included all certificates.

7. Create password it will be used gennerate .cer on iOS.

8. Names file "input.pfx".

9. Click finish's button.

10. Copy file "input.pfx" and transfer to Mac.

11. Open folder on Mac.

12. Run terminal and write command follow image.

13. It will be seen file "mycerts.crt".

14. Run terminal to export certificate it's be used in XCODE

15. There's a file "certificate.cer".

16. Additional file "certificate.cer" to iOS project.

17. Finish change status "isPreventPinning = true" of RxSwiftConnect to protect MITM and RUN!!
private init() {
        let beseUrl = "https://webstarter.megazy.com"
        requester = Requester(initBaseUrl: beseUrl,timeout: 5, isPreventPinning: true, initSessionConfig: URLSessionConfiguration.default)
    }

Sample code upload UIImage and Video's file

rxswiftconnect's People

Contributors

ae-sakon avatar

Stargazers

 avatar sunn avatar skipp avatar  avatar tleaha avatar

Watchers

tleaha avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.