You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123 lines
2.4 KiB

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
  1. package main
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "net/http"
  6. "github.com/fatih/color"
  7. "github.com/gorilla/mux"
  8. )
  9. func Index(w http.ResponseWriter, r *http.Request) {
  10. fmt.Fprintln(w, "clientApp")
  11. }
  12. func GetServer(w http.ResponseWriter, r *http.Request) {
  13. color.Green(config.Server)
  14. fmt.Fprintln(w, config.Server)
  15. }
  16. func GetIDs(w http.ResponseWriter, r *http.Request) {
  17. keys := IDs()
  18. jResp, err := json.Marshal(keys)
  19. check(err)
  20. fmt.Fprintln(w, string(jResp))
  21. }
  22. func GetID(w http.ResponseWriter, r *http.Request) {
  23. vars := mux.Vars(r)
  24. keyID := vars["keyid"]
  25. key := getKeyByKeyID(keyID)
  26. jResp, err := json.Marshal(key)
  27. check(err)
  28. fmt.Fprintln(w, string(jResp))
  29. }
  30. func GetNewID(w http.ResponseWriter, r *http.Request) {
  31. key := NewID()
  32. fmt.Println(key)
  33. jResp, err := json.Marshal(key)
  34. check(err)
  35. fmt.Fprintln(w, string(jResp))
  36. }
  37. func GetBlindAndSendToSign(w http.ResponseWriter, r *http.Request) {
  38. vars := mux.Vars(r)
  39. idKey := vars["keyid"]
  40. color.Green(idKey)
  41. keys := BlindAndSendToSign(idKey)
  42. jResp, err := json.Marshal(keys)
  43. check(err)
  44. fmt.Fprintln(w, string(jResp))
  45. }
  46. func GetVerify(w http.ResponseWriter, r *http.Request) {
  47. vars := mux.Vars(r)
  48. packPubK := vars["pubK"]
  49. color.Green(packPubK)
  50. //keys := Verify(packPubK)
  51. keys := "a"
  52. jResp, err := json.Marshal(keys)
  53. check(err)
  54. fmt.Fprintln(w, string(jResp))
  55. }
  56. func GetDelete(w http.ResponseWriter, r *http.Request) {
  57. vars := mux.Vars(r)
  58. keyID := vars["keyid"]
  59. keys := Delete(keyID)
  60. jResp, err := json.Marshal(keys)
  61. check(err)
  62. fmt.Fprintln(w, string(jResp))
  63. }
  64. type EncryptData struct {
  65. M string `json:"m"`
  66. C []byte `json:"c"`
  67. }
  68. func PostEncrypt(w http.ResponseWriter, r *http.Request) {
  69. vars := mux.Vars(r)
  70. keyID := vars["keyid"]
  71. //get ciphertext from POST json
  72. decoder := json.NewDecoder(r.Body)
  73. var encryptData EncryptData
  74. err := decoder.Decode(&encryptData)
  75. if err != nil {
  76. panic(err)
  77. }
  78. defer r.Body.Close()
  79. encryptData = Encrypt(keyID, encryptData)
  80. jResp, err := json.Marshal(encryptData)
  81. check(err)
  82. fmt.Fprintln(w, string(jResp))
  83. }
  84. func PostDecrypt(w http.ResponseWriter, r *http.Request) {
  85. vars := mux.Vars(r)
  86. keyID := vars["keyid"]
  87. //get ciphertext from POST json
  88. decoder := json.NewDecoder(r.Body)
  89. var encryptData EncryptData
  90. err := decoder.Decode(&encryptData)
  91. if err != nil {
  92. panic(err)
  93. }
  94. defer r.Body.Close()
  95. encryptData = Decrypt(keyID, encryptData)
  96. jResp, err := json.Marshal(encryptData)
  97. check(err)
  98. fmt.Fprintln(w, string(jResp))
  99. }