int ssl_cert_add0_chain_cert(SSL *s, SSL_CTX *ctx, X509 *x)
	{
	int r;
	CERT_PKEY *cpk = s ? s->cert->key : ctx->cert->key;
	if (!cpk)
		return 0;
	r = ssl_security_cert(s, ctx, x, 0, 0);
	if (r != 1)
		{
		SSLerr(SSL_F_SSL_CERT_ADD0_CHAIN_CERT, r);
		return 0;
		}
	if (!cpk->chain)
		cpk->chain = sk_X509_new_null();
	if (!cpk->chain || !sk_X509_push(cpk->chain, x))
		return 0;
	return 1;
	}