Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 32 additions & 42 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,55 +1,45 @@
idf_component_register(
SRCS
"src/json.c"
"src/storage.c"
"src/tlv.c"
"src/server.c"
"src/debug.c"
"src/accessories.c"
"src/base64.c"
"src/port.c"
"src/query_params.c"
"src/crypto.c"
INCLUDE_DIRS include
PRIV_INCLUDE_DIRS src
SRC_DIRS src
EXCLUDE_SRCS
"src/homekit_mdns.c"
"src/homekit_mdns_debug.c"
INCLUDE_DIRS "include"
PRIV_INCLUDE_DIRS "src"
REQUIRES wolfssl json http-parser mdns spi_flash
)

set_source_files_properties(src/storage.c
PROPERTIES COMPILE_FLAGS
-Wno-error=unused-value
)

set(WOLFSSL_C_FLAGS
"-DWOLFCRYPT_HAVE_SRP \
-DWOLFSSL_SHA512 \
-DWOLFSSL_BASE64_ENCODE \
-DNO_MD5 \
-DNO_SHA \
-DHAVE_HKDF \
-DHAVE_CHACHA \
-DHAVE_POLY1305 \
-DHAVE_ED25519 \
-DHAVE_CURVE25519 \
-DNO_SESSION_CACHE \
-DRSA_LOW_MEM \
-DGCM_SMALL \
-DUSE_SLOW_SHA512 \
-DWC_NO_HARDEN \
-DWOLFCRYPT_ONLY"
list(APPEND EXTRA_WOLFSSL_COMPILE_OPTIONS
-DWOLFCRYPT_HAVE_SRP
-DWOLFSSL_SHA512
-DWOLFSSL_BASE64_ENCODE
-DNO_MD5
-DNO_SHA
-DNO_DSA
-DHAVE_HKDF
-DHAVE_CHACHA
-DHAVE_POLY1305
-DHAVE_ED25519
-DHAVE_CURVE25519
-DNO_SESSION_CACHE
-DRSA_LOW_MEM
-DGCM_SMALL
-DUSE_SLOW_SHA512
-DWOLFCRYPT_ONLY
)

if(CONFIG_HOMEKIT_SMALL)
set(WOLFSSL_C_FLAGS "${WOLFSSL_C_FLAGS} -DCURVE25519_SMALL -DED25519_SMALL")
list(APPEND EXTRA_WOLFSSL_COMPILE_OPTIONS -DCURVE25519_SMALL -DED25519_SMALL)
endif()

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} \
${WOLFSSL_C_FLAGS} \
-DHOMEKIT_MAX_CLIENTS=${CONFIG_HOMEKIT_MAX_CLIENTS} \
-DSPIFLASH_BASE_ADDR=${CONFIG_HOMEKIT_SPI_FLASH_BASE_ADDR} \
-DESP_IDF"
idf_build_set_property(COMPILE_OPTIONS "${EXTRA_WOLFSSL_COMPILE_OPTIONS}" APPEND)

target_compile_options(${COMPONENT_LIB} PRIVATE
-Wno-error=unused-variable
-DHOMEKIT_MAX_CLIENTS=${CONFIG_HOMEKIT_MAX_CLIENTS}
-DSPIFLASH_BASE_ADDR=${CONFIG_HOMEKIT_SPI_FLASH_BASE_ADDR}
-DESP_IDF
)

if(CONFIG_HOMEKIT_DEBUG)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DHOMEKIT_DEBUG")
target_compile_options(${COMPONENT_LIB} PRIVATE -DHOMEKIT_DEBUG)
endif()
Binary file modified qrcode-example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 13 additions & 1 deletion src/crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,12 @@ int crypto_ed25519_generate(ed25519_key *key) {
return r;

WC_RNG rng;
r = wc_InitRng(&rng);
if (r) {
DEBUG("Failed to initialize RNG (code %d)", r);
return r;
}

r = wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, key);
if (r) {
DEBUG("Failed to generate key (code %d)", r);
Expand Down Expand Up @@ -479,10 +485,16 @@ int crypto_curve25519_generate(curve25519_key *key) {
}

WC_RNG rng;
r = wc_InitRng(&rng);
if (r) {
DEBUG("Failed to initialize RNG (code %d)", r);
return r;
}

r = wc_curve25519_make_key(&rng, 32, key);
if (r) {
crypto_curve25519_done(key);
return -1;
return r;
}

return 0;
Expand Down
9 changes: 9 additions & 0 deletions src/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -3698,6 +3698,15 @@ static void homekit_client_process(client_context_t *context) {
&context->server->parser, &homekit_http_parser_settings,
(char *)payload, payload_size
);

CLIENT_DEBUG(context, "Parser state: %d, error %s: %s", context->server->parser.state,
http_errno_name(context->server->parser.http_errno),
http_errno_description(context->server->parser.http_errno));
if ( context->server->parser.state == 1 ) {
CLIENT_DEBUG(context, "Reset parser");
http_parser_init(&context->server->parser, HTTP_REQUEST);
}

} while (data_available && !context->server->request_completed);

current_client_context = NULL;
Expand Down
Binary file added tools/SF-Mono-Bold.otf
Binary file not shown.
42 changes: 30 additions & 12 deletions tools/gen_qrcode
Original file line number Diff line number Diff line change
Expand Up @@ -39,32 +39,48 @@ def gen_homekit_setup_uri(category, password, setup_id, version=0, reserved=0, f
return 'X-HM://%s%s' % (''.join(reversed(encodedPayload)), setup_id)


def gen_homekit_qrcode(setup_uri, password):
code = qrcode.QRCode(version=2, border=0, box_size=12,
error_correction=qrcode.constants.ERROR_CORRECT_Q)
code.add_data(setup_uri)
def gen_homekit_qrcode(setup_uri, password, transparent=False):
back_color = 'transparent' if transparent else 'white'

# open template
img = PIL.Image.open(os.path.join(script_dir, 'qrcode.png'))
template = PIL.Image.open(os.path.join(script_dir, 'qrcode.png'))

img = PIL.Image.new('RGBA', template.size, None)
draw = PIL.ImageDraw.Draw(img)

if not transparent:
draw.rounded_rectangle((5, 5, img.width-5, img.height-5), 60, fill='white')

img.paste(template, (0, 0), template)

# add QR code to it
img.paste(code.make_image().get_image(), (50, 180))
code = qrcode.QRCode(version=2, border=0, box_size=12.5,
error_correction=qrcode.constants.ERROR_CORRECT_Q)
code.add_data(setup_uri)
img.paste(
code.
make_image(fill_color='black',
back_color='transparent' if transparent else 'white').
get_image().
resize((320, 320)),
(40, 180)
)

# add password digits
setup_code = password.replace('-', '')


font = PIL.ImageFont.truetype(os.path.join(script_dir, 'Roboto-Bold.ttf'), 56)
draw = PIL.ImageDraw.Draw(img)
font = PIL.ImageFont.truetype(os.path.join(script_dir, 'SF-Mono-Bold.otf'), 69)

for i in range(4):
draw.text((170 + i*50, 35), setup_code[i], font=font, fill=(0, 0, 0))
draw.text((170 + i*50, 95), setup_code[i+4], font=font, fill=(0, 0, 0))
draw.text((173 + i*49, 38-13), setup_code[i], font=font, fill=(0, 0, 0))
draw.text((173 + i*49, 88), setup_code[i+4], font=font, fill=(0, 0, 0))

return img


def main():
parser = argparse.ArgumentParser()
parser.add_argument('--transparent', action='store_true')
parser.add_argument('category', type=int)
parser.add_argument('password')
parser.add_argument('setup_id')
Expand All @@ -80,7 +96,9 @@ def main():

setupURI = gen_homekit_setup_uri(args.category, args.password, args.setup_id)

qrcodeImage = gen_homekit_qrcode(setupURI, args.password)
qrcodeImage = gen_homekit_qrcode(
setupURI, args.password, transparent=args.transparent
)

qrcodeImage.save(args.output_image)

Expand Down
Binary file modified tools/qrcode.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.