| 653 | } |
| 654 | |
| 655 | static u8 *check_channel_announcement(const tal_t *ctx, |
| 656 | const struct node_id *node1_id, const struct node_id *node2_id, |
| 657 | const struct pubkey *bitcoin1_key, const struct pubkey *bitcoin2_key, |
| 658 | const secp256k1_ecdsa_signature *node1_sig, |
| 659 | const secp256k1_ecdsa_signature *node2_sig, |
| 660 | const secp256k1_ecdsa_signature *bitcoin1_sig, |
| 661 | const secp256k1_ecdsa_signature *bitcoin2_sig, const u8 *announcement) |
| 662 | { |
| 663 | /* 2 byte msg type + 256 byte signatures */ |
| 664 | int offset = 258; |
| 665 | struct sha256_double hash; |
| 666 | sha256_double(&hash, announcement + offset, |
| 667 | tal_count(announcement) - offset); |
| 668 | |
| 669 | if (!check_signed_hash_nodeid(&hash, node1_sig, node1_id)) { |
| 670 | return towire_warningfmt(ctx, NULL, |
| 671 | "Bad node_signature_1 %s hash %s" |
| 672 | " on channel_announcement %s", |
| 673 | type_to_string(tmpctx, |
| 674 | secp256k1_ecdsa_signature, |
| 675 | node1_sig), |
| 676 | type_to_string(tmpctx, |
| 677 | struct sha256_double, |
| 678 | &hash), |
| 679 | tal_hex(tmpctx, announcement)); |
| 680 | } |
| 681 | if (!check_signed_hash_nodeid(&hash, node2_sig, node2_id)) { |
| 682 | return towire_warningfmt(ctx, NULL, |
| 683 | "Bad node_signature_2 %s hash %s" |
| 684 | " on channel_announcement %s", |
| 685 | type_to_string(tmpctx, |
| 686 | secp256k1_ecdsa_signature, |
| 687 | node2_sig), |
| 688 | type_to_string(tmpctx, |
| 689 | struct sha256_double, |
| 690 | &hash), |
| 691 | tal_hex(tmpctx, announcement)); |
| 692 | } |
| 693 | if (!check_signed_hash(&hash, bitcoin1_sig, bitcoin1_key)) { |
| 694 | return towire_warningfmt(ctx, NULL, |
| 695 | "Bad bitcoin_signature_1 %s hash %s" |
| 696 | " on channel_announcement %s", |
| 697 | type_to_string(tmpctx, |
| 698 | secp256k1_ecdsa_signature, |
| 699 | bitcoin1_sig), |
| 700 | type_to_string(tmpctx, |
| 701 | struct sha256_double, |
| 702 | &hash), |
| 703 | tal_hex(tmpctx, announcement)); |
| 704 | } |
| 705 | if (!check_signed_hash(&hash, bitcoin2_sig, bitcoin2_key)) { |
| 706 | return towire_warningfmt(ctx, NULL, |
| 707 | "Bad bitcoin_signature_2 %s hash %s" |
| 708 | " on channel_announcement %s", |
| 709 | type_to_string(tmpctx, |
| 710 | secp256k1_ecdsa_signature, |
| 711 | bitcoin2_sig), |
| 712 | type_to_string(tmpctx, |