diff --git a/LICENSE.md b/LICENSE.md index 5ffdba0f..eecdf6cf 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -2,15 +2,15 @@ PrivateBin consists of PHP and JS code which was originally written by Sébastien Sauvage in 2012 and falls unter the Zlib/libpng license. Also included are -libraries that fall under the GPLv2 (SJCL, rawinflate, rawdeflate), BSD -2-clause (SJCL), BSD 3-clause (base64.js version 2.1.9, Showdown), MIT -(base64.js version 1.7, Bootstrap, Identicon, random_compat), Apache -(prettify.js) and CC-BY (favicon, icon, logo) licenses. All of these license -terms can be found here below: +libraries that fall under the GPLv2 (rawinflate), BSD 3-clause (Showdown), MIT +(base64.js version 1.7, Bootstrap, Identicon, random_compat, composer, kjua, +base-x), Apache (prettify.js) and CC-BY (favicon, icon, logo) licenses. All of +these license terms can be found here below: -## Zlib/libpng license for PrivateBin +## Zlib/libpng license for PrivateBin and zlib Copyright © 2012 Sébastien Sauvage +Copyright © 1995-2017 Jean-loup Gailly and Mark Adler This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use @@ -30,17 +30,7 @@ the following restrictions: 3. This notice may not be removed or altered from any source distribution. -### MIT license for kjua - -Copyright (c) 2016 Lars Jung (https://larsjung.de) - -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. - -## GNU General Public License, version 2.0, for SJCL, rawdeflate and rawinflate +## GNU General Public License, version 2.0, for rawinflate _Version 2, June 1991_ _Copyright © 1989, 1991 Free Software Foundation, Inc.,_ @@ -317,31 +307,6 @@ POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS -## BSD 2-Clause License for SJCL - -_Copyright © 2009-2015, Emily Stark, Mike Hamburg and Dan Boneh at Stanford University._ -_All rights reserved._ - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -1. Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. -2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR -ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND -ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - ## BSD 3-Clause License for Showdown Showdown Copyright © 2007, John Fraser @@ -377,31 +342,16 @@ any theory of liability, whether in contract, strict liability, or tort (including negligence or otherwise) arising in any way out of the use of this software, even if advised of the possibility of such damage. -## MIT License for base64.js version 1.7 +## MIT License for base64.js version 1.7, Bootstrap, Identicon, random_compat, Composer, kjua and base-x Copyright © 2012 Dan Kogai - -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. - -## MIT License for Bootstrap - Copyright © 2011-2016 Twitter, Inc. +Copyright © 2013 Benjamin Laugueux +Copyright © 2015 Paragon Initiative Enterprises +Copyright © 2016 Nils Adermann, Jordi Boggiano +Copyright © 2016 Lars Jung (https://larsjung.de) +Copyright © 2018 base-x contributors +Copyright © 2014-2018 The Bitcoin Core developers Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -421,72 +371,6 @@ 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. -## MIT License for Identicon - -Copyright © 2013 Benjamin Laugueux - -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. - -## MIT License for random_compat - -Copyright © 2015 Paragon Initiative Enterprises - -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. - -## MIT license for Composer - -Copyright (c) 2016 Nils Adermann, Jordi Boggiano - -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. - ## Apache License for prettify.js _Version 2.0, January 2004_ diff --git a/js/base-x-3.0.5.1.js b/js/base-x-3.0.5.1.js new file mode 100644 index 00000000..2a69d363 --- /dev/null +++ b/js/base-x-3.0.5.1.js @@ -0,0 +1,151 @@ +// base-x encoding / decoding +// based on https://github.com/cryptocoinjs/base-x 3.0.5 +// modification: removed Buffer dependency and node.modules entry +// Copyright (c) 2018 base-x contributors +// Copyright (c) 2014-2018 The Bitcoin Core developers (base58.cpp) +// Distributed under the MIT software license, see the accompanying +// file LICENSE or http://www.opensource.org/licenses/mit-license.php. + +(function(){ +'use strict'; +this.baseX = function base (ALPHABET) { + if (ALPHABET.length >= 255) throw new TypeError('Alphabet too long') + + const BASE_MAP = new Uint8Array(256) + BASE_MAP.fill(255) + + for (let i = 0; i < ALPHABET.length; i++) { + const x = ALPHABET.charAt(i) + const xc = x.charCodeAt(0) + + if (BASE_MAP[xc] !== 255) throw new TypeError(x + ' is ambiguous') + BASE_MAP[xc] = i + } + + const BASE = ALPHABET.length + const LEADER = ALPHABET.charAt(0) + const FACTOR = Math.log(BASE) / Math.log(256) // log(BASE) / log(256), rounded up + const iFACTOR = Math.log(256) / Math.log(BASE) // log(256) / log(BASE), rounded up + + function encode (source) { + if (source.length === 0) return '' + + // Skip & count leading zeroes. + let zeroes = 0 + let length = 0 + let pbegin = 0 + const pend = source.length + + while (pbegin !== pend && source[pbegin] === 0) { + pbegin++ + zeroes++ + } + + // Allocate enough space in big-endian base58 representation. + const size = ((pend - pbegin) * iFACTOR + 1) >>> 0 + const b58 = new Uint8Array(size) + + // Process the bytes. + while (pbegin !== pend) { + let carry = source[pbegin] + + // Apply "b58 = b58 * 256 + ch". + let i = 0 + for (let it = size - 1; (carry !== 0 || i < length) && (it !== -1); it--, i++) { + carry += (256 * b58[it]) >>> 0 + b58[it] = (carry % BASE) >>> 0 + carry = (carry / BASE) >>> 0 + } + + if (carry !== 0) throw new Error('Non-zero carry') + length = i + pbegin++ + } + + // Skip leading zeroes in base58 result. + let it = size - length + while (it !== size && b58[it] === 0) { + it++ + } + + // Translate the result into a string. + let str = LEADER.repeat(zeroes) + for (; it < size; ++it) str += ALPHABET.charAt(b58[it]) + + return str + } + + function decodeUnsafe (source) { + if (typeof source !== 'string') throw new TypeError('Expected String') + if (source.length === 0) return '' + + let psz = 0 + + // Skip leading spaces. + if (source[psz] === ' ') return + + // Skip and count leading '1's. + let zeroes = 0 + let length = 0 + while (source[psz] === LEADER) { + zeroes++ + psz++ + } + + // Allocate enough space in big-endian base256 representation. + const size = (((source.length - psz) * FACTOR) + 1) >>> 0 // log(58) / log(256), rounded up. + const b256 = new Uint8Array(size) + + // Process the characters. + while (source[psz]) { + // Decode character + let carry = BASE_MAP[source.charCodeAt(psz)] + + // Invalid character + if (carry === 255) return + + let i = 0 + for (let it = size - 1; (carry !== 0 || i < length) && (it !== -1); it--, i++) { + carry += (BASE * b256[it]) >>> 0 + b256[it] = (carry % 256) >>> 0 + carry = (carry / 256) >>> 0 + } + + if (carry !== 0) throw new Error('Non-zero carry') + length = i + psz++ + } + + // Skip trailing spaces. + if (source[psz] === ' ') return + + // Skip leading zeroes in b256. + let it = size - length + while (it !== size && b256[it] === 0) { + it++ + } + + var vch = []; + + let j = zeroes + while (it !== size) { + vch[j++] = b256[it++] + } + + return vch + } + + function decode (string) { + const buffer = decodeUnsafe(string) + if (buffer) return buffer + + throw new Error('Non-base' + BASE + ' character') + } + + return { + encode: encode, + decodeUnsafe: decodeUnsafe, + decode: decode + } +} +}).call(this); \ No newline at end of file diff --git a/js/common.js b/js/common.js index d0c53aa5..d0f34de6 100644 --- a/js/common.js +++ b/js/common.js @@ -17,6 +17,7 @@ global.prettyPrint = window.PR.prettyPrint; global.prettyPrintOne = window.PR.prettyPrintOne; global.showdown = require('./showdown-1.8.6'); global.DOMPurify = require('./purify-1.0.7'); +global.baseX = require('./base-x-3.0.5.1').baseX; require('./bootstrap-3.3.7'); require('./privatebin'); diff --git a/js/privatebin.js b/js/privatebin.js index a4b0daa0..0c5a8ef8 100644 --- a/js/privatebin.js +++ b/js/privatebin.js @@ -531,6 +531,13 @@ jQuery.PrivateBin = (function($, RawDeflate) { const CryptTool = (function () { const me = {}; + /** + * base58 encoder & decoder + * + * @private + */ + let base58 = new baseX('123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'); + /** * convert UTF-8 string stored in a DOMString to a standard UTF-16 DOMString * @@ -922,13 +929,43 @@ jQuery.PrivateBin = (function($, RawDeflate) { * @name CryptTool.getSymmetricKey * @function * @throws {string} - * @return {string} base64 encoded key + * @return {string} raw bytes */ me.getSymmetricKey = function() { return getRandomBytes(32); }; + /** + * base58 encode a DOMString (UTF-16) + * + * @name CryptTool.base58encode + * @function + * @param {string} input + * @return {string} output + */ + me.base58encode = function(input) + { + return base58.encode( + stringToArraybuffer(input) + ); + } + + /** + * base58 decode a DOMString (UTF-16) + * + * @name CryptTool.base58decode + * @function + * @param {string} input + * @return {string} output + */ + me.base58decode = function(input) + { + return arraybufferToString( + base58.decode(input) + ); + } + return me; })(); @@ -1101,7 +1138,12 @@ jQuery.PrivateBin = (function($, RawDeflate) { newKey = newKey.substring(0, ampersandPos); } - symmetricKey = atob(newKey); + // version 2 uses base58, version 1 uses base64 + try { + symmetricKey = CryptTool.base58decode(newKey); + } catch(e) { + symmetricKey = atob(newKey); + } } return symmetricKey; @@ -3174,7 +3216,7 @@ jQuery.PrivateBin = (function($, RawDeflate) { document.title, // recreate paste URL Helper.baseUri() + '?' + Model.getPasteId() + '#' + - btoa(Model.getPasteKey()) + CryptTool.base58encode(Model.getPasteKey()) ); // we use text/html instead of text/plain to avoid a bug when @@ -3931,7 +3973,7 @@ jQuery.PrivateBin = (function($, RawDeflate) { // show notification const baseUri = Helper.baseUri() + '?', - url = baseUri + data.id + '#' + btoa(data.encryptionKey), + url = baseUri + data.id + '#' + CryptTool.base58encode(data.encryptionKey), deleteUrl = baseUri + 'pasteid=' + data.id + '&deletetoken=' + data.deletetoken; PasteStatus.createPasteNotification(url, deleteUrl); diff --git a/js/test/Model.js b/js/test/Model.js index d5a92b38..6f25f9ec 100644 --- a/js/test/Model.js +++ b/js/test/Model.js @@ -132,13 +132,14 @@ describe('Model', function () { }); jsc.property( - 'returns the fragment of the URL', + 'returns the fragment of a v1 URL', jsc.nearray(common.jscA2zString()), jsc.nearray(common.jscA2zString()), jsc.array(common.jscQueryString()), 'nestring', function (schema, address, query, fragment) { - var fragmentString = common.btoa(fragment), + fragment = fragment.padStart(32, String.fromCharCode(0)); + let fragmentString = common.btoa(fragment), clean = jsdom('', { url: schema.join('') + '://' + address.join('') + '/?' + query.join('') + '#' + fragmentString @@ -150,14 +151,52 @@ describe('Model', function () { } ); jsc.property( - 'returns the fragment stripped of trailing query parts', + 'returns the v1 fragment stripped of trailing query parts', jsc.nearray(common.jscA2zString()), jsc.nearray(common.jscA2zString()), jsc.array(common.jscQueryString()), 'nestring', jsc.array(common.jscHashString()), function (schema, address, query, fragment, trail) { - var fragmentString = common.btoa(fragment), + fragment = fragment.padStart(32, String.fromCharCode(0)); + let fragmentString = common.btoa(fragment), + clean = jsdom('', { + url: schema.join('') + '://' + address.join('') + '/?' + + query.join('') + '#' + fragmentString + '&' + trail.join('') + }), + result = $.PrivateBin.Model.getPasteKey(); + $.PrivateBin.Model.reset(); + clean(); + return fragment === result; + } + ); + jsc.property( + 'returns the fragment of a v2 URL', + jsc.nearray(common.jscA2zString()), + jsc.nearray(common.jscA2zString()), + jsc.array(common.jscQueryString()), + 'nestring', + function (schema, address, query, fragment) { + let fragmentString = $.PrivateBin.CryptTool.base58encode(fragment), + clean = jsdom('', { + url: schema.join('') + '://' + address.join('') + + '/?' + query.join('') + '#' + fragmentString + }), + result = $.PrivateBin.Model.getPasteKey(); + $.PrivateBin.Model.reset(); + clean(); + return fragment === result; + } + ); + jsc.property( + 'returns the v2 fragment stripped of trailing query parts', + jsc.nearray(common.jscA2zString()), + jsc.nearray(common.jscA2zString()), + jsc.array(common.jscQueryString()), + 'nestring', + jsc.array(common.jscHashString()), + function (schema, address, query, fragment, trail) { + let fragmentString = $.PrivateBin.CryptTool.base58encode(fragment), clean = jsdom('', { url: schema.join('') + '://' + address.join('') + '/?' + query.join('') + '#' + fragmentString + '&' + trail.join('') diff --git a/tpl/bootstrap.php b/tpl/bootstrap.php index 286af010..daaafae7 100644 --- a/tpl/bootstrap.php +++ b/tpl/bootstrap.php @@ -56,6 +56,7 @@ if ($ZEROBINCOMPATIBILITY): endif; ?> + - + diff --git a/tpl/page.php b/tpl/page.php index a79ac369..d6fd35b0 100644 --- a/tpl/page.php +++ b/tpl/page.php @@ -35,6 +35,7 @@ if ($ZEROBINCOMPATIBILITY): endif; ?> + - +