diff --git a/clientApp/GUI/views/main/main.html b/clientApp/GUI/views/main/main.html index 49ed9fe..eee21ac 100755 --- a/clientApp/GUI/views/main/main.html +++ b/clientApp/GUI/views/main/main.html @@ -25,7 +25,7 @@

My IDs

-
+
Public Key: {{id.pubK}} @@ -40,11 +40,12 @@ Verified
- Not signed - Signed + Not signed + Signed
-
Send to serverIDsigner
-
Verify
+

+
Send to serverIDsigner
+
diff --git a/clientApp/GUI/views/main/main.js b/clientApp/GUI/views/main/main.js index a1d1894..08805b8 100755 --- a/clientApp/GUI/views/main/main.js +++ b/clientApp/GUI/views/main/main.js @@ -39,8 +39,8 @@ angular.module('app.main', ['ngRoute']) }); }; - $scope.blindAndSendToSign = function(pubK) { - $http.get(clientapi + 'blindandsendtosign/' + pubK) + $scope.blindAndSendToSign = function(id) { + $http.get(clientapi + 'blindandsendtosign/' + id) .then(function(data) { console.log('data success'); console.log(data); @@ -50,8 +50,8 @@ angular.module('app.main', ['ngRoute']) console.log('data error'); }); }; - $scope.verify = function(pubK) { - $http.get(clientapi + 'verify/' + pubK) + $scope.verify = function(id) { + $http.get(clientapi + 'verify/' + id) .then(function(data) { console.log('data success'); console.log(data); diff --git a/clientApp/clientApp.go b/clientApp/clientApp.go index 9f27225..353b167 100644 --- a/clientApp/clientApp.go +++ b/clientApp/clientApp.go @@ -12,6 +12,7 @@ import ( "github.com/cryptoballot/fdh" "github.com/cryptoballot/rsablind" + "github.com/fatih/color" ) func IDs() []Key { @@ -51,18 +52,33 @@ type SignResponse struct { PubK rsa.PublicKey `json:"pubK"` } -func BlindAndSendToSign(keyID string) []byte { +func BlindAndSendToSign(keyID string) []Key { //get the key key := getKeyByKeyID(keyID) //privK := openPEMKey(key.PrivK) - pubK := openPublicPEMKey(key.PubK) + pubK, err := openPublicPEMKey(keysDir + "/" + key.PubK) + check(err) + + //pubK to string + m, err := ExportRsaPublicKeyAsPemStr(pubK) + check(err) + mB := []byte(m) + + //get serverPubK + var serverPubK *rsa.PublicKey + res, err := http.Get(config.Server) + check(err) + decoder := json.NewDecoder(res.Body) + err = decoder.Decode(&serverPubK) + if err != nil { + panic(err) + } + defer res.Body.Close() - //TODO pubK to string - m := []byte("pubK") //convert pubK to array of bytes //blind the hashed message // We do a SHA256 full-domain-hash expanded to 1536 bits (3/4 the key size) - hashed := fdh.Sum(crypto.SHA256, hashize, m) - blinded, unblinder, err := rsablind.Blind(&pubK, hashed) + hashed := fdh.Sum(crypto.SHA256, hashize, mB) + blinded, unblinder, err := rsablind.Blind(serverPubK, hashed) if err != nil { panic(err) } @@ -71,10 +87,10 @@ func BlindAndSendToSign(keyID string) []byte { //send blinded to serverIDsigner body := new(bytes.Buffer) json.NewEncoder(body).Encode(askBlindSign) - res, err := http.Post(config.Server+"blindsign", "application/json", body) + res, err = http.Post(config.Server+"blindsign", "application/json", body) check(err) var signResponse SignResponse - decoder := json.NewDecoder(res.Body) + decoder = json.NewDecoder(res.Body) err = decoder.Decode(&signResponse) if err != nil { panic(err) @@ -82,13 +98,26 @@ func BlindAndSendToSign(keyID string) []byte { defer res.Body.Close() sig := signResponse.Sig - serverPubK := signResponse.PubK + //serverPubK := signResponse.PubK //unblind the signedblind - unblindedSig := rsablind.Unblind(&serverPubK, sig, unblinder) + unblindedSig := rsablind.Unblind(serverPubK, sig, unblinder) + color.Green("unblindedSig") fmt.Println(unblindedSig) - return unblindedSig + // Verify the original hashed message against the unblinded signature + if err := rsablind.VerifyBlindSignature(serverPubK, hashed, unblindedSig); err != nil { + fmt.Println(err) + } else { + color.Green("blind signature verified") + key.Verified = true + } + key.UnblindedSig = unblindedSig + key.Hashed = hashed + key.ServerVerifier = serverPubK + saveKey(key) + keys := readKeys() + return keys } func Verify(packPubK string) { diff --git a/clientApp/clientAppRESTFunctions.go b/clientApp/clientAppRESTFunctions.go index 9f2963f..2ce7f69 100644 --- a/clientApp/clientAppRESTFunctions.go +++ b/clientApp/clientAppRESTFunctions.go @@ -40,9 +40,9 @@ func GetBlindAndSendToSign(w http.ResponseWriter, r *http.Request) { idKey := vars["idKey"] color.Green(idKey) - unblindedSig := BlindAndSendToSign(idKey) + keys := BlindAndSendToSign(idKey) - jResp, err := json.Marshal(unblindedSig) + jResp, err := json.Marshal(keys) check(err) fmt.Fprintln(w, string(jResp)) } diff --git a/clientApp/keys.go b/clientApp/keys.go index d3b17be..9d946de 100644 --- a/clientApp/keys.go +++ b/clientApp/keys.go @@ -6,18 +6,67 @@ import ( "encoding/asn1" "encoding/json" "encoding/pem" + "errors" + "fmt" "io/ioutil" "os" "time" + + "github.com/fatih/color" ) type Key struct { - ID string `json:"id"` - PrivK string `json:"privK"` //path of the PrivK file - PubK string `json:"pubK"` //path of the PubK file - Date time.Time `json:"date"` - Verified bool `json:"verified"` - Signed string `json:"signed"` + ID string `json:"id"` + PrivK string `json:"privK"` //path of the PrivK file + PubK string `json:"pubK"` //path of the PubK file + Date time.Time `json:"date"` + Hashed []byte `json:"hashed"` + UnblindedSig []byte `json:"unblindedsig"` + Verified bool `json:"verified"` + ServerVerifier *rsa.PublicKey `json:"serververifier"` +} + +func ExportRsaPrivateKeyAsPemStr(privkey *rsa.PrivateKey) string { + privkey_bytes := x509.MarshalPKCS1PrivateKey(privkey) + privkey_pem := pem.EncodeToMemory( + &pem.Block{ + Type: "RSA PRIVATE KEY", + Bytes: privkey_bytes, + }, + ) + return string(privkey_pem) +} + +func ParseRsaPrivateKeyFromPemStr(privPEM string) (*rsa.PrivateKey, error) { + block, _ := pem.Decode([]byte(privPEM)) + if block == nil { + return nil, errors.New("failed to parse PEM block containing the key") + } + priv, err := x509.ParsePKCS1PrivateKey(block.Bytes) + if err != nil { + return nil, err + } + return priv, nil +} + +func ExportRsaPublicKeyAsPemStr(pubkey rsa.PublicKey) (string, error) { + asn1Bytes, err := asn1.Marshal(pubkey) + check(err) + pubkey_pem := pem.EncodeToMemory( + &pem.Block{ + Type: "PUBLIC KEY", + Bytes: asn1Bytes, + }, + ) + color.Red("pubkey_pem") + fmt.Println(pubkey_pem) + return string(pubkey_pem), nil +} + +func ParseRsaPublicKeyFromPemStr(pubPEM string) (pub rsa.PublicKey, err error) { + pemBlock, _ := pem.Decode([]byte(pubPEM)) + _, err = asn1.Unmarshal(pemBlock.Bytes, &pub) + return } func savePEMKey(fileName string, key *rsa.PrivateKey) { @@ -49,10 +98,20 @@ func savePublicPEMKey(fileName string, pubkey rsa.PublicKey) { err = pem.Encode(pemfile, pemkey) check(err) } -func openPEMKey(path string) (key rsa.PrivateKey) { +func openPEMKey(path string) (key *rsa.PrivateKey, err error) { + b, err := ioutil.ReadFile(path) + if err != nil { + fmt.Print(err) + } + key, err = ParseRsaPrivateKeyFromPemStr(string(b)) return } -func openPublicPEMKey(path string) (key rsa.PublicKey) { +func openPublicPEMKey(path string) (key rsa.PublicKey, err error) { + b, err := ioutil.ReadFile(path) + if err != nil { + fmt.Print(err) + } + key, err = ParseRsaPublicKeyFromPemStr(string(b)) return } func readKeys() []Key { @@ -73,6 +132,16 @@ func saveKeys(keys []Key) { err = ioutil.WriteFile(keysDir+"/keys.json", jsonKeys, 0644) check(err) } +func saveKey(k Key) { + fmt.Println(k) + keys := readKeys() + for i, key := range keys { + if key.ID == k.ID { + keys[i] = k + } + } + saveKeys(keys) +} func getKeyByKeyID(keyID string) (k Key) { keys := readKeys() for _, key := range keys { diff --git a/documentation/screenshot02.png b/documentation/screenshot02.png index 6808745..a9336e6 100644 Binary files a/documentation/screenshot02.png and b/documentation/screenshot02.png differ diff --git a/serverIDsigner/.gitignore b/serverIDsigner/.gitignore new file mode 100644 index 0000000..0bdfd49 --- /dev/null +++ b/serverIDsigner/.gitignore @@ -0,0 +1 @@ +keys diff --git a/serverIDsigner/keys/server_private.pem b/serverIDsigner/keys/server_private.pem deleted file mode 100644 index 0ef88e5..0000000 --- a/serverIDsigner/keys/server_private.pem +++ /dev/null @@ -1,27 +0,0 @@ ------BEGIN PRIVATE KEY----- -MIIEpQIBAAKCAQEA061q3ahXEG9rHf/uekmIk4fSvtG8p7OwkjP3PlafFjxeA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jAvR5t8NnzFDNJuaXCju5kt2RRfszwOBizNViO -jfRzk0hQUsiSA4d4TvAfDS6B3YGxDPJ/HEtK02tXmaTbhDVFnyOVOPw10tspD/zs -NB5iQpfKwtTYnpfH04Y5RuSfAoGAMVzfkgjZXUpl+iepYrOgY3sMm5I9d6QUUa6v -r7WLG3+FdUJyZ95rHliTSghIsczYE8XQBDH0ntavN1Wja0+ra2fb8kMzwQMuJskx -HIKdHbOfwqumcyhyGpkQX0edXdQz5uCJ/utvSQbxVJDvh7Hi2/w0VgCWxkjraR0u -6Ok7YUsCgYEAjiJng9gj3GGZ6noBZ+lcK2VU839yExkJzj68lBzviMeD0kuyVN7R -fNpUOtjgR1a2paJLyXFq2a2AyhakA6r87GGGAGW3o6TCEw3jTXcc2L3CX113Ee5N -DbXbE9rXB8OT0q/x1ugoel+nFQMW+wwAigMl50DcENczyStJNQoXP9I= ------END PRIVATE KEY----- diff --git a/serverIDsigner/keys/server_public.pem b/serverIDsigner/keys/server_public.pem deleted file mode 100644 index a0ae717..0000000 --- a/serverIDsigner/keys/server_public.pem +++ /dev/null @@ -1,8 +0,0 @@ ------BEGIN PUBLIC KEY----- -MIIBCgKCAQEA061q3ahXEG9rHf/uekmIk4fSvtG8p7OwkjP3PlafFjxeA4BS8dkj -PUEboXMftQCFrzWc5nLyQR4Ig5xMzjaEbQv/JBdpP/E1nl+fC6ca45Rov0OE7OQr -DyEPb1qNJ3uQmh+N9ZvTLNndT3bBxtBfmIRyMq+78mMumzNvFbx6zfNpwv9THDgB -nfZoAZ7gpIZeKn/yFasQmzFwpy9hfqZ21SCL7GmiU+nAz2TxtyFkUttMeIxDgSSK -LYxzt6mKdElNv0K97tBU1eRaXz4hpq/I0dtmcidrS/45MtXij6wO1agIvnH+pygS -I5QF3rE+lVYaDuKJZ6QBvnNEF9/cu7j/ZQIDAQAB ------END PUBLIC KEY----- diff --git a/serverIDsigner/userRESTFunctions.go b/serverIDsigner/userRESTFunctions.go index a4af5c5..4f655d7 100644 --- a/serverIDsigner/userRESTFunctions.go +++ b/serverIDsigner/userRESTFunctions.go @@ -20,9 +20,8 @@ type User struct { } func Index(w http.ResponseWriter, r *http.Request) { - //TODO return the public key, to allow others verifign signed strings by this server - - jResp, err := json.Marshal("a") + // return server public key, to allow others verifign signed strings by this server + jResp, err := json.Marshal(serverKey.PublicKey) if err != nil { panic(err) }