diff --git a/.gitmodules b/.gitmodules index eef51baa..82b7f291 100644 --- a/.gitmodules +++ b/.gitmodules @@ -22,3 +22,6 @@ [submodule "platform-darwin/External/libsodium"] path = platform-darwin/External/libsodium url = https://github.com/jedisct1/libsodium.git +[submodule "platform-darwin/External/libjson-c"] + path = platform-darwin/External/libjson-c + url = https://github.com/json-c/json-c.git diff --git a/core/c/mpw-marshall-util.c b/core/c/mpw-marshall-util.c new file mode 100644 index 00000000..885340e3 --- /dev/null +++ b/core/c/mpw-marshall-util.c @@ -0,0 +1,114 @@ +//============================================================================== +// This file is part of Master Password. +// Copyright (c) 2011-2017, Maarten Billemont. +// +// Master Password is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Master Password is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You can find a copy of the GNU General Public License in the +// LICENSE file. Alternatively, see . +//============================================================================== + +#include + +#include "mpw-marshall-util.h" +#include "mpw-util.h" + +char *mpw_get_token(char **in, char *eol, char *delim) { + + // Skip leading spaces. + for (; **in == ' '; ++*in); + + // Find characters up to the first delim. + size_t len = strcspn( *in, delim ); + char *token = len && len <= (size_t)(eol - *in)? strndup( *in, len ): NULL; + + // Advance past the delimitor. + *in = min( eol, *in + len + 1 ); + return token; +} + +time_t mpw_mktime( + const char *time) { + + struct tm tm = { .tm_isdst = -1, .tm_gmtoff = 0 }; + if (time && sscanf( time, "%4d-%2d-%2dT%2d:%2d:%2dZ", + &tm.tm_year, &tm.tm_mon, &tm.tm_mday, + &tm.tm_hour, &tm.tm_min, &tm.tm_sec ) == 6) { + tm.tm_year -= 1900; // tm_year 0 = rfc3339 year 1900 + tm.tm_mon -= 1; // tm_mon 0 = rfc3339 month 1 + return mktime( &tm ); + } + + return false; +} + +json_object *mpw_get_json_section( + json_object *obj, const char *section) { + + json_object *json_value = obj; + char *sectionTokenizer = strdup( section ), *sectionToken = sectionTokenizer; + for (sectionToken = strtok( sectionToken, "." ); sectionToken; sectionToken = strtok( NULL, "." )) + if (!json_object_object_get_ex( json_value, sectionToken, &json_value ) || !json_value) { + dbg( "While resolving: %s: Missing value for: %s\n", section, sectionToken ); + json_value = NULL; + break; + } + free( sectionTokenizer ); + + return json_value; +} + +const char *mpw_get_json_string( + json_object *obj, const char *section, const char *defaultValue) { + + json_object *json_value = mpw_get_json_section( obj, section ); + if (!json_value) + return defaultValue; + + return json_object_get_string( json_value ); +} + +int32_t mpw_get_json_int( + json_object *obj, const char *section, int32_t defaultValue) { + + json_object *json_value = mpw_get_json_section( obj, section ); + if (!json_value) + return defaultValue; + + return json_object_get_int( json_value ); +} + +bool mpw_get_json_boolean( + json_object *obj, const char *section, bool defaultValue) { + + json_object *json_value = mpw_get_json_section( obj, section ); + if (!json_value) + return defaultValue; + + return json_object_get_boolean( json_value ) == TRUE; +} + +bool mpw_update_masterKey(MPMasterKey *masterKey, MPAlgorithmVersion *masterKeyAlgorithm, MPAlgorithmVersion targetKeyAlgorithm, + const char *fullName, const char *masterPassword) { + + if (*masterKeyAlgorithm != targetKeyAlgorithm) { + mpw_free( *masterKey, MPMasterKeySize ); + *masterKeyAlgorithm = targetKeyAlgorithm; + *masterKey = mpw_masterKeyForUser( + fullName, masterPassword, *masterKeyAlgorithm ); + if (!*masterKey) { + err( "Couldn't derive master key for user %s, algorithm %d.\n", fullName, *masterKeyAlgorithm ); + return false; + } + } + + return true; +} diff --git a/core/c/mpw-marshall-util.h b/core/c/mpw-marshall-util.h new file mode 100644 index 00000000..49a242b3 --- /dev/null +++ b/core/c/mpw-marshall-util.h @@ -0,0 +1,69 @@ +//============================================================================== +// This file is part of Master Password. +// Copyright (c) 2011-2017, Maarten Billemont. +// +// Master Password is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Master Password is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You can find a copy of the GNU General Public License in the +// LICENSE file. Alternatively, see . +//============================================================================== + +#ifndef _MPW_MARSHALL_UTIL_H +#define _MPW_MARSHALL_UTIL_H + +#include +#include + +#include "mpw-algorithm.h" + +/// Type parsing. + +/** Get a token from a string by searching until the first character in delim, no farther than eol. + * The input string reference is advanced beyond the token delimitor if one is found. + * @return A new string containing the token or NULL if the delim wasn't found before eol. */ +char *mpw_get_token( + char **in, char *eol, char *delim); +/** Convert an RFC 3339 time string into epoch time. */ +time_t mpw_mktime( + const char *time); + +/// JSON parsing. + +/** Search for a JSON child object in a JSON object tree. + * @param section A dot-delimited list of JSON object keys to walk toward the child object. + * @return A new JSON object or NULL if one of the section's object keys was not found in the source object's tree. */ +json_object *mpw_get_json_section( + json_object *obj, const char *section); +/** Search for a string in a JSON object tree. + * @param section A dot-delimited list of JSON object keys to walk toward the child object. + * @return A new string or defaultValue if one of the section's object keys was not found in the source object's tree. */ +const char *mpw_get_json_string( + json_object *obj, const char *section, const char *defaultValue); +/** Search for an integer in a JSON object tree. + * @param section A dot-delimited list of JSON object keys to walk toward the child object. + * @return The integer value or defaultValue if one of the section's object keys was not found in the source object's tree. */ +int32_t mpw_get_json_int( + json_object *obj, const char *section, int32_t defaultValue); +/** Search for a boolean in a JSON object tree. + * @param section A dot-delimited list of JSON object keys to walk toward the child object. + * @return The boolean value or defaultValue if one of the section's object keys was not found in the source object's tree. */ +bool mpw_get_json_boolean( + json_object *obj, const char *section, bool defaultValue); + +/// mpw. + +/** Calculate a master key if the target master key algorithm is different from the given master key algorithm. + * @return false if an error occurred during the derivation of the master key. */ +bool mpw_update_masterKey( + MPMasterKey *masterKey, MPAlgorithmVersion *masterKeyAlgorithm, MPAlgorithmVersion targetKeyAlgorithm, + const char *fullName, const char *masterPassword); + +#endif // _MPW_MARSHALL_UTIL_H diff --git a/core/c/mpw-marshall.c b/core/c/mpw-marshall.c index d977cd07..8576fa00 100644 --- a/core/c/mpw-marshall.c +++ b/core/c/mpw-marshall.c @@ -19,56 +19,10 @@ #include #include -#include -#include + #include "mpw-marshall.h" #include "mpw-util.h" - -static char *mpw_get_token(char **in, char *eol, char *delim) { - - // Skip leading spaces. - for (; **in == ' '; ++*in); - - // Find characters up to the first delim. - size_t len = strcspn( *in, delim ); - char *token = len? strndup( *in, len ): NULL; - - // Advance past the delimitor. - *in = min( eol, *in + len + 1 ); - return token; -} - -static time_t mpw_mktime( - const char *time) { - - struct tm tm = { .tm_isdst = -1, .tm_gmtoff = 0 }; - if (time && sscanf( time, "%4d-%2d-%2dT%2d:%2d:%2dZ", - &tm.tm_year, &tm.tm_mon, &tm.tm_mday, - &tm.tm_hour, &tm.tm_min, &tm.tm_sec ) == 6) { - tm.tm_year -= 1900; // tm_year 0 = rfc3339 year 1900 - tm.tm_mon -= 1; // tm_mon 0 = rfc3339 month 1 - return mktime( &tm ); - } - - return false; -} - -static bool mpw_update_masterKey(MPMasterKey *masterKey, MPAlgorithmVersion *masterKeyAlgorithm, MPAlgorithmVersion targetKeyAlgorithm, - const char *fullName, const char *masterPassword) { - - if (*masterKeyAlgorithm != targetKeyAlgorithm) { - mpw_free( *masterKey, MPMasterKeySize ); - *masterKeyAlgorithm = targetKeyAlgorithm; - *masterKey = mpw_masterKeyForUser( - fullName, masterPassword, *masterKeyAlgorithm ); - if (!*masterKey) { - err( "Couldn't derive master key for user %s, algorithm %d.\n", fullName, *masterKeyAlgorithm ); - return false; - } - } - - return true; -} +#include "mpw-marshall-util.h" MPMarshalledUser *mpw_marshall_user( const char *fullName, const char *masterPassword, const MPAlgorithmVersion algorithmVersion) { @@ -138,10 +92,10 @@ bool mpw_marshal_free( MPMarshalledUser *marshalledUser) { bool success = true; - for (int s = 0; s < marshalledUser->sites_count; ++s) { + for (size_t s = 0; s < marshalledUser->sites_count; ++s) { MPMarshalledSite site = marshalledUser->sites[s]; success &= mpw_free_string( site.name ); - for (int q = 0; q < site.questions_count; ++q) { + for (size_t q = 0; q < site.questions_count; ++q) { MPMarshalledQuestion question = site.questions[q]; success &= mpw_free_string( question.keyword ); } @@ -157,7 +111,7 @@ bool mpw_marshal_free( #define try_asprintf(...) ({ if (asprintf( __VA_ARGS__ ) < 0) return false; }) -bool mpw_marshall_write_flat( +static bool mpw_marshall_write_flat( char **out, const MPMarshalledUser *user, MPMarshallError *error) { *error = MPMarshallErrorInternal; @@ -204,7 +158,7 @@ bool mpw_marshall_write_flat( try_asprintf( out, "# used used type name\t name\tpassword\n" ); // Sites. - for (int s = 0; s < user->sites_count; ++s) { + for (size_t s = 0; s < user->sites_count; ++s) { MPMarshalledSite site = user->sites[s]; if (!site.name || !strlen( site.name )) continue; @@ -235,7 +189,7 @@ bool mpw_marshall_write_flat( return true; } -bool mpw_marshall_write_json( +static bool mpw_marshall_write_json( char **out, const MPMarshalledUser *user, MPMarshallError *error) { *error = MPMarshallErrorInternal; @@ -271,20 +225,20 @@ bool mpw_marshall_write_json( // Section: "user" json_object *json_user = json_object_new_object(); json_object_object_add( json_file, "user", json_user ); - json_object_object_add( json_user, "avatar", json_object_new_int( user->avatar ) ); + json_object_object_add( json_user, "avatar", json_object_new_int( (int)user->avatar ) ); json_object_object_add( json_user, "full_name", json_object_new_string( user->name ) ); if (strftime( dateString, sizeof( dateString ), "%FT%TZ", gmtime( &user->lastUsed ) )) json_object_object_add( json_user, "last_used", json_object_new_string( dateString ) ); json_object_object_add( json_user, "key_id", json_object_new_string( mpw_id_buf( masterKey, MPMasterKeySize ) ) ); - json_object_object_add( json_user, "algorithm", json_object_new_int( user->algorithm ) ); - json_object_object_add( json_user, "default_type", json_object_new_int( user->defaultType ) ); + json_object_object_add( json_user, "algorithm", json_object_new_int( (int)user->algorithm ) ); + json_object_object_add( json_user, "default_type", json_object_new_int( (int)user->defaultType ) ); // Section "sites" json_object *json_sites = json_object_new_object(); json_object_object_add( json_file, "sites", json_sites ); - for (int s = 0; s < user->sites_count; ++s) { + for (size_t s = 0; s < user->sites_count; ++s) { MPMarshalledSite site = user->sites[s]; if (!site.name || !strlen( site.name )) continue; @@ -306,22 +260,22 @@ bool mpw_marshall_write_json( json_object *json_site = json_object_new_object(); json_object_object_add( json_sites, site.name, json_site ); - json_object_object_add( json_site, "type", json_object_new_int( site.type ) ); - json_object_object_add( json_site, "counter", json_object_new_int( site.counter ) ); - json_object_object_add( json_site, "algorithm", json_object_new_int( site.algorithm ) ); + json_object_object_add( json_site, "type", json_object_new_int( (int)site.type ) ); + json_object_object_add( json_site, "counter", json_object_new_int( (int)site.counter ) ); + json_object_object_add( json_site, "algorithm", json_object_new_int( (int)site.algorithm ) ); if (content) json_object_object_add( json_site, "password", json_object_new_string( content ) ); if (site.loginName) json_object_object_add( json_site, "login_name", json_object_new_string( site.loginName ) ); json_object_object_add( json_site, "login_generated", json_object_new_boolean( site.loginGenerated ) ); - json_object_object_add( json_site, "uses", json_object_new_int( site.uses ) ); + json_object_object_add( json_site, "uses", json_object_new_int( (int)site.uses ) ); if (strftime( dateString, sizeof( dateString ), "%FT%TZ", gmtime( &site.lastUsed ) )) json_object_object_add( json_site, "last_used", json_object_new_string( dateString ) ); json_object *json_site_questions = json_object_new_object(); json_object_object_add( json_site, "questions", json_site_questions ); - for (int q = 0; q < site.questions_count; ++q) { + for (size_t q = 0; q < site.questions_count; ++q) { MPMarshalledQuestion question = site.questions[q]; if (!question.keyword) continue; @@ -366,7 +320,7 @@ bool mpw_marshall_write( return false; } -MPMarshalledUser *mpw_marshall_read_flat( +static MPMarshalledUser *mpw_marshall_read_flat( char *in, const char *masterPassword, MPMarshallError *error) { *error = MPMarshallErrorInternal; @@ -405,7 +359,7 @@ MPMarshalledUser *mpw_marshall_read_flat( char *headerName = mpw_get_token( &positionInLine, endOfLine, ":\n" ); char *headerValue = mpw_get_token( &positionInLine, endOfLine, "\n" ); if (!headerName || !headerValue) { - err( "Invalid header: %s\n", strndup( positionInLine, endOfLine - positionInLine ) ); + err( "Invalid header: %s\n", strndup( positionInLine, (size_t)(endOfLine - positionInLine) ) ); *error = MPMarshallErrorStructure; return NULL; } @@ -563,53 +517,7 @@ MPMarshalledUser *mpw_marshall_read_flat( return user; } -static json_object *mpw_marshall_get_json_section( - json_object *obj, const char *section) { - - json_object *json_value = obj; - char *sectionTokenizer = strdup( section ), *sectionToken = sectionTokenizer; - for (sectionToken = strtok( sectionToken, "." ); sectionToken; sectionToken = strtok( NULL, "." )) - if (!json_object_object_get_ex( json_value, sectionToken, &json_value ) || !json_value) { - dbg( "While resolving: %s: Missing value for: %s\n", section, sectionToken ); - json_value = NULL; - break; - } - free( sectionTokenizer ); - - return json_value; -} - -static const char *mpw_marshall_get_json_string( - json_object *obj, const char *section, const char *defaultValue) { - - json_object *json_value = mpw_marshall_get_json_section( obj, section ); - if (!json_value) - return defaultValue; - - return json_object_get_string( json_value ); -} - -static int32_t mpw_marshall_get_json_int( - json_object *obj, const char *section, int32_t defaultValue) { - - json_object *json_value = mpw_marshall_get_json_section( obj, section ); - if (!json_value) - return defaultValue; - - return json_object_get_int( json_value ); -} - -static bool mpw_marshall_get_json_boolean( - json_object *obj, const char *section, bool defaultValue) { - - json_object *json_value = mpw_marshall_get_json_section( obj, section ); - if (!json_value) - return defaultValue; - - return json_object_get_boolean( json_value ) == TRUE; -} - -MPMarshalledUser *mpw_marshall_read_json( +static MPMarshalledUser *mpw_marshall_read_json( char *in, const char *masterPassword, MPMarshallError *error) { *error = MPMarshallErrorInternal; @@ -630,27 +538,27 @@ MPMarshalledUser *mpw_marshall_read_json( MPMarshalledUser *user = NULL; // Section: "export" - unsigned int fileFormat = (unsigned int)mpw_marshall_get_json_int( json_file, "export.format", 0 ); + unsigned int fileFormat = (unsigned int)mpw_get_json_int( json_file, "export.format", 0 ); if (fileFormat < 1) { err( "Unsupported format: %u\n", fileFormat ); *error = MPMarshallErrorFormat; return NULL; } - bool fileRedacted = mpw_marshall_get_json_boolean( json_file, "export.redacted", true ); - const char *fileDate = mpw_marshall_get_json_string( json_file, "export.date", NULL ); + bool fileRedacted = mpw_get_json_boolean( json_file, "export.redacted", true ); + //const char *fileDate = mpw_get_json_string( json_file, "export.date", NULL ); // unused // Section: "user" - unsigned int avatar = (unsigned int)mpw_marshall_get_json_int( json_file, "user.avatar", 0 ); - const char *fullName = mpw_marshall_get_json_string( json_file, "user.full_name", NULL ); - const char *lastUsed = mpw_marshall_get_json_string( json_file, "user.last_used", NULL ); - const char *keyID = mpw_marshall_get_json_string( json_file, "user.key_id", NULL ); - MPAlgorithmVersion algorithm = (MPAlgorithmVersion)mpw_marshall_get_json_int( json_file, "user.algorithm", MPAlgorithmVersionCurrent ); + unsigned int avatar = (unsigned int)mpw_get_json_int( json_file, "user.avatar", 0 ); + const char *fullName = mpw_get_json_string( json_file, "user.full_name", NULL ); + const char *lastUsed = mpw_get_json_string( json_file, "user.last_used", NULL ); + const char *keyID = mpw_get_json_string( json_file, "user.key_id", NULL ); + MPAlgorithmVersion algorithm = (MPAlgorithmVersion)mpw_get_json_int( json_file, "user.algorithm", MPAlgorithmVersionCurrent ); if (algorithm < MPAlgorithmVersionFirst || algorithm > MPAlgorithmVersionLast) { err( "Invalid user algorithm version: %u\n", algorithm ); *error = MPMarshallErrorIllegal; return NULL; } - MPSiteType defaultType = (MPSiteType)mpw_marshall_get_json_int( json_file, "user.default_type", MPSiteTypeDefault ); + MPSiteType defaultType = (MPSiteType)mpw_get_json_int( json_file, "user.default_type", MPSiteTypeDefault ); if (!fullName || !strlen( fullName )) { err( "Missing value for full name.\n" ); @@ -678,24 +586,24 @@ MPMarshalledUser *mpw_marshall_read_json( // Section "sites" json_object_iter json_site; - json_object *json_sites = mpw_marshall_get_json_section( json_file, "sites" ); + json_object *json_sites = mpw_get_json_section( json_file, "sites" ); json_object_object_foreachC( json_sites, json_site ) { - MPSiteType siteType = (MPSiteType)mpw_marshall_get_json_int( json_site.val, "type", user->defaultType ); - uint32_t siteCounter = (uint32_t)mpw_marshall_get_json_int( json_site.val, "counter", 1 ); - MPAlgorithmVersion siteAlgorithm = (MPAlgorithmVersion)mpw_marshall_get_json_int( json_site.val, "algorithm", user->algorithm ); + MPSiteType siteType = (MPSiteType)mpw_get_json_int( json_site.val, "type", (int)user->defaultType ); + uint32_t siteCounter = (uint32_t)mpw_get_json_int( json_site.val, "counter", 1 ); + MPAlgorithmVersion siteAlgorithm = (MPAlgorithmVersion)mpw_get_json_int( json_site.val, "algorithm", (int)user->algorithm ); if (siteAlgorithm < MPAlgorithmVersionFirst || siteAlgorithm > MPAlgorithmVersionLast) { err( "Invalid site algorithm version: %u\n", siteAlgorithm ); *error = MPMarshallErrorIllegal; return NULL; } - const char *siteContent = mpw_marshall_get_json_string( json_site.val, "password", NULL ); - const char *siteLoginName = mpw_marshall_get_json_string( json_site.val, "login_name", NULL ); - bool siteLoginGenerated = mpw_marshall_get_json_boolean( json_site.val, "login_generated", false ); - unsigned int siteUses = (unsigned int)mpw_marshall_get_json_int( json_site.val, "uses", 0 ); - const char *siteLastUsed = mpw_marshall_get_json_string( json_site.val, "last_used", NULL ); + const char *siteContent = mpw_get_json_string( json_site.val, "password", NULL ); + const char *siteLoginName = mpw_get_json_string( json_site.val, "login_name", NULL ); + bool siteLoginGenerated = mpw_get_json_boolean( json_site.val, "login_generated", false ); + unsigned int siteUses = (unsigned int)mpw_get_json_int( json_site.val, "uses", 0 ); + const char *siteLastUsed = mpw_get_json_string( json_site.val, "last_used", NULL ); - json_object *json_site_mpw = mpw_marshall_get_json_section( json_site.val, "_ext_mpw" ); - const char *siteURL = mpw_marshall_get_json_string( json_site_mpw, "url", NULL ); + json_object *json_site_mpw = mpw_get_json_section( json_site.val, "_ext_mpw" ); + const char *siteURL = mpw_get_json_string( json_site_mpw, "url", NULL ); MPMarshalledSite *site = mpw_marshall_site( user, json_site.key, siteType, siteCounter, siteAlgorithm ); if (!site) { @@ -723,7 +631,7 @@ MPMarshalledUser *mpw_marshall_read_json( } json_object_iter json_site_question; - json_object *json_site_questions = mpw_marshall_get_json_section( json_site.val, "questions" ); + json_object *json_site_questions = mpw_get_json_section( json_site.val, "questions" ); json_object_object_foreachC( json_site_questions, json_site_question ) mpw_marshal_question( site, json_site_question.key ); } diff --git a/core/c/mpw-marshall.h b/core/c/mpw-marshall.h index d70ed6c9..5af21b0f 100644 --- a/core/c/mpw-marshall.h +++ b/core/c/mpw-marshall.h @@ -18,13 +18,10 @@ #ifndef _MPW_MARSHALL_H #define _MPW_MARSHALL_H -#include "mpw-algorithm.h" -#ifdef NS_ENUM -#define enum(_type, _name) NS_ENUM(_type, _name) -#else -#define enum(_type, _name) _type _name; enum -#endif +#include + +#include "mpw-algorithm.h" //// Types. diff --git a/core/c/mpw-types.h b/core/c/mpw-types.h index f2b313a6..e6043e85 100644 --- a/core/c/mpw-types.h +++ b/core/c/mpw-types.h @@ -18,6 +18,7 @@ #ifndef _MPW_TYPES_H #define _MPW_TYPES_H + #include #include #include diff --git a/core/c/mpw-util.c b/core/c/mpw-util.c index 3bef5b29..67807cee 100644 --- a/core/c/mpw-util.c +++ b/core/c/mpw-util.c @@ -16,8 +16,6 @@ // LICENSE file. Alternatively, see . //============================================================================== -#include -#include #include #include @@ -35,6 +33,7 @@ #endif #include "mpw-util.h" + int mpw_verbosity = inf_level; bool mpw_push_buf(uint8_t **const buffer, size_t *const bufferSize, const void *pushBuffer, const size_t pushSize) { @@ -100,7 +99,7 @@ uint8_t const *mpw_scrypt(const size_t keySize, const char *secret, const uint8_ return NULL; } #elif HAS_SODIUM - if (crypto_pwhash_scryptsalsa208sha256_ll( (const uint8_t *)secret, strlen( secret ), salt, saltSize, N, r, p, key, keySize) != 0 ) { + if (crypto_pwhash_scryptsalsa208sha256_ll( (const uint8_t *)secret, strlen( secret ), salt, saltSize, N, r, p, key, keySize ) != 0) { mpw_free( key, keySize ); return NULL; } @@ -156,8 +155,8 @@ bool mpw_id_buf_equals(const char *id1, const char *id2) { if (size != strlen( id2 )) return false; - for (int c = 0; c < size; ++c) - if (tolower(id1[c]) != tolower(id2[c])) + for (size_t c = 0; c < size; ++c) + if (tolower( id1[c] ) != tolower( id2[c] )) return false; return true; @@ -226,7 +225,8 @@ const char *mpw_identicon(const char *fullName, const char *masterPassword) { "♨", "♩", "♪", "♫", "⚐", "⚑", "⚔", "⚖", "⚙", "⚠", "⌘", "⏎", "✄", "✆", "✈", "✉", "✌" }; - const uint8_t *identiconSeed = mpw_hmac_sha256( (const uint8_t *)masterPassword, strlen( masterPassword ), (const uint8_t *)fullName, strlen( fullName ) ); + const uint8_t *identiconSeed = mpw_hmac_sha256( (const uint8_t *)masterPassword, strlen( masterPassword ), (const uint8_t *)fullName, + strlen( fullName ) ); if (!identiconSeed) return NULL; diff --git a/core/c/mpw-util.h b/core/c/mpw-util.h index 0f4b754c..d0197453 100644 --- a/core/c/mpw-util.h +++ b/core/c/mpw-util.h @@ -16,12 +16,13 @@ // LICENSE file. Alternatively, see . //============================================================================== -#include -#include "mpw-types.h" - #ifndef _MPW_UTIL_H #define _MPW_UTIL_H +#include + +#include "mpw-types.h" + //// Logging. #ifndef trc diff --git a/platform-darwin/External/libjson-c b/platform-darwin/External/libjson-c new file mode 160000 index 00000000..fcad0ec0 --- /dev/null +++ b/platform-darwin/External/libjson-c @@ -0,0 +1 @@ +Subproject commit fcad0ec015c1275e7231ee4582bc78b89a2e96da diff --git a/platform-darwin/MasterPassword-macOS.xcodeproj/project.pbxproj b/platform-darwin/MasterPassword-macOS.xcodeproj/project.pbxproj index 94d3a2f6..f4781501 100644 --- a/platform-darwin/MasterPassword-macOS.xcodeproj/project.pbxproj +++ b/platform-darwin/MasterPassword-macOS.xcodeproj/project.pbxproj @@ -39,7 +39,6 @@ DA1C7AAF1F1A8F24009A3551 /* libsodium.a in Frameworks */ = {isa = PBXBuildFile; fileRef = DA0979571E9A824700F0BFE8 /* libsodium.a */; }; DA1C7AB01F1A8F24009A3551 /* libxml2.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = DA09745D1E99586600F0BFE8 /* libxml2.tbd */; }; DA1C7AC31F1A8FBA009A3551 /* mpw-cli.c in Sources */ = {isa = PBXBuildFile; fileRef = DA1C7AB91F1A8F6E009A3551 /* mpw-cli.c */; }; - DA1C7AC81F1A8FD8009A3551 /* mpw-marshall.c in Sources */ = {isa = PBXBuildFile; fileRef = DAA449D31EEC4B6B00E7BDD5 /* mpw-marshall.c */; }; DA1C7ACA1F1A8FD8009A3551 /* mpw-types.c in Sources */ = {isa = PBXBuildFile; fileRef = DA6773C21A4746AF004F356A /* mpw-types.c */; }; DA1C7ACB1F1A8FD8009A3551 /* mpw-util.c in Sources */ = {isa = PBXBuildFile; fileRef = DA6773C51A4746AF004F356A /* mpw-util.c */; }; DA1C7ACD1F1A8FD8009A3551 /* mpw-algorithm.c in Sources */ = {isa = PBXBuildFile; fileRef = DA6773BB1A4746AF004F356A /* mpw-algorithm.c */; }; @@ -84,7 +83,6 @@ DA4DAE951A7D8117003E5423 /* MPTypes.m in Sources */ = {isa = PBXBuildFile; fileRef = DA4DAE931A7D8117003E5423 /* MPTypes.m */; }; DA5180CA19FF2F9200A587E9 /* MPAlgorithmV2.m in Sources */ = {isa = PBXBuildFile; fileRef = DA5180C719FF2F9200A587E9 /* MPAlgorithmV2.m */; }; DA5180CE19FF307E00A587E9 /* MPAppDelegate_Store.m in Sources */ = {isa = PBXBuildFile; fileRef = DA5180CD19FF307E00A587E9 /* MPAppDelegate_Store.m */; }; - DA531CC31EFF3BF4008C72CB /* mpw-marshall.c in Sources */ = {isa = PBXBuildFile; fileRef = DAA449D31EEC4B6B00E7BDD5 /* mpw-marshall.c */; }; DA5E5CF61724A667003798D8 /* MPAlgorithm.m in Sources */ = {isa = PBXBuildFile; fileRef = DA5E5C981724A667003798D8 /* MPAlgorithm.m */; }; DA5E5CF71724A667003798D8 /* MPAlgorithmV0.m in Sources */ = {isa = PBXBuildFile; fileRef = DA5E5C9A1724A667003798D8 /* MPAlgorithmV0.m */; }; DA5E5CF81724A667003798D8 /* MPAlgorithmV1.m in Sources */ = {isa = PBXBuildFile; fileRef = DA5E5C9C1724A667003798D8 /* MPAlgorithmV1.m */; }; @@ -108,6 +106,8 @@ DA6774431A474A3B004F356A /* mpw-algorithm.c in Sources */ = {isa = PBXBuildFile; fileRef = DA6773BB1A4746AF004F356A /* mpw-algorithm.c */; }; DA6774451A474A3B004F356A /* mpw-types.c in Sources */ = {isa = PBXBuildFile; fileRef = DA6773C21A4746AF004F356A /* mpw-types.c */; }; DA6774461A474A3B004F356A /* mpw-util.c in Sources */ = {isa = PBXBuildFile; fileRef = DA6773C51A4746AF004F356A /* mpw-util.c */; }; + DA7471A31F2B71AE005F3468 /* mpw-marshall-util.c in Sources */ = {isa = PBXBuildFile; fileRef = DA7471A01F2B71A9005F3468 /* mpw-marshall-util.c */; }; + DA7471A61F2B71B9005F3468 /* mpw-marshall-util.c in Sources */ = {isa = PBXBuildFile; fileRef = DA7471A01F2B71A9005F3468 /* mpw-marshall-util.c */; }; DA89D4EC1A51EABD00AC64D7 /* Pearl-Cocoa.h in Headers */ = {isa = PBXBuildFile; fileRef = DA89D4EA1A51EABD00AC64D7 /* Pearl-Cocoa.h */; }; DA89D4ED1A51EABD00AC64D7 /* Pearl-Cocoa.m in Sources */ = {isa = PBXBuildFile; fileRef = DA89D4EB1A51EABD00AC64D7 /* Pearl-Cocoa.m */; }; DA8ED895192906920099B726 /* PearlTween.m in Sources */ = {isa = PBXBuildFile; fileRef = DA8ED891192906920099B726 /* PearlTween.m */; }; @@ -898,6 +898,8 @@ DA6773C51A4746AF004F356A /* mpw-util.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = "mpw-util.c"; sourceTree = ""; }; DA6773C61A4746AF004F356A /* mpw-util.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "mpw-util.h"; sourceTree = ""; }; DA67743B1A474A03004F356A /* mpw-test */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = "mpw-test"; sourceTree = BUILT_PRODUCTS_DIR; }; + DA7471A01F2B71A9005F3468 /* mpw-marshall-util.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = "mpw-marshall-util.c"; sourceTree = ""; }; + DA7471A11F2B71A9005F3468 /* mpw-marshall-util.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "mpw-marshall-util.h"; sourceTree = ""; }; DA771FE51E6E15A1004D7EDE /* MasterPassword-Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "MasterPassword-Prefix.pch"; sourceTree = ""; }; DA831A271A6E1146000AC234 /* mpw-algorithm_v0.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = "mpw-algorithm_v0.c"; sourceTree = ""; }; DA831A281A6E1146000AC234 /* mpw-algorithm_v1.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = "mpw-algorithm_v1.c"; sourceTree = ""; }; @@ -1814,6 +1816,8 @@ DA831A2A1A6E1146000AC234 /* mpw-algorithm_v3.c */, DA6773BB1A4746AF004F356A /* mpw-algorithm.c */, DA6773BC1A4746AF004F356A /* mpw-algorithm.h */, + DA7471A01F2B71A9005F3468 /* mpw-marshall-util.c */, + DA7471A11F2B71A9005F3468 /* mpw-marshall-util.h */, DAA449D31EEC4B6B00E7BDD5 /* mpw-marshall.c */, DAA449D41EEC4B6B00E7BDD5 /* mpw-marshall.h */, DA6773C21A4746AF004F356A /* mpw-types.c */, @@ -2526,6 +2530,7 @@ DA1C7AAB1F1A8F24009A3551 /* mpw-types.c in Sources */, DA1C7AAC1F1A8F24009A3551 /* mpw-util.c in Sources */, DA1C7AC31F1A8FBA009A3551 /* mpw-cli.c in Sources */, + DA7471A31F2B71AE005F3468 /* mpw-marshall-util.c in Sources */, DA1C7AAD1F1A8F24009A3551 /* mpw-algorithm.c in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -2534,7 +2539,6 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - DA1C7AC81F1A8FD8009A3551 /* mpw-marshall.c in Sources */, DA1C7ACA1F1A8FD8009A3551 /* mpw-types.c in Sources */, DA1C7ACB1F1A8FD8009A3551 /* mpw-util.c in Sources */, DA1C7AD71F1A8FE6009A3551 /* mpw-bench.c in Sources */, @@ -2585,6 +2589,7 @@ DA4DAE941A7D8117003E5423 /* MPAlgorithmV3.m in Sources */, DA4DAE951A7D8117003E5423 /* MPTypes.m in Sources */, 93D393A1646430FAAC73E7FE /* MPMacApplication.m in Sources */, + DA7471A61F2B71B9005F3468 /* mpw-marshall-util.c in Sources */, 93D398D1F5D8CD5A22AF6929 /* MPGradientView.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -2593,7 +2598,6 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - DA531CC31EFF3BF4008C72CB /* mpw-marshall.c in Sources */, DA1C7AD81F1A8FF4009A3551 /* mpw-tests-util.c in Sources */, DA6774451A474A3B004F356A /* mpw-types.c in Sources */, DA6774461A474A3B004F356A /* mpw-util.c in Sources */, diff --git a/platform-independent/cli-c/build b/platform-independent/cli-c/build index f8893f71..b5b9d7dd 100755 --- a/platform-independent/cli-c/build +++ b/platform-independent/cli-c/build @@ -259,11 +259,12 @@ mpw() { (( mpw_color )) && CFLAGS+=( -DMPW_COLOR ) LDFLAGS+=( -l"curses" ) (( mpw_json )) && CFLAGS+=( -DMPW_JSON ) LDFLAGS+=( -l"json-c" ) - cc "${CFLAGS[@]}" "$@" -c core/mpw-algorithm.c -o core/mpw-algorithm.o - cc "${CFLAGS[@]}" "$@" -c core/mpw-types.c -o core/mpw-types.o - cc "${CFLAGS[@]}" "$@" -c core/mpw-util.c -o core/mpw-util.o - cc "${CFLAGS[@]}" "$@" -c core/mpw-marshall.c -o core/mpw-marshall.o - cc "${CFLAGS[@]}" "$@" "core/mpw-algorithm.o" "core/mpw-types.o" "core/mpw-util.o" "core/mpw-marshall.o" \ + cc "${CFLAGS[@]}" "$@" -c core/mpw-algorithm.c -o core/mpw-algorithm.o + cc "${CFLAGS[@]}" "$@" -c core/mpw-types.c -o core/mpw-types.o + cc "${CFLAGS[@]}" "$@" -c core/mpw-util.c -o core/mpw-util.o + cc "${CFLAGS[@]}" "$@" -c core/mpw-marshall-util.c -o core/mpw-marshall-util.o + cc "${CFLAGS[@]}" "$@" -c core/mpw-marshall.c -o core/mpw-marshall.o + cc "${CFLAGS[@]}" "$@" "core/mpw-algorithm.o" "core/mpw-types.o" "core/mpw-util.o" "core/mpw-marshall-util.o" "core/mpw-marshall.o" \ "${LDFLAGS[@]}" "cli/mpw-cli.c" -o "mpw" echo "done! Now run ./install or use ./mpw" } diff --git a/platform-independent/cli-c/cli/mpw-cli.c b/platform-independent/cli-c/cli/mpw-cli.c index 7d5ac9c2..ba14b029 100644 --- a/platform-independent/cli-c/cli/mpw-cli.c +++ b/platform-independent/cli-c/cli/mpw-cli.c @@ -240,7 +240,7 @@ int main(int argc, char *const argv[]) { masterPassword = strdup( user->masterPassword ); algorithmVersion = user->algorithm; siteType = user->defaultType; - for (int s = 0; s < user->sites_count; ++s) { + for (size_t s = 0; s < user->sites_count; ++s) { MPMarshalledSite site = user->sites[s]; if (strcmp( siteName, site.name ) == 0) { siteType = site.type;