Print this page
6429 SMB domain join doesn't work with libreSSL
Reviewed by: Yuri Pankov <yuripv@gmx.com>
Reviewed by: Vitaliy Gusev <vgusev@racktopsystems.com>

Split Close
Expand all
Collapse all
          --- old/usr/src/lib/krb5/plugins/preauth/pkinit/pkinit_crypto_openssl.c
          +++ new/usr/src/lib/krb5/plugins/preauth/pkinit/pkinit_crypto_openssl.c
↓ open down ↓ 23 lines elided ↑ open up ↑
  24   24   * FOR ANY DAMAGES, INCLUDING SPECIAL, INDIRECT, INCIDENTAL, OR
  25   25   * CONSEQUENTIAL DAMAGES, WITH RESPECT TO ANY CLAIM ARISING
  26   26   * OUT OF OR IN CONNECTION WITH THE USE OF THE SOFTWARE, EVEN
  27   27   * IF IT HAS BEEN OR IS HEREAFTER ADVISED OF THE POSSIBILITY OF
  28   28   * SUCH DAMAGES.
  29   29   */
  30   30  
  31   31  /*
  32   32   * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
  33   33   * Copyright (c) 2012, OmniTI Computer Consulting, Inc. All rights reserved.
       34 + * Copyright 2015 RackTop Systems.
  34   35   */
  35   36  
  36   37  #include <errno.h>
  37   38  #include <string.h>
  38   39  #include <stdio.h>
  39   40  #include <stdlib.h>
  40   41  #include <dlfcn.h>
  41   42  #include <unistd.h>
  42   43  #include <dirent.h>
  43   44  
↓ open down ↓ 318 lines elided ↑ open up ↑
 362  363      0x23, 0x3B, 0xA1, 0x86, 0x51, 0x5B, 0xE7, 0xED,
 363  364      0x1F, 0x61, 0x29, 0x70, 0xCE, 0xE2, 0xD7, 0xAF,
 364  365      0xB8, 0x1B, 0xDD, 0x76, 0x21, 0x70, 0x48, 0x1C,
 365  366      0xD0, 0x06, 0x91, 0x27, 0xD5, 0xB0, 0x5A, 0xA9,
 366  367      0x93, 0xB4, 0xEA, 0x98, 0x8D, 0x8F, 0xDD, 0xC1,
 367  368      0x86, 0xFF, 0xB7, 0xDC, 0x90, 0xA6, 0xC0, 0x8F,
 368  369      0x4D, 0xF4, 0x35, 0xC9, 0x34, 0x06, 0x31, 0x99,
 369  370      0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
 370  371  };
 371  372  
 372      -/* Solaris Kerberos */
 373      -static k5_mutex_t oids_mutex = K5_MUTEX_PARTIAL_INITIALIZER;
 374      -static int pkinit_oids_refs = 0;
 375      -
 376  373  krb5_error_code
 377  374  pkinit_init_plg_crypto(pkinit_plg_crypto_context *cryptoctx) {
 378  375  
 379  376      krb5_error_code retval = ENOMEM;
 380  377      pkinit_plg_crypto_context ctx = NULL;
 381  378  
 382  379      /* initialize openssl routines */
 383  380      /* Solaris Kerberos */
 384  381      retval = openssl_init();
 385  382      if (retval != 0)
↓ open down ↓ 114 lines elided ↑ open up ↑
 500  497        DH_free(req_cryptoctx->dh);
 501  498      if (req_cryptoctx->received_cert != NULL)
 502  499        X509_free(req_cryptoctx->received_cert);
 503  500  
 504  501      free(req_cryptoctx);
 505  502  }
 506  503  
 507  504  static krb5_error_code
 508  505  pkinit_init_pkinit_oids(pkinit_plg_crypto_context ctx)
 509  506  {
 510      -    krb5_error_code retval = ENOMEM;
 511      -    int nid = 0;
      507 +    ctx->id_pkinit_san = OBJ_txt2obj("1.3.6.1.5.2.2", 1);
      508 +    if (ctx->id_pkinit_san == NULL)
      509 +        return ENOMEM;
 512  510  
 513      -    /*
 514      -     * If OpenSSL already knows about the OID, use the
 515      -     * existing definition. Otherwise, create an OID object.
 516      -     */
 517      -    #define CREATE_OBJ_IF_NEEDED(oid, vn, sn, ln) \
 518      -        nid = OBJ_txt2nid(oid); \
 519      -        if (nid == NID_undef) { \
 520      -            nid = OBJ_create(oid, sn, ln); \
 521      -            if (nid == NID_undef) { \
 522      -                pkiDebug("Error creating oid object for '%s'\n", oid); \
 523      -                goto out; \
 524      -            } \
 525      -        } \
 526      -        ctx->vn = OBJ_nid2obj(nid);
 527      -    
 528      -    /* Solaris Kerberos */
 529      -    retval = k5_mutex_lock(&oids_mutex);
 530      -    if (retval != 0)
 531      -        goto out;
      511 +    ctx->id_pkinit_authData = OBJ_txt2obj("1.3.6.1.5.2.3.1", 1);
      512 +    if (ctx->id_pkinit_authData == NULL)
      513 +        return ENOMEM;
 532  514  
 533      -    CREATE_OBJ_IF_NEEDED("1.3.6.1.5.2.2", id_pkinit_san,
 534      -                         "id-pkinit-san", "KRB5PrincipalName");
      515 +    ctx->id_pkinit_DHKeyData = OBJ_txt2obj("1.3.6.1.5.2.3.2", 1);
      516 +    if (ctx->id_pkinit_DHKeyData == NULL)
      517 +        return ENOMEM;
 535  518  
 536      -    CREATE_OBJ_IF_NEEDED("1.3.6.1.5.2.3.1", id_pkinit_authData,
 537      -                         "id-pkinit-authdata", "PKINIT signedAuthPack");
      519 +    ctx->id_pkinit_rkeyData = OBJ_txt2obj("1.3.6.1.5.2.3.3", 1);
      520 +    if (ctx->id_pkinit_rkeyData == NULL)
      521 +        return ENOMEM;
 538  522  
 539      -    CREATE_OBJ_IF_NEEDED("1.3.6.1.5.2.3.2", id_pkinit_DHKeyData,
 540      -                         "id-pkinit-DHKeyData", "PKINIT dhSignedData");
      523 +    ctx->id_pkinit_KPClientAuth = OBJ_txt2obj("1.3.6.1.5.2.3.4", 1);
      524 +    if (ctx->id_pkinit_KPClientAuth == NULL)
      525 +        return ENOMEM;
 541  526  
 542      -    CREATE_OBJ_IF_NEEDED("1.3.6.1.5.2.3.3", id_pkinit_rkeyData,
 543      -                         "id-pkinit-rkeyData", "PKINIT encKeyPack");
      527 +    ctx->id_pkinit_KPKdc = OBJ_txt2obj("1.3.6.1.5.2.3.5", 1);
      528 +    if (ctx->id_pkinit_KPKdc == NULL)
      529 +        return ENOMEM;
 544  530  
 545      -    CREATE_OBJ_IF_NEEDED("1.3.6.1.5.2.3.4", id_pkinit_KPClientAuth,
 546      -                         "id-pkinit-KPClientAuth", "PKINIT Client EKU");
      531 +    ctx->id_ms_kp_sc_logon = OBJ_txt2obj("1.3.6.1.4.1.311.20.2.2", 1);
      532 +    if (ctx->id_ms_kp_sc_logon == NULL)
      533 +        return ENOMEM;
 547  534  
 548      -    CREATE_OBJ_IF_NEEDED("1.3.6.1.5.2.3.5", id_pkinit_KPKdc,
 549      -                         "id-pkinit-KPKdc", "KDC EKU");
      535 +    ctx->id_ms_san_upn = OBJ_txt2obj("1.3.6.1.4.1.311.20.2.3", 1);
      536 +    if (ctx->id_ms_san_upn == NULL)
      537 +        return ENOMEM;
 550  538  
 551      -#if 0
 552      -    CREATE_OBJ_IF_NEEDED("1.2.840.113549.1.7.1", id_pkinit_authData9,
 553      -                         "id-pkcs7-data", "PKCS7 data");
 554      -#else
 555      -    /* See note in pkinit_pkcs7type2oid() */
 556      -    ctx->id_pkinit_authData9 = NULL;
 557      -#endif
      539 +    ctx->id_kp_serverAuth = OBJ_txt2obj("1.3.6.1.5.5.7.3.1", 1);
      540 +    if (ctx->id_kp_serverAuth == NULL)
      541 +        return ENOMEM;
 558  542  
 559      -    CREATE_OBJ_IF_NEEDED("1.3.6.1.4.1.311.20.2.2", id_ms_kp_sc_logon,
 560      -                         "id-ms-kp-sc-logon EKU", "Microsoft SmartCard Login EKU");
 561      -
 562      -    CREATE_OBJ_IF_NEEDED("1.3.6.1.4.1.311.20.2.3", id_ms_san_upn,
 563      -                         "id-ms-san-upn", "Microsoft Universal Principal Name");
 564      -
 565      -    CREATE_OBJ_IF_NEEDED("1.3.6.1.5.5.7.3.1", id_kp_serverAuth,
 566      -                         "id-kp-serverAuth EKU", "Server Authentication EKU");
 567      -
 568      -    /* Success */
 569      -    retval = 0;
 570      -    
 571      -    pkinit_oids_refs++;
 572      -    /* Solaris Kerberos */
 573      -    k5_mutex_unlock(&oids_mutex);
 574      -
 575      -out:
 576      -    return retval;
      543 +    return 0;
 577  544  }
 578  545  
 579  546  static krb5_error_code
 580  547  get_cert(char *filename, X509 **retcert)
 581  548  {
 582  549      X509 *cert = NULL;
 583  550      BIO *tmp = NULL;
 584  551      int code;
 585  552      krb5_error_code retval;
 586  553  
↓ open down ↓ 58 lines elided ↑ open up ↑
 645  612      if (tmp != NULL)
 646  613          BIO_free(tmp);
 647  614      return retval;
 648  615  }
 649  616  
 650  617  static void
 651  618  pkinit_fini_pkinit_oids(pkinit_plg_crypto_context ctx)
 652  619  {
 653  620      if (ctx == NULL)
 654  621          return;
 655      -
 656      -    /* Only call OBJ_cleanup once! */
 657      -    /* Solaris Kerberos: locking */
 658      -    k5_mutex_lock(&oids_mutex);
 659      -    if (--pkinit_oids_refs == 0)
 660      -        OBJ_cleanup();
 661      -    k5_mutex_unlock(&oids_mutex);
      622 +    ASN1_OBJECT_free(ctx->id_pkinit_san);
      623 +    ASN1_OBJECT_free(ctx->id_pkinit_authData);
      624 +    ASN1_OBJECT_free(ctx->id_pkinit_DHKeyData);
      625 +    ASN1_OBJECT_free(ctx->id_pkinit_rkeyData);
      626 +    ASN1_OBJECT_free(ctx->id_pkinit_KPClientAuth);
      627 +    ASN1_OBJECT_free(ctx->id_pkinit_KPKdc);
      628 +    ASN1_OBJECT_free(ctx->id_ms_kp_sc_logon);
      629 +    ASN1_OBJECT_free(ctx->id_ms_san_upn);
      630 +    ASN1_OBJECT_free(ctx->id_kp_serverAuth);
 662  631  }
 663  632  
 664  633  static krb5_error_code
 665  634  pkinit_init_dh_params(pkinit_plg_crypto_context plgctx)
 666  635  {
 667  636      krb5_error_code retval = ENOMEM;
 668  637  
 669  638      plgctx->dh_1024 = DH_new();
 670  639      if (plgctx->dh_1024 == NULL)
 671  640          goto cleanup;
↓ open down ↓ 192 lines elided ↑ open up ↑
 864  833      unsigned char *digestInfo_buf = NULL, *abuf = NULL;
 865  834      unsigned int md_len, md_len2, alen, digestInfo_len;
 866  835      STACK_OF(X509_ATTRIBUTE) * sk;
 867  836      unsigned char *sig = NULL;
 868  837      unsigned int sig_len = 0;
 869  838      X509_ALGOR *alg = NULL;
 870  839      ASN1_OCTET_STRING *digest = NULL;
 871  840      unsigned int alg_len = 0, digest_len = 0;
 872  841      unsigned char *y = NULL, *alg_buf = NULL, *digest_buf = NULL;
 873  842      X509 *cert = NULL;
 874      -    ASN1_OBJECT *oid = NULL;
      843 +    ASN1_OBJECT *oid = NULL, *oid_copy;
 875  844  
 876  845      /* Solaris Kerberos */
 877  846      if (signed_data == NULL)
 878  847          return EINVAL;
 879  848  
 880  849      if (signed_data_len == NULL)
 881  850          return EINVAL;
 882  851  
 883  852      /* start creating PKCS7 data */
 884  853      if ((p7 = PKCS7_new()) == NULL)
↓ open down ↓ 104 lines elided ↑ open up ↑
 989  958          md_tmp = EVP_MD_CTX_md(&ctx);
 990  959          EVP_DigestFinal_ex(&ctx, md_data, &md_len);
 991  960  
 992  961          /* create a message digest attr */
 993  962          digest_attr = ASN1_OCTET_STRING_new();
 994  963          ASN1_OCTET_STRING_set(digest_attr, md_data, (int)md_len);
 995  964          PKCS7_add_signed_attribute(p7si, NID_pkcs9_messageDigest,
 996  965                                     V_ASN1_OCTET_STRING, (char *) digest_attr);
 997  966  
 998  967          /* create a content-type attr */
      968 +        oid_copy = OBJ_dup(oid);
      969 +        if (oid_copy == NULL)
      970 +                goto cleanup2;
 999  971          PKCS7_add_signed_attribute(p7si, NID_pkcs9_contentType, 
1000      -                                   V_ASN1_OBJECT, oid);
      972 +                                   V_ASN1_OBJECT, oid_copy);
1001  973  
1002  974          /* create the signature over signed attributes. get DER encoded value */
1003  975          /* This is the place where smartcard signature needs to be calculated */
1004  976          sk = p7si->auth_attr;
1005  977          alen = ASN1_item_i2d((ASN1_VALUE *) sk, &abuf,
1006  978                               ASN1_ITEM_rptr(PKCS7_ATTR_SIGN));
1007  979          if (abuf == NULL)
1008  980              goto cleanup2;
1009  981      }
1010  982  
↓ open down ↓ 2109 lines elided ↑ open up ↑
3120 3092              default:
3121 3093                  return 0;
3122 3094          }
3123 3095      }
3124 3096      return ok;
3125 3097  }
3126 3098  
3127 3099  static ASN1_OBJECT *
3128 3100  pkinit_pkcs7type2oid(pkinit_plg_crypto_context cryptoctx, int pkcs7_type)
3129 3101  {
3130      -    int nid;
3131      -
3132 3102      switch (pkcs7_type) {
3133 3103          case CMS_SIGN_CLIENT:
3134 3104              return cryptoctx->id_pkinit_authData;
3135 3105          case CMS_SIGN_DRAFT9:
3136      -            /*
3137      -             * Delay creating this OID until we know we need it.
3138      -             * It shadows an existing OpenSSL oid.  If it
3139      -             * is created too early, it breaks things like
3140      -             * the use of pkcs12 (which uses pkcs7 structures).
3141      -             * We need this shadow version because our code
3142      -             * depends on the "other" type to be unknown to the
3143      -             * OpenSSL code.
3144      -             */ 
3145      -            if (cryptoctx->id_pkinit_authData9 == NULL) {
3146      -                pkiDebug("%s: Creating shadow instance of pkcs7-data oid\n",
3147      -                         __FUNCTION__);
3148      -                nid = OBJ_create("1.2.840.113549.1.7.1", "id-pkcs7-data",
3149      -                                 "PKCS7 data");
3150      -                if (nid == NID_undef)
3151      -                    return NULL;
3152      -                cryptoctx->id_pkinit_authData9 = OBJ_nid2obj(nid);
3153      -            }
3154      -            return cryptoctx->id_pkinit_authData9;
     3106 +            return OBJ_nid2obj(NID_pkcs7_data);
3155 3107          case CMS_SIGN_SERVER:
3156 3108              return cryptoctx->id_pkinit_DHKeyData;
3157 3109          case CMS_ENVEL_SERVER:
3158 3110              return cryptoctx->id_pkinit_rkeyData;
3159 3111          default:
3160 3112              return NULL;
3161 3113      }
3162 3114  
3163 3115  }
3164 3116  
↓ open down ↓ 3581 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX