Changed public whisper api not to reveal temporary private keys

pull/258/merge
obscuren 10 years ago
parent bb55307a9d
commit 62e0e18030
  1. 35
      cmd/mist/assets/qml/browser.qml
  2. 4
      ui/qt/qwhisper/message.go
  3. 15
      ui/qt/qwhisper/whisper.go
  4. 17
      whisper/whisper.go

@ -1,4 +1,4 @@
import QtQuick 2.0
import QtQuick 2.1
import QtWebKit 3.0
import QtWebKit.experimental 1.0
import QtQuick.Controls 1.0;
@ -164,6 +164,35 @@ Rectangle {
experimental.preferences.javascriptEnabled: true
experimental.preferences.webGLEnabled: true
experimental.itemSelector: MouseArea {
// To avoid conflicting with ListView.model when inside Initiator context.
property QtObject selectorModel: model
anchors.fill: parent
onClicked: selectorModel.reject()
Menu {
visible: true
id: itemSelector
Instantiator {
model: selectorModel.items
delegate: MenuItem {
text: model.text
onTriggered: {
selectorModel.accept(index)
}
}
onObjectAdded: itemSelector.insertItem(index, object)
onObjectRemoved: itemSelector.removeItem(object)
}
}
Component.onCompleted: {
itemSelector.popup()
}
}
experimental.preferences.webAudioEnabled: true
experimental.preferences.navigatorQtObjectEnabled: true
experimental.preferences.developerExtrasEnabled: true
experimental.userScripts: ["../ext/q.js", "../ext/ethereum.js/lib/web3.js", "../ext/ethereum.js/lib/qt.js", "../ext/setup.js"]
@ -362,6 +391,10 @@ Rectangle {
postData(data._id, messages);
break;
case "ssh_newGroup":
postData(data._id, "");
break;
}
} catch(e) {
console.log(data.call + ": " + e)

@ -17,7 +17,7 @@ func ToQMessage(msg *whisper.Message) *Message {
return &Message{
ref: msg,
Flags: int32(msg.Flags),
Payload: ethutil.Bytes2Hex(msg.Payload),
From: ethutil.Bytes2Hex(crypto.FromECDSAPub(msg.Recover())),
Payload: "0x" + ethutil.Bytes2Hex(msg.Payload),
From: "0x" + ethutil.Bytes2Hex(crypto.FromECDSAPub(msg.Recover())),
}
}

@ -41,13 +41,16 @@ func (self *Whisper) Post(payload []string, to, from string, topics []string, pr
data = append(data, fromHex(d)...)
}
pk := crypto.ToECDSAPub(fromHex(from))
if key := self.Whisper.GetIdentity(pk); key != nil {
msg := whisper.NewMessage(data)
envelope, err := msg.Seal(time.Duration(priority*100000), whisper.Opts{
Ttl: time.Duration(ttl) * time.Second,
To: crypto.ToECDSAPub(fromHex(to)),
From: crypto.ToECDSA(fromHex(from)),
From: key,
Topics: whisper.TopicsFromString(topics...),
})
if err != nil {
qlogger.Infoln(err)
// handle error
@ -59,14 +62,20 @@ func (self *Whisper) Post(payload []string, to, from string, topics []string, pr
// handle error
return
}
} else {
qlogger.Infoln("unmatched pub / priv for seal")
}
}
func (self *Whisper) NewIdentity() string {
return toHex(self.Whisper.NewIdentity().D.Bytes())
key := self.Whisper.NewIdentity()
return toHex(crypto.FromECDSAPub(&key.PublicKey))
}
func (self *Whisper) HasIdentity(key string) bool {
return self.Whisper.HasIdentity(crypto.ToECDSA(fromHex(key)))
return self.Whisper.HasIdentity(crypto.ToECDSAPub(fromHex(key)))
}
func (self *Whisper) Watch(opts map[string]interface{}, view *qml.Common) int {

@ -60,7 +60,7 @@ type Whisper struct {
quit chan struct{}
keys []*ecdsa.PrivateKey
keys map[string]*ecdsa.PrivateKey
}
func New() *Whisper {
@ -69,6 +69,7 @@ func New() *Whisper {
filters: filter.New(),
expiry: make(map[uint32]*set.SetNonTS),
quit: make(chan struct{}),
keys: make(map[string]*ecdsa.PrivateKey),
}
whisper.filters.Start()
@ -101,18 +102,18 @@ func (self *Whisper) NewIdentity() *ecdsa.PrivateKey {
if err != nil {
panic(err)
}
self.keys = append(self.keys, key)
self.keys[string(crypto.FromECDSAPub(&key.PublicKey))] = key
return key
}
func (self *Whisper) HasIdentity(key *ecdsa.PrivateKey) bool {
for _, key := range self.keys {
if key.D.Cmp(key.D) == 0 {
return true
func (self *Whisper) HasIdentity(key *ecdsa.PublicKey) bool {
return self.keys[string(crypto.FromECDSAPub(key))] != nil
}
}
return false
func (self *Whisper) GetIdentity(key *ecdsa.PublicKey) *ecdsa.PrivateKey {
return self.keys[string(crypto.FromECDSAPub(key))]
}
func (self *Whisper) Watch(opts Filter) int {

Loading…
Cancel
Save