Initial commit
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 Martin Reinhardt
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
@@ -0,0 +1,56 @@
|
||||
# Certificate Plugin for Apache Cordova
|
||||
|
||||
[](https://travis-ci.org/hypery2k/cordova-certificate-plugin) [](http://badge.fury.io/js/cordova-plugin-certificates)[](https://www.bountysource.com/trackers/2596540-hypery2k-cordova-certificate-plugin?utm_source=2596540&utm_medium=shield&utm_campaign=TRACKER_BADGE)
|
||||
|
||||
> cordova Plugin to configure SSL Certificates, currently used to enable usage of untrusted aka self-signed SSL certifcates
|
||||
|
||||
[](https://nodei.co/npm/cordova-plugin-certificates/)
|
||||
|
||||
Feel free to **donate**
|
||||
|
||||
<a href='http://www.pledgie.com/campaigns/25442'><img alt='Click here to lend your support to: Owncloud Apps and make a donation at www.pledgie.com !' src='http://www.pledgie.com/campaigns/23447.png?skin_name=chrome' border='0' /></a>
|
||||
<a target="_blank" href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=AGPGLZYNV6Y5S">
|
||||
<img alt="" border="0" src="https://www.paypalobjects.com/de_DE/DE/i/btn/btn_donateCC_LG.gif"/>
|
||||
</img></a>
|
||||
|
||||
|
||||
## Documentation
|
||||
|
||||
### Install
|
||||
|
||||
```
|
||||
cordova plugin add cordova-plugin-certificates
|
||||
```
|
||||
|
||||
> For Cordova-Android before 4.1.0 you need to install this version
|
||||
|
||||
```
|
||||
cordova plugin add cordova-plugin-certificates@0.5.0
|
||||
```
|
||||
|
||||
### Usage
|
||||
|
||||
Activate insecure certificates
|
||||
```
|
||||
cordova.plugins.certificates.trustUnsecureCerts(true)
|
||||
```
|
||||
|
||||
Dectivate insecure certificates
|
||||
```
|
||||
cordova.plugins.certificates.trustUnsecureCerts(false)
|
||||
```
|
||||
|
||||
## Development
|
||||
|
||||
### Running integration tests
|
||||
|
||||
execute the `runIntegrationTests.sh` script for a specific platform:
|
||||
|
||||
```
|
||||
PLATFORM='android' ./runIntegrationTests.sh
|
||||
```
|
||||
|
||||
```
|
||||
PLATFORM='ios' ./runIntegrationTests.sh
|
||||
```
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
{
|
||||
"_args": [
|
||||
[
|
||||
{
|
||||
"raw": "cordova-plugin-certificates",
|
||||
"scope": null,
|
||||
"escapedName": "cordova-plugin-certificates",
|
||||
"name": "cordova-plugin-certificates",
|
||||
"rawSpec": "",
|
||||
"spec": "latest",
|
||||
"type": "tag"
|
||||
},
|
||||
"D:\\pWork\\yunkong2.vis.cordova\\node_modules"
|
||||
]
|
||||
],
|
||||
"_from": "cordova-plugin-certificates@latest",
|
||||
"_id": "cordova-plugin-certificates@0.6.4",
|
||||
"_inCache": true,
|
||||
"_location": "/cordova-plugin-certificates",
|
||||
"_nodeVersion": "6.11.1",
|
||||
"_npmOperationalInternal": {
|
||||
"host": "s3://npm-registry-packages",
|
||||
"tmp": "tmp/cordova-plugin-certificates-0.6.4.tgz_1501142806424_0.2454286552965641"
|
||||
},
|
||||
"_npmUser": {
|
||||
"name": "hypery2k",
|
||||
"email": "contact@martinreinhardt-online.de"
|
||||
},
|
||||
"_npmVersion": "3.10.10",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"raw": "cordova-plugin-certificates",
|
||||
"scope": null,
|
||||
"escapedName": "cordova-plugin-certificates",
|
||||
"name": "cordova-plugin-certificates",
|
||||
"rawSpec": "",
|
||||
"spec": "latest",
|
||||
"type": "tag"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"#USER",
|
||||
"/"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/cordova-plugin-certificates/-/cordova-plugin-certificates-0.6.4.tgz",
|
||||
"_shasum": "8051339be00c691c824338d8fa086ff5f6be2bb9",
|
||||
"_shrinkwrap": null,
|
||||
"_spec": "cordova-plugin-certificates",
|
||||
"_where": "D:\\pWork\\yunkong2.vis.cordova\\node_modules",
|
||||
"author": {
|
||||
"name": "Martin Reinhardt"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/hypery2k/cordova-certificate-plugin/issues"
|
||||
},
|
||||
"cordova": {
|
||||
"id": "cordova-plugin-certificates",
|
||||
"platforms": [
|
||||
"android",
|
||||
"ios"
|
||||
]
|
||||
},
|
||||
"dependencies": {},
|
||||
"description": "Cordova Certificate Plugin",
|
||||
"devDependencies": {},
|
||||
"directories": {},
|
||||
"dist": {
|
||||
"shasum": "8051339be00c691c824338d8fa086ff5f6be2bb9",
|
||||
"tarball": "https://registry.npmjs.org/cordova-plugin-certificates/-/cordova-plugin-certificates-0.6.4.tgz"
|
||||
},
|
||||
"gitHead": "762175849f553a4a98a47f6ab55438df8223647e",
|
||||
"homepage": "https://github.com/hypery2k/cordova-certificate-plugin#readme",
|
||||
"keywords": [
|
||||
"cordova",
|
||||
"certificates",
|
||||
"ecosystem:cordova",
|
||||
"cordova-android",
|
||||
"cordova-ios"
|
||||
],
|
||||
"license": "MIT",
|
||||
"maintainers": [
|
||||
{
|
||||
"name": "hypery2k",
|
||||
"email": "npm@martinreinhardt-online.de"
|
||||
}
|
||||
],
|
||||
"name": "cordova-plugin-certificates",
|
||||
"optionalDependencies": {},
|
||||
"readme": "ERROR: No README data found!",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/hypery2k/cordova-certificate-plugin.git"
|
||||
},
|
||||
"scripts": {},
|
||||
"version": "0.6.4"
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015 Martin Reinhardt
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
-->
|
||||
|
||||
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
|
||||
id="cordova-plugin-certificates"
|
||||
version="0.6.4">
|
||||
|
||||
<name>Certificate Plugin</name>
|
||||
<description>
|
||||
Cordova Certificate Plugin
|
||||
</description>
|
||||
<author>Martin Reinhardt</author>
|
||||
<license>MIT</license>
|
||||
<keywords>cordova,certificates,ssl</keywords>
|
||||
<repo>https://github.com/hypery2k/cordova-certificate-plugin.git</repo>
|
||||
<issue>https://github.com/hypery2k/cordova-certificate-plugin/issues</issue>
|
||||
|
||||
<engines>
|
||||
<engine name="cordova-android" version=">=4.1.0" />
|
||||
<engine name="cordova-ios" version=">=3.4.0" />
|
||||
</engines>
|
||||
|
||||
<js-module src="www/certificate.js" name="Certificates">
|
||||
<clobbers target="cordova.plugins.certificates" />
|
||||
</js-module>
|
||||
|
||||
<!-- ios -->
|
||||
<platform name="ios">
|
||||
<config-file target="config.xml" parent="/*">
|
||||
<feature name="CDVCertificate">
|
||||
<param name="ios-package" value="CDVCertificate"/>
|
||||
</feature>
|
||||
</config-file>
|
||||
|
||||
<header-file src="src/ios/CDVCertificate.h" />
|
||||
<source-file src="src/ios/CDVCertificate.m" />
|
||||
|
||||
<header-file src="src/ios/NSURLRequest+AllowUntrustedCertificates.h" />
|
||||
<source-file src="src/ios/NSURLRequest+AllowUntrustedCertificates.m" />
|
||||
</platform>
|
||||
|
||||
<!-- android -->
|
||||
<platform name="android">
|
||||
<config-file target="res/xml/config.xml" parent="/*">
|
||||
<feature name="CertificatesPlugin" >
|
||||
<param name="android-package" value="de.martinreinhardt.cordova.plugins.CertificatesPlugin"/>
|
||||
</feature>
|
||||
</config-file>
|
||||
|
||||
<source-file src="src/android/de/martinreinhardt/cordova/plugins/CertificatesCordovaWebViewClient.java" target-dir="src/de/martinreinhardt/cordova/plugins/" />
|
||||
<source-file src="src/android/de/martinreinhardt/cordova/plugins/CertificatesPlugin.java" target-dir="src/de/martinreinhardt/cordova/plugins/" />
|
||||
</platform>
|
||||
|
||||
</plugin>
|
||||
@@ -0,0 +1,16 @@
|
||||
#!/bin/sh
|
||||
cwd=$(pwd)
|
||||
cd ..
|
||||
rm -rf cordova-test-app
|
||||
git clone https://github.com/hypery2k/cordova-demo-app.git cordova-test-app
|
||||
cd cordova-test-app
|
||||
npm install
|
||||
bower install
|
||||
echo "Building vanilla cordova app"
|
||||
grunt "ci:$PLATFORM" "$PLATFORM"
|
||||
echo "Adding plugin"
|
||||
cordova plugin add ../cordova-certificate-plugin/
|
||||
echo "Building vanilla cordova app with added plugin"
|
||||
grunt "$PLATFORM"
|
||||
echo "Changing back to plugin directy: "$cwd
|
||||
cd $cwd
|
||||
+96
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015 Martin Reinhardt
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
Certificate Plugin for Cordova
|
||||
|
||||
*/
|
||||
package de.martinreinhardt.cordova.plugins;
|
||||
|
||||
import org.apache.cordova.engine.SystemWebViewEngine;
|
||||
import org.apache.cordova.engine.SystemWebViewClient;
|
||||
|
||||
import android.net.http.SslError;
|
||||
import android.util.Log;
|
||||
import android.webkit.SslErrorHandler;
|
||||
import android.webkit.WebView;
|
||||
|
||||
/**
|
||||
*
|
||||
* Certificates Cordova WebView Client
|
||||
*
|
||||
* author, Martin Reinhardt on 23.06.14.
|
||||
*
|
||||
* Copyright Martin Reinhardt 2014. All rights reserved.
|
||||
*
|
||||
*/
|
||||
public class CertificatesCordovaWebViewClient extends SystemWebViewClient {
|
||||
|
||||
/**
|
||||
* Logging Tag
|
||||
*/
|
||||
public static final String TAG = "CertificatesCordovaWebViewClient";
|
||||
|
||||
private boolean allowUntrusted = false;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param cordova
|
||||
*/
|
||||
public CertificatesCordovaWebViewClient(SystemWebViewEngine parentEngine) {
|
||||
super(parentEngine);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true of usage of untrusted (self-signed) certificates is allowed,
|
||||
* otherwise false
|
||||
*/
|
||||
public boolean isAllowUntrusted() {
|
||||
return allowUntrusted;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param pAllowUntrusted
|
||||
* the allowUntrusted to set
|
||||
*/
|
||||
public void setAllowUntrusted(final boolean pAllowUntrusted) {
|
||||
this.allowUntrusted = pAllowUntrusted;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.apache.cordova.SystemWebViewClient#onReceivedSslError(WebView,
|
||||
* SslErrorHandler, SslError)
|
||||
*/
|
||||
@Override
|
||||
public void onReceivedSslError(WebView view, SslErrorHandler handler,
|
||||
SslError error) {
|
||||
Log.d(TAG, "onReceivedSslError. Proceed? " + isAllowUntrusted());
|
||||
if (isAllowUntrusted()) {
|
||||
handler.proceed();
|
||||
} else {
|
||||
super.onReceivedSslError(view, handler, error);
|
||||
}
|
||||
}
|
||||
}
|
||||
+118
@@ -0,0 +1,118 @@
|
||||
/*
|
||||
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 Martin Reinhardt
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
Certificate Plugin for Cordova
|
||||
|
||||
*/
|
||||
package de.martinreinhardt.cordova.plugins;
|
||||
|
||||
import org.apache.cordova.engine.SystemWebViewEngine;
|
||||
import org.apache.cordova.engine.SystemWebView;
|
||||
import org.apache.cordova.CallbackContext;
|
||||
import org.apache.cordova.CordovaActivity;
|
||||
import org.apache.cordova.CordovaPlugin;
|
||||
import org.apache.cordova.CordovaWebView;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
/**
|
||||
*
|
||||
* Certificate Plugin for Cordova
|
||||
*
|
||||
* author, Martin Reinhardt on 23.06.14.
|
||||
*
|
||||
* Copyright Martin Reinhardt 2014. All rights reserved.
|
||||
*
|
||||
*/
|
||||
public class CertificatesPlugin extends CordovaPlugin {
|
||||
|
||||
/**
|
||||
* Logging Tag
|
||||
*/
|
||||
private static final String LOG_TAG = "Certificates";
|
||||
|
||||
/**
|
||||
* Untrusted Variable
|
||||
*/
|
||||
private boolean allowUntrusted = false;
|
||||
|
||||
/**
|
||||
* Executes the request.
|
||||
*
|
||||
* This method is called from the WebView thread. To do a non-trivial amount
|
||||
* of work, use: cordova.getThreadPool().execute(runnable);
|
||||
*
|
||||
* To run on the UI thread, use:
|
||||
* cordova.getActivity().runOnUiThread(runnable);
|
||||
*
|
||||
* @param action
|
||||
* The action to execute. (Currently "setUntrusted only")
|
||||
* @param args
|
||||
* The exec() arguments.
|
||||
* @param callbackContext
|
||||
* The callback context used when calling back into JavaScript.
|
||||
* @return Whether the action was valid.
|
||||
*
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
public boolean execute(String action, JSONArray args,
|
||||
CallbackContext callbackContext) throws JSONException {
|
||||
|
||||
if (action.equals("setUntrusted")) {
|
||||
try {
|
||||
allowUntrusted = args.getBoolean(0);
|
||||
Log.d(LOG_TAG, "Setting allowUntrusted to " + allowUntrusted);
|
||||
cordova.getActivity().runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
CordovaActivity ca = (CordovaActivity) cordova.getActivity();
|
||||
SystemWebView view = (SystemWebView)webView.getView();
|
||||
CertificatesCordovaWebViewClient cWebClient =
|
||||
new CertificatesCordovaWebViewClient((SystemWebViewEngine)webView.getEngine());
|
||||
|
||||
cWebClient.setAllowUntrusted(allowUntrusted);
|
||||
webView.clearCache();
|
||||
|
||||
// this fixes a crash that displays the error message:
|
||||
// "The connection to the server was unsuccessful.
|
||||
webView.stopLoading();
|
||||
view.setWebViewClient(cWebClient);
|
||||
} catch(Exception e){
|
||||
Log.e(LOG_TAG, "Got unkown error during setting webview in activity", e);
|
||||
}
|
||||
}
|
||||
});
|
||||
callbackContext.success();
|
||||
return true;
|
||||
} catch(Exception e){
|
||||
Log.e(LOG_TAG, "Got unkown error during passing to UI Thread", e);
|
||||
}
|
||||
}
|
||||
callbackContext.error("Invalid Command");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 Martin Reinhardt
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
*/
|
||||
|
||||
//
|
||||
// CDVCertificate.h
|
||||
//
|
||||
// Created by Martin Reinhardt on 23.06.2014.
|
||||
// Copyright Martin Reinhardt 2014. All rights reserved.
|
||||
|
||||
#import <Cordova/CDVPlugin.h>
|
||||
|
||||
@interface CDVCertificate : CDVPlugin
|
||||
|
||||
- (void)setUntrusted:(CDVInvokedUrlCommand*)command;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 Martin Reinhardt
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
*/
|
||||
|
||||
//
|
||||
// CDVCertificate.m
|
||||
//
|
||||
// Created by Martin Reinhardt on 23.06.2014.
|
||||
// Copyright Martin Reinhardt 2014. All rights reserved.
|
||||
//
|
||||
|
||||
#import "CDVCertificate.h"
|
||||
#import <Cordova/CDV.h>
|
||||
#import "NSURLRequest+AllowUntrustedCertificates.h"
|
||||
|
||||
@implementation CDVCertificate
|
||||
|
||||
- (void)setUntrusted:(CDVInvokedUrlCommand*)command {
|
||||
bool isUntrusted = [[command.arguments objectAtIndex:0] boolValue];
|
||||
|
||||
[NSURLRequest setAllowAllRequests:isUntrusted];
|
||||
|
||||
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
|
||||
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 Martin Reinhardt
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
*/
|
||||
|
||||
//
|
||||
// NSURLRequest+AllowUntrustedCertificates.h
|
||||
//
|
||||
// Created by Martin Reinhardt on 23.06.2014.
|
||||
// Copyright Martin Reinhardt 2014. All rights reserved.
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@interface NSURLRequest (AllowUntrustedCertificates)
|
||||
|
||||
+(void)setAllowAllRequests:(BOOL)allowRequests;
|
||||
@end
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 Martin Reinhardt
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
*/
|
||||
|
||||
//
|
||||
// NSURLRequest+AllowUntrustedCertificates.m
|
||||
//
|
||||
// Created by Martin Reinhardt on 23.06.2014.
|
||||
// Copyright Martin Reinhardt 2014. All rights reserved.
|
||||
|
||||
#import "NSURLRequest+AllowUntrustedCertificates.h"
|
||||
@interface NSURLRequest(AllowUntrustedCertificates_hidden)
|
||||
+(bool)getAllowAllRequests;
|
||||
@end
|
||||
@implementation NSURLRequest (AllowUntrustedCertificates)
|
||||
static bool _allowRequests = false;
|
||||
|
||||
+(void)setAllowAllRequests:(BOOL)allowRequests
|
||||
{
|
||||
_allowRequests = allowRequests;
|
||||
}
|
||||
+(bool)getAllowAllRequests
|
||||
{
|
||||
return _allowRequests;
|
||||
}
|
||||
|
||||
+ (BOOL)allowsAnyHTTPSCertificateForHost:(NSString *)host
|
||||
{
|
||||
return [NSURLRequest getAllowAllRequests];
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014 Martin Reinhardt
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
var Certificate = function () {
|
||||
|
||||
};
|
||||
|
||||
Certificate.prototype = {
|
||||
/**
|
||||
* Activates or deactivates the acceptance of self signed/unsecure SSL certificates
|
||||
*
|
||||
* @param {Function} boolActivateUnsecure
|
||||
* boolean value to set desired behaviour
|
||||
*/
|
||||
trustUnsecureCerts: function (boolActivateUnsecure) {
|
||||
if (cordova.platformId == 'android')
|
||||
cordova.exec(null, null, 'CertificatesPlugin', 'setUntrusted', [boolActivateUnsecure]);
|
||||
else
|
||||
cordova.exec(null, null, 'CDVCertificate', 'setUntrusted', [boolActivateUnsecure]);
|
||||
}
|
||||
};
|
||||
|
||||
var plugin = new Certificate();
|
||||
|
||||
module.exports = plugin;
|
||||
Reference in New Issue
Block a user