| 66 | */ |
| 67 | |
| 68 | int // O - 1 on success, 0 on failure |
| 69 | cupsMakeServerCredentials( |
| 70 | const char *path, // I - Path to keychain/directory |
| 71 | const char *common_name, // I - Common name |
| 72 | int num_alt_names, // I - Number of subject alternate names |
| 73 | const char **alt_names, // I - Subject Alternate Names |
| 74 | time_t expiration_date) // I - Expiration date |
| 75 | { |
| 76 | int result = 0; // Return value |
| 77 | EVP_PKEY *pkey; // Private key |
| 78 | RSA *rsa; // RSA key pair |
| 79 | X509 *cert; // Certificate |
| 80 | cups_lang_t *language; // Default language info |
| 81 | time_t curtime; // Current time |
| 82 | X509_NAME *name; // Subject/issuer name |
| 83 | ASN1_INTEGER *serial; // Serial number |
| 84 | ASN1_TIME *notBefore, // Initial date |
| 85 | *notAfter; // Expiration date |
| 86 | BIO *bio; // Output file |
| 87 | char temp[1024], // Temporary directory name |
| 88 | crtfile[1024], // Certificate filename |
| 89 | keyfile[1024]; // Private key filename |
| 90 | const char *common_ptr; // Pointer into common name |
| 91 | GENERAL_NAMES *gens; // Names for SubjectAltName certificate extension |
| 92 | |
| 93 | |
| 94 | DEBUG_printf(("cupsMakeServerCredentials(path=\"%s\", common_name=\"%s\", num_alt_names=%d, alt_names=%p, expiration_date=%d)", path, common_name, num_alt_names, alt_names, (int)expiration_date)); |
| 95 | |
| 96 | // Filenames... |
| 97 | if (!path) |
| 98 | path = http_default_path(temp, sizeof(temp)); |
| 99 | |
| 100 | if (!path || !common_name) |
| 101 | { |
| 102 | _cupsSetError(IPP_STATUS_ERROR_INTERNAL, strerror(EINVAL), 0); |
| 103 | return (0); |
| 104 | } |
| 105 | |
| 106 | http_make_path(crtfile, sizeof(crtfile), path, common_name, "crt"); |
| 107 | http_make_path(keyfile, sizeof(keyfile), path, common_name, "key"); |
| 108 | |
| 109 | // Create the encryption key... |
| 110 | DEBUG_puts("1cupsMakeServerCredentials: Creating key pair."); |
| 111 | |
| 112 | if ((rsa = RSA_generate_key(3072, RSA_F4, NULL, NULL)) == NULL) |
| 113 | { |
| 114 | _cupsSetError(IPP_STATUS_ERROR_INTERNAL, _("Unable to create key pair."), 1); |
| 115 | return (0); |
| 116 | } |
| 117 | |
| 118 | if ((pkey = EVP_PKEY_new()) == NULL) |
| 119 | { |
| 120 | RSA_free(rsa); |
| 121 | _cupsSetError(IPP_STATUS_ERROR_INTERNAL, _("Unable to create private key."), 1); |
| 122 | return (0); |
| 123 | } |
| 124 | |
| 125 | EVP_PKEY_assign_RSA(pkey, rsa); |
no test coverage detected