Skip to content

Commit 3e28bcf

Browse files
Roytakmichalvasko
authored andcommitted
server config UPDATE allow unsupported keys
Do not fail when an unsupported key format is encountered. Instead just possibly fail if it were to be used. Fixes #563
1 parent 329e991 commit 3e28bcf

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/server_config.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -744,8 +744,10 @@ config_pubkey_format(const struct lyd_node *node, enum nc_operation parent_op, s
744744
} else if (!strcmp(format, "subject-public-key-info-format")) {
745745
pubkey->type = NC_PUBKEY_FORMAT_X509;
746746
} else {
747-
ERR(NULL, "Unknown public key format \"%s\".", format);
748-
return 1;
747+
/* do not fail, the key may still be usable, or it may have come from a keystore/truststore
748+
* and have a different purpose other than NETCONF */
749+
WRN(NULL, "Public key format \"%s\" not supported. The key may not be usable.", format);
750+
pubkey->type = NC_PUBKEY_FORMAT_UNKNOWN;
749751
}
750752
}
751753

@@ -794,8 +796,10 @@ config_privkey_format(const struct lyd_node *node, enum nc_operation parent_op,
794796
} else if (!strcmp(format, "openssh-private-key-format")) {
795797
privkey->type = NC_PRIVKEY_FORMAT_OPENSSH;
796798
} else {
797-
ERR(NULL, "Unknown private key format \"%s\".", format);
798-
return 1;
799+
/* do not fail, the key may still be usable, or it may have come from a keystore/truststore
800+
* and have a different purpose other than NETCONF */
801+
WRN(NULL, "Private key format \"%s\" not supported. The key may not be usable.", format);
802+
privkey->type = NC_PRIVKEY_FORMAT_UNKNOWN;
799803
}
800804
}
801805

tests/test_config.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -786,6 +786,8 @@ test_config_all_nodes(void **state)
786786
ret = nc_server_config_setup_diff(dup);
787787
assert_int_equal(ret, 0);
788788

789+
free(mem);
790+
free(mem_filled);
789791
lyd_free_all(dup);
790792
lyd_free_all(tree);
791793
}
@@ -968,6 +970,7 @@ main(void)
968970
cmocka_unit_test_setup_teardown(test_preserve_conn, setup_f, ln2_glob_test_teardown),
969971
cmocka_unit_test_setup_teardown(test_transport_params_oper_get, setup_f, ln2_glob_test_teardown),
970972
cmocka_unit_test_setup_teardown(test_config_all_nodes, setup_f, ln2_glob_test_teardown),
973+
cmocka_unit_test_setup_teardown(test_unusupported_asymkey_format, setup_f, ln2_glob_test_teardown),
971974
};
972975

973976
/* try to get ports from the environment, otherwise use the default */

0 commit comments

Comments
 (0)