Commit Graph

64 Commits

Author SHA1 Message Date
Nicolas Williams
5702bd5b77 asn1: Also decode ProxyCertInfo 2021-09-15 10:56:19 -05:00
Nicolas Williams
edf259dac9 asn1: Update comment in rfc2459.asn1 2021-08-25 15:42:24 -05:00
Nicolas Williams
df4b09f8af asn1: Also pretty-print cert policies 2021-08-12 17:31:35 -05:00
Nicolas Williams
f0e628c2cf asn1: Add Heimdal cert ext for ticket max_life 2021-03-24 19:12:00 -05:00
Nicolas Williams
be2525ef29 asn1: Fix rfc2459.asn1 compilation w/o templates 2021-03-10 21:21:26 -06:00
Nicolas Williams
be61d72be3 asn1: Some TPM fields have to be EXPLICIT
The TCG EK cert profile says that the context tags in the
TPMSecurityAssertions type are IMPLICIT.  The sample EK cert we have
has them as EXPLICIT.

What to do?
2021-03-07 00:31:47 -06:00
Nicolas Williams
a712d4157a asn1: Remove incorrect comment 2021-03-01 15:27:20 -06: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
35ad30b2b3 asn1/hx509: Undo workaround for fixed bug
Now that the ASN.1 compiler properly supports IMPLICIT tagging of named
CHOICE types (meaning: treat them as EXPLICIT tags), we can remove one
workaround for that.
2021-01-25 16:28:44 -06:00
Nicolas Williams
8fde460772 asn1: More IMPLICIT tag fixes (both compilers)
The template compiler was applying IMPLICIT tags to CHOICE types.  This
is very wrong, as the tag of a CHOICE's taken choice cannot be replaced
without making it impossible to figure out what the choice was.  An
example of this is GeneralName's directoryName, which is an IMPLICIT-
tagged CHOICE.

Separately, the non-template compiler was requiring inlining of
IMPLICIT-tagged CHOICEs, which also happens in GeneralName's
directoryName case:

```
    205 Name ::= CHOICE {
    206         rdnSequence  RDNSequence
    207 }
    ...
    287 GeneralName ::= CHOICE {
    288         otherName                       [0]     IMPLICIT -- OtherName --
    SEQUENCE {
    289                 type-id    OBJECT IDENTIFIER,
    290                 value      [0] EXPLICIT heim_any
    291         },
    292         rfc822Name                      [1]     IMPLICIT IA5String,
    293         dNSName                         [2]     IMPLICIT IA5String,
    294 --      x400Address                     [3]     IMPLICIT ORAddress,--
--->295         directoryName                   [4]     IMPLICIT -- Name -- CHOICE
    {
    296                 rdnSequence  RDNSequence
    297         },
    298 --      ediPartyName                    [5]     IMPLICIT EDIPartyName, --
    299         uniformResourceIdentifier       [6]     IMPLICIT IA5String,
    300         iPAddress                       [7]     IMPLICIT OCTET STRING,
    301         registeredID                    [8]     IMPLICIT OBJECT IDENTIFIER
    302 }
```

Anyways, that's fixed now, though changing that will require making
corresponding changes to `lib/hx509/`.

We're getting closer to parity between the two compilers.  The template
compiler is still missing support for `SET { ... }` types.  Speaking of
`SET { ... }`, the regular compiler generates code that uses `qsort()`
to sort the encoded values values of the members of such a set, but this
seems silly because the order of members is knowable at compile time, as
for DER and CER the order by the tags of the members, from lowest to
highest (see X.690, section 9.3 and X.680, section 8.6).  As it happens
using `qsort()` on the encodings of the members works, but it would be
be better to sort in `lib/asn1/asn1parse.y` and then not have to bother
anywhere else.  Sorting SETs at definition time will help keep the
tamplate compiler simple.  Not that we _need_ `SET { ... }` for anything
in-tree other than the X.690 sample...

While we're at it, let's note that the core of PKIX from the RFC
2459/3280/5280/5912 consists of *two* ASN.1 modules, one with
default-EXPLICIT tags, and one with default-IMPLICIT tags, and
Heimdal has these merged as a default-EXPLICIT tags module in
`lib/asn1/rfc2459.asn1`, with `IMPLICIT` added in by hand in all the
tags in the default-IMPLICIT tagged module.  This fixes one recently
added type from PKIX that didn't have `IMPLICIT` added in manually!
2021-01-24 20:24:01 -06:00
Nicolas Williams
94746b4bf8 asn1: Add CPS bits from RFC5280 2021-01-13 20:17:58 -06:00
Nicolas Williams
936d8dd4ee asn1: Add SRVName to PKIX module
This is in preparation to add more support for DNSSRV SANs in lib/hx509.
2021-01-13 20:17:58 -06:00
Nicolas Williams
944eae82cf asn1: Remove alias of id-kp-clientAuth 2019-11-19 23:00:41 -06:00
Nicolas Williams
b54107ee2b asn1: Add more EKU OIDs from RFC7299, OpenSSL 2019-11-02 18:37:13 -05:00
Nicolas Williams
ed1f900cfb asn1: Add some missing OIDs from RFC5280 2019-11-02 18:37:13 -05:00
Nicolas Williams
8af2d79d35 hx509: Add missing CSR extension request support
This is necessary in order to add proper support for CSRs in kx509,
where the KDC can examine all requested KUs/EKUs/SANs, check
authorization, and issue a certificate with all those extensions if
authorized.

This is the convention used by OpenSSL, of encoding all the KU, EKUs,
and SANs being requested as Extensions as they would appear in the
TBSCertificate, then putting those in as a single Attribute in the CSR's
Attributes list with attribute OID {id-pkcs-9, 14}.

 - expose all hx509_request_*() functions
 - finish support in hx509_request_parse*() for KU, EKU, and SAN CSR
   attributes
 - finish support in hx509_request_to_pkcs10() for encoding all
   requested KU, EKU, and SAN extensions as a CSR extReq (extension request)
 - add hx509_request_add_*() support for:
    - id-pkinit-san and ms-upn-pkinit-san
    - XMPP (Jabber) SAN
    - registeredID (useless but trivial)
 - add hxtool request-create options for all supported SANs
 - add hxtool request-create options for KeyUsage
 - add hxtool request-create options for ExtKeyUsage
 - add hxtool request-print support for all these things
 - fix bugs in existing id-pkinit-san handling

Possible future improvements

 - add HX509_TRACE env var and support (it would be nice to be able to
   observe why some certificate is rejected, or not matched in a query)
 - add testing that CSR creating and printing round-trip for all KUs,
   EKUs, and SANs
   (probably in tests/kdc/check-pkinit.in)
 - add testing that OpenSSL can print a CSR made by hxtool and
   vice-versa
 - hxtool ca: add KU sanity checking (via hx509_ca_sign() and/or friends)
   (don't allow encrypt for signing-only algs)
   (don't allow encrypt for RSA at all, or for RSA with small e exponents)
 - hxtool request-print: warn about all unknown attributes and
   extensions
 - hxtool ca: MAYBE add support for adding requested extensions from the
   --req=CSR
   ("Maybe" because CA operators should really verify and authorize all
    requested attributes, and should acknowledge that they have, and the
    simplest way to do this is to make them add all the corresponding
    CLI arguments to the hxtool ca command, but too, that is
    error-prone, thus it's not clear yet which approach is best.
    Perhaps interactively prompt for yes/no for each attribute.)
 - add additional SAN types:
    - iPAddress                 (useless?)
    - dNSSrv                    (useful!)
    - directoryName             (useless, but trivial)
    - uniformResourceIdentifier (useful)
 - it would be nice if the ASN.1 compiler could generate print
   functions..., and/or even better, to-JSON functions
 - it would be nice if we had a known-OID db, including the names of the
   types they refer to in certificate extensions, otherName SANs and CSR
   attributes, then we could generate a CSR and certificate printer for
   all known options even when they are not supported by the rest of
   Heimdal
    - and we could also get friendly names for OIDs, and we could
      resolve their arc names
    - longer term, we could also stand to add some ASN.1 information
      object system functionality, just enough to make
      lib/hx509/asn1_print awesome by being able to automatically decode
      all heim_any and OCTET STRING content (better than its current
      --inner option)
2019-10-08 22:20:40 -05:00
Nicolas Williams
038ed5ec31 hx509: check Name RDN attribute size bounds 2019-10-07 21:32:00 -05:00
Chris Lamb
946caad7d0 Correct "extention" typos.
Signed-off-by: Chris Lamb <chris@chris-lamb.co.uk>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Garming Sam <garming@catalyst.net.nz>
(cherry picked from Samba commit afa9bb4ac55d616fe7816e3830bab5e3a51aed7a)
2018-09-10 14:42:18 -04:00
Viktor Dukhovni
8078e089f1 Add support for ECDSA w/ SHA-2 signature algs 2016-04-15 10:32:50 -05:00
Love Hornquist Astrand
060474df16 quel 64bit warnings, fixup implicit encoding for template, fix spelling 2013-06-03 21:46:20 -07:00
Love Hornquist Astrand
e8317b955f allow optional q in DH DomainParameters 2013-04-29 11:37:39 -07:00
Love Hornquist Astrand
a0fcf9241a add id-secsig-sha-1WithRSAEncryption 2010-08-08 15:49:18 -07:00
Love Hornquist Astrand
3a29886945 add DHParameter 2010-06-16 12:20:31 -07:00
Love Hornquist Astrand
0b144cdf8d implement teletexstring 2009-09-30 00:47:39 -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
24400da6a6 Add secp160r1 and secp160r2
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@24649 ec53bebd-3082-4978-b11e-865c3cabbd6b
2009-02-07 15:12:37 +00:00
Love Hörnquist Åstrand
476f81c4e7 add id-ecdsa-with-SHA1
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@24648 ec53bebd-3082-4978-b11e-865c3cabbd6b
2009-02-07 15:12:22 +00:00
Love Hörnquist Åstrand
0ec483ada2 add ec-group-secp256r1
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@24636 ec53bebd-3082-4978-b11e-865c3cabbd6b
2009-02-07 04:06:22 +00:00
Love Hörnquist Åstrand
a8d40354e1 add secp256r1
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@24633 ec53bebd-3082-4978-b11e-865c3cabbd6b
2009-02-07 04:05:52 +00:00
Love Hörnquist Åstrand
b93daea7ea add ECDSA_Sig_Value
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@24628 ec53bebd-3082-4978-b11e-865c3cabbd6b
2009-02-07 04:05:00 +00:00
Love Hörnquist Åstrand
e79aed842f add id-ecdsa-with-SHA256
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@24626 ec53bebd-3082-4978-b11e-865c3cabbd6b
2009-02-07 04:04:40 +00:00
Love Hörnquist Åstrand
c916bc431e Add ECC bits
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@24624 ec53bebd-3082-4978-b11e-865c3cabbd6b
2009-02-07 04:04:10 +00:00
Love Hörnquist Åstrand
1b1bb2ac1f Add id-heim-rsa-pkcs1-x509.
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@22446 ec53bebd-3082-4978-b11e-865c3cabbd6b
2008-01-14 21:23:52 +00:00
Love Hörnquist Åstrand
2a15a2647a Add back SIZE limitations.
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@21396 ec53bebd-3082-4978-b11e-865c3cabbd6b
2007-07-02 10:22:16 +00:00
Love Hörnquist Åstrand
5d0464a86b Add AuthorityInfoAccessSyntax.
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@21382 ec53bebd-3082-4978-b11e-865c3cabbd6b
2007-06-28 08:29:45 +00:00
Love Hörnquist Åstrand
20a2aa9ada Add authorityInfoAccess, rename proxyCertInfo.
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@21376 ec53bebd-3082-4978-b11e-865c3cabbd6b
2007-06-28 07:36:13 +00:00
Love Hörnquist Åstrand
5de627d609 Do evil things to handle IMPLICIT encoded structures.
Add id-ms-client-authentication.


git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@20728 ec53bebd-3082-4978-b11e-865c3cabbd6b
2007-05-31 14:51:46 +00:00
Love Hörnquist Åstrand
14de225227 id-ms-cert-enroll-domaincontroller
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@20710 ec53bebd-3082-4978-b11e-865c3cabbd6b
2007-05-30 22:08:14 +00:00
Love Hörnquist Åstrand
6b8e488368 Netscape extentions
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@20657 ec53bebd-3082-4978-b11e-865c3cabbd6b
2007-05-10 21:43:20 +00:00
Love Hörnquist Åstrand
4418e220eb add U.S. Federal PKI Common Policy Framework
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@20643 ec53bebd-3082-4978-b11e-865c3cabbd6b
2007-05-10 18:31:11 +00:00
Love Hörnquist Åstrand
af4ed121c8 add CRLDistributionPoints and friends
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@20071 ec53bebd-3082-4978-b11e-865c3cabbd6b
2007-01-30 21:26:33 +00:00
Love Hörnquist Åstrand
7b7acfddc1 Add id-at-streetAddress.
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@19931 ec53bebd-3082-4978-b11e-865c3cabbd6b
2007-01-16 13:02:06 +00:00
Love Hörnquist Åstrand
2a0cc5cfca Add PKIXXmppAddr and id-pkix-on-xmppAddr.
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@19859 ec53bebd-3082-4978-b11e-865c3cabbd6b
2007-01-12 08:35:58 +00:00
Love Hörnquist Åstrand
beaf8c5bc2 Add id-pkix-kp oids.
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@19577 ec53bebd-3082-4978-b11e-865c3cabbd6b
2006-12-30 12:43:41 +00:00
Love Hörnquist Åstrand
5999737afa add pkix proxy cert policy lang oids
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@19292 ec53bebd-3082-4978-b11e-865c3cabbd6b
2006-12-08 00:08:26 +00:00
Love Hörnquist Åstrand
01fde0e9c5 unbreak id-pe-proxyCertInfo
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@19281 ec53bebd-3082-4978-b11e-865c3cabbd6b
2006-12-07 22:53:10 +00:00
Love Hörnquist Åstrand
812f7102a1 ops, remove extra stuff copied from the draft
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@19277 ec53bebd-3082-4978-b11e-865c3cabbd6b
2006-12-07 20:24:06 +00:00
Love Hörnquist Åstrand
b8fc9ba909 Add id-pkix-on-dnsSRV and related oids
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@19276 ec53bebd-3082-4978-b11e-865c3cabbd6b
2006-12-07 20:24:05 +00:00
Love Hörnquist Åstrand
e03eee6809 Add definitions from RFC 3820, Proxy Certificate Profile.
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@17248 ec53bebd-3082-4978-b11e-865c3cabbd6b
2006-04-26 08:02:56 +00:00
Love Hörnquist Åstrand
10ccb6b603 Add id-Userid
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@17203 ec53bebd-3082-4978-b11e-865c3cabbd6b
2006-04-24 09:01:40 +00:00