362
362
* cert object, also contains the char table where
363
363
* the cert object is to be stored
365
* @return 0 if ok -1 if error
367
367
static int cert_spki_build_cert(struct hip_cert_spki_info *minimal_content)
370
369
char needed[] = "(cert )";
371
370
memset(minimal_content->public_key, '\0', sizeof(minimal_content->public_key));
372
371
memset(minimal_content->cert, '\0', sizeof(minimal_content->cert));
373
372
memset(minimal_content->signature, '\0', sizeof(minimal_content->signature));
374
373
sprintf(minimal_content->cert, "%s", needed);
396
395
tmp_cert = calloc(1, strlen(to->cert) + strlen(what) + 1);
400
399
/* Compiling the regular expression */
401
400
HIP_IFEL(regcomp(&re, after, REG_EXTENDED), -1,
584
583
int hip_cert_spki_char2certinfo(char *from, struct hip_cert_spki_info *to)
586
int err = 0, start = 0, stop = 0;
585
int start = 0, stop = 0;
588
587
* p_rule looks for string "(public_key " after which there can be
589
588
* pretty much anything until string "|)))" is encountered.
604
603
char s_rule[] = "[(]signature [ A-Za-z0-9+/|()=]*[|][)][)]";
606
605
/* Look for the public key */
607
HIP_IFEL(hip_cert_regex(p_rule, from, &start, &stop), -1,
608
"Failed to run hip_cert_regex (public-key)\n");
606
if (hip_cert_regex(p_rule, from, &start, &stop)) {
607
HIP_ERROR("Failed to run hip_cert_regex (public-key)\n");
609
610
snprintf(to->public_key, stop - start + 1, "%s", &from[start]);
611
612
/* Look for the cert sequence */
612
613
start = stop = 0;
613
HIP_IFEL(hip_cert_regex(c_rule, from, &start, &stop), -1,
614
"Failed to run hip_cert_regex (cert)\n");
614
if (hip_cert_regex(c_rule, from, &start, &stop)) {
615
HIP_ERROR("Failed to run hip_cert_regex (cert)\n");
615
618
snprintf(to->cert, stop - start + 1, "%s", &from[start]);
617
620
/* look for the signature sequence */
618
621
start = stop = 0;
619
HIP_IFEL(hip_cert_regex(s_rule, from, &start, &stop), -1,
620
"Failed to run hip_cert_regex (signature)\n");
622
if (hip_cert_regex(s_rule, from, &start, &stop)) {
623
HIP_ERROR("Failed to run hip_cert_regex (signature)\n");
621
626
snprintf(to->signature, stop - start + 1, "%s", &from[start]);
640
644
struct hip_common *msg;
641
645
const struct hip_cert_spki_info *returned;
643
HIP_IFEL(!(msg = malloc(HIP_MAX_PACKET)), -1,
644
"Malloc for msg failed\n");
647
if (!(msg = malloc(HIP_MAX_PACKET))) {
648
HIP_ERROR("Malloc for msg failed\n");
645
651
hip_msg_init(msg);
646
652
/* build the msg to be sent to the daemon */
647
653
HIP_IFEL(hip_build_user_hdr(msg, HIP_MSG_CERT_SPKI_VERIFY, 0), -1,
686
692
struct hip_common *msg;
687
693
const struct hip_cert_x509_resp *p;
689
HIP_IFEL(!(msg = malloc(HIP_MAX_PACKET)), -1,
690
"Malloc for msg failed\n");
695
if (!(msg = malloc(HIP_MAX_PACKET))) {
696
HIP_ERROR("Malloc for msg failed\n");
691
699
hip_msg_init(msg);
692
700
/* build the msg to be sent to the daemon */
727
735
struct hip_common *msg;
728
736
const struct hip_cert_x509_resp *received;
730
HIP_IFEL(!(msg = malloc(HIP_MAX_PACKET)), -1,
731
"Malloc for msg failed\n");
738
if (!(msg = malloc(HIP_MAX_PACKET))) {
739
HIP_ERROR("Malloc for msg failed\n");
732
742
hip_msg_init(msg);
734
744
/* build the msg to be sent to the daemon */
773
783
* the conf with NCONF_free().
776
STACK_OF(CONF_VALUE) * hip_cert_read_conf_section(const char *section_name,
786
STACK_OF(CONF_VALUE) *hip_cert_read_conf_section(const char *section_name,
780
STACK_OF(CONF_VALUE) * sec = NULL;
790
STACK_OF(CONF_VALUE) *sec = NULL;
782
792
/* XXTODO conf is opened and reopened here why -Samu */
783
793
conf = NCONF_new(NCONF_default());
784
HIP_IFEL(!NCONF_load(conf, HIP_CERT_CONF_PATH, &err),
785
-1, "Error opening the configuration file");
787
HIP_IFEL(!(sec = NCONF_get_section(conf, section_name)), -1,
788
"Section %s was not in the configuration (%s)\n",
789
section_name, HIP_CERT_CONF_PATH);
794
if (!NCONF_load(conf, HIP_CERT_CONF_PATH, &err)) {
795
HIP_ERROR("Error opening the configuration file");
798
if (!(sec = NCONF_get_section(conf, section_name))) {
799
HIP_ERROR("Section %s was not in the configuration (%s)\n",
800
section_name, HIP_CERT_CONF_PATH);
806
815
CONF *conf = NULL;
808
817
conf = NCONF_new(NCONF_default());
809
HIP_IFEL(!NCONF_load(conf, HIP_CERT_CONF_PATH, &err),
810
-1, "Error opening the configuration file");
818
if (!NCONF_load(conf, HIP_CERT_CONF_PATH, &err)) {
819
HIP_ERROR("Error opening the configuration file");
836
843
*start = *stop = 0;
838
845
/* Compiling the regular expression */
839
HIP_IFEL(regcomp(&re, what, REG_EXTENDED), -1,
840
"Compilation of the regular expression failed\n");
846
if (regcomp(&re, what, REG_EXTENDED)) {
847
HIP_ERROR("Compilation of the regular expression failed\n");
841
850
/* Running the regular expression */
842
851
// TODO this might need to be an error!?
843
852
// this needs to be separated to found, not found, and error -Samu