-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathicd.go
156 lines (131 loc) · 3.74 KB
/
icd.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
// +build go1.4
//go:generate protoc --go_out=iccp -Iiccp iccp/iccp.proto
//make version
//echo "package main\nvar Version string '`date +%Y%m%d`'\n" > version.go
package main
import (
"flag"
"fmt"
"io/ioutil"
"log"
"net/http"
_ "net/http/pprof"
"os"
"runtime"
"github.com/unix4fun/ic/icjs"
"github.com/unix4fun/ic/ickp"
"github.com/unix4fun/ic/icutl"
)
//
// ____ ___ _______ _____
// __ __/ / // _/ / _/ _ |/ ___/
// / // /_ _/ _/ ^ / // __ / /_
// \_,_/ /_//_/ /___/_/ |_\___/ (irc crypto 4 fun)
// Unix4Fun
// Some people doing some stuff somewhere for some reasons...
//
// https://unix4fun.github.io/
//
// This is u4f Irc Crypto 4 Fun
//
// A simple way to crypt your conversation(s) if, like us, you remain on IRC.
// #Slack / HipChat / whatever are soooo overrated...
//
//
// ic -> irc crypto daemon
func usage(mycmd string) {
fmt.Fprintf(os.Stderr, "%s [options]", mycmd)
}
func init() {
//fmt.Printf("INIT NINITNI INIT!!\n")
}
func main() {
Version := icVersion
go func() {
runtime.LockOSThread()
log.Println(http.ListenAndServe("localhost:6060", nil))
runtime.UnlockOSThread()
}()
// parsing the RSA code...
rsaFlag := flag.Bool("genrsa", false, "generate RSA identity keys")
ecFlag := flag.Bool("genec", false, "generate ECDSA identity keys (these are using NIST curve SecP384")
saecFlag := flag.Bool("gen25519", false, "generate EC 25519 identify keys")
dbgFlag := flag.Bool("debug", false, "activate debug log")
//jsonFlag := flag.Bool("json", true, "use json communication channel")
// we cannot use more than 2048K anyway why bother with a flag then
//bitOpt := flag.Int("client", 2048, "generate Client SSL Certificate")
flag.Parse()
if *dbgFlag == true {
//log.SetOutput(os.Stderr)
icutl.InitDebugLog(os.Stderr)
} else {
//log.SetOutput(ioutil.Discard)
icutl.InitDebugLog(ioutil.Discard)
}
if *rsaFlag == true || *ecFlag == true || *saecFlag == true {
// generate a set of identity RSA keys and save them to file encrypted
//accp.GenRSAKeys()
var i *ickp.IdentityKey
var keyType int
var err error
switch {
case *rsaFlag == true:
keyType = ickp.KEYRSA
//i, err = ickp.NewIdentityKey(ickp.KEYRSA)
//ickp.GenKeysRSA(rand.Reader)
case *ecFlag == true:
keyType = ickp.KEYECDSA
//i, err = ickp.NewIdentityKey(ickp.KEYECDSA)
//ickp.GenKeysECDSA(rand.Reader)
case *saecFlag == true:
keyType = ickp.KEYEC25519
//ickp.GenKeysED25519(rand.Reader)
}
// creating and saving key
i, err = ickp.NewIdentityKey(keyType)
if err != nil {
panic(err)
}
icutl.DebugLog.Printf("bleh i: %p err: %v", i, err)
err = i.ToKeyFiles("/home/rival/.ic/ic_id", []byte("proutprout"))
if err != nil {
panic(err)
}
// loading the saved key
i2, err := ickp.LoadIdentityKey("/home/rival/.ic/ic_id", []byte("proutprout"))
if err != nil {
panic(err)
}
fmt.Printf("SAVED KEY: %v\n", i)
fmt.Printf("LOADED KEY: %v\n", i2)
} else {
// find and load the keys in memory to sign our requests
// private key will need to be unlocked using PB request
// may be it should be loaded on-demand
//ickp.LoadIdentityKeys()
// load authorized_nicks file
//ickp.LoadAuthFile()
// memory storage maps init..
//ickp.ACmap = make(ickp.PSKMap)
ickp.ACrun = true
//fmt.Fprintf(os.Stderr, "[+] ac-%s\nstart\n", Version)
icutl.DebugLog.Printf("ic4f Irc Crypto 4 Fun version %s", Version)
// main loop
for ickp.ACrun == true {
// TODO handle error
err := icjs.HandleStdin()
if err != nil {
icutl.DebugLog.Printf("ic4f communication error: %v\n", err)
}
}
icutl.DebugLog.Printf("ic4f version %s QUITTING NOW!", Version)
/*
pprof.WriteHeapProfile(g)
g.Close()
pprof.StopCPUProfile()
f.Close()
*/
}
//cpuProfile.Stop()
os.Exit(0)
}