ObjFW  Check-in [0fd8ab483c]

Overview
Comment:ofhash: Use OFSandbox's new unveiling
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 0fd8ab483cf9cdf43d7793d1256a69230efa28e26f1b8f5df39cfbac8586dcdf
User & Date: js on 2018-11-04 20:28:24
Other Links: manifest | tags
Context
2018-11-04
20:46
ofhttp: Use OFSandbox's new unveiling check-in: c554cd71da user: js tags: trunk
20:28
ofhash: Use OFSandbox's new unveiling check-in: 0fd8ab483c user: js tags: trunk
20:11
OFSecureData: Add support for preallocating memory check-in: 0487a81ced user: js tags: trunk
Changes

Modified utils/ofhash/OFHash.m from [634a2aa8de] to [ec67a88887].

16
17
18
19
20
21
22

23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
 */

#include "config.h"

#import "OFApplication.h"
#import "OFArray.h"
#import "OFFile.h"

#import "OFMD5Hash.h"
#import "OFRIPEMD160Hash.h"
#import "OFSHA1Hash.h"
#import "OFSHA224Hash.h"
#import "OFSHA256Hash.h"
#import "OFSHA384Hash.h"
#import "OFSHA512Hash.h"
#import "OFStdIOStream.h"
#import "OFLocale.h"
#import "OFSandbox.h"

#import "OFOpenItemFailedException.h"
#import "OFReadFailedException.h"

@interface OFHash: OFObject <OFApplicationDelegate>
@end








>







|
|
|







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
 */

#include "config.h"

#import "OFApplication.h"
#import "OFArray.h"
#import "OFFile.h"
#import "OFLocale.h"
#import "OFMD5Hash.h"
#import "OFRIPEMD160Hash.h"
#import "OFSHA1Hash.h"
#import "OFSHA224Hash.h"
#import "OFSHA256Hash.h"
#import "OFSHA384Hash.h"
#import "OFSHA512Hash.h"
#import "OFSandbox.h"
#import "OFSecureData.h"
#import "OFStdIOStream.h"

#import "OFOpenItemFailedException.h"
#import "OFReadFailedException.h"

@interface OFHash: OFObject <OFApplicationDelegate>
@end

76
77
78
79
80
81
82









83
84
85
86
87














88
89
90
91
92
93
94
{
	OFArray OF_GENERIC(OFString *) *arguments = [OFApplication arguments];
	id <OFCryptoHash> hash;
	bool first = true;
	int exitStatus = 0;

#ifdef OF_HAVE_SANDBOX









	OFSandbox *sandbox = [[OFSandbox alloc] init];
	@try {
		[sandbox setAllowsStdIO: true];
		[sandbox setAllowsReadingFiles: true];
		[sandbox setAllowsUserDatabaseReading: true];















		[OFApplication activateSandbox: sandbox];
	} @finally {
		[sandbox release];
	}
#endif








>
>
>
>
>
>
>
>
>
|




>
>
>
>
>
>
>
>
>
>
>
>
>
>







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
{
	OFArray OF_GENERIC(OFString *) *arguments = [OFApplication arguments];
	id <OFCryptoHash> hash;
	bool first = true;
	int exitStatus = 0;

#ifdef OF_HAVE_SANDBOX
	OFSandbox *sandbox;

	/*
	 * SHA-512 is the largest hash supported, so no matter which hash will
	 * be used in the end, this is enough secure memory.
	 */
	[OFSecureData preallocateMemoryWithSize:
	    class_getInstanceSize([OFSHA512Hash class])];

	sandbox = [[OFSandbox alloc] init];
	@try {
		[sandbox setAllowsStdIO: true];
		[sandbox setAllowsReadingFiles: true];
		[sandbox setAllowsUserDatabaseReading: true];

		for (OFString *path in arguments) {
			if (first) {
				first = false;
				continue;
			}

			[sandbox unveilPath: path
				permissions: @"r"];
		}
		first = true;

		[sandbox unveilPath: @LANGUAGE_DIR
			permissions: @"r"];

		[OFApplication activateSandbox: sandbox];
	} @finally {
		[sandbox release];
	}
#endif