Skip to content
Snippets Groups Projects
Commit 6f34f0bb authored by inso's avatar inso
Browse files

Signing is now available !

parent 19542ef7
Branches
Tags
No related merge requests found
...@@ -123,7 +123,7 @@ class API(object): ...@@ -123,7 +123,7 @@ class API(object):
Arguments: Arguments:
- `path`: the request path - `path`: the request path
""" """
if 'self_' in kwargs.keys(): if 'self_' in kwargs:
kwargs['self'] = kwargs.pop('self_') kwargs['self'] = kwargs.pop('self_')
logging.debug("POST : {0}".format(kwargs)) logging.debug("POST : {0}".format(kwargs))
......
...@@ -4,7 +4,9 @@ Created on 3 déc. 2014 ...@@ -4,7 +4,9 @@ Created on 3 déc. 2014
@author: inso @author: inso
''' '''
import base58 import base58
import base64
import re import re
import logging
from ..key import Base58Encoder from ..key import Base58Encoder
class Document: class Document:
...@@ -15,7 +17,10 @@ class Document: ...@@ -15,7 +17,10 @@ class Document:
def __init__(self, version, currency, signatures): def __init__(self, version, currency, signatures):
self.version = version self.version = version
self.currency = currency self.currency = currency
self.signatures = signatures if signatures:
self.signatures = [s for s in signatures if s is not None]
else:
self.signatures = []
def sign(self, keys): def sign(self, keys):
''' '''
...@@ -23,8 +28,10 @@ class Document: ...@@ -23,8 +28,10 @@ class Document:
Warning : current signatures will be replaced with the new ones. Warning : current signatures will be replaced with the new ones.
''' '''
self.signatures = [] self.signatures = []
for k in keys: for key in keys:
self.signatures.append(k.signature(self.raw())) signing = base64.b64encode(key.signature(bytes(self.raw(), 'ascii')))
logging.debug("Signature : \n{0}".format(signing.decode("ascii")))
self.signatures.append(signing.decode("ascii"))
def signed_raw(self): def signed_raw(self):
''' '''
...@@ -32,8 +39,6 @@ class Document: ...@@ -32,8 +39,6 @@ class Document:
If keys are present, returns the raw signed by these keys If keys are present, returns the raw signed by these keys
''' '''
raw = self.raw() raw = self.raw()
signed_raw = raw signed = "\n".join(self.signatures)
for s in self.signatures: signed_raw = raw + signed + "\n"
if s is not None:
signed_raw += s + "\n"
return signed_raw return signed_raw
...@@ -83,10 +83,7 @@ BOTTOM_SIGNATURE ...@@ -83,10 +83,7 @@ BOTTOM_SIGNATURE
''' '''
Constructor Constructor
''' '''
if signature:
super().__init__(version, currency, [signature]) super().__init__(version, currency, [signature])
else:
super().__init__(version, currency, [])
self.noonce = noonce self.noonce = noonce
self.number = number self.number = number
self.powmin = powmin self.powmin = powmin
......
...@@ -4,6 +4,8 @@ Created on 2 déc. 2014 ...@@ -4,6 +4,8 @@ Created on 2 déc. 2014
@author: inso @author: inso
''' '''
import re import re
import base64
import logging
from . import Document from . import Document
...@@ -40,6 +42,9 @@ class SelfCertification(Document): ...@@ -40,6 +42,9 @@ class SelfCertification(Document):
META:TS:{1} META:TS:{1}
""".format(self.uid, self.timestamp) """.format(self.uid, self.timestamp)
def signed_raw(self):
return super().signed_raw()[:-1]
def inline(self): def inline(self):
return "{0}:{1}:{2}:{3}".format(self.pubkey, self.signatures[0], return "{0}:{1}:{2}:{3}".format(self.pubkey, self.signatures[0],
self.timestamp, self.uid) self.timestamp, self.uid)
...@@ -78,15 +83,26 @@ class Certification(Document): ...@@ -78,15 +83,26 @@ class Certification(Document):
blockhash, blocknumber, signature) blockhash, blocknumber, signature)
def raw(self, selfcert): def raw(self, selfcert):
return """{0}META:TS:{1}-{2} return """{0}
META:TS:{1}-{2}
""".format(selfcert.signed_raw(), self.blocknumber, self.blockhash) """.format(selfcert.signed_raw(), self.blocknumber, self.blockhash)
def sign(self, selfcert, keys):
'''
Sign the current document.
Warning : current signatures will be replaced with the new ones.
'''
self.signatures = []
for key in keys:
signing = base64.b64encode(key.signature(bytes(self.raw(selfcert), 'ascii')))
logging.debug("Signature : \n{0}".format(signing.decode("ascii")))
self.signatures.append(signing.decode("ascii"))
def signed_raw(self, selfcert): def signed_raw(self, selfcert):
raw = self.raw(selfcert) raw = self.raw(selfcert)
signed_raw = raw signed = "\n".join(self.signatures)
for s in self.signatures: signed_raw = raw + signed + "\n"
if s is not None:
signed_raw += s + "\n"
return signed_raw return signed_raw
def inline(self): def inline(self):
......
...@@ -39,10 +39,7 @@ class Membership(Document): ...@@ -39,10 +39,7 @@ class Membership(Document):
''' '''
Constructor Constructor
''' '''
if signature:
super().__init__(version, currency, [signature]) super().__init__(version, currency, [signature])
else:
super().__init__(version, currency, [])
self.issuer = issuer self.issuer = issuer
self.block_number = block_number self.block_number = block_number
self.block_hash = block_hash self.block_hash = block_hash
......
...@@ -32,10 +32,7 @@ class Peer(Document): ...@@ -32,10 +32,7 @@ class Peer(Document):
def __init__(self, version, currency, pubkey, blockid, def __init__(self, version, currency, pubkey, blockid,
endpoints, signature): endpoints, signature):
if signature:
super().__init__(version, currency, [signature]) super().__init__(version, currency, [signature])
else:
super().__init__(version, currency, [])
self.pubkey = pubkey self.pubkey = pubkey
self.blockid = blockid self.blockid = blockid
......
...@@ -30,10 +30,7 @@ class Status(Document): ...@@ -30,10 +30,7 @@ class Status(Document):
''' '''
Constructor Constructor
''' '''
if signature:
super().__init__(version, currency, [signature]) super().__init__(version, currency, [signature])
else:
super().__init__(version, currency, [])
self.status = status self.status = status
self.blockid = blockid self.blockid = blockid
......
...@@ -54,10 +54,7 @@ SIGNATURE ...@@ -54,10 +54,7 @@ SIGNATURE
''' '''
Constructor Constructor
''' '''
if signatures:
super().__init__(version, currency, signatures) super().__init__(version, currency, signatures)
else:
super().__init__(version, currency, [])
self.issuers = issuers self.issuers = issuers
self.inputs = inputs self.inputs = inputs
...@@ -80,7 +77,7 @@ SIGNATURE ...@@ -80,7 +77,7 @@ SIGNATURE
inputs = [] inputs = []
outputs = [] outputs = []
signatures = [] signatures = []
logging.debug(compact)
for i in range(0, issuers_num): for i in range(0, issuers_num):
issuer = Transaction.re_pubkey.match(lines[n]).group(1) issuer = Transaction.re_pubkey.match(lines[n]).group(1)
issuers.append(issuer) issuers.append(issuer)
......
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>CertificationDialog</class>
<widget class="QDialog" name="CertificationDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>399</width>
<height>216</height>
</rect>
</property>
<property name="windowTitle">
<string>Certification</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>Community</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QComboBox" name="combo_community"/>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Certify user</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QRadioButton" name="radio_contact">
<property name="text">
<string>Contact</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="combo_contact">
<property name="enabled">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QRadioButton" name="radio_pubkey">
<property name="text">
<string>User public key</string>
</property>
<property name="checked">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="edit_pubkey">
<property name="enabled">
<bool>false</bool>
</property>
<property name="inputMask">
<string/>
</property>
<property name="text">
<string/>
</property>
<property name="placeholderText">
<string>Key</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="button_box">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>button_box</sender>
<signal>accepted()</signal>
<receiver>CertificationDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>button_box</sender>
<signal>rejected()</signal>
<receiver>CertificationDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>radio_pubkey</sender>
<signal>toggled(bool)</signal>
<receiver>CertificationDialog</receiver>
<slot>recipient_mode_changed(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>87</x>
<y>51</y>
</hint>
<hint type="destinationlabel">
<x>199</x>
<y>244</y>
</hint>
</hints>
</connection>
<connection>
<sender>combo_community</sender>
<signal>currentIndexChanged(int)</signal>
<receiver>CertificationDialog</receiver>
<slot>change_current_community(int)</slot>
<hints>
<hint type="sourcelabel">
<x>199</x>
<y>50</y>
</hint>
<hint type="destinationlabel">
<x>199</x>
<y>165</y>
</hint>
</hints>
</connection>
</connections>
<slots>
<slot>open_manage_wallet_coins()</slot>
<slot>change_displayed_wallet(int)</slot>
<slot>transfer_mode_changed(bool)</slot>
<slot>recipient_mode_changed(bool)</slot>
<slot>change_current_community(int)</slot>
<slot>amount_changed()</slot>
<slot>relative_amount_changed()</slot>
</slots>
</ui>
...@@ -120,14 +120,10 @@ class Account(object): ...@@ -120,14 +120,10 @@ class Account(object):
block_hash, block.number, None) block_hash, block.number, None)
selfcert = certified.selfcert(community) selfcert = certified.selfcert(community)
raw_cert = certification.raw(selfcert)
logging.debug("SelfCertification : {0}".format(selfcert.raw())) logging.debug("SelfCertification : {0}".format(selfcert.raw()))
key = SigningKey(self.salt, password) key = SigningKey(self.salt, password)
signing = base64.b64encode(key.signature(bytes(raw_cert, 'ascii'))) certification.sign(selfcert, [key])
logging.debug("Raw certification {0}".format(raw_cert))
logging.debug("Signature of {0}".format(signing.decode("ascii")))
certification.signatures = [signing.decode("ascii")]
signed_cert = certification.signed_raw(selfcert) signed_cert = certification.signed_raw(selfcert)
logging.debug("Certification : {0}".format(signed_cert)) logging.debug("Certification : {0}".format(signed_cert))
......
...@@ -116,9 +116,7 @@ class Wallet(object): ...@@ -116,9 +116,7 @@ class Wallet(object):
key = SigningKey("{0}{1}".format(salt, self.walletid), password) key = SigningKey("{0}{1}".format(salt, self.walletid), password)
logging.debug("Sender pubkey:{0}".format(key.pubkey)) logging.debug("Sender pubkey:{0}".format(key.pubkey))
signing = base64.b64encode(key.signature(bytes(tx.raw(), 'ascii'))) tx.sign([key])
logging.debug("Signature : {0}".format(signing.decode("ascii")))
tx.signatures = [signing.decode("ascii")]
logging.debug("Transaction : {0}".format(tx.signed_raw())) logging.debug("Transaction : {0}".format(tx.signed_raw()))
community.post(bma.tx.Process, community.post(bma.tx.Process,
post_args={'transaction': tx.signed_raw()}) post_args={'transaction': tx.signed_raw()})
......
'''
Created on 24 dec. 2014
@author: inso
'''
from PyQt5.QtWidgets import QDialog, QErrorMessage, QInputDialog, QLineEdit, QMessageBox
from cutecoin.core.person import Person
from cutecoin.gen_resources.certification_uic import Ui_CertificationDialog
class CertificationDialog(QDialog, Ui_CertificationDialog):
'''
classdocs
'''
def __init__(self, certifier):
'''
Constructor
'''
super().__init__()
self.setupUi(self)
self.certifier = certifier
self.community = self.certifier.communities[0]
for community in self.certifier.communities:
self.combo_community.addItem(community.currency)
for contact in certifier.contacts:
self.combo_contact.addItem(contact.name)
def accept(self):
if self.radio_contact.isChecked():
index = self.combo_contact.currentIndex()
pubkey = self.certifier.contacts[index].pubkey
else:
pubkey = self.edit_pubkey.text()
password = QInputDialog.getText(self, "Account password",
"Please enter your password",
QLineEdit.Password)
if password[1] is True:
password = password[0]
else:
return
while not self.certifier.check_password(password):
password = QInputDialog.getText(self, "Account password",
"Wrong password.\nPlease enter your password",
QLineEdit.Password)
if password[1] is True:
password = password[0]
else:
return
try:
self.certifier.certify(password, self.community, pubkey)
QMessageBox.information(self, "Certification",
"Success certifying {0} from {1}".format(pubkey,
self.community.currency))
except ValueError as e:
QMessageBox.critical(self, "Certification",
"Something wrong happened : {0}".format(e),
QMessageBox.Ok)
self.accepted.emit()
self.close()
def change_current_community(self, index):
self.community = self.certifier.communities[index]
def recipient_mode_changed(self, pubkey_toggled):
self.edit_pubkey.setEnabled(pubkey_toggled)
self.combo_contact.setEnabled(not pubkey_toggled)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment