Exemplo n.º 1
0
/**
 * shishi_encapreppart_cusec_set:
 * @handle: shishi handle as allocated by shishi_init().
 * @encapreppart: EncAPRepPart as allocated by shishi_encapreppart().
 * @cusec: client microseconds to set in authenticator, 0-999999.
 *
 * Set the cusec field in the Authenticator.
 *
 * Return value: Returns SHISHI_OK iff successful.
 **/
int
shishi_encapreppart_cusec_set (Shishi * handle,
			       Shishi_asn1 encapreppart, uint32_t cusec)
{
  int res;

  res = shishi_asn1_write_integer (handle, encapreppart, "cusec", cusec);
  if (res != SHISHI_OK)
    return res;

  return SHISHI_OK;
}
Exemplo n.º 2
0
/**
 * shishi_authenticator_add_authorizationdata:
 * @handle: shishi handle as allocated by shishi_init().
 * @authenticator: authenticator as allocated by shishi_authenticator().
 * @adtype: input authorization data type to add.
 * @addata: input authorization data to add.
 * @addatalen: size of input authorization data to add.
 *
 * Add authorization data to authenticator.
 *
 * Return value: Returns SHISHI_OK iff successful.
 **/
int
shishi_authenticator_add_authorizationdata (Shishi * handle,
        Shishi_asn1 authenticator,
        int32_t adtype,
        const char *addata,
        size_t addatalen)
{
    char *format;
    int res;
    size_t i;

    res = shishi_asn1_write (handle, authenticator,
                             "authorization-data", "NEW", 1);
    if (res != SHISHI_OK)
        return res;

    res = shishi_asn1_number_of_elements (handle, authenticator,
                                          "authorization-data", &i);
    if (res != SHISHI_OK)
        return res;

    asprintf (&format, "authorization-data.?%zu.ad-type", i);
    res = shishi_asn1_write_integer (handle, authenticator, format, adtype);
    if (res != SHISHI_OK)
    {
        free (format);
        return res;
    }

    sprintf (format, "authorization-data.?%zu.ad-data", i);
    res = shishi_asn1_write (handle, authenticator, format, addata, addatalen);
    free (format);
    if (res != SHISHI_OK)
        return res;

    return SHISHI_OK;
}
Exemplo n.º 3
0
/**
 * shishi_kdcreq_add_padata_preauth:
 * @handle: shishi handle as allocated by shishi_init().
 * @kdcreq: KDC-REQ to add pre-authentication data to.
 * @key: Key used to encrypt pre-auth data.
 *
 * Add pre-authentication data to KDC-REQ.
 *
 * Return value: Returns SHISHI_OK iff successful.
 **/
int
shishi_kdcreq_add_padata_preauth (Shishi * handle,
                                  Shishi_asn1 kdcreq, Shishi_key * key)
{
    char *der, *data;
    size_t derlen, datalen;
    Shishi_asn1 pa;
    struct timeval tv;
    int rc;
    Shishi_asn1 ed;

    pa = shishi_asn1_pa_enc_ts_enc (handle);
    if (!pa)
        return SHISHI_ASN1_ERROR;

    rc = gettimeofday (&tv, NULL);
    if (rc != 0)
        return SHISHI_GETTIMEOFDAY_ERROR;

    rc = shishi_asn1_write (handle, pa, "patimestamp",
                            shishi_generalize_time (handle, tv.tv_sec),
                            SHISHI_GENERALIZEDTIME_LENGTH);
    if (rc != SHISHI_OK)
        return rc;

    rc = shishi_asn1_write_integer (handle, pa, "pausec", tv.tv_usec);
    if (rc != SHISHI_OK)
        return rc;

    rc = shishi_asn1_to_der (handle, pa, &der, &derlen);
    if (rc != SHISHI_OK)
        return rc;

    rc = shishi_encrypt (handle, key, SHISHI_KEYUSAGE_ASREQ_PA_ENC_TIMESTAMP,
                         der, derlen, &data, &datalen);
    free (der);
    if (rc != SHISHI_OK)
        return rc;

    ed = shishi_asn1_encrypteddata (handle);
    if (!ed)
        return SHISHI_ASN1_ERROR;

    rc = shishi_asn1_write_integer (handle, ed, "etype", shishi_key_type (key));
    if (rc != SHISHI_OK)
        return rc;

    rc = shishi_asn1_write (handle, ed, "cipher", data, datalen);
    if (rc != SHISHI_OK)
        return rc;

    rc = shishi_asn1_write (handle, ed, "kvno", NULL, 0);
    if (rc != SHISHI_OK)
        return rc;

    rc = shishi_asn1_to_der (handle, ed, &der, &derlen);
    free (data);
    if (rc != SHISHI_OK)
        return rc;

    rc = shishi_kdcreq_add_padata (handle, kdcreq, SHISHI_PA_ENC_TIMESTAMP,
                                   der, derlen);
    free (der);
    if (rc != SHISHI_OK)
        return rc;

    return rc;
}