예제 #1
0
파일: blob.go 프로젝트: jaredhanson/webfist
func (s *server) ServeBlob(w http.ResponseWriter, r *http.Request) {
	if r.ParseForm() != nil {
		log.Printf("Could not parse form: %+v", r)
		http.Error(w, "Bad request", http.StatusBadRequest)
		return
	}

	base := path.Base(r.URL.Path)
	parts := strings.SplitN(base, "-", 2)
	if len(parts) != 2 {
		log.Printf("Invalid blob path: %q", r.URL.Path)
		http.Error(w, "Bad request", http.StatusBadRequest)
		return
	}

	hexKey, encSHA1 := parts[0], parts[1]

	all, err := s.storage.EncryptedEmail(hexKey, encSHA1)
	if err != nil {
		http.NotFound(w, r)
		return
	}

	decryptKey := r.Form.Get("decrypt")
	if decryptKey == "" {
		w.Header().Add("Content-Type", "application/octet-stream")
		w.Write(all)
		return
	}

	addr := webfist.NewEmailAddr(decryptKey)
	decrypted, err := ioutil.ReadAll(addr.Decrypter(bytes.NewReader(all)))
	if err != nil {
		http.Error(w, "Could not decrypt blob", http.StatusInternalServerError)
		return
	}

	w.Header().Add("Content-Type", "text/plain; charset=utf-8")
	w.Header().Add("Access-Control-Allow-Origin", "*")
	w.Write(decrypted)
}
예제 #2
0
func (l *emailLookup) WebFinger(addr string) (*webfist.WebFingerResponse, error) {
	emailAddr := webfist.NewEmailAddr(addr)
	emailList, err := l.storage.Emails(emailAddr)
	if err != nil {
		return nil, err
	}
	if len(emailList) == 0 {
		return nil, nil
	}
	sort.Sort(byEmailDate(emailList))
	lastEmail := emailList[len(emailList)-1]
	// TODO: Garbage collect old emails

	delegationURL, err := lastEmail.WebFist()
	if err != nil {
		return nil, err
	}
	encSHA1, err := lastEmail.EncSHA1()
	if err != nil {
		return nil, err
	}
	proofURL := fmt.Sprintf("%s/webfist/proof/%s-%s?decrypt=%s", *baseURL, emailAddr.HexKey(), encSHA1, url.QueryEscape(emailAddr.Canonical()))

	resp := &webfist.WebFingerResponse{
		Subject: emailAddr.Canonical(),
		Links: []webfist.Link{
			{
				Rel:  "http://webfist.org/spec/rel",
				Href: delegationURL,
				Properties: map[string]string{
					"http://webfist.org/spec/proof": proofURL,
				},
			},
		},
	}
	return resp, nil
}
예제 #3
0
파일: smtp.go 프로젝트: jaredhanson/webfist
func (s *server) onNewMail(conn smtpd.Connection, from smtpd.MailAddress) (smtpd.Envelope, error) {
	log.Printf("smtp: new mail from %s", from.Email())
	return &env{s: s, from: webfist.NewEmailAddr(from.Email())}, nil
}