activity.go (view raw)
1//
2// Copyright (c) 2019 Ted Unangst <tedu@tedunangst.com>
3//
4// Permission to use, copy, modify, and distribute this software for any
5// purpose with or without fee is hereby granted, provided that the above
6// copyright notice and this permission notice appear in all copies.
7//
8// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15
16package main
17
18import (
19 "bytes"
20 "compress/gzip"
21 "crypto/rsa"
22 "database/sql"
23 "encoding/json"
24 "fmt"
25 "io"
26 "log"
27 "net/http"
28 "net/url"
29 "os"
30 "strconv"
31 "strings"
32 "sync"
33 "time"
34)
35
36func NewJunk() map[string]interface{} {
37 return make(map[string]interface{})
38}
39
40func WriteJunk(w io.Writer, j map[string]interface{}) error {
41 e := json.NewEncoder(w)
42 e.SetEscapeHTML(false)
43 e.SetIndent("", " ")
44 err := e.Encode(j)
45 return err
46}
47
48func ReadJunk(r io.Reader) (map[string]interface{}, error) {
49 decoder := json.NewDecoder(r)
50 var j map[string]interface{}
51 err := decoder.Decode(&j)
52 if err != nil {
53 return nil, err
54 }
55 return j, nil
56}
57
58var theonetruename = `application/ld+json; profile="https://www.w3.org/ns/activitystreams"`
59var thefakename = `application/activity+json`
60var falsenames = []string{
61 `application/ld+json`,
62 `application/activity+json`,
63}
64var itiswhatitis = "https://www.w3.org/ns/activitystreams"
65var thewholeworld = "https://www.w3.org/ns/activitystreams#Public"
66
67func friendorfoe(ct string) bool {
68 ct = strings.ToLower(ct)
69 for _, at := range falsenames {
70 if strings.HasPrefix(ct, at) {
71 return true
72 }
73 }
74 return false
75}
76
77func PostJunk(keyname string, key *rsa.PrivateKey, url string, j map[string]interface{}) error {
78 var buf bytes.Buffer
79 WriteJunk(&buf, j)
80 return PostMsg(keyname, key, url, buf.Bytes())
81}
82
83func PostMsg(keyname string, key *rsa.PrivateKey, url string, msg []byte) error {
84 client := http.DefaultClient
85 req, err := http.NewRequest("POST", url, bytes.NewReader(msg))
86 if err != nil {
87 return err
88 }
89 req.Header.Set("Content-Type", theonetruename)
90 zig(keyname, key, req, msg)
91 resp, err := client.Do(req)
92 if err != nil {
93 return err
94 }
95 resp.Body.Close()
96 switch resp.StatusCode {
97 case 200:
98 case 201:
99 case 202:
100 default:
101 return fmt.Errorf("http post status: %d", resp.StatusCode)
102 }
103 log.Printf("successful post: %s %d", url, resp.StatusCode)
104 return nil
105}
106
107type gzCloser struct {
108 r *gzip.Reader
109 under io.ReadCloser
110}
111
112func (gz *gzCloser) Read(p []byte) (int, error) {
113 return gz.r.Read(p)
114}
115
116func (gz *gzCloser) Close() error {
117 defer gz.under.Close()
118 return gz.r.Close()
119}
120
121func GetJunk(url string) (map[string]interface{}, error) {
122 client := http.DefaultClient
123 req, err := http.NewRequest("GET", url, nil)
124 if err != nil {
125 return nil, err
126 }
127 at := thefakename
128 if strings.Contains(url, ".well-known/webfinger?resource") {
129 at = "application/jrd+json"
130 }
131 req.Header.Set("Accept", at)
132 req.Header.Set("Accept-Encoding", "gzip")
133 resp, err := client.Do(req)
134 if err != nil {
135 return nil, err
136 }
137 if resp.StatusCode != 200 {
138 resp.Body.Close()
139 return nil, fmt.Errorf("http get status: %d", resp.StatusCode)
140 }
141 if strings.EqualFold(resp.Header.Get("Content-Encoding"), "gzip") {
142 gz, err := gzip.NewReader(resp.Body)
143 if err != nil {
144 resp.Body.Close()
145 return nil, err
146 }
147 resp.Body = &gzCloser{r: gz, under: resp.Body}
148 }
149 defer resp.Body.Close()
150 j, err := ReadJunk(resp.Body)
151 return j, err
152}
153
154func jsonfindinterface(ii interface{}, keys []string) interface{} {
155 for _, key := range keys {
156 idx, err := strconv.Atoi(key)
157 if err == nil {
158 m := ii.([]interface{})
159 if idx >= len(m) {
160 return nil
161 }
162 ii = m[idx]
163 } else {
164 m := ii.(map[string]interface{})
165 ii = m[key]
166 if ii == nil {
167 return nil
168 }
169 }
170 }
171 return ii
172}
173func jsonfindstring(j interface{}, keys []string) (string, bool) {
174 s, ok := jsonfindinterface(j, keys).(string)
175 return s, ok
176}
177func jsonfindarray(j interface{}, keys []string) ([]interface{}, bool) {
178 a, ok := jsonfindinterface(j, keys).([]interface{})
179 return a, ok
180}
181func jsonfindmap(j interface{}, keys []string) (map[string]interface{}, bool) {
182 m, ok := jsonfindinterface(j, keys).(map[string]interface{})
183 return m, ok
184}
185func jsongetstring(j interface{}, key string) (string, bool) {
186 return jsonfindstring(j, []string{key})
187}
188func jsongetarray(j interface{}, key string) ([]interface{}, bool) {
189 return jsonfindarray(j, []string{key})
190}
191func jsongetmap(j interface{}, key string) (map[string]interface{}, bool) {
192 return jsonfindmap(j, []string{key})
193}
194
195func savedonk(url string, name, media string) *Donk {
196 var donk Donk
197 row := stmtFindFile.QueryRow(url)
198 err := row.Scan(&donk.FileID)
199 if err == nil {
200 return &donk
201 }
202 log.Printf("saving donk: %s", url)
203 if err != nil && err != sql.ErrNoRows {
204 log.Printf("error querying: %s", err)
205 }
206 resp, err := http.Get(url)
207 if err != nil {
208 log.Printf("error fetching %s: %s", url, err)
209 return nil
210 }
211 defer resp.Body.Close()
212 if resp.StatusCode != 200 {
213 return nil
214 }
215 var buf bytes.Buffer
216 io.Copy(&buf, resp.Body)
217
218 xid := xfiltrate()
219
220 res, err := stmtSaveFile.Exec(xid, name, url, media, buf.Bytes())
221 if err != nil {
222 log.Printf("error saving file %s: %s", url, err)
223 return nil
224 }
225 donk.FileID, _ = res.LastInsertId()
226 return &donk
227}
228
229func needxonk(user *WhatAbout, x *Honk) bool {
230 if x == nil {
231 return false
232 }
233 if x.What == "eradicate" {
234 return true
235 }
236 if thoudostbitethythumb(user.ID, x.Audience, x.XID) {
237 log.Printf("not saving thumb biter? %s", x.Honker)
238 return false
239 }
240 return needxonkid(user, x.XID)
241}
242func needxonkid(user *WhatAbout, xid string) bool {
243 if strings.HasPrefix(xid, user.URL+"/h/") {
244 return false
245 }
246 row := stmtFindXonk.QueryRow(user.ID, xid)
247 var id int64
248 err := row.Scan(&id)
249 if err == nil {
250 return false
251 }
252 if err != sql.ErrNoRows {
253 log.Printf("err querying xonk: %s", err)
254 }
255 return true
256}
257
258func savexonk(user *WhatAbout, x *Honk) {
259 if x.What == "eradicate" {
260 log.Printf("eradicating %s by %s", x.RID, x.Honker)
261 _, err := stmtDeleteHonk.Exec(x.RID, x.Honker, user.ID)
262 if err != nil {
263 log.Printf("error eradicating: %s", err)
264 }
265 return
266 }
267 dt := x.Date.UTC().Format(dbtimeformat)
268 aud := strings.Join(x.Audience, " ")
269 whofore := 0
270 if strings.Contains(aud, user.URL) {
271 whofore = 1
272 }
273 res, err := stmtSaveHonk.Exec(x.UserID, x.What, x.Honker, x.XID, x.RID, dt, x.URL, aud,
274 x.Noise, x.Convoy, whofore)
275 if err != nil {
276 log.Printf("err saving xonk: %s", err)
277 return
278 }
279 x.ID, _ = res.LastInsertId()
280 for _, d := range x.Donks {
281 _, err = stmtSaveDonk.Exec(x.ID, d.FileID)
282 if err != nil {
283 log.Printf("err saving donk: %s", err)
284 return
285 }
286 }
287}
288
289type Box struct {
290 In string
291 Out string
292 Shared string
293}
294
295var boxofboxes = make(map[string]*Box)
296var boxlock sync.Mutex
297var boxinglock sync.Mutex
298
299func getboxes(ident string) (*Box, error) {
300 boxlock.Lock()
301 b, ok := boxofboxes[ident]
302 boxlock.Unlock()
303 if ok {
304 return b, nil
305 }
306
307 boxinglock.Lock()
308 defer boxinglock.Unlock()
309
310 boxlock.Lock()
311 b, ok = boxofboxes[ident]
312 boxlock.Unlock()
313 if ok {
314 return b, nil
315 }
316
317 db := opendatabase()
318
319 row := db.QueryRow("select ibox, obox, sbox from xonkers where xid = ?", ident)
320 b = &Box{}
321 err := row.Scan(&b.In, &b.Out, &b.Shared)
322 if err != nil {
323 j, err := GetJunk(ident)
324 if err != nil {
325 return nil, err
326 }
327 inbox, _ := jsongetstring(j, "inbox")
328 outbox, _ := jsongetstring(j, "outbox")
329 sbox, _ := jsonfindstring(j, []string{"endpoints", "sharedInbox"})
330 b = &Box{In: inbox, Out: outbox, Shared: sbox}
331 if inbox != "" {
332 db.Exec("insert into xonkers (xid, ibox, obox, sbox, pubkey) values (?, ?, ?, ?, ?)",
333 ident, inbox, outbox, sbox, "")
334 }
335 }
336 boxlock.Lock()
337 boxofboxes[ident] = b
338 boxlock.Unlock()
339 return b, nil
340}
341
342func peeppeep() {
343 user, _ := butwhatabout("htest")
344 honkers := gethonkers(user.ID)
345 for _, f := range honkers {
346 if f.Flavor != "peep" {
347 continue
348 }
349 log.Printf("getting updates: %s", f.XID)
350 box, err := getboxes(f.XID)
351 if err != nil {
352 log.Printf("error getting outbox: %s", err)
353 continue
354 }
355 log.Printf("getting outbox")
356 j, err := GetJunk(box.Out)
357 if err != nil {
358 log.Printf("err: %s", err)
359 continue
360 }
361 t, _ := jsongetstring(j, "type")
362 if t == "OrderedCollection" {
363 items, _ := jsongetarray(j, "orderedItems")
364 if items == nil {
365 page1, _ := jsongetstring(j, "first")
366 j, err = GetJunk(page1)
367 if err != nil {
368 log.Printf("err: %s", err)
369 continue
370 }
371 items, _ = jsongetarray(j, "orderedItems")
372 }
373
374 for _, item := range items {
375 xonk := xonkxonk(user, item)
376 if needxonk(user, xonk) {
377 savexonk(user, xonk)
378 }
379 }
380 }
381 }
382}
383
384func whosthere(xid string) ([]string, string) {
385 obj, err := GetJunk(xid)
386 if err != nil {
387 log.Printf("error getting remote xonk: %s", err)
388 return nil, ""
389 }
390 convoy, _ := jsongetstring(obj, "context")
391 if convoy == "" {
392 convoy, _ = jsongetstring(obj, "conversation")
393 }
394 return newphone(nil, obj), convoy
395}
396
397func newphone(a []string, obj map[string]interface{}) []string {
398 for _, addr := range []string{"to", "cc", "attributedTo"} {
399 who, _ := jsongetstring(obj, addr)
400 if who != "" {
401 a = append(a, who)
402 }
403 whos, _ := jsongetarray(obj, addr)
404 for _, w := range whos {
405 who, _ := w.(string)
406 if who != "" {
407 a = append(a, who)
408 }
409 }
410 }
411 return a
412}
413
414func xonkxonk(user *WhatAbout, item interface{}) *Honk {
415 depth := 0
416 maxdepth := 4
417 var xonkxonkfn func(item interface{}) *Honk
418
419 saveoneup := func(xid string) {
420 log.Printf("getting oneup: %s", xid)
421 if depth >= maxdepth {
422 log.Printf("in too deep")
423 return
424 }
425 obj, err := GetJunk(xid)
426 if err != nil {
427 log.Printf("error getting oneup: %s", err)
428 return
429 }
430 depth++
431 xonk := xonkxonkfn(obj)
432 if needxonk(user, xonk) {
433 xonk.UserID = user.ID
434 savexonk(user, xonk)
435 }
436 depth--
437 }
438
439 xonkxonkfn = func(item interface{}) *Honk {
440 // id, _ := jsongetstring(item, "id")
441 what, _ := jsongetstring(item, "type")
442 dt, _ := jsongetstring(item, "published")
443
444 var audience []string
445 var err error
446 var xid, rid, url, content, convoy string
447 var obj map[string]interface{}
448 var ok bool
449 switch what {
450 case "Announce":
451 xid, ok = jsongetstring(item, "object")
452 if ok {
453 if !needxonkid(user, xid) {
454 return nil
455 }
456 log.Printf("getting bonk: %s", xid)
457 obj, err = GetJunk(xid)
458 if err != nil {
459 log.Printf("error regetting: %s", err)
460 }
461 } else {
462 obj, _ = jsongetmap(item, "object")
463 }
464 what = "bonk"
465 case "Create":
466 obj, _ = jsongetmap(item, "object")
467 what = "honk"
468 case "Note":
469 obj = item.(map[string]interface{})
470 what = "honk"
471 case "Delete":
472 obj, _ = jsongetmap(item, "object")
473 rid, _ = jsongetstring(item, "object")
474 what = "eradicate"
475 default:
476 log.Printf("unknown activity: %s", what)
477 return nil
478 }
479
480 var xonk Honk
481 who, _ := jsongetstring(item, "actor")
482 if obj != nil {
483 if who == "" {
484 who, _ = jsongetstring(obj, "attributedTo")
485 }
486 ot, _ := jsongetstring(obj, "type")
487 url, _ = jsongetstring(obj, "url")
488 if ot == "Note" || ot == "Article" {
489 audience = newphone(audience, obj)
490 xid, _ = jsongetstring(obj, "id")
491 content, _ = jsongetstring(obj, "content")
492 summary, _ := jsongetstring(obj, "summary")
493 if !strings.HasPrefix(content, "<p>") {
494 content = "<p>" + content
495 }
496 if summary != "" {
497 content = "<p>summary: " + summary + content
498 }
499 rid, _ = jsongetstring(obj, "inReplyTo")
500 convoy, _ = jsongetstring(obj, "context")
501 if convoy == "" {
502 convoy, _ = jsongetstring(obj, "conversation")
503 }
504 if what == "honk" && rid != "" {
505 what = "tonk"
506 if needxonkid(user, rid) {
507 saveoneup(rid)
508 }
509 }
510 }
511 if ot == "Tombstone" {
512 rid, _ = jsongetstring(obj, "id")
513 }
514 atts, _ := jsongetarray(obj, "attachment")
515 for _, att := range atts {
516 at, _ := jsongetstring(att, "type")
517 mt, _ := jsongetstring(att, "mediaType")
518 u, _ := jsongetstring(att, "url")
519 name, _ := jsongetstring(att, "name")
520 if at == "Document" {
521 mt = strings.ToLower(mt)
522 log.Printf("attachment: %s %s", mt, u)
523 if mt == "image/jpeg" || mt == "image/png" ||
524 mt == "image/gif" || mt == "text/plain" {
525 donk := savedonk(u, name, mt)
526 if donk != nil {
527 xonk.Donks = append(xonk.Donks, donk)
528 }
529 }
530 }
531 }
532 tags, _ := jsongetarray(obj, "tag")
533 for _, tag := range tags {
534 tt, _ := jsongetstring(tag, "type")
535 name, _ := jsongetstring(tag, "name")
536 if tt == "Emoji" {
537 icon, _ := jsongetmap(tag, "icon")
538 mt, _ := jsongetstring(icon, "mediaType")
539 if mt == "" {
540 mt = "image/png"
541 }
542 u, _ := jsongetstring(icon, "url")
543 donk := savedonk(u, name, mt)
544 if donk != nil {
545 xonk.Donks = append(xonk.Donks, donk)
546 }
547 }
548 }
549 }
550 audience = append(audience, who)
551
552 audience = oneofakind(audience)
553
554 xonk.UserID = user.ID
555 xonk.What = what
556 xonk.Honker = who
557 xonk.XID = xid
558 xonk.RID = rid
559 xonk.Date, _ = time.Parse(time.RFC3339, dt)
560 xonk.URL = url
561 xonk.Noise = content
562 xonk.Audience = audience
563 xonk.Convoy = convoy
564
565 return &xonk
566 }
567
568 return xonkxonkfn(item)
569}
570
571func rubadubdub(user *WhatAbout, req map[string]interface{}) {
572 xid, _ := jsongetstring(req, "id")
573 reqactor, _ := jsongetstring(req, "actor")
574 j := NewJunk()
575 j["@context"] = itiswhatitis
576 j["id"] = user.URL + "/dub/" + xid
577 j["type"] = "Accept"
578 j["actor"] = user.URL
579 j["to"] = reqactor
580 j["published"] = time.Now().UTC().Format(time.RFC3339)
581 j["object"] = req
582
583 WriteJunk(os.Stdout, j)
584
585 actor, _ := jsongetstring(req, "actor")
586 box, err := getboxes(actor)
587 if err != nil {
588 log.Printf("can't get dub box: %s", err)
589 return
590 }
591 keyname, key := ziggy(user.Name)
592 err = PostJunk(keyname, key, box.In, j)
593 if err != nil {
594 log.Printf("can't rub a dub: %s", err)
595 return
596 }
597 stmtSaveDub.Exec(user.ID, actor, actor, "dub")
598}
599
600func itakeitallback(user *WhatAbout, xid string) error {
601 j := NewJunk()
602 j["@context"] = itiswhatitis
603 j["id"] = user.URL + "/unsub/" + xid
604 j["type"] = "Undo"
605 j["actor"] = user.URL
606 j["to"] = xid
607 f := NewJunk()
608 f["id"] = user.URL + "/sub/" + xid
609 f["type"] = "Follow"
610 f["actor"] = user.URL
611 f["to"] = xid
612 j["object"] = f
613 j["published"] = time.Now().UTC().Format(time.RFC3339)
614
615 box, err := getboxes(xid)
616 if err != nil {
617 return err
618 }
619 keyname, key := ziggy(user.Name)
620 err = PostJunk(keyname, key, box.In, j)
621 if err != nil {
622 return err
623 }
624 return nil
625}
626
627func subsub(user *WhatAbout, xid string) {
628 j := NewJunk()
629 j["@context"] = itiswhatitis
630 j["id"] = user.URL + "/sub/" + xid
631 j["type"] = "Follow"
632 j["actor"] = user.URL
633 j["to"] = xid
634 j["object"] = xid
635 j["published"] = time.Now().UTC().Format(time.RFC3339)
636
637 box, err := getboxes(xid)
638 if err != nil {
639 log.Printf("can't send follow: %s", err)
640 return
641 }
642 WriteJunk(os.Stdout, j)
643 keyname, key := ziggy(user.Name)
644 err = PostJunk(keyname, key, box.In, j)
645 if err != nil {
646 log.Printf("failed to subsub: %s", err)
647 }
648}
649
650func jonkjonk(user *WhatAbout, h *Honk) (map[string]interface{}, map[string]interface{}) {
651 dt := h.Date.Format(time.RFC3339)
652 var jo map[string]interface{}
653 j := NewJunk()
654 j["id"] = user.URL + "/" + h.What + "/" + h.XID
655 j["actor"] = user.URL
656 j["published"] = dt
657 j["to"] = h.Audience[0]
658 if len(h.Audience) > 1 {
659 j["cc"] = h.Audience[1:]
660 }
661
662 switch h.What {
663 case "zonk":
664 fallthrough
665 case "tonk":
666 fallthrough
667 case "honk":
668 j["type"] = "Create"
669 if h.What == "zonk" {
670 j["type"] = "Delete"
671 }
672
673 jo = NewJunk()
674 jo["id"] = user.URL + "/h/" + h.XID
675 jo["type"] = "Note"
676 if h.What == "zonk" {
677 jo["type"] = "Tombstone"
678 }
679 jo["published"] = dt
680 jo["url"] = user.URL + "/h/" + h.XID
681 jo["attributedTo"] = user.URL
682 if h.RID != "" {
683 jo["inReplyTo"] = h.RID
684 }
685 if h.Convoy != "" {
686 jo["context"] = h.Convoy
687 jo["conversation"] = h.Convoy
688 }
689 jo["to"] = h.Audience[0]
690 if len(h.Audience) > 1 {
691 jo["cc"] = h.Audience[1:]
692 }
693 jo["content"] = mentionize(h.Noise)
694 jo["summary"] = nil
695 var tags []interface{}
696 g := bunchofgrapes(h.Noise)
697 for _, m := range g {
698 t := NewJunk()
699 t["type"] = "Mention"
700 t["name"] = m.who
701 t["href"] = m.where
702 tags = append(tags, t)
703 }
704 herd := herdofemus(h.Noise)
705 for _, e := range herd {
706 t := NewJunk()
707 t["id"] = e.ID
708 t["type"] = "Emoji"
709 t["name"] = e.Name
710 i := NewJunk()
711 i["type"] = "Image"
712 i["mediaType"] = "image/png"
713 i["url"] = e.ID
714 t["icon"] = i
715 tags = append(tags, t)
716 }
717 if len(tags) > 0 {
718 jo["tag"] = tags
719 }
720 var atts []interface{}
721 for _, d := range h.Donks {
722 if re_emus.MatchString(d.Name) {
723 continue
724 }
725 jd := NewJunk()
726 jd["mediaType"] = d.Media
727 jd["name"] = d.Name
728 jd["type"] = "Document"
729 jd["url"] = d.URL
730 atts = append(atts, jd)
731 }
732 if len(atts) > 0 {
733 jo["attachment"] = atts
734 }
735 j["object"] = jo
736 case "bonk":
737 j["type"] = "Announce"
738 j["object"] = h.XID
739 }
740
741 return j, jo
742}
743
744func honkworldwide(user *WhatAbout, honk *Honk) {
745 jonk, _ := jonkjonk(user, honk)
746 jonk["@context"] = itiswhatitis
747 var buf bytes.Buffer
748 WriteJunk(&buf, jonk)
749 msg := buf.Bytes()
750
751 rcpts := make(map[string]bool)
752 for _, a := range honk.Audience {
753 if a != thewholeworld && a != user.URL && !strings.HasSuffix(a, "/followers") {
754 box, _ := getboxes(a)
755 if box != nil && box.Shared != "" {
756 rcpts["%"+box.Shared] = true
757 } else {
758 rcpts[a] = true
759 }
760 }
761 }
762 for _, f := range getdubs(user.ID) {
763 box, _ := getboxes(f.XID)
764 if box != nil && box.Shared != "" {
765 rcpts["%"+box.Shared] = true
766 } else {
767 rcpts[f.XID] = true
768 }
769 }
770 for a := range rcpts {
771 go deliverate(0, user.Name, a, msg)
772 }
773}
774
775func asjonker(user *WhatAbout) map[string]interface{} {
776 about := obfusbreak(user.About)
777
778 j := NewJunk()
779 j["@context"] = itiswhatitis
780 j["id"] = user.URL
781 j["type"] = "Person"
782 j["inbox"] = user.URL + "/inbox"
783 j["outbox"] = user.URL + "/outbox"
784 j["followers"] = user.URL + "/followers"
785 j["following"] = user.URL + "/following"
786 j["name"] = user.Display
787 j["preferredUsername"] = user.Name
788 j["summary"] = about
789 j["url"] = user.URL
790 a := NewJunk()
791 a["type"] = "icon"
792 a["mediaType"] = "image/png"
793 a["url"] = fmt.Sprintf("https://%s/a?a=%s", serverName, url.QueryEscape(user.URL))
794 j["icon"] = a
795 k := NewJunk()
796 k["id"] = user.URL + "#key"
797 k["owner"] = user.URL
798 k["publicKeyPem"] = user.Key
799 j["publicKey"] = k
800
801 return j
802}