Commit Graph

25 Commits

Author SHA1 Message Date
Nicolas Williams
f0e628c2cf asn1: Add Heimdal cert ext for ticket max_life 2021-03-24 19:12:00 -05:00
Nicolas Williams
db7763ca7b asn1: X.681/682/683 magic handling of open types
Status:

 - And it works!

 - We have an extensive test based on decoding a rich EK certficate.

   This test exercises all of:

    - decoding
    - encoding with and without decoded open types
    - copying of decoded values with decoded open types
    - freeing of decoded values with decoded open types

   Valgrind finds no memory errors.

 - Added a manual page for the compiler.

 - rfc2459.asn1 now has all three primary PKIX types that we care about
   defined as in RFC5912, with IOS constraints and parameterization:

    - `Extension`       (embeds open type in an `OCTET STRING`)
    - `OtherName`       (embeds open type in an        `ANY`-like type)
    - `SingleAttribute` (embeds open type in an        `ANY`-like type)
    - `AttributeSet`    (embeds open type in a  `SET OF ANY`-like type)

   All of these use OIDs as the open type type ID field, but integer
   open type type ID fields are also supported (and needed, for
   Kerberos).

   That will cover every typed hole pattern in all our ASN.1 modules.

   With this we'll be able to automatically and recursively decode
   through all subject DN attributes even when the subject DN is a
   directoryName SAN, and subjectDirectoryAttributes, and all
   extensions, and all SANs, and all authorization-data elements, and
   PA-data, and...

   We're not really using `SingleAttribute` and `AttributeSet` yet
   because various changes are needed in `lib/hx509` for that.

 - `asn1_compile` builds and recognizes the subset of X.681/682/683 that
   we need for, and now use in, rfc2459.asn1.  It builds the necessary
   AST, generates the correct C types, and generates templating for
   object sets and open types!

 - See READMEs for details.

 - Codegen backend not tested; I won't make it implement automatic open
   type handling, but it should at least not crash by substituting
   `heim_any` for open types not embedded in `OCTET STRING`.

 - We're _really_ starting to have problems with the ITU-T ASN.1
   grammar and our version of it...

   Type names have to start with upper-case, value names with
   lower-case, but it's not enough to disambiguate.

   The fact the we've allowed value and type names to violate their
   respective start-with case rules is causing us trouble now that we're
   adding grammar from X.681/682/683, and we're going to have to undo
   that.

   In preparation for that I'm capitalizing the `heim_any` and
   `heim_any_set` types, and doing some additional cleanup, which
   requires changes to other parts of Heimdal (all in this same commit
   for now).

   Problems we have because of this:

    - We cannot IMPORT values into modules because we have no idea if a
      symbol being imported refers to a value or a type because the only
      clue we would have is the symbol's name, so we assume IMPORTed
      symbols are for types.

      This means we can't import OIDs, for example, which is super
      annoying.

      One thing we might be able to do here is mark imported symbols as
      being of an undetermined-but-not-undefined type, then coerce the
      symbol's type the first time it's used in a context where its type
      is inferred as type, value, object, object set, or class.  (Though
      since we don't generate C symbols for objects or classes, we won't
      be able to import them, especially since we need to know them at
      compile time and cannot defer their handling to link- or
      run-time.)

    - The `NULL` type name, and the `NULL` value name now cause two
      reduce/reduce conflicts via the `FieldSetting` production.

    - Various shift/reduce conflicts involving `NULL` values in
      non-top-level contexts (in constraints, for example).

 - Currently I have a bug where to disambiguate the grammar I have a
   CLASS_IDENTIFIER token that is all caps, while TYPE_IDENTIFIER must
   start with a capital but not be all caps, but this breaks Kerberos
   since all its types are all capitalized -- oof!

   To fix this I made it so class names have to be all caps and
   start with an underscore (ick).

TBD:

 - Check all the XXX comments and address them
 - Apply this treatment to Kerberos!  Automatic handling of authz-data
   sounds useful :)
 - Apply this treatment to PKCS#10 (CSRs) and other ASN.1 modules too.
 - Replace various bits of code in `lib/hx509/` with uses of this
   feature.
 - Add JER.
 - Enhance `hxtool` and `asn1_print`.

Getting there!
2021-02-28 18:13:08 -06:00
Nicolas Williams
0729692cc8 asn1: Templates work for IMPLICIT; add build opt
Finally.  We're almost at parity for the template compiler.

Now we have a build option to use templating:

    `./configure --enable-asn1-templating`

Tests fail if you build `rfc2459.asn1` with `--template`.

TBD: Figure out what differences remain between the two compilers, and
     fix the templating compiler accordingly, adding tests along the
     way.

Making IMPLICIT tags work in the templating compiler turned out to be a
simple fix: don't attempt to do anything clever about IMPLICIT tags in
the template generator in the compiler other than denoting them --
instead leave all the smarts about IMPLICIT tags to the interpreter.
This might be a very slight pessimization, but also a great
simplification.

The result is very elegant: when the interpreter finds an IMPLICIT
tag it then recurses to find the template for the body of the type
so-tagged, and evaluates that.  Much more elegant than the code
generated by the non-template compiler, not least for not needing
any additional temporary memory allocation.

With this we finally have parity in basic testing of the template
compiler.  Indeed, for IMPLICIT tags the template compiler and
interpreter might even be better because they support IMPLICIT tags
with BER lengths, whereas the non-template compiler doesn't (mostly
because `der_replace_tag()` needs to be changed to support it.

And, of course, the template compiler is simply superior in that it
produces smaller code and is *much* easier to work with because the
functions to interpret templates are small and simple.  Which means we
can add more functions to deal with other encoding rules fairly
trivially.  It should be possible to add all of these with very little
work, almost all of it localized to `lib/asn1/template.c`:

 - PER  Packed Encoding Rules [X.691]
 - XER  XML Encoding Rules    [X.693]
 - OER  Octet Encoding Rules  [X.696] (intended to replace PER)
 - JER  JSON Encoding Rules   [X.697] (doubles as visual representation)
 - GSER Generic String E.R.s  [RFC3641] (a visual representation)

 - XDR  External Data Repr.   [STD67][RFC4506]

       (XDR is *not* an ASN.1 encoding rules specification, but it's a
        *lot* like PER/OER but with 4-octet alignment, and is specified
        for the syntax equivalent (XDR) of only a subset of ASN.1 syntax
        and semantics.)

All we'd have to do is add variants of `_asn1_{length,encode,decode}()`
for each set of rules, then generate per-type stub functions that call
them (as we already do for DER).

We could then have an encoding rule transliteration program that takes a
`TypeName` and some representation of a value encoded by some encoding
rules, and outputs the same thing encoded by a different set of rules.
This would double as a pretty-printer and parser if we do add support
for JER and/or GSER.  It would find the template for the given type
using `dlsym()` against some shared object (possibly `libasn1` itself).

Whereas generating source code for C (or whatever language) for
additional ERs requires much more work.  Plus, templates are much
smaller, and the interpreter is tiny, which yields much smaller text and
much smaller CPU icache/dcache footprint, which yields better
performance in many cases.

As well, the template system should be much easier to port to other
languages.  Though in the cases of, e.g., Rust, it would require use of
`unsafe` in the interpreter, so in fact the inverse might be true: that
it's easier to generate safe Rust code than to implement a template
interpreter in Rust.  Similarly for Haskell, OCAML, etc.  But wherever
the template interpreter is easy to implement, it's a huge win.

Note that implementing OER and PER using the templates as they are
currently would be a bit of a challenge, as the interpreter would have
to first do a pass of each SEQUENCE/SET to determine the size and
layout of the OER/PER sequence/set preamble by counting the number of
OPTIONAL/DEFAULT members, BOOLEAN members, and extensibility markers
with extensions present.  We could always generate more entries to
encode precomputed preamble metadata.  We would also need to add a
template entry type for extensibility markers, which currently we do
not.
2021-01-23 17:48:12 -06:00
Love Hornquist Astrand
060474df16 quel 64bit warnings, fixup implicit encoding for template, fix spelling 2013-06-03 21:46:20 -07:00
Love Hörnquist Åstrand
0e6b5c5c22 remove trailing whitespace
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@25232 ec53bebd-3082-4978-b11e-865c3cabbd6b
2009-05-28 01:17:17 +00:00
Love Hörnquist Åstrand
ef2a4a3969 add BTMM style pkinit reply
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@24209 ec53bebd-3082-4978-b11e-865c3cabbd6b
2008-12-18 04:59:57 +00:00
Love Hörnquist Åstrand
c0770bf249 add id-pkinit-kdf
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@22930 ec53bebd-3082-4978-b11e-865c3cabbd6b
2008-04-09 13:06:44 +00:00
Love Hörnquist Åstrand
bc0c286502 add PkinitSP80056AOtherInfo
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@22925 ec53bebd-3082-4978-b11e-865c3cabbd6b
2008-04-09 13:06:18 +00:00
Love Hörnquist Åstrand
928c06737e Fold in pk-init-alg-agilty.
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@21677 ec53bebd-3082-4978-b11e-865c3cabbd6b
2007-07-23 18:33:31 +00:00
Love Hörnquist Åstrand
a4e2b83667 Drop ad-initial-verified-cas.
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@21094 ec53bebd-3082-4978-b11e-865c3cabbd6b
2007-06-15 19:53:52 +00:00
Love Hörnquist Åstrand
272ac7eac4 Make the pkinit nonce signed (like the kerberos nonce).
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@21088 ec53bebd-3082-4978-b11e-865c3cabbd6b
2007-06-13 19:29:49 +00:00
Love Hörnquist Åstrand
9df9f6a9da revert 21003
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@21004 ec53bebd-3082-4978-b11e-865c3cabbd6b
2007-06-08 01:53:10 +00:00
Love Hörnquist Åstrand
12df8538af use "roken.h" consitantly
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@21003 ec53bebd-3082-4978-b11e-865c3cabbd6b
2007-06-08 01:42:05 +00:00
Love Hörnquist Åstrand
8cf89ccd07 add MS-UPN-SAN
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@20743 ec53bebd-3082-4978-b11e-865c3cabbd6b
2007-05-31 17:15:52 +00:00
Love Hörnquist Åstrand
2607c5771c add id-pkinit-ms-eku
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@20186 ec53bebd-3082-4978-b11e-865c3cabbd6b
2007-02-05 11:31:29 +00:00
Love Hörnquist Åstrand
7991175dca fill in more bits of id-pkinit-ms-san
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@20185 ec53bebd-3082-4978-b11e-865c3cabbd6b
2007-02-05 11:27:48 +00:00
Love Hörnquist Åstrand
d0b797a71a Add ExternalPrincipalIdentifiers, shared between several elements.
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@17362 ec53bebd-3082-4978-b11e-865c3cabbd6b
2006-04-29 19:09:22 +00:00
Love Hörnquist Åstrand
8c6b7f98ff Add id-pkinit-ms-san.
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@16845 ec53bebd-3082-4978-b11e-865c3cabbd6b
2006-03-28 00:03:34 +00:00
Love Hörnquist Åstrand
8c24e62151 Rename id-pksan to id-pkinit-san
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@16807 ec53bebd-3082-4978-b11e-865c3cabbd6b
2006-03-26 23:13:26 +00:00
Love Hörnquist Åstrand
365aa1b86b paChecksum is now OPTIONAL so it can be upgraded to something better then SHA1
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@16730 ec53bebd-3082-4978-b11e-865c3cabbd6b
2006-02-13 11:03:24 +00:00
Love Hörnquist Åstrand
f961f7f538 Fix comment
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@16142 ec53bebd-3082-4978-b11e-865c3cabbd6b
2005-10-07 11:02:15 +00:00
Love Hörnquist Åstrand
1ef128fbff Removing PK-INIT-19 support.
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@16141 ec53bebd-3082-4978-b11e-865c3cabbd6b
2005-10-07 11:00:05 +00:00
Love Hörnquist Åstrand
9b6c2d438b Update to pkinit-27
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@15761 ec53bebd-3082-4978-b11e-865c3cabbd6b
2005-07-26 18:38:08 +00:00
Love Hörnquist Åstrand
b838707d0e Commit much improved ASN.1 compiler from joda-choice-branch.
Highlighs for the compiler is support for CHOICE and in general better
support for tags. This compiler support most of what is needed for
PK-INIT, LDAP, X.509, PKCS-12 and many other protocols.


git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@15617 ec53bebd-3082-4978-b11e-865c3cabbd6b
2005-07-12 06:27:42 +00:00
Johan Danielsson
d2e9f53ffc jox
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@8187 ec53bebd-3082-4978-b11e-865c3cabbd6b
2000-04-14 15:49:32 +00:00