| 1533 | } |
| 1534 | |
| 1535 | u8 *hsmd_handle_client_message(const tal_t *ctx, struct hsmd_client *client, |
| 1536 | const u8 *msg) |
| 1537 | { |
| 1538 | enum hsmd_wire t = fromwire_peektype(msg); |
| 1539 | |
| 1540 | hsmd_status_debug("Client: Received message %d from client", t); |
| 1541 | |
| 1542 | /* Before we do anything else, is this client allowed to do |
| 1543 | * what he asks for? */ |
| 1544 | if (!hsmd_check_client_capabilities(client, t)) |
| 1545 | return hsmd_status_bad_request_fmt( |
| 1546 | client, msg, "does not have capability to run %d", t); |
| 1547 | |
| 1548 | /* If we aren't initialized yet we better get an init message |
| 1549 | * first. Otherwise we don't load the secret and every |
| 1550 | * signature we produce is just going to be junk. */ |
| 1551 | if (!initialized && t != WIRE_HSMD_INIT) |
| 1552 | hsmd_status_failed(STATUS_FAIL_MASTER_IO, |
| 1553 | "hsmd was not initialized correctly, expected " |
| 1554 | "message type %d, got %d", |
| 1555 | WIRE_HSMD_INIT, t); |
| 1556 | |
| 1557 | /* Now actually go and do what the client asked for */ |
| 1558 | switch (t) { |
| 1559 | case WIRE_HSMD_INIT: |
| 1560 | case WIRE_HSMD_CLIENT_HSMFD: |
| 1561 | /* Not implemented yet. Should not have been passed here yet. */ |
| 1562 | return hsmd_status_bad_request_fmt( |
| 1563 | client, msg, |
| 1564 | "Message of type %s should be handled externally to " |
| 1565 | "libhsmd", |
| 1566 | hsmd_wire_name(t)); |
| 1567 | |
| 1568 | case WIRE_HSMD_NEW_CHANNEL: |
| 1569 | return handle_new_channel(client, msg); |
| 1570 | case WIRE_HSMD_READY_CHANNEL: |
| 1571 | return handle_ready_channel(client, msg); |
| 1572 | case WIRE_HSMD_GET_OUTPUT_SCRIPTPUBKEY: |
| 1573 | return handle_get_output_scriptpubkey(client, msg); |
| 1574 | case WIRE_HSMD_CHECK_FUTURE_SECRET: |
| 1575 | return handle_check_future_secret(client, msg); |
| 1576 | case WIRE_HSMD_ECDH_REQ: |
| 1577 | return handle_ecdh(client, msg); |
| 1578 | case WIRE_HSMD_SIGN_INVOICE: |
| 1579 | return handle_sign_invoice(client, msg); |
| 1580 | case WIRE_HSMD_SIGN_OPTION_WILL_FUND_OFFER: |
| 1581 | return handle_sign_option_will_fund_offer(client, msg); |
| 1582 | case WIRE_HSMD_SIGN_BOLT12: |
| 1583 | return handle_sign_bolt12(client, msg); |
| 1584 | case WIRE_HSMD_SIGN_MESSAGE: |
| 1585 | return handle_sign_message(client, msg); |
| 1586 | case WIRE_HSMD_GET_CHANNEL_BASEPOINTS: |
| 1587 | return handle_get_channel_basepoints(client, msg); |
| 1588 | case WIRE_HSMD_CANNOUNCEMENT_SIG_REQ: |
| 1589 | return handle_cannouncement_sig(client, msg); |
| 1590 | case WIRE_HSMD_NODE_ANNOUNCEMENT_SIG_REQ: |
| 1591 | return handle_sign_node_announcement(client, msg); |
| 1592 | case WIRE_HSMD_CUPDATE_SIG_REQ: |
no test coverage detected