Пример #1
0
/* Encodes and public key parameters into a
 * subjectPublicKeyInfo structure and stores it in der.
 */
int
_gnutls_x509_encode_PKI_params (gnutls_datum_t *der,
                                gnutls_pk_algorithm_t
                                pk_algorithm, gnutls_pk_params_st * params)
{
  int ret;
  ASN1_TYPE tmp;

  ret = asn1_create_element (_gnutls_get_pkix (),
                                "PKIX1.Certificate", &tmp);
  if (ret != ASN1_SUCCESS)
    {
      gnutls_assert ();
      return _gnutls_asn2err (ret);
    }
    
  ret = _gnutls_x509_encode_and_copy_PKI_params (tmp,
                                         "tbsCertificate.subjectPublicKeyInfo",
                                         pk_algorithm, params);
  if (ret != ASN1_SUCCESS)
    {
      gnutls_assert ();
      ret = _gnutls_asn2err (ret);
      goto cleanup;
    }

  ret = _gnutls_x509_der_encode(tmp, "tbsCertificate.subjectPublicKeyInfo", der, 0);

cleanup:
  asn1_delete_structure (&tmp);

  return ret;
}
Пример #2
0
/**
  * gnutls_x509_crq_set_key - This function will associate the Certificate request with a key
  * @crq: should contain a gnutls_x509_crq_t structure
  * @key: holds a private key
  *
  * This function will set the public parameters from the given private key to the
  * request. Only RSA keys are currently supported.
  *
  * Returns 0 on success.
  *
  **/
int
gnutls_x509_crq_set_key (gnutls_x509_crq_t crq, gnutls_x509_privkey_t key)
{
    int result;

    if (crq == NULL)
    {
        gnutls_assert ();
        return GNUTLS_E_INVALID_REQUEST;
    }

    result = _gnutls_x509_encode_and_copy_PKI_params (crq->crq,
             "certificationRequestInfo.subjectPKInfo",
             key->pk_algorithm,
             key->params,
             key->params_size);

    if (result < 0)
    {
        gnutls_assert ();
        return result;
    }

    return 0;
}
Пример #3
0
/**
 * gnutls_x509_crt_set_key:
 * @crt: a certificate of type #gnutls_x509_crt_t
 * @key: holds a private key
 *
 * This function will set the public parameters from the given
 * private key to the certificate. Only RSA keys are currently
 * supported.
 *
 * Returns: On success, %GNUTLS_E_SUCCESS (0) is returned, otherwise a
 *   negative error value.
 *
 **/
int
gnutls_x509_crt_set_key(gnutls_x509_crt_t crt, gnutls_x509_privkey_t key)
{
	int result;

	if (crt == NULL) {
		gnutls_assert();
		return GNUTLS_E_INVALID_REQUEST;
	}

	result = _gnutls_x509_encode_and_copy_PKI_params(crt->cert,
							 "tbsCertificate.subjectPublicKeyInfo",
							 key->pk_algorithm,
							 &key->params);

	if (result < 0) {
		gnutls_assert();
		return result;
	}

	return 0;
}