keygen/src/ssl.c
/**
 * gen_signed_cert() - Generate an X509 cert with a public key
 * @pkey: The public key to certify as an EVP_PKEY*
 * @cn: The IPv6 address (as a string) to assign to CN
 *
 * Caller must free returned buffer with destroy_signed_cert
 *
 * Return: A new x509 certificate or NULL on error
 */
Generate an X509 cert with a public key
@pkey: The public key to certify as an EVP_PKEY
@cn: The IPv6 address (as a string) to assign to CN

Caller must free returned buffer with destroy_signed_cert

A new x509 certificate or NULL on error
Generate an X509 cert with a public key @pkey : The public key to certify as an EVP_PKEY @cn : The IPv6 address ( as a string ) to assign to CN Caller must free returned buffer with destroy_signed_cert A new x509 certificate or NULL on error
static X509 *gen_signed_cert(EVP_PKEY *pkey, const char *cn)
{
    X509 *x509;
    int ret;
    x509 = new_cert_1year();
    if (!x509) {
        fprintf(stderr, "%s ERR: Could generate new cert", __func__);
       goto out;
    }
    ret = X509_set_pubkey(x509, pkey);
    if (!ret) {
        fprintf(stderr, "%s ERR: Could add public key to cert", __func__);
        goto cleanup_err;
    }
    X509_NAME *name = X509_get_subject_name(x509);
    ret = X509_NAME_add_entry_by_txt(name, "CN", MBSTRING_ASC, (const unsigned char *)cn, -1, -1, 0);
    if (!ret) {
        fprintf(stderr, "%s ERR: Could not add CN", __func__);
        goto cleanup_err;
    }
    ret = X509_set_issuer_name(x509, name);
    if (!ret) {
        fprintf(stderr, "%s ERR: Could not add name", __func__);
        goto cleanup_err;
    }
    x509_set_rand_serial(x509);
    if (!X509_sign(x509, pkey, EVP_sha256())) {
        fprintf(stderr, "%s ERR: Could not sign key", __func__);
        goto cleanup_err;
    }
    goto out;
cleanup_err:
    if (x509)
        X509_free(x509);
    x509 = NULL;
out:
    return x509;
}
static X509 * gen_signed_cert ( EVP_PKEY * pkey , const char * cn ) { X509 * x509 ; int ret ; x509 = new_cert_1year ( ) ; if ( ! x509 ) { fprintf ( stderr , " " , __func__ ) ; goto out ; } ret = X509_set_pubkey ( x509 , pkey ) ; if ( ! ret ) { fprintf ( stderr , " " , __func__ ) ; goto cleanup_err ; } X509_NAME * name = X509_get_subject_name ( x509 ) ; ret = X509_NAME_add_entry_by_txt ( name , " " , MBSTRING_ASC , ( const unsigned char * ) cn , -1 , -1 , 0 ) ; if ( ! ret ) { fprintf ( stderr , " " , __func__ ) ; goto cleanup_err ; } ret = X509_set_issuer_name ( x509 , name ) ; if ( ! ret ) { fprintf ( stderr , " " , __func__ ) ; goto cleanup_err ; } x509_set_rand_serial ( x509 ) ; if ( ! X509_sign ( x509 , pkey , EVP_sha256 ( ) ) ) { fprintf ( stderr , " " , __func__ ) ; goto cleanup_err ; } goto out ; cleanup_err : if ( x509 ) X509_free ( x509 ) ; x509 = NULL ; out : return x509 ; }
gen_signed_cert() - Generate an X509 cert with a public key
 @pkey: The public key to certify as an EVP_PKEY
 @cn: The IPv6 address (as a string) to assign to CN
gen_signed_cert () - Generate an X509 cert with a public key @pkey : The public key to certify as an EVP_PKEY @cn : The IPv6 address ( as a string ) to assign to CN
/* Set the public key for our certificate. */ /* We want to copy the subject name to the issuer name. */ /* Set the common name. */ /* Set the issuer name to the same value as the subject name */ /* Set the serial number to a random value */ /* Sign the cert */ /* Success! */