From 4aab3c0061d17dac0e7d5ed7a7757988cb297469 Mon Sep 17 00:00:00 2001 From: Harald Leithner Date: Wed, 8 May 2019 15:25:42 +0200 Subject: [PATCH 1/4] Encode key as base58 --- js/base-x-3.0.5.1.js | 148 +++++++++++++++++++++++++++++++++++++++++++ js/privatebin.js | 3 +- tpl/bootstrap.php | 3 +- tpl/page.php | 3 +- 4 files changed, 154 insertions(+), 3 deletions(-) create mode 100644 js/base-x-3.0.5.1.js 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..9a8eb72b --- /dev/null +++ b/js/base-x-3.0.5.1.js @@ -0,0 +1,148 @@ +// 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. + +var 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 + } +} diff --git a/js/privatebin.js b/js/privatebin.js index cf747335..fc07ec5d 100644 --- a/js/privatebin.js +++ b/js/privatebin.js @@ -643,7 +643,8 @@ jQuery.PrivateBin = (function($, sjcl, Base64, RawDeflate) { */ me.getSymmetricKey = function() { - return sjcl.codec.base64.fromBits(sjcl.random.randomWords(8, 10), 0); + var bs58 = new baseX('123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'); + return bs58.encode(sjcl.codec.base64.fromBits(sjcl.random.randomWords(8, 10), 0)); }; return me; diff --git a/tpl/bootstrap.php b/tpl/bootstrap.php index fdc1b51b..d8419ffa 100644 --- a/tpl/bootstrap.php +++ b/tpl/bootstrap.php @@ -60,6 +60,7 @@ else: + @@ -76,7 +77,7 @@ if ($MARKDOWN): endif; ?> - + diff --git a/tpl/page.php b/tpl/page.php index 8d87ea68..849d3ed4 100644 --- a/tpl/page.php +++ b/tpl/page.php @@ -39,6 +39,7 @@ else: + - + From b12a099e294d087d2424e7d0cf67645d5150bff6 Mon Sep 17 00:00:00 2001 From: El RIDO Date: Wed, 8 May 2019 18:32:45 +0200 Subject: [PATCH 2/4] updating license document to include base-x' MIT license --- LICENSE.md | 62 ++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 49 insertions(+), 13 deletions(-) diff --git a/LICENSE.md b/LICENSE.md index 8492fc32..443dfc37 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -4,9 +4,9 @@ PrivateBin consists of PHP and JS code which was originally written by Sébastie 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: +(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 @@ -30,16 +30,6 @@ 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 _Version 2, June 1991_ @@ -517,6 +507,52 @@ 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 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. + +### MIT license for base-x + +Copyright (c) 2018 base-x contributors +Copyright (c) 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 +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_ From 54d21a7803aa2279274373f2afc35e2c2416b3c6 Mon Sep 17 00:00:00 2001 From: El RIDO Date: Wed, 8 May 2019 19:00:22 +0200 Subject: [PATCH 3/4] making base-x compatible with node & browser --- js/base-x-3.0.5.1.js | 5 ++++- js/common.js | 1 + tpl/bootstrap.php | 4 ++-- tpl/page.php | 4 ++-- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/js/base-x-3.0.5.1.js b/js/base-x-3.0.5.1.js index 9a8eb72b..2a69d363 100644 --- a/js/base-x-3.0.5.1.js +++ b/js/base-x-3.0.5.1.js @@ -6,7 +6,9 @@ // Distributed under the MIT software license, see the accompanying // file LICENSE or http://www.opensource.org/licenses/mit-license.php. -var baseX = function base (ALPHABET) { +(function(){ +'use strict'; +this.baseX = function base (ALPHABET) { if (ALPHABET.length >= 255) throw new TypeError('Alphabet too long') const BASE_MAP = new Uint8Array(256) @@ -146,3 +148,4 @@ var baseX = function base (ALPHABET) { decode: decode } } +}).call(this); \ No newline at end of file diff --git a/js/common.js b/js/common.js index be1cf377..615042ab 100644 --- a/js/common.js +++ b/js/common.js @@ -18,6 +18,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/tpl/bootstrap.php b/tpl/bootstrap.php index d8419ffa..04e85d6b 100644 --- a/tpl/bootstrap.php +++ b/tpl/bootstrap.php @@ -60,7 +60,7 @@ else: - + @@ -77,7 +77,7 @@ if ($MARKDOWN): endif; ?> - + diff --git a/tpl/page.php b/tpl/page.php index 849d3ed4..708e2767 100644 --- a/tpl/page.php +++ b/tpl/page.php @@ -39,7 +39,7 @@ else: - + - + From 7f1afb2b3e9f46b85910305c0c6004bffb3d61c8 Mon Sep 17 00:00:00 2001 From: El RIDO Date: Wed, 8 May 2019 19:06:26 +0200 Subject: [PATCH 4/4] unifying MIT licenses, diff showed them to be identical --- LICENSE.md | 142 +++-------------------------------------------------- 1 file changed, 8 insertions(+), 134 deletions(-) diff --git a/LICENSE.md b/LICENSE.md index 443dfc37..2f3d33f8 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -397,31 +397,17 @@ 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. -## 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 @@ -441,118 +427,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. - -### 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. - -### MIT license for base-x - -Copyright (c) 2018 base-x contributors -Copyright (c) 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 -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_