接通 Windows 与 Web 设备间加密文字聊天
This commit is contained in:
1 parent
b04034ee89
commit
d1efdedc57
27 files changed
+880
-22
No files matched your search
@@ -53,6 +53,8 @@ func New(accounts *account.Store, contactStore *contacts.Store, envelopeStore *d
|
||||
mux.HandleFunc("GET /api/v1/contacts/{id}/devices", a.authorized(a.contactDevices))
|
||||
mux.HandleFunc("POST /api/v1/contacts/{id}/devices/{device}/claim", a.authorized(a.claimPackage))
|
||||
mux.HandleFunc("POST /api/v1/key-packages", a.authorized(a.publishPackage))
|
||||
mux.HandleFunc("POST /api/v1/mls-credential", a.authorized(a.publishCredential))
|
||||
mux.HandleFunc("GET /api/v1/mls-local-key", a.authorized(a.localMLSKey))
|
||||
return a.boundary(mux)
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
package httpapi
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"xhchat/server/internal/account"
|
||||
"xhchat/server/internal/delivery"
|
||||
)
|
||||
|
||||
func (a *API) localMLSKey(w http.ResponseWriter, r *http.Request, _ string, identity account.Identity) {
|
||||
key, err := a.delivery.LocalIdentityKey(r.Context(), identity.Device.ID)
|
||||
if errors.Is(err, delivery.ErrUnavailable) {
|
||||
problem(w, 404, "device_not_found", "设备不可用")
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
unavailable(w, err)
|
||||
return
|
||||
}
|
||||
respond(w, 200, map[string][]byte{"publicKey": key})
|
||||
}
|
||||
|
||||
func (a *API) publishCredential(w http.ResponseWriter, r *http.Request, _ string, identity account.Identity) {
|
||||
var input delivery.Credential
|
||||
if !parse(w, r, &input) {
|
||||
return
|
||||
}
|
||||
if len(input.PublicKey) != 32 || len(input.Signature) != 64 {
|
||||
problem(w, 400, "invalid_credential", "MLS 设备凭据格式无效")
|
||||
return
|
||||
}
|
||||
err := a.delivery.PublishCredential(r.Context(), identity.User.ID, identity.Device.ID, input)
|
||||
switch {
|
||||
case errors.Is(err, delivery.ErrSignature):
|
||||
problem(w, 400, "invalid_credential_signature", "MLS 设备凭据签名无效")
|
||||
case errors.Is(err, delivery.ErrConflict):
|
||||
problem(w, 409, "credential_changed", "该设备已绑定其他 MLS 密钥")
|
||||
case errors.Is(err, delivery.ErrUnavailable):
|
||||
problem(w, 404, "device_not_found", "设备不可用")
|
||||
case err != nil:
|
||||
unavailable(w, err)
|
||||
default:
|
||||
w.WriteHeader(204)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user