Crypt-LibSCEP

 view release on metacpan or  search on metacpan

LibSCEP.xs  view on Meta::CPAN

    }
    if(config->handle->configuration->params) {
        config->handle->configuration->params = NULL;
    }
    err:return;
        free(engine_config);
        create_err_msg(config, NULL);
}


EVP_PKEY *load_key(char *key_str, Conf *config) {
    EVP_PKEY *key = NULL;
    BIO *b = NULL;

    if (! config)
      Perl_croak(aTHX_ "*** Internal error: missing config");

    if (! (config->handle && config->handle->configuration))
      create_err_msg(config, "*** Internal error: missing config handle configuration");

    if(config->handle->configuration->engine == NULL) {
        b = BIO_new(BIO_s_mem());
        if(b == NULL) {
            scep_log(config->handle, ERROR, "Memory allocation failure for BIO");
            create_err_msg(config, NULL);
        }
        if(!BIO_write(b, key_str, strlen(key_str))) {
            scep_log(config->handle, ERROR, "Could not write to BIO");
            goto err;
        }
        char *pwd = NULL;
        if(!strcmp(config->passin, "env")) {
            pwd = getenv("pwd");
            if (pwd == NULL) {
                scep_log(config->handle, ERROR, "env:pwd not set");
                goto err;
            }
        }
        else if(!strcmp(config->passin, "pass")) {
            pwd = config->passwd;
            if(pwd == NULL) {
                scep_log(config->handle, ERROR, "pass set but no password provided");
                goto err;
            }
        }
        else if (!strcmp(config->passin, "plain")) {
            pwd = "";
        }
        else {
            scep_log(config->handle, ERROR, "unsupported pass format");
            goto err;
        }
        if(!(key = PEM_read_bio_PrivateKey(b, NULL, 0, pwd))) {
            scep_log(config->handle, ERROR, "Reading private key failed");
            goto err;
        }
        BIO_free(b);
    }
    else {
        //we got an engine
        if(!(key = ENGINE_load_private_key(config->handle->configuration->engine, key_str, NULL, NULL))) {
            scep_log(config->handle, ERROR, "Loading private key from engine failed");
            create_err_msg(config, NULL);
        }
    }
    return key;
    err:
        BIO_free(b);
        EVP_PKEY_free(key);
        create_err_msg(config, NULL);
    return NULL;
}


X509_CRL *
str2crl (Conf *config, char *str, BIO *b) {
    X509_CRL *c = NULL;
    if (! config)
      Perl_croak(aTHX_ "*** Internal error: missing config");

    if (! config->handle)
      create_err_msg(config, "*** Internal error: missing config handle");

    if(BIO_write(b, str, strlen(str)) <= 0) {
        scep_log(config->handle, ERROR, "Could not write CRL to BIO");
        BIO_free(b);
        create_err_msg(config, NULL);
    }
    c = PEM_read_bio_X509_CRL(b, NULL, 0, 0);
    if(c == NULL) {
        scep_log(config->handle, ERROR, "Could not read CRL");
        BIO_free(b);
        create_err_msg(config, NULL);
    }
    (void)BIO_reset(b);
    return c;
}


X509_REQ *
str2req (Conf *config, char *str, BIO *b) {
    X509_REQ *c = NULL;
    if (! config)
      Perl_croak(aTHX_ "*** Internal error: missing config");

    if (! config->handle)
      create_err_msg(config, "*** Internal error: missing config handle");

    if(BIO_write(b, str, strlen(str)) <= 0) {
        scep_log(config->handle, ERROR, "Could not write REQ to BIO");
        BIO_free(b);
        create_err_msg(config, NULL);
    }
    c = PEM_read_bio_X509_REQ(b, NULL, 0, 0);
    if(c == NULL) {
        scep_log(config->handle, ERROR, "Could not read REQ");
        BIO_free(b);
        create_err_msg(config, NULL);
    }
    (void)BIO_reset(b);
    return c;

 view all matches for this distribution
 view release on metacpan -  search on metacpan

( run in 0.655 second using v1.00-cache-2.02-grep-82fe00e-cpan-2cc899e4a130 )