Skip to content

Commit fe46b5e

Browse files
committed
npm publish
0 parents  commit fe46b5e

32 files changed

+7239
-0
lines changed

.npmignore

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
demo/
2+
.idea/
3+
support/
4+
*.tar
5+
*.tgz
6+
.npmignore
7+
*.map
8+
*.ts
9+
tsconfig.json
10+
scripts
11+
.DS_Store
12+
*.aar
13+
node_modules
14+
*.esm.json
15+
!extractTGZ.js
16+
*.js.map
17+
*.log
18+
19+
# Editor directories and files
20+
.idea
21+
.vscode

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# nativescript-yoonit-handshakeA NativeScript NPM implementing dynamic SSL pinning for Android and iOS.* [About](#about)* [Installation](#installation)* [Usage](#usage)* [API](#api) * [Method](#method) * [Event](#event) * [Handshake Result](#handshake-result)* [To contribute and make it better](#to-contribute-and-make-it-better)## AboutThe SSL pinning is a technique mitigating man-in-the-middle attacks against the secure HTTP communication, but has a drawback, the certificate's expiration date. This resolve this problem, implementing dynamic SSL pinning, providing easy to use fingerprint validation on the TLS handshake. The remote server must be the responsible to update the certificate(s).## Installation```npm i -s @yoonit/nativescript-handshake ```> ### Special thanks and credits...> The current version of the library depends on `[Wultra SSL Pinning]` ([Android]((https://github.com/wultra/ssl-pinning-android) and [iOS]((https://github.com/wultra/ssl-pinning-ios)))).## Usage```javascriptfunction updateFingerprint() { this.$yoo.handshake.updateFingerprints( "YOUR PUBLIC KEY", "YOUR SERVICE URL", (result) => { switch (result) { case HandshakeResult.OK: // - Everything is OK; // - No Action is required; return; case HandshakeResult.STORE_IS_EMPTY: // - The update request succeeded; // - Result is still an empty list of certificates; // - May loading & validating of remote data succeeded; // - All loaded certificates are already expired;" return; case HandshakeResult.NETWORK_ERROR: // - The update request failed on a network communication. return; case HandshakeResult.INVALID_DATA: // The update request returned the data which did not pass the signature validation. return; case HandshakeResult.INVALID_SIGNATURE: // The update request returned the data which did not pass the signature validation. return; case HandshakeResult.INVALID_URL_SERVICE: // The url service does not exist or is invalid. return; } } );}```## API### Method| Function | Parameters | Description| - | - | -| updateFingerprint | `publicKey: string, serviceUrl: string, callback: (result: string) => void` | Update the list of fingerprints from the remote server. The method is asynchronous. Response can get in the callback.### Handshake Result| HandshakeResult | Description| - | -| `"OK"` | <ul><li>Everything is OK;</li><li>No Action is required;</li></ul>| `STORE_IS_EMPTY"` | <ul><li>The update request succeeded;</li><li>Result is still an empty list of certificates;</li><li>May loading & validating of remote data succeeded;</li><li>All loaded certificates are already expired;</li><li>All loaded certificates are already expired;</li></ul>| `"NETWORK_ERROR"` | The update request failed on a network communication.| `"INVALID_DATA"` | The update request returned the data which did not pass the signature validation.| `"INVALID_SIGNATURE"` | The update request returned the data which did not pass the signature validation.| `"INVALID_URL_SERVICE"` | The url service does not exist or is invalid.## To contribute and make it betterClone the repo, change what you want and send PR.For commit messages we use <a href="https://www.conventionalcommits.org/">Conventional Commits</a>.Contributions are always welcome!<a href="https://github.com/Yoonit-Labs/ios-yoonit-handshake/graphs/contributors"> <img src="https://contrib.rocks/image?repo=Yoonit-Labs/ios-yoonit-handshake" /></a>---Code with ❤ by the [**Cyberlabs AI**](https://cyberlabs.ai/) Front-End Team

Result.d.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
declare const Result: {
2+
OK: string;
3+
STORE_IS_EMPTY: string;
4+
NETWORK_ERROR: string;
5+
INVALID_DATA: string;
6+
INVALID_SIGNATURE: string;
7+
INVALID_URL_SERVICE: string;
8+
};
9+
export default Result;

Result.js

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Result.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Result.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// +-+-+-+-+-+-+// |y|o|o|n|i|t|// +-+-+-+-+-+-+//// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+// | Yoonit Handshake Plugin for NativeScript applications |// | Luigui Delyer, Gabriel Rizzo, |// | Haroldo Teruya & Victor Goulart @ Cyberlabs AI 2020-2021 |// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+const Result = { OK: "OK", STORE_IS_EMPTY: "STORE_IS_EMPTY", NETWORK_ERROR: "NETWORK_ERROR", INVALID_DATA: "INVALID_DATA", INVALID_SIGNATURE: "INVALID_SIGNATURE", INVALID_URL_SERVICE: "INVALID_URL_SERVICE",};export default Result;

Yoonit.Handshake.android.d.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { HandshakeBase } from "./Yoonit.Handshake.common";
2+
export declare class YoonitHandshake extends HandshakeBase {
3+
native: com.yoonit.handshake.Handshake;
4+
handshakeListener: HandshakeEventListener;
5+
constructor();
6+
updateFingerprints(publicKey: string, serviceUrl: string, callback: (result: string) => void): void;
7+
}
8+
declare class HandshakeEventListener extends java.lang.Object implements com.yoonit.handshake.HandshakeListener {
9+
private owner;
10+
resultCallback: (result: string) => void;
11+
static initWithOwner(owner: WeakRef<YoonitHandshake>): HandshakeEventListener;
12+
continueExecution(): void;
13+
handleFailedUpdate(type: string, result: string): void;
14+
}
15+
export {};

Yoonit.Handshake.android.js

Lines changed: 66 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Yoonit.Handshake.android.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Yoonit.Handshake.android.ts

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
// +-+-+-+-+-+-+
2+
// |y|o|o|n|i|t|
3+
// +-+-+-+-+-+-+
4+
//
5+
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
6+
// | Yoonit Handshake Plugin for NativeScript applications |
7+
// | Luigui Delyer, Gabriel Rizzo, |
8+
// | Haroldo Teruya & Victor Goulart @ Cyberlabs AI 2020-2021 |
9+
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
10+
11+
import * as application from "@nativescript/core/application";
12+
import { HandshakeBase } from "./Yoonit.Handshake.common";
13+
import Result from './Result';
14+
15+
export class YoonitHandshake extends HandshakeBase {
16+
17+
native: com.yoonit.handshake.Handshake;
18+
handshakeListener: HandshakeEventListener;
19+
20+
constructor() {
21+
super();
22+
23+
application.on(application.launchEvent, () => {
24+
let context = application.android.context;
25+
this.handshakeListener = HandshakeEventListener.initWithOwner(new WeakRef(this));
26+
this.native = new com.yoonit.handshake.Handshake(context, this.handshakeListener);
27+
});
28+
}
29+
30+
public updateFingerprints(
31+
publicKey: string,
32+
serviceUrl: string,
33+
callback: (result: string) => void
34+
): void {
35+
this.handshakeListener.resultCallback = callback
36+
this.native.updateFingerprint(publicKey, serviceUrl);
37+
}
38+
}
39+
40+
@Interfaces([com.yoonit.handshake.HandshakeListener])
41+
@NativeClass
42+
class HandshakeEventListener extends java.lang.Object implements com.yoonit.handshake.HandshakeListener {
43+
44+
private owner: WeakRef<YoonitHandshake>;
45+
public resultCallback: (result: string) => void;
46+
47+
public static initWithOwner(owner: WeakRef<YoonitHandshake>): HandshakeEventListener {
48+
const listener = new HandshakeEventListener as HandshakeEventListener;
49+
listener.owner = owner;
50+
51+
return listener;
52+
}
53+
54+
public continueExecution(): void {
55+
if (!this.resultCallback || !this.owner.get()) {
56+
return;
57+
}
58+
59+
this.resultCallback(Result.OK)
60+
}
61+
62+
public handleFailedUpdate(type: string, result: string): void {
63+
if (!this.resultCallback || !this.owner.get()) {
64+
return;
65+
}
66+
67+
switch (result) {
68+
case Result.OK:
69+
this.resultCallback(Result.OK);
70+
return;
71+
72+
case Result.STORE_IS_EMPTY:
73+
this.resultCallback(Result.STORE_IS_EMPTY);
74+
return;
75+
76+
case Result.NETWORK_ERROR:
77+
this.resultCallback(Result.NETWORK_ERROR);
78+
return;
79+
80+
case Result.INVALID_DATA:
81+
this.resultCallback(Result.INVALID_DATA);
82+
return;
83+
84+
case Result.INVALID_SIGNATURE:
85+
this.resultCallback(Result.INVALID_SIGNATURE);
86+
return;
87+
88+
case Result.INVALID_URL_SERVICE:
89+
this.resultCallback(Result.INVALID_URL_SERVICE);
90+
return;
91+
}
92+
}
93+
}

0 commit comments

Comments
 (0)