ln/tests/testinc_ln_bolt8.cpp
//name: transport-initiator act2 bad MAC test
transport-initiator act2 bad MAC test
transport - initiator act2 bad MAC test
TEST_F(bolt8test, initiator_fail_act2_bad_mac)
{
    bool ret;
    ln_noise_t noise;
    const uint8_t LS_PRIV[] = {
        0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
        0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
        0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
        0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
    };
    const uint8_t RS_PUB[] = {
        0x02, 0x8d, 0x75, 0x00, 0xdd, 0x4c, 0x12, 0x68,
        0x5d, 0x1f, 0x56, 0x8b, 0x4c, 0x2b, 0x50, 0x48,
        0xe8, 0x53, 0x4b, 0x87, 0x33, 0x19, 0xf3, 0xa8,
        0xda, 0xa6, 0x12, 0xb4, 0x69, 0x13, 0x2e, 0xc7,
        0xf7,
    };
    ln_node_setkey(LS_PRIV);
    ret = ln_noise_handshake_init(&noise, RS_PUB);
    ASSERT_TRUE(ret);
    struct bolt8_t *pBolt = (struct bolt8_t *)noise.p_handshake;
    ASSERT_EQ(START_INITIATOR, pBolt->state);
    const uint8_t EPRIV[] = {
        0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12,
        0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12,
        0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12,
        0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12,
    };
    const uint8_t EPUB[] = {
        0x03, 0x63, 0x60, 0xe8, 0x56, 0x31, 0x0c, 0xe5,
        0xd2, 0x94, 0xe8, 0xbe, 0x33, 0xfc, 0x80, 0x70,
        0x77, 0xdc, 0x56, 0xac, 0x80, 0xd9, 0x5d, 0x9c,
        0xd4, 0xdd, 0xbd, 0x21, 0x32, 0x5e, 0xff, 0x73,
        0xf7,
    };
    memcpy(pBolt->e.priv, EPRIV, sizeof(EPRIV));
    memcpy(pBolt->e.pub, EPUB, sizeof(EPUB));
    utl_buf_t buf = UTL_BUF_INIT;
    ret = ln_noise_handshake_start(&noise, &buf, RS_PUB);
    ASSERT_TRUE(ret);
    const uint8_t OUTPUT_1S[50] = {
        0x00, 0x03, 0x63, 0x60, 0xe8, 0x56, 0x31, 0x0c,
        0xe5, 0xd2, 0x94, 0xe8, 0xbe, 0x33, 0xfc, 0x80,
        0x70, 0x77, 0xdc, 0x56, 0xac, 0x80, 0xd9, 0x5d,
        0x9c, 0xd4, 0xdd, 0xbd, 0x21, 0x32, 0x5e, 0xff,
        0x73, 0xf7, 0x0d, 0xf6, 0x08, 0x65, 0x51, 0x15,
        0x1f, 0x58, 0xb8, 0xaf, 0xe6, 0xc1, 0x95, 0x78,
        0x2c, 0x6a,
    };
    ASSERT_EQ(sizeof(OUTPUT_1S), buf.len);
    ASSERT_EQ(0, memcmp(OUTPUT_1S, buf.buf, sizeof(OUTPUT_1S)));
    utl_buf_free(&buf);
    const uint8_t INPUT_2S[50] = {
        0x00, 0x02, 0x46, 0x6d, 0x7f, 0xca, 0xe5, 0x63,
        0xe5, 0xcb, 0x09, 0xa0, 0xd1, 0x87, 0x0b, 0xb5,
        0x80, 0x34, 0x48, 0x04, 0x61, 0x78, 0x79, 0xa1,
        0x49, 0x49, 0xcf, 0x22, 0x28, 0x5f, 0x1b, 0xae,
        0x3f, 0x27, 0x6e, 0x24, 0x70, 0xb9, 0x3a, 0xac,
        0x58, 0x3c, 0x9e, 0xf6, 0xea, 0xfc, 0xa3, 0xf7,
        0x30, 0xaf,
    };
    utl_buf_alloccopy(&buf, INPUT_2S, sizeof(INPUT_2S));
    ret = ln_noise_handshake_recv(&noise, &buf);
    ASSERT_FALSE(ret);
    ASSERT_EQ(0, noise.p_handshake);
    ASSERT_FALSE(ln_noise_handshake_state(&noise));
    utl_buf_free(&buf);
    ret = ln_noise_handshake_recv(&noise, &buf);
    ASSERT_FALSE(ret);
}
TEST_F ( bolt8test , initiator_fail_act2_bad_mac ) { bool ret ; ln_noise_t noise ; const uint8_t LS_PRIV [ ] = { 0x11 , 0x11 , 0x11 , 0x11 , 0x11 , 0x11 , 0x11 , 0x11 , 0x11 , 0x11 , 0x11 , 0x11 , 0x11 , 0x11 , 0x11 , 0x11 , 0x11 , 0x11 , 0x11 , 0x11 , 0x11 , 0x11 , 0x11 , 0x11 , 0x11 , 0x11 , 0x11 , 0x11 , 0x11 , 0x11 , 0x11 , 0x11 , } ; const uint8_t RS_PUB [ ] = { 0x02 , 0x8d , 0x75 , 0x00 , 0xdd , 0x4c , 0x12 , 0x68 , 0x5d , 0x1f , 0x56 , 0x8b , 0x4c , 0x2b , 0x50 , 0x48 , 0xe8 , 0x53 , 0x4b , 0x87 , 0x33 , 0x19 , 0xf3 , 0xa8 , 0xda , 0xa6 , 0x12 , 0xb4 , 0x69 , 0x13 , 0x2e , 0xc7 , 0xf7 , } ; ln_node_setkey ( LS_PRIV ) ; ret = ln_noise_handshake_init ( & noise , RS_PUB ) ; ASSERT_TRUE ( ret ) ; struct bolt8_t * pBolt = ( struct bolt8_t * ) noise . p_handshake ; ASSERT_EQ ( START_INITIATOR , pBolt -> state ) ; const uint8_t EPRIV [ ] = { 0x12 , 0x12 , 0x12 , 0x12 , 0x12 , 0x12 , 0x12 , 0x12 , 0x12 , 0x12 , 0x12 , 0x12 , 0x12 , 0x12 , 0x12 , 0x12 , 0x12 , 0x12 , 0x12 , 0x12 , 0x12 , 0x12 , 0x12 , 0x12 , 0x12 , 0x12 , 0x12 , 0x12 , 0x12 , 0x12 , 0x12 , 0x12 , } ; const uint8_t EPUB [ ] = { 0x03 , 0x63 , 0x60 , 0xe8 , 0x56 , 0x31 , 0x0c , 0xe5 , 0xd2 , 0x94 , 0xe8 , 0xbe , 0x33 , 0xfc , 0x80 , 0x70 , 0x77 , 0xdc , 0x56 , 0xac , 0x80 , 0xd9 , 0x5d , 0x9c , 0xd4 , 0xdd , 0xbd , 0x21 , 0x32 , 0x5e , 0xff , 0x73 , 0xf7 , } ; memcpy ( pBolt -> e . priv , EPRIV , sizeof ( EPRIV ) ) ; memcpy ( pBolt -> e . pub , EPUB , sizeof ( EPUB ) ) ; utl_buf_t buf = UTL_BUF_INIT ; ret = ln_noise_handshake_start ( & noise , & buf , RS_PUB ) ; ASSERT_TRUE ( ret ) ; const uint8_t OUTPUT_1S [ 50 ] = { 0x00 , 0x03 , 0x63 , 0x60 , 0xe8 , 0x56 , 0x31 , 0x0c , 0xe5 , 0xd2 , 0x94 , 0xe8 , 0xbe , 0x33 , 0xfc , 0x80 , 0x70 , 0x77 , 0xdc , 0x56 , 0xac , 0x80 , 0xd9 , 0x5d , 0x9c , 0xd4 , 0xdd , 0xbd , 0x21 , 0x32 , 0x5e , 0xff , 0x73 , 0xf7 , 0x0d , 0xf6 , 0x08 , 0x65 , 0x51 , 0x15 , 0x1f , 0x58 , 0xb8 , 0xaf , 0xe6 , 0xc1 , 0x95 , 0x78 , 0x2c , 0x6a , } ; ASSERT_EQ ( sizeof ( OUTPUT_1S ) , buf . len ) ; ASSERT_EQ ( 0 , memcmp ( OUTPUT_1S , buf . buf , sizeof ( OUTPUT_1S ) ) ) ; utl_buf_free ( & buf ) ; const uint8_t INPUT_2S [ 50 ] = { 0x00 , 0x02 , 0x46 , 0x6d , 0x7f , 0xca , 0xe5 , 0x63 , 0xe5 , 0xcb , 0x09 , 0xa0 , 0xd1 , 0x87 , 0x0b , 0xb5 , 0x80 , 0x34 , 0x48 , 0x04 , 0x61 , 0x78 , 0x79 , 0xa1 , 0x49 , 0x49 , 0xcf , 0x22 , 0x28 , 0x5f , 0x1b , 0xae , 0x3f , 0x27 , 0x6e , 0x24 , 0x70 , 0xb9 , 0x3a , 0xac , 0x58 , 0x3c , 0x9e , 0xf6 , 0xea , 0xfc , 0xa3 , 0xf7 , 0x30 , 0xaf , } ; utl_buf_alloccopy ( & buf , INPUT_2S , sizeof ( INPUT_2S ) ) ; ret = ln_noise_handshake_recv ( & noise , & buf ) ; ASSERT_FALSE ( ret ) ; ASSERT_EQ ( 0 , noise . p_handshake ) ; ASSERT_FALSE ( ln_noise_handshake_state ( & noise ) ) ; utl_buf_free ( & buf ) ; ret = ln_noise_handshake_recv ( & noise , & buf ) ; ASSERT_FALSE ( ret ) ; }
name: transport-initiator act2 bad MAC test
name : transport - initiator act2 bad MAC test
//vector //const uint8_t RS_PRIV[] = { //    0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, //    0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, //    0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, //    0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, //}; //ephemeralの差し替え //Act One send //Act Two Receivce //input: 0x0002466d7fcae563e5cb09a0d1870bb580344804617879a14949cf22285f1bae3f276e2470b93aac583c9ef6eafca3f730af