Overview
Comment: | Add OFSecureData |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
d4d9072480081505027856dcfa2d5761 |
User & Date: | js on 2018-04-07 14:13:48 |
Other Links: | manifest | tags |
Context
2018-04-07
| ||
20:05 | OF*Hash: Make use of the new OFSecureData check-in: a5006f1d31 user: js tags: trunk | |
14:13 | Add OFSecureData check-in: d4d9072480 user: js tags: trunk | |
2018-03-19
| ||
23:42 | Ignore empty and slash-only path components check-in: 69148d4e5e user: js tags: trunk | |
Changes
Modified configure.ac from [b503c44591] to [be01d4c07f].
︙ | ︙ | |||
782 783 784 785 786 787 788 789 790 791 792 793 794 795 | dnl When disabling __thread, it doesn't freeze, but all symbols dnl are wrong. ;; *) AC_CHECK_FUNCS(dladdr) ;; esac AC_ARG_ENABLE(threads, AS_HELP_STRING([--disable-threads], [disable thread support])) AS_IF([test x"$enable_threads" != x"no"], [ AC_MSG_CHECKING(for threads) case "$host_os" in | > > > | 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 | dnl When disabling __thread, it doesn't freeze, but all symbols dnl are wrong. ;; *) AC_CHECK_FUNCS(dladdr) ;; esac AC_CHECK_HEADERS(sys/mman.h) AC_CHECK_FUNCS(mmap mlock) AC_ARG_ENABLE(threads, AS_HELP_STRING([--disable-threads], [disable thread support])) AS_IF([test x"$enable_threads" != x"no"], [ AC_MSG_CHECKING(for threads) case "$host_os" in |
︙ | ︙ |
Modified src/Makefile from [41173c04c6] to [0390ef4ea5].
︙ | ︙ | |||
58 59 60 61 62 63 64 65 66 67 68 69 70 71 | OFObject+Serialization.m \ OFOptionsParser.m \ OFPair.m \ ${OFPROCESS_M} \ OFRIPEMD160Hash.m \ OFRunLoop.m \ OFSandbox.m \ OFSeekableStream.m \ OFSet.m \ OFSHA1Hash.m \ OFSHA224Hash.m \ OFSHA224Or256Hash.m \ OFSHA256Hash.m \ OFSHA384Hash.m \ | > | 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | OFObject+Serialization.m \ OFOptionsParser.m \ OFPair.m \ ${OFPROCESS_M} \ OFRIPEMD160Hash.m \ OFRunLoop.m \ OFSandbox.m \ OFSecureData.m \ OFSeekableStream.m \ OFSet.m \ OFSHA1Hash.m \ OFSHA224Hash.m \ OFSHA224Or256Hash.m \ OFSHA256Hash.m \ OFSHA384Hash.m \ |
︙ | ︙ |
Modified src/OFData.m from [8d40ffbf81] to [b6b253b742].
︙ | ︙ | |||
128 129 130 131 132 133 134 | { self = [super init]; @try { if (itemSize == 0) @throw [OFInvalidArgumentException exception]; | < < > > | | 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 | { self = [super init]; @try { if (itemSize == 0) @throw [OFInvalidArgumentException exception]; _items = [self allocMemoryWithSize: itemSize count: count]; _itemSize = itemSize; _count = count; memcpy(_items, items, count * itemSize); } @catch (id e) { [self release]; @throw e; } return self; } |
︙ | ︙ |
Modified src/OFMutableData.h from [1cee6cebc3] to [4a4b799e1f].
︙ | ︙ | |||
185 186 187 188 189 190 191 | #if defined(__clang__) || defined(DOXYGEN) /*! * @brief All items of the OFMutableData as a C array. * * @warning The pointer is only valid until the OFMutableData is changed! * * Modifying the returned array directly is allowed and will change the contents | | | | | | 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 | #if defined(__clang__) || defined(DOXYGEN) /*! * @brief All items of the OFMutableData as a C array. * * @warning The pointer is only valid until the OFMutableData is changed! * * Modifying the returned array directly is allowed and will change the contents * of the data. */ @property (readonly, nonatomic) void *items OF_RETURNS_INNER_POINTER; /*! * @brief The first item of the OFMutableData or `NULL`. * * Modifying the returned item directly is allowed and will change the contents * of the data. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) void *firstItem OF_RETURNS_INNER_POINTER; /*! * @brief Last item of the OFMutableData or `NULL`. * * Modifying the returned item directly is allowed and will change the contents * of the data. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) void *lastItem OF_RETURNS_INNER_POINTER; #else - (void *)items; - (nullable void *)firstItem; - (nullable void *)lastItem; #endif /*! * @brief Returns a specific item of the OFMutableData. * * Modifying the returned item directly is allowed and will change the contents * of the data. * * @param index The number of the item to return * @return The specified item of the OFMutableData */ - (void *)itemAtIndex: (size_t)index OF_RETURNS_INNER_POINTER; @end OF_ASSUME_NONNULL_END |
Modified src/OFMutableData.m from [419f5baa46] to [e5870d8b2c].
︙ | ︙ | |||
111 112 113 114 115 116 117 | { self = [super initWithItems: items itemSize: itemSize count: count]; _capacity = _count; | < < < < < < < < < < < < < | 111 112 113 114 115 116 117 118 119 120 121 122 123 124 | { self = [super initWithItems: items itemSize: itemSize count: count]; _capacity = _count; return self; } - (instancetype)initWithItemsNoCopy: (void *)items itemSize: (size_t)itemSize count: (size_t)count freeWhenDone: (bool)freeWhenDone |
︙ | ︙ |
Added src/OFSecureData.h version [67148514e7].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 | /* * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, * 2018 * Jonathan Schleifer <js@heap.zone> * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the * Q Public License 1.0, which can be found in the file LICENSE.QPL included in * the packaging of this file. * * Alternatively, it may be distributed under the terms of the GNU General * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFData.h" OF_ASSUME_NONNULL_BEGIN /*! * @class OFSecureData OFSecureData.h ObjFW/OFSecureData.h * * @brief A class for storing arbitrary data in secure memory, securely wiping * it when it gets deallocated. * * @note Secure memory might be unavailable on the platform, in which case this * falls back to insecure (potentially swappable) memory. */ @interface OFSecureData: OFData { size_t _mappingSize; } /*! * @brief Creates a new, autoreleased OFSecureData with count items of item * size 1, all set to zero. * * @param count The number of zero items the OFSecureData should contain * @return A new, autoreleased OFSecureData */ + (instancetype)dataWithCount: (size_t)count; /*! * @brief Creates a new, autoreleased OFSecureData with count items of the * specified item size, all set to zero. * * @param itemSize The size of a single item in the OFSecureData in bytes * @param count The number of zero items the OFSecureData should contain * @return A new, autoreleased OFSecureData */ + (instancetype)dataWithItemSize: (size_t)itemSize count: (size_t)count; #ifdef OF_HAVE_FILES + (instancetype)dataWithContentsOfFile: (OFString *)path OF_UNAVAILABLE; #endif + (instancetype)dataWithContentsOfURL: (OFURL *)URL OF_UNAVAILABLE; + (instancetype)dataWithStringRepresentation: (OFString *)string OF_UNAVAILABLE; + (instancetype)dataWithBase64EncodedString: (OFString *)string OF_UNAVAILABLE; + (instancetype)dataWithSerialization: (OFXMLElement *)element OF_UNAVAILABLE; /*! * @brief Initializes an already allocated OFSecureData with count items of * item size 1, all set to zero. * * @param count The number of zero items the OFSecureData should contain * @return An initialized OFSecureData */ - (instancetype)initWithCount: (size_t)count; /*! * @brief Initializes an already allocated OFSecureData with count items of the * specified item size, all set to zero. * * @param itemSize The size of a single item in the OFSecureData in bytes * @param count The number of zero items the OFSecureData should contain * @return An initialized OFSecureData */ - (instancetype)initWithItemSize: (size_t)itemSize count: (size_t)count; /*! * @brief Zeroes the data. */ - (void)zero; #ifdef OF_HAVE_FILES - (instancetype)initWithContentsOfFile: (OFString *)path OF_UNAVAILABLE; #endif - (instancetype)initWithContentsOfURL: (OFURL *)URL OF_UNAVAILABLE; - (instancetype)initWithStringRepresentation: (OFString *)string OF_UNAVAILABLE; - (instancetype)initWithBase64EncodedString: (OFString *)string OF_UNAVAILABLE; - (instancetype)initWithSerialization: (OFXMLElement *)element OF_UNAVAILABLE; - (OFString *)stringRepresentation OF_UNAVAILABLE; - (OFString *)stringByBase64Encoding OF_UNAVAILABLE; #ifdef OF_HAVE_FILES - (void)writeToFile: (OFString *)path OF_UNAVAILABLE; #endif - (void)writeToURL: (OFURL *)URL OF_UNAVAILABLE; - (OFXMLElement *)XMLElementBySerializing OF_UNAVAILABLE; - (OFData *)messagePackRepresentation OF_UNAVAILABLE; @end @interface OFSecureData (MutableRetrieving) /* GCC does not like overriding properties with a different type. */ #if defined(__clang__) || defined(DOXYGEN) /*! * @brief All items of the OFSecureData as a C array. * * Modifying the returned array directly is allowed and will change the contents * of the data. */ @property (readonly, nonatomic) void *items OF_RETURNS_INNER_POINTER; /*! * @brief The first item of the OFSecureData or `NULL`. * * Modifying the returned item directly is allowed and will change the contents * of the data. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) void *firstItem OF_RETURNS_INNER_POINTER; /*! * @brief Last item of the OFSecureData or `NULL`. * * Modifying the returned item directly is allowed and will change the contents * of the data. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) void *lastItem OF_RETURNS_INNER_POINTER; #else - (void *)items; - (nullable void *)firstItem; - (nullable void *)lastItem; #endif /*! * @brief Returns a specific item of the OFSecureData. * * Modifying the returned item directly is allowed and will change the contents * of the data array. * * @param index The number of the item to return * @return The specified item of the OFSecureData */ - (void *)itemAtIndex: (size_t)index OF_RETURNS_INNER_POINTER; @end OF_ASSUME_NONNULL_END |
Added src/OFSecureData.m version [9dff65470c].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 | /* * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, * 2018 * Jonathan Schleifer <js@heap.zone> * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the * Q Public License 1.0, which can be found in the file LICENSE.QPL included in * the packaging of this file. * * Alternatively, it may be distributed under the terms of the GNU General * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" #include <stdlib.h> #ifdef HAVE_SYS_MMAN_H # include <sys/mman.h> #endif #import "OFSecureData.h" #import "OFString.h" #import "OFSystemInfo.h" #import "OFInvalidArgumentException.h" #import "OFOutOfMemoryException.h" #import "OFOutOfRangeException.h" @implementation OFSecureData + (instancetype)dataWithCount: (size_t)count { return [[[self alloc] initWithCount: count] autorelease]; } + (instancetype)dataWithItemSize: (size_t)itemSize count: (size_t)count { return [[[self alloc] initWithItemSize: itemSize count: count] autorelease]; } #ifdef OF_HAVE_FILES + (instancetype)dataWithContentsOfFile: (OFString *)path { OF_UNRECOGNIZED_SELECTOR } #endif + (instancetype)dataWithContentsOfURL: (OFURL *)URL { OF_UNRECOGNIZED_SELECTOR } + (instancetype)dataWithStringRepresentation: (OFString *)string { OF_UNRECOGNIZED_SELECTOR } + (instancetype)dataWithBase64EncodedString: (OFString *)string { OF_UNRECOGNIZED_SELECTOR } + (instancetype)dataWithSerialization: (OFXMLElement *)element { OF_UNRECOGNIZED_SELECTOR } - (instancetype)initWithCount: (size_t)count { return [self initWithItemSize: 1 count: count]; } - (instancetype)initWithItemSize: (size_t)itemSize count: (size_t)count { self = [super init]; @try { size_t size, pageSize; if OF_UNLIKELY (itemSize == 0) @throw [OFInvalidArgumentException exception]; if OF_UNLIKELY (count > SIZE_MAX / itemSize) @throw [OFOutOfRangeException exception]; size = itemSize * count; pageSize = [OFSystemInfo pageSize]; #if defined(HAVE_MMAP) && defined(HAVE_MLOCK) && defined(MAP_ANON) _mappingSize = OF_ROUND_UP_POW2(pageSize, size); if OF_UNLIKELY (_mappingSize < size) @throw [OFOutOfRangeException exception]; if OF_UNLIKELY ((_items = mmap(NULL, _mappingSize, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0)) == MAP_FAILED) @throw [OFOutOfMemoryException exceptionWithRequestedSize: _mappingSize]; if OF_UNLIKELY (mlock(_items, _mappingSize) != 0) @throw [OFOutOfMemoryException exceptionWithRequestedSize: _mappingSize]; of_explicit_memset(_items, 0, _mappingSize); #else if OF_UNLIKELY ((_items = malloc(size)) == NULL) @throw [OFOutOfMemoryException exceptionWithRequestedSize: size]; of_explicit_memset(_items, 0, size); #endif _itemSize = itemSize; _count = count; } @catch (id e) { [self release]; @throw e; } return self; } - (instancetype)initWithItems: (const void *)items itemSize: (size_t)itemSize count: (size_t)count { self = [self initWithItemSize: itemSize count: count]; memcpy(_items, items, count * itemSize); return self; } - (instancetype)initWithItemsNoCopy: (void *)items itemSize: (size_t)itemSize count: (size_t)count freeWhenDone: (bool)freeWhenDone { self = [self initWithItems: items itemSize: itemSize count: count]; if (freeWhenDone) { of_explicit_memset(items, 0, count * itemSize); free(items); } return self; } #ifdef OF_HAVE_FILES - (instancetype)initWithContentsOfFile: (OFString *)path { OF_INVALID_INIT_METHOD } #endif - (instancetype)initWithContentsOfURL: (OFURL *)URL { OF_INVALID_INIT_METHOD } - (instancetype)initWithStringRepresentation: (OFString *)string { OF_INVALID_INIT_METHOD } - (instancetype)initWithBase64EncodedString: (OFString *)string { OF_INVALID_INIT_METHOD } - (instancetype)initWithSerialization: (OFXMLElement *)element { OF_INVALID_INIT_METHOD } - (void)dealloc { [self zero]; #if defined(HAVE_MMAP) && defined(HAVE_MLOCK) && defined(MAP_ANON) munlock(_items, _mappingSize); munmap(_items, _mappingSize); #else free(_items); #endif [super dealloc]; } - (void)zero { #if defined(HAVE_MMAP) && defined(HAVE_MLOCK) && defined(MAP_ANON) of_explicit_memset(_items, 0, _mappingSize); #else of_explicit_memset(_items, 0, _count * _itemSize); #endif } - (id)copy { return [[OFSecureData alloc] initWithItems: _items itemSize: _itemSize count: _count]; } - (id)mutableCopy { return [[OFSecureData alloc] initWithItems: _items itemSize: _itemSize count: _count]; } - (OFString *)description { return @"<OFSecureData>"; } - (OFString *)stringRepresentation { OF_UNRECOGNIZED_SELECTOR } - (OFString *)stringByBase64Encoding { OF_UNRECOGNIZED_SELECTOR } #ifdef OF_HAVE_FILES - (void)writeToFile: (OFString *)path { OF_UNRECOGNIZED_SELECTOR } #endif - (void)writeToURL: (OFURL *)URL { OF_UNRECOGNIZED_SELECTOR } - (OFXMLElement *)XMLElementBySerializing { OF_UNRECOGNIZED_SELECTOR } - (OFData *)messagePackRepresentation { OF_UNRECOGNIZED_SELECTOR } @end |
Modified src/ObjFW.h from [8e512daaa9] to [55f533bb8f].
︙ | ︙ | |||
20 21 22 23 24 25 26 27 28 29 30 31 32 33 | #import "OFAutoreleasePool.h" #import "OFString.h" #import "OFCharacterSet.h" #import "OFData.h" #import "OFArray.h" #import "OFList.h" #import "OFSortedList.h" #import "OFDictionary.h" #import "OFMapTable.h" | > | 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | #import "OFAutoreleasePool.h" #import "OFString.h" #import "OFCharacterSet.h" #import "OFData.h" #import "OFArray.h" #import "OFSecureData.h" #import "OFList.h" #import "OFSortedList.h" #import "OFDictionary.h" #import "OFMapTable.h" |
︙ | ︙ |