Ignore:
Timestamp:
Nov 27, 2012, 4:43:17 PM (13 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: updated trunk to 3.6.0

Location:
trunk/server
Files:
29 edited
2 copied

Legend:

Unmodified
Added
Removed
  • trunk/server

  • trunk/server/source4/heimdal/lib/hx509/ca.c

    r414 r745  
    11/*
    2  * Copyright (c) 2006 - 2007 Kungliga Tekniska Högskolan
     2 * Copyright (c) 2006 - 2010 Kungliga Tekniska Högskolan
    33 * (Royal Institute of Technology, Stockholm, Sweden).
    44 * All rights reserved.
     
    5454        unsigned int serial:1;
    5555        unsigned int domaincontroller:1;
     56        unsigned int xUniqueID:1;
    5657    } flags;
    5758    time_t notBefore;
     
    5960    int pathLenConstraint; /* both for CA and Proxy */
    6061    CRLDistributionPoints crldp;
     62    heim_bit_string subjectUniqueID;
     63    heim_bit_string issuerUniqueID;
     64
    6165};
    6266
     
    8084    if (*tbs == NULL)
    8185        return ENOMEM;
    82 
    83     (*tbs)->subject = NULL;
    84     (*tbs)->san.len = 0;
    85     (*tbs)->san.val = NULL;
    86     (*tbs)->eku.len = 0;
    87     (*tbs)->eku.val = NULL;
    88     (*tbs)->pathLenConstraint = 0;
    89     (*tbs)->crldp.len = 0;
    90     (*tbs)->crldp.val = NULL;
    9186
    9287    return 0;
     
    112107    der_free_heim_integer(&(*tbs)->serial);
    113108    free_CRLDistributionPoints(&(*tbs)->crldp);
    114 
     109    der_free_bit_string(&(*tbs)->subjectUniqueID);
     110    der_free_bit_string(&(*tbs)->issuerUniqueID);
    115111    hx509_name_free(&(*tbs)->subject);
    116112
     
    486482
    487483        gn.element = choice_GeneralName_uniformResourceIdentifier;
    488         gn.u.uniformResourceIdentifier = rk_UNCONST(uri);
     484        gn.u.uniformResourceIdentifier.data = rk_UNCONST(uri);
     485        gn.u.uniformResourceIdentifier.length = strlen(uri);
    489486
    490487        ASN1_MALLOC_ENCODE(DistributionPointName,
     
    786783    memset(&gn, 0, sizeof(gn));
    787784    gn.element = choice_GeneralName_dNSName;
    788     gn.u.dNSName = rk_UNCONST(dnsname);
     785    gn.u.dNSName.data = rk_UNCONST(dnsname);
     786    gn.u.dNSName.length = strlen(dnsname);
    789787
    790788    return add_GeneralNames(&tbs->san, &gn);
     
    813811    memset(&gn, 0, sizeof(gn));
    814812    gn.element = choice_GeneralName_rfc822Name;
    815     gn.u.rfc822Name = rk_UNCONST(rfc822Name);
     813    gn.u.rfc822Name.data = rk_UNCONST(rfc822Name);
     814    gn.u.rfc822Name.length = strlen(rfc822Name);
    816815
    817816    return add_GeneralNames(&tbs->san, &gn);
     
    841840
    842841/**
     842 * Set the issuerUniqueID and subjectUniqueID
     843 *
     844 * These are only supposed to be used considered with version 2
     845 * certificates, replaced by the two extensions SubjectKeyIdentifier
     846 * and IssuerKeyIdentifier. This function is to allow application
     847 * using legacy protocol to issue them.
     848 *
     849 * @param context A hx509 context.
     850 * @param tbs object to be signed.
     851 * @param issuerUniqueID to be set
     852 * @param subjectUniqueID to be set
     853 *
     854 * @return An hx509 error code, see hx509_get_error_string().
     855 *
     856 * @ingroup hx509_ca
     857 */
     858
     859int
     860hx509_ca_tbs_set_unique(hx509_context context,
     861                        hx509_ca_tbs tbs,
     862                        const heim_bit_string *subjectUniqueID,
     863                        const heim_bit_string *issuerUniqueID)
     864{
     865    int ret;
     866
     867    der_free_bit_string(&tbs->subjectUniqueID);
     868    der_free_bit_string(&tbs->issuerUniqueID);
     869   
     870    if (subjectUniqueID) {
     871        ret = der_copy_bit_string(subjectUniqueID, &tbs->subjectUniqueID);
     872        if (ret)
     873            return ret;
     874    }
     875
     876    if (issuerUniqueID) {
     877        ret = der_copy_bit_string(issuerUniqueID, &tbs->issuerUniqueID);
     878        if (ret)
     879            return ret;
     880    }
     881
     882    return 0;
     883}
     884
     885/**
    843886 * Expand the the subject name in the to-be-signed certificate object
    844887 * using hx509_name_expand().
     
    861904    return hx509_name_expand(context, tbs->subject, env);
    862905}
     906
     907/*
     908 *
     909 */
    863910
    864911static int
     
    10911138    }
    10921139    /* issuerUniqueID  [1]  IMPLICIT BIT STRING OPTIONAL */
     1140    if (tbs->issuerUniqueID.length) {
     1141        tbsc->issuerUniqueID = calloc(1, sizeof(*tbsc->issuerUniqueID));
     1142        if (tbsc->issuerUniqueID == NULL) {
     1143            ret = ENOMEM;
     1144            hx509_set_error_string(context, 0, ret, "Out of memory");
     1145            goto out;
     1146        }
     1147        ret = der_copy_bit_string(&tbs->issuerUniqueID, tbsc->issuerUniqueID);
     1148        if (ret) {
     1149            hx509_set_error_string(context, 0, ret, "Out of memory");
     1150            goto out;
     1151        }
     1152    }
    10931153    /* subjectUniqueID [2]  IMPLICIT BIT STRING OPTIONAL */
     1154    if (tbs->subjectUniqueID.length) {
     1155        tbsc->subjectUniqueID = calloc(1, sizeof(*tbsc->subjectUniqueID));
     1156        if (tbsc->subjectUniqueID == NULL) {
     1157            ret = ENOMEM;
     1158            hx509_set_error_string(context, 0, ret, "Out of memory");
     1159            goto out;
     1160        }
     1161
     1162        ret = der_copy_bit_string(&tbs->subjectUniqueID, tbsc->subjectUniqueID);
     1163        if (ret) {
     1164            hx509_set_error_string(context, 0, ret, "Out of memory");
     1165            goto out;
     1166        }
     1167    }
     1168
    10941169    /* extensions      [3]  EXPLICIT Extensions OPTIONAL */
    10951170    tbsc->extensions = calloc(1, sizeof(*tbsc->extensions));
     
    11941269
    11951270        {
    1196             SHA_CTX m;
    1197        
    1198             SHA1_Init(&m);
    1199             SHA1_Update(&m, tbs->spki.subjectPublicKey.data,
    1200                         tbs->spki.subjectPublicKey.length / 8);
    1201             SHA1_Final (hash, &m);
     1271            EVP_MD_CTX *ctx;
     1272
     1273            ctx = EVP_MD_CTX_create();
     1274            EVP_DigestInit_ex(ctx, EVP_sha1(), NULL);
     1275            EVP_DigestUpdate(ctx, tbs->spki.subjectPublicKey.data,
     1276                             tbs->spki.subjectPublicKey.length / 8);
     1277            EVP_DigestFinal_ex(ctx, hash, NULL);
     1278            EVP_MD_CTX_destroy(ctx);
    12021279        }
    12031280
  • trunk/server/source4/heimdal/lib/hx509/cert.c

    r414 r745  
    284284    }
    285285    if (size != len) {
     286        free_Certificate(&t);
    286287        hx509_set_error_string(context, 0, HX509_EXTRA_DATA_AFTER_STRUCTURE,
    287288                               "Extra data after certificate");
     
    310311{
    311312    if (cert->private_key)
    312         _hx509_private_key_free(&cert->private_key);
     313        hx509_private_key_free(&cert->private_key);
    313314    cert->private_key = _hx509_private_key_ref(private_key);
    314315    return 0;
     
    341342
    342343    if (cert->private_key)
    343         _hx509_private_key_free(&cert->private_key);
     344        hx509_private_key_free(&cert->private_key);
    344345
    345346    free_Certificate(cert->data);
     
    446447    if (ctx->trust_anchors)
    447448        hx509_certs_free(&ctx->trust_anchors);
    448     ctx->trust_anchors = _hx509_certs_ref(set);
     449    ctx->trust_anchors = hx509_certs_ref(set);
    449450}
    450451
     
    10231024                          &cert->tbsCertificate.issuer, &diff);
    10241025    *self_signed = (diff == 0);
    1025     if (ret)
     1026    if (ret) {
    10261027        hx509_set_error_string(context, 0, ret,
    10271028                               "Failed to check if self signed");
     1029    } else
     1030        ret = _hx509_self_signed_valid(context, &cert->signatureAlgorithm);
     1031
    10281032    return ret;
    10291033}
     
    15071511}
    15081512
     1513static int
     1514get_x_unique_id(hx509_context context, const char *name,
     1515                const heim_bit_string *cert, heim_bit_string *subject)
     1516{
     1517    int ret;
     1518
     1519    if (cert == NULL) {
     1520        ret = HX509_EXTENSION_NOT_FOUND;
     1521        hx509_set_error_string(context, 0, ret, "%s unique id doesn't exists", name);
     1522        return ret;
     1523    }
     1524    ret = der_copy_bit_string(cert, subject);
     1525    if (ret) {
     1526        hx509_set_error_string(context, 0, ret, "malloc out of memory", name);
     1527        return ret;
     1528    }
     1529    return 0;
     1530}
     1531
     1532/**
     1533 * Get a copy of the Issuer Unique ID
     1534 *
     1535 * @param context a hx509_context
     1536 * @param p a hx509 certificate
     1537 * @param issuer the issuer id returned, free with der_free_bit_string()
     1538 *
     1539 * @return An hx509 error code, see hx509_get_error_string(). The
     1540 * error code HX509_EXTENSION_NOT_FOUND is returned if the certificate
     1541 * doesn't have a issuerUniqueID
     1542 *
     1543 * @ingroup hx509_cert
     1544 */
     1545
     1546int
     1547hx509_cert_get_issuer_unique_id(hx509_context context, hx509_cert p, heim_bit_string *issuer)
     1548{
     1549    return get_x_unique_id(context, "issuer", p->data->tbsCertificate.issuerUniqueID, issuer);
     1550}
     1551
     1552/**
     1553 * Get a copy of the Subect Unique ID
     1554 *
     1555 * @param context a hx509_context
     1556 * @param p a hx509 certificate
     1557 * @param subject the subject id returned, free with der_free_bit_string()
     1558 *
     1559 * @return An hx509 error code, see hx509_get_error_string(). The
     1560 * error code HX509_EXTENSION_NOT_FOUND is returned if the certificate
     1561 * doesn't have a subjectUniqueID
     1562 *
     1563 * @ingroup hx509_cert
     1564 */
     1565
     1566int
     1567hx509_cert_get_subject_unique_id(hx509_context context, hx509_cert p, heim_bit_string *subject)
     1568{
     1569    return get_x_unique_id(context, "subject", p->data->tbsCertificate.subjectUniqueID, subject);
     1570}
     1571
    15091572
    15101573hx509_private_key
     
    15451608    }
    15461609
    1547     return _hx509_private_key_private_decrypt(context,
     1610    return hx509_private_key_private_decrypt(context,
    15481611                                              ciphertext,
    15491612                                              encryption_oid,
     
    15531616
    15541617int
    1555 _hx509_cert_public_encrypt(hx509_context context,
     1618hx509_cert_public_encrypt(hx509_context context,
    15561619                           const heim_octet_string *cleartext,
    15571620                           const hx509_cert p,
     
    16931756        const char *s;
    16941757        size_t len1, len2;
    1695         s = strchr(c->u.rfc822Name, '@');
     1758        s = memchr(c->u.rfc822Name.data, '@', c->u.rfc822Name.length);
    16961759        if (s) {
    1697             if (strcasecmp(c->u.rfc822Name, n->u.rfc822Name) != 0)
     1760            if (der_printable_string_cmp(&c->u.rfc822Name, &n->u.rfc822Name) != 0)
    16981761                return HX509_NAME_CONSTRAINT_ERROR;
    16991762        } else {
    1700             s = strchr(n->u.rfc822Name, '@');
     1763            s = memchr(n->u.rfc822Name.data, '@', n->u.rfc822Name.length);
    17011764            if (s == NULL)
    17021765                return HX509_NAME_CONSTRAINT_ERROR;
    1703             len1 = strlen(c->u.rfc822Name);
    1704             len2 = strlen(s + 1);
     1766            len1 = c->u.rfc822Name.length;
     1767            len2 = n->u.rfc822Name.length -
     1768                (s - ((char *)n->u.rfc822Name.data));
    17051769            if (len1 > len2)
    17061770                return HX509_NAME_CONSTRAINT_ERROR;
    1707             if (strcasecmp(s + 1 + len2 - len1, c->u.rfc822Name) != 0)
     1771            if (memcmp(s + 1 + len2 - len1, c->u.rfc822Name.data, len1) != 0)
    17081772                return HX509_NAME_CONSTRAINT_ERROR;
    17091773            if (len1 < len2 && s[len2 - len1 + 1] != '.')
     
    17151779    case choice_GeneralName_dNSName: {
    17161780        size_t lenc, lenn;
    1717 
    1718         lenc = strlen(c->u.dNSName);
    1719         lenn = strlen(n->u.dNSName);
     1781        char *ptr;
     1782
     1783        lenc = c->u.dNSName.length;
     1784        lenn = n->u.dNSName.length;
    17201785        if (lenc > lenn)
    17211786            return HX509_NAME_CONSTRAINT_ERROR;
    1722         if (strcasecmp(&n->u.dNSName[lenn - lenc], c->u.dNSName) != 0)
     1787        ptr = n->u.dNSName.data;
     1788        if (memcmp(&ptr[lenn - lenc], c->u.dNSName.data, lenc) != 0)
    17231789            return HX509_NAME_CONSTRAINT_ERROR;
    1724         if (lenc != lenn && n->u.dNSName[lenn - lenc - 1] != '.')
     1790        if (lenn != lenc && ptr[lenn - lenc - 1] != '.')
    17251791            return HX509_NAME_CONSTRAINT_ERROR;
    17261792        *match = 1;
     
    19271993     */
    19281994    if (ctx->trust_anchors)
    1929         anchors = _hx509_certs_ref(ctx->trust_anchors);
     1995        anchors = hx509_certs_ref(ctx->trust_anchors);
    19301996    else if (context->default_trust_anchors && ALLOW_DEF_TA(ctx))
    1931         anchors = _hx509_certs_ref(context->default_trust_anchors);
     1997        anchors = hx509_certs_ref(context->default_trust_anchors);
    19321998    else {
    19331999        ret = hx509_certs_init(context, "MEMORY:no-TA", 0, NULL, &anchors);
     
    22442310
    22452311    for (i = path.len - 1; i >= 0; i--) {
    2246         Certificate *signer, *c;
     2312        hx509_cert signer;
     2313        Certificate *c;
    22472314
    22482315        c = _hx509_get_cert(path.val[i]);
     
    22522319            int selfsigned;
    22532320
    2254             signer = path.val[i]->data;
    2255 
    2256             ret = certificate_is_self_signed(context, signer, &selfsigned);
     2321            signer = path.val[i];
     2322
     2323            ret = certificate_is_self_signed(context, signer->data, &selfsigned);
    22572324            if (ret)
    22582325                goto out;
     
    22632330        } else {
    22642331            /* take next certificate in chain */
    2265             signer = path.val[i + 1]->data;
     2332            signer = path.val[i + 1];
    22662333        }
    22672334
     
    23272394                       const heim_octet_string *sig)
    23282395{
    2329     return _hx509_verify_signature(context, signer->data, alg, data, sig);
    2330 }
     2396    return _hx509_verify_signature(context, signer, alg, data, sig);
     2397}
     2398
     2399int
     2400_hx509_verify_signature_bitstring(hx509_context context,
     2401                                  const hx509_cert signer,
     2402                                  const AlgorithmIdentifier *alg,
     2403                                  const heim_octet_string *data,
     2404                                  const heim_bit_string *sig)
     2405{
     2406    heim_octet_string os;
     2407
     2408    if (sig->length & 7) {
     2409        hx509_set_error_string(context, 0, HX509_CRYPTO_SIG_INVALID_FORMAT,
     2410                               "signature not multiple of 8 bits");
     2411        return HX509_CRYPTO_SIG_INVALID_FORMAT;
     2412    }
     2413
     2414    os.data = sig->data;
     2415    os.length = sig->length / 8;
     2416
     2417    return _hx509_verify_signature(context, signer, alg, data, &os);
     2418}
     2419
    23312420
    23322421
     
    23792468        for (j = 0; j < san.len; j++) {
    23802469            switch (san.val[j].element) {
    2381             case choice_GeneralName_dNSName:
    2382                 if (strcasecmp(san.val[j].u.dNSName, hostname) == 0) {
     2470            case choice_GeneralName_dNSName: {
     2471                heim_printable_string hn;
     2472                hn.data = rk_UNCONST(hostname);
     2473                hn.length = strlen(hostname);
     2474               
     2475                if (der_printable_string_cmp(&san.val[j].u.dNSName, &hn) == 0) {
    23832476                    free_GeneralNames(&san);
    23842477                    return 0;
    23852478                }
    23862479                break;
     2480            }
    23872481            default:
    23882482                break;
     
    24022496                DirectoryString *ds = &n->value;
    24032497                switch (ds->element) {
    2404                 case choice_DirectoryString_printableString:
    2405                     if (strcasecmp(ds->u.printableString, hostname) == 0)
     2498                case choice_DirectoryString_printableString: {
     2499                    heim_printable_string hn;
     2500                    hn.data = rk_UNCONST(hostname);
     2501                    hn.length = strlen(hostname);
     2502
     2503                    if (der_printable_string_cmp(&ds->u.printableString, &hn) == 0)
    24062504                        return 0;
    24072505                    break;
    2408                 case choice_DirectoryString_ia5String:
    2409                     if (strcasecmp(ds->u.ia5String, hostname) == 0)
    2410                     return 0;
     2506                }
     2507                case choice_DirectoryString_ia5String: {
     2508                    heim_ia5_string hn;
     2509                    hn.data = rk_UNCONST(hostname);
     2510                    hn.length = strlen(hostname);
     2511
     2512                    if (der_ia5_string_cmp(&ds->u.ia5String, &hn) == 0)
     2513                        return 0;
    24112514                    break;
     2515                }
    24122516                case choice_DirectoryString_utf8String:
    24132517                    if (strcasecmp(ds->u.utf8String, hostname) == 0)
     
    32283332 * @param c the certificate to encode.
    32293333 * @param os the encode certificate, set to NULL, 0 on case of
    3230  * error. Free the returned structure with hx509_xfree().
     3334 * error. Free the os->data with hx509_xfree().
    32313335 *
    32323336 * @return An hx509 error code, see hx509_get_error_string().
     
    33843488        heim_octet_string os, sig;
    33853489        hx509_env envhash = NULL;
    3386         char *buf;
    33873490
    33883491        os.data = c->tbsCertificate.subjectPublicKeyInfo.subjectPublicKey.data;
     
    34303533    return ret;
    34313534}
     3535
     3536/**
     3537 * Print a simple representation of a certificate
     3538 *
     3539 * @param context A hx509 context, can be NULL
     3540 * @param cert certificate to print
     3541 * @param out the stdio output stream, if NULL, stdout is used
     3542 *
     3543 * @return An hx509 error code
     3544 *
     3545 * @ingroup hx509_cert
     3546 */
     3547
     3548int
     3549hx509_print_cert(hx509_context context, hx509_cert cert, FILE *out)
     3550{
     3551    hx509_name name;
     3552    char *str;
     3553    int ret;
     3554
     3555    if (out == NULL)
     3556        out = stderr;
     3557
     3558    ret = hx509_cert_get_issuer(cert, &name);
     3559    if (ret)
     3560        return ret;
     3561    hx509_name_to_string(name, &str);
     3562    hx509_name_free(&name);
     3563    fprintf(out, "    issuer:  \"%s\"\n", str);
     3564    free(str);
     3565
     3566    ret = hx509_cert_get_subject(cert, &name);
     3567    if (ret)
     3568        return ret;
     3569    hx509_name_to_string(name, &str);
     3570    hx509_name_free(&name);
     3571    fprintf(out, "    subject: \"%s\"\n", str);
     3572    free(str);
     3573
     3574    {
     3575        heim_integer serialNumber;
     3576
     3577        ret = hx509_cert_get_serialnumber(cert, &serialNumber);
     3578        if (ret)
     3579            return ret;
     3580        ret = der_print_hex_heim_integer(&serialNumber, &str);
     3581        if (ret)
     3582            return ret;
     3583        der_free_heim_integer(&serialNumber);
     3584        fprintf(out, "    serial: %s\n", str);
     3585        free(str);
     3586    }
     3587
     3588    printf("    keyusage: ");
     3589    ret = hx509_cert_keyusage_print(context, cert, &str);
     3590    if (ret == 0) {
     3591        fprintf(out, "%s\n", str);
     3592        free(str);
     3593    } else
     3594        fprintf(out, "no");
     3595
     3596    return 0;
     3597}
  • trunk/server/source4/heimdal/lib/hx509/cms.c

    r414 r745  
    533533 *    - HX509_CMS_EV_NO_KU_CHECK - Dont check KU on certificate
    534534 *    - HX509_CMS_EV_ALLOW_WEAK - Allow weak crytpo
     535 *    - HX509_CMS_EV_ID_NAME - prefer issuer name and serial number
    535536 * @param cert Certificate to encrypt the EnvelopedData encryption key
    536537 * with.
     
    560561    heim_octet_string key;
    561562    hx509_crypto crypto = NULL;
     563    int ret, cmsidflag;
    562564    EnvelopedData ed;
    563565    size_t size;
    564     int ret;
    565566
    566567    memset(&ivec, 0, sizeof(ivec));
     
    649650    ri = &ed.recipientInfos.val[0];
    650651
    651     ri->version = 0;
    652     ret = fill_CMSIdentifier(cert, CMS_ID_SKI, &ri->rid);
     652    if (flags & HX509_CMS_EV_ID_NAME) {
     653        ri->version = 0;
     654        cmsidflag = CMS_ID_NAME;
     655    } else {
     656        ri->version = 2;
     657        cmsidflag = CMS_ID_SKI;
     658    }
     659       
     660    ret = fill_CMSIdentifier(cert, cmsidflag, &ri->rid);
    653661    if (ret) {
    654662        hx509_set_error_string(context, 0, ret,
     
    658666    }
    659667
    660     ret = _hx509_cert_public_encrypt(context,
     668    ret = hx509_cert_public_encrypt(context,
    661669                                     &key, cert,
    662670                                     &ri->keyEncryptionAlgorithm.algorithm,
     
    11711179    hx509_peer_info peer;
    11721180    int cmsidflag;
     1181    int leafonly;
    11731182    hx509_certs certs;
    11741183    hx509_certs anchors;
     
    13611370        unsigned int i;
    13621371
    1363         if (sigctx->pool) {
     1372        if (sigctx->pool && sigctx->leafonly == 0) {
    13641373            _hx509_calculate_path(context,
    13651374                                  HX509_CALCULATE_PATH_NO_ANCHOR,
     
    14161425}
    14171426
     1427static int
     1428cmp_AlgorithmIdentifier(const AlgorithmIdentifier *p, const AlgorithmIdentifier *q)
     1429{
     1430    return der_heim_oid_cmp(&p->algorithm, &q->algorithm);
     1431}
     1432
    14181433int
    14191434hx509_cms_create_signed(hx509_context context,
     
    14281443                        heim_octet_string *signed_data)
    14291444{
    1430     unsigned int i;
     1445    unsigned int i, j;
    14311446    hx509_name name;
    14321447    int ret;
     
    14551470        sigctx.cmsidflag = CMS_ID_SKI;
    14561471
    1457     ret = hx509_certs_init(context, "MEMORY:certs", 0, NULL, &sigctx.certs);
    1458     if (ret)
    1459         return ret;
     1472    /**
     1473     * Use HX509_CMS_SIGNATURE_LEAF_ONLY to only request leaf
     1474     * certificates to be added to the SignedData.
     1475     */
     1476    sigctx.leafonly = (flags & HX509_CMS_SIGNATURE_LEAF_ONLY) ? 1 : 0;
     1477
     1478    /**
     1479     * Use HX509_CMS_NO_CERTS to make the SignedData contain no
     1480     * certificates, overrides HX509_CMS_SIGNATURE_LEAF_ONLY.
     1481     */
     1482
     1483    if ((flags & HX509_CMS_SIGNATURE_NO_CERTS) == 0) {
     1484        ret = hx509_certs_init(context, "MEMORY:certs", 0, NULL, &sigctx.certs);
     1485        if (ret)
     1486            return ret;
     1487    }
    14601488
    14611489    sigctx.anchors = anchors;
     
    14921520     */
    14931521    if ((flags & HX509_CMS_SIGNATURE_NO_SIGNER) == 0) {
    1494         ret = hx509_certs_iter(context, certs, sig_process, &sigctx);
     1522        ret = hx509_certs_iter_f(context, certs, sig_process, &sigctx);
    14951523        if (ret)
    14961524            goto out;
     
    14981526
    14991527    if (sigctx.sd.signerInfos.len) {
    1500         ALLOC_SEQ(&sigctx.sd.digestAlgorithms, sigctx.sd.signerInfos.len);
    1501         if (sigctx.sd.digestAlgorithms.val == NULL) {
    1502             ret = ENOMEM;
    1503             hx509_clear_error_string(context);
    1504             goto out;
    1505         }
    1506        
    1507         /* XXX remove dups */
    15081528        for (i = 0; i < sigctx.sd.signerInfos.len; i++) {
    15091529            AlgorithmIdentifier *di =
    15101530                &sigctx.sd.signerInfos.val[i].digestAlgorithm;
    1511             ret = copy_AlgorithmIdentifier(di,
    1512                                            &sigctx.sd.digestAlgorithms.val[i]);
    1513             if (ret) {
    1514                 hx509_clear_error_string(context);
    1515                 goto out;
     1531
     1532            for (j = 0; j < sigctx.sd.digestAlgorithms.len; j++)
     1533                if (cmp_AlgorithmIdentifier(di, &sigctx.sd.digestAlgorithms.val[j]) == 0)
     1534                    break;
     1535            if (j < sigctx.sd.digestAlgorithms.len) {
     1536                ret = add_DigestAlgorithmIdentifiers(&sigctx.sd.digestAlgorithms, di);
     1537                if (ret) {
     1538                    hx509_clear_error_string(context);
     1539                    goto out;
     1540                }
    15161541            }
    15171542        }
     
    15261551        }
    15271552
    1528         ret = hx509_certs_iter(context, sigctx.certs, cert_process, &sigctx);
     1553        ret = hx509_certs_iter_f(context, sigctx.certs, cert_process, &sigctx);
    15291554        if (ret)
    15301555            goto out;
  • trunk/server/source4/heimdal/lib/hx509/collector.c

    r414 r745  
    106106    free_AlgorithmIdentifier(&key->alg);
    107107    if (key->private_key)
    108         _hx509_private_key_free(&key->private_key);
     108        hx509_private_key_free(&key->private_key);
    109109    der_free_octet_string(&key->localKeyId);
    110110    free(key);
     
    144144        key->private_key = private_key;
    145145    } else {
    146         ret = _hx509_parse_private_key(context, alg,
     146        ret = hx509_parse_private_key(context, alg,
    147147                                       key_data->data, key_data->length,
     148                                       HX509_KEY_FORMAT_DER,
    148149                                       &key->private_key);
    149150        if (ret)
  • trunk/server/source4/heimdal/lib/hx509/crypto.c

    r414 r745  
    5454    int (*export)(hx509_context context,
    5555                  const hx509_private_key,
     56                  hx509_key_format_t,
    5657                  heim_octet_string *);
    5758    int (*import)(hx509_context, const AlgorithmIdentifier *,
    58                   const void *, size_t, hx509_private_key);
     59                  const void *, size_t, hx509_key_format_t,
     60                  hx509_private_key);
    5961    int (*generate_private_key)(hx509_context,
    6062                                struct hx509_generate_private_context *,
     
    8890    const AlgorithmIdentifier *digest_alg;
    8991    int flags;
    90 #define PROVIDE_CONF 1
    91 #define REQUIRE_SIGNER 2
     92#define PROVIDE_CONF    0x1
     93#define REQUIRE_SIGNER  0x2
     94#define SELF_SIGNED_OK  0x4
    9295
    9396#define SIG_DIGEST      0x100
     
    98101
    99102    time_t best_before; /* refuse signature made after best before date */
     103    const EVP_MD *(*evp_md)(void);
    100104    int (*verify_signature)(hx509_context context,
    101105                            const struct signature_alg *,
     
    148152};
    149153
    150 static const unsigned md2_oid_tree[] = { 1, 2, 840, 113549, 2, 2 };
    151 const AlgorithmIdentifier _hx509_signature_md2_data = {
    152     { 6, rk_UNCONST(md2_oid_tree) }, rk_UNCONST(&null_entry_oid)
    153 };
    154 
    155154static const unsigned ecPublicKey[] ={ 1, 2, 840, 10045, 2, 1 };
    156155const AlgorithmIdentifier _hx509_signature_ecPublicKey = {
     
    191190const AlgorithmIdentifier _hx509_signature_rsa_with_md5_data = {
    192191    { 7, rk_UNCONST(rsa_with_md5_oid) }, NULL
    193 };
    194 
    195 static const unsigned rsa_with_md2_oid[] ={ 1, 2, 840, 113549, 1, 1, 2 };
    196 const AlgorithmIdentifier _hx509_signature_rsa_with_md2_data = {
    197     { 7, rk_UNCONST(rsa_with_md2_oid) }, NULL
    198192};
    199193
     
    282276     */
    283277
    284     if (der_heim_oid_cmp(oid, &asn1_oid_id_ec_group_secp256r1) == 0)
     278    if (der_heim_oid_cmp(oid, ASN1_OID_ID_EC_GROUP_SECP256R1) == 0)
    285279        return NID_X9_62_prime256v1;
    286     else if (der_heim_oid_cmp(oid, &asn1_oid_id_ec_group_secp160r1) == 0)
     280    else if (der_heim_oid_cmp(oid, ASN1_OID_ID_EC_GROUP_SECP160R1) == 0)
    287281        return NID_secp160r1;
    288     else if (der_heim_oid_cmp(oid, &asn1_oid_id_ec_group_secp160r2) == 0)
     282    else if (der_heim_oid_cmp(oid, ASN1_OID_ID_EC_GROUP_SECP160R2) == 0)
    289283        return NID_secp160r2;
    290284
     
    369363    spi = &signer->tbsCertificate.subjectPublicKeyInfo;
    370364
    371     if (der_heim_oid_cmp(&spi->algorithm.algorithm, &asn1_oid_id_ecPublicKey) != 0)
     365    if (der_heim_oid_cmp(&spi->algorithm.algorithm, ASN1_OID_ID_ECPUBLICKEY) != 0)
    372366        return HX509_CRYPTO_SIG_INVALID_FORMAT;
    373367
     
    430424    int ret;
    431425
    432     if (signer->ops && der_heim_oid_cmp(signer->ops->key_oid, &asn1_oid_id_ecPublicKey) != 0)
     426    if (signer->ops && der_heim_oid_cmp(signer->ops->key_oid, ASN1_OID_ID_ECPUBLICKEY) != 0)
    433427        _hx509_abort("internal error passing private key to wrong ops");
    434428
     
    550544    int ret;
    551545    RSA *rsa;
    552     RSAPublicKey pk;
    553546    size_t size;
     547    const unsigned char *p;
    554548
    555549    memset(&di, 0, sizeof(di));
     
    557551    spi = &signer->tbsCertificate.subjectPublicKeyInfo;
    558552
    559     rsa = RSA_new();
     553    p = spi->subjectPublicKey.data;
     554    size = spi->subjectPublicKey.length / 8;
     555   
     556    rsa = d2i_RSAPublicKey(NULL, &p, size);
    560557    if (rsa == NULL) {
    561         hx509_set_error_string(context, 0, ENOMEM, "out of memory");
    562         return ENOMEM;
    563     }
    564     ret = decode_RSAPublicKey(spi->subjectPublicKey.data,
    565                               spi->subjectPublicKey.length / 8,
    566                               &pk, &size);
    567     if (ret) {
    568         hx509_set_error_string(context, 0, ret, "Failed to decode RSAPublicKey");
    569         goto out;
    570     }
    571 
    572     rsa->n = heim_int2BN(&pk.modulus);
    573     rsa->e = heim_int2BN(&pk.publicExponent);
    574 
    575     free_RSAPublicKey(&pk);
    576 
    577     if (rsa->n == NULL || rsa->e == NULL) {
    578558        ret = ENOMEM;
    579559        hx509_set_error_string(context, 0, ret, "out of memory");
     
    642622    } else {
    643623        if (retsize != data->length ||
    644             memcmp(to, data->data, retsize) != 0)
     624            ct_memcmp(to, data->data, retsize) != 0)
    645625        {
    646626            ret = HX509_CRYPTO_SIG_INVALID_FORMAT;
     
    650630        free(to);
    651631    }
     632    ret = 0;
    652633
    653634 out:
    654635    free_DigestInfo(&di);
    655     RSA_free(rsa);
     636    if (rsa)
     637        RSA_free(rsa);
    656638    return ret;
    657639}
     
    672654    int ret;
    673655
    674     if (signer->ops && der_heim_oid_cmp(signer->ops->key_oid, &asn1_oid_id_pkcs1_rsaEncryption) != 0)
     656    if (signer->ops && der_heim_oid_cmp(signer->ops->key_oid, ASN1_OID_ID_PKCS1_RSAENCRYPTION) != 0)
    675657        return HX509_ALG_NOT_SUPP;
    676658
     
    680662        sig_oid = signer->signature_alg;
    681663
    682     if (der_heim_oid_cmp(sig_oid, &asn1_oid_id_pkcs1_sha256WithRSAEncryption) == 0) {
     664    if (der_heim_oid_cmp(sig_oid, ASN1_OID_ID_PKCS1_SHA512WITHRSAENCRYPTION) == 0) {
     665        digest_alg = hx509_signature_sha512();
     666    } else if (der_heim_oid_cmp(sig_oid, ASN1_OID_ID_PKCS1_SHA384WITHRSAENCRYPTION) == 0) {
     667        digest_alg = hx509_signature_sha384();
     668    } else if (der_heim_oid_cmp(sig_oid, ASN1_OID_ID_PKCS1_SHA256WITHRSAENCRYPTION) == 0) {
    683669        digest_alg = hx509_signature_sha256();
    684     } else if (der_heim_oid_cmp(sig_oid, &asn1_oid_id_pkcs1_sha1WithRSAEncryption) == 0) {
     670    } else if (der_heim_oid_cmp(sig_oid, ASN1_OID_ID_PKCS1_SHA1WITHRSAENCRYPTION) == 0) {
    685671        digest_alg = hx509_signature_sha1();
    686     } else if (der_heim_oid_cmp(sig_oid, &asn1_oid_id_pkcs1_md5WithRSAEncryption) == 0) {
     672    } else if (der_heim_oid_cmp(sig_oid, ASN1_OID_ID_PKCS1_MD5WITHRSAENCRYPTION) == 0) {
    687673        digest_alg = hx509_signature_md5();
    688     } else if (der_heim_oid_cmp(sig_oid, &asn1_oid_id_pkcs1_md5WithRSAEncryption) == 0) {
     674    } else if (der_heim_oid_cmp(sig_oid, ASN1_OID_ID_PKCS1_MD5WITHRSAENCRYPTION) == 0) {
    689675        digest_alg = hx509_signature_md5();
    690     } else if (der_heim_oid_cmp(sig_oid, &asn1_oid_id_dsa_with_sha1) == 0) {
     676    } else if (der_heim_oid_cmp(sig_oid, ASN1_OID_ID_DSA_WITH_SHA1) == 0) {
    691677        digest_alg = hx509_signature_sha1();
    692     } else if (der_heim_oid_cmp(sig_oid, &asn1_oid_id_pkcs1_rsaEncryption) == 0) {
     678    } else if (der_heim_oid_cmp(sig_oid, ASN1_OID_ID_PKCS1_RSAENCRYPTION) == 0) {
    693679        digest_alg = hx509_signature_sha1();
    694     } else if (der_heim_oid_cmp(sig_oid, &asn1_oid_id_heim_rsa_pkcs1_x509) == 0) {
     680    } else if (der_heim_oid_cmp(sig_oid, ASN1_OID_ID_HEIM_RSA_PKCS1_X509) == 0) {
    695681        digest_alg = NULL;
    696682    } else
     
    751737        ret = HX509_CMS_FAILED_CREATE_SIGATURE;
    752738        hx509_set_error_string(context, 0, ret,
    753                                "RSA private decrypt failed: %d", ret);
     739                               "RSA private encrypt failed: %d", ret);
    754740        return ret;
    755741    }
     
    767753                       const void *data,
    768754                       size_t len,
     755                       hx509_key_format_t format,
    769756                       hx509_private_key private_key)
    770757{
    771     const unsigned char *p = data;
    772 
    773     private_key->private_key.rsa =
    774         d2i_RSAPrivateKey(NULL, &p, len);
    775     if (private_key->private_key.rsa == NULL) {
    776         hx509_set_error_string(context, 0, HX509_PARSING_KEY_FAILED,
    777                                "Failed to parse RSA key");
    778         return HX509_PARSING_KEY_FAILED;
    779     }
    780     private_key->signature_alg = &asn1_oid_id_pkcs1_sha1WithRSAEncryption;
     758    switch (format) {
     759    case HX509_KEY_FORMAT_DER: {
     760        const unsigned char *p = data;
     761
     762        private_key->private_key.rsa =
     763            d2i_RSAPrivateKey(NULL, &p, len);
     764        if (private_key->private_key.rsa == NULL) {
     765            hx509_set_error_string(context, 0, HX509_PARSING_KEY_FAILED,
     766                                   "Failed to parse RSA key");
     767            return HX509_PARSING_KEY_FAILED;
     768        }
     769        private_key->signature_alg = ASN1_OID_ID_PKCS1_SHA1WITHRSAENCRYPTION;
     770        break;
     771
     772    }
     773    default:
     774        return HX509_CRYPTO_KEY_FORMAT_UNSUPPORTED;
     775    }
    781776
    782777    return 0;
     
    801796    spki->subjectPublicKey.length = len * 8;
    802797
    803     ret = set_digest_alg(&spki->algorithm, &asn1_oid_id_pkcs1_rsaEncryption,
     798    ret = set_digest_alg(&spki->algorithm, ASN1_OID_ID_PKCS1_RSAENCRYPTION,
    804799                         "\x05\x00", 2);
    805800    if (ret) {
     
    829824
    830825    static const int default_rsa_e = 65537;
    831     static const int default_rsa_bits = 1024;
     826    static const int default_rsa_bits = 2048;
    832827
    833828    private_key->private_key.rsa = RSA_new();
     
    845840    if (ctx->num_bits)
    846841        bits = ctx->num_bits;
    847     else if (ctx->isCA)
    848         bits *= 2;
    849842
    850843    ret = RSA_generate_key_ex(private_key->private_key.rsa, bits, e, NULL);
     
    855848        return HX509_PARSING_KEY_FAILED;
    856849    }
    857     private_key->signature_alg = &asn1_oid_id_pkcs1_sha1WithRSAEncryption;
     850    private_key->signature_alg = ASN1_OID_ID_PKCS1_SHA1WITHRSAENCRYPTION;
    858851
    859852    return 0;
     
    863856rsa_private_key_export(hx509_context context,
    864857                       const hx509_private_key key,
     858                       hx509_key_format_t format,
    865859                       heim_octet_string *data)
    866860{
     
    870864    data->length = 0;
    871865
    872     ret = i2d_RSAPrivateKey(key->private_key.rsa, NULL);
    873     if (ret <= 0) {
    874         ret = EINVAL;
    875         hx509_set_error_string(context, 0, ret,
     866    switch (format) {
     867    case HX509_KEY_FORMAT_DER:
     868
     869        ret = i2d_RSAPrivateKey(key->private_key.rsa, NULL);
     870        if (ret <= 0) {
     871            ret = EINVAL;
     872            hx509_set_error_string(context, 0, ret,
    876873                               "Private key is not exportable");
    877         return ret;
    878     }
    879 
    880     data->data = malloc(ret);
    881     if (data->data == NULL) {
    882         ret = ENOMEM;
    883         hx509_set_error_string(context, 0, ret, "malloc out of memory");
    884         return ret;
    885     }
    886     data->length = ret;
    887 
    888     {
    889         unsigned char *p = data->data;
    890         i2d_RSAPrivateKey(key->private_key.rsa, &p);
     874            return ret;
     875        }
     876
     877        data->data = malloc(ret);
     878        if (data->data == NULL) {
     879            ret = ENOMEM;
     880            hx509_set_error_string(context, 0, ret, "malloc out of memory");
     881            return ret;
     882        }
     883        data->length = ret;
     884
     885        {
     886            unsigned char *p = data->data;
     887            i2d_RSAPrivateKey(key->private_key.rsa, &p);
     888        }
     889        break;
     890    default:
     891        return HX509_CRYPTO_KEY_FORMAT_UNSUPPORTED;
    891892    }
    892893
     
    911912static hx509_private_key_ops rsa_private_key_ops = {
    912913    "RSA PRIVATE KEY",
    913     &asn1_oid_id_pkcs1_rsaEncryption,
     914    ASN1_OID_ID_PKCS1_RSAENCRYPTION,
    914915    NULL,
    915916    rsa_private_key2SPKI,
     
    934935ecdsa_private_key_export(hx509_context context,
    935936                         const hx509_private_key key,
     937                         hx509_key_format_t format,
    936938                         heim_octet_string *data)
    937939{
    938     return ENOMEM;
     940    return HX509_CRYPTO_KEY_FORMAT_UNSUPPORTED;
    939941}
    940942
     
    944946                         const void *data,
    945947                         size_t len,
     948                         hx509_key_format_t format,
    946949                         hx509_private_key private_key)
    947950{
     
    978981    }
    979982
    980     private_key->private_key.ecdsa = d2i_ECPrivateKey(pkey, &p, len);
    981     if (private_key->private_key.ecdsa == NULL) {
    982         hx509_set_error_string(context, 0, HX509_PARSING_KEY_FAILED,
    983                                "Failed to parse EC private key");
    984         return HX509_PARSING_KEY_FAILED;
    985     }
    986     private_key->signature_alg = &asn1_oid_id_ecdsa_with_SHA256;
     983    switch (format) {
     984    case HX509_KEY_FORMAT_DER:
     985
     986        private_key->private_key.ecdsa = d2i_ECPrivateKey(pkey, &p, len);
     987        if (private_key->private_key.ecdsa == NULL) {
     988            hx509_set_error_string(context, 0, HX509_PARSING_KEY_FAILED,
     989                                   "Failed to parse EC private key");
     990            return HX509_PARSING_KEY_FAILED;
     991        }
     992        private_key->signature_alg = ASN1_OID_ID_ECDSA_WITH_SHA256;
     993        break;
     994
     995    default:
     996        return HX509_CRYPTO_KEY_FORMAT_UNSUPPORTED;
     997    }
    987998
    988999    return 0;
     
    10081019static hx509_private_key_ops ecdsa_private_key_ops = {
    10091020    "EC PRIVATE KEY",
    1010     &asn1_oid_id_ecPublicKey,
     1021    ASN1_OID_ID_ECPUBLICKEY,
    10111022    ecdsa_available,
    10121023    ecdsa_private_key2SPKI,
     
    11211132    if (private_key->private_key.dsa == NULL)
    11221133        return EINVAL;
    1123     private_key->signature_alg = &asn1_oid_id_dsa_with_sha1;
     1134    private_key->signature_alg = ASN1_OID_ID_DSA_WITH_SHA1;
    11241135
    11251136    return 0;
     
    11311142#endif
    11321143
    1133 
    11341144static int
    1135 sha1_verify_signature(hx509_context context,
    1136                       const struct signature_alg *sig_alg,
    1137                       const Certificate *signer,
    1138                       const AlgorithmIdentifier *alg,
    1139                       const heim_octet_string *data,
    1140                       const heim_octet_string *sig)
    1141 {
    1142     unsigned char digest[SHA_DIGEST_LENGTH];
    1143     SHA_CTX m;
    1144 
    1145     if (sig->length != SHA_DIGEST_LENGTH) {
    1146         hx509_set_error_string(context, 0, HX509_CRYPTO_SIG_INVALID_FORMAT,
    1147                                "SHA1 sigature have wrong length");
    1148         return HX509_CRYPTO_SIG_INVALID_FORMAT;
    1149     }
    1150 
    1151     SHA1_Init(&m);
    1152     SHA1_Update(&m, data->data, data->length);
    1153     SHA1_Final (digest, &m);
    1154        
    1155     if (memcmp(digest, sig->data, SHA_DIGEST_LENGTH) != 0) {
    1156         hx509_set_error_string(context, 0, HX509_CRYPTO_BAD_SIGNATURE,
    1157                                "Bad SHA1 sigature");
    1158         return HX509_CRYPTO_BAD_SIGNATURE;
    1159     }
    1160 
    1161     return 0;
    1162 }
    1163 
    1164 static int
    1165 sha256_create_signature(hx509_context context,
     1145evp_md_create_signature(hx509_context context,
    11661146                        const struct signature_alg *sig_alg,
    11671147                        const hx509_private_key signer,
     
    11711151                        heim_octet_string *sig)
    11721152{
    1173     SHA256_CTX m;
     1153    size_t sigsize = EVP_MD_size(sig_alg->evp_md());
     1154    EVP_MD_CTX *ctx;
    11741155
    11751156    memset(sig, 0, sizeof(*sig));
     
    11841165       
    11851166
    1186     sig->data = malloc(SHA256_DIGEST_LENGTH);
     1167    sig->data = malloc(sigsize);
    11871168    if (sig->data == NULL) {
    11881169        sig->length = 0;
    11891170        return ENOMEM;
    11901171    }
    1191     sig->length = SHA256_DIGEST_LENGTH;
    1192 
    1193     SHA256_Init(&m);
    1194     SHA256_Update(&m, data->data, data->length);
    1195     SHA256_Final (sig->data, &m);
     1172    sig->length = sigsize;
     1173
     1174    ctx = EVP_MD_CTX_create();
     1175    EVP_DigestInit_ex(ctx, sig_alg->evp_md(), NULL);
     1176    EVP_DigestUpdate(ctx, data->data, data->length);
     1177    EVP_DigestFinal_ex(ctx, sig->data, NULL);
     1178    EVP_MD_CTX_destroy(ctx);
     1179
    11961180
    11971181    return 0;
     
    11991183
    12001184static int
    1201 sha256_verify_signature(hx509_context context,
     1185evp_md_verify_signature(hx509_context context,
    12021186                        const struct signature_alg *sig_alg,
    12031187                        const Certificate *signer,
     
    12061190                        const heim_octet_string *sig)
    12071191{
    1208     unsigned char digest[SHA256_DIGEST_LENGTH];
    1209     SHA256_CTX m;
    1210 
    1211     if (sig->length != SHA256_DIGEST_LENGTH) {
     1192    unsigned char digest[EVP_MAX_MD_SIZE];
     1193    EVP_MD_CTX *ctx;
     1194    size_t sigsize = EVP_MD_size(sig_alg->evp_md());
     1195
     1196    if (sig->length != sigsize || sigsize > sizeof(digest)) {
    12121197        hx509_set_error_string(context, 0, HX509_CRYPTO_SIG_INVALID_FORMAT,
    12131198                               "SHA256 sigature have wrong length");
     
    12151200    }
    12161201
    1217     SHA256_Init(&m);
    1218     SHA256_Update(&m, data->data, data->length);
    1219     SHA256_Final (digest, &m);
    1220        
    1221     if (memcmp(digest, sig->data, SHA256_DIGEST_LENGTH) != 0) {
     1202    ctx = EVP_MD_CTX_create();
     1203    EVP_DigestInit_ex(ctx, sig_alg->evp_md(), NULL);
     1204    EVP_DigestUpdate(ctx, data->data, data->length);
     1205    EVP_DigestFinal_ex(ctx, digest, NULL);
     1206    EVP_MD_CTX_destroy(ctx);
     1207
     1208    if (ct_memcmp(digest, sig->data, sigsize) != 0) {
    12221209        hx509_set_error_string(context, 0, HX509_CRYPTO_BAD_SIGNATURE,
    1223                                "Bad SHA256 sigature");
    1224         return HX509_CRYPTO_BAD_SIGNATURE;
    1225     }
    1226 
    1227     return 0;
    1228 }
    1229 
    1230 static int
    1231 sha1_create_signature(hx509_context context,
    1232                       const struct signature_alg *sig_alg,
    1233                       const hx509_private_key signer,
    1234                       const AlgorithmIdentifier *alg,
    1235                       const heim_octet_string *data,
    1236                       AlgorithmIdentifier *signatureAlgorithm,
    1237                       heim_octet_string *sig)
    1238 {
    1239     SHA_CTX m;
    1240 
    1241     memset(sig, 0, sizeof(*sig));
    1242 
    1243     if (signatureAlgorithm) {
    1244         int ret;
    1245         ret = set_digest_alg(signatureAlgorithm, sig_alg->sig_oid,
    1246                              "\x05\x00", 2);
    1247         if (ret)
    1248             return ret;
    1249     }
    1250        
    1251 
    1252     sig->data = malloc(SHA_DIGEST_LENGTH);
    1253     if (sig->data == NULL) {
    1254         sig->length = 0;
    1255         return ENOMEM;
    1256     }
    1257     sig->length = SHA_DIGEST_LENGTH;
    1258 
    1259     SHA1_Init(&m);
    1260     SHA1_Update(&m, data->data, data->length);
    1261     SHA1_Final (sig->data, &m);
    1262 
    1263     return 0;
    1264 }
    1265 
    1266 static int
    1267 md5_verify_signature(hx509_context context,
    1268                      const struct signature_alg *sig_alg,
    1269                      const Certificate *signer,
    1270                      const AlgorithmIdentifier *alg,
    1271                      const heim_octet_string *data,
    1272                      const heim_octet_string *sig)
    1273 {
    1274     unsigned char digest[MD5_DIGEST_LENGTH];
    1275     MD5_CTX m;
    1276 
    1277     if (sig->length != MD5_DIGEST_LENGTH) {
    1278         hx509_set_error_string(context, 0, HX509_CRYPTO_SIG_INVALID_FORMAT,
    1279                                "MD5 sigature have wrong length");
    1280         return HX509_CRYPTO_SIG_INVALID_FORMAT;
    1281     }
    1282 
    1283     MD5_Init(&m);
    1284     MD5_Update(&m, data->data, data->length);
    1285     MD5_Final (digest, &m);
    1286        
    1287     if (memcmp(digest, sig->data, MD5_DIGEST_LENGTH) != 0) {
    1288         hx509_set_error_string(context, 0, HX509_CRYPTO_BAD_SIGNATURE,
    1289                                "Bad MD5 sigature");
    1290         return HX509_CRYPTO_BAD_SIGNATURE;
    1291     }
    1292 
    1293     return 0;
    1294 }
    1295 
    1296 static int
    1297 md2_verify_signature(hx509_context context,
    1298                      const struct signature_alg *sig_alg,
    1299                      const Certificate *signer,
    1300                      const AlgorithmIdentifier *alg,
    1301                      const heim_octet_string *data,
    1302                      const heim_octet_string *sig)
    1303 {
    1304     unsigned char digest[MD2_DIGEST_LENGTH];
    1305     MD2_CTX m;
    1306 
    1307     if (sig->length != MD2_DIGEST_LENGTH) {
    1308         hx509_set_error_string(context, 0, HX509_CRYPTO_SIG_INVALID_FORMAT,
    1309                                "MD2 sigature have wrong length");
    1310         return HX509_CRYPTO_SIG_INVALID_FORMAT;
    1311     }
    1312 
    1313     MD2_Init(&m);
    1314     MD2_Update(&m, data->data, data->length);
    1315     MD2_Final (digest, &m);
    1316        
    1317     if (memcmp(digest, sig->data, MD2_DIGEST_LENGTH) != 0) {
    1318         hx509_set_error_string(context, 0, HX509_CRYPTO_BAD_SIGNATURE,
    1319                                "Bad MD2 sigature");
     1210                               "Bad %s sigature", sig_alg->name);
    13201211        return HX509_CRYPTO_BAD_SIGNATURE;
    13211212    }
     
    13281219static const struct signature_alg ecdsa_with_sha256_alg = {
    13291220    "ecdsa-with-sha256",
    1330     &asn1_oid_id_ecdsa_with_SHA256,
     1221    ASN1_OID_ID_ECDSA_WITH_SHA256,
    13311222    &_hx509_signature_ecdsa_with_sha256_data,
    1332     &asn1_oid_id_ecPublicKey,
     1223    ASN1_OID_ID_ECPUBLICKEY,
    13331224    &_hx509_signature_sha256_data,
    1334     PROVIDE_CONF|REQUIRE_SIGNER|RA_RSA_USES_DIGEST_INFO|SIG_PUBLIC_SIG,
     1225    PROVIDE_CONF|REQUIRE_SIGNER|RA_RSA_USES_DIGEST_INFO|SIG_PUBLIC_SIG|SELF_SIGNED_OK,
    13351226    0,
     1227    NULL,
    13361228    ecdsa_verify_signature,
    13371229    ecdsa_create_signature,
     
    13411233static const struct signature_alg ecdsa_with_sha1_alg = {
    13421234    "ecdsa-with-sha1",
    1343     &asn1_oid_id_ecdsa_with_SHA1,
     1235    ASN1_OID_ID_ECDSA_WITH_SHA1,
    13441236    &_hx509_signature_ecdsa_with_sha1_data,
    1345     &asn1_oid_id_ecPublicKey,
     1237    ASN1_OID_ID_ECPUBLICKEY,
    13461238    &_hx509_signature_sha1_data,
    1347     PROVIDE_CONF|REQUIRE_SIGNER|RA_RSA_USES_DIGEST_INFO|SIG_PUBLIC_SIG,
     1239    PROVIDE_CONF|REQUIRE_SIGNER|RA_RSA_USES_DIGEST_INFO|SIG_PUBLIC_SIG|SELF_SIGNED_OK,
    13481240    0,
     1241    NULL,
    13491242    ecdsa_verify_signature,
    13501243    ecdsa_create_signature,
     
    13561249static const struct signature_alg heim_rsa_pkcs1_x509 = {
    13571250    "rsa-pkcs1-x509",
    1358     &asn1_oid_id_heim_rsa_pkcs1_x509,
     1251    ASN1_OID_ID_HEIM_RSA_PKCS1_X509,
    13591252    &_hx509_signature_rsa_pkcs1_x509_data,
    1360     &asn1_oid_id_pkcs1_rsaEncryption,
     1253    ASN1_OID_ID_PKCS1_RSAENCRYPTION,
    13611254    NULL,
    13621255    PROVIDE_CONF|REQUIRE_SIGNER|SIG_PUBLIC_SIG,
    13631256    0,
     1257    NULL,
    13641258    rsa_verify_signature,
    13651259    rsa_create_signature
     
    13681262static const struct signature_alg pkcs1_rsa_sha1_alg = {
    13691263    "rsa",
    1370     &asn1_oid_id_pkcs1_rsaEncryption,
     1264    ASN1_OID_ID_PKCS1_RSAENCRYPTION,
    13711265    &_hx509_signature_rsa_with_sha1_data,
    1372     &asn1_oid_id_pkcs1_rsaEncryption,
     1266    ASN1_OID_ID_PKCS1_RSAENCRYPTION,
    13731267    NULL,
    1374     PROVIDE_CONF|REQUIRE_SIGNER|RA_RSA_USES_DIGEST_INFO|SIG_PUBLIC_SIG,
     1268    PROVIDE_CONF|REQUIRE_SIGNER|RA_RSA_USES_DIGEST_INFO|SIG_PUBLIC_SIG|SELF_SIGNED_OK,
    13751269    0,
     1270    NULL,
    13761271    rsa_verify_signature,
    13771272    rsa_create_signature
    13781273};
    13791274
     1275static const struct signature_alg rsa_with_sha512_alg = {
     1276    "rsa-with-sha512",
     1277    ASN1_OID_ID_PKCS1_SHA512WITHRSAENCRYPTION,
     1278    &_hx509_signature_rsa_with_sha512_data,
     1279    ASN1_OID_ID_PKCS1_RSAENCRYPTION,
     1280    &_hx509_signature_sha512_data,
     1281    PROVIDE_CONF|REQUIRE_SIGNER|RA_RSA_USES_DIGEST_INFO|SIG_PUBLIC_SIG|SELF_SIGNED_OK,
     1282    0,
     1283    NULL,
     1284    rsa_verify_signature,
     1285    rsa_create_signature
     1286};
     1287
     1288static const struct signature_alg rsa_with_sha384_alg = {
     1289    "rsa-with-sha384",
     1290    ASN1_OID_ID_PKCS1_SHA384WITHRSAENCRYPTION,
     1291    &_hx509_signature_rsa_with_sha384_data,
     1292    ASN1_OID_ID_PKCS1_RSAENCRYPTION,
     1293    &_hx509_signature_sha384_data,
     1294    PROVIDE_CONF|REQUIRE_SIGNER|RA_RSA_USES_DIGEST_INFO|SIG_PUBLIC_SIG|SELF_SIGNED_OK,
     1295    0,
     1296    NULL,
     1297    rsa_verify_signature,
     1298    rsa_create_signature
     1299};
     1300
    13801301static const struct signature_alg rsa_with_sha256_alg = {
    13811302    "rsa-with-sha256",
    1382     &asn1_oid_id_pkcs1_sha256WithRSAEncryption,
     1303    ASN1_OID_ID_PKCS1_SHA256WITHRSAENCRYPTION,
    13831304    &_hx509_signature_rsa_with_sha256_data,
    1384     &asn1_oid_id_pkcs1_rsaEncryption,
     1305    ASN1_OID_ID_PKCS1_RSAENCRYPTION,
    13851306    &_hx509_signature_sha256_data,
    1386     PROVIDE_CONF|REQUIRE_SIGNER|RA_RSA_USES_DIGEST_INFO|SIG_PUBLIC_SIG,
     1307    PROVIDE_CONF|REQUIRE_SIGNER|RA_RSA_USES_DIGEST_INFO|SIG_PUBLIC_SIG|SELF_SIGNED_OK,
    13871308    0,
     1309    NULL,
    13881310    rsa_verify_signature,
    13891311    rsa_create_signature
     
    13921314static const struct signature_alg rsa_with_sha1_alg = {
    13931315    "rsa-with-sha1",
    1394     &asn1_oid_id_pkcs1_sha1WithRSAEncryption,
     1316    ASN1_OID_ID_PKCS1_SHA1WITHRSAENCRYPTION,
    13951317    &_hx509_signature_rsa_with_sha1_data,
    1396     &asn1_oid_id_pkcs1_rsaEncryption,
     1318    ASN1_OID_ID_PKCS1_RSAENCRYPTION,
    13971319    &_hx509_signature_sha1_data,
    1398     PROVIDE_CONF|REQUIRE_SIGNER|RA_RSA_USES_DIGEST_INFO|SIG_PUBLIC_SIG,
     1320    PROVIDE_CONF|REQUIRE_SIGNER|RA_RSA_USES_DIGEST_INFO|SIG_PUBLIC_SIG|SELF_SIGNED_OK,
    13991321    0,
     1322    NULL,
    14001323    rsa_verify_signature,
    14011324    rsa_create_signature
    14021325};
    14031326
     1327static const struct signature_alg rsa_with_sha1_alg_secsig = {
     1328    "rsa-with-sha1",
     1329    ASN1_OID_ID_SECSIG_SHA_1WITHRSAENCRYPTION,
     1330    &_hx509_signature_rsa_with_sha1_data,
     1331    ASN1_OID_ID_PKCS1_RSAENCRYPTION,
     1332    &_hx509_signature_sha1_data,
     1333    PROVIDE_CONF|REQUIRE_SIGNER|RA_RSA_USES_DIGEST_INFO|SIG_PUBLIC_SIG|SELF_SIGNED_OK,
     1334    0,
     1335    NULL,
     1336    rsa_verify_signature,
     1337    rsa_create_signature
     1338};
     1339
    14041340static const struct signature_alg rsa_with_md5_alg = {
    14051341    "rsa-with-md5",
    1406     &asn1_oid_id_pkcs1_md5WithRSAEncryption,
     1342    ASN1_OID_ID_PKCS1_MD5WITHRSAENCRYPTION,
    14071343    &_hx509_signature_rsa_with_md5_data,
    1408     &asn1_oid_id_pkcs1_rsaEncryption,
     1344    ASN1_OID_ID_PKCS1_RSAENCRYPTION,
    14091345    &_hx509_signature_md5_data,
    14101346    PROVIDE_CONF|REQUIRE_SIGNER|RA_RSA_USES_DIGEST_INFO|SIG_PUBLIC_SIG,
    14111347    1230739889,
     1348    NULL,
    14121349    rsa_verify_signature,
    14131350    rsa_create_signature
    14141351};
    14151352
    1416 static const struct signature_alg rsa_with_md2_alg = {
    1417     "rsa-with-md2",
    1418     &asn1_oid_id_pkcs1_md2WithRSAEncryption,
    1419     &_hx509_signature_rsa_with_md2_data,
    1420     &asn1_oid_id_pkcs1_rsaEncryption,
    1421     &_hx509_signature_md2_data,
    1422     PROVIDE_CONF|REQUIRE_SIGNER|RA_RSA_USES_DIGEST_INFO|SIG_PUBLIC_SIG,
    1423     1230739889,
    1424     rsa_verify_signature,
    1425     rsa_create_signature
    1426 };
    1427 
    14281353static const struct signature_alg dsa_sha1_alg = {
    14291354    "dsa-with-sha1",
    1430     &asn1_oid_id_dsa_with_sha1,
     1355    ASN1_OID_ID_DSA_WITH_SHA1,
    14311356    NULL,
    1432     &asn1_oid_id_dsa,
     1357    ASN1_OID_ID_DSA,
    14331358    &_hx509_signature_sha1_data,
    14341359    PROVIDE_CONF|REQUIRE_SIGNER|SIG_PUBLIC_SIG,
    14351360    0,
     1361    NULL,
    14361362    dsa_verify_signature,
    14371363    /* create_signature */ NULL,
    14381364};
    14391365
     1366static const struct signature_alg sha512_alg = {
     1367    "sha-512",
     1368    ASN1_OID_ID_SHA512,
     1369    &_hx509_signature_sha512_data,
     1370    NULL,
     1371    NULL,
     1372    SIG_DIGEST,
     1373    0,
     1374    EVP_sha512,
     1375    evp_md_verify_signature,
     1376    evp_md_create_signature
     1377};
     1378
     1379static const struct signature_alg sha384_alg = {
     1380    "sha-384",
     1381    ASN1_OID_ID_SHA512,
     1382    &_hx509_signature_sha384_data,
     1383    NULL,
     1384    NULL,
     1385    SIG_DIGEST,
     1386    0,
     1387    EVP_sha384,
     1388    evp_md_verify_signature,
     1389    evp_md_create_signature
     1390};
     1391
    14401392static const struct signature_alg sha256_alg = {
    14411393    "sha-256",
    1442     &asn1_oid_id_sha256,
     1394    ASN1_OID_ID_SHA256,
    14431395    &_hx509_signature_sha256_data,
    14441396    NULL,
     
    14461398    SIG_DIGEST,
    14471399    0,
    1448     sha256_verify_signature,
    1449     sha256_create_signature
     1400    EVP_sha256,
     1401    evp_md_verify_signature,
     1402    evp_md_create_signature
    14501403};
    14511404
    14521405static const struct signature_alg sha1_alg = {
    14531406    "sha1",
    1454     &asn1_oid_id_secsig_sha_1,
     1407    ASN1_OID_ID_SECSIG_SHA_1,
    14551408    &_hx509_signature_sha1_data,
    14561409    NULL,
     
    14581411    SIG_DIGEST,
    14591412    0,
    1460     sha1_verify_signature,
    1461     sha1_create_signature
     1413    EVP_sha1,
     1414    evp_md_verify_signature,
     1415    evp_md_create_signature
    14621416};
    14631417
    14641418static const struct signature_alg md5_alg = {
    14651419    "rsa-md5",
    1466     &asn1_oid_id_rsa_digest_md5,
     1420    ASN1_OID_ID_RSA_DIGEST_MD5,
    14671421    &_hx509_signature_md5_data,
    14681422    NULL,
     
    14701424    SIG_DIGEST,
    14711425    0,
    1472     md5_verify_signature
    1473 };
    1474 
    1475 static const struct signature_alg md2_alg = {
    1476     "rsa-md2",
    1477     &asn1_oid_id_rsa_digest_md2,
    1478     &_hx509_signature_md2_data,
    1479     NULL,
    1480     NULL,
    1481     SIG_DIGEST,
    1482     0,
    1483     md2_verify_signature
     1426    EVP_md5,
     1427    evp_md_verify_signature,
     1428    NULL
    14841429};
    14851430
     
    14941439    &ecdsa_with_sha1_alg,
    14951440#endif
     1441    &rsa_with_sha512_alg,
     1442    &rsa_with_sha384_alg,
    14961443    &rsa_with_sha256_alg,
    14971444    &rsa_with_sha1_alg,
     1445    &rsa_with_sha1_alg_secsig,
    14981446    &pkcs1_rsa_sha1_alg,
    14991447    &rsa_with_md5_alg,
    1500     &rsa_with_md2_alg,
    15011448    &heim_rsa_pkcs1_x509,
    15021449    &dsa_sha1_alg,
     1450    &sha512_alg,
     1451    &sha384_alg,
    15031452    &sha256_alg,
    15041453    &sha1_alg,
    15051454    &md5_alg,
    1506     &md2_alg,
    15071455    NULL
    15081456};
     
    15591507};
    15601508
    1561 static hx509_private_key_ops *
    1562 find_private_alg(const heim_oid *oid)
     1509hx509_private_key_ops *
     1510hx509_find_private_alg(const heim_oid *oid)
    15631511{
    15641512    int i;
     
    15991547
    16001548int
    1601 _hx509_verify_signature(hx509_context context,
    1602                         const Certificate *signer,
    1603                         const AlgorithmIdentifier *alg,
    1604                         const heim_octet_string *data,
    1605                         const heim_octet_string *sig)
     1549_hx509_self_signed_valid(hx509_context context,
     1550                         const AlgorithmIdentifier *alg)
    16061551{
    16071552    const struct signature_alg *md;
     
    16121557        return HX509_SIG_ALG_NO_SUPPORTED;
    16131558    }
     1559    if ((md->flags & SELF_SIGNED_OK) == 0) {
     1560        hx509_set_error_string(context, 0, HX509_CRYPTO_ALGORITHM_BEST_BEFORE,
     1561                               "Algorithm %s not trusted for self signatures",
     1562                               md->name);
     1563        return HX509_CRYPTO_ALGORITHM_BEST_BEFORE;
     1564    }
     1565    return 0;
     1566}
     1567
     1568
     1569int
     1570_hx509_verify_signature(hx509_context context,
     1571                        const hx509_cert cert,
     1572                        const AlgorithmIdentifier *alg,
     1573                        const heim_octet_string *data,
     1574                        const heim_octet_string *sig)
     1575{
     1576    const struct signature_alg *md;
     1577    const Certificate *signer = NULL;
     1578
     1579    if (cert)
     1580        signer = _hx509_get_cert(cert);
     1581
     1582    md = find_sig_alg(&alg->algorithm);
     1583    if (md == NULL) {
     1584        hx509_clear_error_string(context);
     1585        return HX509_SIG_ALG_NO_SUPPORTED;
     1586    }
    16141587    if (signer && (md->flags & PROVIDE_CONF) == 0) {
    16151588        hx509_clear_error_string(context);
     
    16301603    }
    16311604    return (*md->verify_signature)(context, md, signer, alg, data, sig);
    1632 }
    1633 
    1634 int
    1635 _hx509_verify_signature_bitstring(hx509_context context,
    1636                                   const Certificate *signer,
    1637                                   const AlgorithmIdentifier *alg,
    1638                                   const heim_octet_string *data,
    1639                                   const heim_bit_string *sig)
    1640 {
    1641     heim_octet_string os;
    1642 
    1643     if (sig->length & 7) {
    1644         hx509_set_error_string(context, 0, HX509_CRYPTO_SIG_INVALID_FORMAT,
    1645                                "signature not multiple of 8 bits");
    1646         return HX509_CRYPTO_SIG_INVALID_FORMAT;
    1647     }
    1648 
    1649     os.data = sig->data;
    1650     os.length = sig->length / 8;
    1651 
    1652     return _hx509_verify_signature(context, signer, alg, data, &os);
    16531605}
    16541606
     
    17121664    int ret;
    17131665    RSA *rsa;
    1714     RSAPublicKey pk;
    17151666    size_t size;
     1667    const unsigned char *p;
    17161668
    17171669    ciphertext->data = NULL;
     
    17201672    spi = &cert->tbsCertificate.subjectPublicKeyInfo;
    17211673
    1722     rsa = RSA_new();
     1674    p = spi->subjectPublicKey.data;
     1675    size = spi->subjectPublicKey.length / 8;
     1676   
     1677    rsa = d2i_RSAPublicKey(NULL, &p, size);
    17231678    if (rsa == NULL) {
    1724         hx509_set_error_string(context, 0, ENOMEM, "out of memory");
    1725         return ENOMEM;
    1726     }
    1727 
    1728     ret = decode_RSAPublicKey(spi->subjectPublicKey.data,
    1729                               spi->subjectPublicKey.length / 8,
    1730                               &pk, &size);
    1731     if (ret) {
    1732         RSA_free(rsa);
    1733         hx509_set_error_string(context, 0, ret, "RSAPublicKey decode failure");
    1734         return ret;
    1735     }
    1736     rsa->n = heim_int2BN(&pk.modulus);
    1737     rsa->e = heim_int2BN(&pk.publicExponent);
    1738 
    1739     free_RSAPublicKey(&pk);
    1740 
    1741     if (rsa->n == NULL || rsa->e == NULL) {
    1742         RSA_free(rsa);
    17431679        hx509_set_error_string(context, 0, ENOMEM, "out of memory");
    17441680        return ENOMEM;
     
    17691705    ciphertext->data = to;
    17701706
    1771     ret = der_copy_oid(&asn1_oid_id_pkcs1_rsaEncryption, encryption_oid);
     1707    ret = der_copy_oid(ASN1_OID_ID_PKCS1_RSAENCRYPTION, encryption_oid);
    17721708    if (ret) {
    17731709        der_free_octet_string(ciphertext);
     
    17801716
    17811717int
    1782 _hx509_private_key_private_decrypt(hx509_context context,
     1718hx509_private_key_private_decrypt(hx509_context context,
    17831719                                   const heim_octet_string *ciphertext,
    17841720                                   const heim_oid *encryption_oid,
     
    18231759
    18241760int
    1825 _hx509_parse_private_key(hx509_context context,
     1761hx509_parse_private_key(hx509_context context,
    18261762                         const AlgorithmIdentifier *keyai,
    18271763                         const void *data,
    18281764                         size_t len,
     1765                         hx509_key_format_t format,
    18291766                         hx509_private_key *private_key)
    18301767{
     
    18341771    *private_key = NULL;
    18351772
    1836     ops = find_private_alg(&keyai->algorithm);
     1773    ops = hx509_find_private_alg(&keyai->algorithm);
    18371774    if (ops == NULL) {
    18381775        hx509_clear_error_string(context);
     
    18401777    }
    18411778
    1842     ret = _hx509_private_key_init(private_key, ops, NULL);
     1779    ret = hx509_private_key_init(private_key, ops, NULL);
    18431780    if (ret) {
    18441781        hx509_set_error_string(context, 0, ret, "out of memory");
     
    18461783    }
    18471784
    1848     ret = (*ops->import)(context, keyai, data, len, *private_key);
     1785    ret = (*ops->import)(context, keyai, data, len, format, *private_key);
    18491786    if (ret)
    1850         _hx509_private_key_free(private_key);
     1787        hx509_private_key_free(private_key);
    18511788
    18521789    return ret;
     
    18581795
    18591796int
    1860 _hx509_private_key2SPKI(hx509_context context,
     1797hx509_private_key2SPKI(hx509_context context,
    18611798                        hx509_private_key private_key,
    18621799                        SubjectPublicKeyInfo *spki)
     
    18781815    *ctx = NULL;
    18791816
    1880     if (der_heim_oid_cmp(oid, &asn1_oid_id_pkcs1_rsaEncryption) != 0) {
     1817    if (der_heim_oid_cmp(oid, ASN1_OID_ID_PKCS1_RSAENCRYPTION) != 0) {
    18811818        hx509_set_error_string(context, 0, EINVAL,
    18821819                               "private key not an RSA key");
     
    19291866    *private_key = NULL;
    19301867
    1931     ops = find_private_alg(ctx->key_oid);
     1868    ops = hx509_find_private_alg(ctx->key_oid);
    19321869    if (ops == NULL) {
    19331870        hx509_clear_error_string(context);
     
    19351872    }
    19361873
    1937     ret = _hx509_private_key_init(private_key, ops, NULL);
     1874    ret = hx509_private_key_init(private_key, ops, NULL);
    19381875    if (ret) {
    19391876        hx509_set_error_string(context, 0, ret, "out of memory");
     
    19431880    ret = (*ops->generate_private_key)(context, ctx, *private_key);
    19441881    if (ret)
    1945         _hx509_private_key_free(private_key);
     1882        hx509_private_key_free(private_key);
    19461883
    19471884    return ret;
     
    19731910
    19741911const AlgorithmIdentifier *
    1975 hx509_signature_md2(void)
    1976 { return &_hx509_signature_md2_data; }
    1977 
    1978 const AlgorithmIdentifier *
    19791912hx509_signature_ecPublicKey(void)
    19801913{ return &_hx509_signature_ecPublicKey; }
     
    20071940hx509_signature_rsa_with_md5(void)
    20081941{ return &_hx509_signature_rsa_with_md5_data; }
    2009 
    2010 const AlgorithmIdentifier *
    2011 hx509_signature_rsa_with_md2(void)
    2012 { return &_hx509_signature_rsa_with_md2_data; }
    20131942
    20141943const AlgorithmIdentifier *
     
    20481977
    20491978int
    2050 _hx509_private_key_init(hx509_private_key *key,
     1979hx509_private_key_init(hx509_private_key *key,
    20511980                        hx509_private_key_ops *ops,
    20521981                        void *keydata)
     
    20792008
    20802009int
    2081 _hx509_private_key_free(hx509_private_key *key)
     2010hx509_private_key_free(hx509_private_key *key)
    20822011{
    20832012    if (key == NULL || *key == NULL)
     
    20892018        return 0;
    20902019
    2091     if ((*key)->ops && der_heim_oid_cmp((*key)->ops->key_oid, &asn1_oid_id_pkcs1_rsaEncryption) == 0) {
     2020    if ((*key)->ops && der_heim_oid_cmp((*key)->ops->key_oid, ASN1_OID_ID_PKCS1_RSAENCRYPTION) == 0) {
    20922021        if ((*key)->private_key.rsa)
    20932022            RSA_free((*key)->private_key.rsa);
    20942023#ifdef HAVE_OPENSSL
    2095     } else if ((*key)->ops && der_heim_oid_cmp((*key)->ops->key_oid, &asn1_oid_id_ecPublicKey) == 0) {
     2024    } else if ((*key)->ops && der_heim_oid_cmp((*key)->ops->key_oid, ASN1_OID_ID_ECPUBLICKEY) == 0) {
    20962025        if ((*key)->private_key.ecdsa)
    20972026            EC_KEY_free((*key)->private_key.ecdsa);
     
    21052034
    21062035void
    2107 _hx509_private_key_assign_rsa(hx509_private_key key, void *ptr)
     2036hx509_private_key_assign_rsa(hx509_private_key key, void *ptr)
    21082037{
    21092038    if (key->private_key.rsa)
    21102039        RSA_free(key->private_key.rsa);
    21112040    key->private_key.rsa = ptr;
    2112     key->signature_alg = &asn1_oid_id_pkcs1_sha1WithRSAEncryption;
     2041    key->signature_alg = ASN1_OID_ID_PKCS1_SHA1WITHRSAENCRYPTION;
    21132042    key->md = &pkcs1_rsa_sha1_alg;
    21142043}
     
    21472076_hx509_private_key_export(hx509_context context,
    21482077                          const hx509_private_key key,
     2078                          hx509_key_format_t format,
    21492079                          heim_octet_string *data)
    21502080{
     
    21532083        return HX509_UNIMPLEMENTED_OPERATION;
    21542084    }
    2155     return (*key->ops->export)(context, key, data);
     2085    return (*key->ops->export)(context, key, format, data);
    21562086}
    21572087
     
    21762106    char *name;
    21772107    int flags;
    2178 #define ALLOW_WEAK 1
     2108#define ALLOW_WEAK      1
     2109
     2110#define PADDING_NONE    2
     2111#define PADDING_PKCS7   4
     2112#define PADDING_FLAGS   (2|4)
    21792113    const struct hx509cipher *cipher;
    21802114    const EVP_CIPHER *c;
     
    23322266        "rc2-cbc",
    23332267        CIPHER_WEAK,
    2334         &asn1_oid_id_pkcs3_rc2_cbc,
     2268        ASN1_OID_ID_PKCS3_RC2_CBC,
    23352269        NULL,
    23362270        EVP_rc2_cbc,
     
    23412275        "rc2-cbc",
    23422276        CIPHER_WEAK,
    2343         &asn1_oid_id_rsadsi_rc2_cbc,
     2277        ASN1_OID_ID_RSADSI_RC2_CBC,
    23442278        NULL,
    23452279        EVP_rc2_cbc,
     
    23592293        "des-ede3-cbc",
    23602294        0,
    2361         &asn1_oid_id_pkcs3_des_ede3_cbc,
     2295        ASN1_OID_ID_PKCS3_DES_EDE3_CBC,
    23622296        NULL,
    23632297        EVP_des_ede3_cbc,
     
    23682302        "des-ede3-cbc",
    23692303        0,
    2370         &asn1_oid_id_rsadsi_des_ede3_cbc,
     2304        ASN1_OID_ID_RSADSI_DES_EDE3_CBC,
    23712305        hx509_crypto_des_rsdi_ede3_cbc,
    23722306        EVP_des_ede3_cbc,
     
    23772311        "aes-128-cbc",
    23782312        0,
    2379         &asn1_oid_id_aes_128_cbc,
     2313        ASN1_OID_ID_AES_128_CBC,
    23802314        hx509_crypto_aes128_cbc,
    23812315        EVP_aes_128_cbc,
     
    23862320        "aes-192-cbc",
    23872321        0,
    2388         &asn1_oid_id_aes_192_cbc,
     2322        ASN1_OID_ID_AES_192_CBC,
    23892323        NULL,
    23902324        EVP_aes_192_cbc,
     
    23952329        "aes-256-cbc",
    23962330        0,
    2397         &asn1_oid_id_aes_256_cbc,
     2331        ASN1_OID_ID_AES_256_CBC,
    23982332        hx509_crypto_aes256_cbc,
    23992333        EVP_aes_256_cbc,
     
    24622396    }
    24632397
     2398    (*crypto)->flags = PADDING_PKCS7;
    24642399    (*crypto)->cipher = cipher;
    24652400    (*crypto)->c = (*cipher->evp_func)();
     
    25072442}
    25082443
     2444void
     2445hx509_crypto_set_padding(hx509_crypto crypto, int padding_type)
     2446{
     2447    switch (padding_type) {
     2448    case HX509_CRYPTO_PADDING_PKCS7:
     2449        crypto->flags &= ~PADDING_FLAGS;
     2450        crypto->flags |= PADDING_PKCS7;
     2451        break;
     2452    case HX509_CRYPTO_PADDING_NONE:
     2453        crypto->flags &= ~PADDING_FLAGS;
     2454        crypto->flags |= PADDING_NONE;
     2455        break;
     2456    default:
     2457        _hx509_abort("Invalid padding");
     2458    }
     2459}
     2460
    25092461int
    25102462hx509_crypto_set_key_data(hx509_crypto crypto, const void *data, size_t length)
     
    25982550{
    25992551    EVP_CIPHER_CTX evp;
    2600     size_t padsize;
     2552    size_t padsize, bsize;
    26012553    int ret;
    26022554
     
    26252577    }
    26262578
    2627     if (EVP_CIPHER_block_size(crypto->c) == 1) {
    2628         padsize = 0;
    2629     } else {
    2630         int bsize = EVP_CIPHER_block_size(crypto->c);
    2631         padsize = bsize - (length % bsize);
    2632     }
     2579    assert(crypto->flags & PADDING_FLAGS);
     2580
     2581    bsize = EVP_CIPHER_block_size(crypto->c);
     2582    padsize = 0;
     2583
     2584    if (crypto->flags & PADDING_NONE) {
     2585        if (bsize != 1 && (length % bsize) != 0)
     2586            return HX509_CMS_PADDING_ERROR;
     2587    } else if (crypto->flags & PADDING_PKCS7) {
     2588        if (bsize != 1)
     2589            padsize = bsize - (length % bsize);
     2590    }
     2591
    26332592    (*ciphertext)->length = length + padsize;
    26342593    (*ciphertext)->data = malloc(length + padsize);
     
    27202679    EVP_CIPHER_CTX_cleanup(&evp);
    27212680
    2722     if (EVP_CIPHER_block_size(crypto->c) > 1) {
     2681    if ((crypto->flags & PADDING_PKCS7) && EVP_CIPHER_block_size(crypto->c) > 1) {
    27232682        int padsize;
    27242683        unsigned char *p;
     
    28322791                PBE_string2key_func *s2k)
    28332792{
    2834     if (der_heim_oid_cmp(oid, &asn1_oid_id_pbewithSHAAnd40BitRC2_CBC) == 0) {
     2793    if (der_heim_oid_cmp(oid, ASN1_OID_ID_PBEWITHSHAAND40BITRC2_CBC) == 0) {
    28352794        *c = EVP_rc2_40_cbc();
    28362795        *md = EVP_sha1();
    28372796        *s2k = PBE_string2key;
    28382797        return &asn1_oid_private_rc2_40;
    2839     } else if (der_heim_oid_cmp(oid, &asn1_oid_id_pbeWithSHAAnd128BitRC2_CBC) == 0) {
     2798    } else if (der_heim_oid_cmp(oid, ASN1_OID_ID_PBEWITHSHAAND128BITRC2_CBC) == 0) {
    28402799        *c = EVP_rc2_cbc();
    28412800        *md = EVP_sha1();
    28422801        *s2k = PBE_string2key;
    2843         return &asn1_oid_id_pkcs3_rc2_cbc;
     2802        return ASN1_OID_ID_PKCS3_RC2_CBC;
    28442803#if 0
    2845     } else if (der_heim_oid_cmp(oid, &asn1_oid_id_pbeWithSHAAnd40BitRC4) == 0) {
     2804    } else if (der_heim_oid_cmp(oid, ASN1_OID_ID_PBEWITHSHAAND40BITRC4) == 0) {
    28462805        *c = EVP_rc4_40();
    28472806        *md = EVP_sha1();
    28482807        *s2k = PBE_string2key;
    28492808        return NULL;
    2850     } else if (der_heim_oid_cmp(oid, &asn1_oid_id_pbeWithSHAAnd128BitRC4) == 0) {
     2809    } else if (der_heim_oid_cmp(oid, ASN1_OID_ID_PBEWITHSHAAND128BITRC4) == 0) {
    28512810        *c = EVP_rc4();
    28522811        *md = EVP_sha1();
    28532812        *s2k = PBE_string2key;
    2854         return &asn1_oid_id_pkcs3_rc4;
     2813        return ASN1_OID_ID_PKCS3_RC4;
    28552814#endif
    2856     } else if (der_heim_oid_cmp(oid, &asn1_oid_id_pbeWithSHAAnd3_KeyTripleDES_CBC) == 0) {
     2815    } else if (der_heim_oid_cmp(oid, ASN1_OID_ID_PBEWITHSHAAND3_KEYTRIPLEDES_CBC) == 0) {
    28572816        *c = EVP_des_ede3_cbc();
    28582817        *md = EVP_sha1();
    28592818        *s2k = PBE_string2key;
    2860         return &asn1_oid_id_pkcs3_des_ede3_cbc;
     2819        return ASN1_OID_ID_PKCS3_DES_EDE3_CBC;
    28612820    }
    28622821
     
    30352994_hx509_match_keys(hx509_cert c, hx509_private_key key)
    30362995{
    3037     if (der_heim_oid_cmp(key->ops->key_oid, &asn1_oid_id_pkcs1_rsaEncryption) == 0)
     2996    if (der_heim_oid_cmp(key->ops->key_oid, ASN1_OID_ID_PKCS1_RSAENCRYPTION) == 0)
    30382997        return match_keys_rsa(c, key);
    3039     if (der_heim_oid_cmp(key->ops->key_oid, &asn1_oid_id_ecPublicKey) == 0)
     2998    if (der_heim_oid_cmp(key->ops->key_oid, ASN1_OID_ID_ECPUBLICKEY) == 0)
    30402999        return match_keys_ec(c, key);
    30413000    return 0;
  • trunk/server/source4/heimdal/lib/hx509/error.c

    r414 r745  
    6868hx509_clear_error_string(hx509_context context)
    6969{
    70     free_error_string(context->error);
    71     context->error = NULL;
     70    if (context) {
     71        free_error_string(context->error);
     72        context->error = NULL;
     73    }
    7274}
    7375
     
    9193{
    9294    hx509_error msg;
     95
     96    if (context == NULL)
     97        return;
    9398
    9499    msg = calloc(1, sizeof(*msg));
  • trunk/server/source4/heimdal/lib/hx509/file.c

    r414 r745  
    6767
    6868static void
    69 header(FILE *f, const char *type, const char *str)
     69print_pem_stamp(FILE *f, const char *type, const char *str)
    7070{
    7171    fprintf(f, "-----%s %s-----\n", type, str);
     
    8383#define ENCODE_LINE_LENGTH      54
    8484
    85     header(f, "BEGIN", type);
     85    print_pem_stamp(f, "BEGIN", type);
    8686
    8787    while (headers) {
     
    111111    }
    112112
    113     header(f, "END", type);
     113    print_pem_stamp(f, "END", type);
    114114
    115115    return 0;
  • trunk/server/source4/heimdal/lib/hx509/hx509.h

    r414 r745  
    4949typedef struct hx509_name_data *hx509_name;
    5050typedef struct hx509_private_key *hx509_private_key;
     51typedef struct hx509_private_key_ops hx509_private_key_ops;
    5152typedef struct hx509_validate_ctx_data *hx509_validate_ctx;
    5253typedef struct hx509_verify_ctx_data *hx509_verify_ctx;
     
    7172    HX509_VALIDATE_F_VERBOSE = 2
    7273};
     74
     75enum {
     76    HX509_CRYPTO_PADDING_PKCS7 = 0,
     77    HX509_CRYPTO_PADDING_NONE = 1
     78};
     79
     80enum {
     81    HX509_KEY_FORMAT_GUESS = 0,
     82    HX509_KEY_FORMAT_DER = 1,
     83    HX509_KEY_FORMAT_WIN_BACKUPKEY = 2
     84};
     85typedef uint32_t hx509_key_format_t;
    7386
    7487struct hx509_cert_attribute_data {
     
    131144#define HX509_CMS_EV_NO_KU_CHECK                        0x01
    132145#define HX509_CMS_EV_ALLOW_WEAK                         0x02
     146#define HX509_CMS_EV_ID_NAME                            0x04
    133147
    134148/* flags to hx509_cms_verify_signed */
     
    158172#define HX509_CMS_SIGNATURE_ID_NAME                     0x02
    159173#define HX509_CMS_SIGNATURE_NO_SIGNER                   0x04
     174#define HX509_CMS_SIGNATURE_LEAF_ONLY                   0x08
     175#define HX509_CMS_SIGNATURE_NO_CERTS                    0x10
    160176
    161177/* hx509_verify_hostname nametype */
  • trunk/server/source4/heimdal/lib/hx509/hx509_err.et

    r414 r745  
    6767error_code RSA_PRIVATE_DECRYPT, "RSA private decryption failed"
    6868error_code ALGORITHM_BEST_BEFORE, "Algorithm has passed its best before date"
     69error_code KEY_FORMAT_UNSUPPORTED, "Key format is unsupported"
    6970
    7071# revoke related errors
  • trunk/server/source4/heimdal/lib/hx509/hx_locl.h

    r414 r745  
    4040#include <ctype.h>
    4141#include <errno.h>
     42#ifdef HAVE_STRINGS_H
    4243#include <strings.h>
     44#endif
    4345#include <assert.h>
    4446#include <stdarg.h>
     
    4648#include <limits.h>
    4749
     50#include <roken.h>
     51
    4852#include <getarg.h>
    4953#include <base64.h>
    5054#include <hex.h>
    51 #include <roken.h>
    5255#include <com_err.h>
    5356#include <parse_units.h>
     
    8083typedef void (*_hx509_cert_release_func)(struct hx509_cert_data *, void *);
    8184
    82 typedef struct hx509_private_key_ops hx509_private_key_ops;
    8385
    8486#include "sel.h"
  • trunk/server/source4/heimdal/lib/hx509/keyset.c

    r414 r745  
    33 * (Royal Institute of Technology, Stockholm, Sweden).
    44 * All rights reserved.
     5 *
     6 * Portions Copyright (c) 2009 Apple Inc. All rights reserved.
    57 *
    68 * Redistribution and use in source and binary forms, with or without
     
    199201
    200202hx509_certs
    201 _hx509_certs_ref(hx509_certs certs)
     203hx509_certs_ref(hx509_certs certs)
    202204{
    203205    if (certs == NULL)
     
    324326 * @param func function to call for each certificate. The function
    325327 * should return non-zero to abort the iteration, that value is passed
    326  * back to te caller of hx509_certs_iter().
     328 * back to the caller of hx509_certs_iter_f().
    327329 * @param ctx context variable that will passed to the function.
    328330 *
     
    333335
    334336int
    335 hx509_certs_iter(hx509_context context,
    336                  hx509_certs certs,
    337                  int (*func)(hx509_context, void *, hx509_cert),
    338                  void *ctx)
     337hx509_certs_iter_f(hx509_context context,
     338                   hx509_certs certs,
     339                   int (*func)(hx509_context, void *, hx509_cert),
     340                   void *ctx)
    339341{
    340342    hx509_cursor cursor;
     
    365367}
    366368
    367 
    368 /**
    369  * Function to use to hx509_certs_iter() as a function argument, the
    370  * ctx variable to hx509_certs_iter() should be a FILE file descriptor.
    371  *
    372  * @param context a hx509 context.
    373  * @param ctx used by hx509_certs_iter().
     369/**
     370 * Iterate over all certificates in a keystore and call an function
     371 * for each fo them.
     372 *
     373 * @param context a hx509 context.
     374 * @param certs certificate store to iterate over.
     375 * @param func function to call for each certificate. The function
     376 * should return non-zero to abort the iteration, that value is passed
     377 * back to the caller of hx509_certs_iter().
     378 *
     379 * @return Returns an hx509 error code.
     380 *
     381 * @ingroup hx509_keyset
     382 */
     383
     384#ifdef __BLOCKS__
     385
     386static int
     387certs_iter(hx509_context context, void *ctx, hx509_cert cert)
     388{
     389    int (^func)(hx509_cert) = ctx;
     390    return func(cert);
     391}
     392
     393int
     394hx509_certs_iter(hx509_context context,
     395                 hx509_certs certs,
     396                 int (^func)(hx509_cert))
     397{
     398    return hx509_certs_iter_f(context, certs, certs_iter, func);
     399}
     400#endif
     401
     402
     403/**
     404 * Function to use to hx509_certs_iter_f() as a function argument, the
     405 * ctx variable to hx509_certs_iter_f() should be a FILE file descriptor.
     406 *
     407 * @param context a hx509 context.
     408 * @param ctx used by hx509_certs_iter_f().
    374409 * @param c a certificate
    375410 *
     
    588623    if (from == NULL)
    589624        return 0;
    590     return hx509_certs_iter(context, from, certs_merge_func, to);
     625    return hx509_certs_iter_f(context, from, certs_merge_func, to);
    591626}
    592627
     
    747782    int i;
    748783    for (i = 0; keys[i]; i++)
    749         _hx509_private_key_free(&keys[i]);
     784        hx509_private_key_free(&keys[i]);
    750785    free(keys);
    751786}
  • trunk/server/source4/heimdal/lib/hx509/ks_dir.c

    r414 r745  
    9494}
    9595
    96 
    97 
    9896static int
    9997dir_iter_start(hx509_context context,
     
    116114        return errno;
    117115    }
    118     rk_cloexec(dirfd(d->dir));
     116    rk_cloexec_dir(d->dir);
    119117    d->certs = NULL;
    120118    d->iter = NULL;
  • trunk/server/source4/heimdal/lib/hx509/ks_file.c

    r414 r745  
    368368{
    369369    char *p, *pnext;
    370     struct ks_file *f = NULL;
     370    struct ks_file *ksf = NULL;
    371371    hx509_private_key *keys = NULL;
    372372    int ret;
     
    381381        lock = _hx509_empty_lock;
    382382
    383     f = calloc(1, sizeof(*f));
    384     if (f == NULL) {
     383    ksf = calloc(1, sizeof(*ksf));
     384    if (ksf == NULL) {
    385385        hx509_clear_error_string(context);
    386386        return ENOMEM;
    387387    }
    388     f->format = format;
    389 
    390     f->fn = strdup(residue);
    391     if (f->fn == NULL) {
     388    ksf->format = format;
     389
     390    ksf->fn = strdup(residue);
     391    if (ksf->fn == NULL) {
    392392        hx509_clear_error_string(context);
    393393        ret = ENOMEM;
     
    402402    if (flags & HX509_CERTS_CREATE) {
    403403        ret = hx509_certs_init(context, "MEMORY:ks-file-create",
    404                                0, lock, &f->certs);
     404                               0, lock, &ksf->certs);
    405405        if (ret)
    406406            goto out;
    407         *data = f;
     407        *data = ksf;
    408408        return 0;
    409409    }
     
    413413        goto out;
    414414
    415     for (p = f->fn; p != NULL; p = pnext) {
     415    for (p = ksf->fn; p != NULL; p = pnext) {
    416416        FILE *f;
    417417
     
    462462    }
    463463
    464     ret = _hx509_collector_collect_certs(context, pem_ctx.c, &f->certs);
     464    ret = _hx509_collector_collect_certs(context, pem_ctx.c, &ksf->certs);
    465465    if (ret)
    466466        goto out;
     
    471471
    472472        for (i = 0; keys[i]; i++)
    473             _hx509_certs_keys_add(context, f->certs, keys[i]);
     473            _hx509_certs_keys_add(context, ksf->certs, keys[i]);
    474474        _hx509_certs_keys_free(context, keys);
    475475    }
     
    477477out:
    478478    if (ret == 0)
    479         *data = f;
     479        *data = ksf;
    480480    else {
    481         if (f->fn)
    482             free(f->fn);
    483         free(f);
     481        if (ksf->fn)
     482            free(ksf->fn);
     483        free(ksf);
    484484    }
    485485    if (pem_ctx.c)
     
    508508file_free(hx509_certs certs, void *data)
    509509{
    510     struct ks_file *f = data;
    511     hx509_certs_free(&f->certs);
    512     free(f->fn);
    513     free(f);
     510    struct ks_file *ksf = data;
     511    hx509_certs_free(&ksf->certs);
     512    free(ksf->fn);
     513    free(ksf);
    514514    return 0;
    515515}
     
    542542        if (_hx509_cert_private_key_exportable(c)) {
    543543            hx509_private_key key = _hx509_cert_private_key(c);
    544             ret = _hx509_private_key_export(context, key, &data);
     544            ret = _hx509_private_key_export(context, key,
     545                                            HX509_KEY_FORMAT_DER, &data);
    545546            if (ret)
    546547                break;
     
    559560           hx509_certs certs, void *data, int flags, hx509_lock lock)
    560561{
    561     struct ks_file *f = data;
     562    struct ks_file *ksf = data;
    562563    struct store_ctx sc;
    563564    int ret;
    564565
    565     sc.f = fopen(f->fn, "w");
     566    sc.f = fopen(ksf->fn, "w");
    566567    if (sc.f == NULL) {
    567568        hx509_set_error_string(context, 0, ENOENT,
     
    570571    }
    571572    rk_cloexec_file(sc.f);
    572     sc.format = f->format;
    573 
    574     ret = hx509_certs_iter(context, f->certs, store_func, &sc);
     573    sc.format = ksf->format;
     574
     575    ret = hx509_certs_iter_f(context, ksf->certs, store_func, &sc);
    575576    fclose(sc.f);
    576577    return ret;
     
    580581file_add(hx509_context context, hx509_certs certs, void *data, hx509_cert c)
    581582{
    582     struct ks_file *f = data;
    583     return hx509_certs_add(context, f->certs, c);
     583    struct ks_file *ksf = data;
     584    return hx509_certs_add(context, ksf->certs, c);
    584585}
    585586
     
    588589                hx509_certs certs, void *data, void **cursor)
    589590{
    590     struct ks_file *f = data;
    591     return hx509_certs_start_seq(context, f->certs, cursor);
     591    struct ks_file *ksf = data;
     592    return hx509_certs_start_seq(context, ksf->certs, cursor);
    592593}
    593594
     
    596597          hx509_certs certs, void *data, void *iter, hx509_cert *cert)
    597598{
    598     struct ks_file *f = data;
    599     return hx509_certs_next_cert(context, f->certs, iter, cert);
     599    struct ks_file *ksf = data;
     600    return hx509_certs_next_cert(context, ksf->certs, iter, cert);
    600601}
    601602
     
    606607              void *cursor)
    607608{
    608     struct ks_file *f = data;
    609     return hx509_certs_end_seq(context, f->certs, cursor);
     609    struct ks_file *ksf = data;
     610    return hx509_certs_end_seq(context, ksf->certs, cursor);
    610611}
    611612
     
    616617             hx509_private_key **keys)
    617618{
    618     struct ks_file *f = data;
    619     return _hx509_certs_keys_get(context, f->certs, keys);
     619    struct ks_file *ksf = data;
     620    return _hx509_certs_keys_get(context, ksf->certs, keys);
    620621}
    621622
     
    626627             hx509_private_key key)
    627628{
    628     struct ks_file *f = data;
    629     return _hx509_certs_keys_add(context, f->certs, key);
     629    struct ks_file *ksf = data;
     630    return _hx509_certs_keys_add(context, ksf->certs, key);
    630631}
    631632
  • trunk/server/source4/heimdal/lib/hx509/ks_keychain.c

    r414 r745  
    4444                              int, const CSSM_ACCESS_CREDENTIALS **);
    4545#define kSecCredentialTypeDefault 0
     46#define CSSM_SIZE uint32_t
    4647#endif
    4748
     
    259260    int ret;
    260261
    261     ret = _hx509_private_key_init(&key, NULL, NULL);
     262    ret = hx509_private_key_init(&key, NULL, NULL);
    262263    if (ret)
    263264        return ret;
     
    302303        _hx509_abort("RSA_set_app_data");
    303304
    304     _hx509_private_key_assign_rsa(key, rsa);
     305    hx509_private_key_assign_rsa(key, rsa);
    305306    _hx509_cert_assign_key(cert, key);
    306307
  • trunk/server/source4/heimdal/lib/hx509/ks_mem.c

    r414 r745  
    7979    free(mem->certs.val);
    8080    for (i = 0; mem->keys && mem->keys[i]; i++)
    81         _hx509_private_key_free(&mem->keys[i]);
     81        hx509_private_key_free(&mem->keys[i]);
    8282    free(mem->keys);
    8383    free(mem->name);
     
    168168        if ((*keys)[i] == NULL) {
    169169            while (--i >= 0)
    170                 _hx509_private_key_free(&(*keys)[i]);
     170                hx509_private_key_free(&(*keys)[i]);
    171171            hx509_set_error_string(context, 0, ENOMEM, "out of memory");
    172172            return ENOMEM;
  • trunk/server/source4/heimdal/lib/hx509/ks_p11.c

    r414 r745  
    614614    localKeyId.length = query[0].ulValueLen;
    615615
    616     ret = _hx509_private_key_init(&key, NULL, NULL);
     616    ret = hx509_private_key_init(&key, NULL, NULL);
    617617    if (ret)
    618618        return ret;
     
    649649        _hx509_abort("RSA_set_app_data");
    650650
    651     _hx509_private_key_assign_rsa(key, rsa);
     651    hx509_private_key_assign_rsa(key, rsa);
    652652
    653653    ret = _hx509_collector_private_key_add(context,
     
    659659
    660660    if (ret) {
    661         _hx509_private_key_free(&key);
     661        hx509_private_key_free(&key);
    662662        return ret;
    663663    }
     
    836836    }
    837837
    838     getFuncs = dlsym(p->dl_handle, "C_GetFunctionList");
     838    getFuncs = (CK_C_GetFunctionList) dlsym(p->dl_handle, "C_GetFunctionList");
    839839    if (getFuncs == NULL) {
    840840        ret = HX509_PKCS11_LOAD;
     
    11401140                MECHNAME(CKM_SHA_1, "sha1");
    11411141                MECHNAME(CKM_MD5, "md5");
    1142                 MECHNAME(CKM_MD2, "md2");
    11431142                MECHNAME(CKM_RIPEMD160, "ripemd-160");
    11441143                MECHNAME(CKM_DES_ECB, "des-ecb");
  • trunk/server/source4/heimdal/lib/hx509/ks_p12.c

    r414 r745  
    536536        ret = _hx509_private_key_export(context,
    537537                                        _hx509_cert_private_key(c),
     538                                        HX509_KEY_FORMAT_DER,
    538539                                        &pki.privateKey);
    539540        if (ret) {
     
    572573    memset(&pfx, 0, sizeof(pfx));
    573574
    574     ret = hx509_certs_iter(context, p12->certs, store_func, &as);
     575    ret = hx509_certs_iter_f(context, p12->certs, store_func, &as);
    575576    if (ret)
    576577        goto out;
  • trunk/server/source4/heimdal/lib/hx509/lock.c

    r414 r745  
    215215hx509_lock_free(hx509_lock lock)
    216216{
    217     hx509_certs_free(&lock->certs);
    218     hx509_lock_reset_passwords(lock);
    219     memset(lock, 0, sizeof(*lock));
    220     free(lock);
     217    if (lock) {
     218        hx509_certs_free(&lock->certs);
     219        hx509_lock_reset_passwords(lock);
     220        memset(lock, 0, sizeof(*lock));
     221        free(lock);
     222    }
    221223}
    222224
  • trunk/server/source4/heimdal/lib/hx509/name.c

    r414 r745  
    3434#include "hx_locl.h"
    3535#include <wind.h>
     36#include "char_map.h"
    3637
    3738/**
     
    4445 * types are defined by OID and have long and short description. For
    4546 * example id-at-commonName (2.5.4.3) have the long name CommonName
    46  * and short name CN. The string itself can be of serveral encoding,
     47 * and short name CN. The string itself can be of several encoding,
    4748 * UTF8, UTF16, Teltex string, etc. The type limit what encoding
    4849 * should be used.
     
    8081
    8182static char *
    82 quote_string(const char *f, size_t len, size_t *rlen)
     83quote_string(const char *f, size_t len, int flags, size_t *rlen)
    8384{
    8485    size_t i, j, tolen;
    85     const char *from = f;
    86     char *to;
     86    const unsigned char *from = (const unsigned char *)f;
     87    unsigned char *to;
    8788
    8889    tolen = len * 3 + 1;
     
    9293
    9394    for (i = 0, j = 0; i < len; i++) {
    94         if (from[i] == ' ' && i + 1 < len)
    95             to[j++] = from[i];
    96         else if (from[i] == ',' || from[i] == '=' || from[i] == '+' ||
    97                  from[i] == '<' || from[i] == '>' || from[i] == '#' ||
    98                  from[i] == ';' || from[i] == ' ')
    99         {
     95        unsigned char map = char_map[from[i]] & flags;
     96        if (i == 0 && (map & Q_RFC2253_QUOTE_FIRST)) {
    10097            to[j++] = '\\';
    10198            to[j++] = from[i];
    102         } else if (((unsigned char)from[i]) >= 32 && ((unsigned char)from[i]) <= 127) {
     99        } else if ((i + 1) == len && (map & Q_RFC2253_QUOTE_LAST)) {
     100
     101            to[j++] = '\\';
    103102            to[j++] = from[i];
    104         } else {
    105             int l = snprintf(&to[j], tolen - j - 1,
     103        } else if (map & Q_RFC2253_QUOTE) {
     104            to[j++] = '\\';
     105            to[j++] = from[i];
     106        } else if (map & Q_RFC2253_HEX) {
     107            int l = snprintf((char *)&to[j], tolen - j - 1,
    106108                             "#%02x", (unsigned char)from[i]);
    107109            j += l;
     110        } else {
     111            to[j++] = from[i];
    108112        }
    109113    }
     
    111115    assert(j < tolen);
    112116    *rlen = j;
    113     return to;
     117    return (char *)to;
    114118}
    115119
     
    122126
    123127    if (quote)
    124         qs = quote_string(ss, len, &len);
     128        qs = quote_string(ss, len, Q_RFC2253, &len);
    125129    else
    126130        qs = rk_UNCONST(ss);
     
    204208
    205209    for (i = n->u.rdnSequence.len - 1 ; i >= 0 ; i--) {
    206         int len;
     210        size_t len;
    207211
    208212        for (j = 0; j < n->u.rdnSequence.val[i].len; j++) {
     
    215219            switch(ds->element) {
    216220            case choice_DirectoryString_ia5String:
    217                 ss = ds->u.ia5String;
     221                ss = ds->u.ia5String.data;
     222                len = ds->u.ia5String.length;
    218223                break;
    219224            case choice_DirectoryString_printableString:
    220                 ss = ds->u.printableString;
     225                ss = ds->u.printableString.data;
     226                len = ds->u.printableString.length;
    221227                break;
    222228            case choice_DirectoryString_utf8String:
    223229                ss = ds->u.utf8String;
     230                len = strlen(ss);
    224231                break;
    225232            case choice_DirectoryString_bmpString: {
     
    241248                }
    242249                ss[k] = '\0';
     250                len = k;
    243251                break;
    244252            }
    245253            case choice_DirectoryString_teletexString:
    246                 ss = malloc(ds->u.teletexString.length + 1);
    247                 if (ss == NULL)
    248                     _hx509_abort("allocation failure"); /* XXX */
    249                 memcpy(ss, ds->u.teletexString.data, ds->u.teletexString.length);
    250                 ss[ds->u.teletexString.length] = '\0';
     254                ss = ds->u.teletexString;
     255                len = strlen(ss);
    251256                break;
    252257            case choice_DirectoryString_universalString: {
     
    268273                }
    269274                ss[k] = '\0';
     275                len = k;
    270276                break;
    271277            }
     
    277283            free(oidname);
    278284            append_string(str, &total_len, "=", 1, 0);
    279             len = strlen(ss);
    280285            append_string(str, &total_len, ss, len, 1);
    281             if (ds->element == choice_DirectoryString_universalString ||
    282                 ds->element == choice_DirectoryString_bmpString ||
    283                 ds->element == choice_DirectoryString_teletexString)
     286            if (ds->element == choice_DirectoryString_bmpString ||
     287                ds->element == choice_DirectoryString_universalString)
    284288            {
    285289                free(ss);
     
    325329dsstringprep(const DirectoryString *ds, uint32_t **rname, size_t *rlen)
    326330{
    327     wind_profile_flags flags = 0;
     331    wind_profile_flags flags;
    328332    size_t i, len;
    329333    int ret;
     
    335339    switch(ds->element) {
    336340    case choice_DirectoryString_ia5String:
    337         COPYCHARARRAY(ds, ia5String, len, name);
     341        flags = WIND_PROFILE_LDAP;
     342        COPYVOIDARRAY(ds, ia5String, len, name);
    338343        break;
    339344    case choice_DirectoryString_printableString:
    340         flags = WIND_PROFILE_LDAP_CASE_EXACT_ATTRIBUTE;
    341         COPYCHARARRAY(ds, printableString, len, name);
     345        flags = WIND_PROFILE_LDAP;
     346        flags |= WIND_PROFILE_LDAP_CASE_EXACT_ATTRIBUTE;
     347        COPYVOIDARRAY(ds, printableString, len, name);
    342348        break;
    343349    case choice_DirectoryString_teletexString:
    344         COPYVOIDARRAY(ds, teletexString, len, name);
     350        flags = WIND_PROFILE_LDAP_CASE;
     351        COPYCHARARRAY(ds, teletexString, len, name);
    345352        break;
    346353    case choice_DirectoryString_bmpString:
     354        flags = WIND_PROFILE_LDAP;
    347355        COPYVALARRAY(ds, bmpString, len, name);
    348356        break;
    349357    case choice_DirectoryString_universalString:
     358        flags = WIND_PROFILE_LDAP;
    350359        COPYVALARRAY(ds, universalString, len, name);
    351360        break;
    352361    case choice_DirectoryString_utf8String:
     362        flags = WIND_PROFILE_LDAP;
    353363        ret = wind_utf8ucs4_length(ds->u.utf8String, &len);
    354364        if (ret)
     
    373383        *rname = malloc(*rlen * sizeof((*rname)[0]));
    374384
    375         ret = wind_stringprep(name, len, *rname, rlen,
    376                               WIND_PROFILE_LDAP|flags);
     385        ret = wind_stringprep(name, len, *rname, rlen, flags);
    377386        if (ret == WIND_ERR_OVERRUN) {
    378387            free(*rname);
     
    400409{
    401410    uint32_t *ds1lp, *ds2lp;
    402     size_t ds1len, ds2len;
     411    size_t ds1len, ds2len, i;
    403412    int ret;
    404413
     
    414423    if (ds1len != ds2len)
    415424        *diff = ds1len - ds2len;
    416     else
    417         *diff = memcmp(ds1lp, ds2lp, ds1len * sizeof(ds1lp[0]));
    418 
     425    else {
     426        for (i = 0; i < ds1len; i++) {
     427            *diff = ds1lp[i] - ds2lp[i];
     428            if (*diff)
     429                break;
     430        }
     431    }
    419432    free(ds1lp);
    420433    free(ds2lp);
     
    927940    switch (name->element) {
    928941    case choice_GeneralName_otherName: {
    929         char *str;
    930         hx509_oid_sprint(&name->u.otherName.type_id, &str);
    931         if (str == NULL)
     942        char *oid;
     943        hx509_oid_sprint(&name->u.otherName.type_id, &oid);
     944        if (oid == NULL)
    932945            return ENOMEM;
    933         strpool = rk_strpoolprintf(strpool, "otherName: %s", str);
    934         free(str);
     946        strpool = rk_strpoolprintf(strpool, "otherName: %s", oid);
     947        free(oid);
    935948        break;
    936949    }
    937950    case choice_GeneralName_rfc822Name:
    938         strpool = rk_strpoolprintf(strpool, "rfc822Name: %s\n",
    939                                    name->u.rfc822Name);
     951        strpool = rk_strpoolprintf(strpool, "rfc822Name: %.*s\n",
     952                                   (int)name->u.rfc822Name.length,
     953                                   (char *)name->u.rfc822Name.data);
    940954        break;
    941955    case choice_GeneralName_dNSName:
    942         strpool = rk_strpoolprintf(strpool, "dNSName: %s\n",
    943                                    name->u.dNSName);
     956        strpool = rk_strpoolprintf(strpool, "dNSName: %.*s\n",
     957                                   (int)name->u.dNSName.length,
     958                                   (char *)name->u.dNSName.data);
    944959        break;
    945960    case choice_GeneralName_directoryName: {
     
    958973    }
    959974    case choice_GeneralName_uniformResourceIdentifier:
    960         strpool = rk_strpoolprintf(strpool, "URI: %s",
    961                                    name->u.uniformResourceIdentifier);
     975        strpool = rk_strpoolprintf(strpool, "URI: %.*s",
     976                                   (int)name->u.uniformResourceIdentifier.length,
     977                                   (char *)name->u.uniformResourceIdentifier.data);
    962978        break;
    963979    case choice_GeneralName_iPAddress: {
     
    9871003    }
    9881004    case choice_GeneralName_registeredID: {
    989         char *str;
    990         hx509_oid_sprint(&name->u.registeredID, &str);
    991         if (str == NULL)
     1005        char *oid;
     1006        hx509_oid_sprint(&name->u.registeredID, &oid);
     1007        if (oid == NULL)
    9921008            return ENOMEM;
    993         strpool = rk_strpoolprintf(strpool, "registeredID: %s", str);
    994         free(str);
     1009        strpool = rk_strpoolprintf(strpool, "registeredID: %s", oid);
     1010        free(oid);
    9951011        break;
    9961012    }
  • trunk/server/source4/heimdal/lib/hx509/peer.c

    r414 r745  
    33 * (Royal Institute of Technology, Stockholm, Sweden).
    44 * All rights reserved.
     5 *
     6 * Portions Copyright (c) 2009 Apple Inc. All rights reserved.
    57 *
    68 * Redistribution and use in source and binary forms, with or without
     
    145147        return ENOMEM;
    146148    }
     149    peer->val = ptr;
    147150    ret = copy_AlgorithmIdentifier(val, &peer->val[peer->len]);
    148151    if (ret == 0)
  • trunk/server/source4/heimdal/lib/hx509/print.c

    r414 r745  
    10181018    if (status.selfsigned) {
    10191019        ret = _hx509_verify_signature_bitstring(context,
    1020                                                 c,
     1020                                                cert,
    10211021                                                &c->signatureAlgorithm,
    10221022                                                &c->tbsCertificate._save,
  • trunk/server/source4/heimdal/lib/hx509/req.c

    r414 r745  
    4747
    4848int
    49 _hx509_request_init(hx509_context context, hx509_request *req)
     49hx509_request_init(hx509_context context, hx509_request *req)
    5050{
    5151    *req = calloc(1, sizeof(**req));
     
    5757
    5858void
    59 _hx509_request_free(hx509_request *req)
     59hx509_request_free(hx509_request *req)
    6060{
    6161    if ((*req)->name)
     
    7070
    7171int
    72 _hx509_request_set_name(hx509_context context,
     72hx509_request_set_name(hx509_context context,
    7373                        hx509_request req,
    7474                        hx509_name name)
     
    8585
    8686int
    87 _hx509_request_get_name(hx509_context context,
     87hx509_request_get_name(hx509_context context,
    8888                        hx509_request req,
    8989                        hx509_name *name)
     
    9797
    9898int
    99 _hx509_request_set_SubjectPublicKeyInfo(hx509_context context,
     99hx509_request_set_SubjectPublicKeyInfo(hx509_context context,
    100100                                        hx509_request req,
    101101                                        const SubjectPublicKeyInfo *key)
     
    106106
    107107int
    108 _hx509_request_get_SubjectPublicKeyInfo(hx509_context context,
     108hx509_request_get_SubjectPublicKeyInfo(hx509_context context,
    109109                                        hx509_request req,
    110110                                        SubjectPublicKeyInfo *key)
     
    144144    memset(&name, 0, sizeof(name));
    145145    name.element = choice_GeneralName_dNSName;
    146     name.u.dNSName = rk_UNCONST(hostname);
     146    name.u.dNSName.data = rk_UNCONST(hostname);
     147    name.u.dNSName.length = strlen(hostname);
    147148
    148149    return add_GeneralNames(&req->san, &name);
     
    158159    memset(&name, 0, sizeof(name));
    159160    name.element = choice_GeneralName_rfc822Name;
    160     name.u.dNSName = rk_UNCONST(email);
     161    name.u.dNSName.data = rk_UNCONST(email);
     162    name.u.dNSName.length = strlen(email);
    161163
    162164    return add_GeneralNames(&req->san, &name);
     
    270272    }
    271273
    272     ret = _hx509_request_init(context, req);
     274    ret = hx509_request_init(context, req);
    273275    if (ret) {
    274276        free_CertificationRequest(&r);
     
    278280    rinfo = &r.certificationRequestInfo;
    279281
    280     ret = _hx509_request_set_SubjectPublicKeyInfo(context, *req,
     282    ret = hx509_request_set_SubjectPublicKeyInfo(context, *req,
    281283                                                  &rinfo->subjectPKInfo);
    282284    if (ret) {
    283285        free_CertificationRequest(&r);
    284         _hx509_request_free(req);
     286        hx509_request_free(req);
    285287        return ret;
    286288    }
     
    289291    if (ret) {
    290292        free_CertificationRequest(&r);
    291         _hx509_request_free(req);
    292         return ret;
    293     }
    294     ret = _hx509_request_set_name(context, *req, subject);
     293        hx509_request_free(req);
     294        return ret;
     295    }
     296    ret = hx509_request_set_name(context, *req, subject);
    295297    hx509_name_free(&subject);
    296298    free_CertificationRequest(&r);
    297299    if (ret) {
    298         _hx509_request_free(req);
     300        hx509_request_free(req);
    299301        return ret;
    300302    }
  • trunk/server/source4/heimdal/lib/hx509/revoke.c

    r414 r745  
    224224
    225225        ret = _hx509_verify_signature_bitstring(context,
    226                                                 p,
     226                                                parent,
    227227                                                &s->signatureAlgorithm,
    228228                                                &s->tbsCertificate._save,
     
    241241
    242242    ret = _hx509_verify_signature_bitstring(context,
    243                                             _hx509_get_cert(signer),
     243                                            signer,
    244244                                            &ocsp->ocsp.signatureAlgorithm,
    245245                                            &ocsp->ocsp.tbsResponseData._save,
     
    507507
    508508    ret = _hx509_verify_signature_bitstring(context,
    509                                             _hx509_get_cert(signer),
     509                                            signer,
    510510                                            &crl->signatureAlgorithm,
    511511                                            &crl->tbsCertList._save,
     
    990990    ctx.parent = NULL;
    991991
    992     ret = hx509_certs_iter(context, reqcerts, add_to_req, &ctx);
     992    ret = hx509_certs_iter_f(context, reqcerts, add_to_req, &ctx);
    993993    hx509_cert_free(ctx.parent);
    994994    if (ret)
     
    11541154    fprintf(out, "appended certs:\n");
    11551155    if (ocsp.certs)
    1156         ret = hx509_certs_iter(context, ocsp.certs, hx509_ci_print_names, out);
     1156        ret = hx509_certs_iter_f(context, ocsp.certs, hx509_ci_print_names, out);
    11571157
    11581158    free_ocsp(&ocsp);
     
    14871487    c.tbsCertList.crlExtensions = NULL;
    14881488
    1489     ret = hx509_certs_iter(context, crl->revoked, add_revoked, &c.tbsCertList);
     1489    ret = hx509_certs_iter_f(context, crl->revoked, add_revoked, &c.tbsCertList);
    14901490    if (ret)
    14911491        goto out;
  • trunk/server/source4/heimdal/lib/hx509/sel-gram.c

    r414 r745  
    1 /* A Bison parser, made by GNU Bison 2.3.  */
     1
     2/* A Bison parser, made by GNU Bison 2.4.1.  */
    23
    34/* Skeleton implementation for Bison's Yacc-like parsers in C
    4 
    5    Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006
     5   
     6      Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006
    67   Free Software Foundation, Inc.
    7 
    8    This program is free software; you can redistribute it and/or modify
     8   
     9   This program is free software: you can redistribute it and/or modify
    910   it under the terms of the GNU General Public License as published by
    10    the Free Software Foundation; either version 2, or (at your option)
    11    any later version.
    12 
     11   the Free Software Foundation, either version 3 of the License, or
     12   (at your option) any later version.
     13   
    1314   This program is distributed in the hope that it will be useful,
    1415   but WITHOUT ANY WARRANTY; without even the implied warranty of
    1516   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1617   GNU General Public License for more details.
    17 
     18   
    1819   You should have received a copy of the GNU General Public License
    19    along with this program; if not, write to the Free Software
    20    Foundation, Inc., 51 Franklin Street, Fifth Floor,
    21    Boston, MA 02110-1301, USA.  */
     20   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
    2221
    2322/* As a special exception, you may create a larger work that contains
     
    3029   Bison output files to be licensed under the GNU General Public
    3130   License without this special exception.
    32 
     31   
    3332   This special exception was added by the Free Software Foundation in
    3433   version 2.2 of Bison.  */
     
    4847
    4948/* Bison version.  */
    50 #define YYBISON_VERSION "2.3"
     49#define YYBISON_VERSION "2.4.1"
    5150
    5251/* Skeleton name.  */
     
    5655#define YYPURE 0
    5756
     57/* Push parsers.  */
     58#define YYPUSH 0
     59
     60/* Pull parsers.  */
     61#define YYPULL 1
     62
    5863/* Using locations.  */
    5964#define YYLSP_NEEDED 0
    6065
     66
     67
     68/* Copy the first part of user declarations.  */
     69
     70/* Line 189 of yacc.c  */
     71#line 34 "sel-gram.c"
     72
     73#ifdef HAVE_CONFIG_H
     74#include <config.h>
     75#endif
     76#include <stdio.h>
     77#include <stdlib.h>
     78#include <hx_locl.h>
     79
     80
     81
     82
     83/* Line 189 of yacc.c  */
     84#line 85 "sel-gram.c"
     85
     86/* Enabling traces.  */
     87#ifndef YYDEBUG
     88# define YYDEBUG 0
     89#endif
     90
     91/* Enabling verbose error messages.  */
     92#ifdef YYERROR_VERBOSE
     93# undef YYERROR_VERBOSE
     94# define YYERROR_VERBOSE 1
     95#else
     96# define YYERROR_VERBOSE 0
     97#endif
     98
     99/* Enabling the token table.  */
     100#ifndef YYTOKEN_TABLE
     101# define YYTOKEN_TABLE 0
     102#endif
    61103
    62104
     
    92134
    93135
    94 /* Copy the first part of user declarations.  */
    95 #line 34 "heimdal/lib/hx509/sel-gram.y"
    96 
    97 #ifdef HAVE_CONFIG_H
    98 #include <config.h>
    99 #endif
    100 #include <stdio.h>
    101 #include <stdlib.h>
    102 #include <hx_locl.h>
    103 
    104 
    105 
    106 
    107 /* Enabling traces.  */
    108 #ifndef YYDEBUG
    109 # define YYDEBUG 0
    110 #endif
    111 
    112 /* Enabling verbose error messages.  */
    113 #ifdef YYERROR_VERBOSE
    114 # undef YYERROR_VERBOSE
    115 # define YYERROR_VERBOSE 1
    116 #else
    117 # define YYERROR_VERBOSE 0
    118 #endif
    119 
    120 /* Enabling the token table.  */
    121 #ifndef YYTOKEN_TABLE
    122 # define YYTOKEN_TABLE 0
    123 #endif
    124 
    125136#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
    126137typedef union YYSTYPE
    127 #line 45 "heimdal/lib/hx509/sel-gram.y"
    128 {
     138{
     139
     140/* Line 214 of yacc.c  */
     141#line 45 "sel-gram.c"
     142
    129143    char *string;
    130144    struct hx_expr *expr;
    131 }
    132 /* Line 187 of yacc.c.  */
    133 #line 134 "heimdal/lib/hx509/sel-gram.y"
    134         YYSTYPE;
     145
     146
     147
     148/* Line 214 of yacc.c  */
     149#line 150 "sel-gram.c"
     150} YYSTYPE;
     151# define YYSTYPE_IS_TRIVIAL 1
    135152# define yystype YYSTYPE /* obsolescent; will be withdrawn */
    136153# define YYSTYPE_IS_DECLARED 1
    137 # define YYSTYPE_IS_TRIVIAL 1
    138 #endif
    139 
     154#endif
    140155
    141156
     
    143158
    144159
    145 /* Line 216 of yacc.c.  */
    146 #line 147 "heimdal/lib/hx509/sel-gram.y"
     160/* Line 264 of yacc.c  */
     161#line 162 "sel-gram.c"
    147162
    148163#ifdef short
     
    219234     || defined __cplusplus || defined _MSC_VER)
    220235static int
    221 YYID (int i)
     236YYID (int yyi)
    222237#else
    223238static int
    224 YYID (i)
    225     int i;
    226 #endif
    227 {
    228   return i;
     239YYID (yyi)
     240    int yyi;
     241#endif
     242{
     243  return yyi;
    229244}
    230245#endif
     
    307322union yyalloc
    308323{
    309   yytype_int16 yyss;
    310   YYSTYPE yyvs;
    311   };
     324  yytype_int16 yyss_alloc;
     325  YYSTYPE yyvs_alloc;
     326};
    312327
    313328/* The size of the maximum gap between one aligned stack and the next.  */
     
    343358   stack.  Advance YYPTR to a properly aligned location for the next
    344359   stack.  */
    345 # define YYSTACK_RELOCATE(Stack)                                        \
     360# define YYSTACK_RELOCATE(Stack_alloc, Stack)                           \
    346361    do                                                                  \
    347362      {                                                                 \
    348363        YYSIZE_T yynewbytes;                                            \
    349         YYCOPY (&yyptr->Stack, Stack, yysize);                          \
    350         Stack = &yyptr->Stack                                        \
     364        YYCOPY (&yyptr->Stack_alloc, Stack, yysize);                    \
     365        Stack = &yyptr->Stack_alloc;                                    \
    351366        yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
    352367        yyptr += yynewbytes / sizeof (*yyptr);                          \
     
    738753     || defined __cplusplus || defined _MSC_VER)
    739754static void
    740 yy_stack_print (yytype_int16 *bottom, yytype_int16 *top)
     755yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop)
    741756#else
    742757static void
    743 yy_stack_print (bottom, top)
    744     yytype_int16 *bottom;
    745     yytype_int16 *top;
     758yy_stack_print (yybottom, yytop)
     759    yytype_int16 *yybottom;
     760    yytype_int16 *yytop;
    746761#endif
    747762{
    748763  YYFPRINTF (stderr, "Stack now");
    749   for (; bottom <= top; ++bottom)
    750     YYFPRINTF (stderr, " %d", *bottom);
     764  for (; yybottom <= yytop; yybottom++)
     765    {
     766      int yybot = *yybottom;
     767      YYFPRINTF (stderr, " %d", yybot);
     768    }
    751769  YYFPRINTF (stderr, "\n");
    752770}
     
    782800  for (yyi = 0; yyi < yynrhs; yyi++)
    783801    {
    784       fprintf (stderr, "   $%d = ", yyi + 1);
     802      YYFPRINTF (stderr, "   $%d = ", yyi + 1);
    785803      yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi],
    786804                       &(yyvsp[(yyi + 1) - (yynrhs)])
    787805                                       );
    788       fprintf (stderr, "\n");
     806      YYFPRINTF (stderr, "\n");
    789807    }
    790808}
     
    10691087}
    10701088
    1071 
    1072 
    10731089/* Prevent warnings from -Wmissing-prototypes.  */
    1074 
    10751090#ifdef YYPARSE_PARAM
    10761091#if defined __STDC__ || defined __cplusplus
     
    10881103
    10891104
    1090 
    1091 /* The look-ahead symbol.  */
     1105/* The lookahead symbol.  */
    10921106int yychar;
    10931107
    1094 /* The semantic value of the look-ahead symbol.  */
     1108/* The semantic value of the lookahead symbol.  */
    10951109YYSTYPE yylval;
    10961110
     
    11001114
    11011115
    1102 /*----------.
    1103 | yyparse.  |
    1104 `----------*/
     1116/*-------------------------.
     1117| yyparse or yypush_parse.  |
     1118`-------------------------*/
    11051119
    11061120#ifdef YYPARSE_PARAM
     
    11261140#endif
    11271141{
    1128  
    1129   int yystate;
     1142
     1143
     1144    int yystate;
     1145    /* Number of tokens to shift before error messages enabled.  */
     1146    int yyerrstatus;
     1147
     1148    /* The stacks and their tools:
     1149       `yyss': related to states.
     1150       `yyvs': related to semantic values.
     1151
     1152       Refer to the stacks thru separate pointers, to allow yyoverflow
     1153       to reallocate them elsewhere.  */
     1154
     1155    /* The state stack.  */
     1156    yytype_int16 yyssa[YYINITDEPTH];
     1157    yytype_int16 *yyss;
     1158    yytype_int16 *yyssp;
     1159
     1160    /* The semantic value stack.  */
     1161    YYSTYPE yyvsa[YYINITDEPTH];
     1162    YYSTYPE *yyvs;
     1163    YYSTYPE *yyvsp;
     1164
     1165    YYSIZE_T yystacksize;
     1166
    11301167  int yyn;
    11311168  int yyresult;
    1132   /* Number of tokens to shift before error messages enabled.  */
    1133   int yyerrstatus;
    1134   /* Look-ahead token as an internal (translated) token number.  */
    1135   int yytoken = 0;
     1169  /* Lookahead token as an internal (translated) token number.  */
     1170  int yytoken;
     1171  /* The variables used to return semantic value and location from the
     1172     action routines.  */
     1173  YYSTYPE yyval;
     1174
    11361175#if YYERROR_VERBOSE
    11371176  /* Buffer for error messages, and its allocated size.  */
     
    11411180#endif
    11421181
    1143   /* Three stacks and their tools:
    1144      `yyss': related to states,
    1145      `yyvs': related to semantic values,
    1146      `yyls': related to locations.
    1147 
    1148      Refer to the stacks thru separate pointers, to allow yyoverflow
    1149      to reallocate them elsewhere.  */
    1150 
    1151   /* The state stack.  */
    1152   yytype_int16 yyssa[YYINITDEPTH];
    1153   yytype_int16 *yyss = yyssa;
    1154   yytype_int16 *yyssp;
    1155 
    1156   /* The semantic value stack.  */
    1157   YYSTYPE yyvsa[YYINITDEPTH];
    1158   YYSTYPE *yyvs = yyvsa;
    1159   YYSTYPE *yyvsp;
    1160 
    1161 
    1162 
    11631182#define YYPOPSTACK(N)   (yyvsp -= (N), yyssp -= (N))
    1164 
    1165   YYSIZE_T yystacksize = YYINITDEPTH;
    1166 
    1167   /* The variables used to return semantic value and location from the
    1168      action routines.  */
    1169   YYSTYPE yyval;
    1170 
    11711183
    11721184  /* The number of symbols on the RHS of the reduced rule.
     
    11741186  int yylen = 0;
    11751187
     1188  yytoken = 0;
     1189  yyss = yyssa;
     1190  yyvs = yyvsa;
     1191  yystacksize = YYINITDEPTH;
     1192
    11761193  YYDPRINTF ((stderr, "Starting parse\n"));
    11771194
     
    11791196  yyerrstatus = 0;
    11801197  yynerrs = 0;
    1181   yychar = YYEMPTY;             /* Cause a token to be read.  */
     1198  yychar = YYEMPTY; /* Cause a token to be read.  */
    11821199
    11831200  /* Initialize stack pointers.
     
    11851202     so that they stay on the same level as the state stack.
    11861203     The wasted elements are never initialized.  */
    1187 
    11881204  yyssp = yyss;
    11891205  yyvsp = yyvs;
     
    12151231        yytype_int16 *yyss1 = yyss;
    12161232
    1217 
    12181233        /* Each stack pointer address is followed by the size of the
    12191234           data in use in that stack, in bytes.  This used to be a
     
    12231238                    &yyss1, yysize * sizeof (*yyssp),
    12241239                    &yyvs1, yysize * sizeof (*yyvsp),
    1225 
    12261240                    &yystacksize);
    12271241
     
    12461260        if (! yyptr)
    12471261          goto yyexhaustedlab;
    1248         YYSTACK_RELOCATE (yyss);
    1249         YYSTACK_RELOCATE (yyvs);
    1250 
     1262        YYSTACK_RELOCATE (yyss_alloc, yyss);
     1263        YYSTACK_RELOCATE (yyvs_alloc, yyvs);
    12511264#  undef YYSTACK_RELOCATE
    12521265        if (yyss1 != yyssa)
     
    12591272      yyvsp = yyvs + yysize - 1;
    12601273
    1261 
    12621274      YYDPRINTF ((stderr, "Stack size increased to %lu\n",
    12631275                  (unsigned long int) yystacksize));
     
    12681280
    12691281  YYDPRINTF ((stderr, "Entering state %d\n", yystate));
     1282
     1283  if (yystate == YYFINAL)
     1284    YYACCEPT;
    12701285
    12711286  goto yybackup;
     
    12771292
    12781293  /* Do appropriate processing given the current state.  Read a
    1279      look-ahead token if we need one and don't already have one.  */
    1280 
    1281   /* First try to decide what to do without reference to look-ahead token.  */
     1294     lookahead token if we need one and don't already have one.  */
     1295
     1296  /* First try to decide what to do without reference to lookahead token.  */
    12821297  yyn = yypact[yystate];
    12831298  if (yyn == YYPACT_NINF)
    12841299    goto yydefault;
    12851300
    1286   /* Not known => get a look-ahead token if don't already have one.  */
    1287 
    1288   /* YYCHAR is either YYEMPTY or YYEOF or a valid look-ahead symbol.  */
     1301  /* Not known => get a lookahead token if don't already have one.  */
     1302
     1303  /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol.  */
    12891304  if (yychar == YYEMPTY)
    12901305    {
     
    13181333    }
    13191334
    1320   if (yyn == YYFINAL)
    1321     YYACCEPT;
    1322 
    13231335  /* Count tokens shifted since error; after three, turn off error
    13241336     status.  */
     
    13261338    yyerrstatus--;
    13271339
    1328   /* Shift the look-ahead token.  */
     1340  /* Shift the lookahead token.  */
    13291341  YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
    13301342
    1331   /* Discard the shifted token unless it is eof.  */
    1332   if (yychar != YYEOF)
    1333     yychar = YYEMPTY;
     1343  /* Discard the shifted token.  */
     1344  yychar = YYEMPTY;
    13341345
    13351346  yystate = yyn;
     
    13711382    {
    13721383        case 2:
    1373 #line 73 "heimdal/lib/hx509/sel-gram.y"
     1384
     1385/* Line 1455 of yacc.c  */
     1386#line 73 "sel-gram.c"
    13741387    { _hx509_expr_input.expr = (yyvsp[(1) - (1)].expr); }
    13751388    break;
    13761389
    13771390  case 3:
    1378 #line 75 "heimdal/lib/hx509/sel-gram.y"
     1391
     1392/* Line 1455 of yacc.c  */
     1393#line 75 "sel-gram.c"
    13791394    { (yyval.expr) = _hx509_make_expr(op_TRUE, NULL, NULL); }
    13801395    break;
    13811396
    13821397  case 4:
    1383 #line 76 "heimdal/lib/hx509/sel-gram.y"
     1398
     1399/* Line 1455 of yacc.c  */
     1400#line 76 "sel-gram.c"
    13841401    { (yyval.expr) = _hx509_make_expr(op_FALSE, NULL, NULL); }
    13851402    break;
    13861403
    13871404  case 5:
    1388 #line 77 "heimdal/lib/hx509/sel-gram.y"
     1405
     1406/* Line 1455 of yacc.c  */
     1407#line 77 "sel-gram.c"
    13891408    { (yyval.expr) = _hx509_make_expr(op_NOT, (yyvsp[(2) - (2)].expr), NULL); }
    13901409    break;
    13911410
    13921411  case 6:
    1393 #line 78 "heimdal/lib/hx509/sel-gram.y"
     1412
     1413/* Line 1455 of yacc.c  */
     1414#line 78 "sel-gram.c"
    13941415    { (yyval.expr) = _hx509_make_expr(op_AND, (yyvsp[(1) - (3)].expr), (yyvsp[(3) - (3)].expr)); }
    13951416    break;
    13961417
    13971418  case 7:
    1398 #line 79 "heimdal/lib/hx509/sel-gram.y"
     1419
     1420/* Line 1455 of yacc.c  */
     1421#line 79 "sel-gram.c"
    13991422    { (yyval.expr) = _hx509_make_expr(op_OR, (yyvsp[(1) - (3)].expr), (yyvsp[(3) - (3)].expr)); }
    14001423    break;
    14011424
    14021425  case 8:
    1403 #line 80 "heimdal/lib/hx509/sel-gram.y"
     1426
     1427/* Line 1455 of yacc.c  */
     1428#line 80 "sel-gram.c"
    14041429    { (yyval.expr) = (yyvsp[(2) - (3)].expr); }
    14051430    break;
    14061431
    14071432  case 9:
    1408 #line 81 "heimdal/lib/hx509/sel-gram.y"
     1433
     1434/* Line 1455 of yacc.c  */
     1435#line 81 "sel-gram.c"
    14091436    { (yyval.expr) = _hx509_make_expr(op_COMP, (yyvsp[(1) - (1)].expr), NULL); }
    14101437    break;
    14111438
    14121439  case 10:
    1413 #line 84 "heimdal/lib/hx509/sel-gram.y"
     1440
     1441/* Line 1455 of yacc.c  */
     1442#line 84 "sel-gram.c"
    14141443    { (yyval.expr) = _hx509_make_expr(expr_WORDS, (yyvsp[(1) - (1)].expr), NULL); }
    14151444    break;
    14161445
    14171446  case 11:
    1418 #line 85 "heimdal/lib/hx509/sel-gram.y"
     1447
     1448/* Line 1455 of yacc.c  */
     1449#line 85 "sel-gram.c"
    14191450    { (yyval.expr) = _hx509_make_expr(expr_WORDS, (yyvsp[(1) - (3)].expr), (yyvsp[(3) - (3)].expr)); }
    14201451    break;
    14211452
    14221453  case 12:
    1423 #line 88 "heimdal/lib/hx509/sel-gram.y"
     1454
     1455/* Line 1455 of yacc.c  */
     1456#line 88 "sel-gram.c"
    14241457    { (yyval.expr) = _hx509_make_expr(comp_EQ, (yyvsp[(1) - (4)].expr), (yyvsp[(4) - (4)].expr)); }
    14251458    break;
    14261459
    14271460  case 13:
    1428 #line 89 "heimdal/lib/hx509/sel-gram.y"
     1461
     1462/* Line 1455 of yacc.c  */
     1463#line 89 "sel-gram.c"
    14291464    { (yyval.expr) = _hx509_make_expr(comp_NE, (yyvsp[(1) - (4)].expr), (yyvsp[(4) - (4)].expr)); }
    14301465    break;
    14311466
    14321467  case 14:
    1433 #line 90 "heimdal/lib/hx509/sel-gram.y"
     1468
     1469/* Line 1455 of yacc.c  */
     1470#line 90 "sel-gram.c"
    14341471    { (yyval.expr) = _hx509_make_expr(comp_TAILEQ, (yyvsp[(1) - (3)].expr), (yyvsp[(3) - (3)].expr)); }
    14351472    break;
    14361473
    14371474  case 15:
    1438 #line 91 "heimdal/lib/hx509/sel-gram.y"
     1475
     1476/* Line 1455 of yacc.c  */
     1477#line 91 "sel-gram.c"
    14391478    { (yyval.expr) = _hx509_make_expr(comp_IN, (yyvsp[(1) - (5)].expr), (yyvsp[(4) - (5)].expr)); }
    14401479    break;
    14411480
    14421481  case 16:
    1443 #line 92 "heimdal/lib/hx509/sel-gram.y"
     1482
     1483/* Line 1455 of yacc.c  */
     1484#line 92 "sel-gram.c"
    14441485    { (yyval.expr) = _hx509_make_expr(comp_IN, (yyvsp[(1) - (3)].expr), (yyvsp[(3) - (3)].expr)); }
    14451486    break;
    14461487
    14471488  case 17:
    1448 #line 95 "heimdal/lib/hx509/sel-gram.y"
     1489
     1490/* Line 1455 of yacc.c  */
     1491#line 95 "sel-gram.c"
    14491492    { (yyval.expr) = (yyvsp[(1) - (1)].expr); }
    14501493    break;
    14511494
    14521495  case 18:
    1453 #line 96 "heimdal/lib/hx509/sel-gram.y"
     1496
     1497/* Line 1455 of yacc.c  */
     1498#line 96 "sel-gram.c"
    14541499    { (yyval.expr) = (yyvsp[(1) - (1)].expr); }
    14551500    break;
    14561501
    14571502  case 19:
    1458 #line 97 "heimdal/lib/hx509/sel-gram.y"
     1503
     1504/* Line 1455 of yacc.c  */
     1505#line 97 "sel-gram.c"
    14591506    { (yyval.expr) = (yyvsp[(1) - (1)].expr); }
    14601507    break;
    14611508
    14621509  case 20:
    1463 #line 98 "heimdal/lib/hx509/sel-gram.y"
     1510
     1511/* Line 1455 of yacc.c  */
     1512#line 98 "sel-gram.c"
    14641513    { (yyval.expr) = (yyvsp[(1) - (1)].expr); }
    14651514    break;
    14661515
    14671516  case 21:
    1468 #line 101 "heimdal/lib/hx509/sel-gram.y"
     1517
     1518/* Line 1455 of yacc.c  */
     1519#line 101 "sel-gram.c"
    14691520    { (yyval.expr) = _hx509_make_expr(expr_NUMBER, (yyvsp[(1) - (1)].string), NULL); }
    14701521    break;
    14711522
    14721523  case 22:
    1473 #line 102 "heimdal/lib/hx509/sel-gram.y"
     1524
     1525/* Line 1455 of yacc.c  */
     1526#line 102 "sel-gram.c"
    14741527    { (yyval.expr) = _hx509_make_expr(expr_STRING, (yyvsp[(1) - (1)].string), NULL); }
    14751528    break;
    14761529
    14771530  case 23:
    1478 #line 104 "heimdal/lib/hx509/sel-gram.y"
     1531
     1532/* Line 1455 of yacc.c  */
     1533#line 104 "sel-gram.c"
    14791534    {
    14801535                        (yyval.expr) = _hx509_make_expr(expr_FUNCTION, (yyvsp[(1) - (4)].string), (yyvsp[(3) - (4)].expr)); }
     
    14821537
    14831538  case 24:
    1484 #line 107 "heimdal/lib/hx509/sel-gram.y"
     1539
     1540/* Line 1455 of yacc.c  */
     1541#line 107 "sel-gram.c"
    14851542    { (yyval.expr) = (yyvsp[(3) - (4)].expr); }
    14861543    break;
    14871544
    14881545  case 25:
    1489 #line 110 "heimdal/lib/hx509/sel-gram.y"
     1546
     1547/* Line 1455 of yacc.c  */
     1548#line 110 "sel-gram.c"
    14901549    {
    14911550                        (yyval.expr) = _hx509_make_expr(expr_VAR, (yyvsp[(1) - (3)].string), (yyvsp[(3) - (3)].expr)); }
     
    14931552
    14941553  case 26:
    1495 #line 112 "heimdal/lib/hx509/sel-gram.y"
     1554
     1555/* Line 1455 of yacc.c  */
     1556#line 112 "sel-gram.c"
    14961557    {
    14971558                        (yyval.expr) = _hx509_make_expr(expr_VAR, (yyvsp[(1) - (1)].string), NULL); }
     
    14991560
    15001561
    1501 /* Line 1267 of yacc.c.  */
    1502 #line 1500 "heimdal/lib/hx509/sel-gram.y"
     1562
     1563/* Line 1455 of yacc.c  */
     1564#line 1563 "sel-gram.c"
    15031565      default: break;
    15041566    }
     
    15101572
    15111573  *++yyvsp = yyval;
    1512 
    15131574
    15141575  /* Now `shift' the result of the reduction.  Determine what state
     
    15761637  if (yyerrstatus == 3)
    15771638    {
    1578       /* If just tried and failed to reuse look-ahead token after an
     1639      /* If just tried and failed to reuse lookahead token after an
    15791640         error, discard it.  */
    15801641
     
    15931654    }
    15941655
    1595   /* Else will try to reuse look-ahead token after shifting the error
     1656  /* Else will try to reuse lookahead token after shifting the error
    15961657     token.  */
    15971658  goto yyerrlab1;
     
    16501711    }
    16511712
    1652   if (yyn == YYFINAL)
    1653     YYACCEPT;
    1654 
    16551713  *++yyvsp = yylval;
    16561714
     
    16771735  goto yyreturn;
    16781736
    1679 #ifndef yyoverflow
     1737#if !defined(yyoverflow) || YYERROR_VERBOSE
    16801738/*-------------------------------------------------.
    16811739| yyexhaustedlab -- memory exhaustion comes here.  |
     
    16881746
    16891747yyreturn:
    1690   if (yychar != YYEOF && yychar != YYEMPTY)
     1748  if (yychar != YYEMPTY)
    16911749     yydestruct ("Cleanup: discarding lookahead",
    16921750                 yytoken, &yylval);
  • trunk/server/source4/heimdal/lib/hx509/sel-gram.h

    r414 r745  
    1 /* A Bison parser, made by GNU Bison 2.3.  */
     1
     2/* A Bison parser, made by GNU Bison 2.4.1.  */
    23
    34/* Skeleton interface for Bison's Yacc-like parsers in C
    4 
    5    Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006
     5   
     6      Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006
    67   Free Software Foundation, Inc.
    7 
    8    This program is free software; you can redistribute it and/or modify
     8   
     9   This program is free software: you can redistribute it and/or modify
    910   it under the terms of the GNU General Public License as published by
    10    the Free Software Foundation; either version 2, or (at your option)
    11    any later version.
    12 
     11   the Free Software Foundation, either version 3 of the License, or
     12   (at your option) any later version.
     13   
    1314   This program is distributed in the hope that it will be useful,
    1415   but WITHOUT ANY WARRANTY; without even the implied warranty of
    1516   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1617   GNU General Public License for more details.
    17 
     18   
    1819   You should have received a copy of the GNU General Public License
    19    along with this program; if not, write to the Free Software
    20    Foundation, Inc., 51 Franklin Street, Fifth Floor,
    21    Boston, MA 02110-1301, USA.  */
     20   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
    2221
    2322/* As a special exception, you may create a larger work that contains
     
    3029   Bison output files to be licensed under the GNU General Public
    3130   License without this special exception.
    32 
     31   
    3332   This special exception was added by the Free Software Foundation in
    3433   version 2.2 of Bison.  */
     34
    3535
    3636/* Tokens.  */
     
    6767#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
    6868typedef union YYSTYPE
    69 #line 45 "heimdal/lib/hx509/sel-gram.y"
    7069{
     70
     71/* Line 1676 of yacc.c  */
     72#line 45 "sel-gram.c"
     73
    7174    char *string;
    7275    struct hx_expr *expr;
    73 }
    74 /* Line 1489 of yacc.c.  */
    75 #line 76 "heimdal/lib/hx509/sel-gram.y"
    76         YYSTYPE;
     76
     77
     78
     79/* Line 1676 of yacc.c  */
     80#line 81 "sel-gram.c"
     81} YYSTYPE;
     82# define YYSTYPE_IS_TRIVIAL 1
    7783# define yystype YYSTYPE /* obsolescent; will be withdrawn */
    7884# define YYSTYPE_IS_DECLARED 1
    79 # define YYSTYPE_IS_TRIVIAL 1
    8085#endif
    8186
    8287extern YYSTYPE yylval;
    8388
     89
  • trunk/server/source4/heimdal/lib/hx509/sel-lex.c

    r414 r745  
    11#include "config.h"
    22
    3 #line 3 "heimdal/lib/hx509/sel-lex.c"
     3#line 3 "sel-lex.c"
    44
    55#define  YY_INT_ALIGNED short int
     
    1010#define YY_FLEX_MAJOR_VERSION 2
    1111#define YY_FLEX_MINOR_VERSION 5
    12 #define YY_FLEX_SUBMINOR_VERSION 34
     12#define YY_FLEX_SUBMINOR_VERSION 35
    1313#if YY_FLEX_SUBMINOR_VERSION > 0
    1414#define FLEX_BETA
     
    5555typedef unsigned short int flex_uint16_t;
    5656typedef unsigned int flex_uint32_t;
    57 #endif /* ! C99 */
    5857
    5958/* Limits of integral types. */
     
    8584#define UINT32_MAX             (4294967295U)
    8685#endif
     86
     87#endif /* ! C99 */
    8788
    8889#endif /* ! FLEXINT_H */
     
    142143/* Size of default input buffer. */
    143144#ifndef YY_BUF_SIZE
     145#ifdef __ia64__
     146/* On IA-64, the buffer size is 16k, not 8k.
     147 * Moreover, YY_BUF_SIZE is 2*YY_READ_BUF_SIZE in the general case.
     148 * Ditto for the __ia64__ case accordingly.
     149 */
     150#define YY_BUF_SIZE 32768
     151#else
    144152#define YY_BUF_SIZE 16384
     153#endif /* __ia64__ */
    145154#endif
    146155
     
    179188
    180189#define unput(c) yyunput( c, (yytext_ptr)  )
    181 
    182 /* The following is because we cannot portably get our hands on size_t
    183  * (without autoconf's help, which isn't available because we want
    184  * flex-generated scanners to compile on their own).
    185  * Given that the standard has decreed that size_t exists since 1989,
    186  * I guess we can afford to depend on it. Manoj.
    187  */
    188190
    189191#ifndef YY_TYPEDEF_YY_SIZE_T
     
    532534struct hx_expr_input _hx509_expr_input;
    533535
     536#ifndef YY_NULL
     537#define YY_NULL 0
     538#endif
     539
    534540#define YY_NO_UNPUT 1
    535541
     
    539545#undef ECHO
    540546
    541 #line 541 "heimdal/lib/hx509/sel-lex.c"
     547#line 547 "sel-lex.c"
    542548
    543549#define INITIAL 0
     
    556562
    557563static int yy_init_globals (void );
     564
     565/* Accessor methods to globals.
     566   These are made visible to non-reentrant scanners for convenience. */
     567
     568int yylex_destroy (void );
     569
     570int yyget_debug (void );
     571
     572void yyset_debug (int debug_flag  );
     573
     574YY_EXTRA_TYPE yyget_extra (void );
     575
     576void yyset_extra (YY_EXTRA_TYPE user_defined  );
     577
     578FILE *yyget_in (void );
     579
     580void yyset_in  (FILE * in_str  );
     581
     582FILE *yyget_out (void );
     583
     584void yyset_out  (FILE * out_str  );
     585
     586int yyget_leng (void );
     587
     588char *yyget_text (void );
     589
     590int yyget_lineno (void );
     591
     592void yyset_lineno (int line_number  );
    558593
    559594/* Macros after this point can all be overridden by user definitions in
     
    591626/* Amount of stuff to slurp up with each read. */
    592627#ifndef YY_READ_BUF_SIZE
     628#ifdef __ia64__
     629/* On IA-64, the buffer size is 16k, not 8k */
     630#define YY_READ_BUF_SIZE 16384
     631#else
    593632#define YY_READ_BUF_SIZE 8192
     633#endif /* __ia64__ */
    594634#endif
    595635
     
    599639 * we now use fwrite().
    600640 */
    601 #define ECHO fwrite( yytext, yyleng, 1, yyout )
     641#define ECHO do { if (fwrite( yytext, yyleng, 1, yyout )) {} } while (0)
    602642#endif
    603643
     
    610650                { \
    611651                int c = '*'; \
    612                 int n; \
     652                size_t n; \
    613653                for ( n = 0; n < max_size && \
    614654                             (c = getc( yyin )) != EOF && c != '\n'; ++n ) \
     
    692732        register int yy_act;
    693733   
    694 #line 64 "sel-lex.l"
    695 
    696 
    697 #line 697 "heimdal/lib/hx509/sel-lex.c"
     734#line 68 "sel-lex.l"
     735
     736
     737#line 737 "sel-lex.c"
    698738
    699739        if ( !(yy_init) )
     
    780820case 1:
    781821YY_RULE_SETUP
    782 #line 66 "sel-lex.l"
     822#line 70 "sel-lex.l"
    783823{ return kw_TRUE; }
    784824        YY_BREAK
    785825case 2:
    786826YY_RULE_SETUP
    787 #line 67 "sel-lex.l"
     827#line 71 "sel-lex.l"
    788828{ return kw_FALSE; }
    789829        YY_BREAK
    790830case 3:
    791831YY_RULE_SETUP
    792 #line 68 "sel-lex.l"
     832#line 72 "sel-lex.l"
    793833{ return kw_AND; }
    794834        YY_BREAK
    795835case 4:
    796836YY_RULE_SETUP
    797 #line 69 "sel-lex.l"
     837#line 73 "sel-lex.l"
    798838{ return kw_OR; }
    799839        YY_BREAK
    800840case 5:
    801841YY_RULE_SETUP
    802 #line 70 "sel-lex.l"
     842#line 74 "sel-lex.l"
    803843{ return kw_IN; }
    804844        YY_BREAK
    805845case 6:
    806846YY_RULE_SETUP
    807 #line 71 "sel-lex.l"
     847#line 75 "sel-lex.l"
    808848{ return kw_TAILMATCH; }
    809849        YY_BREAK
    810850case 7:
    811851YY_RULE_SETUP
    812 #line 73 "sel-lex.l"
     852#line 77 "sel-lex.l"
    813853{
    814854                          yylval.string = strdup ((const char *)yytext);
     
    818858case 8:
    819859YY_RULE_SETUP
    820 #line 77 "sel-lex.l"
     860#line 81 "sel-lex.l"
    821861{ yylval.string = handle_string(); return STRING; }
    822862        YY_BREAK
     
    824864/* rule 9 can match eol */
    825865YY_RULE_SETUP
    826 #line 78 "sel-lex.l"
     866#line 82 "sel-lex.l"
    827867{ ++lineno; }
    828868        YY_BREAK
    829869case 10:
    830870YY_RULE_SETUP
    831 #line 79 "sel-lex.l"
     871#line 83 "sel-lex.l"
    832872{ return *yytext; }
    833873        YY_BREAK
    834874case 11:
    835875YY_RULE_SETUP
    836 #line 80 "sel-lex.l"
     876#line 84 "sel-lex.l"
    837877;
    838878        YY_BREAK
    839879case 12:
    840880YY_RULE_SETUP
    841 #line 81 "sel-lex.l"
     881#line 85 "sel-lex.l"
    842882ECHO;
    843883        YY_BREAK
    844 #line 844 "heimdal/lib/hx509/sel-lex.c"
     884#line 884 "sel-lex.c"
    845885case YY_STATE_EOF(INITIAL):
    846886        yyterminate();
     
    16001640/** Setup the input buffer state to scan the given bytes. The next call to yylex() will
    16011641 * scan from a @e copy of @a bytes.
    1602  * @param bytes the byte buffer to scan
    1603  * @param len the number of bytes in the buffer pointed to by @a bytes.
     1642 * @param yybytes the byte buffer to scan
     1643 * @param _yybytes_len the number of bytes in the buffer pointed to by @a bytes.
    16041644 *
    16051645 * @return the newly allocated buffer state object.
     
    18401880#define YYTABLES_NAME "yytables"
    18411881
    1842 #line 81 "sel-lex.l"
     1882#line 85 "sel-lex.l"
    18431883
    18441884
  • trunk/server/source4/heimdal/lib/hx509/sel-lex.l

    r414 r745  
    5353
    5454struct hx_expr_input _hx509_expr_input;
     55
     56#ifndef YY_NULL
     57#define YY_NULL 0
     58#endif
    5559
    5660#define YY_NO_UNPUT 1
  • trunk/server/source4/heimdal/lib/hx509/sel.c

    r414 r745  
    176176    default:
    177177        _hx509_abort("hx509 eval expr with unknown op: %d", (int)expr->op);
     178        UNREACHABLE(return 0);
    178179    }
    179180}
Note: See TracChangeset for help on using the changeset viewer.