Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Combined updates with iOS & Android support #1

Open
wants to merge 60 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
14e97d6
Initial commit
johannes-staehlin Sep 11, 2015
35037c2
Initial commit
johannes-staehlin-sap Sep 11, 2015
4d9c8e0
Update plugin.xml
johannes-staehlin Sep 11, 2015
9dca963
inline return
magruschinske Oct 6, 2015
dd32dc7
Merge pull request #1 from magruschinske/patch-1
johannes-staehlin Oct 6, 2015
cf49429
Update README.md
volkrass Feb 25, 2016
dd22af0
package.json added for npm upload
stefanjauker Mar 1, 2016
91afdf3
Merge branch 'master' of github.com:mwaylabs/cordova-plugin-client-ce…
stefanjauker Mar 1, 2016
728c695
add ssl / tls chain validation
stefanjauker Mar 4, 2016
156be2b
Update README.md
johannes-staehlin Jun 18, 2016
d0a2967
Update README.md
johannes-staehlin Jun 18, 2016
4836477
Update README.md
johannes-staehlin Jul 17, 2016
bab8b8e
Update ClientCertificate.m
peterprice Aug 25, 2016
1a7eb9e
Update README.md
peterprice Aug 25, 2016
3d8d7eb
Enable persistent identity storage in keychain.
peterprice Aug 25, 2016
48d65b3
Set self as delegate on init.
peterprice Aug 26, 2016
667a326
Delete identity from keychain before adding.
peterprice Aug 26, 2016
f20f6bb
Check for NULLs
peterprice Aug 26, 2016
5043412
Update readme
ohetzendorfer Sep 1, 2016
bbeb114
Merge pull request #5 from omastny/master
stefanjauker Sep 1, 2016
ed0f495
Add typings.
peterprice Sep 14, 2016
a345fad
Update README.md
stefanjauker Sep 15, 2016
3b8ed9f
Merge pull request #6 from binderhq/master
stefanjauker Sep 15, 2016
bf4acd5
support user selected cancel on certification selection dialog.
Dec 1, 2016
34f258a
Merge pull request #3 from hroeck/master
johannes-staehlin Dec 1, 2016
44f2da7
Increase Version
johannes-staehlin Dec 1, 2016
780ab14
Set theme jekyll-theme-hacker
EbilPanda Mar 31, 2017
fd7ed1d
changed android to use system keystore
Mar 31, 2017
79e1f25
fix package
Mar 31, 2017
36c8fbf
added git ignore
Mar 31, 2017
47fcb4c
.DS_Store banished!
Mar 31, 2017
856c460
fixed typos in android
Mar 31, 2017
470d91b
removed unused variables
Mar 31, 2017
bf05d4c
added handler for myp12 files
Mar 31, 2017
0165c23
updated plugin.xml and OpenCertFile
Mar 31, 2017
d3556c3
fixed version number
Mar 31, 2017
cc500de
upped version number
Mar 31, 2017
4173fe0
Update README.md
johannes-staehlin Jan 15, 2019
622b44f
Good OpenCertFile feature in plugin.xml
Jan 23, 2019
c4ccb6e
Some general documentation updates
Jan 24, 2019
c2b1bfa
plugin.xml reset plugin id & links
Jan 24, 2019
66011a1
plugin.xml add blank lines
Jan 24, 2019
84530f1
general description updates for Android/iOS
Jan 24, 2019
d2fd063
Remove trailing spaces from ClientCertificate.[hm]
Jan 24, 2019
4df45e7
Remove trailing spaces from other iOS sources
Jan 24, 2019
10d6769
Add space to comments in ClientCertificate.m
Jan 25, 2019
825ea15
README.md remove trailing tabs from code samples
Jan 25, 2019
6109c0b
Merge branch 'general-ios-updates'
Jan 25, 2019
6e98810
Set version to 0.0.4-dev
Jan 25, 2019
e9a79ff
README.md updates and fixes
Jan 25, 2019
c9c3b56
OpenCertFile updates & fixes
Jan 25, 2019
71dda4d
handle open cert file on iOS, with no password
Jan 25, 2019
25e4a40
Update plugin author, license, etc.
Mar 7, 2019
fc5fb52
doc updates & fixes for this plugin version
Mar 7, 2019
7e9c284
JavaScript module for iOS only
Mar 8, 2019
efb6552
Android plugin updates before merge
Mar 8, 2019
6f33aa3
Merge branch 'fork-updates' into combined-updates
Mar 8, 2019
be873b6
Some Android platform doc text moved up
Mar 8, 2019
ac69baf
doc updates for the newly combined plugin version
Mar 8, 2019
03b2075
add link to Cordova test app
Mar 8, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.DS_Store
15 changes: 15 additions & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"browser": true,
"bitwise": true,
"undef": true,
"trailing": true,
"quotmark": false,
"indent": 4,
"unused": "vars",
"latedef": "nofunc",
"globals": {
"module": false,
"exports": false,
"require": false
}
}
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
language: node_js
sudo: false
node_js:
- "4.2"
7 changes: 3 additions & 4 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
Expand Down Expand Up @@ -179,15 +178,15 @@
APPENDIX: How to apply the Apache License to your work.

To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
boilerplate notice, with the fields enclosed by brackets "{}"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright [yyyy] [name of copyright owner]
Copyright {yyyy} {name of copyright owner}

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -199,4 +198,4 @@
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
limitations under the License.
153 changes: 126 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,45 @@
# Cordova Client Certificate Plugin
This plugin uses iOS implementation and API from mwaylabs/cordova-plugin-client-certificate
# Cordova Client Certificate authentication support plugin

This plugin is a forked from zxyang/cordova-plugin-clientcertificate
Plugin that uses a client certificate for authentication, with special `myp12` file association as described below.

This plugin handles client certificate request from both iOS and Android WebView the full path to the certificat is required.
This plugin uses iOS implementation and API based on: [`mwaylabs/cordova-plugin-client-certificate`](https://github.com/mwaylabs/cordova-plugin-client-certificate)

This plugin read the certificate in any folder even in a cordova.file.dataDirectory (r/w folder). (So you can retrieve you cert file from a API and use it)
This plugin version is known to include code from the following other plugin versions:

#Todo
Add Windows platform
- [`EbilPanda/cordova-plugin-client-certificate-ebilpanda`](https://github.com/EbilPanda/cordova-plugin-client-certificate-ebilpanda)
- [`addictic/cordova-plugin-client-certificate-addictic`](https://github.com/addictic/cordova-plugin-client-certificate-addictic)
- [`zxyang/cordova-plugin-clientcertificate`](https://github.com/zxyang/cordova-plugin-clientcertificate) (this version seems to have copied some version of the code from [`johannes-staehlin/cordova-client-cert-authentication`](https://github.com/johannes-staehlin/cordova-client-cert-authentication))
- [`mwaylabs/cordova-plugin-client-certificate`](https://github.com/mwaylabs/cordova-plugin-client-certificate)
- [`johannes-staehlin/cordova-client-cert-authentication`](https://github.com/johannes-staehlin/cordova-client-cert-authentication)

**LICENSE:** Apache 2.0, with some code for iOS under [Apple MIT License](https://spdx.org/licenses/AML.html) (more detailed license statement below)

## About

This plugin handles client certificate request on iOS and Android. On iOS this plugin version supports using client certificates from both file association and local file system, as documented below. On Android this plugin supports using client certificates from the key chain, using shared preferences from the preference manager (code from [`johannes-staehlin/cordova-client-cert-authentication`](https://github.com/johannes-staehlin/cordova-client-cert-authentication)).

Specific for iOS:
- This plugin version uses `config-file` elements to configure the app to handle open requests for files with the custom `myp12` extension, by attempting to a register p12 client certificate from such a file with no password, on iOS only.
- This plugin reads the certificate in any folder even in a cordova.file.dataDirectory (r/w folder). (So you can retrieve a cert file from an API and use it)

Specific for Android:

- Android platform implementation was replaced with an implementation that is almost the same as [`johannes-staehlin/cordova-client-cert-authentication`](https://github.com/johannes-staehlin/cordova-client-cert-authentication), which does not work with any JavaScript API at all (see documentation below).

## Usage

## Prerequisites

**Recommended:**

Install Cordova File API plugin (`cordova-plugin-file`), as described below:

$ cordova plugin add cordova-plugin-file

**Optional:**

Add the following to `config.xml`:

#Prerequisites
Add to config.xml the following
```xml
<platform name="android">
<preference name="AndroidPersistentFileLocation" value="Internal" />
Expand All @@ -21,31 +49,63 @@ Add to config.xml the following
</platform>
```

#Use Steps
Clone the plugin
## Usage

$ git clone https://github.com/agenceaddictic/cordova-plugin-client-certificate-addictic.git
### Installing the plugin

Create a new Cordova Project

$ cordova create hello com.example.helloapp Hello
Install the plugin

Install the plugin, for example:

$ cd hello
$ cordova plugin add ../cordova-plugin-client-certificate-addictic
Install plugin File
$ cordova plugin add https://github.com/mwaylabs/cordova-plugin-client-certificate

Install File API plugin:

$ cordova plugin add cordova-plugin-file


### Android keychain

This plugin adds certificate-based authentication (SSO) to your cordova application. There is no extra coding or Android platform knowledge required when using this plugin on Android. It does not contain any JavaScript part since it just waits until the SSLSocket asks the client for a certificate and then shows the default client-cert pop-up you would also get when visiting your web page using the Android Chrome browser.

(Not supported by the JavaScript API)

### Use with file association

**for iOS ONLY:**

This plugin version associates itself with the `myp12` extension in plist on iOS only when it is added to a Cordova app, as specified in `plugin.xml`.

If the user tells another iOS application such as Mail to open a `myp12` file with a Cordova app that uses this plugin version, this plugin will use the certificate from the `myp12` file. No special JavaScript code is required for this file association to function.

### Cordova test app

- <https://github.com/cordova-ccafix/cordova-client-cert-test-app>

### Sample programs

**for iOS ONLY:**

Exemple :
Copy of an embedded certificate in /www (read only) to a directory accessible in read/write
Retrieve the final path and execute the handshake SSL
**WARNING:** Client certificate should NEVER be included in the `www` folder or any other part of a published app.

Add the following code inside `onDeviceReady`
#### Quick sample

FOR TESTING PURPOSES ONLY (see warning above): Copy a client certificate into the `www` folder.

Edit `www/js/index.js` and add the following code inside `onDeviceReady`:

```js
clientCertificate.registerAuthenticationCertificate("certfilePath/cert.p12", "s3cr37", success, failure);
```

#### With File API

- FOR TESTING PURPOSES ONLY (see warning above): Copy of an embedded certificate in `www` (read only) to a directory accessible in read/write
- Retrieve the final path and execute the handshake SSL

Add the following code inside `onDeviceReady`:

```js
var certAutomate = 'mycert.p12';
Expand All @@ -71,31 +131,70 @@ var certAuthenticate = function() {
// Full path to the cert
var p12path = datDir.substring(7) + certFolder + certAutomate;
var p12pass = 'myPassword';
clientCertificate.register(p12path, p12pass, certificateRegistred, onFailure);

// Updated API from mwaylabs/cordova-plugin-client-certificate
clientCertificate.registerAuthenticationCertificate(p12path, p12pass, certificateRegistred, onFailure);
};

var certificateRegistred = function(message) {
console.log(message);
console.log(message);
// launch your web service that requires certificate authentication here
};

var onSuccess = function(message){
console.log('Success : ', message);
};

var onFailure = function(message){
console.log('Error : ', message);
};

```

### Build and run

Install iOS and Android platform

cordova platform add ios
cordova platform add android

Run the code

cordova run android
cordova run ios

## For future consideration

- Prompt the user for a p12 certificate password on iOS, if necessary. Native dialog prompt would be ideal; using JavaScript on this plugin or callback to the application code would also be possible.
- Add Windows platform

## More Info

For more information on setting up Cordova see [the Cordova CLI documentation](https://cordova.apache.org/docs/en/latest/guide/cli/index.html#installing-the-cordova-cli)

For more info on plugins see the [Cordova Plugin Development Guide](https://cordova.apache.org/docs/en/latest/guide/hybrid/plugins/index.html)

## Contributing

Feel free to contribute code to this project through GitHub by forking the repository and sending a pull request.

## License

Copyright 2019 Christopher J. Brody

Copyright 2018 Johannes Stählin

with code from other authors and contributors

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

with some code for iOS under [Apple MIT License](https://spdx.org/licenses/AML.html)
1 change: 1 addition & 0 deletions _config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
theme: jekyll-theme-hacker
45 changes: 45 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"name": "cordova-plugin-client-certificate",
"description": "Client certificate authentication for your Cordova app.",
"version": "0.0.4-dev",
"homepage": "https://github.com/mwaylabs/cordova-plugin-client-certificate",
"repository": {
"type": "git",
"url": "https://github.com/mwaylabs/cordova-plugin-client-certificate.git"
},
"bugs": {
"url": "https://github.com/mwaylabs/cordova-plugin-client-certificate/issues"
},
"cordova": {
"id": "cordova-plugin-client-certificate",
"platforms": [
"ios"
]
},
"keywords": [
"ecosystem:cordova",
"ecosystem:phonegap",
"cordova-ios",
"cordova",
"client",
"certificate",
"authentication",
"pkcs12",
"p12"
],
"scripts": {
"test": "npm run jshint",
"jshint": "node node_modules/jshint/bin/jshint www && node node_modules/jshint/bin/jshint src"
},
"engines": [
{
"name": "cordova",
"version": ">=3.0.0"
}
],
"author": "Various",
"license": "Apache-2.0 AND AML",
"devDependencies": {
"jshint": "^2.6.0"
}
}
Loading