beaglebone.txt 107KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544
  1. #+TITLE: FreedomBone
  2. #+AUTHOR: Bob Mottram
  3. #+EMAIL: bob@robotics.uk.to
  4. #+KEYWORDS: freedombox, debian, beaglebone, friendica, email, web server, home server, internet, censorship, surveillance, social network, irc, jabber, chat
  5. #+DESCRIPTION: Turn the Beaglebone Black into a personal communications server
  6. #+OPTIONS: ^:nil
  7. #+BEGIN_CENTER
  8. *How to turn the Beaglebone Black into a FreedomBox-like personal communications server*
  9. #+END_CENTER
  10. #+BEGIN_CENTER
  11. [[[[file:images/freedombone.jpg]]]]
  12. #+END_CENTER
  13. #+BEGIN_CENTER
  14. Copyright (C) 2014 Bob Mottram
  15. Permission is granted to copy, distribute and/or modify this document under the terms of the [[https://gnu.org/licenses/fdl.html][GNU Free Documentation License]], Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
  16. Source for this web site in [[https://en.wikipedia.org/wiki/Org-mode][Emacs org-mode]] format is available [[/beaglebone.txt][here]]. Comments or patches may be submitted via [[https://github.com/fuzzgun/freedombone][Github]].
  17. #+END_CENTER
  18. * Introduction
  19. #+BEGIN_VERSE
  20. /If you look at it from an engineering perspective, an iterative perspective, it’s clear that you have to try something rather than do nothing./
  21. -- Edward J. Snowden
  22. #+END_VERSE
  23. ** What is FreedomBone?
  24. Today many of us rely upon "free" services in the cloud, such as Gmail, Facebook, Google+ and so on. It might appear that these services are indispensible infrastructure of the modern internet, but actually they're not strictly needed and the amount of value which they deliver to the average internet user is very marginal. It is possible to be a citizen of the internet and yet not use those things - to disintermediate the most well known companies and cut out their prurient or merely cringeworthy business models.
  25. FreedomBone is a personal home communications server based upon the BeagleBone Black hardware. It's small and cheap and will allow you to use email, have your own web site and do social networking in a federated way without needing to rely upon any intermediary companies other than your ISP.
  26. ** Do I need any prior knowledge?
  27. In these instructions only a minimal level of familiarity with Linux is assumed. It's assumed that you know the basics of the /nano/ and /emacs/ editors, but it would be simple to also use other editors if you prefer.
  28. ** Why should I do this?
  29. You should consider doing this if you are a freedom-oriented sort of person and you want to maintain sovereignty over your information. Laws in many places in the world consider you to have relinquished any property rights over data which you put onto a server not owned by youself (i.e. owned by a third party, such as Google or Facebook).
  30. If you don't like the idea of having all your communications intercepted and investigated by the Surveillance State then you should consider running a FreedomBone. If your profession involves maintaining confidentiality as an essential feature, such as legal or medical services, counselling, teaching or any sort of activism then you should consider running a FreedomBone.
  31. As Eben Moglen noted in his now famous [[https://www.youtube.com/watch?v=QOEMv0S8AcA]["Freedom in The Cloud"]] talk the simple fact of you keeping your own internet logs (found in the /var/log directory) puts a certain amount of power in your hands and takes it away from parties who would otherwise sell that information without your knowledge or permission to advertisers or other shady outfits who may not have your best interests at heart.
  32. ** After it's installed will it need a lot of maintenance?
  33. So long as the hardware is ok the amount of maintenance needed should be very small. Unlike on Windows based systems you don't need to defragment drives or mess about with anti-virus programs. I ran a similar Sheevaplug system between 2010 and 2013 with only occasional software updates or reboots, and uptime was probably 99% or better.
  34. ** Is it secure?
  35. Nothing is totally secure or infallible. You could have the most secure technology and yet still use easy to guess passwords. This system will not defend you from an attacker who is actively trying to block or corrupt your communications, but I assume that doesn't apply in the majority of cases. Another thing to be aware of is that running a FreedomBone could make you more vulnerable to traffic analysis, since the server is associated with your home address and isn't a giant aggregation of users somewhere in the cloud. You need to weigh this alongside the additional legal protection which owning the server and having it in your own home gives you.
  36. FreedomBone should be far more secure than using popular cloud-based services which have spying built into them as a core feature (although not one which is typically advertised), but it is not necessarily an impenetrable information fortress.
  37. ** Will running a server all the time affect my electricity bill?
  38. Hardly at all. The BeagleBone Black consumes very little power - less than 5W. It would even be potentially possible to run it from a solar panel.
  39. * Inventory
  40. #+BEGIN_VERSE
  41. /You can’t help someone just by making a wish to do so, you have to take action./
  42. -- Dalai Lama
  43. #+END_VERSE
  44. These instructions assume that you have the following ingredients.
  45. ** A BeagleBone Black (BBB)
  46. It should come with a suitable USB cable for the initial setup. To make things look nicer you may also want to get a case for it.
  47. ** An internet connection
  48. It is assumed that the most common situation is via a router installed at home. The router should have ethernet sockets on it and a web interface which allows you to forward ports (sometimes under the "firewall" settings), so that you can forward ssh and web traffic to the BBB.
  49. ** microSD card
  50. To use as the main storage for the BBB. 16 or 32GB is fine, and can be obtained quite cheaply. Try to use Sandisk (class 10 or better) where possible and avoid cheaper cards which often have poor performance.
  51. You may also need an SD card adaptor or USB card reader in order to flash the operating image to the microSD card. For instance, many laptops have an SD card slot but not a microSD slot.
  52. ** 5V/1A power supply
  53. With a plug suitable for powering the BBB. If you have some device with a USB socket nearby you may also be able to just use that for electrical power. However, powering from the USB cable alone might result in crashes when the system is under load, depending upon how many milliamps can be supplied by the USB hub/socket. If the system crashes due to running out of power then you will see that the LEDs on the BBB are continuously on, rather than flashing.
  54. ** An ethernet patch cable
  55. Just an ordinary cat5 or cat6 cable that you can get from most electrical/computer stores.
  56. * Installing Debian onto the microSD card
  57. The Debian Linux OS will be installed onto a small flash drive. It's a good idea to do this rather than using the internal flash, because it will allow you to easily create backups of the entire system if necessary using the dd command.
  58. Download the image.
  59. #+BEGIN_SRC: bash
  60. cd ~/
  61. wget http://freedombone.uk.to/debian-7.2-console-armhf-2013-11-15.tar.xz
  62. #+END_SRC
  63. Verify it.
  64. #+BEGIN_SRC: bash
  65. md5sum debian-7.2-console-armhf-2013-11-15.tar.xz
  66. 0a448f55d14f64c5a7eb3d7cb2c54185 debian-7.2-console-armhf-2013-11-15.tar.xz
  67. #+END_SRC
  68. Uncompress it.
  69. #+BEGIN_SRC: bash
  70. tar xJf debian-7.2-console-armhf-2013-11-15.tar.xz
  71. cd debian-7.2-console-armhf-2013-11-15
  72. #+END_SRC
  73. Create the disk image, where sdX is the name of the flash drive (probably it will be sdb or sdc).
  74. #+BEGIN_SRC: bash
  75. sudo apt-get install u-boot-tools
  76. sudo ./setup_sdcard.sh --mmc /dev/sdX --uboot bone --swap-file 1024
  77. #+END_SRC
  78. Once completed then safely remove the microSD card via your file manager (usually right click and "safely remove" or "eject").
  79. * Setup
  80. #+BEGIN_VERSE
  81. /Build the tools for a future you would want to live in/
  82. -- Kurt Opsahl
  83. #+END_VERSE
  84. ** Things to be aware of
  85. *** A note on ssh
  86. When using ssh to log into the BBB if you get warnings of the type "/the ECDSA host key for domain differs from the key for the IP address/" then run the command:
  87. #+BEGIN_SRC: bash
  88. ssh-keygen -R <IP address>
  89. #+END_SRC
  90. *** Passwords
  91. It's highly recommended that you use a password manager, such as KeepassX, and make all your passwords long random strings. It's also a good idea to use different passwords for different pieces of software, instead of one or two passwords for the whole system. That compartmentalises the security such that even if an attacker gains access to one system they can't necessarily get access to others.
  92. ** Initial
  93. Plug the microSD card into the BBB and Connect the USB cable to your laptop/desktop, then login via ssh.
  94. #+BEGIN_SRC: bash
  95. ssh debian@192.168.7.2
  96. #+END_SRC
  97. The default password is /temppwd/
  98. Then log in as root:
  99. #+BEGIN_SRC: bash
  100. su
  101. #+END_SRC
  102. The default password is /root/
  103. The first thing to do is to change the passwords from their defaults.
  104. #+BEGIN_SRC: bash
  105. passwd
  106. #+END_SRC
  107. Then you will need to change the network interfaces. The main task here is to comment out the stuff related to usb0. That will enable you to plug the BBB into the back of a router and for it to be detectable on the network.
  108. #+BEGIN_SRC: bash
  109. nano /etc/network/interfaces
  110. #+END_SRC
  111. The resulting interfaces file should look like this:
  112. #+BEGIN_SRC: bash
  113. # This file describes the network interfaces available on your system
  114. # and how to activate them. For more information, see interfaces(5).
  115. # The loopback network interface
  116. auto lo
  117. iface lo inet loopback
  118. # The primary network interface
  119. allow-hotplug eth0
  120. iface eth0 inet static
  121. address 192.168.1.60
  122. netmask 255.255.255.0
  123. gateway 192.168.1.254
  124. dns-nameservers 213.73.91.35 85.214.20.141
  125. # Example to keep MAC address between reboots
  126. #hwaddress ether DA:AD:CE:EF:CA:FE
  127. # WiFi Example
  128. #auto wlan0
  129. #iface wlan0 inet dhcp
  130. # wpa-ssid "essid"
  131. # wpa-psk "password"
  132. # Ethernet/RNDIS gadget (g_ether)
  133. # ... or on host side, usbnet and random hwaddr
  134. # Note on some boards, usb0 is automaticly setup with an init script
  135. # in that case, to completely disable remove file [run_boot-scripts] from the boot partition
  136. #iface usb0 inet static
  137. # address 192.168.7.2
  138. # netmask 255.255.255.0
  139. # network 192.168.7.0
  140. # gateway 192.168.7.1
  141. #+END_SRC
  142. CTRL-O followed by ENTER to save, then CTRL-X to exit.
  143. In the above example "address 192.168.1.60" is a static IP address for the BBB, which will allow incoming network traffic to be directed from the router in a reliable manner. It should be outside of the DHCP range set up on the router.
  144. "gateway 192.168.1.254" should be the IP address of the router.
  145. Note that setting the DNS servers with dns-nameservers is important because some home routers do not allow you to change the DNS settings.
  146. Edit resolv.conf.
  147. #+BEGIN_SRC: bash
  148. nano /etc/resolv.conf
  149. #+END_SRC
  150. It should look something like the following:
  151. #+BEGIN_SRC: bash
  152. domain localdomain
  153. search localdomain
  154. nameserver 213.73.91.35
  155. nameserver 85.214.20.141
  156. #+END_SRC
  157. CTRL-O followed by ENTER to save, then CTRL-X to exit.
  158. Now disconnect the BBB from your computer and plug it into the router. You'll need an ethernet patch cable and you may also need a 5V/1A power supply for the BBB.
  159. If you go to the web administration screen for your internet router (often it's on 192.168.2.1 or 192.168.1.254) then after a few minutes you should see the BBB appear on the network. It's name will be "arm".
  160. ** Add a user
  161. Ssh back in to the BBB and login as root. In this example the BBB's IP address is 192.168.1.60.
  162. #+BEGIN_SRC: bash
  163. ssh-keygen -f "/home/myusername/.ssh/known_hosts" -R 192.168.1.60
  164. ssh debian@192.168.1.60
  165. su
  166. #+END_SRC
  167. Then make a new user. It's a bad idea to add users to the sudo group, because that then means that an attacker potentially only needs to know one password in order to get administrator access to the system. With no sudoers an attacker needs to know, or be able to obtain, two separate passwords to be able to really compromise the system.
  168. #+BEGIN_SRC: bash
  169. adduser myusername
  170. #+END_SRC
  171. Exit from the ssh login by typing "exit" a couple of times, then ssh back in as the new user. Make sure you use a difficult to guess password/phrase, or ideally a randomly generated password used together with a password manager such as KeepassX.
  172. Remove the default debian user.
  173. #+BEGIN_SRC: bash
  174. userdel -r debian
  175. #+END_SRC
  176. ** Text editor
  177. For an editor which is less erratic than vi when used within a remote console such as Terminator.
  178. #+BEGIN_SRC: bash
  179. apt-get update
  180. apt-get install emacs
  181. #+END_SRC
  182. Some basic Emacs keys which will be useful to new users are:
  183. | Load a file | CTRL-x CTRL-f |
  184. | Save | CTRL-x CTRL-s |
  185. | Exit | CTRL-x CTRL-c |
  186. ** Create a swap file
  187. Without a swap file the system may occasionally run out of memory and crash, since the Beaglebone only has 512MB of RAM. The following commands will create a 1GB swap file:
  188. #+BEGIN_SRC: bash
  189. mkdir -p /var/cache/swap/
  190. dd if=/dev/zero of=/var/cache/swap/swapfile bs=1M count=1024
  191. chmod 600 /var/cache/swap/swapfile
  192. mkswap /var/cache/swap/swapfile
  193. swapon /var/cache/swap/swapfile
  194. #+END_SRC
  195. To tell the OS to load this swapfile on each start up.
  196. #+BEGIN_SRC: bash
  197. emacs /etc/fstab
  198. #+END_SRC
  199. Append the following line:
  200. #+BEGIN_SRC: bash
  201. /var/cache/swap/swapfile none swap sw 0 0
  202. #+END_SRC
  203. Then save and exit.
  204. To verify that the swapfile is accessilble type /top/ and look for the line which begins with "KiB Swap". Probably there will be zero bytes used, but this might be non-zero when the system is under some load (for example getting a lot of web views or being crawled by a search engine). CTRL-C exits from the /top/ command.
  205. ** Enable backports
  206. To enable some newer packages add backports to the repositories.
  207. #+BEGIN_SRC
  208. echo "deb http://ftp.us.debian.org/debian wheezy-backports main" >> /etc/apt/sources.list
  209. apt-get update
  210. apt-get dist-upgrade
  211. #+END_SRC
  212. ** Random number generation
  213. #+BEGIN_VERSE
  214. /Near as I can tell, the answer on what has been requested is everything: deliberate weakenings of encryption algorithms, deliberate weakenings of random number generations, copies of master keys, encryption of the session key with an NSA-specific key … everything./
  215. -- Bruce Schneier, on the 2013 leaked NSA documents
  216. #+END_VERSE
  217. The security of encryption depends upon how random the pseudo-random number generation on your system is. If it isn't very random then it may be far more vulnerable to cryptanalysis, and it's known that in the past some dubious agencies have encouraged the use of flawed random number generators to assist with their prurient activities. Randomness - typically referred to as /entropy/ - is often gathered from factors such as the timing of key presses or mouse movements, but since the BBB won't have such devices plugged into it this reduces the amount of entropy available.
  218. To improve entropy generation there are two options. One is to install a kernel module which enables the hardware crypto available on the BBB, but that's a bit complicated and might have some stability implications. The other option is to install [[http://www.issihosts.com/haveged/][havegd]]. While not as good as a true hardware random number generator, havegd is better than the default pseudo-random number generation within the Linux kernel. To install it:
  219. #+BEGIN_SRC: bash
  220. apt-get install haveged
  221. #+END_SRC
  222. At the time of writing there is also some hardware called [[http://beagleboard.org/project/CryptoCape/][cryptocape]] being developed, with the intention of adding extra random number generation capabilities to the BBB.
  223. ** Alter ssh configuration
  224. Altering the ssh configuration will make it a little more secure than the standard Debian settings.
  225. #+BEGIN_SRC: bash
  226. emacs /etc/ssh/sshd_config
  227. #+END_SRC
  228. Check the following values:
  229. #+BEGIN_SRC: bash
  230. PermitRootLogin no
  231. X11Forwarding no
  232. ServerKeyBits 4096
  233. Protocol 2
  234. PermitEmptyPasswords no
  235. StrictModes yes
  236. #+END_SRC
  237. Append the following:
  238. #+BEGIN_SRC: bash
  239. Ciphers aes256-ctr,aes192-ctr,aes128-ctr
  240. MACs hmac-sha2-512,hmac-sha2-256,hmac-ripemd160
  241. KexAlgorithms diffie-hellman-group-exchange-sha256,diffie-hellman-group14-sha1,diffie-hellman-group-exchange-sha1
  242. #+END_SRC
  243. CTRL-X CTRL-S to save, then CTRL-X CTRL-C to exit.
  244. #+BEGIN_SRC: bash
  245. service ssh restart
  246. #+END_SRC
  247. To test the new settings log out by typing "exit" a couple of times, then log back in again with:
  248. #+BEGIN_SRC: bash
  249. ssh -vvv myusername@192.168.1.60
  250. #+END_SRC
  251. and check that some number of bits are set within a 4096 bit sized key:
  252. #+BEGIN_SRC: bash
  253. debug2: bits set: */4096
  254. #+END_SRC
  255. ** Set the host name
  256. #+BEGIN_SRC: bash
  257. emacs /etc/hostname
  258. #+END_SRC
  259. CTRL-X CTRL-S to save, then CTRL-X CTRL-C to exit.
  260. also issue the command
  261. #+BEGIN_SRC: bash
  262. hostname /myhostname/
  263. #+END_SRC
  264. You may also need to assign the same hostname separately via your router's web interface.
  265. ** Install NTP
  266. To synchronise time.
  267. #+BEGIN_SRC: bash
  268. apt-get install ntp
  269. #+END_SRC
  270. ** Install fail2ban
  271. #+BEGIN_SRC: bash
  272. apt-get install fail2ban
  273. #+END_SRC
  274. ** Getting onto the web
  275. Create a subdomain on [[http://freedns.afraid.org][freeDNS]]. You may need to click on "/subdomains/" a couple of times. FreeDNS is preferred because it is one of the few domain name providers which supports genuinely free (as in beer) accounts. So if your budget is tiny or non-existent you can still participate as a first class citizen of the internet. If you do have money to spend there is also a premium option.
  276. Select "/dynamic DNS/" then click "/quick cron example/"
  277. An example would look like:
  278. #+BEGIN_SRC: bash
  279. 4,9,14,19,24,29,34,39,44,49,54,59 * * * * root sleep 29 ; wget -O - http://free\ dns.afraid.org/dynamic/update.php?ABCKDNRCLFHENSLKNFEGSBFLFF== >> /\ tmp/freedns_mysubdomain_us_to.log 2>&1 &
  280. #+END_SRC
  281. Edit /etc/crontab and append that to the end of the file.
  282. Via your router's firewall settings you should now open port 22 (secure shell). This will allow you to ssh into your BBB from any location - not just your own local network.
  283. ** install Email
  284. #+BEGIN_VERSE
  285. /If you knew what I know about email, you might not use it/
  286. -- Ladar Levison
  287. #+END_VERSE
  288. Email is not very secure, but its usefulness and ubiquity mean that it's likely to continue as a primary communications method for many years to come. You can encrypt the contents of email using PGP/GPG, but very few people do that and even for those that do the metadata (the From/To/CC/BCC) is always transmitted in the clear as a fundamental aspect of the protocol, allowing an attacker to easily construct detailed models of people's social network and life patterns even without knowing the content.
  289. Exim4 seems much easier to install and configure than Postfix.
  290. #+BEGIN_SRC: bash
  291. aptitude install exim4 sasl2-bin swaks libnet-ssleay-perl
  292. #+END_SRC
  293. You will be prompted to remove postfix. Say yes and yes again.
  294. #+BEGIN_SRC: bash
  295. dpkg-reconfigure exim4-config
  296. #+END_SRC
  297. Settings as follows:
  298. #+BEGIN_SRC: bash
  299. internet site
  300. System mail name: mydomainname.com
  301. IP addresses to listen on: blank
  302. Destinations: mydomainname.com
  303. Domains to relay mail: blank
  304. Smarthost Relay: 192.168.1.0/60 (the range of addresses on your LAN)
  305. Dial on demand = no
  306. Maildir format in home directory
  307. Split configuration = no
  308. Root and postmaster: root email
  309. #+END_SRC
  310. To test the installation:
  311. #+BEGIN_SRC: bash
  312. telnet 192.168.1.60 25
  313. ehlo xxx
  314. quit
  315. #+END_SRC
  316. #+BEGIN_SRC: bash
  317. emacs /etc/default/saslauthd
  318. #+END_SRC
  319. set START=yes then save and exit.
  320. #+BEGIN_SRC: bash
  321. /etc/init.d/saslauthd start
  322. emacs exim-gencert
  323. #+END_SRC
  324. #+BEGIN_SRC: bash
  325. #!/bin/sh -e
  326. if [ -n "$EX4DEBUG" ]; then
  327. echo "now debugging $0 $@"
  328. set -x
  329. fi
  330. DIR=/etc/exim4
  331. CERT=$DIR/exim.crt
  332. KEY=$DIR/exim.key
  333. # This exim binary was built with GnuTLS which does not support dhparams
  334. # from a file. See /usr/share/doc/exim4-base/README.Debian.gz
  335. #DH=$DIR/exim.dhparam
  336. if ! which openssl > /dev/null ;then
  337. echo "$0: openssl is not installed, exiting" 1>&2
  338. exit 1
  339. fi
  340. # valid for ten years
  341. DAYS=3650
  342. if [ "$1" != "--force" ] && [ -f $CERT ] && [ -f $KEY ]; then
  343. echo "[*] $CERT and $KEY exists!"
  344. echo " Use \"$0 --force\" to force generation!"
  345. exit 0
  346. fi
  347. if [ "$1" = "--force" ]; then
  348. shift
  349. fi
  350. #SSLEAY=/tmp/exim.ssleay.$$.cnf
  351. SSLEAY="$(tempfile -m600 -pexi)"
  352. cat > $SSLEAY <<EOM
  353. RANDFILE = $HOME/.rnd
  354. [ req ]
  355. default_bits = 4096
  356. default_keyfile = exim.key
  357. distinguished_name = req_distinguished_name
  358. [ req_distinguished_name ]
  359. countryName = Country Code (2 letters)
  360. countryName_default = GB
  361. countryName_min = 2
  362. countryName_max = 2
  363. stateOrProvinceName = State or Province Name (full name)
  364. localityName = Locality Name (eg, city)
  365. organizationName = Organization Name (eg, company; recommended)
  366. organizationName_max = 64
  367. organizationalUnitName = Organizational Unit Name (eg, section)
  368. organizationalUnitName_max = 64
  369. commonName = Server name (eg. ssl.domain.tld; required!!!)
  370. commonName_max = 64
  371. emailAddress = Email Address
  372. emailAddress_max = 40
  373. EOM
  374. echo "[*] Creating a self signed SSL certificate for Exim!"
  375. echo " This may be sufficient to establish encrypted connections but for"
  376. echo " secure identification you need to buy a real certificate!"
  377. echo " "
  378. echo " Please enter the hostname of your MTA at the Common Name (CN) prompt!"
  379. echo " "
  380. openssl req -config $SSLEAY -x509 -sha256 -newkey rsa:4096 -keyout $KEY -out $CERT -days $DAYS -nodes
  381. #see README.Debian.gz*# openssl dhparam -check -text -5 512 -out $DH
  382. rm -f $SSLEAY
  383. chown root:Debian-exim $KEY $CERT $DH
  384. chmod 640 $KEY $CERT $DH
  385. echo "[*] Done generating self signed certificates for exim!"
  386. echo " Refer to the documentation and example configuration files"
  387. echo " over at /usr/share/doc/exim4-base/ for an idea on how to enable TLS"
  388. echo " support in your mail transfer agent."
  389. #+END_SRC
  390. Save and exit
  391. #+BEGIN_SRC: bash
  392. chmod +x exim-gencert
  393. ./exim-gencert
  394. #+END_SRC
  395. This will generate the certificate used for email authentication. You will be asked for various details, the most important of which is the server name, which should be your domain name.
  396. #+BEGIN_SRC: bash
  397. emacs /etc/exim4/exim4.conf.template
  398. #+END_SRC
  399. Append the following:
  400. #+BEGIN_SRC: bash
  401. login_saslauthd_server:
  402. driver = plaintext
  403. public_name = LOGIN
  404. server_prompts = "Username:: : Password::"
  405. # don't send system passwords over unencrypted connections
  406. server_condition = ${if saslauthd{{$auth1}{$auth2}}{1}{0}}
  407. server_set_id = $auth1
  408. .ifndef AUTH_SERVER_ALLOW_NOTLS_PASSWORDS
  409. server_advertise_condition = ${if eq{$tls_cipher}{}{}{*}}
  410. .endif
  411. #+END_SRC
  412. Search for the line *.ifdef MAIN_HARDCODE_PRIMARY_HOSTNAME* and above it insert the line:
  413. #+BEGIN_SRC: bash
  414. MAIN_HARDCODE_PRIMARY_HOSTNAME = mydomainname.com
  415. #+END_SRC
  416. Save and exit.
  417. #+BEGIN_SRC: bash
  418. emacs /etc/exim4/exim4.conf.template
  419. #+END_SRC
  420. Add the line:
  421. #+BEGIN_SRC: bash
  422. MAIN_TLS_ENABLE = true
  423. #+END_SRC
  424. Save and exit.
  425. #+BEGIN_SRC: bash
  426. emacs /etc/default/exim4
  427. change SMTPLISTENEROPTIONS to:
  428. SMTPLISTENEROPTIONS='-oX 465:25 -oP /var/run/exim4/exim.pid'
  429. #+END_SRC
  430. save and exit
  431. #+BEGIN_SRC: bash
  432. emacs /etc/exim4/exim4.conf.template
  433. under the section "main/03_exim4-config_tlsoptions"
  434. Add the following:
  435. tls_on_connect_ports=465
  436. #+END_SRC
  437. save and exit
  438. #+BEGIN_SRC: bash
  439. adduser myusername sasl
  440. addgroup Debian-exim sasl
  441. /etc/init.d/exim4 restart
  442. mkdir /etc/skel/Maildir
  443. #+END_SRC
  444. ** Spam filtering
  445. #+BEGIN_SRC: bash
  446. apt-get install spamassassin exim4-daemon-heavy
  447. emacs /etc/default/spamassassin
  448. #+END_SRC
  449. Set ENABLED=1 then save and exit.
  450. #+BEGIN_SRC: bash
  451. emacs /etc/exim4/exim4.conf.template
  452. #+END_SRC
  453. uncomment or change according to your configuration
  454. #+BEGIN_SRC: bash
  455. # For spam scanning, there is a similar option that defines the interface to
  456. # SpamAssassin. You do not need to set this if you are using the default, which
  457. # is shown in this commented example. As for virus scanning, you must also
  458. # modify the acl_check_data access control list to enable spam scanning.
  459. spamd_address = 127.0.0.1 783
  460. #+END_SRC
  461. add spam header in the /acl_check_data/ section:
  462. #+BEGIN_SRC: bash
  463. ### acl/40_exim4-config_check_data
  464. #################################
  465. # This ACL is used after the contents of a message have been received. This
  466. # is the ACL in which you can test a message's headers or body, and in
  467. # particular, this is where you can invoke external virus or spam scanners.
  468. acl_check_data:
  469. ...
  470. ...
  471. ...
  472. # See the exim docs and the exim wiki for more suitable examples.
  473. #
  474. # warn
  475. # spam = Debian-exim:true
  476. # add_header = X-Spam_score: $spam_score\n\
  477. # X-Spam_score_int: $spam_score_int\n\
  478. # X-Spam_bar: $spam_bar\n\
  479. # X-Spam_report: $spam_report
  480. # put headers in all messages (no matter if spam or not)
  481. warn spam = nobody:true
  482. add_header = X-Spam-Score: $spam_score ($spam_bar)
  483. add_header = X-Spam-Report: $spam_report
  484. # add second subject line with *SPAM* marker when message
  485. # is over threshold
  486. warn spam = nobody
  487. add_header = Subject: ***SPAM (score:$spam_score)*** $h_Subject:
  488. #+END_SRC
  489. Save and exit.
  490. Then restart
  491. #+BEGIN_SRC: bash
  492. exit
  493. emacs ~/.procmailrc
  494. #+END_SRC
  495. The text should look like the following.
  496. #+BEGIN_SRC: sh
  497. MAILDIR=$HOME/Maildir
  498. DEFAULT=$MAILDIR/
  499. LOGFILE=$HOME/log/procmail.log
  500. LOGABSTRACT=all
  501. # get spamassassin to check emails
  502. :0fw: .spamassassin.lock
  503. * < 256000
  504. | spamc
  505. # strong spam are discarded
  506. :0
  507. * ^X-Spam-Level: \*\*\*\*\*\*
  508. /dev/null
  509. # weak spam are kept just in case - clear this out every now and then
  510. :0
  511. * ^X-Spam-Level: \*\*\*\*\*
  512. .0-spam/
  513. # if it wasn't detected as spam, but is to a fake address, then we
  514. # know it is spam, so learn from that
  515. :0
  516. * !^(From|To|cc|bcc)[ :].*($USER|root|webmaster|admin|postmaster).*@acooke\.org
  517. * !^(From|To|cc|bcc)[ :].*@isti\.com
  518. # add mailing lists below
  519. * !^From[ :].*(snowmail_daily@...|Section@...|rforno@...|alert@...).*
  520. {
  521. # save in case of screw-ups, mailing lists, etc
  522. :0 c
  523. .0-spam/
  524. :0
  525. .learn-spam/
  526. }
  527. # otherwise, marginal spam goes here for revision
  528. :0
  529. * ^X-Spam-Level: \*\*
  530. .spam/
  531. #+END_SRC
  532. Save and exit.
  533. #+BEGIN_SRC: bash
  534. su
  535. emacs /usr/bin/filterspam
  536. #+END_SRC
  537. Add the following contents:
  538. #+BEGIN_SRC: bash
  539. #!/bin/bash
  540. USERNAME=$1
  541. MAILDIR=/home/$USERNAME/Maildir/.learn-spam
  542. if [ ! -d "$MAILDIR" ]; then
  543. exit
  544. fi
  545. for f in `ls $MAILDIR/cur`
  546. do
  547. spamc -L spam < "$MAILDIR/cur/$f" > /dev/null
  548. rm "$MAILDIR/cur/$f"
  549. done
  550. for f in `ls $MAILDIR/new`
  551. do
  552. spamc -L spam < "$MAILDIR/new/$f" > /dev/null
  553. rm "$MAILDIR/new/$f"
  554. done
  555. #+END_SRC
  556. Save and exit.
  557. #+BEGIN_SRC: bash
  558. emacs /usr/bin/filterham
  559. #+END_SRC
  560. Add the following contents:
  561. #+BEGIN_SRC: bash
  562. #!/bin/bash
  563. USERNAME=$1
  564. MAILDIR=/home/$USERNAME/Maildir/.learn-ham
  565. if [ ! -d "$MAILDIR" ]; then
  566. exit
  567. fi
  568. for f in `ls $MAILDIR/cur`
  569. do
  570. spamc -L ham < "$MAILDIR/cur/$f" > /dev/null
  571. rm "$MAILDIR/cur/$f"
  572. done
  573. for f in `ls $MAILDIR/new`
  574. do
  575. spamc -L ham < "$MAILDIR/new/$f" > /dev/null
  576. rm "$MAILDIR/new/$f"
  577. done
  578. #+END_SRC
  579. Save and exit.
  580. #+BEGIN_SRC: bash
  581. emacs /etc/crontab
  582. #+END_SRC
  583. Append the following, replacing *myusername* with your username.
  584. #+BEGIN_SRC: bash
  585. */3 * * * * root /usr/bin/filterspam myusername
  586. */3 * * * * root /usr/bin/filterham myusername
  587. #+END_SRC
  588. Save and exit.
  589. #+BEGIN_SRC: bash
  590. chmod 655 /usr/bin/filterspam /usr/bin/filterham
  591. service spamassassin restart
  592. service exim4 restart
  593. service cron restart
  594. #+END_SRC
  595. ** Install dovecot
  596. #+BEGIN_SRC: bash
  597. aptitude -y install dovecot-common dovecot-pop3d dovecot-imapd
  598. #+END_SRC
  599. #+BEGIN_SRC: bash
  600. emacs /etc/dovecot/dovecot.conf
  601. #+END_SRC
  602. # line 26: change ( if not listen IPv6 port )
  603. listen = *
  604. #+BEGIN_SRC: bash
  605. emacs /etc/dovecot/conf.d/10-auth.conf
  606. #+END_SRC
  607. # line 9: uncomment and change ( allow plain text auth )
  608. disable_plaintext_auth = no
  609. # line 99: add
  610. auth_mechanisms = plain login
  611. #+BEGIN_SRC: bash
  612. emacs /etc/dovecot/conf.d/10-mail.conf
  613. #+END_SRC
  614. # line 30: uncomment and add
  615. mail_location = maildir:~/Maildir
  616. #+BEGIN_SRC: bash
  617. service dovecot restart
  618. #+END_SRC
  619. ** Setting up a web site
  620. #+BEGIN_VERSE
  621. /I hope we will use the Net to cross barriers and connect cultures./
  622. -- Tim Berners-Lee
  623. #+END_VERSE
  624. Edit the apache configuration so that it doesn't run out of memory if there are a lot of connections.
  625. #+BEGIN_SRC: bash
  626. su
  627. emacs /etc/apache2/apache2.conf
  628. #+END_SRC
  629. Search for MaxClients and replace the value with 10 then save and exit.
  630. In the examples below replace mydomainname.com with your own domain.
  631. #+BEGIN_SRC: bash
  632. export HOSTNAME=mydomainname.com
  633. mkdir /var/www/$HOSTNAME
  634. mkdir /var/www/$HOSTNAME/htdocs
  635. emacs /etc/apache2/sites-available/$HOSTNAME
  636. #+END_SRC
  637. The Apache configuration for the site should look something like the following. Replace /mydonainname.com/ with the site domain name.
  638. #+BEGIN_SRC: bash
  639. <VirtualHost *:80>
  640. ServerAdmin myusername@mydomainname.com
  641. ServerName mydomainname.com
  642. DocumentRoot /var/www/mydomainname.com/htdocs
  643. <Directory />
  644. Options FollowSymLinks
  645. AllowOverride All
  646. </Directory>
  647. <Directory /var/www/mydomainname.com/htdocs/>
  648. Options All
  649. AllowOverride All
  650. Order allow,deny
  651. allow from all
  652. </Directory>
  653. # Don't serve .php~ or .php# files created by emacs
  654. <Files ~ "(^#.*#|~|\.sw[op])$">
  655. Order allow,deny
  656. Deny from all
  657. </Files>
  658. <IfModule headers_module>
  659. Header set X-Content-Type-Options nosniff
  660. Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate, private"
  661. Header set Pragma no-cache
  662. </IfModule>
  663. <Files .htaccess>
  664. deny from all
  665. </Files>
  666. ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
  667. <Directory "/usr/lib/cgi-bin">
  668. AllowOverride All
  669. Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
  670. Order allow,deny
  671. Allow from all
  672. </Directory>
  673. ErrorLog ${APACHE_LOG_DIR}/error.log
  674. # Possible values include: debug, info, notice, warn, error, crit,
  675. # alert, emerg.
  676. LogLevel warn
  677. CustomLog ${APACHE_LOG_DIR}/access.log combined
  678. </VirtualHost>
  679. <IfModule mod_ssl.c>
  680. <VirtualHost *:443>
  681. ServerAdmin myusername@mydomainname.com
  682. ServerName mydomainname.com
  683. DocumentRoot /var/www/mydomainname.com/htdocs
  684. <Directory />
  685. Options FollowSymLinks
  686. AllowOverride All
  687. </Directory>
  688. <Directory /var/www/mydomainname.com/htdocs/>
  689. Options All
  690. AllowOverride All
  691. Order allow,deny
  692. allow from all
  693. </Directory>
  694. # Don't serve .php~ or .php# files created by emacs
  695. <Files ~ "(^#.*#|~|\.sw[op])$">
  696. Order allow,deny
  697. Deny from all
  698. </Files>
  699. <IfModule headers_module>
  700. Header set X-Content-Type-Options nosniff
  701. Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate, private"
  702. Header set Pragma no-cache
  703. </IfModule>
  704. <Files .htaccess>
  705. deny from all
  706. </Files>
  707. ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
  708. <Directory "/usr/lib/cgi-bin">
  709. AllowOverride All
  710. Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
  711. Order allow,deny
  712. Allow from all
  713. </Directory>
  714. ErrorLog ${APACHE_LOG_DIR}/error.log
  715. # Possible values include: debug, info, notice, warn, error, crit,
  716. # alert, emerg.
  717. LogLevel warn
  718. CustomLog ${APACHE_LOG_DIR}/ssl_access.log combined
  719. # SSL Engine Switch:
  720. # Enable/Disable SSL for this virtual host.
  721. SSLEngine on
  722. # A self-signed certificate
  723. SSLCertificateFile /etc/ssl/certs/mydomainname.com.crt
  724. SSLCertificateKeyFile /etc/ssl/private/mydomainname.com.key
  725. # Options based on bettercrypto.org
  726. SSLProtocol All -SSLv2 -SSLv3
  727. SSLHonorCipherOrder On
  728. SSLCompression off
  729. SSLCipherSuite EDH+CAMELLIA:EDH+aRSA:EECDH+aRSA+AESGCM:EECDH+aRSA+SHA384:EECDH+aRSA+SHA256:EECDH:+CAMELLIA256:+AES256:+CAMELLIA128:+AES128:+SSLv3:!aNULL:!eNULL:!LOW:!3DES:!MD5:!EXP:!PSK:!SRP:!DSS:!RC4:!SEED:!ECDSA:CAMELLIA256-SHA:AES256-SHA:CAMELLIA128-SHA:AES128-SHA
  730. # Add six earth month HSTS header for all users ...
  731. Header add Strict-Transport-Security "max-age=15768000"
  732. # If you want to protect all subdomains , use the following header
  733. # ALL subdomains HAVE TO support https if you use this !
  734. # Strict-Transport-Security: max-age=15768000 ; includeSubDomains
  735. # SSL Engine Options:
  736. # Set various options for the SSL engine.
  737. # o FakeBasicAuth:
  738. # Translate the client X.509 into a Basic Authorisation. This means that
  739. # the standard Auth/DBMAuth methods can be used for access control. The
  740. # user name is the `one line' version of the client's X.509 certificate.
  741. # Note that no password is obtained from the user. Every entry in the user
  742. # file needs this password: `xxj31ZMTZzkVA'.
  743. # o ExportCertData:
  744. # This exports two additional environment variables: SSL_CLIENT_CERT and
  745. # SSL_SERVER_CERT. These contain the PEM-encoded certificates of the
  746. # server (always existing) and the client (only existing when client
  747. # authentication is used). This can be used to import the certificates
  748. # into CGI scripts.
  749. # o StdEnvVars:
  750. # This exports the standard SSL/TLS related `SSL_*' environment variables.
  751. # Per default this exportation is switched off for performance reasons,
  752. # because the extraction step is an expensive operation and is usually
  753. # useless for serving static content. So one usually enables the
  754. # exportation for CGI and SSI requests only.
  755. # o StrictRequire:
  756. # This denies access when "SSLRequireSSL" or "SSLRequire" applied even
  757. # under a "Satisfy any" situation, i.e. when it applies access is denied
  758. # and no other module can change it.
  759. # o OptRenegotiate:
  760. # This enables optimized SSL connection renegotiation handling when SSL
  761. # directives are used in per-directory context.
  762. #SSLOptions +FakeBasicAuth +ExportCertData +StrictRequire
  763. <FilesMatch "\.(cgi|shtml|phtml|php)$">
  764. SSLOptions +StdEnvVars
  765. </FilesMatch>
  766. <Directory /usr/lib/cgi-bin>
  767. SSLOptions +StdEnvVars
  768. </Directory>
  769. # SSL Protocol Adjustments:
  770. # The safe and default but still SSL/TLS standard compliant shutdown
  771. # approach is that mod_ssl sends the close notify alert but doesn't wait for
  772. # the close notify alert from client. When you need a different shutdown
  773. # approach you can use one of the following variables:
  774. # o ssl-unclean-shutdown:
  775. # This forces an unclean shutdown when the connection is closed, i.e. no
  776. # SSL close notify alert is send or allowed to received. This violates
  777. # the SSL/TLS standard but is needed for some brain-dead browsers. Use
  778. # this when you receive I/O errors because of the standard approach where
  779. # mod_ssl sends the close notify alert.
  780. # o ssl-accurate-shutdown:
  781. # This forces an accurate shutdown when the connection is closed, i.e. a
  782. # SSL close notify alert is send and mod_ssl waits for the close notify
  783. # alert of the client. This is 100% SSL/TLS standard compliant, but in
  784. # practice often causes hanging connections with brain-dead browsers. Use
  785. # this only for browsers where you know that their SSL implementation
  786. # works correctly.
  787. # Notice: Most problems of broken clients are also related to the HTTP
  788. # keep-alive facility, so you usually additionally want to disable
  789. # keep-alive for those clients, too. Use variable "nokeepalive" for this.
  790. # Similarly, one has to force some clients to use HTTP/1.0 to workaround
  791. # their broken HTTP/1.1 implementation. Use variables "downgrade-1.0" and
  792. # "force-response-1.0" for this.
  793. BrowserMatch "MSIE [2-6]" \
  794. nokeepalive ssl-unclean-shutdown \
  795. downgrade-1.0 force-response-1.0
  796. # MSIE 7 and newer should be able to use keepalive
  797. BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown
  798. </VirtualHost>
  799. </IfModule>
  800. #+END_SRC
  801. Then to enable the site:
  802. #+BEGIN_SRC: bash
  803. a2ensite
  804. a2dissite default
  805. a2dissite default-ssl
  806. a2enmod rewrite
  807. a2enmod headers
  808. #+END_SRC
  809. Ensure that "NameVirtualHost *:443" is added to /etc/apache2/ports.conf. It should look something like the following:
  810. #+BEGIN_SRC: bash
  811. NameVirtualHost *:80
  812. Listen 80
  813. <IfModule mod_ssl.c>
  814. NameVirtualHost *:443
  815. Listen 443
  816. </IfModule>
  817. <IfModule mod_gnutls.c>
  818. NameVirtualHost *:443
  819. Listen 443
  820. </IfModule>
  821. #+END_SRC
  822. Create a self-signed certificate. The passphrase isn't important and will be removed, so make it easy (such as "password").
  823. #+BEGIN_SRC: bash
  824. emacs makecert
  825. #+END_SRC
  826. Enter the following:
  827. #+BEGIN_SRC: bash
  828. #!/bin/bash
  829. HOSTNAME=$1
  830. openssl genrsa -des3 -out $HOSTNAME.key 1024
  831. openssl req -new -x509 -nodes -sha1 -days 3650 -key $HOSTNAME.key -out $HOSTNAME.crt
  832. openssl rsa -in $HOSTNAME.key -out $HOSTNAME.new.key
  833. cp $HOSTNAME.new.key $HOSTNAME.key
  834. rm $HOSTNAME.new.key
  835. cp $HOSTNAME.key /etc/ssl/private
  836. chmod 400 /etc/ssl/private/$HOSTNAME.key
  837. cp $HOSTNAME.crt /etc/ssl/certs
  838. shred -zu $HOSTNAME.key $HOSTNAME.crt
  839. a2enmod ssl
  840. service apache2 restart
  841. #+END_SRC
  842. Save and exit.
  843. #+BEGIN_SRC: bash
  844. chmod +x makecert
  845. ./makecert mydomainname.com
  846. #+END_SRC
  847. Enter some trivial password for the key file. The password will be removed as part of the makecert script. Note that leaving a password on the key file would mean that after a power cycle the apache server will not be able to boot properly (it would wait indefinitely for a password to be manually entered) and would look as if it had crashed.
  848. If all has gone well then there should be no warnings or errors after you run the service restart command. After that you should enable ports 80 (HTTP) and 443 (HTTPS) on your internet router/firewall, such that they are redirected to the BBB.
  849. ** Accessing your Email
  850. *** Mutt email client
  851. #+BEGIN_VERSE
  852. /I dreamt last night that I was living in a surveillance state. I woke up and… I’m still in a surveillance state./
  853. -- Conrad Kramer
  854. #+END_VERSE
  855. #+BEGIN_SRC: bash
  856. apt-get install mutt lynx abook
  857. exit
  858. mkdir ~/.mutt
  859. echo "text/html; lynx -dump -width=78 -nolist %s | sed ‘s/^ //’; copiousoutput; needsterminal; nametemplate=%s.html" > ~/.mutt/mailcap
  860. #+END_SRC
  861. Save and exit.
  862. #+BEGIN_SRC: bash
  863. su
  864. emacs /etc/Muttrc
  865. #+END_SRC
  866. Append the following:
  867. #+BEGIN_SRC: bash
  868. set mbox_type=Maildir
  869. set folder="~/Maildir"
  870. set mask="!^\\.[^.]"
  871. set mbox="~/Maildir"
  872. set record="+.Sent"
  873. set postponed="+.Drafts"
  874. set spoolfile="~/Maildir"
  875. auto_view text/x-vcard text/html text/enriched
  876. set editor="emacsclient %s"
  877. macro index S "<tag-prefix><save-message>=.learn-spam<enter>" "move to learn-spam"
  878. macro pager S "<save-message>=.learn-spam<enter>" "move to learn-spam"
  879. macro index H "<tag-prefix><copy-message>=.learn-ham<enter>" "copy to learn-ham"
  880. macro pager H "<copy-message>=.learn-ham<enter>" "copy to learn-ham"
  881. #+END_SRC
  882. Save and exit.
  883. #+BEGIN_SRC: bash
  884. emacs /etc/mail/spamassassin/local.cf
  885. #+END_SRC
  886. Uncomment *use_bayes*, *bayes_auto_learn*
  887. Save and exit, then run:
  888. #+BEGIN_SRC: bash
  889. service spamassassin restart
  890. #+END_SRC
  891. Now to add an address book:
  892. #+BEGIN_SRC: bash
  893. emacs ~/.muttrc
  894. #+END_SRC
  895. Append the following:
  896. #+BEGIN_SRC: bash
  897. set alias_file=~/.mutt-alias
  898. source ~/.mutt-alias
  899. set query_command= "abook --mutt-query '%s'"
  900. macro index,pager A "<pipe-message>abook --add-email-quiet<return>" "add the sender address to abook"
  901. #+END_SRC
  902. Then save and exit.
  903. #+BEGIN_SRC: bash
  904. touch ~/.mutt-alias
  905. #+END_SRC
  906. Finally you can then type *mutt* to get access to your email. Hence as a fallback, or if you prefer as the primary way of accessing email, you can ssh into the BBB and use the mutt command line email client. Ssh clients are available for all operating systems, and also you should be reasonably protected from passive surveillance between wherever you are and the BBB (although not between the BBB and the wider internet), which can be useful if you are for example using an Android tablet from a cafe or railway station.
  907. To use the address book system open an email and then to add the sender to the address list press the A key. It will ask you for an alias which may be used the next time you want to send a mail. Alternatively you may just edit the *~/.mutt-alias* file directly to add email addresses.
  908. Some useful keys to know are:
  909. | ESC / | Search for text within message contents |
  910. | "/" | Search for text within headers |
  911. | * | Move to the last message |
  912. | TAB | Move to the next unread message |
  913. | d | Delete a message |
  914. | u | Undelete a mail which is pending deletion |
  915. | $ | Delete all messages selected and check for new messages |
  916. | a | Add to the address book |
  917. | m | Send a new mail |
  918. | S | Mark a message as spam |
  919. | H | Mark a message as ham |
  920. *** K9 Android client
  921. #+BEGIN_VERSE
  922. /The surveillance state is robust. It is robust politically, legally, and technically./
  923. -- Bruce Schneier
  924. #+END_VERSE
  925. **** Incoming server settings
  926. * Select settings/account settings
  927. * Select Fetching mail/incoming server
  928. * Enter your username and password
  929. * IMAP server should be your domain name
  930. * Security: SSL/TLS (always)
  931. * Authentication: Plain
  932. * Port: 993
  933. **** Outgoing (SMTP) server settings
  934. * Select settings/account settings
  935. * Select Sending mail/outgoing server
  936. * Set SMTP server to your domain name
  937. * Set Security to SSL/TLS (always)
  938. * Set port to 465
  939. * Set authentication to PLAIN
  940. * Enter your username and password
  941. * Accept the SSL certificate
  942. *** Webmail
  943. #+BEGIN_VERSE
  944. /Most of the information extracted is "content", such as recordings of phone calls or the substance of email messages./
  945. -- From a 2013 Guardian article on GCHQ/NSA bulk internet data interception.
  946. #+END_VERSE
  947. For maximum speed and efficiency the recommended email client is Mutt, accessed via ssh, but non-technical people who aren't using an Android app are unlikely to want to use email in that manner. So it's a good idea to also have a webmail system installed, both for accessibility and as a fallback should ssh not be available due to port blocking.
  948. Install dependencies.
  949. #+BEGIN_SRC: bash
  950. apt-get install libapache2-mod-authz-unixgroup
  951. #+END_SRC
  952. Create a mysql database, specifying a password which should be a long random string generated with a password manager such as KeepassX.
  953. #+BEGIN_SRC: bash
  954. mysql -u root -p
  955. create database roundcubemail;
  956. CREATE USER 'roundcube'@'localhost' IDENTIFIED BY 'roundcubepassword';
  957. GRANT ALL PRIVILEGES ON roundcubemail.* TO 'roundcube'@'localhost';
  958. quit
  959. #+END_SRC
  960. Download roundcube.
  961. #+BEGIN_SRC: bash
  962. cd /tmp
  963. wget http://freedombone.uk.to/roundcubemail.tar.gz
  964. #+END_SRC
  965. Verify it.
  966. #+BEGIN_SRC: bash
  967. md5sum roundcubemail.tar.gz
  968. 1b1b4056f5fe3903124229427a3bbd1f
  969. #+END_SRC
  970. Extract the files.
  971. #+BEGIN_SRC: bash
  972. tar -xzvf roundcubemail.tar.gz
  973. export HOSTNAME=mydomainname.com
  974. cp -r roundcubemail-* /var/www/$HOSTNAME/htdocs/mail
  975. chown -R www-data:www-data /var/www/$HOSTNAME/htdocs/mail/temp
  976. chown -R www-data:www-data /var/www/$HOSTNAME/htdocs/mail/logs
  977. rm /var/www/$HOSTNAME/htdocs/mail/.htaccess
  978. #+END_SRC
  979. Edit your web site configuration.
  980. #+BEGIN_SRC: bash
  981. emacs /etc/apache2/sites-available/$HOSTNAME
  982. #+END_SRC
  983. Within the 80 VirtualHost section add the following:
  984. #+BEGIN_SRC: bash
  985. <Directory /var/www/mydomainname.com/htdocs/mail>
  986. deny from all
  987. </Directory>
  988. #+END_SRC
  989. Within the 443 VirtualHost section add the following:
  990. #+BEGIN_SRC: bash
  991. <Directory /var/www/mydomainname.com/htdocs/mail>
  992. Options Indexes FollowSymLinks MultiViews
  993. AllowOverride All
  994. Order allow,deny
  995. allow from all
  996. </Directory>
  997. #+END_SRC
  998. Save and exit, then restart Apache.
  999. #+BEGIN_SRC: bash
  1000. service apache2 restart
  1001. #+END_SRC
  1002. Now with a browser visit https://mydomainname.com/mail/installer. Scroll down and click "next". Give your webmail site a product name.
  1003. The *spellcheck_engine* option being limited to Google is slightly concerning in terms of privacy and security, but seems not to be implemented.
  1004. Change the *database password* to the password you gave when creating the MySql database above.
  1005. Set *smtp_port* to 465.
  1006. Click *create config*
  1007. Click download to download the file.
  1008. In a terminal on your local machine (not logged into the BBB):
  1009. #+BEGIN_SRC: bash
  1010. cd ~/Downloads
  1011. scp config.inc.php myusername@mydomainname.com:/home/myusername
  1012. #+END_SRC
  1013. Then in a terminal ssh'd into the BBB:
  1014. #+BEGIN_SRC: bash
  1015. mv /home/myusername/config.inc.php /var/www/$HOSTNAME/htdocs/mail/config
  1016. chmod 755 /var/www/$HOSTNAME/htdocs/mail/config/config.inc.php
  1017. #+END_SRC
  1018. Click *continue*.
  1019. Click *initialize database*.
  1020. Under *Test SMTP config* you can use a [[mailinator.com]] address to check that mail can be sent.
  1021. Now we can delete the installer.
  1022. #+BEGIN_SRC: bash
  1023. rm -rf /var/www/$HOSTNAME/htdocs/mail/installer
  1024. #+END_SRC
  1025. Now with a browser navigate to https://mydomainname.com/mail and log in.
  1026. TODO: connect Sent and Draft folders.
  1027. ** Install a Blog
  1028. #+BEGIN_VERSE
  1029. /When society gives censors wide and vague powers they never confine themselves to deserving targets. They are not snipers, but machine-gunners. Allow them to fire at will, and they will hit anything that moves./
  1030. -- Nick Cohen
  1031. #+END_VERSE
  1032. Wordpress is the most popular blogging platform, but in practice I found it to be high maintenance with frequent security updates and breakages. More practical for a home server is Flatpress. Flatpress doesn't use a MySql database, just text files, and so is easy to relocate or reinstall.
  1033. See the [[Setting up a web site]] section of this document for details of how to configure the web server for your blog's domain.
  1034. Download flatpress.
  1035. #+BEGIN_SRC: bash
  1036. cd /tmp
  1037. wget http://freedombone.uk.to/flatpress.tar.gz
  1038. #+END_SRC
  1039. Verify the download:
  1040. #+BEGIN_SRC: bash
  1041. md5sum flatpress.tar.gz
  1042. 6ad5c230a5cb1ac096ff657f1b138cc7 flatpress.tar.gz
  1043. #+END_SRC
  1044. Extract and install it.
  1045. #+BEGIN_SRC: bash
  1046. tar -xzvf flatpress.tar.gz
  1047. cd flatpress-*
  1048. cp -r * /var/www/$HOSTNAME/htdocs
  1049. rm -rf flatpress-*
  1050. rm -f flatpress.tar.gz
  1051. #+END_SRC
  1052. Now visit your blog and follow the setup instructions, which are quite minimal. Various themes and addons are available from the Flatpress web site, http://www.flatpress.org
  1053. ** Install an IRC server
  1054. #+BEGIN_VERSE
  1055. /Give me the liberty to know, to utter, and to argue freely according to conscience, above all liberties./
  1056. -- John Milton
  1057. #+END_VERSE
  1058. *** Base install
  1059. IRC is not an especially secure system. For instance, even with the best encryption it's easily possible to imagine IRC-specific cribs which could be used by cryptanalytic systems. However, we'll try to implement it in a manner which will at least give the surveillance aparatus something to ponder over.
  1060. First install some dependencies.
  1061. #+BEGIN_SRC: bash
  1062. apt-get update
  1063. apt-get install build-essential openssl libssl-dev
  1064. #+END_SRC
  1065. Then get the source code for ircd-hybrid.
  1066. #+BEGIN_SRC: bash
  1067. cd /tmp
  1068. mkdir hybrid
  1069. cd hybrid
  1070. apt-get source ircd-hybrid
  1071. #+END_SRC
  1072. Modify the source code to include SSL security.
  1073. #+BEGIN_SRC: bash
  1074. emacs ircd-hybrid-*/debian/rules
  1075. #+END_SRC
  1076. Beneath MAXCLIENTS add the line:
  1077. #+BEGIN_SRC: bash
  1078. USE_OPENSSL = 1
  1079. #+END_SRC
  1080. Then save and exit. Now we can build the debian package for ircd-hybrid and install it.
  1081. #+BEGIN_SRC: bash
  1082. cd ircd-hybrid-*
  1083. dpkg-buildpackage -rfakeroot -uc -b
  1084. cd ..
  1085. dpkg -i ircd-hybrid_*.deb
  1086. #+END_SRC
  1087. Customise the configuration to your system, giving it a name and description. In this example 192.168.1.60 is the static IP address on the BBB on the local network, so change that if necessary.
  1088. #+BEGIN_SRC: bash
  1089. emacs /etc/ircd-hybrid/ircd.conf
  1090. #+END_SRC
  1091. Set *name* to the name of your server, and set a description.
  1092. Set a *network_name* and *network_desc*. The network name should not contain any spaces.
  1093. Set max_clients to 20, or however many you expect that you'll typically need.
  1094. Within the admin section set your *name* and *email*.
  1095. Within the *listen* section set host to your fixed IP address (in the earlier
  1096. sections it was 192.168.1.60).
  1097. Within the *auth* section set user = "*@192.168.1.60" - or whatever the fixed IP address of the BBB is on your network.
  1098. Uncomment the first *connect* section and set the *name* to your domain name, the *host* to 192.168.1.60 and the send/accept passwords to a password which you use to log into the IRC server. Also set the *port* to 6670.
  1099. Save and exit, then restart the IRC server. Open port 6670 on your internet router and forward it to the BBB.
  1100. Ensure that the configuration is only readable by the root user.
  1101. #+BEGIN_SRC: bash
  1102. chmod 600 /etc/ircd-hybrid/ircd.conf
  1103. #+END_SRC
  1104. *** Channel management
  1105. To to install channel management tools.
  1106. #+BEGIN_SRC: bash
  1107. cd /tmp
  1108. wget http://freedombone.uk.to/hybserv_1.9.4-1_armhf.deb
  1109. #+END_SRC
  1110. Verify it.
  1111. #+BEGIN_SRC: bash
  1112. md5sum hybserv_1.9.4-1_armhf.deb
  1113. 5b66551ceabb679bdeda1859d23ca6ac hybserv_1.9.4-1_armhf.deb
  1114. #+END_SRC
  1115. Install it.
  1116. #+BEGIN_SRC: bash
  1117. dpkg -i hybserv_1.9.4-1_armhf.deb
  1118. #+END_SRC
  1119. Make a md5 version of the password for the IRC server operator.
  1120. #+BEGIN_SRC: bash
  1121. /usr/bin/mkpasswd <myoperatorpassword>
  1122. #+END_SRC
  1123. Edit the ircd-hybrid configuration.
  1124. #+BEGIN_SRC: bash
  1125. emacs /etc/ircd-hybrid/ircd.conf
  1126. #+END_SRC
  1127. Enter the md5 password which you previously created within the /operator/ section. Also change /user/ to:
  1128. #+BEGIN_SRC: bash
  1129. user = "*@*";
  1130. #+END_SRC
  1131. Then save and exit.
  1132. #+BEGIN_SRC: bash
  1133. emacs /etc/hybserv/hybserv.conf
  1134. #+END_SRC
  1135. Change #MD5 PASSWORD HERE# to the md5 operator password created earlier, mydomainname.com to your domain name and mysendacceptpassword to the send/accept password specified within /ircd.conf/.
  1136. #+BEGIN_SRC: bash
  1137. A:mynickname <myemailaddress>
  1138. N:irc.mydomainname.com:Hybrid services
  1139. O:*@*:#MD5 PASSWORD HERE#:root:segj (comment out other Q: lines)
  1140. S:mysendacceptpassword:192.168.1.60:6670 (remove the other two services)
  1141. #+END_SRC
  1142. Also remove the line *#NOT-EDITED#*, then save and exit.
  1143. Now we need to restart the ircd and hybrid server to make things work:
  1144. #+BEGIN_SRC: bash
  1145. service ircd-hybrid restart
  1146. service hybserv start
  1147. #+END_SRC
  1148. *** Usage
  1149. On another computer (not the BBB).
  1150. #+BEGIN_SRC: bash
  1151. sudo apt-get install irssi
  1152. irssi
  1153. #+END_SRC
  1154. Connect to the IRC and identify yourself as an operator. Here /mynetwork/ should be the same as *network_name* specified earlier within /ircd.conf/.
  1155. #+BEGIN_SRC: bash
  1156. /server add -auto -network mynetwork -ssl mydonainname.com 6670 mysendacceptpassword
  1157. /connect mydomainname.com
  1158. /channel add -auto #mychannel mynetwork channelpassword
  1159. /network add -nick mynick mychannel
  1160. /join #mychannel
  1161. /msg -servername chanserv REGISTER #mychannel channelpassword
  1162. /msg -servername chanserv set #mychannel mlock +k channelpassword
  1163. #+END_SRC
  1164. If you edit the irssi config file:
  1165. #+BEGIN_SRC: bash
  1166. emacs ~/.irssi/config
  1167. #+END_SRC
  1168. It should look something like this:
  1169. #+BEGIN_SRC: bash
  1170. {
  1171. address = "mydomainname.com";
  1172. chatnet = "mynetwork";
  1173. port = "6670";
  1174. password = "mysendacceptpassword";
  1175. use_ssl = "yes";
  1176. ssl_verify = "no";
  1177. autoconnect = "yes";
  1178. },
  1179. #+END_SRC
  1180. If you're not using a self-signed certificate (self-signed is the default) then you can set *ssl_verify* to "yes".
  1181. ** Install a Jabber/XMPP server
  1182. #+BEGIN_VERSE
  1183. /Well heck, it isn’t that hard to write an instant messaging system./
  1184. --Jeremie Miller
  1185. #+END_VERSE
  1186. *** The Server
  1187. Generate a SSL certificate.
  1188. #+BEGIN_SRC: bash
  1189. openssl ecparam -out /etc/ssl/private/xmpp.pem -name prime256v1
  1190. openssl genpkey -paramfile /etc/ssl/private/xmpp.pem -out /etc/ssl/private/xmpp.key
  1191. openssl req -new -x509 -key /etc/ssl/private/xmpp.key -out /etc/ssl/certs/xmpp.crt -days 3650
  1192. #+END_SRC
  1193. The above uses a Diffie-Hellman elliptic curve (ECDH P-256) algorithm. It is apparent that amongst crypographers there are differences of opinion about the security of elliptic curves, so if you prefer there is also a more traditional RSA way to generate an SSL certificate:
  1194. #+BEGIN_SRC: bash
  1195. openssl genrsa -out /etc/ssl/private/xmpp.key 4096
  1196. openssl req -new -x509 -key /etc/ssl/private/xmpp.key -out /etc/ssl/certs/xmpp.crt -days 3650
  1197. #+END_SRC
  1198. Change permissions.
  1199. #+BEGIN_SRC: bash
  1200. chmod 600 /etc/ssl/private/xmpp.key
  1201. chmod 600 /etc/ssl/certs/xmpp.crt
  1202. chown prosody:prosody /etc/ssl/private/xmpp.key
  1203. chown prosody:prosody /etc/ssl/certs/xmpp.crt
  1204. #+END_SRC
  1205. Install Prosody.
  1206. #+BEGIN_SRC: bash
  1207. apt-get install prosody
  1208. cp -a /etc/prosody/conf.avail/example.com.cfg.lua /etc/prosody/conf.avail/xmpp.cfg.lua
  1209. emacs /etc/prosody/conf.avail/xmpp.cfg.lua
  1210. #+END_SRC
  1211. Change the *VirtualHost* name to your domain name and remove the line below it.
  1212. Set the ssl section to:
  1213. #+BEGIN_SRC: bash
  1214. ssl = {
  1215. key = "/etc/ssl/private/xmpp.key";
  1216. certificate = "/etc/ssl/certs/xmpp.crt";
  1217. }
  1218. #+END_SRC
  1219. And also append the following:
  1220. #+BEGIN_SRC: bash
  1221. modules_enabled = {
  1222. "bosh"; -- Enable mod_bosh
  1223. }
  1224. #+END_SRC
  1225. Save and exit. Create a symbolic link.
  1226. #+BEGIN_SRC: bash
  1227. ln -sf /etc/prosody/conf.avail/xmpp.cfg.lua /etc/prosody/conf.d/xmpp.cfg.lua
  1228. #+END_SRC
  1229. Add a user. You will be prompted to specify a password. You can repeat the process for as many users as needed. This will also be your Jabber ID (JID).
  1230. #+BEGIN_SRC: bash
  1231. prosodyctl adduser myusername@mydomainname.com
  1232. #+END_SRC
  1233. Restart the server
  1234. #+BEGIN_SRC: bash
  1235. service prosody restart
  1236. #+END_SRC
  1237. On your internet router/firewall open ports 5222, 5223, 5269, 5280 and 5281 and forward them to the BBB.
  1238. It's possible to test that your XMPP server is working at https://xmpp.net. It may take several minutes and you'll get a low score because of the self-signed certificate, but it will at least verify that your server is capable of communicating.
  1239. *** Managing users
  1240. To add a user:
  1241. #+BEGIN_SRC: bash
  1242. prosodyctl adduser myusername@mydomainname.com
  1243. #+END_SRC
  1244. To change a user password:
  1245. #+BEGIN_SRC: bash
  1246. prosodyctl passwd myusername@mydomainname.com
  1247. #+END_SRC
  1248. To remove a user:
  1249. #+BEGIN_SRC: bash
  1250. prosodyctl deluser myusername@mydomainname.com
  1251. #+END_SRC
  1252. Report the status of the XMPP server:
  1253. #+BEGIN_SRC: bash
  1254. prosodyctl status
  1255. #+END_SRC
  1256. *** Using with Jitsi
  1257. Jitsi is the recommended communications client for desktop or laptop systems, since it includes the /off the record/ (OTR) feature which provides some additional security beyond the usual SSL certificates.
  1258. Jitsi can be downloaded from https://jitsi.org/
  1259. On your desktop/laptop open Jitsi and select *Options* from the *Tools* menu.
  1260. Click *Add* to add a new user, then enter the Jabber ID which you previously specified with /prosodyctl/ when setting up the XMPP server. Close and then you should notice that your status is "Online" (or if not then you should be able to set it to online).
  1261. From the *File* menu you can add contacts, then select the chat icon to begin a chat. Click on the lock icon on the right hand side and this will initiate an authentication procedure in which you can specify a question and answer to verify the identity of the person you're communicating with. Once authentication is complete then you'll be chating using OTR, which provides an additional layer of security.
  1262. When opening Jitsi initially you will get a certificate warning for your domain name (assuming that you're using a self-signed certificate). If this happens then select *View Certificate* and enable the checkbox to trust the certificate, then select *Continue Anyway*. Once you've done this then the certificate warning will not appear again unless you reinstall Jitsi or use a different computer.
  1263. You can also [[https://www.youtube.com/watch?v=vgx7VSrDGjk][see this video]] as an example of using OTR.
  1264. *** Using with Ubuntu
  1265. The default XMPP client in Ubuntu is Empathy. Using Empathy isn't as secure as using Jitsi, since it doesn't include the /off the record/ feature, but since it's the default it's what many users will have easy access to.
  1266. Open *System Settings* and select *Online Accounts*, *Add account* and then *Jabber*.
  1267. Enter your username (myusername@mydomainname.com) and password.
  1268. Click on *Advanced* and make sure that *Encryption required* and *Ignore SSL certificate errors* are checked. Ignoring the certificate errors will allow you to use the self-signed certificate created earlier. Then click *Done* and set your Jabber account and Empathy to *On*.
  1269. *** Using with Android
  1270. Install [[https://f-droid.org/][F-Droid]]
  1271. Search for and install Gibberbot
  1272. From the menu open *Accounts*
  1273. Select *Add account*
  1274. Change the server port from 0 to 5222
  1275. Done
  1276. Accept unknown certificate? Select *Always*
  1277. Go back to the initial screen and then using the menu you can add contacts and begin chatting.
  1278. ** Social Networking
  1279. #+BEGIN_VERSE
  1280. /Facebook is not your friend, it is a surveillance engine./
  1281. -- Richard Stallman, Free Software Foundation
  1282. #+END_VERSE
  1283. *** Friendica
  1284. **** Installation
  1285. See [[Setting up a web site]] for details of how to update the Apache configuration for your Friendica site. You should have a separate domain name specifically to run Friendica on. It can't be installed in a subdirectory on a domain used for something else.
  1286. Edit your Apache configuration and disable the port 80 (HTTP) version of the site. We only want to log into Friendica via HTTPS, so to prevent anyone from accidentally logging in insecurely:
  1287. #+BEGIN_SRC: bash
  1288. emacs /etc/apache2/sites-available/mydomainname.com
  1289. #+END_SRC
  1290. Within the section which begins with *<VirtualHost *:80>* change the following:
  1291. #+BEGIN_SRC: bash
  1292. <Directory /var/www/mydomainname.com/htdocs/>
  1293. deny from all
  1294. </Directory>
  1295. #+END_SRC
  1296. Save and exit, then restart the apache server.
  1297. #+BEGIN_SRC: bash
  1298. service apache2 restart
  1299. #+END_SRC
  1300. Now install some dependencies.
  1301. #+BEGIN_SRC: bash
  1302. apt-get install mysql-server php5-common php5-cli php5-curl php5-gd php5-mysql php5-mcrypt
  1303. #+END_SRC
  1304. Enter an admin password for MySQL.
  1305. Create a mysql database.
  1306. #+BEGIN_SRC: bash
  1307. mysql -u root -p
  1308. create database friendica;
  1309. CREATE USER 'friendicaadmin'@'localhost' IDENTIFIED BY 'password';
  1310. GRANT ALL PRIVILEGES ON friendica.* TO 'friendicaadmin'@'localhost';
  1311. quit
  1312. #+END_SRC
  1313. You may need to fix Git SSL problems.
  1314. #+BEGIN_SRC: bash
  1315. git config --global http.sslVerify true
  1316. apt-get install ca-certificates
  1317. cd ~/
  1318. emacs .gitconfig
  1319. #+END_SRC
  1320. The .gitconfig file should look something like this:
  1321. #+BEGIN_SRC: bash
  1322. [http]
  1323. sslVerify = true
  1324. sslCAinfo = /etc/ssl/certs/ca-certificates.crt
  1325. [user]
  1326. email = myusername@mydomainname.com
  1327. name = yourname
  1328. #+END_SRC
  1329. Get the source code.
  1330. #+BEGIN_SRC: bash
  1331. export HOSTNAME=mydomainname.com
  1332. cd /var/www/$HOSTNAME
  1333. mv htdocs htdocs_old
  1334. git clone https://github.com/friendica/friendica.git htdocs
  1335. chmod -R 755 htdocs
  1336. chown -R www-data:www-data htdocs
  1337. chown -R www-data:www-data htdocs/view/smarty3
  1338. git clone https://github.com/friendica/friendica-addons.git htdocs/addon
  1339. #+END_SRC
  1340. Now visit the URL of your site and you should be taken through the rest of the installation procedure. If you have trouble with "allow override" ensure that "AllowOverride" is set to "all" in your Apache settings for the site (within /etc/apache2/sites-available) and then restart the apache2 service.
  1341. Install the poller.
  1342. #+BEGIN_SRC: bash
  1343. emacs /etc/crontab
  1344. #+END_SRC
  1345. and append the following, changing mydomainname.com to whatever your domain is.
  1346. #+BEGIN_SRC: bash
  1347. */10 * * * * root cd /var/www/mydomainname.com/htdocs; /usr/bin/php include/poller.php
  1348. #+END_SRC
  1349. Save and exit, then restart cron.
  1350. #+BEGIN_SRC: bash
  1351. service cron restart
  1352. #+END_SRC
  1353. You can improve the speed of Friendica database searches by adding the following indexes:
  1354. #+BEGIN_SRC: bash
  1355. mysql -u root -p
  1356. use friendica;
  1357. CREATE INDEX `uri_received` ON item(`uri`, `received`);
  1358. CREATE INDEX `received_uri` ON item(`received`, `uri`);
  1359. CREATE INDEX `contact-id_created` ON item(`contact-id`, created);
  1360. CREATE INDEX `uid_network_received` ON item(`uid`, `network`, `received`);
  1361. CREATE INDEX `uid_parent` ON item(`uid`, `parent`);
  1362. CREATE INDEX `uid_received` ON item(`uid`, `received`);
  1363. CREATE INDEX `uid_network_commented` ON item(`uid`, `network`, `commented`);
  1364. CREATE INDEX `uid_title` ON item(uid, `title`);
  1365. CREATE INDEX `created_contact-id` ON item(`created`, `contact-id`);
  1366. quit
  1367. #+END_SRC
  1368. Make sure that Friendica doesn't use too much memory.
  1369. #+BEGIN_SRC: bash
  1370. emacs /var/www/$HOSTNAME/htdocs/.htaccess
  1371. #+END_SRC
  1372. Append the following:
  1373. #+BEGIN_SRC: bash
  1374. php_value memory_limit 32M
  1375. #+END_SRC
  1376. The save ane exit.
  1377. **** Backups
  1378. Make sure that the database gets backed up. By using cron if anything goes wrong then you should be able to recover the database either from the previous day or the previous week.
  1379. #+BEGIN_SRC: bash
  1380. emacs /etc/cron.daily/friendicabackup
  1381. #+END_SRC
  1382. Enter the following
  1383. #+BEGIN_SRC: bash
  1384. #!/bin/sh
  1385. MYSQL_PASSWORD=<mysql root password>
  1386. umask 0077
  1387. # Backup the database
  1388. mysqldump --password=$MYSQL_PASSWORD friendica > /var/backups/friendica_daily.sql
  1389. # Make the backup readable only by root
  1390. chmod 600 /var/backups/friendica_daily.sql
  1391. #+END_SRC
  1392. Save and exit.
  1393. #+BEGIN_SRC: bash
  1394. chmod 600 /etc/cron.daily/friendicabackup
  1395. chmod +x /etc/cron.daily/friendicabackup
  1396. emacs /etc/cron.weekly/friendicabackup
  1397. #+END_SRC
  1398. Enter the following
  1399. #+BEGIN_SRC: bash
  1400. #!/bin/sh
  1401. MYSQL_PASSWORD=<mysql root password>
  1402. umask 0077
  1403. # Backup the database
  1404. mysqldump --password=$MYSQL_PASSWORD friendica > /var/backups/friendica_weekly.sql
  1405. # Make the backup readable only by root
  1406. chmod 600 /var/backups/friendica_weekly.sql
  1407. #+END_SRC
  1408. Save and exit.
  1409. #+BEGIN_SRC: bash
  1410. chmod 600 /etc/cron.weekly/friendicabackup
  1411. chmod +x /etc/cron.weekly/friendicabackup
  1412. #+END_SRC
  1413. **** Recommended configuration
  1414. ***** Admin
  1415. To get to the admin settings you will need to be logged in with the admin email address which you specified at the beginning of the installation procedure. Depending upon the theme which you're using "/admin/" will be available either as an icon or on a drop down menu.
  1416. Under the *plugins* section the main one which you may wish to enable is the NSFW plugin. With that enabled if a post contans the #NSFW tag then it will appear minimised by default and you will need to click a button to open it.
  1417. Under the *themes* section select a few themes, including mobile themes which are suitable for phones or tablets.
  1418. Under the *site* section give your Friendica node a name other than "/my friend network/", you can change the icon and banner text and set the default mobile theme typically to /frost-mobile/. If you don't want your node to host a lot of accounts for people you don't know then you may want to set the register policy to "/requires approval/". For security it's probably a good idea only to host accounts for people who you actually know, rather than random strangers. Also be aware that the Beaglebone does not have a great deal of computational power or bandwidth and will not function well if there are hundreds of users using your node. If you're not federating with Diaspora or other sites then you may wish to select "/only allow Friendica contacts/". That improves the security of the system, since communication between Friendica nodes is always encrypted separately and in addition to the usual SSL encryption layer - which makes life interesting for the Surveillance State and at least keeps those cryptanalysts employed.
  1419. It's probably a good idea to enable "/private posts by default for new users/" and also "/don't include post content in email notifications/". Since traditional email isn't a secure system and is easily vulnerable to attack by systems such as [[https://en.wikipedia.org/wiki/XKeyscore][Xkeyscore]].
  1420. ***** Settings
  1421. Each user has their own customisable settings, typically available either via an icon or by an entry on a drop down menu.
  1422. Under *additional features* enable "/richtext editor/", "/post preview/", "/group filter/", "/network filter/", "/edit sent posts/" and "/dislike posts/".
  1423. Under *display settings* select your desktop and mobile themes.
  1424. Once you have connected to enough friends it's also a good idea to use the "/export personal data/" option from here. This will save a file to your local system, which you can import into another friendica node if necessary.
  1425. **** To access from an Android device
  1426. ***** App
  1427. Open a browser on your device and go to https://f-droid.org/ then download and install the F-Droid apk. If you then open F-Droid you can search for and install the Friendica app.
  1428. If you are using a self-signed certificate then at the login screen scroll down to the bottom, select the SSL settings then scroll down and disable SSL certificate checks. You will then be able to log in using https, which at least gives you some protection via the encryption.
  1429. More information about the Friendica app can be found on http://friendica-for-android.wiki-lab.net/
  1430. ***** Mobile Theme
  1431. Another way to access Friendica from a mobile device is to just use the web browser. If you have selected a mobile theme within your settings then when viewing from an Android system the mobile theme will be displayed.
  1432. *** Movim
  1433. #+BEGIN_VERSE
  1434. /The way we communicate with others and with ourselves ultimately determines the quality of our lives/
  1435. -- Anthony Robbins
  1436. #+END_VERSE
  1437. Movim is another social networking system based around the XMPP protocol.
  1438. You will need to have previously [[Install a Jabber/XMPP server][installed the Jabber/XMPP server]].
  1439. Edit your Apache configuration and disable the port 80 (HTTP) version of the site. We only want to log into Movim via HTTPS, so to prevent anyone from accidentally logging in insecurely:
  1440. #+BEGIN_SRC: bash
  1441. emacs /etc/apache2/sites-available/mydomainname.com
  1442. #+END_SRC
  1443. Within the section which begins with *<VirtualHost *:80>* add the following:
  1444. #+BEGIN_SRC: bash
  1445. <Directory /var/www/mydomainname.com/htdocs/movim>
  1446. deny from all
  1447. </Directory>
  1448. #+END_SRC
  1449. Within the section which begins with *<VirtualHost *:443>* add the following:
  1450. #+BEGIN_SRC: bash
  1451. <Directory /var/www/mydomainname.com/htdocs/movim>
  1452. Options Indexes FollowSymLinks MultiViews
  1453. AllowOverride All
  1454. Order allow,deny
  1455. allow from all
  1456. </Directory>
  1457. #+END_SRC
  1458. Save and exit, then restart the apache server.
  1459. #+BEGIN_SRC: bash
  1460. service apache2 restart
  1461. #+END_SRC
  1462. Download the source.
  1463. #+BEGIN_SRC: bash
  1464. cd /tmp
  1465. wget http://freedombone.uk.to/movim.tar.gz
  1466. #+END_SRC
  1467. Verify it.
  1468. #+BEGIN_SRC: bash
  1469. md5sum movim.tar.gz
  1470. 311f66d5a3d70d14a8c05da38b08d7e5
  1471. #+END_SRC
  1472. Install it.
  1473. #+BEGIN_SRC: bash
  1474. tar -xzvf movim.tar.gz
  1475. export HOSTNAME=mydomainname.com
  1476. cp -r movim-* /var/www/$HOSTNAME/htdocs/movim
  1477. chmod 755 /var/www/$HOSTNAME/htdocs/movim
  1478. chown -R www-data:www-data /var/www/$HOSTNAME/htdocs/movim
  1479. #+END_SRC
  1480. Install some MySql prerequisites.
  1481. #+BEGIN_SRC: bash
  1482. apt-get install mysql-server php5-common php5-cli php5-curl php5-gd php5-mysql php5-mcrypt
  1483. #+END_SRC
  1484. If necessary, enter an admin password for MySQL.
  1485. Create a mysql database.
  1486. #+BEGIN_SRC: bash
  1487. mysql -u root -p
  1488. create database movim;
  1489. CREATE USER 'movimadmin'@'localhost' IDENTIFIED BY 'movimadminpassword';
  1490. GRANT ALL PRIVILEGES ON movim.* TO 'movimadmin'@'localhost';
  1491. quit
  1492. #+END_SRC
  1493. With a web browser navigate to:
  1494. https://mydomainname.com/movim/admin
  1495. Enter /admin/ as the username and /password/ as the password.
  1496. Click on /General Settings/ and alter the administrator username to /movimadmin/ and password to some long random string (using a password manager such as KeepassX).
  1497. Change the /Environment/ from /Development/ to /Production/.
  1498. The /BOSH URL/ should be http://localhost:5280/http-bind (TODO: should this be https://localhost:5281/http-bind and if so do certificate warnings need to be disabled?)
  1499. Click /Submit/ followed by /Resend/.
  1500. Click on /Database Settings/ and alter the MySql movim database username to /movimadmin/ and password to the password you specified in the previous step.
  1501. Click /Submit/ followed by /Resend/. If you get a lot of orange warnings about database fields being created then hit /Submit/ again until you see "Movim database is up to date".
  1502. If everything on all three tabs looks green then you are ready to go. Click on the Movim logo at the top left and then log in with your Jabber ID (JID).
  1503. *** Red Matrix
  1504. **** Introduction
  1505. Red Matrix is the current version of the Friendica social networking system. It's more general than Friendica in that it's designed as a generic communication system based around a protocol called "zot". At the time of writing in early 2014 Red Matrix remains at an alpha stage of development and so it's not advised that you install it unless you're willing to put up with bugs and frustrations. In the large majority of cases it's better to stick with Friendica for now.
  1506. **** Prerequisites
  1507. The main problem with Red Matrix is that in order to install it you will need to have purchased a domain name (i.e. not a FreeDNS subdomain) and a SSL certificate for it.
  1508. You could join some other Red Matrix server, but this suffers from "/The Levison Problem/" in which some goons show up with a gagging order demanding coppies of the SSL private key. In that scenario unless the owner of the server is exceptionally brave users may never be informed that the site has been compromised or that there is interception hardware attached to the server. Joining another server defeats the object of being digitally self-sufficient and raises legal question marks about the ownership of data which you might upload to a server which doesn't belong to you.
  1509. **** Installation
  1510. See [[Setting up a web site]] for details of how to update the Apache configuration for your Red Matrix site. You should have a separate domain name specifically to run Red Matrix on. It can't be installed in a subdirectory on a domain used for something else.
  1511. Edit your Apache configuration and disable the port 80 (HTTP) version of the site. We only want to log into Red Matrix via HTTPS, so to prevent anyone from accidentally logging in insecurely:
  1512. #+BEGIN_SRC: bash
  1513. emacs /etc/apache2/sites-available/mydomainname.com
  1514. #+END_SRC
  1515. Within the section which begins with *<VirtualHost *:80>* change the following:
  1516. #+BEGIN_SRC: bash
  1517. <Directory /var/www/mydomainname.com/htdocs/>
  1518. deny from all
  1519. </Directory>
  1520. #+END_SRC
  1521. Save and exit, then restart the apache server.
  1522. #+BEGIN_SRC: bash
  1523. service apache2 restart
  1524. #+END_SRC
  1525. Now install some dependencies.
  1526. #+BEGIN_SRC: bash
  1527. apt-get install mysql-server php5-common php5-cli php5-curl php5-gd php5-mysql php5-mcrypt
  1528. #+END_SRC
  1529. Enter an admin password for MySQL.
  1530. Create a mysql database.
  1531. #+BEGIN_SRC: bash
  1532. mysql -u root -p
  1533. create database redmatrix;
  1534. CREATE USER 'redmatrixadmin'@'localhost' IDENTIFIED BY 'password';
  1535. GRANT ALL PRIVILEGES ON redmatrix.* TO 'redmatrixadmin'@'localhost';
  1536. quit
  1537. #+END_SRC
  1538. You may need to fix Git SSL problems.
  1539. #+BEGIN_SRC: bash
  1540. git config --global http.sslVerify true
  1541. apt-get install ca-certificates
  1542. cd ~/
  1543. emacs .gitconfig
  1544. #+END_SRC
  1545. The .gitconfig file should look something like this:
  1546. #+BEGIN_SRC: bash
  1547. [http]
  1548. sslVerify = true
  1549. sslCAinfo = /etc/ssl/certs/ca-certificates.crt
  1550. [user]
  1551. email = myusername@mydomainname.com
  1552. name = yourname
  1553. #+END_SRC
  1554. Get the source code.
  1555. #+BEGIN_SRC: bash
  1556. export HOSTNAME=mydomainname.com
  1557. cd /var/www/$HOSTNAME
  1558. mv htdocs htdocs_old
  1559. git clone https://github.com/friendica/red.git htdocs
  1560. chmod -R 755 htdocs
  1561. chown -R www-data:www-data htdocs
  1562. mkdir htdocs/view/tpl/smarty3
  1563. chmod 777 htdocs/view/tpl
  1564. chmod 777 htdocs/view/tpl/smarty3
  1565. git clone https://github.com/friendica/red-addons.git htdocs/addon
  1566. #+END_SRC
  1567. Now visit the URL of your site and you should be taken through the rest of the installation procedure. Note that this may take a few minutes so don't be concerned if it looks as if it has crashed - just leave it running. If you have trouble with "allow override" ensure that "AllowOverride" is set to "all" in your Apache settings for the site (within /etc/apache2/sites-available) and then restart the apache2 service.
  1568. Install the poller.
  1569. #+BEGIN_SRC
  1570. emacs /etc/crontab
  1571. #+END_SRC
  1572. and append the following, changing mydomainname.com to whatever your domain is.
  1573. #+BEGIN_SRC
  1574. */10 * * * * root cd /var/www/mydomainname.com/htdocs; /usr/bin/php include/poller.php
  1575. #+END_SRC
  1576. Save and exit, then restart cron.
  1577. #+BEGIN_SRC: bash
  1578. service cron restart
  1579. #+END_SRC
  1580. **** Backups
  1581. Make sure that the database gets backed up. By using cron if anything goes wrong then you should be able to recover the database either from the previous day or the previous week.
  1582. #+BEGIN_SRC: bash
  1583. emacs /etc/cron.daily/redmatrixbackup
  1584. #+END_SRC
  1585. Enter the following
  1586. #+BEGIN_SRC: bash
  1587. #!/bin/sh
  1588. MYSQL_PASSWORD=<mysql root password>
  1589. umask 0077
  1590. # Backup the database
  1591. mysqldump --password=$MYSQL_PASSWORD redmatrix > /var/backups/redmatrix_daily.sql
  1592. # Make the backup readable only by root
  1593. chmod 600 /var/backups/redmatrix_daily.sql
  1594. #+END_SRC
  1595. Save and exit.
  1596. #+BEGIN_SRC: bash
  1597. chmod 600 /etc/cron.daily/redmatrixbackup
  1598. chmod +x /etc/cron.daily/redmatrixbackup
  1599. emacs /etc/cron.weekly/redmatrixbackup
  1600. #+END_SRC
  1601. Enter the following
  1602. #+BEGIN_SRC: bash
  1603. #!/bin/sh
  1604. MYSQL_PASSWORD=<mysql root password>
  1605. umask 0077
  1606. # Backup the database
  1607. mysqldump --password=$MYSQL_PASSWORD redmatrix > /var/backups/redmatrix_weekly.sql
  1608. # Make the backup readable only by root
  1609. chmod 600 /var/backups/redmatrix_weekly.sql
  1610. #+END_SRC
  1611. Save and exit.
  1612. #+BEGIN_SRC: bash
  1613. chmod 600 /etc/cron.weekly/redmatrixbackup
  1614. chmod +x /etc/cron.weekly/redmatrixbackup
  1615. #+END_SRC
  1616. **** To access from an Android device
  1617. ***** App
  1618. Open a browser on your device and go to https://f-droid.org/ then download and install the F-Droid apk. If you then open F-Droid you can search for and install the Friendica app.
  1619. If you are using a self-signed certificate then at the login screen scroll down to the bottom, select the SSL settings then scroll down and disable SSL certificate checks. You will then be able to log in using https, which at least gives you some protection via the encryption.
  1620. More information about the Friendica app can be found on http://friendica-for-android.wiki-lab.net/
  1621. ** Install Gopher
  1622. Gopher is an old internet protocol which originated a few years before the web and is purely text based. It can be quite fun to build a gopher site and browse the gopherverse. One thing to keep in mind is that there is no security with gopher, so any text transmitted is trivially interceptable by systems such as [[https://en.wikipedia.org/wiki/XKeyscore][Xkeyscore]] or deep packet inspection.
  1623. To set up a gopher server:
  1624. #+BEGIN_SRC: bash
  1625. apt-get install build-essential
  1626. cd /tmp
  1627. wget http://freedombone.uk.to/geomyidae-current.tgz
  1628. #+END_SRC
  1629. Verify the download:
  1630. #+BEGIN_SRC: bash
  1631. md5sum geomyidae-current.tgz
  1632. 3d8bb8601f37ca953b00fc2445ab5abe geomyidae-current.tgz
  1633. #+END_SRC
  1634. Then extract and install it.
  1635. #+BEGIN_SRC: bash
  1636. tar -xzvf geomyidae-current.tgz
  1637. cd geomyidae-*
  1638. make
  1639. make install
  1640. mkdir -p /var/gopher
  1641. #+END_SRC
  1642. Your content should be placed within /var/gopher with the index page being named index.gph. The Gopher format is very simple - simpler than HTML - so creating pages is not much more difficult than editing a text file.
  1643. #+BEGIN_SRC: bash
  1644. emacs /etc/init.d/gopher
  1645. #+END_SRC
  1646. Enter the following:
  1647. #+BEGIN_SRC: bash
  1648. #! /bin/sh
  1649. ### BEGIN INIT INFO
  1650. # Provides: gopher
  1651. # Required-Start: $remote_fs $syslog
  1652. # Required-Stop: $remote_fs $syslog
  1653. # Default-Start: 2 3 4 5
  1654. # Default-Stop: 0 1 6
  1655. # Short-Description: Gopher daemon
  1656. # Description: Gopher daemon
  1657. ### END INIT INFO
  1658. # Do NOT "set -e"
  1659. # PATH should only include /usr/* if it runs after the mountnfs.sh script
  1660. PATH=/sbin:/usr/sbin:/bin:/usr/bin
  1661. DESC="Gopher daemon"
  1662. NAME=geomyidae
  1663. DAEMON=/usr/bin/$NAME
  1664. DAEMON_ARGS="-l /var/log/geomyidae.log -b /var/gopher -p 70"
  1665. PIDFILE=/var/run/$NAME.pid
  1666. SCRIPTNAME=/etc/init.d/$NAME
  1667. # Exit if the package is not installed
  1668. [ -x "$DAEMON" ] || exit 0
  1669. # Read configuration variable file if it is present
  1670. [ -r /etc/default/$NAME ] && . /etc/default/$NAME
  1671. # Load the VERBOSE setting and other rcS variables
  1672. . /lib/init/vars.sh
  1673. # Define LSB log_* functions.
  1674. # Depend on lsb-base (>= 3.2-14) to ensure that this file is present
  1675. # and status_of_proc is working.
  1676. . /lib/lsb/init-functions
  1677. #
  1678. # Function that starts the daemon/service
  1679. #
  1680. do_start()
  1681. {
  1682. # Return
  1683. # 0 if daemon has been started
  1684. # 1 if daemon was already running
  1685. # 2 if daemon could not be started
  1686. start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
  1687. || return 1
  1688. start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
  1689. $DAEMON_ARGS \
  1690. || return 2
  1691. # Add code here, if necessary, that waits for the process to be ready
  1692. # to handle requests from services started subsequently which depend
  1693. # on this one. As a last resort, sleep for some time.
  1694. }
  1695. #
  1696. # Function that stops the daemon/service
  1697. #
  1698. do_stop()
  1699. {
  1700. # Return
  1701. # 0 if daemon has been stopped
  1702. # 1 if daemon was already stopped
  1703. # 2 if daemon could not be stopped
  1704. # other if a failure occurred
  1705. start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
  1706. RETVAL="$?"
  1707. [ "$RETVAL" = 2 ] && return 2
  1708. # Wait for children to finish too if this is a daemon that forks
  1709. # and if the daemon is only ever run from this initscript.
  1710. # If the above conditions are not satisfied then add some other code
  1711. # that waits for the process to drop all resources that could be
  1712. # needed by services started subsequently. A last resort is to
  1713. # sleep for some time.
  1714. start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
  1715. [ "$?" = 2 ] && return 2
  1716. # Many daemons don't delete their pidfiles when they exit.
  1717. rm -f $PIDFILE
  1718. return "$RETVAL"
  1719. }
  1720. #
  1721. # Function that sends a SIGHUP to the daemon/service
  1722. #
  1723. do_reload() {
  1724. #
  1725. # If the daemon can reload its configuration without
  1726. # restarting (for example, when it is sent a SIGHUP),
  1727. # then implement that here.
  1728. #
  1729. start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
  1730. return 0
  1731. }
  1732. case "$1" in
  1733. start)
  1734. [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
  1735. do_start
  1736. case "$?" in
  1737. 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  1738. 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  1739. esac
  1740. ;;
  1741. stop)
  1742. [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
  1743. do_stop
  1744. case "$?" in
  1745. 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  1746. 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  1747. esac
  1748. ;;
  1749. status)
  1750. status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
  1751. ;;
  1752. #reload|force-reload)
  1753. #
  1754. # If do_reload() is not implemented then leave this commented out
  1755. # and leave 'force-reload' as an alias for 'restart'.
  1756. #
  1757. #log_daemon_msg "Reloading $DESC" "$NAME"
  1758. #do_reload
  1759. #log_end_msg $?
  1760. #;;
  1761. restart|force-reload)
  1762. #
  1763. # If the "reload" option is implemented then remove the
  1764. # 'force-reload' alias
  1765. #
  1766. log_daemon_msg "Restarting $DESC" "$NAME"
  1767. do_stop
  1768. case "$?" in
  1769. 0|1)
  1770. do_start
  1771. case "$?" in
  1772. 0) log_end_msg 0 ;;
  1773. 1) log_end_msg 1 ;; # Old process is still running
  1774. *) log_end_msg 1 ;; # Failed to start
  1775. esac
  1776. ;;
  1777. *)
  1778. # Failed to stop
  1779. log_end_msg 1
  1780. ;;
  1781. esac
  1782. ;;
  1783. *)
  1784. #echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
  1785. echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
  1786. exit 3
  1787. ;;
  1788. esac
  1789. :
  1790. #+END_SRC
  1791. Save and exit. Then start the gopher service.
  1792. #+BEGIN_SRC: bash
  1793. chmod +x /etc/init.d/gopher
  1794. update-rc.d gopher defaults
  1795. service gopher start
  1796. #+END_SRC
  1797. On your internet router change the firewall settings to route port 70 to the BBB, then provided that you have a gopher plugin installed within your browser then you should be able to navigate to your gopher site with:
  1798. #+BEGIN_SRC: bash
  1799. gopher://mydomainname.com
  1800. #+END_SRC
  1801. There is a browser addon for Gopher called "overbite". Installing that should enable you to view your site.
  1802. ** Install a Wiki
  1803. #+BEGIN_VERSE
  1804. /I believe that technology can liberate, but you need to be a master rather than a user. You need to pull technology apart and master it rather than letting it control you./
  1805. -- Tom Barbalet
  1806. #+END_VERSE
  1807. Dokuwiki is based upon flat files, and so is easy to move from one server to another without a lot of database complications.
  1808. Download the wiki.
  1809. #+BEGIN_SRC: bash
  1810. cd /tmp
  1811. wget http://freedombone.uk.to/dokuwiki.tgz
  1812. #+END_SRC
  1813. Verify it.
  1814. #+BEGIN_SRC: bash
  1815. md5sum dokuwiki.tgz
  1816. 9f35055848429659fd63cda1cfea5a48 dokuwiki.tgz
  1817. #+END_SRC
  1818. Then extract and install it.
  1819. #+BEGIN_SRC: bash
  1820. export HOSTNAME=mywikidomainname.com
  1821. tar -xzvf dokuwiki.tgz
  1822. mv /var/www/$HOSTNAME/htdocs /var/www/$HOSTNAME/htdocs_old
  1823. mv dokuwiki /var/www/$HOSTNAME/htdocs
  1824. #+END_SRC
  1825. Edit the Apache configuration for your wiki site.
  1826. #+BEGIN_SRC: bash
  1827. emacs /etc/apache2/sites-available/$HOSTNAME
  1828. #+END_SRC
  1829. The settings should look something like the following.
  1830. #+BEGIN_SRC: bash
  1831. <VirtualHost *:80>
  1832. ServerAdmin myusername@mywikidomainname.com
  1833. ServerName mydomainname.com
  1834. DocumentRoot /var/www/mywikidomainname.com/htdocs
  1835. <Directory /var/www/mywikidomainname.com/htdocs>
  1836. order deny,allow
  1837. allow from all
  1838. </Directory>
  1839. <LocationMatch "/(data|conf|bin|inc)/">
  1840. order allow,deny
  1841. deny from all
  1842. satisfy all
  1843. </LocationMatch>
  1844. <Directory />
  1845. Options FollowSymLinks
  1846. AllowOverride All
  1847. </Directory>
  1848. ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
  1849. <Directory "/usr/lib/cgi-bin">
  1850. AllowOverride All
  1851. Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
  1852. Order allow,deny
  1853. Allow from all
  1854. </Directory>
  1855. ErrorLog ${APACHE_LOG_DIR}/error.log
  1856. # Possible values include: debug, info, notice, warn, error, crit,
  1857. # alert, emerg.
  1858. LogLevel warn
  1859. CustomLog ${APACHE_LOG_DIR}/access.log combined
  1860. </VirtualHost>
  1861. <IfModule mod_ssl.c>
  1862. <VirtualHost *:443>
  1863. ServerAdmin myusername@mywikidomainname.com
  1864. ServerName mywikidomainname.com
  1865. DocumentRoot /var/www/mywikidomainname.com/htdocs
  1866. <Directory /var/www/mywikidomainname.com/htdocs>
  1867. order deny,allow
  1868. allow from all
  1869. </Directory>
  1870. <LocationMatch "/(data|conf|bin|inc)/">
  1871. order allow,deny
  1872. deny from all
  1873. satisfy all
  1874. </LocationMatch>
  1875. <Directory />
  1876. Options FollowSymLinks
  1877. AllowOverride All
  1878. </Directory>
  1879. ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
  1880. <Directory "/usr/lib/cgi-bin">
  1881. AllowOverride All
  1882. Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
  1883. Order allow,deny
  1884. Allow from all
  1885. </Directory>
  1886. ErrorLog ${APACHE_LOG_DIR}/error.log
  1887. # Possible values include: debug, info, notice, warn, error, crit,
  1888. # alert, emerg.
  1889. LogLevel warn
  1890. CustomLog ${APACHE_LOG_DIR}/ssl_access.log combined
  1891. # SSL Engine Switch:
  1892. # Enable/Disable SSL for this virtual host.
  1893. SSLEngine on
  1894. # A self-signed certificate
  1895. SSLCertificateFile /etc/ssl/certs/mydomainname.com.crt
  1896. SSLCertificateKeyFile /etc/ssl/private/mydomainname.com.key
  1897. # Options based on bettercrypto.org
  1898. SSLProtocol All -SSLv2 -SSLv3
  1899. SSLHonorCipherOrder On
  1900. SSLCompression off
  1901. SSLCipherSuite EDH+CAMELLIA:EDH+aRSA:EECDH+aRSA+AESGCM:EECDH+aRSA+SHA384:EECDH+aRSA+SHA256:EECDH:+CAMELLIA256:+AES256:+CAMELLIA128:+AES128:+SSLv3:!aNULL:!eNULL:!LOW:!3DES:!MD5:!EXP:!PSK:!SRP:!DSS:!RC4:!SEED:!ECDSA:CAMELLIA256-SHA:AES256-SHA:CAMELLIA128-SHA:AES128-SHA
  1902. # SSL Engine Options:
  1903. # Set various options for the SSL engine.
  1904. # o FakeBasicAuth:
  1905. # Translate the client X.509 into a Basic Authorisation. This means that
  1906. # the standard Auth/DBMAuth methods can be used for access control. The
  1907. # user name is the `one line' version of the client's X.509 certificate.
  1908. # Note that no password is obtained from the user. Every entry in the user
  1909. # file needs this password: `xxj31ZMTZzkVA'.
  1910. # o ExportCertData:
  1911. # This exports two additional environment variables: SSL_CLIENT_CERT and
  1912. # SSL_SERVER_CERT. These contain the PEM-encoded certificates of the
  1913. # server (always existing) and the client (only existing when client
  1914. # authentication is used). This can be used to import the certificates
  1915. # into CGI scripts.
  1916. # o StdEnvVars:
  1917. # This exports the standard SSL/TLS related `SSL_*' environment variables.
  1918. # Per default this exportation is switched off for performance reasons,
  1919. # because the extraction step is an expensive operation and is usually
  1920. # useless for serving static content. So one usually enables the
  1921. # exportation for CGI and SSI requests only.
  1922. # o StrictRequire:
  1923. # This denies access when "SSLRequireSSL" or "SSLRequire" applied even
  1924. # under a "Satisfy any" situation, i.e. when it applies access is denied
  1925. # and no other module can change it.
  1926. # o OptRenegotiate:
  1927. # This enables optimized SSL connection renegotiation handling when SSL
  1928. # directives are used in per-directory context.
  1929. #SSLOptions +FakeBasicAuth +ExportCertData +StrictRequire
  1930. <FilesMatch "\.(cgi|shtml|phtml|php)$">
  1931. SSLOptions +StdEnvVars
  1932. </FilesMatch>
  1933. <Directory /usr/lib/cgi-bin>
  1934. SSLOptions +StdEnvVars
  1935. </Directory>
  1936. # SSL Protocol Adjustments:
  1937. # The safe and default but still SSL/TLS standard compliant shutdown
  1938. # approach is that mod_ssl sends the close notify alert but doesn't wait for
  1939. # the close notify alert from client. When you need a different shutdown
  1940. # approach you can use one of the following variables:
  1941. # o ssl-unclean-shutdown:
  1942. # This forces an unclean shutdown when the connection is closed, i.e. no
  1943. # SSL close notify alert is send or allowed to received. This violates
  1944. # the SSL/TLS standard but is needed for some brain-dead browsers. Use
  1945. # this when you receive I/O errors because of the standard approach where
  1946. # mod_ssl sends the close notify alert.
  1947. # o ssl-accurate-shutdown:
  1948. # This forces an accurate shutdown when the connection is closed, i.e. a
  1949. # SSL close notify alert is send and mod_ssl waits for the close notify
  1950. # alert of the client. This is 100% SSL/TLS standard compliant, but in
  1951. # practice often causes hanging connections with brain-dead browsers. Use
  1952. # this only for browsers where you know that their SSL implementation
  1953. # works correctly.
  1954. # Notice: Most problems of broken clients are also related to the HTTP
  1955. # keep-alive facility, so you usually additionally want to disable
  1956. # keep-alive for those clients, too. Use variable "nokeepalive" for this.
  1957. # Similarly, one has to force some clients to use HTTP/1.0 to workaround
  1958. # their broken HTTP/1.1 implementation. Use variables "downgrade-1.0" and
  1959. # "force-response-1.0" for this.
  1960. BrowserMatch "MSIE [2-6]" \
  1961. nokeepalive ssl-unclean-shutdown \
  1962. downgrade-1.0 force-response-1.0
  1963. # MSIE 7 and newer should be able to use keepalive
  1964. BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown
  1965. </VirtualHost>
  1966. </IfModule>
  1967. #+END_SRC
  1968. Enable your site with:
  1969. #+BEGIN_SRC: bash
  1970. a2ensite
  1971. #+END_SRC
  1972. then select the domain name and reload.
  1973. #+BEGIN_SRC: bash
  1974. service apache2 reload
  1975. #+END_SRC
  1976. and alter permissions:
  1977. #+BEGIN_SRC: bash
  1978. chmod -R 755 /var/www/$HOSTNAME/htdocs
  1979. chown -R www-data:www-data /var/www/$HOSTNAME/htdocs
  1980. #+END_SRC
  1981. Open a browser and visit http://$HOSTNAME/install.php, then fill out the details. Once everything has been accepted without errors:
  1982. #+BEGIN_SRC: bash
  1983. rm /var/www/$HOSTNAME/htdocs/install.php
  1984. #+END_SRC
  1985. Add a few extra mime types:
  1986. #+BEGIN_SRC: bash
  1987. emacs /var/www/$HOSTNAME/htdocs/conf/mime.conf
  1988. #+END_SRC
  1989. Append the following:
  1990. #+BEGIN_SRC: bash
  1991. ogv video/ogg
  1992. mp4 video/mp4
  1993. webm video/webm
  1994. #+END_SRC
  1995. Save and exit.
  1996. If you need to be able to upload large files to the wiki then edit */etc/php5/apache2/php.ini* and set *upload_max_filesize* accordingly. If the directory */etc/php5/apache2* doesn't exist then you will need to install the package *libapache2-mod-php5*.
  1997. Now you can visit your wiki and begin editing.
  1998. ** Install Owncloud
  1999. #+BEGIN_VERSE
  2000. /It's not water vapour/
  2001. -- Larry Ellison
  2002. #+END_VERSE
  2003. Owncloud will allow you to upload and download files, share photos, collaboratively edit documents, have a calendar and more. You should be warned that Owncloud runs quite slowly via an ordinary web browser, but it can be a convenient way to access and share your data from any location in a reasonably secure manner.
  2004. *** Server Installation
  2005. Install some dependencies:
  2006. #+BEGIN_SRC: bash
  2007. apt-get install apache2 php5 php5-gd php-xml-parser php5-intl
  2008. apt-get install php5-sqlite php5-mysql smbclient curl libcurl3 php5-curl
  2009. #+END_SRC
  2010. It's very important that /mod_php5/ and not /mod_php5filter/ be installed. If you have /mod_php5filter/ installed then Owncloud will always fail to install.
  2011. #+BEGIN_SRC: bash
  2012. a2dismod php5filter
  2013. apt-get install libapache2-mod-php5
  2014. #+END_SRC
  2015. Ensure that the size of files which may be uploaded or downloaded is large enough.
  2016. #+BEGIN_SRC: bash
  2017. emacs /etc/php5/apache2/php.ini
  2018. #+END_SRC
  2019. Set the following:
  2020. #+BEGIN_SRC: bash
  2021. upload_max_filesize = 512M
  2022. post_max_size = 512M
  2023. #+END_SRC
  2024. Save and exit, then edit your Apache configuration.
  2025. #+BEGIN_SRC: bash
  2026. export HOSTNAME=mydomainname.com
  2027. emacs /etc/apache2/sites-available/$HOSTNAME
  2028. #+END_SRC
  2029. And add the following, to the 443 VirtualHost section. Really we only will want to be using Owncloud with HTTPS to ensure some level of security and avoidance of dragnet surveillance.
  2030. #+BEGIN_SRC: bash
  2031. <Directory /var/www/mydomainname.com/htdocs/owncloud>
  2032. Options Indexes FollowSymLinks MultiViews
  2033. AllowOverride All
  2034. Order allow,deny
  2035. allow from all
  2036. </Directory>
  2037. #+END_SRC
  2038. To ensure that nobody logs in insecurely add the following to the 80 VirtualHost section.
  2039. #+BEGIN_SRC: bash
  2040. <Directory /var/www/mydomainname.com/htdocs/owncloud>
  2041. deny from all
  2042. </Directory>
  2043. #+END_SRC
  2044. Save and exit, then restart apache.
  2045. #+BEGIN_SRC: bash
  2046. service apache2 restart
  2047. #+END_SRC
  2048. Download owncloud.
  2049. #+BEGIN_SRC: bash
  2050. cd /tmp
  2051. wget http://freedombone.uk.to/owncloud.tar.bz2
  2052. #+END_SRC
  2053. Verify the download:
  2054. #+BEGIN_SRC: bash
  2055. md5sum owncloud.tar.bz2
  2056. f43eabb746b5e339ee70d0a6aaf4a49c
  2057. #+END_SRC
  2058. Extract the archive. This may take a couple of minutes, so don't be alarmed that the system has crashed.
  2059. #+BEGIN_SRC: bash
  2060. export HOSTNAME=mydomainname.com
  2061. tar -xjf owncloud.tar.bz2
  2062. #+END_SRC
  2063. Move the extracted files to your site and set file permissions.
  2064. #+BEGIN_SRC: bash
  2065. cp -r owncloud /var/www/$HOSTNAME/htdocs
  2066. chown -R www-data:www-data /var/www/$HOSTNAME/htdocs/owncloud/apps
  2067. chown -R www-data:www-data /var/www/$HOSTNAME/htdocs/owncloud/config
  2068. chown www-data:www-data /var/www/$HOSTNAME/htdocs/owncloud
  2069. #+END_SRC
  2070. Edit the htaccess file for Owncloud.
  2071. #+BEGIN_SRC: bash
  2072. emacs /var/www/$HOSTNAME/htdocs/owncloud/.htaccess
  2073. #+END_SRC
  2074. Set the following.
  2075. #+BEGIN_SRC: bash
  2076. php_value upload_max_filesize 512M
  2077. php_value post_max_size 512M
  2078. php_value memory_limit 32M
  2079. #+END_SRC
  2080. Save and exit.
  2081. With a web browser visit your domain (mydomainname.com/owncloud) and enter an administrator username and password.
  2082. *** Owncloud on Android
  2083. First install [[https://f-droid.org/][F-Droid]] and then search for the current Owncloud app. Once it's installed you'll then be able to log into the BBB with the URL https://mydomainname.com/opencloud, supplying your username and password.
  2084. ** Install Bitmessage
  2085. #+BEGIN_VERSE
  2086. /Love your neighbour. Fight the future. If you are reading this you ARE the resistance./
  2087. -- BitChirp
  2088. #+END_VERSE
  2089. *** A new kind of Email
  2090. [[https://bitmessage.org][Bitmessage]] is a new type of messaging system intended to fulfill the same role as email, but without the security problems. In particular, Bitmessage attempts to not just encrypt the content but also the metadata. It's message broadcasting system makes it exceedingly difficult for an attacker to know which computer a message is destined for. The only way you know whether a message has been sent to you is whether you are able to decrypt it from the passing stream of messages.
  2091. Although similar to Bitcoin in some regards, such as "/proof of work/", Bitmessage has no block chain and messages are only buffered for approximately three days after which they are deleted from any given node.
  2092. Installing Bitmessage as a daemon will increase the size of the network, and therefore the level of security for all users.
  2093. *** The Daemon
  2094. Install from the current source code.
  2095. #+BEGIN_SRC: bash
  2096. apt-get install python screen
  2097. cd /tmp
  2098. git clone https://github.com/Bitmessage/PyBitmessage.git
  2099. cd PyBitmessage
  2100. make install
  2101. #+END_SRC
  2102. Now create the daemon.
  2103. #+BEGIN_SRC: bash
  2104. emacs /etc/init.d/pybitmessage
  2105. #+END_SRC
  2106. Add the following text:
  2107. #+BEGIN_SRC: bash
  2108. #!/bin/bash
  2109. # /etc/init.d/bitmessage
  2110. ### BEGIN INIT INFO
  2111. # Provides: pybitmessage
  2112. # Required-Start: $remote_fs $syslog
  2113. # Required-Stop: $remote_fs $syslog
  2114. # Default-Start: 2 3 4 5
  2115. # Default-Stop: 0 1 6
  2116. # Short-Description: starts bitmessage as a background daemon, suitable for servers
  2117. # Description: This file should be used to construct scripts to be
  2118. # placed in /etc/init.d.
  2119. ### END INIT INFO
  2120. # Author: Super-Nathan <BM-Gu2k3Wy2hpTMYBxSoM2937SPcuU6xzEj>
  2121. #Settings
  2122. SERVICE='pybitmessage'
  2123. LOGFILE='/dev/null' # this disables logging
  2124. # LOGFILE='/var/log/bitmessage.log' # comment out the above line and un-comment this line to save a log
  2125. COMMAND="python bitmessagemain.py > $LOGFILE"
  2126. USERNAME='bitmsg'
  2127. NICELEVEL=19 # from 0-19 the bigger the number, the less the impact on system resources
  2128. HISTORY=1024
  2129. PBM_LOCATION="/usr/local/share/pybitmessage"
  2130. INVOCATION="nice -n ${NICELEVEL} ${COMMAND}"
  2131. PATH='/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/bin/core_perl:/sbin:/usr/sbin:/bin:/usr/local/share/pybitmessage'
  2132. bm_start() {
  2133. echo "Starting $SERVICE..."
  2134. cd ${PBM_LOCATION}
  2135. su --command "screen -h ${HISTORY} -dmS ${SERVICE} ${INVOCATION}" $USERNAME
  2136. }
  2137. bm_stop() {
  2138. echo "Stopping $SERVICE"
  2139. su --command "screen -p 0 -S ${SERVICE} -X stuff "'^C'"" $USERNAME
  2140. }
  2141. #Start-Stop here
  2142. case "$1" in
  2143. start)
  2144. bm_start
  2145. ;;
  2146. stop)
  2147. bm_stop
  2148. ;;
  2149. restart)
  2150. bm_stop
  2151. sleep 60s
  2152. bm_start
  2153. ;;
  2154. *)
  2155. echo "Usage: $0 {start|stop|restart}"
  2156. exit 1
  2157. ;;
  2158. esac
  2159. exit 0
  2160. #+END_SRC
  2161. Save and exit.
  2162. Add a user which will be specifically for Bitmessage. Since bitmessage is still a relatively young and experimental project, this adds further compartmentalisation such that if there are any bugs within PyBitmessage then an attacker can't neccessarily gain control of root or any other user account. Here we create a user called /bitmsg/ and give it a long random password.
  2163. #+BEGIN_SRC: bash
  2164. adduser bitmsg
  2165. #+END_SRC
  2166. Create a /keys.dat/ file which is used to configure Bitmessage.
  2167. #+BEGIN_SRC: bash
  2168. mkdir /home/bitmsg/.config
  2169. mkdir /home/bitmsg/.config/PyBitmessage
  2170. emacs /home/bitmsg/.config/PyBitmessage/keys.dat
  2171. #+END_SRC
  2172. Add the following:
  2173. #+BEGIN_SRC: bash
  2174. [bitmessagesettings]
  2175. settingsversion = 7
  2176. port = 8444
  2177. timeformat = %%a, %%d %%b %%Y %%I:%%M %%p
  2178. blackwhitelist = black
  2179. startonlogon = false
  2180. minimizetotray = false
  2181. showtraynotifications = false
  2182. startintray = false
  2183. socksproxytype = none
  2184. sockshostname = localhost
  2185. socksport = 9050
  2186. socksauthentication = false
  2187. sockslisten = false
  2188. socksusername =
  2189. sockspassword =
  2190. keysencrypted = false
  2191. messagesencrypted = false
  2192. defaultnoncetrialsperbyte = 640
  2193. defaultpayloadlengthextrabytes = 14000
  2194. minimizeonclose = false
  2195. maxacceptablenoncetrialsperbyte = 0
  2196. maxacceptablepayloadlengthextrabytes = 0
  2197. userlocale = system
  2198. namecoinrpctype = namecoind
  2199. namecoinrpchost = localhost
  2200. namecoinrpcuser =
  2201. namecoinrpcpassword =
  2202. namecoinrpcport = 8336
  2203. sendoutgoingconnections = True
  2204. daemon = true
  2205. #+END_SRC
  2206. Save and exit. Then enable the daemon and run it.
  2207. #+BEGIN_SRC: bash
  2208. rm -f /tmp/-usr-local-share-pybitmessage-*.lock
  2209. chown -R bitmsg:bitmsg /home/bitmsg
  2210. chmod +x /etc/init.d/pybitmessage
  2211. update-rc.d pybitmessage defaults
  2212. service pybitmessage start
  2213. #+END_SRC
  2214. Now open port 8444 on your internet router or firewall and direct it to the BBB.
  2215. *** Using Bitmessage
  2216. Although in principle it would be possible to send Bitmessages directly from the BBB, in practice the /proof of work/ requirement would mean that it would take an infeasibly long time to send messages, and the computational workload would likely greatly impair the performance of other services also running on the system. So to send and receive Bitmessages it's better to just install the client on a laptop or desktop machine.
  2217. The easiest way to install the client is either to download it from [[https://bitmessage.org][bitmessage.org]] or to get the latest build from Github as follows:
  2218. #+BEGIN_SRC: bash
  2219. cd /tmp
  2220. git clone https://github.com/Bitmessage/PyBitmessage.git
  2221. cd PyBitmessage
  2222. make install
  2223. pybitmessage
  2224. #+END_SRC
  2225. ** Install Tripwire
  2226. #+BEGIN_VERSE
  2227. /...by the time you get done with all of that, we have a freedom box/
  2228. -- Eben Moglen
  2229. #+END_VERSE
  2230. Tripwire will try to detect any intrusions into your system. It's a good idea to install it after you have installed all of the other programs which you intend to use.
  2231. #+BEGIN_SRC: bash
  2232. apt-get install tripwire
  2233. export HOSTNAME=mydomainname.com
  2234. cd /etc/tripwire
  2235. cp arm-local.key $HOSTNAME-local.key
  2236. cp site.key $HOSTNAME-site.key
  2237. tripwire --init
  2238. tripwire --update-policy --secure-mode low /etc/tripwire/twpol.txt
  2239. tripwire --check --interactive
  2240. #+END_SRC
  2241. you will be asked for two passphrases ("site" and "local"). Make a note of these.
  2242. If you subsequently install any more packages or make configuration changes then update the policy again with:
  2243. #+BEGIN_SRC: bash
  2244. tripwire --update-policy --secure-mode low /etc/tripwire/twpol.txt
  2245. #+END_SRC
  2246. Also, to look for any rootkits.
  2247. #+BEGIN_SRC: bash
  2248. apt-get install rkhunter
  2249. #+END_SRC
  2250. * Router/Firewall ports
  2251. The following ports on your internet router/firewall should be forwarded to the BBB.
  2252. | Protocol | Port/s |
  2253. |---------------+------------|
  2254. | Gopher | 70 |
  2255. | HTTP | 80 |
  2256. | HTTPS | 443 |
  2257. | IMAP | 143 |
  2258. | IRC SSL | 6670 |
  2259. | SIP | 5060..5061 |
  2260. | SMTP | 25 |
  2261. | SMTPS | 465 |
  2262. | SSH | 22 |
  2263. | XMPP | 5222..5223 |
  2264. | XMPP (server) | 5269 |
  2265. | XMPP (BOSH) | 5280..5281 |
  2266. | Bitmessage | 8444 |
  2267. * Hints and Tips
  2268. ** Messaging security
  2269. If you're connected to other friends via Friendica then the preferred way to send private messages is via Friendica's built-in messaging system. This is a lot more convenient than using GPG with ordinary email and yet still provides a similar level of protection from unwarranted interception.
  2270. ** Restrictive/hostile user environments
  2271. If you are typically operating within a restrictive of hostile environment where using ssh is not an option because everything other than web ports are blocked then you may wish to try installing oterm:
  2272. http://www.coralbits.com/oterm/
  2273. https://github.com/davidmoreno/onion
  2274. ** Moving Domains
  2275. If you're moving servers and using a different domain name or path then you can search and replace URLs within files in the following way:
  2276. #+BEGIN_SRC: bash
  2277. find /var/www/mynewdomain/htdocs -type f -exec sed -i 's@myolddomain@mynewdomain@g' {} \;
  2278. #+END_SRC
  2279. ** MySql foo
  2280. *** Backup all databases
  2281. To back up all mysql databases:
  2282. #+BEGIN_SRC: bash
  2283. mysqldump -u root -p --all-databases --events > /var/backups/databasebackup.sql
  2284. #+END_SRC
  2285. *** Restoring a particular mysql database
  2286. To restore yesterday's friendica backup:
  2287. #+BEGIN_SRC: bash
  2288. mysql -D friendica -o < /var/backups/friendica_daily.sql
  2289. #+END_SRC
  2290. To restore yesterday's mediawiki backup:
  2291. #+BEGIN_SRC: bash
  2292. mysql -D wikidb -o < /var/backups/wikidb_daily.sql
  2293. #+END_SRC
  2294. *** Removing mysql server
  2295. If you manage to screw up sql server completely then it can be fully deleted with:
  2296. #+BEGIN_SRC: bash
  2297. ps aux | grep mysql
  2298. #+END_SRC
  2299. and use /kill -9 <pid>/ to kill all mysql processes.
  2300. #+BEGIN_SRC: bash
  2301. apt-get remove --purge mysql\*
  2302. apt-get clean
  2303. updatedb
  2304. #+END_SRC
  2305. * Deprecated
  2306. The following items have been deprecated until such time as a successful installation is achieved.
  2307. ** Collaborative Document Editing
  2308. #+BEGIN_VERSE
  2309. /Openness and participation are antidotes to surveillance and control./
  2310. -- Howard Rheingold
  2311. #+END_VERSE
  2312. #+BEGIN_SRC: bash
  2313. apt-get install nodejs-legacy
  2314. curl https://npmjs.org/install.sh | sh
  2315. #+END_SRC
  2316. Create an etherpad database.
  2317. #+BEGIN_SRC: bash
  2318. mysql -p
  2319. CREATE DATABASE etherpad CHARACTER SET utf8 COLLATE utf8_general_ci;
  2320. GRANT ALL PRIVILEGES ON etherpad.* TO etherpad@localhost IDENTIFIED BY '__yourPasswd__';
  2321. FLUSH PRIVILEGES;
  2322. exit
  2323. #+END_SRC
  2324. Download etherpad.
  2325. #+BEGIN_SRC: bash
  2326. export HOSTNAME=mydomainname.com
  2327. cd /var/www/$HOSTNAME/htdocs
  2328. git clone git://github.com/ether/etherpad-lite.git etherpad
  2329. #+END_SRC
  2330. Edit the configuration file
  2331. #+BEGIN_SRC: bash
  2332. cd /var/www/$HOSTNAME/htdocs/etherpad
  2333. cp settings.json.template settings.json
  2334. emacs /var/www/$HOSTNAME/htdocs/etherpad/settings.json
  2335. #+END_SRC
  2336. Change the following settings. /rAnD0m5tRIng/ should be altered to a random string 10 characters in length.
  2337. #+BEGIN_SRC: bash
  2338. //IP and port which etherpad should bind at
  2339. "ip": "127.0.0.1",
  2340. // set a session key
  2341. "sessionKey" : "rAnD0m5tRIng",
  2342. //configure the connection settings
  2343. "dbType" : "mysql",
  2344. "dbSettings" : {
  2345. "user" : "etherpad",
  2346. "host" : "localhost",
  2347. "password": "__yourPassword__",
  2348. "database": "etherpad"
  2349. },
  2350. // add admin user
  2351. "users": {
  2352. "admin": {
  2353. "password": "__yourAdminPassword__",
  2354. "is_admin": true
  2355. }
  2356. },
  2357. #+END_SRC
  2358. Save and exit, then create a system user.
  2359. #+BEGIN_SRC: bash
  2360. adduser --system --home=/var/www/$HOSTNAME/htdocs/etherpad/ --group etherpad
  2361. chown -R etherpad: /var/www/$HOSTNAME/htdocs/etherpad/
  2362. #+END_SRC
  2363. Chick that it runs.
  2364. #+BEGIN_SRC: bash
  2365. su -c "/var/www/$HOSTNAME/htdocs/etherpad/bin/run.sh" -s /bin/bash etherpad
  2366. #+END_SRC
  2367. If it ran without exiting abnormally or complaining about node.js being missing then kill the process.
  2368. #+BEGIN_SRC: bash
  2369. pkill -u etherpad
  2370. #+END_SRC
  2371. Create an init script using your favorite editor, changing /mydomainname.com/ to your domain name.
  2372. #+BEGIN_SRC: bash
  2373. emacs /etc/init.d/etherpad
  2374. #+END_SRC
  2375. Add the following:
  2376. #+BEGIN_SRC: bash
  2377. #!/bin/sh
  2378. ### BEGIN INIT INFO
  2379. # Provides: etherpad-lite
  2380. # Required-Start: $local_fs $remote_fs $network $syslog
  2381. # Required-Stop: $local_fs $remote_fs $network $syslog
  2382. # Default-Start: 2 3 4 5
  2383. # Default-Stop: 0 1 6
  2384. # Short-Description: starts etherpad lite
  2385. # Description: starts etherpad lite using start-stop-daemon
  2386. ### END INIT INFO
  2387. PATH="/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/opt/node/bin"
  2388. LOGFILE="/var/www/mydomainname.com/htdocs/etherpad/etherpad-lite.log"
  2389. EPLITE_DIR="/var/www/mydomainname.com/htdocs/etherpad"
  2390. EPLITE_BIN="bin/safeRun.sh"
  2391. USER="etherpad"
  2392. GROUP="etherpad"
  2393. DESC="Etherpad Lite"
  2394. NAME="etherpad-lite"
  2395. set -e
  2396. . /lib/lsb/init-functions
  2397. start() {
  2398. echo "Starting $DESC... "
  2399. start-stop-daemon --start --chuid "$USER:$GROUP" --background --make-pidfile --pidfile /var/run/$NAME.pid --exec $EPLITE_DIR/$EPLITE_BIN -- $LOGFILE || true
  2400. echo "done"
  2401. }
  2402. #We need this function to ensure the whole process tree will be killed
  2403. killtree() {
  2404. local _pid=$1
  2405. local _sig=${2-TERM}
  2406. for _child in $(ps -o pid --no-headers --ppid ${_pid}); do
  2407. killtree ${_child} ${_sig}
  2408. done
  2409. kill -${_sig} ${_pid}
  2410. }
  2411. stop() {
  2412. echo "Stopping $DESC... "
  2413. while test -d /proc/$(cat /var/run/$NAME.pid); do
  2414. killtree $(cat /var/run/$NAME.pid) 15
  2415. sleep 0.5
  2416. done
  2417. rm /var/run/$NAME.pid
  2418. echo "done"
  2419. }
  2420. status() {
  2421. status_of_proc -p /var/run/$NAME.pid "" "etherpad-lite" && exit 0 || exit $?
  2422. }
  2423. case "$1" in
  2424. start)
  2425. start
  2426. ;;
  2427. stop)
  2428. stop
  2429. ;;
  2430. restart)
  2431. stop
  2432. start
  2433. ;;
  2434. status)
  2435. status
  2436. ;;
  2437. *)
  2438. echo "Usage: $NAME {start|stop|restart|status}" >&2
  2439. exit 1
  2440. ;;
  2441. esac
  2442. exit 0
  2443. #+END_SRC
  2444. Save and exit, then enable the daemon.
  2445. #+BEGIN_SRC: bash
  2446. chmod +x /etc/init.d/etherpad
  2447. update-rc.d etherpad defaults
  2448. service etherpad start
  2449. #+END_SRC
  2450. Update your Apache configuration.
  2451. #+BEGIN_SRC: bash
  2452. emacs /etc/apache2/sites-available/$HOSTNAME
  2453. #+END_SRC
  2454. Within the 443 section add the following:
  2455. #+BEGIN_SRC: bash
  2456. <Location /etherpad>
  2457. AuthType Basic
  2458. AuthName "Welcome to Etherpad"
  2459. AuthUserFile /home/mydomainname.com/public_html/.htpasswd
  2460. AuthGroupFile /home/mydomainname.com/public_html/.htgroup
  2461. Require group etherpad
  2462. </Location>
  2463. <IfModule mod_proxy.c>
  2464. ProxyVia On
  2465. ProxyRequests Off
  2466. ProxyPass /etherpad http://192.168.1.60:9001/
  2467. ProxyPassReverse /etherpad 192.168.1.60:9001/
  2468. ProxyPreserveHost on
  2469. <Proxy *>
  2470. Options FollowSymLinks MultiViews
  2471. AllowOverride All
  2472. Order allow,deny
  2473. allow from all
  2474. </Proxy>
  2475. </IfModule>
  2476. #+END_SRC
  2477. Save and exit, then restart Apache.
  2478. #+BEGIN_SRC: bash
  2479. apt-get install libapache2-mod-proxy-html
  2480. a2enmod proxy proxy_http headers deflate
  2481. service apache2 restart
  2482. #+END_SRC
  2483. Create some passwords for users.
  2484. #+BEGIN_SRC: bash
  2485. mkdir /home/$HOSTNAME
  2486. mkdir /home/$HOSTNAME/public_html
  2487. htpasswd -c /home/$HOSTNAME/public_html/.htpasswd myusername
  2488. #+END_SRC
  2489. Create a user group.
  2490. #+BEGIN_SRC: bash
  2491. emacs /home/$HOSTNAME/public_html/.htgroup
  2492. #+END_SRC
  2493. Add the following:
  2494. #+BEGIN_SRC: bash
  2495. etherpad: myusername
  2496. #+END_SRC
  2497. Save and exit.
  2498. ** Install a VoIP server
  2499. #+BEGIN_VERSE
  2500. /Our core principles, whether in software or sovereignty, have always been about freedom and dignity, for all people, on an equal basis/
  2501. -- David Sugar, GNU Telephony
  2502. #+END_VERSE
  2503. *** The server
  2504. Sipwitch is like an introduction service or phone book for SIP VoIP clients. Once introduced the clients can then talk directly, and this means that sipwitch is very lightweight and can run on low power systems such as the BBB.
  2505. Edit your package sources:
  2506. #+BEGIN_SRC: bash
  2507. emacs /etc/apt/sources.list
  2508. #+END_SRC
  2509. Append the following line:
  2510. #+BEGIN_SRC: bash
  2511. deb http://dev.gnutelephony.org/archive/ wheezy/
  2512. #+END_SRC
  2513. Save and exit.
  2514. To load the repository the first time after adding it to the sources.list, since you do not have the verification keys already installed yet. Then do
  2515. #+BEGIN_SRC: bash
  2516. apt-get install gnutelephony-keyring
  2517. #+END_SRC
  2518. After that it will be happy to accept it as a signed repository. The verification keys can also be directly fetched with
  2519. #+BEGIN_SRC: bash
  2520. cd /tmp
  2521. wget http://dev.gnutelephony.org/archive/wheezy/public.key
  2522. #+END_SRC
  2523. and manually added instead with
  2524. #+BEGIN_SRC: bash
  2525. apt-key add public.key
  2526. #+END_SRC
  2527. To make sure you have all dependencies, do
  2528. #+BEGIN_SRC: bash
  2529. apt-get update;apt-get dist-upgrade
  2530. #+END_SRC
  2531. Before we install anything, let's inspect what is available to us by using
  2532. #+BEGIN_SRC: bash
  2533. dpkg -l sipwitch
  2534. #+END_SRC
  2535. To see the main application. The columns will indicate if the package is installed, which version and a description of the package. Then do
  2536. #+BEGIN_SRC: bash
  2537. dpkg -l sipwitch-*
  2538. #+END_SRC
  2539. to see available supporting applications and plugins. Again, the columns will indicate if the package is installed, which version and a description of each of these.
  2540. To install only the main application, do
  2541. #+BEGIN_SRC: bash
  2542. apt-get install sipwitch
  2543. #+END_SRC
  2544. and to install all supporting plugins:
  2545. #+BEGIN_SRC: bash
  2546. apt-get install sipwitch-plugin-scripting sipwitch-plugin-subscriber sipwitch-plugin-forward sipwitch-plugin-zeroconf
  2547. #+END_SRC
  2548. Add your user into the sipwitch group
  2549. #+BEGIN_SRC: bash
  2550. groupadd sipwitch
  2551. groupadd sipusers
  2552. usermod -aG sipwitch myusername
  2553. usermod -aG sipusers myusername
  2554. #+END_SRC
  2555. Then edit the configuration
  2556. #+BEGIN_SRC: bash
  2557. emacs /etc/sipwitch.conf
  2558. #+END_SRC
  2559. Change the *mapped* value from 200 to 20, since we don't want to be serving huge numbers of calls.
  2560. Alter the *range* value to 10, since we don't need a large number of extensions. This will mean that exension numbers 200 to 209 are available.
  2561. Do not set the *realm* value, as doing so seems to prevent the server from working.
  2562. Save and exit.
  2563. Create a digest string for your username:
  2564. #+BEGIN_SRC: bash
  2565. sipwitch digest myusername
  2566. #+END_SRC
  2567. Make a note of the resulting string because you're going to use it in the users file you'll now create.
  2568. #+BEGIN_SRC: bash
  2569. export HOSTNAME=mydomainname.com
  2570. touch /etc/sipwitch.d/$HOSTNAME.xml
  2571. chmod 600 /etc/sipwitch.d/$HOSTNAME.xml
  2572. emacs /etc/sipwitch.d/$HOSTNAME.xml
  2573. #+END_SRC
  2574. It should look something like the following:
  2575. #+BEGIN_SRC: bash
  2576. <provision>
  2577. <user id="myusername">
  2578. <digest>yourdigeststring</digest>
  2579. <extension>201</extension>
  2580. <display>Your full name</display>
  2581. </user>
  2582. </provision>
  2583. #+END_SRC
  2584. Save and exit. Now edit the configuration.
  2585. #+BEGIN_SRC: bash
  2586. emacs /etc/default/sipwitch
  2587. #+END_SRC
  2588. Change "desktop" to "server", then save and exit.
  2589. Update the IP settings:
  2590. #+BEGIN_SRC: bash
  2591. iptables -A INPUT -p tcp --dport 5060 -j ACCEPT
  2592. iptables -A INPUT -p udp --dport 5060 -j ACCEPT
  2593. iptables -A INPUT -p tcp --dport 5061 -j ACCEPT
  2594. iptables -A INPUT -p udp --dport 5061 -j ACCEPT
  2595. iptables-save
  2596. #+END_SRC
  2597. Test that it's working:
  2598. #+BEGIN_SRC: bash
  2599. pkill -9 sipw
  2600. sipw -x9 -f
  2601. #+END_SRC
  2602. Then try to register with the server using a SIP client (such as Jitsi). If everything worked then use CTRL-C to exit. Then start the service.
  2603. #+BEGIN_SRC: bash
  2604. service sipwitch start
  2605. #+END_SRC
  2606. *** Clients
  2607. **** Jitsi
  2608. Download the latst version from https://jitsi.org/index.php/Main/Download
  2609. TODO
  2610. **** Twinkle client
  2611. The client should have a user profile as following:
  2612. The "user name" is the xxx id used in the <user id="xxx"> entry of /etc/sipwitch.conf
  2613. The "domain" is the yyy domain in the main config <stack><domain>yyy entry of /etc/sipwitch.conf
  2614. The SIP Authentication should have:
  2615. realm = realm as set in <registry><realm> of /etc/sipwitch.conf
  2616. authentication name = <user id="xx"> entry, same as "User Name" field.
  2617. password = value of <secret>zzz in <user> entry of /etc/sipwitch.conf
  2618. Under security tab, set "Enable ZRTP/SRTP encryption"
  2619. **** Android
  2620. TODO
  2621. CSipSimple?