Check-in [058bbf6b95]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Add S/MIME patch
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 058bbf6b95686d3ba25b6f78a44ff10dba0ac07a
User & Date: rkeene 2020-09-02 20:07:04
Context
2020-09-02
20:08
Actually perform cleanup check-in: e27e3470a6 user: rkeene tags: trunk
20:07
Add S/MIME patch check-in: 058bbf6b95 user: rkeene tags: trunk
18:05
Add support for mremap, which fixes some memory issues so we can decrease the amount of available memory for each process check-in: b7941c450f user: rkeene tags: trunk
Changes

Changes to scripts/fossil/build-fossil-static.sh.

32
33
34
35
36
37
38



39
40
41
42
43
44
45
...
310
311
312
313
314
315
316









317
318
319
320
321
322
323

# File to create
result="fossil-${fossil_version}-${target}"

# Clean-up the result file before starting
rm -f "${result}" "${result}.info" "${result}.log"




# Helper functions
function random() {
	openssl rand -base64 6 | tr '/+' 'ZZ'
}

function downloadFile() {
	local downloadProgram downloadProgramPath file urls
................................................................................

	# Download the archive
	download "${fossil_url}" "${fossil_archive}" "${fossil_sha256}" || exit 1

	# Extract the archive
	extract "${fossil_archive}" "${fossil_dir}" || exit 1
	cd "${fossil_dir}" || exit 1










	# Setup cross-compiler
	## From Build-CC 0.9+
	eval $(~/root/cross-compilers/setup-cc "${target}") || exit 1

	# Setup to use LibreSSL we just compiled
	export PKG_CONFIG_PATH="${workdir}/libressl/INST/lib/pkgconfig"







>
>
>







 







>
>
>
>
>
>
>
>
>







32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
...
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335

# File to create
result="fossil-${fossil_version}-${target}"

# Clean-up the result file before starting
rm -f "${result}" "${result}.info" "${result}.log"

# Start Directory
start_dir="$(pwd)" || exit 1

# Helper functions
function random() {
	openssl rand -base64 6 | tr '/+' 'ZZ'
}

function downloadFile() {
	local downloadProgram downloadProgramPath file urls
................................................................................

	# Download the archive
	download "${fossil_url}" "${fossil_archive}" "${fossil_sha256}" || exit 1

	# Extract the archive
	extract "${fossil_archive}" "${fossil_dir}" || exit 1
	cd "${fossil_dir}" || exit 1

	# Apply patches
	for file in "${start_dir}/patches"/fossil-*.diff; do
		if [ ! -e "${file}" ]; then
			continue
		fi

		patch --no-backup-if-mismatch --force -p1 < "${file}" || exit 1
	done

	# Setup cross-compiler
	## From Build-CC 0.9+
	eval $(~/root/cross-compilers/setup-cc "${target}") || exit 1

	# Setup to use LibreSSL we just compiled
	export PKG_CONFIG_PATH="${workdir}/libressl/INST/lib/pkgconfig"

Added scripts/fossil/patches/fossil-6ca400a315-add-smime-support-1rsk.diff.



















































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
Binary files fossil-1.32.orig/src/.manifest.c.swp and fossil-1.32-smime/src/.manifest.c.swp differ
diff -uNr fossil-1.32.orig/src/manifest.c fossil-1.32-smime/src/manifest.c
--- fossil-1.32.orig/src/manifest.c	2015-03-14 08:20:34.000000000 -0500
+++ fossil-1.32-smime/src/manifest.c	2015-03-27 00:32:19.288505002 -0500
@@ -229,23 +229,163 @@
 ** Remove the PGP signature from the artifact, if there is one.
 */
 static void remove_pgp_signature(char **pz, int *pn){
-  char *z = *pz;
-  int n = *pn;
-  int i;
-  if( strncmp(z, "-----BEGIN PGP SIGNED MESSAGE-----", 34)!=0 ) return;
-  for(i=34; i<n && !after_blank_line(z+i); i++){}
-  if( i>=n ) return;
-  z += i;
-  n -= i;
-  *pz = z;
-  for(i=n-1; i>=0; i--){
-    if( z[i]=='\n' && strncmp(&z[i],"\n-----BEGIN PGP SIGNATURE-", 25)==0 ){
-      n = i+1;
-      break;
-    }
-  }
-  *pn = n;
-  return;
+	char *manifest, boundary[256];
+	int manifest_len;
+	int idx;
+	int line_start, line_end, boundary_start, boundary_end, boundary_len;
+	int manifestclear_start, manifestclear_end, manifestclear_len;
+	int allow_quote;
+
+	manifest = *pz;
+	manifest_len = *pn;
+
+	if (manifest_len >= 34 && memcmp(manifest, "-----BEGIN PGP SIGNED MESSAGE-----", 34) == 0) {
+		/* Process as a GPG clear-signed message */
+
+		for (idx = 34; idx < manifest_len && !after_blank_line(manifest + idx); idx++) {
+			/* Nothing to do here, we're just iterating over the contents */
+		}
+
+		if (idx >= manifest_len) {
+			return;
+		}
+
+		manifest += idx;
+		manifest_len -= idx;
+
+		if (manifest_len < 25) {
+			return;
+		}
+
+		for (idx = manifest_len - 25; idx >= 0; idx--) {
+			if (manifest[idx] != '\n') {
+				continue;
+			}
+
+			if (memcmp(&manifest[idx],"\n-----BEGIN PGP SIGNATURE-", 25) == 0) {
+				manifest_len = idx + 1;
+
+				break;
+			}
+		}
+
+		*pz = manifest;
+		*pn = manifest_len;
+	} else if (manifest_len >= 18 && memcmp(manifest, "MIME-Version: 1.0\n", 18) == 0) {
+		/* Proccess as a multipart MIME message */
+		if (manifest_len < 30) {
+			return;
+		}
+
+		line_start = -1;
+		for (idx = 18; idx < manifest_len - 30; idx++) {
+			if (memcmp(&manifest[idx], "Content-Type: multipart/signed", 30) != 0) {
+				continue;
+			}
+
+			line_start = idx;
+
+			break;
+		}
+
+		if (line_start == -1) {
+			return;
+		}
+
+		line_end = -1;
+		for (idx = line_start + 1; idx < manifest_len; idx++) {
+			if (manifest[idx] != '\n') {
+				continue;
+			}
+
+			line_end = idx - 1;
+
+			break;
+		}
+
+		if (line_end == -1) {
+			return;
+		}
+
+		boundary_start = -1;
+		allow_quote = 1;
+		for (idx = line_start; idx < line_end - 9; idx++) {
+			if (memcmp(&manifest[idx], "boundary=", 9) != 0) {
+				continue;
+			}
+
+			if (manifest[idx - 1] != ' ' && manifest[idx - 1] != ';') {
+				continue;
+			}
+
+			boundary_start = idx + 9;
+
+			if (manifest[idx + 9] == '"') {
+				allow_quote = 0;
+
+				boundary_start++;
+			}
+
+			break;
+		}
+		if (boundary_start == -1) {
+			return;
+		}
+
+		boundary_end = line_end;
+		for (idx = boundary_start; idx < line_end; idx++) {
+			if (manifest[idx] == '"' && allow_quote) {
+				continue;
+			}
+
+			if (manifest[idx] != ' ' && manifest[idx] != ';' && manifest[idx] != '"') {
+				continue;
+			}
+
+			boundary_end = idx;
+
+			break;
+		}
+
+		boundary_len = boundary_end - boundary_start;
+		boundary_len = snprintf(boundary, sizeof(boundary), "\n--%.*s\n", boundary_len, manifest + boundary_start);
+
+		manifestclear_start = -1;
+		for (idx = 0; idx < manifest_len - boundary_len; idx++) {
+			if (memcmp(&manifest[idx], boundary, boundary_len) != 0) {
+				continue;
+			}
+
+			manifestclear_start = idx + boundary_len;
+
+			break;
+		}
+
+		if (manifestclear_start == -1) {
+			return;
+		}
+
+		manifestclear_end = -1;
+		for (idx = manifestclear_start; idx < manifest_len - boundary_len; idx++) {
+			if (memcmp(&manifest[idx], boundary, boundary_len) != 0) {
+				continue;
+			}
+
+			manifestclear_end = idx;
+
+			break;
+		}
+
+		if (manifestclear_end == -1) {
+			return;
+		}
+
+		manifestclear_len = manifestclear_end - manifestclear_start;
+		*pz = &manifest[manifestclear_start];
+		*pn = manifestclear_len;
+	}
+
+	return;
 }
 
 /*