1 /* $NetBSD: print-ah.c,v 1.4 1996/05/20 00:41:16 fvdl Exp $ */
4 * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994
5 * The Regents of the University of California. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that: (1) source code distributions
9 * retain the above copyright notice and this paragraph in its entirety, (2)
10 * distributions including binary code include the above copyright notice and
11 * this paragraph in its entirety in the documentation or other materials
12 * provided with the distribution, and (3) all advertising materials mentioning
13 * features or use of this software display the following acknowledgement:
14 * ``This product includes software developed by the University of California,
15 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
16 * the University nor the names of its contributors may be used to endorse
17 * or promote products derived from this software without specific prior
19 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
20 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
21 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
24 /* \summary: IPSEC Encapsulating Security Payload (ESP) printer */
30 #include "netdissect-stdinc.h"
35 /* Any code in this file that depends on HAVE_LIBCRYPTO depends on
36 * HAVE_OPENSSL_EVP_H too. Undefining the former when the latter isn't defined
37 * is the simplest way of handling the dependency.
40 #ifdef HAVE_OPENSSL_EVP_H
41 #include <openssl/evp.h>
47 #include "netdissect.h"
51 #include "strtoaddr.h"
52 #include "ascii_strcasecmp.h"
59 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
60 * All rights reserved.
62 * Redistribution and use in source and binary forms, with or without
63 * modification, are permitted provided that the following conditions
65 * 1. Redistributions of source code must retain the above copyright
66 * notice, this list of conditions and the following disclaimer.
67 * 2. Redistributions in binary form must reproduce the above copyright
68 * notice, this list of conditions and the following disclaimer in the
69 * documentation and/or other materials provided with the distribution.
70 * 3. Neither the name of the project nor the names of its contributors
71 * may be used to endorse or promote products derived from this software
72 * without specific prior written permission.
74 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
75 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
76 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
77 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
78 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
79 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
80 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
81 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
82 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
83 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
88 * RFC1827/2406 Encapsulated Security Payload.
92 nd_uint32_t esp_spi
; /* ESP */
93 nd_uint32_t esp_seq
; /* Sequence number */
94 /*variable size*/ /* (IV and) Payload data */
95 /*variable size*/ /* padding */
96 /*8bit*/ /* pad size */
97 /*8bit*/ /* next header */
98 /*8bit*/ /* next header */
99 /*variable size, 32bit bound*/ /* Authentication data */
102 #ifdef HAVE_LIBCRYPTO
108 struct sa_list
*next
;
110 union inaddr_u daddr
;
111 uint32_t spi
; /* if == 0, then IKEv2 */
113 u_char spii
[8]; /* for IKEv2 */
115 const EVP_CIPHER
*evp
;
118 u_char authsecret
[256];
120 u_char secret
[256]; /* is that big enough for all secrets? */
124 #ifndef HAVE_EVP_CIPHER_CTX_NEW
126 * Allocate an EVP_CIPHER_CTX.
127 * Used if we have an older version of OpenSSL that doesn't provide
128 * routines to allocate and free them.
130 static EVP_CIPHER_CTX
*
131 EVP_CIPHER_CTX_new(void)
135 ctx
= malloc(sizeof(*ctx
));
138 memset(ctx
, 0, sizeof(*ctx
));
143 EVP_CIPHER_CTX_free(EVP_CIPHER_CTX
*ctx
)
145 EVP_CIPHER_CTX_cleanup(ctx
);
150 #ifdef HAVE_EVP_DECRYPTINIT_EX
152 * Initialize the cipher by calling EVP_DecryptInit_ex(), because
153 * calling EVP_DecryptInit() will reset the cipher context, clearing
154 * the cipher, so calling it twice, with the second call having a
155 * null cipher, will clear the already-set cipher. EVP_DecryptInit_ex(),
156 * however, won't reset the cipher context, so you can use it to specify
157 * the IV in a second call after a first call to EVP_DecryptInit_ex()
158 * to set the cipher and the key.
160 * XXX - is there some reason why we need to make two calls?
163 set_cipher_parameters(EVP_CIPHER_CTX
*ctx
, const EVP_CIPHER
*cipher
,
164 const unsigned char *key
,
165 const unsigned char *iv
)
167 return EVP_DecryptInit_ex(ctx
, cipher
, NULL
, key
, iv
);
171 * Initialize the cipher by calling EVP_DecryptInit(), because we don't
172 * have EVP_DecryptInit_ex(); we rely on it not trashing the context.
175 set_cipher_parameters(EVP_CIPHER_CTX
*ctx
, const EVP_CIPHER
*cipher
,
176 const unsigned char *key
,
177 const unsigned char *iv
)
179 return EVP_DecryptInit(ctx
, cipher
, key
, iv
);
184 do_decrypt(netdissect_options
*ndo
, const char *caller
, struct sa_list
*sa
,
185 const u_char
*iv
, const u_char
*ct
, unsigned int ctlen
)
188 unsigned int block_size
;
193 ctx
= EVP_CIPHER_CTX_new();
196 * Failed to initialize the cipher context.
197 * From a look at the OpenSSL code, this appears to
198 * mean "couldn't allocate memory for the cipher context";
199 * note that we're not passing any parameters, so there's
200 * not much else it can mean.
202 (*ndo
->ndo_error
)(ndo
, S_ERR_ND_MEM_ALLOC
,
203 "%s: can't allocate memory for cipher context", caller
);
207 if (set_cipher_parameters(ctx
, sa
->evp
, sa
->secret
, NULL
) < 0) {
208 EVP_CIPHER_CTX_free(ctx
);
209 (*ndo
->ndo_warning
)(ndo
, "%s: espkey init failed", caller
);
212 if (set_cipher_parameters(ctx
, NULL
, NULL
, iv
) < 0) {
213 EVP_CIPHER_CTX_free(ctx
);
214 (*ndo
->ndo_warning
)(ndo
, "%s: IV init failed", caller
);
219 * At least as I read RFC 5996 section 3.14 and RFC 4303 section 2.4,
220 * if the cipher has a block size of which the ciphertext's size must
221 * be a multiple, the payload must be padded to make that happen, so
222 * the ciphertext length must be a multiple of the block size. Fail
223 * if that's not the case.
225 block_size
= (unsigned int)EVP_CIPHER_CTX_block_size(ctx
);
226 if ((ctlen
% block_size
) != 0) {
227 EVP_CIPHER_CTX_free(ctx
);
228 (*ndo
->ndo_warning
)(ndo
,
229 "%s: ciphertext size %u is not a multiple of the cipher block size %u",
230 caller
, ctlen
, block_size
);
235 * Attempt to allocate a buffer for the decrypted data, because
236 * we can't decrypt on top of the input buffer.
239 pt
= (u_char
*)malloc(ptlen
);
241 EVP_CIPHER_CTX_free(ctx
);
242 (*ndo
->ndo_error
)(ndo
, S_ERR_ND_MEM_ALLOC
,
243 "%s: can't allocate memory for decryption buffer", caller
);
248 * The size of the ciphertext handed to us is a multiple of the
249 * cipher block size, so we don't need to worry about padding.
251 if (!EVP_CIPHER_CTX_set_padding(ctx
, 0)) {
253 EVP_CIPHER_CTX_free(ctx
);
254 (*ndo
->ndo_warning
)(ndo
,
255 "%s: EVP_CIPHER_CTX_set_padding failed", caller
);
258 if (!EVP_DecryptUpdate(ctx
, pt
, &len
, ct
, ctlen
)) {
260 EVP_CIPHER_CTX_free(ctx
);
261 (*ndo
->ndo_warning
)(ndo
, "%s: EVP_DecryptUpdate failed",
265 EVP_CIPHER_CTX_free(ctx
);
270 * This will allocate a new buffer containing the decrypted data.
271 * It returns 1 on success and 0 on failure.
273 * It will push the new buffer and the values of ndo->ndo_packetp and
274 * ndo->ndo_snapend onto the buffer stack, and change ndo->ndo_packetp
275 * and ndo->ndo_snapend to refer to the new buffer.
277 * Our caller must pop the buffer off the stack when it's finished
278 * dissecting anything in it and before it does any dissection of
279 * anything in the old buffer. That will free the new buffer.
281 USES_APPLE_DEPRECATED_API
282 int esp_decrypt_buffer_by_ikev2_print(netdissect_options
*ndo
,
284 const u_char spii
[8],
285 const u_char spir
[8],
286 const u_char
*buf
, const u_char
*end
)
294 /* initiator arg is any non-zero value */
295 if(initiator
) initiator
=1;
297 /* see if we can find the SA, and if so, decode it */
298 for (sa
= ndo
->ndo_sa_list_head
; sa
!= NULL
; sa
= sa
->next
) {
300 && initiator
== sa
->initiator
301 && memcmp(spii
, sa
->spii
, 8) == 0
302 && memcmp(spir
, sa
->spir
, 8) == 0)
306 if(sa
== NULL
) return 0;
307 if(sa
->evp
== NULL
) return 0;
310 * remove authenticator, and see if we still have something to
313 end
= end
- sa
->authlen
;
318 if(end
<= ct
) return 0;
320 pt
= do_decrypt(ndo
, "esp_decrypt_buffer_by_ikev2_print", sa
, iv
,
326 * Switch to the output buffer for dissection, and save it
327 * on the buffer stack so it can be freed; our caller must
330 if (!nd_push_buffer(ndo
, pt
, pt
, pt
+ ctlen
)) {
339 static void esp_print_addsa(netdissect_options
*ndo
,
340 struct sa_list
*sa
, int sa_def
)
346 /* malloc() return used in a 'struct sa_list': do not free() */
347 nsa
= (struct sa_list
*)malloc(sizeof(struct sa_list
));
349 (*ndo
->ndo_error
)(ndo
, S_ERR_ND_MEM_ALLOC
,
350 "%s: malloc", __func__
);
355 ndo
->ndo_sa_default
= nsa
;
357 nsa
->next
= ndo
->ndo_sa_list_head
;
358 ndo
->ndo_sa_list_head
= nsa
;
362 static u_int
hexdigit(netdissect_options
*ndo
, char hex
)
364 if (hex
>= '0' && hex
<= '9')
366 else if (hex
>= 'A' && hex
<= 'F')
367 return (hex
- 'A' + 10);
368 else if (hex
>= 'a' && hex
<= 'f')
369 return (hex
- 'a' + 10);
371 (*ndo
->ndo_error
)(ndo
, S_ERR_ND_ESP_SECRET
,
372 "invalid hex digit %c in espsecret\n", hex
);
376 static u_int
hex2byte(netdissect_options
*ndo
, char *hexstring
)
380 byte
= (hexdigit(ndo
, hexstring
[0]) << 4) + hexdigit(ndo
, hexstring
[1]);
385 * returns size of binary, 0 on failure.
388 int espprint_decode_hex(netdissect_options
*ndo
,
389 u_char
*binbuf
, unsigned int binbuf_len
,
395 len
= strlen(hex
) / 2;
397 if (len
> binbuf_len
) {
398 (*ndo
->ndo_warning
)(ndo
, "secret is too big: %u\n", len
);
403 while (hex
[0] != '\0' && hex
[1]!='\0') {
404 binbuf
[i
] = hex2byte(ndo
, hex
);
413 * decode the form: SPINUM@IP <tab> ALGONAME:0xsecret
416 USES_APPLE_DEPRECATED_API
418 espprint_decode_encalgo(netdissect_options
*ndo
,
419 char *decode
, struct sa_list
*sa
)
422 const EVP_CIPHER
*evp
;
426 colon
= strchr(decode
, ':');
428 (*ndo
->ndo_warning
)(ndo
, "failed to decode espsecret: %s\n", decode
);
433 if (strlen(decode
) > strlen("-hmac96") &&
434 !strcmp(decode
+ strlen(decode
) - strlen("-hmac96"),
436 p
= strstr(decode
, "-hmac96");
440 if (strlen(decode
) > strlen("-cbc") &&
441 !strcmp(decode
+ strlen(decode
) - strlen("-cbc"), "-cbc")) {
442 p
= strstr(decode
, "-cbc");
445 evp
= EVP_get_cipherbyname(decode
);
448 (*ndo
->ndo_warning
)(ndo
, "failed to find cipher algo %s\n", decode
);
456 sa
->authlen
= authlen
;
457 /* This returns an int, but it should never be negative */
458 sa
->ivlen
= EVP_CIPHER_iv_length(evp
);
461 if (colon
[0] == '0' && colon
[1] == 'x') {
462 /* decode some hex! */
465 sa
->secretlen
= espprint_decode_hex(ndo
, sa
->secret
, sizeof(sa
->secret
), colon
);
466 if(sa
->secretlen
== 0) return 0;
470 if (i
< sizeof(sa
->secret
)) {
471 memcpy(sa
->secret
, colon
, i
);
474 memcpy(sa
->secret
, colon
, sizeof(sa
->secret
));
475 sa
->secretlen
= sizeof(sa
->secret
);
484 * for the moment, ignore the auth algorithm, just hard code the authenticator
485 * length. Need to research how openssl looks up HMAC stuff.
488 espprint_decode_authalgo(netdissect_options
*ndo
,
489 char *decode
, struct sa_list
*sa
)
493 colon
= strchr(decode
, ':');
495 (*ndo
->ndo_warning
)(ndo
, "failed to decode espsecret: %s\n", decode
);
500 if(ascii_strcasecmp(decode
,"sha1") == 0 ||
501 ascii_strcasecmp(decode
,"md5") == 0) {
507 static void esp_print_decode_ikeline(netdissect_options
*ndo
, char *line
,
508 const char *file
, int lineno
)
510 /* it's an IKEv2 secret, store it instead */
514 char *icookie
, *rcookie
;
519 init
= strsep(&line
, " \t");
520 icookie
= strsep(&line
, " \t");
521 rcookie
= strsep(&line
, " \t");
522 authkey
= strsep(&line
, " \t");
523 enckey
= strsep(&line
, " \t");
525 /* if any fields are missing */
526 if(!init
|| !icookie
|| !rcookie
|| !authkey
|| !enckey
) {
527 (*ndo
->ndo_warning
)(ndo
, "print_esp: failed to find all fields for ikev2 at %s:%u",
533 ilen
= strlen(icookie
);
534 rlen
= strlen(rcookie
);
536 if((init
[0]!='I' && init
[0]!='R')
537 || icookie
[0]!='0' || icookie
[1]!='x'
538 || rcookie
[0]!='0' || rcookie
[1]!='x'
541 (*ndo
->ndo_warning
)(ndo
, "print_esp: line %s:%u improperly formatted.",
544 (*ndo
->ndo_warning
)(ndo
, "init=%s icookie=%s(%u) rcookie=%s(%u)",
545 init
, icookie
, ilen
, rcookie
, rlen
);
551 sa1
.initiator
= (init
[0] == 'I');
552 if(espprint_decode_hex(ndo
, sa1
.spii
, sizeof(sa1
.spii
), icookie
+2)!=8)
555 if(espprint_decode_hex(ndo
, sa1
.spir
, sizeof(sa1
.spir
), rcookie
+2)!=8)
558 if(!espprint_decode_encalgo(ndo
, enckey
, &sa1
)) return;
560 if(!espprint_decode_authalgo(ndo
, authkey
, &sa1
)) return;
562 esp_print_addsa(ndo
, &sa1
, FALSE
);
567 * special form: file /name
568 * causes us to go read from this file instead.
571 static void esp_print_decode_onesecret(netdissect_options
*ndo
, char *line
,
572 const char *file
, int lineno
)
580 spikey
= strsep(&line
, " \t");
582 memset(&sa1
, 0, sizeof(struct sa_list
));
584 /* if there is only one token, then it is an algo:key token */
588 /* sa1.daddr.version = 0; */
589 /* memset(&sa1.daddr, 0, sizeof(sa1.daddr)); */
595 if (spikey
&& ascii_strcasecmp(spikey
, "file") == 0) {
596 /* open file and read it */
599 int subfile_lineno
=0;
601 char *filename
= line
;
603 secretfile
= fopen(filename
, FOPEN_READ_TXT
);
604 if (secretfile
== NULL
) {
605 (*ndo
->ndo_error
)(ndo
, S_ERR_ND_OPEN_FILE
,
606 "%s: can't open %s: %s\n",
607 __func__
, filename
, strerror(errno
));
610 while (fgets(fileline
, sizeof(fileline
)-1, secretfile
) != NULL
) {
612 /* remove newline from the line */
613 nl
= strchr(fileline
, '\n');
616 if (fileline
[0] == '#') continue;
617 if (fileline
[0] == '\0') continue;
619 esp_print_decode_onesecret(ndo
, fileline
, filename
, subfile_lineno
);
626 if (spikey
&& ascii_strcasecmp(spikey
, "ikev2") == 0) {
627 esp_print_decode_ikeline(ndo
, line
, file
, lineno
);
636 spistr
= strsep(&spikey
, "@");
637 if (spistr
== NULL
) {
638 (*ndo
->ndo_warning
)(ndo
, "print_esp: failed to find the @ token");
642 spino
= strtoul(spistr
, &foo
, 0);
643 if (spistr
== foo
|| !spikey
) {
644 (*ndo
->ndo_warning
)(ndo
, "print_esp: failed to decode spi# %s\n", foo
);
650 if (strtoaddr6(spikey
, &sa1
.daddr
.in6
) == 1) {
651 sa1
.daddr_version
= 6;
652 } else if (strtoaddr(spikey
, &sa1
.daddr
.in4
) == 1) {
653 sa1
.daddr_version
= 4;
655 (*ndo
->ndo_warning
)(ndo
, "print_esp: can not decode IP# %s\n", spikey
);
661 /* skip any blank spaces */
662 while (*decode
== ' ' || *decode
== '\t' || *decode
== '\r' || *decode
== '\n')
665 if(!espprint_decode_encalgo(ndo
, decode
, &sa1
)) {
670 esp_print_addsa(ndo
, &sa1
, sa_def
);
673 USES_APPLE_DEPRECATED_API
674 static void esp_init(netdissect_options
*ndo _U_
)
677 * 0.9.6 doesn't appear to define OPENSSL_API_COMPAT, so
678 * we check whether it's undefined or it's less than the
681 #if !defined(OPENSSL_API_COMPAT) || OPENSSL_API_COMPAT < 0x10100000L
682 OpenSSL_add_all_algorithms();
684 EVP_add_cipher_alias(SN_des_ede3_cbc
, "3des");
688 void esp_decodesecret_print(netdissect_options
*ndo
)
692 static int initialized
= 0;
699 p
= ndo
->ndo_espsecret
;
701 while (p
&& p
[0] != '\0') {
702 /* pick out the first line or first thing until a comma */
703 if ((line
= strsep(&p
, "\n,")) == NULL
) {
708 esp_print_decode_onesecret(ndo
, line
, "cmdline", 0);
711 ndo
->ndo_espsecret
= NULL
;
716 #ifdef HAVE_LIBCRYPTO
717 #define USED_IF_LIBCRYPTO
719 #define USED_IF_LIBCRYPTO _U_
722 #ifdef HAVE_LIBCRYPTO
723 USES_APPLE_DEPRECATED_API
726 esp_print(netdissect_options
*ndo
,
727 const u_char
*bp
, u_int length
,
728 const u_char
*bp2 USED_IF_LIBCRYPTO
,
729 u_int ver USED_IF_LIBCRYPTO
,
730 int fragmented USED_IF_LIBCRYPTO
,
731 u_int ttl_hl USED_IF_LIBCRYPTO
)
733 const struct newesp
*esp
;
735 #ifdef HAVE_LIBCRYPTO
737 struct sa_list
*sa
= NULL
;
738 const struct ip6_hdr
*ip6
= NULL
;
748 ndo
->ndo_protocol
= "esp";
749 esp
= (const struct newesp
*)bp
;
751 /* 'ep' points to the end of available data. */
752 ep
= ndo
->ndo_snapend
;
754 if ((const u_char
*)(esp
+ 1) >= ep
) {
758 ND_PRINT("ESP(spi=0x%08x", GET_BE_U_4(esp
->esp_spi
));
759 ND_PRINT(",seq=0x%x)", GET_BE_U_4(esp
->esp_seq
));
760 ND_PRINT(", length %u", length
);
762 #ifdef HAVE_LIBCRYPTO
763 /* initiailize SAs */
764 if (ndo
->ndo_sa_list_head
== NULL
) {
765 if (!ndo
->ndo_espsecret
)
768 esp_decodesecret_print(ndo
);
771 if (ndo
->ndo_sa_list_head
== NULL
)
774 ip
= (const struct ip
*)bp2
;
777 ip6
= (const struct ip6_hdr
*)bp2
;
778 /* we do not attempt to decrypt jumbograms */
779 if (!GET_BE_U_2(ip6
->ip6_plen
))
781 /* XXX - check whether it's fragmented? */
782 /* if we can't get nexthdr, we do not need to decrypt it */
784 /* see if we can find the SA, and if so, decode it */
785 for (sa
= ndo
->ndo_sa_list_head
; sa
!= NULL
; sa
= sa
->next
) {
786 if (sa
->spi
== GET_BE_U_4(esp
->esp_spi
) &&
787 sa
->daddr_version
== 6 &&
788 UNALIGNED_MEMCMP(&sa
->daddr
.in6
, &ip6
->ip6_dst
,
789 sizeof(nd_ipv6
)) == 0) {
795 /* nexthdr & padding are in the last fragment */
799 /* see if we can find the SA, and if so, decode it */
800 for (sa
= ndo
->ndo_sa_list_head
; sa
!= NULL
; sa
= sa
->next
) {
801 if (sa
->spi
== GET_BE_U_4(esp
->esp_spi
) &&
802 sa
->daddr_version
== 4 &&
803 UNALIGNED_MEMCMP(&sa
->daddr
.in4
, &ip
->ip_dst
,
804 sizeof(nd_ipv4
)) == 0) {
813 /* if we didn't find the specific one, then look for
814 * an unspecified one.
817 sa
= ndo
->ndo_sa_default
;
819 /* if not found fail */
823 /* pointer to the IV, if there is one */
824 iv
= (const u_char
*)(esp
+ 1) + 0;
825 /* length of the IV, if there is one; 0, if there isn't */
829 * Get a pointer to the ciphertext.
831 * p points to the beginning of the payload, i.e. to the
832 * initialization vector, so if we skip past the initialization
833 * vector, it points to the beginning of the ciphertext.
838 * Make sure the authentication data/integrity check value length
839 * isn't bigger than the total amount of data available after
840 * the ESP header and initialization vector is removed and,
841 * if not, slice the authentication data/ICV off.
843 if (ep
- ct
< sa
->authlen
) {
847 ep
= ep
- sa
->authlen
;
850 * Calculate the length of the ciphertext. ep points to
851 * the beginning of the authentication data/integrity check
852 * value, i.e. right past the end of the ciphertext;
854 payloadlen
= ep
- ct
;
860 * If the next header value is past the end of the available
861 * data, we won't be able to fetch it once we've decrypted
862 * the ciphertext, so there's no point in decrypting the data.
864 * Report it as truncation.
866 if (!ND_TTEST_1(ep
- 1)) {
871 pt
= do_decrypt(ndo
, "esp_print", sa
, iv
, ct
, payloadlen
);
876 * Switch to the output buffer for dissection, and
877 * save it on the buffer stack so it can be freed.
879 ep
= pt
+ payloadlen
;
880 if (!nd_push_buffer(ndo
, pt
, pt
, ep
)) {
882 (*ndo
->ndo_error
)(ndo
, S_ERR_ND_MEM_ALLOC
,
883 "%s: can't push buffer on buffer stack", __func__
);
887 * Sanity check for pad length; if it, plus 2 for the pad
888 * length and next header fields, is bigger than the ciphertext
889 * length (which is also the plaintext length), it's too big.
891 * XXX - the check can fail if the packet is corrupt *or* if
892 * it was not decrypted with the correct key, so that the
893 * "plaintext" is not what was being sent.
895 padlen
= GET_U_1(ep
- 2);
896 if (padlen
+ 2 > payloadlen
) {
901 /* Get the next header */
902 nh
= GET_U_1(ep
- 1);
906 /* Now dissect the plaintext. */
907 ip_demux_print(ndo
, pt
, payloadlen
- (padlen
+ 2), ver
, fragmented
,
910 /* Pop the buffer, freeing it. */
911 nd_pop_packet_info(ndo
);
914 #ifdef HAVE_LIBCRYPTO