3030#include "logger.h"
3131#include "intercept.h"
3232#include "etsiencoding.h"
33+ #include "util.h"
3334
3435static inline uint8_t encode_pspdu_sequence (uint8_t * space , uint8_t space_len ,
35- uint32_t contentsize , char * liid , uint16_t liidlen ) {
36+ uint32_t contentsize , char * liid ) {
3637
3738 uint8_t len_space_req = DERIVE_INTEGER_LENGTH (contentsize );
3839 int i ;
39- uint16_t l ;
40+ uint16_t l , l_swap ;
41+ l = (uint16_t )strlen (liid );
4042
41- if (liidlen > space_len - 8 ) {
43+ if (l > space_len - 8 ) {
4244 logger (LOG_INFO ,
43- "OpenLI: invalid LIID for PSPDU: %s (%u %u)" , liid , liidlen , space_len );
45+ "OpenLI: invalid LIID for PSPDU: %s (%u %u)" , liid , l , space_len );
4446 return 0 ;
4547 }
4648
47- l = htons (liidlen );
48- memcpy (space , & l , sizeof (uint16_t ));
49- memcpy (space + 2 , liid , liidlen );
50- space += (2 + liidlen );
49+ l_swap = htons (l );
50+ memcpy (space , & l_swap , sizeof (uint16_t ));
51+ memcpy (space + 2 , liid , l );
52+ space += (2 + l );
5153
5254 * space = (uint8_t )((WANDDER_CLASS_UNIVERSAL_CONSTRUCT << 5 ) |
5355 WANDDER_TAG_SEQUENCE );
5456 space ++ ;
5557
5658 if (len_space_req == 1 ) {
5759 * space = (uint8_t )contentsize ;
58- return 2 + (2 + liidlen );
60+ return 2 + (2 + l );
5961 }
6062
6163 * space = len_space_req | 0x80 ;
@@ -66,7 +68,7 @@ static inline uint8_t encode_pspdu_sequence(uint8_t *space, uint8_t space_len,
6668 contentsize = contentsize >> 8 ;
6769 }
6870
69- return len_space_req + 2 + (2 + liidlen );
71+ return len_space_req + 2 + (2 + l );
7072}
7173
7274void encode_etsili_pshdr (wandder_encoder_t * encoder ,
@@ -89,9 +91,30 @@ void encode_etsili_pshdr(wandder_encoder_t *encoder,
8991 WANDDER_CLASS_CONTEXT_PRIMITIVE , 0 ,
9092 (uint8_t * )WANDDER_ETSILI_PSDOMAINID ,
9193 sizeof (WANDDER_ETSILI_PSDOMAINID ));
92- wandder_encode_next (encoder , WANDDER_TAG_OCTETSTRING ,
93- WANDDER_CLASS_CONTEXT_PRIMITIVE , 1 , hdrdata -> liid ,
94- hdrdata -> liid_len );
94+
95+ // if the LIID is binary octets, we need to first convert the
96+ // hex string that we have into pure binary
97+
98+ if (hdrdata -> liid_format == OPENLI_LIID_FORMAT_BINARY_OCTETS ) {
99+ uint8_t liidbuf [OPENLI_LIID_MAXSIZE ];
100+ size_t liidsize = 0 ;
101+ liidsize = openli_convert_hexstring_to_binary (hdrdata -> liid , liidbuf ,
102+ OPENLI_LIID_MAXSIZE );
103+ if (liidsize > 0 ) {
104+ wandder_encode_next (encoder , WANDDER_TAG_OCTETSTRING ,
105+ WANDDER_CLASS_CONTEXT_PRIMITIVE , 1 , liidbuf ,
106+ liidsize );
107+ } else {
108+ wandder_encode_next (encoder , WANDDER_TAG_OCTETSTRING ,
109+ WANDDER_CLASS_CONTEXT_PRIMITIVE , 1 , "liidmissing" ,
110+ strlen ("liidmissing" ));
111+ }
112+ } else {
113+ wandder_encode_next (encoder , WANDDER_TAG_OCTETSTRING ,
114+ WANDDER_CLASS_CONTEXT_PRIMITIVE , 1 , hdrdata -> liid ,
115+ hdrdata -> liid_len );
116+ }
117+
95118 wandder_encode_next (encoder , WANDDER_TAG_PRINTABLE ,
96119 WANDDER_CLASS_CONTEXT_PRIMITIVE , 2 , hdrdata -> authcc ,
97120 hdrdata -> authcc_len );
@@ -256,8 +279,7 @@ int create_etsi_encoded_result(openli_encoded_result_t *res,
256279 * a preceding pS-PDU sequence with the appropriate length...
257280 */
258281 pspdu_len = encode_pspdu_sequence (pspdu , sizeof (pspdu ),
259- hdr_tplate -> header_len + bodylen , job -> liid ,
260- job -> preencoded [OPENLI_PREENCODE_LIID ].vallen );
282+ hdr_tplate -> header_len + bodylen , job -> liid );
261283
262284 if (pspdu_len == 0 ) {
263285 return -1 ;
0 commit comments