. "$BST_LIB" require asn1Parser libtasn1/present # Every expectation below is a literal taken from a native x86_64 build of the same # 4.20.0 source, not from the ASN.1 standards -- so a red can only mean the platform. # The three DER payloads and pkix.asn.out are upstream's own test vectors. W=${TMPDIR:-/tmp}/bst-libtasn1.$$ mkdir -p "$W" || { bst_notok libtasn1/workdir "cannot mkdir $W"; exit 0; } # Stage the payloads under their UPSTREAM names in a short path. Both halves matter: # asn1Parser derives the generated C array's name from the input filename (so only # pkix.asn reproduces pkix_asn1_tab), and libtasn1's error description is a fixed # 128-byte buffer that a long input path crowds the actual diagnostic out of. cp "$BST_DATA/libtasn1-pkix.asn" "$W/pkix.asn" cp "$BST_DATA/libtasn1-bst.asn" "$W/bst.asn" cp "$BST_DATA/libtasn1-bst.asg" "$W/bst.asg" cp "$BST_DATA/libtasn1-broken.asn" "$W/broken.asn" cp "$BST_DATA/libtasn1-badref.asg" "$W/badref.asg" WANT=$BST_DATA/libtasn1-pkix.asn.out CRL=$BST_DATA/libtasn1-crl.der BADTIME=$BST_DATA/libtasn1-cert-badtime.der OVERFLOW=$BST_DATA/libtasn1-cert-overflow.der # The image's install prefix. Overridable only so the same file can be driven # against a native control build, where libtasn1 is not under /usr. PFX=${LIBTASN1_PREFIX:-/usr} # --- the other two tools of the lib_package split ---------------------------- check libtasn1/coding-present command -v asn1Coding check libtasn1/decoding-present command -v asn1Decoding check_out libtasn1/parser-version "(libtasn1) 4.20.0" asn1Parser --version check_out libtasn1/coding-version "(libtasn1) 4.20.0" asn1Coding --version check_out libtasn1/decoding-version "(libtasn1) 4.20.0" asn1Decoding --version # --- -dev / -staticdev actually landed --------------------------------------- check libtasn1/dev-header test -f "$PFX/include/libtasn1.h" check libtasn1/staticdev-lib test -f "$PFX/lib/libtasn1.a" check_out libtasn1/pkgconfig-version "Version: 4.20.0" cat "$PFX/lib/pkgconfig/libtasn1.pc" # --- asn1Parser: the real PKIX1 module -------------------------------------- # The strongest single assertion in the suite: the generated C table must equal # upstream's own expected output byte for byte, which is what parser.sh checks. check_out libtasn1/parser-check-pkix "Done." asn1Parser -c "$W/pkix.asn" asn1Parser "$W/pkix.asn" -o "$W/gen.c" >"$W/gen.log" 2>&1; gen_rc=$? LC_ALL=C tr -d '\r' < "$W/gen.c" > "$W/gen.norm" 2>/dev/null check_eq libtasn1/parser-gen-rc 0 "$gen_rc" check_eq libtasn1/parser-gen-lines 1142 "$(grep -c '^' "$W/gen.norm" 2>/dev/null)" check libtasn1/parser-gen-exact cmp "$W/gen.norm" "$WANT" check_out libtasn1/parser-gen-arrayname "const asn1_static_node pkix_asn1_tab[] = {" cat "$W/gen.norm" check_out libtasn1/parser-gen-firstnode '{ "PKIX1", 536875024, NULL },' cat "$W/gen.norm" check_out libtasn1/parser-gen-oid-node '{ "joint-iso-ccitt", 1073741825, "2"},' cat "$W/gen.norm" if command -v md5sum >/dev/null 2>&1; then check_eq libtasn1/parser-gen-md5 e22e16dcd0364ae1992094ff123f037a \ "$(md5sum < "$W/gen.norm" | cut -d' ' -f1)" else bst_skip libtasn1/parser-gen-md5 "md5sum not on this image" fi check_out libtasn1/parser-name-flag "const asn1_static_node bst_tab[] = {" \ sh -c "asn1Parser -n bst_tab -o '$W/named.c' '$W/bst.asn' >/dev/null 2>&1; cat '$W/named.c'" # A rejection case has to assert the rc AND the diagnostic: an rc-only check # passes for a tool that failed for an unrelated reason. check_rc libtasn1/parser-syntax-error 1 asn1Parser -c "$W/broken.asn" check_out libtasn1/parser-syntax-error-msg "syntax error" \ sh -c "asn1Parser -c '$W/broken.asn' 2>&1; exit 0" # --- asn1Coding: DER encoding, asserted byte for byte ------------------------ check libtasn1/coding-check asn1Coding -c "$W/bst.asn" "$W/bst.asg" asn1Coding -o "$W/bst.der" "$W/bst.asn" "$W/bst.asg" >"$W/code.log" 2>&1; code_rc=$? check_eq libtasn1/coding-rc 0 "$code_rc" check_eq libtasn1/coding-size 47 "$(wc -c < "$W/bst.der" 2>/dev/null | tr -d ' ')" check_eq libtasn1/coding-der-bytes \ 302d02012a0201d606092a864886f70d01010b030305232004076272696e744f5330090101ff160468776a73020107 \ "$(od -An -v -tx1 "$W/bst.der" 2>/dev/null | tr -d ' \n')" check_out libtasn1/coding-reports-size "Number of bytes=47" cat "$W/code.log" check_rc libtasn1/coding-badref 1 asn1Coding -c "$W/bst.asn" "$W/badref.asg" check_out libtasn1/coding-badref-msg "ELEMENT_NOT_FOUND" \ sh -c "asn1Coding -c '$W/bst.asn' '$W/badref.asg' 2>&1; exit 0" # --- asn1Decoding: round-trip every primitive the module encodes ------------- asn1Decoding "$W/bst.asn" "$W/bst.der" BST.Sig > "$W/dec.txt" 2>&1; dec_rc=$? check_eq libtasn1/roundtrip-rc 0 "$dec_rc" check_out libtasn1/roundtrip-success "Decoding: SUCCESS" cat "$W/dec.txt" check_out libtasn1/roundtrip-int "name:r type:INTEGER value:0x2a" cat "$W/dec.txt" check_out libtasn1/roundtrip-negint "name:s type:INTEGER value:0xd6" cat "$W/dec.txt" check_out libtasn1/roundtrip-oid "name:alg type:OBJ_ID value:1.2.840.113549.1.1.11" cat "$W/dec.txt" check_out libtasn1/roundtrip-bitstr "name:key type:BIT_STR value(11):2320" cat "$W/dec.txt" check_out libtasn1/roundtrip-octstr "name:salt type:OCT_STR value:6272696e744f53" cat "$W/dec.txt" check_out libtasn1/roundtrip-bool "name:flag type:BOOLEAN value:TRUE" cat "$W/dec.txt" check_out libtasn1/roundtrip-ia5 "name:tag type:IA5_STR value:hwjs" cat "$W/dec.txt" check_out libtasn1/roundtrip-choice "name:a type:INTEGER value:0x07" cat "$W/dec.txt" # `opt (NULL)` must leave the OPTIONAL field out of the encoding entirely. check_rc libtasn1/roundtrip-optional-absent 1 grep -q 'name:opt' "$W/dec.txt" # --- asn1Decoding against a real X.509 CRL and the real PKIX1 module -------- asn1Decoding "$W/pkix.asn" "$CRL" PKIX1.CertificateList > "$W/crl.txt" 2>&1; crl_rc=$? check_eq libtasn1/crl-rc 0 "$crl_rc" check_out libtasn1/crl-success "Decoding: SUCCESS" cat "$W/crl.txt" check_out libtasn1/crl-tbs "name:tbsCertList type:SEQUENCE" cat "$W/crl.txt" check_out libtasn1/crl-sigalg-oid "type:OBJ_ID value:1.2.840.113549.1.1.5" cat "$W/crl.txt" check_out libtasn1/crl-issuer-o-oid "type:OBJ_ID value:2.5.4.10" cat "$W/crl.txt" check_out libtasn1/crl-issuer-cn-oid "type:OBJ_ID value:2.5.4.3" cat "$W/crl.txt" check_out libtasn1/crl-email-oid "type:OBJ_ID value:1.2.840.113549.1.9.1" cat "$W/crl.txt" # A 128-bit serial: the value is read out of the DER, so a wrong bignum path shows here. check_out libtasn1/crl-revoked-serial "value:0x2e103703df46859d7a550da659618538" cat "$W/crl.txt" check_out libtasn1/crl-issuer-name "130e566572695369676e2c20496e632e" cat "$W/crl.txt" check_eq libtasn1/crl-node-count 83 "$(grep -c 'name:' "$W/crl.txt" 2>/dev/null)" # --- what must be REJECTED (a decoder that accepts everything is not a decoder) check_rc libtasn1/reject-overflow 1 asn1Decoding "$W/pkix.asn" "$OVERFLOW" PKIX1.Certificate check_out libtasn1/reject-overflow-msg "DER_ERROR" \ sh -c "asn1Decoding '$W/pkix.asn' '$OVERFLOW' PKIX1.Certificate 2>&1; exit 0" check_rc libtasn1/reject-wrong-type 1 asn1Decoding "$W/pkix.asn" "$CRL" PKIX1.Certificate check_rc libtasn1/reject-missing-file 1 asn1Decoding "$W/pkix.asn" "$W/absent.der" PKIX1.Certificate check_out libtasn1/reject-missing-file-msg "could not read" \ sh -c "asn1Decoding '$W/pkix.asn' '$W/absent.der' PKIX1.Certificate 2>&1; exit 0" # The -s / -t pair on one payload: strict DER must refuse the malformed time # field, and -t must accept the same bytes. Both halves, so they cannot drift. check_rc libtasn1/strict-time-rejected 1 asn1Decoding -s "$W/pkix.asn" "$BADTIME" PKIX1.Certificate check_rc libtasn1/no-time-strict-accept 0 asn1Decoding -t "$W/pkix.asn" "$BADTIME" PKIX1.Certificate rm -rf "$W"