Skip to content

Commit

Permalink
Merge pull request #32 from unravelin/lite-fallback
Browse files Browse the repository at this point in the history
v0.1.0: Lite fallback
  • Loading branch information
Paul Scott committed Jun 26, 2020
2 parents b431287 + a225e08 commit b7c15be
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 8 deletions.
11 changes: 10 additions & 1 deletion README.md
Expand Up @@ -36,6 +36,12 @@ exception is raised.

### Tracking Page Activity

Page tracking is performed by a third-party script loaded into your page by
ravelinjs. To handle cases where the loading of this script fails, it is
recommended that you host a copy of
https://cdn.ravelin.net/js/rvn-0.1.18-lite.min.js (at '/rvn.js' in the example
below) and pass its address to `setFallbackJS`.

Using ravelinjs, the `setPublicAPIKey` (called immediately), `track`, and
`trackPage` (call on page load) methods can be used instead of the [device
fingerprinting snippet][device-track]. See the example below for more.
Expand All @@ -59,6 +65,9 @@ and send that encrypted value (the cipher) back to your server.

<script src="ravelin.min.js"></script>
<script>
// Fallback.
ravelinjs.setFallbackJS('/rvn.js');
// Tracking.
ravelinjs.setPublicAPIKey('pk_live_...');
ravelinjs.trackPage();
Expand Down Expand Up @@ -123,7 +132,7 @@ upon which it relies:

* Tidy up exceptions used in older browsers where insufficient entropy is
available when trying to encrypt

* Provide recommedations for how to handle exceptions.

[device-track]: https://developer.ravelin.com/v2/#device-tracking
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "ravelinjs",
"version": "0.0.13",
"version": "0.1.0",
"description": "Ravelin Client-side Card Encryption Library.",
"main": "ravelin.js",
"scripts": {
Expand Down
37 changes: 34 additions & 3 deletions ravelin.js
Expand Up @@ -9,7 +9,7 @@
}
}(typeof self !== 'undefined' ? self : this, function () {

var version = '0.0.13';
var version = '0.1.0';

var RSAKey = (function(){
// prng4.js - uses Arcfour as a PRNG
Expand Down Expand Up @@ -914,13 +914,44 @@
return;
}
if (!window.ravelin) {
// https://developer.ravelin.com/v2/#device-tracking.
(function(r,a,v,e,l,i,n){r[l]=r[l]||function(){(r[l].q=r[l].q||[]).push(arguments)};i=a.createElement(v);i.async=i.defer=1;i.src=e;a.body.appendChild(i)})(window, document, 'script', 'https://cdn.ravelin.net/js/rvn-beta.min.js', 'ravelin');
(function r(a,v,e,l,i,n) {
a[e] = a[e] || function() { (a[e].q = a[e].q || []).push(arguments)};
n = v.createElement('script');
n.async = n.defer = 1;
n.src = l;
if (i) n.onerror = function() { r(a, v, e, i) };
v.body.appendChild(n);
})(
/* r(*/
/* a */ window,
/* v */ document,
/* e */ 'ravelin',
/* l */ 'https://cdn.ravelin.net/js/rvn-beta.min.js',
/* i */ this.fallbackJS
/* n)*/
);
}

window.ravelin.apply(window, args);
}

/**
* setFallbackJS defines an alternative source from the default ravelin-hosted
* JavaScript used for simple device tracking. It is recommended you host a
* copy of https://cdn.ravelin.net/js/rvn-0.1.18-lite.min.js on your domain
* and reference it here.
*
* Must be called before setPublicAPIKey.
*
* @param {String} src Your self-hosted copy of https://cdn.ravelin.net/js/rvn-0.1.18-lite.min.js.
* @example ravelinjs.setFallbackJS('/rvn.js');
* @deprecated This method will be removed in ravelinjs 1.0.0 which will no
* longer rely on any third-party scripts.
*/
RavelinJS.prototype.setFallbackJS = function(src) {
this.fallbackJS = src;
};

/**
* setPublicAPIKey sets the API Key used to authenticate with Ravelin. It should be called
* before anything else. You can find your publishable API key inside the Ravelin dashboard.
Expand Down
5 changes: 5 additions & 0 deletions test/crossbrowser.conf.js
Expand Up @@ -155,6 +155,11 @@ exports.config = Object.assign(base, {
platformVersion: '5.0',
platformName: 'Android',
deviceOrientation: 'portrait',

// FIXME. I've spent a couple of days trying to get meaningful errors
// back from this device. In manual testing it works consistently.
requireJSTestDisabled: true,
webpackTestDisabled: true,
},
// iOS
{
Expand Down
8 changes: 8 additions & 0 deletions test/pages/amd/index.html
Expand Up @@ -43,6 +43,14 @@ <h2>Output Error</h2>
<script src="require.js"></script>
<script>
require(['ravelin'], function(ravelin) {
output(function() {
ravelin.setFallbackJS('/rvn.js');
ravelin.setPublicAPIKey('pk_live_Mgp7YkLK48IOnHzfcrBotxAJlo1RwiBi');
ravelin.trackFingerprint('paul');
ravelin.trackPage();
return 'Cookies: ' + document.cookie;
});

ravelin.setRSAKey('10001|BB2D2D2FD3812FEBECF8955843228A0E1952342583DFC02B8393475C414E16FDCBE8753BD63C164104785D8A67E344D495B5C0C622CE8D643F3191BC6BE0D3050F391F77E1D7E1B8F69DA34B308477E31F775CCC44158E33FD7DDD51AC87DD33AD80B9B1BF850CEC79A189F011C0689C36C0C91BF6DB9CD65BB7399710E32D9876C00DD44103E54A64A44BF427E1BA4F48DA7AF3D623DBCCF282ED8D4CCAE31B921A9BE92F9E8D7B5C50FBD89D828539CAE3E3493D4F6D7ADA19A876D9DF3801B5C3CFFA6A3C72A246150F307D789BAD6E2408DA5EF05EE805E11C133FFEDFA57CD1C35E49106ADDAC43C51995B9C318066C9ACB4042D8A534370D79F1BAD601');
document.getElementById('form').onsubmit = function() {
var month = document.getElementById('month');
Expand Down
10 changes: 9 additions & 1 deletion test/pages/scripttag/index.html
Expand Up @@ -62,6 +62,14 @@ <h2>Output Error</h2>
}
setRSAKey();

output(function() {
ravelinjs.setFallbackJS('/rvn.js');
ravelinjs.setPublicAPIKey('pk_live_Mgp7YkLK48IOnHzfcrBotxAJlo1RwiBi');
ravelinjs.trackFingerprint('paul');
ravelinjs.trackPage();
return 'Cookies: ' + document.cookie;
});

document.getElementById('form').onsubmit = function() {
var month = document.getElementById('month');
output(function() {
Expand All @@ -76,4 +84,4 @@ <h2>Output Error</h2>
};
</script>
</body>
</html>
</html>
9 changes: 8 additions & 1 deletion test/pages/webpack/index.js
@@ -1,6 +1,13 @@
import ravelin from '../../../ravelin.js';
import output from '../common.js';

output(function() {
ravelin.setPublicAPIKey('pk_live_Mgp7YkLK48IOnHzfcrBotxAJlo1RwiBi');
ravelin.trackFingerprint('paul');
ravelin.trackPage();
return 'Cookies: ' + document.cookie;
});

ravelin.setRSAKey('10001|BB2D2D2FD3812FEBECF8955843228A0E1952342583DFC02B8393475C414E16FDCBE8753BD63C164104785D8A67E344D495B5C0C622CE8D643F3191BC6BE0D3050F391F77E1D7E1B8F69DA34B308477E31F775CCC44158E33FD7DDD51AC87DD33AD80B9B1BF850CEC79A189F011C0689C36C0C91BF6DB9CD65BB7399710E32D9876C00DD44103E54A64A44BF427E1BA4F48DA7AF3D623DBCCF282ED8D4CCAE31B921A9BE92F9E8D7B5C50FBD89D828539CAE3E3493D4F6D7ADA19A876D9DF3801B5C3CFFA6A3C72A246150F307D789BAD6E2408DA5EF05EE805E11C133FFEDFA57CD1C35E49106ADDAC43C51995B9C318066C9ACB4042D8A534370D79F1BAD601');
document.getElementById('form').onsubmit = function() {
var month = document.getElementById('month');
Expand All @@ -13,4 +20,4 @@ document.getElementById('form').onsubmit = function() {
});
});
return false;
};
};
2 changes: 1 addition & 1 deletion test/test.js
Expand Up @@ -105,6 +105,6 @@ function validateCipher(c) {
c.cardCiphertext != '' && c.cardCiphertext.length > 10 &&
c.aesKeyCiphertext != '' && c.aesKeyCiphertext.length > 10 &&
c.algorithm == 'RSA_WITH_AES_256_GCM' &&
c.ravelinSDKVersion == '0.0.13-ravelinjs' &&
c.ravelinSDKVersion == '0.1.0-ravelinjs' &&
typeof(c.keyIndex) === 'number';
}

0 comments on commit b7c15be

Please sign in to comment.