| 78 | } |
| 79 | |
| 80 | struct ext_key *hsm_init(struct lightningd *ld) |
| 81 | { |
| 82 | u8 *msg; |
| 83 | int fds[2]; |
| 84 | struct ext_key *bip32_base; |
| 85 | u32 hsm_version; |
| 86 | struct pubkey unused; |
| 87 | |
| 88 | /* We actually send requests synchronously: only status is async. */ |
| 89 | if (socketpair(AF_LOCAL, SOCK_STREAM, 0, fds) != 0) |
| 90 | err(EXITCODE_HSM_GENERIC_ERROR, "Could not create hsm socketpair"); |
| 91 | |
| 92 | ld->hsm = new_global_subd(ld, "lightning_hsmd", |
| 93 | hsmd_wire_name, |
| 94 | hsm_msg, |
| 95 | take(&fds[1]), NULL); |
| 96 | if (!ld->hsm) |
| 97 | err(EXITCODE_HSM_GENERIC_ERROR, "Could not subd hsm"); |
| 98 | |
| 99 | ld->hsm_fd = fds[0]; |
| 100 | |
| 101 | if (ld->developer) { |
| 102 | struct tlv_hsmd_dev_preinit_tlvs *tlv; |
| 103 | |
| 104 | tlv = tlv_hsmd_dev_preinit_tlvs_new(tmpctx); |
| 105 | tlv->fail_preapprove = tal_dup(tlv, bool, |
| 106 | &ld->dev_hsmd_fail_preapprove); |
| 107 | tlv->no_preapprove_check = tal_dup(tlv, bool, |
| 108 | &ld->dev_hsmd_no_preapprove_check); |
| 109 | tlv->warn_on_overgrind = tal_dup(tlv, bool, |
| 110 | &ld->dev_hsmd_warn_on_overgrind); |
| 111 | |
| 112 | msg = towire_hsmd_dev_preinit(tmpctx, tlv); |
| 113 | if (!wire_sync_write(ld->hsm_fd, msg)) |
| 114 | err(EXITCODE_HSM_GENERIC_ERROR, "Writing preinit msg to hsm"); |
| 115 | } |
| 116 | |
| 117 | /* Create TLV for passphrase if needed */ |
| 118 | struct tlv_hsmd_init_tlvs *tlv = NULL; |
| 119 | if (ld->hsm_passphrase) { |
| 120 | tlv = tlv_hsmd_init_tlvs_new(tmpctx); |
| 121 | tlv->hsm_passphrase = tal_strdup(tlv, ld->hsm_passphrase); |
| 122 | } |
| 123 | |
| 124 | if (!wire_sync_write(ld->hsm_fd, towire_hsmd_init(tmpctx, |
| 125 | &chainparams->bip32_key_version, |
| 126 | chainparams, |
| 127 | NULL, |
| 128 | ld->dev_force_privkey, |
| 129 | ld->dev_force_bip32_seed, |
| 130 | ld->dev_force_channel_secrets, |
| 131 | ld->dev_force_channel_secrets_shaseed, |
| 132 | HSM_MIN_VERSION, |
| 133 | HSM_MAX_VERSION, |
| 134 | tlv))) |
| 135 | err(EXITCODE_HSM_GENERIC_ERROR, "Writing init msg to hsm"); |
| 136 | |
| 137 | bip32_base = tal(ld, struct ext_key); |
no test coverage detected