coffin

secure lan file storage on a device
git clone git://parazyd.org/coffin.git
Log | Files | Refs | Submodules | README | LICENSE

keyops (3811B)


      1 #!/usr/bin/env zsh
      2 #
      3 # Copyright (c) 2016 Dyne.org Foundation
      4 # coffin is written and maintained by Ivan J. <parazyd@dyne.org>
      5 #
      6 # This file is part of coffin
      7 #
      8 # This source code is free software: you can redistribute it and/or modify
      9 # it under the terms of the GNU General Public License as published by
     10 # the Free Software Foundation, either version 3 of the License, or
     11 # (at your option) any later version.
     12 #
     13 # This software is distributed in the hope that it will be useful,
     14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
     15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     16 # GNU General Public License for more details.
     17 #
     18 # You should have received a copy of the GNU General Public License
     19 # along with this source code. If not, see <http://www.gnu.org/licenses/>.
     20 
     21 vars+=(keyhash)
     22 
     23 hash-key() {
     24 	fn hash-key
     25 
     26 	keyhash=""
     27 	keyhash=${$(sha256sum $COFFINDOT/$tombid.key)[(ws: :)1]}
     28 }
     29 
     30 compare-key() {
     31 	fn compare-key
     32 
     33 	hash-key
     34 	$(grep $keyhash $TOMBS | grep $keyuuid) || return 1
     35 }
     36 
     37 genssl() {
     38 	fn genssl
     39 	req=(tombid COFFINDOT GRAVEYARD)
     40 	ckreq || return 1
     41 
     42 	notice "generating tomb's ssl cert"
     43 
     44 	openssl genrsa -out $COFFINDOT/${tombid}-priv.pem 4096
     45 	openssl rsa -in $COFFINDOT/${tombid}-priv.pem \
     46 		-out $GRAVEYARD/${tombid}-pub.pem \
     47 		-outform PEM \
     48 		-pubout
     49 
     50 	cp -f $GRAVEYARD/${tombid}-pub.pem $COFFINDOT/
     51 }
     52 
     53 encrypt-password() {
     54 	fn encrypt-password $*
     55 	req=(password GRAVEYARD tombid)
     56 	local password="$*"
     57 	ckreq || return 1
     58 
     59 	act "encrypting password"
     60 	print $password | openssl rsautl -encrypt -inkey $GRAVEYARD/${tombid}-pub.pem -pubin \
     61 		> $GRAVEYARD/${tombid}.pass
     62 }
     63 
     64 decrypt-password() {
     65 	fn decrypt-password
     66 	req=(tombid GRAVEYARD COFFINDOT)
     67 	ckreq || return 1
     68 
     69 	act "decrypting password"
     70 	openssl rsautl -decrypt -inkey $COFFINDOT/${tombid}-priv.pem -in $GRAVEYARD/${tombid}.pass
     71 }
     72 
     73 #                                 ,_-=(!7(7/zs_.
     74 #                              .='  ' .`/,/!(=)Zm.
     75 #                .._,,._..  ,-`- `,\ ` -` -`\\7//WW.
     76 #           ,v=~/.-,-\- -!|V-s.)iT-|s|\-.'   `///mK%.
     77 #         v!`i!-.e]-g`bT/i(/[=.Z/m)K(YNYi..   /-]i44M.
     78 #       v`/,`|v]-DvLcfZ/eV/iDLN\D/ZK@%8W[Z..   `/d!Z8m
     79 #      //,c\(2(X/NYNY8]ZZ/bZd\()/\7WY%WKKW)   -'|(][%4.
     80 #    ,\\i\c(e)WX@WKKZKDKWMZ8(b5/ZK8]Z7%ffVM,   -.Y!bNMi
     81 #    /-iit5N)KWG%%8%%%%W8%ZWM(8YZvD)XN(@.  [   \]!/GXW[
     82 #   / ))G8\NMN%W%%%%%%%%%%8KK@WZKYK*ZG5KMi,-   vi[NZGM[
     83 #  i\!(44Y8K%8%%%**~YZYZ@%%%%%4KWZ/PKN)ZDZ7   c=//WZK%!    This is a euphemism for how my code is structured.
     84 # ,\v\YtMZW8W%%f`,`.t/bNZZK%%W%%ZXb*K(K5DZ   -c\\/KM48
     85 # -|c5PbM4DDW%f  v./c\[tMY8W%PMW%D@KW)Gbf   -/(=ZZKM8[     If you're reading this, you have probably been put
     86 # 2(N8YXWK85@K   -'c|K4/KKK%@  V%@@WD8e~  .//ct)8ZK%8`     in charge of maintaining this program.
     87 # =)b%]Nd)@KM[  !'\cG!iWYK%%|   !M@KZf    -c\))ZDKW%`
     88 # YYKWZGNM4/Pb  '-VscP4]b@W%     'Mf`   -L\///KM(%W!       I am so, so sorry for you.
     89 # !KKW4ZK/W7)Z. '/cttbY)DKW%     -`  .',\v)K(5KW%%f
     90 # 'W)KWKZZg)Z2/,!/L(-DYYb54%  ,,`, -\-/v(((KK5WW%f         God speed.
     91 #  \M4NDDKZZ(e!/\7vNTtZd)8\Mi!\-,-/i-v((tKNGN%W%%
     92 #  'M8M88(Zd))///((|D\tDY\\KK-`/-i(=)KtNNN@W%%%@%[
     93 #   !8%@KW5KKN4///s(\Pd!ROBY8/=2(/4ZdzKD%K%%%M8@%%
     94 #    '%%%W%dGNtPK(c\/2\[Z(ttNYZ2NZW8W8K%%%%YKM%M%%.
     95 #      *%%W%GW5@/%!e]_tZdY()v)ZXMZW%W%%%*5Y]K%ZK%8[
     96 #       '*%%%%8%8WK\)[/ZmZ/Zi]!/M%%%%@f\ \Y/NNMK%%!
     97 #         'VM%%%%W%WN5Z/Gt5/b)((cV@f`  - |cZbMKW%%|
     98 #            'V*M%%%WZ/ZG\t5((+)L'-,,/  -)X(NWW%%%
     99 #                 `~`MZ/DZGNZG5(((\,    ,t\\Z)KW%@
    100 #                    'M8K%8GN8\5(5///]i!v\K)85W%%f
    101 #                      YWWKKKKWZ8G54X/GGMeK@WM8%@
    102 #                       !M8%8%48WG@KWYbW%WWW%%%@
    103 #                         VM%WKWK%8K%%8WWWW%%%@`
    104 #                           ~*%%%%%%W%%%%%%%@~
    105 #                              ~*MM%%%%%%@f`
    106 #                                  '''''