-
Notifications
You must be signed in to change notification settings - Fork 0
/
at_pubkey.go
85 lines (70 loc) · 1.6 KB
/
at_pubkey.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
package main
import (
"crypto/tls"
"flag"
"fmt"
"io"
"log"
"os"
)
func main() {
args := os.Args
port := flag.String("port", "64", "port to connect")
atsign := flag.String("atsign", args[1], "atSign to query")
flag.Parse()
config := &tls.Config{}
dirconn, err := tls.Dial("tcp", "root.atsign.org:"+*port, config)
if err != nil {
log.Fatal(err)
}
buf1 := make([]byte, 256)
n1, err := dirconn.Read(buf1)
if err != nil && err != io.EOF {
log.Fatal(err)
}
if string(buf1[:n1]) != "@" {
log.Fatal("No prompt from atDirectory")
}
_, err = io.WriteString(dirconn, *atsign+"\n")
if err != nil {
log.Fatal("client write error:", err)
}
if err = dirconn.CloseWrite(); err != nil {
log.Fatal(err)
}
buf2 := make([]byte, 256)
n2, err := dirconn.Read(buf2)
if err != nil && err != io.EOF {
log.Fatal(err)
}
atSignURL := string(buf2[:n2-3])
fmt.Println("atServer URL:", atSignURL)
dirconn.Close()
secconn, err := tls.Dial("tcp", atSignURL, config)
if err != nil {
log.Fatal(err)
}
buf3 := make([]byte, 256)
n3, err := secconn.Read(buf3)
if err != nil && err != io.EOF {
log.Fatal(err)
}
if string(buf3[:n3]) != "@" {
log.Fatal("No prompt from atServer")
}
_, err = io.WriteString(secconn, "lookup:publickey@"+*atsign+"\n")
if err != nil {
log.Fatal("client write error:", err)
}
if err = secconn.CloseWrite(); err != nil {
log.Fatal(err)
}
buf4 := make([]byte, 512)
n4, err := secconn.Read(buf4)
if err != nil && err != io.EOF {
log.Fatal(err)
}
atSignPublicKey := string(buf4[5 : n4-2])
fmt.Println("atServer public key:", atSignPublicKey)
secconn.Close()
}