Skip to content

Commit 952a1e9

Browse files
authored
Merge pull request #460 from nasa/385-operational-sas-for-testing-in-nos3
WIP [#385] Operational sas for testing in nos3
2 parents bbfcb96 + 4a054a1 commit 952a1e9

File tree

6 files changed

+65
-50
lines changed

6 files changed

+65
-50
lines changed

src/core/crypto_config.c

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,36 @@ int32_t Crypto_SC_Init(void)
8888

8989
// TM
9090
GvcidManagedParameters_t TM_UT_Managed_Parameters = {
91-
0, 0x0003, 1, TM_HAS_FECF, AOS_FHEC_NA, AOS_IZ_NA, 0, TM_SEGMENT_HDRS_NA, 1786, TM_NO_OCF, 1};
91+
0, 0x0003, 1, TM_NO_FECF, AOS_FHEC_NA, AOS_IZ_NA, 0, TM_SEGMENT_HDRS_NA, 1786, TM_NO_OCF, 1};
9292
Crypto_Config_Add_Gvcid_Managed_Parameters(TM_UT_Managed_Parameters);
9393
TM_UT_Managed_Parameters.vcid = 4;
9494
Crypto_Config_Add_Gvcid_Managed_Parameters(TM_UT_Managed_Parameters);
9595
TM_UT_Managed_Parameters.vcid = 5;
9696
Crypto_Config_Add_Gvcid_Managed_Parameters(TM_UT_Managed_Parameters);
9797
status = Crypto_Init();
98+
99+
SecurityAssociation_t *sa_ptr = NULL;
100+
sa_if->sa_get_from_spi(1, &sa_ptr);
101+
sa_ptr->gvcid_blk.vcid = 0;
102+
sa_if->sa_get_from_spi(2, &sa_ptr);
103+
sa_ptr->gvcid_blk.vcid = 2;
104+
sa_if->sa_get_from_spi(3, &sa_ptr);
105+
sa_ptr->sa_state = SA_OPERATIONAL;
106+
sa_ptr->gvcid_blk.vcid = 3;
107+
sa_ptr->abm_len = ABM_SIZE;
108+
sa_if->sa_get_from_spi(5, &sa_ptr);
109+
sa_ptr->sa_state = SA_OPERATIONAL;
110+
sa_ptr->shsnf_len = 0;
111+
sa_ptr->arsn_len = 0;
112+
sa_ptr->gvcid_blk.vcid = 1;
113+
sa_if->sa_get_from_spi(6, &sa_ptr);
114+
sa_ptr->sa_state = SA_OPERATIONAL;
115+
sa_ptr->gvcid_blk.vcid = 4;
116+
sa_if->sa_get_from_spi(7, &sa_ptr);
117+
sa_ptr->sa_state = SA_OPERATIONAL;
118+
sa_ptr->abm_len = ABM_SIZE;
119+
sa_ptr->gvcid_blk.vcid = 5;
120+
98121
return status;
99122
}
100123

src/core/crypto_tm.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -927,7 +927,8 @@ int32_t Crypto_TM_ApplySecurity(uint8_t *pTfBuffer, uint16_t len_ingest)
927927
printf("Actual secondary header length: %d\n", secondary_hdr_len);
928928
#endif
929929
// Only validate SHVN if secondary header is present
930-
if (idx > secondary_hdr_start && shvn > 0) // SHVN is 2 bits, 0b00 is the only allowed value
930+
931+
if (idx > secondary_hdr_start && shvn != 0) // SHVN is 2 bits, so max value is 3
931932
{
932933
status = CRYPTO_LIB_ERR_TM_SECONDARY_HDR_VN;
933934
mc_if->mc_log(status);

src/sa/internal/sa_interface_inmemory.template.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ void sa_populate(void)
346346
sa[5].gvcid_blk.tfvn = 0;
347347
sa[5].gvcid_blk.scid = SCID & 0x3FF;
348348
sa[5].gvcid_blk.vcid = 1;
349-
sa[5].gvcid_blk.mapid = TYPE_TM;
349+
sa[5].gvcid_blk.mapid = TYPE_TC;
350350

351351
// TM - Encryption Only - AES-CBC-256 (Keyed)
352352
// IV = 0...0, IV-Len = 16, TFVN = 0, VCID = 0; MAC-Len = 0, ARSNW = 5
@@ -368,7 +368,7 @@ void sa_populate(void)
368368
sa[6].gvcid_blk.tfvn = 0;
369369
sa[6].gvcid_blk.scid = SCID & 0x3FF;
370370
sa[6].gvcid_blk.vcid = 0;
371-
sa[6].gvcid_blk.mapid = TYPE_TM;
371+
sa[6].gvcid_blk.mapid = TYPE_TC;
372372

373373
// TM - Authentication Only HMAC_SHA512 (Keyed)
374374
// IV = 0...0, IV-Len = 12, MAC-Len = 16, TFVN = 0, VCID = 0, ARSNW = 5
@@ -390,7 +390,7 @@ void sa_populate(void)
390390
sa[7].gvcid_blk.tfvn = 0;
391391
sa[7].gvcid_blk.scid = SCID & 0x3FF;
392392
sa[7].gvcid_blk.vcid = 0;
393-
sa[7].gvcid_blk.mapid = TYPE_TM;
393+
sa[7].gvcid_blk.mapid = TYPE_TC;
394394

395395
// TM - Authenticated Encryption AES-CBC-256 (Keyed)
396396
// IV = 0...0, IV-Len = 16, MAC-Len = 16, TFVN = 0, VCID = 0, ARSNW = 5
@@ -413,7 +413,7 @@ void sa_populate(void)
413413
sa[8].gvcid_blk.tfvn = 0;
414414
sa[8].gvcid_blk.scid = SCID & 0x3FF;
415415
sa[8].gvcid_blk.vcid = 0;
416-
sa[8].gvcid_blk.mapid = TYPE_TM;
416+
sa[8].gvcid_blk.mapid = TYPE_TC;
417417

418418
// AOS - Clear Mode
419419
// IV = 0...0, IV-Len = 12, MAC-Len = 0, TFVN = 1, VCID = 0, ARSNW = 5
@@ -546,7 +546,7 @@ void sa_populate(void)
546546
sa[15].arsn_len = 2;
547547
sa[15].gvcid_blk.tfvn = 2;
548548
sa[15].gvcid_blk.scid = SCID & 0x3FF;
549-
sa[15].gvcid_blk.vcid = 3;
549+
sa[15].gvcid_blk.vcid = 7;
550550
sa[15].gvcid_blk.mapid = TYPE_TC;
551551

552552
sa_perform_save(&sa[0]);

support/standalone/standalone.c

Lines changed: 31 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ int32_t crypto_standalone_process_command(int32_t cc, int32_t num_tokens, char *
163163
{
164164
Crypto_saPrint(test_association);
165165
}
166-
166+
printf("Get_SA_Status: %d\n", status);
167167
if ((status == CRYPTO_LIB_SUCCESS) && (test_association->sa_state == SA_OPERATIONAL) &&
168168
(test_association->gvcid_blk.mapid == TYPE_TC) && (test_association->gvcid_blk.scid == SCID))
169169
{
@@ -372,14 +372,10 @@ void crypto_standalone_tc_frame(uint8_t *in_data, uint16_t in_length, uint8_t *o
372372
/* TC Length */
373373
if (DYNAMIC_LENGTHS)
374374
{
375-
uint8_t segment_hdr_len = tc_current_managed_parameters_struct.has_segmentation_hdr ? 1 : 0;
375+
uint8_t segment_hdr_len = 1;
376376
uint8_t fecf_len = tc_current_managed_parameters_struct.has_fecf ? 2 : 0;
377377

378-
SecurityAssociation_t *sa_ptr;
379-
sa_if->sa_get_from_spi(tc_vcid, &sa_ptr);
380-
381-
*out_length = TC_FRAME_HEADER_SIZE + segment_hdr_len + sa_ptr->arsn_len + sa_ptr->shivf_len +
382-
sa_ptr->shplf_len + sa_ptr->shsnf_len + in_length + sa_ptr->stmacf_len + fecf_len;
378+
*out_length = TC_FRAME_HEADER_SIZE + segment_hdr_len + in_length + fecf_len;
383379
}
384380
else
385381
{
@@ -525,8 +521,9 @@ void crypto_standalone_tm_frame(uint8_t *in_data, uint16_t in_length, uint8_t *o
525521
}
526522

527523
// Calculate security headers and trailers
528-
uint8_t header_length = TM_PRI_HDR_LENGTH + SDLS_SPI_LENGTH + sa_ptr->shivf_len + sa_ptr->shplf_len +
529-
sa_ptr->shsnf_len; // TODO: Why +40?
524+
uint8_t header_length =
525+
TM_PRI_HDR_LENGTH + SDLS_SPI_LENGTH + sa_ptr->shivf_len + sa_ptr->shplf_len + sa_ptr->shsnf_len;
526+
530527
uint8_t trailer_length = sa_ptr->stmacf_len;
531528
if (tm_current_managed_parameters_struct.has_fecf == TM_HAS_FECF)
532529
{
@@ -571,85 +568,76 @@ void crypto_standalone_tm_debug_process(uint8_t *tm_process_in)
571568
}
572569
}
573570

574-
void crypto_standalone_spp_telem_or_idle(int32_t *status_p, uint8_t *tm_ptr, uint16_t *spp_len_p,
575-
udp_interface_t *tm_socks, int *tm_process_len_p)
571+
void crypto_standalone_spp_telem_or_idle(int32_t *status, uint8_t *tm_ptr, uint16_t *spp_len, udp_interface_t *tm_socks,
572+
int *tm_process_len)
576573
{
577-
int32_t status = *status_p;
578-
uint16_t spp_len = *spp_len_p;
579-
int tm_process_len = *tm_process_len_p;
580-
581574
udp_info_t *tm_write_sock = &tm_socks->write;
582575

583576
if ((tm_ptr[0] == 0x08) || (tm_ptr[0] == 0x09) || ((tm_ptr[0] == 0x07) && (tm_ptr[1] == 0xff)) ||
584-
(tm_ptr[0] == 0x0F && tm_ptr[1] == 0xFD) || (tm_ptr[0] == 0x1F && tm_ptr[1] == 0xFD))
577+
(tm_ptr[0] == 0x0F && tm_ptr[1] == 0xFD))
585578
{
586-
spp_len = (((0xFFFF & tm_ptr[4]) << 8) | tm_ptr[5]) + 7;
579+
*spp_len = (((0xFFFF & tm_ptr[4]) << 8) | tm_ptr[5]) + 7;
587580
#ifdef CRYPTO_STANDALONE_TM_PROCESS_DEBUG
588-
printf("crypto_standalone_tm_process - SPP[%d]: 0x", spp_len);
589-
for (int i = 0; i < spp_len; i++)
581+
printf("crypto_standalone_tm_process - SPP[%d]: 0x", *spp_len);
582+
for (int i = 0; i < *spp_len; i++)
590583
{
591584
printf("%02x", tm_ptr[i]);
592585
}
593586
printf("\n");
594587
#endif
595-
596588
// Send all SPP telemetry packets
597589
// 0x09 for HK/Device TLM Packets (Generic Components)
590+
// 0x0FFD = CFDP
598591
if (tm_ptr[0] == 0x08 || tm_ptr[0] == 0x09 || (tm_ptr[0] == 0x0f && tm_ptr[1] == 0xfd))
599592
{
600-
status = sendto(tm_write_sock->sockfd, tm_ptr, spp_len, 0, (struct sockaddr *)&tm_write_sock->saddr,
601-
sizeof(tm_write_sock->saddr));
593+
*status = sendto(tm_write_sock->sockfd, tm_ptr, *spp_len, 0, (struct sockaddr *)&tm_write_sock->saddr,
594+
sizeof(tm_write_sock->saddr));
602595
}
603596
// Only send idle packets if configured to do so
604597
else
605598
{
606599
#ifdef CRYPTO_STANDALONE_DISCARD_IDLE_PACKETS
607600
// Don't forward idle packets
608-
status = spp_len;
601+
*status = *spp_len;
609602
#else
610-
status = sendto(tm_write_sock->sockfd, tm_ptr, spp_len, 0, (struct sockaddr *)&tm_write_sock->saddr,
603+
status = sendto(tm_write_sock->sockfd, tm_ptr, *spp_len, 0, (struct sockaddr *)&tm_write_sock->saddr,
611604
sizeof(tm_write_sock->saddr));
612605
#endif
613606
}
614607

615608
// Check status
616-
if ((status == -1) || (status != spp_len))
609+
if ((*status == -1) || (*status != *spp_len))
617610
{
618-
printf("crypto_standalone_tm_process - Reply error %d \n", status);
611+
printf("crypto_standalone_tm_process - Reply error %d \n", *status);
619612
}
620-
tm_ptr = &tm_ptr[spp_len];
621-
tm_process_len = tm_process_len - spp_len;
613+
614+
*tm_process_len -= *spp_len;
622615
}
623616
else if ((tm_ptr[0] == 0xFF && tm_ptr[1] == 0x48) || (tm_ptr[0] == 0x00 && tm_ptr[1] == 0x00) ||
624-
(tm_ptr[0] == 0x02 && tm_ptr[1] == 0x00) || (tm_ptr[0] == 0xFF && tm_ptr[1] == 0xFF) ||
625-
(tm_ptr[0] == 0x1F && tm_ptr[1] == 0xFE))
617+
(tm_ptr[0] == 0x02 && tm_ptr[1] == 0x00) || (tm_ptr[0] == 0xFF && tm_ptr[1] == 0xFF))
626618
{
627619
// TODO: Why 0x0200?
628620
// Idle Frame
629621
// Idle Frame is entire length of remaining data
630622
#ifdef CRYPTO_STANDALONE_DISCARD_IDLE_FRAMES
631623
// Don't forward idle frame
632-
status = spp_len;
624+
*status = *spp_len;
633625
#else
634-
status = sendto(tm_write_sock->sockfd, tm_ptr, spp_len, 0, (struct sockaddr *)&tm_write_sock->saddr,
626+
status = sendto(tm_write_sock->sockfd, tm_ptr, *spp_len, 0, (struct sockaddr *)&tm_write_sock->saddr,
635627
sizeof(tm_write_sock->saddr));
636-
if ((status == -1) || (status != spp_len))
628+
if ((status == -1) || (status != *spp_len))
637629
{
638-
printf("crypto_standalone_tm_process - Reply error %d \n", status);
630+
printf("crypto_standalone_tm_process - Reply error %d \n", *status);
639631
}
640-
tm_ptr = &tm_ptr[spp_len];
641632
#endif
642-
tm_process_len = 0;
633+
*tm_process_len = 0;
643634
}
644635
else
645636
{
646637
printf("crypto_standalone_tm_process - SPP loop error, expected idle packet or frame! tm_ptr = 0x%02x%02x \n",
647638
tm_ptr[0], tm_ptr[1]);
648-
tm_process_len = 0;
639+
*tm_process_len = 0;
649640
}
650-
*status_p = status;
651-
*spp_len_p = spp_len;
652-
*tm_process_len_p = tm_process_len;
653641
}
654642

655643
void *crypto_standalone_tm_process(void *socks)
@@ -747,6 +735,7 @@ void *crypto_standalone_tm_process(void *socks)
747735
{
748736
// SPP Telemetry OR SPP Idle Packet
749737
crypto_standalone_spp_telem_or_idle(&status, tm_ptr, &spp_len, tm_socks, &tm_process_len);
738+
tm_ptr = &tm_ptr[spp_len];
750739
}
751740
}
752741
else
@@ -757,13 +746,14 @@ void *crypto_standalone_tm_process(void *socks)
757746
/* Reset */
758747
memset(tm_process_in, 0x00, sizeof(tm_process_in));
759748
tm_process_len = 0;
749+
memset(tm_ptr, 0x00, sizeof(tm_process_in));
760750
#ifdef CRYPTO_STANDALONE_TM_PROCESS_DEBUG
761751
printf("\n");
762752
#endif
763753
}
764754

765755
/* Delay */
766-
usleep(100);
756+
usleep(10);
767757
}
768758
close(tm_read_sock->port);
769759
close(tm_write_sock->port);

test/unit/ut_sa_save.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,7 @@ UTEST(SA_SAVE, VERIFY_SAVE_ADJACENT)
622622
ASSERT_EQ(test_association->gvcid_blk.tfvn, 0);
623623
ASSERT_EQ(test_association->gvcid_blk.scid, 3);
624624
ASSERT_EQ(test_association->gvcid_blk.vcid, 1);
625-
ASSERT_EQ(test_association->gvcid_blk.mapid, 2);
625+
ASSERT_EQ(test_association->gvcid_blk.mapid, 0);
626626
ASSERT_EQ(test_association->est, 0);
627627
ASSERT_EQ(test_association->ast, 0);
628628
ASSERT_EQ(test_association->shivf_len, 12);

test/unit/ut_tm_apply.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2087,7 +2087,8 @@ UTEST(TM_APPLY_ENC_VAL, AEAD_AES_GCM_BITMASK_1)
20872087
hex_conversion(next_iv_h, &next_iv_b, &next_iv_len);
20882088
ASSERT_EQ(next_iv_len, iv_len);
20892089

2090-
Crypto_TM_ApplySecurity((uint8_t *)framed_tm_b, framed_tm_len);
2090+
status = Crypto_TM_ApplySecurity((uint8_t *)framed_tm_b, framed_tm_len);
2091+
ASSERT_EQ(status, CRYPTO_LIB_SUCCESS);
20912092

20922093
printf("Static frame contents:\n\t");
20932094
for (int i = 0; i < 1786; i++)

0 commit comments

Comments
 (0)