1 /* $KAME: cfparse.y,v 1.111 2001/12/31 20:13:40 thorpej Exp $ */
7 #include <sys/socket.h>
9 #include <netinet/in.h>
10 #include <netinet6/ipsec.h>
11 #include <netkey/key_var.h>
18 #if !defined(HAVE_GETADDRINFO) || !defined(HAVE_GETNAMEINFO)
30 /*#include "cfparse.h"*/
32 #include "algorithm.h"
33 #include "localconf.h"
38 #include "remoteconf.h"
39 #include "grabmyaddr.h"
40 #include "isakmp_var.h"
43 #include "ipsec_doi.h"
52 time_t lifetime; /* for isakmp/ipsec */
53 int lifebyte; /* for isakmp/ipsec */
54 struct secprotospec *spspec; /* the head is always current spec. */
55 struct proposalspec *next; /* the tail is the most prefered. */
56 struct proposalspec *prev;
62 int strength; /* for isakmp/ipsec */
63 int encklen; /* for isakmp/ipsec */
64 time_t lifetime; /* for isakmp */
65 int lifebyte; /* for isakmp */
66 int proto_id; /* for ipsec (isakmp?) */
67 int ipsec_level; /* for ipsec */
68 int encmode; /* for ipsec */
69 int vendorid; /* for isakmp */
71 struct sockaddr *remote;
72 int algclass[MAXALGCLASS];
74 struct secprotospec *next; /* the tail is the most prefiered. */
75 struct secprotospec *prev;
76 struct proposalspec *back;
79 static int num2dhgroup[] = {
81 OAKLEY_ATTR_GRP_DESC_MODP768,
82 OAKLEY_ATTR_GRP_DESC_MODP1024,
83 OAKLEY_ATTR_GRP_DESC_EC2N155,
84 OAKLEY_ATTR_GRP_DESC_EC2N185,
85 OAKLEY_ATTR_GRP_DESC_MODP1536,
88 static struct remoteconf *cur_rmconf;
89 static int tmpalgtype[MAXALGCLASS];
90 static struct sainfo *cur_sainfo;
91 static int cur_algclass;
93 static struct proposalspec *prhead; /* the head is always current. */
95 static struct proposalspec *newprspec __P((void));
96 static void cleanprhead __P((void));
97 static void insprspec __P((struct proposalspec *, struct proposalspec **));
98 static struct secprotospec *newspspec __P((void));
99 static void insspspec __P((struct secprotospec *, struct proposalspec **));
101 static int set_isakmp_proposal
102 __P((struct remoteconf *, struct proposalspec *));
103 static void clean_tmpalgtype __P((void));
104 static int expand_isakmpspec __P((int, int, int *,
105 int, int, time_t, int, int, int, char *, struct remoteconf *));
108 static int fix_lifebyte __P((u_long));
115 struct remoteconf *rmconf;
116 struct sockaddr *saddr;
117 struct sainfoalg *alg;
124 /* self information */
125 %token IDENTIFIER VENDORID
127 %token LOGGING LOGLEV
129 %token PADDING PAD_RANDOMIZE PAD_RANDOMIZELEN PAD_MAXLEN PAD_STRICT PAD_EXCLTAIL
131 %token LISTEN X_ISAKMP X_ADMIN STRICT_ADDRESS
133 %token RETRY RETRY_COUNTER RETRY_INTERVAL RETRY_PERSEND
134 %token RETRY_PHASE1 RETRY_PHASE2
136 %token ALGORITHM_CLASS ALGORITHMTYPE STRENGTHTYPE
140 %token REMOTE ANONYMOUS
141 %token EXCHANGE_MODE EXCHANGETYPE DOI DOITYPE SITUATION SITUATIONTYPE
142 %token CERTIFICATE_TYPE CERTTYPE PEERS_CERTFILE VERIFY_CERT SEND_CERT SEND_CR
143 %token IDENTIFIERTYPE MY_IDENTIFIER PEERS_IDENTIFIER VERIFY_IDENTIFIER
144 %token DNSSEC CERT_X509
145 %token NONCE_SIZE DH_GROUP KEEPALIVE PASSIVE INITIAL_CONTACT
146 %token PROPOSAL_CHECK PROPOSAL_CHECK_LEVEL
147 %token GENERATE_POLICY SUPPORT_MIP6
149 %token EXEC_PATH EXEC_COMMAND EXEC_SUCCESS EXEC_FAILURE
151 %token COMPLEX_BUNDLE
153 %token PREFIX PORT PORTANY UL_PROTO ANY
154 %token PFS_GROUP LIFETIME LIFETYPE_TIME LIFETYPE_BYTE STRENGTH
156 %token NUMBER SWITCH BOOLEAN
157 %token HEXSTRING QUOTEDSTRING ADDRSTRING
158 %token UNITTYPE_BYTE UNITTYPE_KBYTES UNITTYPE_MBYTES UNITTYPE_TBYTES
159 %token UNITTYPE_SEC UNITTYPE_MIN UNITTYPE_HOUR
160 %token EOS BOC EOC COMMA
162 %type <num> NUMBER BOOLEAN SWITCH keylength
163 %type <num> PATHTYPE IDENTIFIERTYPE LOGLEV
164 %type <num> ALGORITHM_CLASS dh_group_num
165 %type <num> ALGORITHMTYPE STRENGTHTYPE
166 %type <num> PREFIX prefix PORT port ike_port
167 %type <num> ul_proto UL_PROTO
168 %type <num> EXCHANGETYPE DOITYPE SITUATIONTYPE
169 %type <num> CERTTYPE CERT_X509 PROPOSAL_CHECK_LEVEL
170 %type <num> unittype_time unittype_byte
171 %type <val> QUOTEDSTRING HEXSTRING ADDRSTRING sainfo_id
172 %type <val> identifierstring
173 %type <saddr> remote_index ike_addrinfo_port
174 %type <alg> algorithm
180 | statements statement
185 | identifier_statement
197 : PATH PATHTYPE QUOTEDSTRING
199 if ($2 > LC_PATHTYPE_MAX) {
200 yyerror("invalid path type %d", $2);
204 /* free old pathinfo */
205 if (lcconf->pathinfo[$2])
206 racoon_free(lcconf->pathinfo[$2]);
208 /* set new pathinfo */
209 lcconf->pathinfo[$2] = strdup($3->v);
217 : COMPLEX_BUNDLE SWITCH { lcconf->complex_bundle = $2; } EOS
222 : INCLUDE QUOTEDSTRING
224 char path[MAXPATHLEN];
226 getpathname(path, sizeof(path),
227 LC_PATHTYPE_INCLUDE, $2->v);
229 if (yycf_switch_buffer(path) != 0)
235 /* self infomation */
237 : IDENTIFIER identifier_stmt
242 /*XXX to be deleted */
245 | IDENTIFIERTYPE QUOTEDSTRING
247 /*XXX to be deleted */
248 $2->l--; /* nuke '\0' */
249 lcconf->ident[$1] = $2;
250 if (lcconf->ident[$1] == NULL) {
251 yyerror("failed to set my ident: %s",
261 : LOGGING log_level EOS
267 * XXX ignore it because this specification
270 yywarn("see racoon.conf(5), such a log specification will be obsoleted.");
276 * set the loglevel by configuration file only when
277 * the command line did not specify any loglevel.
279 if (loglevel <= LLV_BASE)
286 : PADDING BOC padding_stmts EOC
290 | padding_stmts padding_stmt
293 : PAD_RANDOMIZE SWITCH { lcconf->pad_random = $2; } EOS
294 | PAD_RANDOMIZELEN SWITCH { lcconf->pad_randomlen = $2; } EOS
295 | PAD_MAXLEN NUMBER { lcconf->pad_maxsize = $2; } EOS
296 | PAD_STRICT SWITCH { lcconf->pad_strict = $2; } EOS
297 | PAD_EXCLTAIL SWITCH { lcconf->pad_excltail = $2; } EOS
302 : LISTEN BOC listen_stmts EOC
306 | listen_stmts listen_stmt
309 : X_ISAKMP ike_addrinfo_port
315 yyerror("failed to allocate myaddrs");
319 if (p->addr == NULL) {
320 yyerror("failed to copy sockaddr ");
325 insmyaddr(p, &lcconf->myaddrs);
327 lcconf->autograbaddr = 0;
332 yyerror("admin directive is obsoleted.");
335 | STRICT_ADDRESS { lcconf->strict_address = TRUE; } EOS
338 : ADDRSTRING ike_port
342 snprintf(portbuf, sizeof(portbuf), "%ld", $2);
343 $$ = str2saddr($1->v, portbuf);
350 : /* nothing */ { $$ = PORT_ISAKMP; }
356 : RETRY BOC timer_stmts EOC
360 | timer_stmts timer_stmt
363 : RETRY_COUNTER NUMBER
365 lcconf->retry_counter = $2;
368 | RETRY_INTERVAL NUMBER unittype_time
370 lcconf->retry_interval = $2 * $3;
373 | RETRY_PERSEND NUMBER
375 lcconf->count_persend = $2;
378 | RETRY_PHASE1 NUMBER unittype_time
380 lcconf->retry_checkph1 = $2 * $3;
383 | RETRY_PHASE2 NUMBER unittype_time
385 lcconf->wait_ph2complete = $2 * $3;
394 cur_sainfo = newsainfo();
395 if (cur_sainfo == NULL) {
396 yyerror("failed to allocate sainfo");
400 sainfo_name BOC sainfo_specs
402 struct sainfo *check;
405 if (cur_sainfo->algs[algclass_ipsec_enc] == 0) {
406 yyerror("no encryption algorithm at %s",
407 sainfo2str(cur_sainfo));
410 if (cur_sainfo->algs[algclass_ipsec_auth] == 0) {
411 yyerror("no authentication algorithm at %s",
412 sainfo2str(cur_sainfo));
415 if (cur_sainfo->algs[algclass_ipsec_comp] == 0) {
416 yyerror("no compression algorithm at %s",
417 sainfo2str(cur_sainfo));
421 /* duplicate check */
422 check = getsainfo(cur_sainfo->idsrc, cur_sainfo->iddst);
423 if (check && (!check->idsrc && !cur_sainfo->idsrc)) {
424 yyerror("duplicated sainfo: %s",
425 sainfo2str(cur_sainfo));
428 inssainfo(cur_sainfo);
435 cur_sainfo->idsrc = NULL;
436 cur_sainfo->iddst = NULL;
438 | sainfo_id sainfo_id
440 cur_sainfo->idsrc = $1;
441 cur_sainfo->iddst = $2;
445 : IDENTIFIERTYPE ADDRSTRING prefix port ul_proto
448 struct sockaddr *saddr;
450 if (($5 == IPPROTO_ICMP || $5 == IPPROTO_ICMPV6)
451 && ($4 != IPSEC_PORT_ANY || $4 != IPSEC_PORT_ANY)) {
452 yyerror("port number must be \"any\".");
456 snprintf(portbuf, sizeof(portbuf), "%lu", $4);
457 saddr = str2saddr($2->v, portbuf);
462 switch (saddr->sa_family) {
464 if ($5 == IPPROTO_ICMPV6) {
465 yyerror("upper layer protocol mismatched.\n");
469 $$ = ipsecdoi_sockaddr2id(saddr,
470 $3 == ~0 ? (sizeof(struct in_addr) << 3): $3,
475 if ($5 == IPPROTO_ICMP) {
476 yyerror("upper layer protocol mismatched.\n");
480 $$ = ipsecdoi_sockaddr2id(saddr,
481 $3 == ~0 ? (sizeof(struct in6_addr) << 3) : $3,
486 yyerror("invalid family: %d", saddr->sa_family);
493 | IDENTIFIERTYPE QUOTEDSTRING
495 struct ipsecdoi_id_b *id_b;
497 if ($1 == IDTYPE_ASN1DN) {
498 yyerror("id type forbidden: %d", $1);
504 $$ = vmalloc(sizeof(*id_b) + $2->l);
506 yyerror("failed to allocate identifier");
510 id_b = (struct ipsecdoi_id_b *)$$->v;
511 id_b->type = idtype2doi($1);
516 memcpy($$->v + sizeof(*id_b), $2->v, $2->l);
521 | sainfo_specs sainfo_spec
524 : PFS_GROUP dh_group_num
526 cur_sainfo->pfs_group = $2;
529 | LIFETIME LIFETYPE_TIME NUMBER unittype_time
531 cur_sainfo->lifetime = $3 * $4;
534 | LIFETIME LIFETYPE_BYTE NUMBER unittype_byte
537 yyerror("byte lifetime support is deprecated");
540 cur_sainfo->lifebyte = fix_lifebyte($3 * $4);
541 if (cur_sainfo->lifebyte == 0)
550 | IDENTIFIER IDENTIFIERTYPE
552 yyerror("it's deprecated to specify a identifier in phase 2");
555 | MY_IDENTIFIER IDENTIFIERTYPE QUOTEDSTRING
557 yyerror("it's deprecated to specify a identifier in phase 2");
565 inssainfoalg(&cur_sainfo->algs[cur_algclass], $1);
569 inssainfoalg(&cur_sainfo->algs[cur_algclass], $1);
574 : ALGORITHMTYPE keylength
580 yyerror("failed to get algorithm alocation");
584 $$->alg = algtype2doi(cur_algclass, $1);
586 yyerror("algorithm mismatched");
591 defklen = default_keylen(cur_algclass, $1);
594 yyerror("keylen not allowed");
599 if ($2 && check_keylen(cur_algclass, $1, $2) < 0) {
600 yyerror("invalid keylen %d", $2);
609 $$->encklen = defklen;
611 /* check if it's supported algorithm by kernel */
612 if (!(cur_algclass == algclass_ipsec_auth && $1 == algtype_non_auth)
613 && pk_checkalg(cur_algclass, $1, $$->encklen)) {
614 int a = algclass2doi(cur_algclass);
615 int b = algtype2doi(cur_algclass, $1);
616 if (a == IPSECDOI_ATTR_AUTH)
617 a = IPSECDOI_PROTO_IPSEC_AH;
618 yyerror("algorithm %s not supported",
619 s_ipsecdoi_trns(a, b));
626 : /* nothing */ { $$ = ~0; }
627 | PREFIX { $$ = $1; }
630 : /* nothing */ { $$ = IPSEC_PORT_ANY; }
632 | PORTANY { $$ = IPSEC_PORT_ANY; }
635 : NUMBER { $$ = $1; }
636 | UL_PROTO { $$ = $1; }
637 | ANY { $$ = IPSEC_ULPROTO_ANY; }
640 : /* nothing */ { $$ = 0; }
641 | NUMBER { $$ = $1; }
646 : REMOTE remote_index
648 struct remoteconf *new;
649 struct proposalspec *prspec;
653 yyerror("failed to get new remoteconf.");
660 prspec = newprspec();
663 prspec->lifetime = oakley_get_defaultlifetime();
664 insprspec(prspec, &prhead);
668 /* check a exchange mode */
669 if (cur_rmconf->etypes == NULL) {
670 yyerror("no exchange mode specified.\n");
674 if (cur_rmconf->idvtype == IDTYPE_ASN1DN
675 && cur_rmconf->mycertfile == NULL) {
676 yyerror("id type mismatched due to "
677 "no CERT defined.\n");
681 if (set_isakmp_proposal(cur_rmconf, prhead) != 0)
684 /* DH group settting if aggressive mode is there. */
685 if (check_etypeok(cur_rmconf, ISAKMP_ETYPE_AGG) != NULL) {
690 for (p = cur_rmconf->proposal; p; p = p->next) {
691 if (b == 0 || (b && b == p->dh_group)) {
695 yyerror("DH group must be equal "
696 "to each proposals's "
697 "when aggressive mode is "
701 cur_rmconf->dh_group = b;
703 if (cur_rmconf->dh_group == 0) {
704 yyerror("DH group must be required.\n");
708 /* DH group settting if PFS is required. */
709 if (oakley_setdhgroup(cur_rmconf->dh_group,
710 &cur_rmconf->dhgrp) < 0) {
711 yyerror("failed to set DH value.\n");
716 insrmconf(cur_rmconf);
725 $$ = newsaddr(sizeof(struct sockaddr *));
726 $$->sa_family = AF_UNSPEC;
727 ((struct sockaddr_in *)$$)->sin_port = htons($2);
733 yyerror("failed to allocate sockaddr");
740 | remote_specs remote_spec
743 : EXCHANGE_MODE exchange_types EOS
744 | DOI DOITYPE { cur_rmconf->doitype = $2; } EOS
745 | SITUATION SITUATIONTYPE { cur_rmconf->sittype = $2; } EOS
746 | CERTIFICATE_TYPE cert_spec
747 | PEERS_CERTFILE QUOTEDSTRING
749 #ifdef HAVE_SIGNING_C
750 cur_rmconf->getcert_method = ISAKMP_GETCERT_LOCALFILE;
751 cur_rmconf->peerscertfile = strdup($2->v);
754 yyerror("directive not supported");
759 | PEERS_CERTFILE DNSSEC
761 #ifdef HAVE_SIGNING_C
762 cur_rmconf->getcert_method = ISAKMP_GETCERT_DNS;
763 cur_rmconf->peerscertfile = NULL;
765 yyerror("directive not supported");
770 | VERIFY_CERT SWITCH { cur_rmconf->verify_cert = $2; } EOS
771 | SEND_CERT SWITCH { cur_rmconf->send_cert = $2; } EOS
772 | SEND_CR SWITCH { cur_rmconf->send_cr = $2; } EOS
773 | IDENTIFIER IDENTIFIERTYPE
775 /*XXX to be deleted */
776 cur_rmconf->idvtype = $2;
779 | MY_IDENTIFIER IDENTIFIERTYPE identifierstring
781 if (set_identifier(&cur_rmconf->idv, $2, $3) != 0) {
782 yyerror("failed to set identifer.\n");
785 cur_rmconf->idvtype = $2;
788 | PEERS_IDENTIFIER IDENTIFIERTYPE identifierstring
790 if (set_identifier(&cur_rmconf->idv_p, $2, $3) != 0) {
791 yyerror("failed to set identifer.\n");
794 cur_rmconf->idvtype_p = $2;
797 | VERIFY_IDENTIFIER SWITCH { cur_rmconf->verify_identifier = $2; } EOS
798 | NONCE_SIZE NUMBER { cur_rmconf->nonce_size = $2; } EOS
801 yyerror("dh_group cannot be defined here.");
805 | KEEPALIVE { cur_rmconf->keepalive = TRUE; } EOS
806 | PASSIVE SWITCH { cur_rmconf->passive = $2; } EOS
807 | GENERATE_POLICY SWITCH { cur_rmconf->gen_policy = $2; } EOS
808 | SUPPORT_MIP6 SWITCH { cur_rmconf->support_mip6 = $2; } EOS
809 | INITIAL_CONTACT SWITCH { cur_rmconf->ini_contact = $2; } EOS
810 | PROPOSAL_CHECK PROPOSAL_CHECK_LEVEL { cur_rmconf->pcheck_level = $2; } EOS
811 | LIFETIME LIFETYPE_TIME NUMBER unittype_time
813 prhead->lifetime = $3 * $4;
816 | LIFETIME LIFETYPE_BYTE NUMBER unittype_byte
819 yyerror("byte lifetime support is deprecated");
822 yywarn("the lifetime of bytes in phase 1 "
823 "will be ignored at the moment.");
824 prhead->lifebyte = fix_lifebyte($3 * $4);
825 if (prhead->lifebyte == 0)
832 struct secprotospec *spspec;
834 spspec = newspspec();
837 insspspec(spspec, &prhead);
839 BOC isakmpproposal_specs EOC
843 | exchange_types EXCHANGETYPE
846 new = racoon_malloc(sizeof(struct etypes));
848 yyerror("filed to allocate etypes");
853 if (cur_rmconf->etypes == NULL)
854 cur_rmconf->etypes = new;
857 for (p = cur_rmconf->etypes;
866 : CERT_X509 QUOTEDSTRING QUOTEDSTRING
868 #ifdef HAVE_SIGNING_C
869 cur_rmconf->certtype = $1;
870 cur_rmconf->mycertfile = strdup($2->v);
872 cur_rmconf->myprivfile = strdup($3->v);
875 yyerror("directive not supported");
884 $$ = algtype2doi(algclass_isakmp_dh, $1);
886 yyerror("must be DH group");
892 if (ARRAYLEN(num2dhgroup) > $1 && num2dhgroup[$1] != 0) {
893 $$ = num2dhgroup[$1];
895 yyerror("must be DH group");
901 : /* nothing */ { $$ = NULL; }
902 | ADDRSTRING { $$ = $1; }
903 | QUOTEDSTRING { $$ = $1; }
907 | isakmpproposal_specs isakmpproposal_spec
912 yyerror("strength directive is obsoleted.");
914 | LIFETIME LIFETYPE_TIME NUMBER unittype_time
916 prhead->spspec->lifetime = $3 * $4;
919 | LIFETIME LIFETYPE_BYTE NUMBER unittype_byte
922 yyerror("byte lifetime support is deprecated");
925 prhead->spspec->lifebyte = fix_lifebyte($3 * $4);
926 if (prhead->spspec->lifebyte == 0)
931 | DH_GROUP dh_group_num
933 prhead->spspec->algclass[algclass_isakmp_dh] = $2;
936 | GSSAPI_ID QUOTEDSTRING
938 if (prhead->spspec->vendorid != VENDORID_GSSAPI) {
939 yyerror("wrong Vendor ID for gssapi_id");
942 prhead->spspec->gssid = strdup($2->v);
945 | ALGORITHM_CLASS ALGORITHMTYPE keylength
950 doi = algtype2doi($1, $2);
952 yyerror("algorithm mismatched 1");
957 case algclass_isakmp_enc:
958 /* reject suppressed algorithms */
959 #ifndef HAVE_OPENSSL_RC5_H
960 if ($2 == algtype_rc5) {
961 yyerror("algorithm %s not supported",
962 s_attr_isakmp_enc(doi));
966 #ifndef HAVE_OPENSSL_IDEA_H
967 if ($2 == algtype_idea) {
968 yyerror("algorithm %s not supported",
969 s_attr_isakmp_enc(doi));
974 prhead->spspec->algclass[algclass_isakmp_enc] = doi;
975 defklen = default_keylen($1, $2);
978 yyerror("keylen not allowed");
982 if ($3 && check_keylen($1, $2, $3) < 0) {
983 yyerror("invalid keylen %d", $3);
988 prhead->spspec->encklen = $3;
990 prhead->spspec->encklen = defklen;
992 case algclass_isakmp_hash:
993 prhead->spspec->algclass[algclass_isakmp_hash] = doi;
995 case algclass_isakmp_ameth:
996 prhead->spspec->algclass[algclass_isakmp_ameth] = doi;
998 * We may have to set the Vendor ID for the
999 * authentication method we're using.
1002 case algtype_gssapikrb:
1003 if (prhead->spspec->vendorid !=
1005 yyerror("Vendor ID mismatch "
1010 * For interoperability with Win2k,
1011 * we set the Vendor ID to "GSSAPI".
1013 prhead->spspec->vendorid =
1021 yyerror("algorithm mismatched 2");
1029 : UNITTYPE_SEC { $$ = 1; }
1030 | UNITTYPE_MIN { $$ = 60; }
1031 | UNITTYPE_HOUR { $$ = (60 * 60); }
1034 : UNITTYPE_BYTE { $$ = 1; }
1035 | UNITTYPE_KBYTES { $$ = 1024; }
1036 | UNITTYPE_MBYTES { $$ = (1024 * 1024); }
1037 | UNITTYPE_TBYTES { $$ = (1024 * 1024 * 1024); }
1041 static struct proposalspec *
1044 struct proposalspec *new;
1046 new = racoon_calloc(1, sizeof(*new));
1048 yyerror("failed to allocate proposal");
1056 struct proposalspec *p, *next;
1061 for (p = prhead; p != NULL; p = next) {
1070 * insert into head of list.
1073 insprspec(prspec, head)
1074 struct proposalspec *prspec;
1075 struct proposalspec **head;
1078 (*head)->prev = prspec;
1079 prspec->next = *head;
1083 static struct secprotospec *
1086 struct secprotospec *new;
1088 new = racoon_calloc(1, sizeof(*new));
1090 yyerror("failed to allocate spproto");
1094 new->encklen = 0; /*XXX*/
1097 * Default to "uknown" vendor -- we will override this
1098 * as necessary. When we send a Vendor ID payload, an
1099 * "unknown" will be translated to a KAME/racoon ID.
1101 new->vendorid = VENDORID_UNKNOWN;
1107 * insert into head of list.
1110 insspspec(spspec, head)
1111 struct secprotospec *spspec;
1112 struct proposalspec **head;
1114 spspec->back = *head;
1116 if ((*head)->spspec != NULL)
1117 (*head)->spspec->prev = spspec;
1118 spspec->next = (*head)->spspec;
1119 (*head)->spspec = spspec;
1122 /* set final acceptable proposal */
1124 set_isakmp_proposal(rmconf, prspec)
1125 struct remoteconf *rmconf;
1126 struct proposalspec *prspec;
1128 struct proposalspec *p;
1129 struct secprotospec *s;
1132 u_int32_t types[MAXALGCLASS];
1136 plog(LLV_ERROR, LOCATION, NULL,
1137 "multiple proposal definition.\n");
1141 /* mandatory check */
1142 if (p->spspec == NULL) {
1143 yyerror("no remote specification found: %s.\n",
1147 for (s = p->spspec; s != NULL; s = s->next) {
1148 /* XXX need more to check */
1149 if (s->algclass[algclass_isakmp_enc] == 0) {
1150 yyerror("encryption algorithm required.");
1153 if (s->algclass[algclass_isakmp_hash] == 0) {
1154 yyerror("hash algorithm required.");
1157 if (s->algclass[algclass_isakmp_dh] == 0) {
1158 yyerror("DH group required.");
1161 if (s->algclass[algclass_isakmp_ameth] == 0) {
1162 yyerror("authentication method required.");
1167 /* skip to last part */
1168 for (s = p->spspec; s->next != NULL; s = s->next)
1172 plog(LLV_DEBUG2, LOCATION, NULL,
1173 "lifetime = %ld\n", (long)
1174 (s->lifetime ? s->lifetime : p->lifetime));
1175 plog(LLV_DEBUG2, LOCATION, NULL,
1177 s->lifebyte ? s->lifebyte : p->lifebyte);
1178 plog(LLV_DEBUG2, LOCATION, NULL,
1179 "encklen=%d\n", s->encklen);
1181 memset(types, 0, ARRAYLEN(types));
1182 types[algclass_isakmp_enc] = s->algclass[algclass_isakmp_enc];
1183 types[algclass_isakmp_hash] = s->algclass[algclass_isakmp_hash];
1184 types[algclass_isakmp_dh] = s->algclass[algclass_isakmp_dh];
1185 types[algclass_isakmp_ameth] =
1186 s->algclass[algclass_isakmp_ameth];
1188 /* expanding spspec */
1190 trns_no = expand_isakmpspec(prop_no, trns_no, types,
1191 algclass_isakmp_enc, algclass_isakmp_ameth + 1,
1192 s->lifetime ? s->lifetime : p->lifetime,
1193 s->lifebyte ? s->lifebyte : p->lifebyte,
1194 s->encklen, s->vendorid, s->gssid,
1196 if (trns_no == -1) {
1197 plog(LLV_ERROR, LOCATION, NULL,
1198 "failed to expand isakmp proposal.\n");
1205 if (rmconf->proposal == NULL) {
1206 plog(LLV_ERROR, LOCATION, NULL,
1207 "no proposal found.\n");
1218 for (i = 0; i < MAXALGCLASS; i++)
1219 tmpalgtype[i] = 0; /* means algorithm undefined. */
1223 expand_isakmpspec(prop_no, trns_no, types,
1224 class, last, lifetime, lifebyte, encklen, vendorid, gssid,
1226 int prop_no, trns_no;
1227 int *types, class, last;
1233 struct remoteconf *rmconf;
1235 struct isakmpsa *new;
1241 plog(LLV_DEBUG2, LOCATION, NULL,
1242 "p:%d t:%d\n", prop_no, trns_no);
1243 for (j = class; j < MAXALGCLASS; j++) {
1244 snprintf(tb, sizeof(tb), "%d", types[j]);
1245 plog(LLV_DEBUG2, LOCATION, NULL,
1247 s_algtype(j, types[j]),
1248 types[j] ? "(" : "",
1249 tb[0] == '0' ? "" : tb,
1250 types[j] ? ")" : "");
1252 plog(LLV_DEBUG2, LOCATION, NULL, "\n");
1255 #define TMPALGTYPE2STR(n) \
1256 s_algtype(algclass_isakmp_##n, types[algclass_isakmp_##n])
1257 /* check mandatory values */
1258 if (types[algclass_isakmp_enc] == 0
1259 || types[algclass_isakmp_ameth] == 0
1260 || types[algclass_isakmp_hash] == 0
1261 || types[algclass_isakmp_dh] == 0) {
1262 yyerror("few definition of algorithm "
1263 "enc=%s ameth=%s hash=%s dhgroup=%s.\n",
1264 TMPALGTYPE2STR(enc),
1265 TMPALGTYPE2STR(ameth),
1266 TMPALGTYPE2STR(hash),
1267 TMPALGTYPE2STR(dh));
1270 #undef TMPALGTYPE2STR
1273 new = newisakmpsa();
1275 yyerror("failed to allocate isakmp sa");
1278 new->prop_no = prop_no;
1279 new->trns_no = trns_no++;
1280 new->lifetime = lifetime;
1281 new->lifebyte = lifebyte;
1282 new->enctype = types[algclass_isakmp_enc];
1283 new->encklen = encklen;
1284 new->authmethod = types[algclass_isakmp_ameth];
1285 new->hashtype = types[algclass_isakmp_hash];
1286 new->dh_group = types[algclass_isakmp_dh];
1287 new->vendorid = vendorid;
1289 if (gssid != NULL) {
1290 new->gssid = vmalloc(strlen(gssid) + 1);
1291 memcpy(new->gssid->v, gssid, new->gssid->l);
1296 insisakmpsa(new, rmconf);
1304 * Must be more than 1024B because its unit is kilobytes.
1305 * That is defined RFC2407.
1312 yyerror("byte size should be more than 1024B.");
1327 if (yycf_set_buffer(lcconf->racoon_conf) != 0)
1335 plog(LLV_ERROR, LOCATION, NULL,
1336 "fatal parse failure (%d errors)\n",
1339 plog(LLV_ERROR, LOCATION, NULL,
1340 "fatal parse failure.\n");
1345 if (error == 0 && yyerrorcount) {
1346 plog(LLV_ERROR, LOCATION, NULL,
1347 "parse error is nothing, but yyerrorcount is %d.\n",
1352 yycf_clean_buffer();
1354 plog(LLV_DEBUG2, LOCATION, NULL, "parse successed.\n");
1369 if (yycf_set_buffer(lcconf->racoon_conf) != 0)