Skip to content

Commit b20bab9

Browse files
romanmichalvasko
roman
authored andcommitted
cli UPDATE remove CRL from file support
CRLs are now obtainable only through a x509 extension. Removed all mentions of the ability to configure a path to a CRL file.
1 parent 90f2c5f commit b20bab9

File tree

5 files changed

+7
-322
lines changed

5 files changed

+7
-322
lines changed

cli/README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ trusted store, or use the default directory. To add certificates
2121
to this directory, use the `cert add` command.
2222

2323
## Certificate Revocation Lists
24-
For netopeer-cli to check if a certificate was not revocated by
25-
its issuer, use the `crl add` command to provide
26-
CRLs of your trusted CAs for netopeer-cli.
24+
CRLs are automatically downloaded from URIs specified in the
25+
x509 CRLDistributionPoints extensions of set certificates.
26+
Be wary that if any configured certificate has this extension,
27+
then a CRL issued by the server's CA has to be present for the connection to succeed.
2728

2829
## Certificates
2930

cli/commands.c

Lines changed: 1 addition & 230 deletions
Original file line numberDiff line numberDiff line change
@@ -1284,12 +1284,6 @@ cmd_cert_help(void)
12841284
printf("cert [--help | display | add <cert_path> | remove <cert_name> | displayown | replaceown (<cert_path.pem> | <cert_path.crt> <key_path.key>)]\n");
12851285
}
12861286

1287-
static void
1288-
cmd_crl_help(void)
1289-
{
1290-
printf("crl [--help | display | add <crl_path> | remove <crl_name>]\n");
1291-
}
1292-
12931287
static int
12941288
cmd_auth(const char *arg, char **UNUSED(tmp_config_file))
12951289
{
@@ -1911,85 +1905,6 @@ parse_cert(const char *name, const char *path)
19111905
fclose(fp);
19121906
}
19131907

1914-
static void
1915-
parse_crl(const char *name, const char *path)
1916-
{
1917-
int i;
1918-
BIO *bio_out;
1919-
FILE *fp;
1920-
X509_CRL *crl;
1921-
const ASN1_INTEGER *bs;
1922-
X509_REVOKED *rev;
1923-
1924-
fp = fopen(path, "r");
1925-
if (fp == NULL) {
1926-
ERROR("parse_crl", "Unable to open \"%s\": %s", path, strerror(errno));
1927-
return;
1928-
}
1929-
crl = PEM_read_X509_CRL(fp, NULL, NULL, NULL);
1930-
if (crl == NULL) {
1931-
ERROR("parse_crl", "Unable to parse certificate: %s", path);
1932-
fclose(fp);
1933-
return;
1934-
}
1935-
1936-
bio_out = BIO_new_fp(stdout, BIO_NOCLOSE);
1937-
1938-
BIO_printf(bio_out, "-----%s-----\n", name);
1939-
1940-
BIO_printf(bio_out, "Issuer: ");
1941-
X509_NAME_print(bio_out, X509_CRL_get_issuer(crl), 0);
1942-
BIO_printf(bio_out, "\n");
1943-
1944-
BIO_printf(bio_out, "Last update: ");
1945-
#if OPENSSL_VERSION_NUMBER < 0x10100000L // < 1.1.0
1946-
ASN1_TIME_print(bio_out, X509_CRL_get_lastUpdate(crl));
1947-
#else
1948-
ASN1_TIME_print(bio_out, X509_CRL_get0_lastUpdate(crl));
1949-
#endif
1950-
BIO_printf(bio_out, "\n");
1951-
1952-
BIO_printf(bio_out, "Next update: ");
1953-
#if OPENSSL_VERSION_NUMBER < 0x10100000L // < 1.1.0
1954-
ASN1_TIME_print(bio_out, X509_CRL_get_nextUpdate(crl));
1955-
#else
1956-
ASN1_TIME_print(bio_out, X509_CRL_get0_nextUpdate(crl));
1957-
#endif
1958-
BIO_printf(bio_out, "\n");
1959-
1960-
BIO_printf(bio_out, "REVOKED:\n");
1961-
1962-
if ((rev = sk_X509_REVOKED_pop(X509_CRL_get_REVOKED(crl))) == NULL) {
1963-
BIO_printf(bio_out, "\tNone\n");
1964-
}
1965-
while (rev != NULL) {
1966-
#if OPENSSL_VERSION_NUMBER < 0x10100000L // < 1.1.0
1967-
bs = rev->serialNumber;
1968-
#else
1969-
bs = X509_REVOKED_get0_serialNumber(rev);
1970-
#endif
1971-
BIO_printf(bio_out, "\tSerial no.: ");
1972-
for (i = 0; i < bs->length; i++) {
1973-
BIO_printf(bio_out, "%02x", bs->data[i]);
1974-
}
1975-
1976-
BIO_printf(bio_out, " Date: ");
1977-
#if OPENSSL_VERSION_NUMBER < 0x10100000L // < 1.1.0
1978-
ASN1_TIME_print(bio_out, rev->revocationDate);
1979-
#else
1980-
ASN1_TIME_print(bio_out, X509_REVOKED_get0_revocationDate(rev));
1981-
#endif
1982-
BIO_printf(bio_out, "\n");
1983-
1984-
X509_REVOKED_free(rev);
1985-
rev = sk_X509_REVOKED_pop(X509_CRL_get_REVOKED(crl));
1986-
}
1987-
1988-
X509_CRL_free(crl);
1989-
BIO_vfree(bio_out);
1990-
fclose(fp);
1991-
}
1992-
19931908
static int
19941909
cmd_cert(const char *arg, char **UNUSED(tmp_config_file))
19951910
{
@@ -2255,140 +2170,6 @@ cmd_cert(const char *arg, char **UNUSED(tmp_config_file))
22552170
return EXIT_FAILURE;
22562171
}
22572172

2258-
static int
2259-
cmd_crl(const char *arg, char **UNUSED(tmp_config_file))
2260-
{
2261-
int ret;
2262-
char *args = strdupa(arg);
2263-
char *cmd = NULL, *ptr = NULL, *path, *dest = NULL;
2264-
char *crl_dir = NULL, *rehash_cmd = NULL;
2265-
DIR *dir = NULL;
2266-
struct dirent *d;
2267-
2268-
cmd = strtok_r(args, " ", &ptr);
2269-
cmd = strtok_r(NULL, " ", &ptr);
2270-
if (!cmd || !strcmp(cmd, "--help") || !strcmp(cmd, "-h")) {
2271-
cmd_crl_help();
2272-
2273-
} else if (!strcmp(cmd, "display")) {
2274-
int none = 1;
2275-
char *name;
2276-
2277-
if (!(crl_dir = get_default_CRL_dir(NULL))) {
2278-
ERROR("crl display", "Could not get the default CRL directory");
2279-
goto error;
2280-
}
2281-
2282-
dir = opendir(crl_dir);
2283-
while ((d = readdir(dir))) {
2284-
if (!strcmp(d->d_name + strlen(d->d_name) - 4, ".pem")) {
2285-
none = 0;
2286-
name = strdup(d->d_name);
2287-
name[strlen(name) - 4] = '\0';
2288-
if (asprintf(&path, "%s/%s", crl_dir, d->d_name) == -1) {
2289-
free(name);
2290-
break;
2291-
}
2292-
parse_crl(name, path);
2293-
free(name);
2294-
free(path);
2295-
}
2296-
}
2297-
closedir(dir);
2298-
if (none) {
2299-
printf("No CRLs found in the default CRL directory.\n");
2300-
}
2301-
2302-
} else if (!strcmp(cmd, "add")) {
2303-
path = strtok_r(NULL, " ", &ptr);
2304-
if (!path || (strlen(path) < 5)) {
2305-
ERROR("crl add", "Missing or wrong path to the certificate");
2306-
goto error;
2307-
}
2308-
if (eaccess(path, R_OK)) {
2309-
ERROR("crl add", "Cannot access certificate \"%s\": %s", path, strerror(errno));
2310-
goto error;
2311-
}
2312-
2313-
crl_dir = get_default_CRL_dir(NULL);
2314-
if (!crl_dir) {
2315-
ERROR("crl add", "Could not get the default CRL directory");
2316-
goto error;
2317-
}
2318-
2319-
if ((asprintf(&dest, "%s/%s", crl_dir, strrchr(path, '/') + 1) == -1) ||
2320-
(asprintf(&rehash_cmd, "openssl rehash %s &> /dev/null", crl_dir) == -1)) {
2321-
ERROR("crl add", "Memory allocation failed");
2322-
goto error;
2323-
}
2324-
2325-
if (strcmp(dest + strlen(dest) - 4, ".pem")) {
2326-
ERROR("crl add", "CRLs are expected to be in *.pem format");
2327-
strcpy(dest + strlen(dest) - 4, ".pem");
2328-
}
2329-
2330-
if (cp(dest, path)) {
2331-
ERROR("crl add", "Could not copy the CRL \"%s\": %s", path, strerror(errno));
2332-
goto error;
2333-
}
2334-
2335-
if (((ret = system(rehash_cmd)) == -1) || WEXITSTATUS(ret)) {
2336-
ERROR("crl add", "openssl rehash execution failed");
2337-
goto error;
2338-
}
2339-
2340-
} else if (!strcmp(cmd, "remove")) {
2341-
path = strtok_r(NULL, " ", &ptr);
2342-
if (!path) {
2343-
ERROR("crl remove", "Missing the certificate name");
2344-
goto error;
2345-
}
2346-
2347-
// delete ".pem" if the user unnecessarily included it
2348-
if ((strlen(path) > 4) && !strcmp(path + strlen(path) - 4, ".pem")) {
2349-
path[strlen(path) - 4] = '\0';
2350-
}
2351-
2352-
crl_dir = get_default_CRL_dir(NULL);
2353-
if (!crl_dir) {
2354-
ERROR("crl remove", "Could not get the default CRL directory");
2355-
goto error;
2356-
}
2357-
2358-
if ((asprintf(&dest, "%s/%s.pem", crl_dir, path) == -1) ||
2359-
(asprintf(&rehash_cmd, "openssl rehash %s &> /dev/null", crl_dir) == -1)) {
2360-
ERROR("crl remove", "Memory allocation failed");
2361-
goto error;
2362-
}
2363-
2364-
if (remove(dest)) {
2365-
ERROR("crl remove", "Cannot remove CRL \"%s\": %s (use the name from \"crl display\" output)",
2366-
path, strerror(errno));
2367-
goto error;
2368-
}
2369-
2370-
if (((ret = system(rehash_cmd)) == -1) || WEXITSTATUS(ret)) {
2371-
ERROR("crl remove", "openssl rehash execution failed");
2372-
goto error;
2373-
}
2374-
2375-
} else {
2376-
ERROR("crl", "Unknown argument %s", cmd);
2377-
goto error;
2378-
}
2379-
2380-
free(dest);
2381-
free(rehash_cmd);
2382-
free(crl_dir);
2383-
return EXIT_SUCCESS;
2384-
2385-
error:
2386-
free(dest);
2387-
free(rehash_cmd);
2388-
free(crl_dir);
2389-
return EXIT_FAILURE;
2390-
}
2391-
23922173
static int
23932174
cmd_connect_listen_tls(struct arglist *cmd, int is_connect)
23942175
{
@@ -2397,7 +2178,7 @@ cmd_connect_listen_tls(struct arglist *cmd, int is_connect)
23972178
DIR *dir = NULL;
23982179
struct dirent *d;
23992180
int c, n, timeout = 0, ret = EXIT_FAILURE;
2400-
char *cert = NULL, *key = NULL, *trusted_dir = NULL, *crl_dir = NULL;
2181+
char *cert = NULL, *key = NULL, *trusted_dir = NULL;
24012182
unsigned short port = 0;
24022183
int option_index = 0;
24032184
struct option long_options[] = {
@@ -2510,15 +2291,10 @@ cmd_connect_listen_tls(struct arglist *cmd, int is_connect)
25102291
goto error_cleanup;
25112292
}
25122293
}
2513-
if (!(crl_dir = get_default_CRL_dir(NULL))) {
2514-
ERROR(func_name, "Could not use the CRL directory.");
2515-
goto error_cleanup;
2516-
}
25172294

25182295
if (is_connect) {
25192296
nc_client_tls_set_cert_key_paths(cert, key);
25202297
nc_client_tls_set_trusted_ca_paths(trusted_store, trusted_dir);
2521-
nc_client_tls_set_crl_paths(NULL, crl_dir);
25222298

25232299
/* default port */
25242300
if (!port) {
@@ -2539,7 +2315,6 @@ cmd_connect_listen_tls(struct arglist *cmd, int is_connect)
25392315
} else {
25402316
nc_client_tls_ch_set_cert_key_paths(cert, key);
25412317
nc_client_tls_ch_set_trusted_ca_paths(trusted_store, trusted_dir);
2542-
nc_client_tls_ch_set_crl_paths(NULL, crl_dir);
25432318

25442319
/* default timeout */
25452320
if (!timeout) {
@@ -2575,7 +2350,6 @@ cmd_connect_listen_tls(struct arglist *cmd, int is_connect)
25752350

25762351
error_cleanup:
25772352
free(trusted_dir);
2578-
free(crl_dir);
25792353
free(cert);
25802354
free(key);
25812355
return ret;
@@ -6742,9 +6516,6 @@ COMMAND commands[] = {
67426516
{"commit", cmd_commit, cmd_commit_help, "ietf-netconf <commit> operation"},
67436517
{"connect", cmd_connect, cmd_connect_help, "Connect to a NETCONF server"},
67446518
{"copy-config", cmd_copyconfig, cmd_copyconfig_help, "ietf-netconf <copy-config> operation"},
6745-
#ifdef NC_ENABLED_SSH_TLS
6746-
{"crl", cmd_crl, cmd_crl_help, "Manage Certificate Revocation List directory"},
6747-
#endif
67486519
{"delete-config", cmd_deleteconfig, cmd_deleteconfig_help, "ietf-netconf <delete-config> operation"},
67496520
{"delete-sub", cmd_deletesub, cmd_deletesub_help, "ietf-subscribed-notifications <delete-subscription> operation"},
67506521
{"discard-changes", cmd_discardchanges, cmd_discardchanges_help, "ietf-netconf <discard-changes> operation"},

cli/completion.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,8 @@ complete_cmd(const char *buf, const char *hint, linenoiseCompletions *lc)
8383

8484
if (!strncmp(buf, "searchpath ", 11)
8585
#ifdef NC_ENABLED_SSH_TLS
86-
|| !strncmp(buf, "auth keys add ", 14) ||
87-
!strncmp(buf, "cert add ", 9) || !strncmp(buf, "cert remove ", 12) || !strncmp(buf, "cert replaceown ", 16) ||
88-
!strncmp(buf, "crl add ", 8) || !strncmp(buf, "crl remove ", 11)
86+
|| !strncmp(buf, "auth keys add ", 14) || !strncmp(buf, "cert add ", 9) ||
87+
!strncmp(buf, "cert remove ", 12) || !strncmp(buf, "cert replaceown ", 16)
8988
#endif
9089
) {
9190
linenoisePathCompletion(buf, hint, lc);

cli/configuration.c

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ struct cli_opts opts = {.output_format = LYD_XML};
4545
#define NCC_DIR ".netopeer2-cli"
4646
/* all these appended to NCC_DIR */
4747
#define CA_DIR "certs"
48-
#define CRL_DIR "crl"
4948
#define CERT_CRT "client.crt"
5049
#define CERT_PEM "client.pem"
5150
#define CERT_KEY "client.key"
@@ -200,50 +199,6 @@ get_default_trustedCA_dir(DIR **ret_dir)
200199
return cert_dir;
201200
}
202201

203-
char *
204-
get_default_CRL_dir(DIR **ret_dir)
205-
{
206-
char *netconf_dir, *crl_dir;
207-
208-
if (!(netconf_dir = get_netconf_dir())) {
209-
return NULL;
210-
}
211-
212-
if (asprintf(&crl_dir, "%s/%s", netconf_dir, CRL_DIR) == -1) {
213-
ERROR(__func__, "asprintf() failed (%s:%d).", __FILE__, __LINE__);
214-
ERROR(__func__, "Unable to use the trusted CA directory due to the previous error.");
215-
free(netconf_dir);
216-
return NULL;
217-
}
218-
free(netconf_dir);
219-
220-
if (ret_dir) {
221-
if (!(*ret_dir = opendir(crl_dir))) {
222-
ERROR(__func__, "Unable to open the default CRL directory (%s).", strerror(errno));
223-
}
224-
free(crl_dir);
225-
return NULL;
226-
}
227-
228-
errno = 0;
229-
if (eaccess(crl_dir, R_OK | W_OK | X_OK)) {
230-
if (errno == ENOENT) {
231-
ERROR(__func__, "Default CRL dir does not exist, creating it.");
232-
if (mkdir(crl_dir, 00777)) {
233-
ERROR(__func__, "Failed to create the default CRL directory (%s).", strerror(errno));
234-
free(crl_dir);
235-
return NULL;
236-
}
237-
} else {
238-
ERROR(__func__, "Unable to access the default CRL directory (%s).", strerror(errno));
239-
free(crl_dir);
240-
return NULL;
241-
}
242-
}
243-
244-
return crl_dir;
245-
}
246-
247202
void
248203
load_history(void)
249204
{

0 commit comments

Comments
 (0)