From 4d96af0988407f6216671c9000cd907ab367bafd Mon Sep 17 00:00:00 2001
From: Kevin Niehage
Date: Thu, 8 Sep 2016 11:00:47 +0200
Subject: [PATCH] url-safe Base64 encoding publication on github
---
CHANGELOG.md | 11 ++++++++
actions/share.php | 2 +-
index.php | 9 +++++--
libs/shared-secrets.def.php | 25 ++++++++++++------
libs/shared-secrets.exec.php | 50 ++++++++++++++++++++++++++++--------
pages/read/get.php | 2 +-
6 files changed, 77 insertions(+), 22 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index f6caa54..6e8c2df 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,14 @@
+# 0.7b0 (2016-09-08)
+
+* version bump for url-safe Base64 encoding publication on github
+
+# 0.6b1 (2016-09-07)
+
+* implemented so-called url-safe Base64 encoding of secrets to reduce URL-encoding junk
+* checked backward-compatibility with previous standard URL-encoded URLs
+* improved line-break handling in GPG message unstripping
+* tested url-safe Base64 encoding feature within chroot environment
+
# 0.6b0 (2016-09-02)
* version bump for increased readability publication on github
diff --git a/actions/share.php b/actions/share.php
index d6afc39..19ce8b0 100644
--- a/actions/share.php
+++ b/actions/share.php
@@ -18,7 +18,7 @@ function share_secret($secret) {
if (null !== $stripped_secret) {
# return the secret sharing URL
- $result = htmlentities(SECRET_SHARING_URL.urlencode($stripped_secret));
+ $result = htmlentities(SECRET_SHARING_URL.urlencode(url_base64_encode($stripped_secret)));
}
}
} else {
diff --git a/index.php b/index.php
index ab7e1cd..bc192ce 100644
--- a/index.php
+++ b/index.php
@@ -1,6 +1,6 @@
diff --git a/libs/shared-secrets.exec.php b/libs/shared-secrets.exec.php
index 9ac4c00..abc43fc 100644
--- a/libs/shared-secrets.exec.php
+++ b/libs/shared-secrets.exec.php
@@ -3,6 +3,36 @@
# prevent direct access
if (!defined("SYS11_SECRETS")) { die(""); }
+ ########## URL-ENCODING FUNCTIONS ##########
+
+ function url_base64_decode($url_base64_content) {
+ $result = null;
+
+ if (is_string($url_base64_content)) {
+ $result = str_replace(URL_BASE64_MARKER_B,
+ BASE64_MARKER_B,
+ str_replace(URL_BASE64_MARKER_A,
+ BASE64_MARKER_A,
+ $url_base64_content));
+ }
+
+ return $result;
+ }
+
+ function url_base64_encode($base64_content) {
+ $result = null;
+
+ if (is_string($base64_content)) {
+ $result = str_replace(BASE64_MARKER_B,
+ URL_BASE64_MARKER_B,
+ str_replace(BASE64_MARKER_A,
+ URL_BASE64_MARKER_A,
+ $base64_content));
+ }
+
+ return $result;
+ }
+
########## SYSTEM FUNCTIONS ##########
# calls $command, prints $stdin to its standard input and reads
@@ -142,23 +172,23 @@ function unstrip_message($content) {
$left = null;
$right = null;
- # search for double equation to fix line breaks
- $double_equation = strrpos($content, "==");
- if (false !== $double_equation) {
- $left = substr($content, 0, $double_equation+1);
- $right = substr($content, $double_equation+1, strlen($content)-$double_equation-1);
+ # search for equation sign from the end to fix line breaks
+ $equation_pos = strrpos($content, GPG_MESSAGE_PARTS_MARKER);
+ if (false !== $equation_pos) {
+ $left = substr($content, 0, $equation_pos);
+ $right = substr($content, $equation_pos);
} else {
$left = $content;
$right = null;
}
- $result = GPG_MESSAGE_PREFIX."\n".
- GPG_MESSAGE_COMMENT." Dummy\n".
- "\n".
- trim(chunk_split($left, GPG_MESSAGE_LINE_LENGTH, "\n"))."\n";
+ $result = GPG_MESSAGE_PREFIX.GPG_MESSAGE_LINE_SEPARATOR.
+ GPG_MESSAGE_COMMENT.GPG_MESSAGE_VALUE_SEPARATOR.GPG_MESSAGE_COMMENT_DUMMY.GPG_MESSAGE_LINE_SEPARATOR.
+ GPG_MESSAGE_LINE_SEPARATOR.
+ trim(chunk_split($left, GPG_MESSAGE_LINE_LENGTH, GPG_MESSAGE_LINE_SEPARATOR)).GPG_MESSAGE_LINE_SEPARATOR;
if (null !== $right) {
- $result .= $right."\n";
+ $result .= $right.GPG_MESSAGE_LINE_SEPARATOR;
}
$result .= GPG_MESSAGE_SUFFIX;
diff --git a/pages/read/get.php b/pages/read/get.php
index c7b30b3..5f1d7ca 100644
--- a/pages/read/get.php
+++ b/pages/read/get.php
@@ -26,7 +26,7 @@
Read a Secret:
-