Lines Matching refs:req
664 static EVP_PKEY * php_openssl_generate_private_key(struct php_x509_request * req);
877 static int php_openssl_add_oid_section(struct php_x509_request * req) /* {{{ */ in php_openssl_add_oid_section() argument
884 str = php_openssl_conf_get_string(req->req_config, NULL, "oid_section"); in php_openssl_add_oid_section()
888 sktmp = NCONF_get_section(req->req_config, str); in php_openssl_add_oid_section()
907 #define PHP_SSL_REQ_INIT(req) memset(req, 0, sizeof(*req)) argument
908 #define PHP_SSL_REQ_DISPOSE(req) php_openssl_dispose_config(req) argument
909 #define PHP_SSL_REQ_PARSE(req, zval) php_openssl_parse_config(req, zval) argument
911 #define PHP_SSL_CONFIG_SYNTAX_CHECK(var) if (req->var && php_openssl_config_check_syntax(#var, \
912 req->config_filename, req->var, req->req_config) == FAILURE) return FAILURE
952 static int php_openssl_parse_config(struct php_x509_request * req, zval * optional_args) /* {{{ */ in php_openssl_parse_config() argument
957 SET_OPTIONAL_STRING_ARG("config", req->config_filename, default_ssl_conf_filename); in php_openssl_parse_config()
958 SET_OPTIONAL_STRING_ARG("config_section_name", req->section_name, "req"); in php_openssl_parse_config()
959 req->global_config = NCONF_new(NULL); in php_openssl_parse_config()
960 if (!NCONF_load(req->global_config, default_ssl_conf_filename, NULL)) { in php_openssl_parse_config()
964 req->req_config = NCONF_new(NULL); in php_openssl_parse_config()
965 if (!NCONF_load(req->req_config, req->config_filename, NULL)) { in php_openssl_parse_config()
970 str = php_openssl_conf_get_string(req->req_config, NULL, "oid_file"); in php_openssl_parse_config()
979 if (php_openssl_add_oid_section(req) == FAILURE) { in php_openssl_parse_config()
982 SET_OPTIONAL_STRING_ARG("digest_alg", req->digest_name, in php_openssl_parse_config()
983 php_openssl_conf_get_string(req->req_config, req->section_name, "default_md")); in php_openssl_parse_config()
984 SET_OPTIONAL_STRING_ARG("x509_extensions", req->extensions_section, in php_openssl_parse_config()
985 php_openssl_conf_get_string(req->req_config, req->section_name, "x509_extensions")); in php_openssl_parse_config()
986 SET_OPTIONAL_STRING_ARG("req_extensions", req->request_extensions_section, in php_openssl_parse_config()
987 php_openssl_conf_get_string(req->req_config, req->section_name, "req_extensions")); in php_openssl_parse_config()
988 SET_OPTIONAL_LONG_ARG("private_key_bits", req->priv_key_bits, in php_openssl_parse_config()
989 php_openssl_conf_get_number(req->req_config, req->section_name, "default_bits")); in php_openssl_parse_config()
990 SET_OPTIONAL_LONG_ARG("private_key_type", req->priv_key_type, OPENSSL_KEYTYPE_DEFAULT); in php_openssl_parse_config()
993 req->priv_key_encrypt = Z_TYPE_P(item) == IS_TRUE ? 1 : 0; in php_openssl_parse_config()
995 str = php_openssl_conf_get_string(req->req_config, req->section_name, "encrypt_rsa_key"); in php_openssl_parse_config()
997 str = php_openssl_conf_get_string(req->req_config, req->section_name, "encrypt_key"); in php_openssl_parse_config()
1000 req->priv_key_encrypt = 0; in php_openssl_parse_config()
1002 req->priv_key_encrypt = 1; in php_openssl_parse_config()
1006 if (req->priv_key_encrypt && in php_openssl_parse_config()
1017 req->priv_key_encrypt_cipher = cipher; in php_openssl_parse_config()
1020 req->priv_key_encrypt_cipher = NULL; in php_openssl_parse_config()
1024 if (req->digest_name == NULL) { in php_openssl_parse_config()
1025 req->digest_name = php_openssl_conf_get_string(req->req_config, req->section_name, "default_md"); in php_openssl_parse_config()
1027 if (req->digest_name != NULL) { in php_openssl_parse_config()
1028 if (strcmp(req->digest_name, "null") == 0) { in php_openssl_parse_config()
1029 req->digest = req->md_alg = EVP_md_null(); in php_openssl_parse_config()
1031 req->digest = req->md_alg = EVP_get_digestbyname(req->digest_name); in php_openssl_parse_config()
1034 if (req->md_alg == NULL) { in php_openssl_parse_config()
1035 req->md_alg = req->digest = EVP_sha1(); in php_openssl_parse_config()
1042 req->curve_name = NID_undef; in php_openssl_parse_config()
1045 req->curve_name = OBJ_sn2nid(Z_STRVAL_P(item)); in php_openssl_parse_config()
1046 if (req->curve_name == NID_undef) { in php_openssl_parse_config()
1054 str = php_openssl_conf_get_string(req->req_config, req->section_name, "string_mask"); in php_openssl_parse_config()
1066 static void php_openssl_dispose_config(struct php_x509_request * req) /* {{{ */ in php_openssl_dispose_config() argument
1068 if (req->priv_key) { in php_openssl_dispose_config()
1069 EVP_PKEY_free(req->priv_key); in php_openssl_dispose_config()
1070 req->priv_key = NULL; in php_openssl_dispose_config()
1072 if (req->global_config) { in php_openssl_dispose_config()
1073 NCONF_free(req->global_config); in php_openssl_dispose_config()
1074 req->global_config = NULL; in php_openssl_dispose_config()
1076 if (req->req_config) { in php_openssl_dispose_config()
1077 NCONF_free(req->req_config); in php_openssl_dispose_config()
1078 req->req_config = NULL; in php_openssl_dispose_config()
2919 static zend_result php_openssl_csr_make(struct php_x509_request * req, X509_REQ * csr, zval * dn, z… in php_openssl_csr_make() argument
2924 dn_sect = NCONF_get_string(req->req_config, req->section_name, "distinguished_name"); in php_openssl_csr_make()
2929 dn_sk = NCONF_get_section(req->req_config, dn_sect); in php_openssl_csr_make()
2934 attr_sect = php_openssl_conf_get_string(req->req_config, req->section_name, "attributes"); in php_openssl_csr_make()
2938 attr_sk = NCONF_get_section(req->req_config, attr_sect); in php_openssl_csr_make()
3071 if (!X509_REQ_set_pubkey(csr, req->priv_key)) { in php_openssl_csr_make()
3248 struct php_x509_request req; in PHP_FUNCTION() local
3269 PHP_SSL_REQ_INIT(&req); in PHP_FUNCTION()
3297 if (PHP_SSL_REQ_PARSE(&req, args) == FAILURE) { in PHP_FUNCTION()
3371 if (req.extensions_section) { in PHP_FUNCTION()
3375 X509V3_set_nconf(&ctx, req.req_config); in PHP_FUNCTION()
3376 if (!X509V3_EXT_add_nconf(req.req_config, &ctx, req.extensions_section, new_cert)) { in PHP_FUNCTION()
3383 if (!X509_sign(new_cert, priv_key, req.digest)) { in PHP_FUNCTION()
3400 PHP_SSL_REQ_DISPOSE(&req); in PHP_FUNCTION()
3415 struct php_x509_request req; in PHP_FUNCTION() local
3426 PHP_SSL_REQ_INIT(&req); in PHP_FUNCTION()
3428 if (PHP_SSL_REQ_PARSE(&req, args) == SUCCESS) { in PHP_FUNCTION()
3435 req.priv_key = php_openssl_pkey_from_zval(out_pkey_val, 0, NULL, 0, 2); in PHP_FUNCTION()
3437 if (req.priv_key == NULL) { in PHP_FUNCTION()
3438 php_openssl_generate_private_key(&req); in PHP_FUNCTION()
3441 if (req.priv_key == NULL) { in PHP_FUNCTION()
3446 if (php_openssl_csr_make(&req, csr, dn, attribs) == SUCCESS) { in PHP_FUNCTION()
3450 X509V3_set_nconf(&ext_ctx, req.req_config); in PHP_FUNCTION()
3453 if (req.request_extensions_section && !X509V3_EXT_REQ_add_nconf(req.req_config, in PHP_FUNCTION()
3454 &ext_ctx, req.request_extensions_section, csr)) in PHP_FUNCTION()
3457 …php_error_docref(NULL, E_WARNING, "Error loading extension section %s", req.request_extensions_sec… in PHP_FUNCTION()
3461 if (X509_REQ_sign(csr, req.priv_key, req.digest)) { in PHP_FUNCTION()
3475 &zkey_object, req.priv_key, /* is_private */ true); in PHP_FUNCTION()
3477 req.priv_key = NULL; /* make sure the cleanup code doesn't zap it! */ in PHP_FUNCTION()
3490 PHP_SSL_REQ_DISPOSE(&req); in PHP_FUNCTION()
3800 static EVP_PKEY * php_openssl_generate_private_key(struct php_x509_request * req) in php_openssl_generate_private_key() argument
3802 if (req->priv_key_bits < MIN_KEY_LENGTH) { in php_openssl_generate_private_key()
3804 MIN_KEY_LENGTH, req->priv_key_bits); in php_openssl_generate_private_key()
3808 int type = php_openssl_get_evp_pkey_type(req->priv_key_type); in php_openssl_generate_private_key()
3815 char *randfile = php_openssl_conf_get_string(req->req_config, req->section_name, "RANDFILE"); in php_openssl_generate_private_key()
3836 if (EVP_PKEY_CTX_set_dsa_paramgen_bits(ctx, req->priv_key_bits) <= 0) { in php_openssl_generate_private_key()
3844 if (EVP_PKEY_CTX_set_dh_paramgen_prime_len(ctx, req->priv_key_bits) <= 0) { in php_openssl_generate_private_key()
3852 if (req->curve_name == NID_undef) { in php_openssl_generate_private_key()
3857 if (EVP_PKEY_CTX_set_ec_paramgen_curve_nid(ctx, req->curve_name) <= 0 || in php_openssl_generate_private_key()
3895 if (type == EVP_PKEY_RSA && EVP_PKEY_CTX_set_rsa_keygen_bits(ctx, req->priv_key_bits) <= 0) { in php_openssl_generate_private_key()
3905 req->priv_key = key; in php_openssl_generate_private_key()
4807 struct php_x509_request req; in PHP_FUNCTION() local
4877 PHP_SSL_REQ_INIT(&req); in PHP_FUNCTION()
4879 if (PHP_SSL_REQ_PARSE(&req, args) == SUCCESS) { in PHP_FUNCTION()
4880 if (php_openssl_generate_private_key(&req)) { in PHP_FUNCTION()
4882 php_openssl_pkey_object_init(return_value, req.priv_key, /* is_private */ true); in PHP_FUNCTION()
4884 req.priv_key = NULL; in PHP_FUNCTION()
4887 PHP_SSL_REQ_DISPOSE(&req); in PHP_FUNCTION()
4894 struct php_x509_request req; in PHP_FUNCTION() local
4924 PHP_SSL_REQ_INIT(&req); in PHP_FUNCTION()
4926 if (PHP_SSL_REQ_PARSE(&req, args) == SUCCESS) { in PHP_FUNCTION()
4933 if (passphrase && req.priv_key_encrypt) { in PHP_FUNCTION()
4934 if (req.priv_key_encrypt_cipher) { in PHP_FUNCTION()
4935 cipher = req.priv_key_encrypt_cipher; in PHP_FUNCTION()
4956 PHP_SSL_REQ_DISPOSE(&req); in PHP_FUNCTION()
4966 struct php_x509_request req; in PHP_FUNCTION() local
4989 PHP_SSL_REQ_INIT(&req); in PHP_FUNCTION()
4991 if (PHP_SSL_REQ_PARSE(&req, args) == SUCCESS) { in PHP_FUNCTION()
4994 if (passphrase && req.priv_key_encrypt) { in PHP_FUNCTION()
4995 if (req.priv_key_encrypt_cipher) { in PHP_FUNCTION()
4996 cipher = req.priv_key_encrypt_cipher; in PHP_FUNCTION()
5021 PHP_SSL_REQ_DISPOSE(&req); in PHP_FUNCTION()