blob: d06502c010b01b086a59636c6c46f96019a37eef [file] [log] [blame]
Brian Waters13d96012017-12-08 16:53:31 -06001#
2# Software License Agreement (BSD License)
3#
4# Copyright (c) 2013, WIDE Project and NICT
5# All rights reserved.
6#
7# See LICENSE file from freeDiameter source package for more information.
8#
9
10include $(TOPDIR)/rules.mk
11
12PKG_NAME:=freeDiameter
13PKG_REV:=696
14PKG_VERSION:=r$(PKG_REV)
15PKG_RELEASE:=1
16
17PKG_SOURCE_PROTO:=hg
18PKG_SOURCE_VERSION:=$(PKG_REV)
19PKG_SOURCE_SUBDIR:=$(PKG_NAME)-$(PKG_VERSION)
20PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
21PKG_SOURCE_URL:=http://www.freediameter.net/hg/freeDiameter
22# PKG_MD5SUM:=
23
24PKG_FIXUP:=libtool
25PKG_INSTALL:=1
26
27include $(INCLUDE_DIR)/package.mk
28
29define Package/freeDiameter
30 SECTION:=freeDiameter
31 CATEGORY:=Network
32 TITLE:=freeDiameter
33 URL:=http://www.freediameter.net
34 DEPENDS:=+sctp +libgnutls +libpthread +kmod-ipv6
35endef
36
37define Package/freeDiameter-test
38 SECTION:=freeDiameter
39 CATEGORY:=Network
40 TITLE:=freeDiameter-test
41 URL:=http://www.freediameter.net
42 DEPENDS:=+freeDiameter
43endef
44
45define Package/freeDiameter/description
46 freeDiameter + RADIUS/Diameter gateway extension package.
47endef
48
49define Package/freeDiameter-test/description
50 The app_test.fdx extension for freeDiameter, useful only to perform some
51tests between freeDiameter peers (ping-like for Diameter).
52endef
53
54define Package/freeDiameter/conffiles
55/etc/freeDiameter/freeDiameter.conf
56/etc/freeDiameter/rgw.conf
57endef
58
59define Build/Configure
60 IN_OPENWRT=1 \
61 AR="$(TARGET_CROSS)ar" \
62 AS="$(TARGET_CC) -c $(TARGET_CFLAGS)" \
63 LD="$(TARGET_CROSS)ld" \
64 NM="$(TARGET_CROSS)nm" \
65 CC="$(TARGET_CC)" \
66 GCC="$(TARGET_CC)" \
67 CXX="$(TARGET_CROSS)g++" \
68 RANLIB="$(TARGET_CROSS)ranlib" \
69 STRIP="$(TARGET_CROSS)strip" \
70 OBJCOPY="$(TARGET_CROSS)objcopy" \
71 OBJDUMP="$(TARGET_CROSS)objdump" \
72 TARGET_CPPFLAGS="$(TARGET_CPPFLAGS)" \
73 TARGET_CFLAGS="$(TARGET_CFLAGS)" \
74 TARGET_LDFLAGS="$(TARGET_LDFLAGS)" \
75 cmake \
76 -DCMAKE_PREFIX_PATH:PATH=$(STAGING_DIR)/usr \
77 -DCMAKE_INSTALL_PREFIX:PATH=/usr \
78 -DDIAMID_IDNA_REJECT:BOOL=ON \
79 -DBUILD_TESTING:BOOL=OFF \
80 -DCMAKE_BUILD_TYPE:STRING=DebianPackage \
81 -DDEFAULT_CONF_PATH:PATH=/etc/freeDiameter \
82 -DBUILD_APP_RADGW:BOOL=ON \
83 -DBUILD_DBG_MONITOR:BOOL=ON \
84 -DBUILD_TEST_APP:BOOL=ON \
85 VERBOSE=1 \
86 $(PKG_BUILD_DIR)/CMakeLists.txt
87endef
88
89TARGET_LDFLAGS := -L$(STAGING_DIR)/usr/lib $(TARGET_LDFLAGS)
90define Package/freeDiameter/install
91 # binaries
92 $(INSTALL_DIR) $(1)/usr/bin
93 $(CP) \
94 $(PKG_INSTALL_DIR)/usr/bin/freeDiameterd* \
95 $(1)/usr/bin/
96 # libraries & extensions
97 $(INSTALL_DIR) $(1)/usr/lib/
98 $(CP) \
99 $(PKG_INSTALL_DIR)/usr/lib/* \
100 $(1)/usr/lib/
101 # Remove the test_app from the main package (see freeDiameter-test)
102 $(RM) $(1)/usr/lib/freeDiameter/test_app*
103
104 # configuration files
105 $(INSTALL_DIR) $(1)/etc/freeDiameter
106 $(INSTALL_CONF) \
107 $(PKG_BUILD_DIR)/doc/freediameter.conf.sample \
108 $(1)/etc/freeDiameter/freeDiameter.conf
109 $(SED) 's,TLS_Cred,#TLS_Cred,g' $(1)/etc/freeDiameter/freeDiameter.conf
110 echo "" >> $(1)/etc/freeDiameter/freeDiameter.conf
111 echo "### OPENWRT specific" >> $(1)/etc/freeDiameter/freeDiameter.conf
112 echo "TLS_Cred = \"/etc/freeDiameter/freeDiameter.pem\", \"/etc/freeDiameter/freeDiameter.key\";" \
113 >> $(1)/etc/freeDiameter/freeDiameter.conf
114 echo "TLS_CA = \"/etc/freeDiameter/freeDiameter.ca.pem\";" \
115 >> $(1)/etc/freeDiameter/freeDiameter.conf
116 echo "TLS_DH_File = \"/etc/freeDiameter/dh.pem\";" \
117 >> $(1)/etc/freeDiameter/freeDiameter.conf
118 echo "SCTP_streams = 3;" >> $(1)/etc/freeDiameter/freeDiameter.conf
119 echo "LoadExtension = \"dict_nasreq.fdx\";" >> $(1)/etc/freeDiameter/freeDiameter.conf
120 echo "LoadExtension = \"dict_eap.fdx\";" >> $(1)/etc/freeDiameter/freeDiameter.conf
121 echo "LoadExtension = \"app_radgw.fdx\":\"rgw.conf\";" \
122 >> $(1)/etc/freeDiameter/freeDiameter.conf
123 echo "# test_app.fdx provided in freeDiameter-test package:" \
124 >> $(1)/etc/freeDiameter/freeDiameter.conf
125 echo "# LoadExtension = \"test_app.fdx\";" >> $(1)/etc/freeDiameter/freeDiameter.conf
126 echo "## Add overrides below this point" >> $(1)/etc/freeDiameter/freeDiameter.conf
127
128
129 $(INSTALL_CONF) \
130 $(PKG_BUILD_DIR)/doc/app_radgw.conf.sample \
131 $(1)/etc/freeDiameter/rgw.conf
132 $(SED) 's,RGWX,#RGWX,g' $(1)/etc/freeDiameter/rgw.conf
133 echo "" >> $(1)/etc/freeDiameter/rgw.conf
134 echo "### OPENWRT specific" >> $(1)/etc/freeDiameter/rgw.conf
135 echo " RGWX = \"auth.rgwx\" : auth;" >> $(1)/etc/freeDiameter/rgw.conf
136 echo " RGWX = \"acct.rgwx\" : acct;" >> $(1)/etc/freeDiameter/rgw.conf
137 echo "" >> $(1)/etc/freeDiameter/rgw.conf
138 echo " cli = 127.0.0.1 / \"secret key\" ;" >> $(1)/etc/freeDiameter/rgw.conf
139 echo " auth_server_ip4 = 127.0.0.1;" >> $(1)/etc/freeDiameter/rgw.conf
140 echo " auth_server_ip6 = ::1 ;" >> $(1)/etc/freeDiameter/rgw.conf
141 echo " acct_server_ip4 = 127.0.0.1;" >> $(1)/etc/freeDiameter/rgw.conf
142 echo " acct_server_ip6 = ::1 ;" >> $(1)/etc/freeDiameter/rgw.conf
143endef
144
145define Package/freeDiameter-test/install
146 # Only the test_app extension
147 $(INSTALL_DIR) $(1)/usr/lib/freeDiameter/
148 $(CP) $(PKG_INSTALL_DIR)/usr/lib/freeDiameter/test_app* \
149 $(1)/usr/lib/freeDiameter/
150endef
151
152define Package/freeDiameter/postinst
153#!/bin/sh
154
155# Test if the configuration file contains the local identity already
156localid=`sed -n -r -e "s/^[[:space:]]*Identity[[:space:]]*=[[:space:]]*\"([^\"]*)\"[[:space:]]*;/\1/p" /etc/freeDiameter/freeDiameter.conf`
157if [ -z "$$localid" ]; then
158 # Ask for the local name
159 echo -n "Full name of your access point? (openwrt.localdomain) : "
160 read localid
161 if [ -z "$$localid" ]; then
162 localid="openwrt.localdomain"
163 fi
164 echo "Identity = \"$$localid\";" >> /etc/freeDiameter/freeDiameter.conf
165fi
166
167# Is there already a ConnectPeer directive?
168grep -q -E -e "^[[:space:]]*ConnectPeer[[:space:]]*=" /etc/freeDiameter/freeDiameter.conf
169if [ "$$?" -eq "1" ]; then
170 echo -n "Diameter Identity of your Diameter server: "
171 read serverid
172 if [ -z "$$serverid" ]; then
173 echo "Skipped. Please add ConnectPeer directive to your /etc/freeDiameter/freeDiameter.conf file later."
174 else
175 echo -n "IP or IPv6 address of your Diameter server? (leave blank for dynamic resolution) "
176 read serverip
177 connstr=""
178 if [ -n "$$serverip" ]; then
179 connstr=" { ConnectTo = \"$$serverip\"; }"
180 fi
181 echo "ConnectPeer = \"$$serverid\"$$connstr;" >> /etc/freeDiameter/freeDiameter.conf
182 fi
183fi
184
185# Certificate configuration
186if [ ! -f "/usr/bin/certtool" ]; then
187 echo "certtool is not installed, skipping creation of default certificate and DH parameters."
188 echo "The following files are expected by freeDiameter:"
189 echo " /etc/freeDiameter/freeDiameter.key"
190 echo " /etc/freeDiameter/freeDiameter.pem"
191 echo " /etc/freeDiameter/freeDiameter.ca.pem"
192 echo " /etc/freeDiameter/dh.pem"
193 exit 0
194fi
195if [ ! -f "/etc/freeDiameter/freeDiameter.key" ]; then
196 echo "Creating a new private key for freeDiameter, please wait"
197 certtool -p --outfile /etc/freeDiameter/freeDiameter.key
198fi
199if [ ! -f "/etc/freeDiameter/freeDiameter.pem" ]; then
200 echo "organization = freeDiameter" > /tmp/template.cnf
201 echo "unit = OpenWRT" >>/tmp/template.cnf
202 echo "state = internet" >>/tmp/template.cnf
203 echo "country = net" >>/tmp/template.cnf
204 echo "cn = $$localid" >>/tmp/template.cnf
205 echo "expiration_days = 3650" >>/tmp/template.cnf
206 echo "signing_key" >>/tmp/template.cnf
207 echo "encryption_key" >>/tmp/template.cnf
208 if [ ! -f "/etc/freeDiameter/freeDiameter.csr" ]; then
209 echo "Creating a new CSR (use if you have a separate CA)"
210 certtool -q --load-privkey /etc/freeDiameter/freeDiameter.key \
211 --outfile /etc/freeDiameter/freeDiameter.csr \
212 --template /tmp/template.cnf
213 fi
214 echo "Creating a new certificate for freeDiameter"
215 certtool -s --load-privkey /etc/freeDiameter/freeDiameter.key \
216 --outfile /etc/freeDiameter/freeDiameter.pem \
217 --template /tmp/template.cnf
218 rm -f /tmp/template.cnf
219 cat /etc/freeDiameter/freeDiameter.pem >> /etc/freeDiameter/freeDiameter.ca.pem
220 echo "Done."
221 echo "========================================================================"
222 echo "To enable TLS communication, you should either:"
223 echo " - use a real certificate signed by your server's CA:"
224 echo " Use the CSR provided in /etc/freeDiameter/freeDiameter.csr"
225 echo " Save the new certificate as /etc/freeDiameter/freeDiameter.pem"
226 echo " Replace the contents of /etc/freeDiameter/freeDiameter.ca.pem with your CA's certificate"
227 echo " - or, declare the certificates as trusted as follow: "
228 echo " Add your server's CA certificate into /etc/freeDiameter/freeDiameter.ca.pem"
229 echo " Add the content of /etc/freeDiameter/freeDiameter.pem into your server's trusted CA file"
230 echo "========================================================================"
231fi
232if [ ! -f "/etc/freeDiameter/dh.pem" ]; then
233 echo "Creating new Diffie-Hellman parameters file. This operation takes a while..."
234 certtool --generate-dh-params --outfile /etc/freeDiameter/dh.pem
235 echo "Done."
236fi
237echo "freeDiameter configuration completed and stored in /etc/freeDiameter/."
238endef
239
240$(eval $(call BuildPackage,freeDiameter))
241$(eval $(call BuildPackage,freeDiameter-test))