Skip to content

Commit

Permalink
Apollo test addressed.
Browse files Browse the repository at this point in the history
  • Loading branch information
Pankaj committed Jun 16, 2022
1 parent 6b1a34a commit 6c81258
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 12 deletions.
14 changes: 14 additions & 0 deletions tests/apollo/util/bft.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,16 +503,30 @@ def _generate_operator_keys(self):
if self.builddir is None:
return
with open(self.builddir + "/operator_pub.pem", 'w') as f:
# EdDSA public key.
f.write("-----BEGIN PUBLIC KEY-----\n"
"MCowBQYDK2VwAyEAq6x6mTckhvzscZmDtRAwgneYpIE3sqkdLdaZ4B5JBbw=\n"
"-----END PUBLIC KEY-----")
"""
# ECDSA public key.
f.write("-----BEGIN PUBLIC KEY-----\n"
"MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAENEMHcbJgnnYxfa1zDlIF7lzp/Ioa"
"NfwGuJpAg84an5FdPALwZwBp/m/X3d8kwmfZEytqt2PGMNhHMkovIaRI1A==\n"
"-----END PUBLIC KEY-----")
"""
with open(self.builddir + "/operator_priv.pem", 'w') as f:
# EdDSA private key.
f.write("-----BEGIN PRIVATE KEY-----\n"
"MC4CAQAwBQYDK2VwBCIEIIIyaCtHzqPqMdvvcTIp+ZtOGccurc7e8qMPs8+jt0xo\n"
"-----END PRIVATE KEY-----")
"""
# ECDSA private key.
f.write("-----BEGIN EC PRIVATE KEY-----\n"
"MHcCAQEEIEWf8ZTkCWbdA9WrMSNGCC7GQxvSXiDlU6dlZAi6JaCboAoGCCqGSM49"
"AwEHoUQDQgAENEMHcbJgnnYxfa1zDlIF7lzp/IoaNfwGuJpAg84an5FdPALwZwBp"
"/m/X3d8kwmfZEytqt2PGMNhHMkovIaRI1A==\n"
"-----END EC PRIVATE KEY-----")
"""

def generate_tls_certs(self, num_to_generate, start_index=0):
"""
Expand Down
37 changes: 25 additions & 12 deletions tests/apollo/util/operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,37 @@

sys.path.append(os.path.abspath("../../util/pyclient"))

from cryptography.hazmat.primitives import serialization

import bft_client
from ecdsa import SigningKey
from ecdsa import SECP256k1
import hashlib
#from ecdsa import SigningKey
#from ecdsa import SECP256k1
#import hashlib

import util.eliot_logging as log


class Operator:
def __init__(self, config, client, priv_key_dir):
self.config = config
self.client = client
with open(priv_key_dir + "/operator_priv.pem") as f:
self.private_key = SigningKey.from_pem(f.read(), hashlib.sha256)

def _sign_reconf_msg(self, msg):
return self.private_key.sign_deterministic(msg.serialize())
# Read ECDSA signing key.
# with open(priv_key_dir + "/operator_priv.pem") as f:
# self.private_key = SigningKey.from_pem(f.read(), hashlib.sha256)

# Read EdDSA signing key.
txn_signing_key_path = priv_key_dir + "/operator_priv.pem"
if txn_signing_key_path:
with open(txn_signing_key_path, 'rb') as f:
self.private_key = serialization.load_pem_private_key(f.read(), password=None)

def _sign_reconf_msg(self, msg):
signature = b''
if self.private_key:
signature = self.private_key.sign(bytes(msg.serialize()))
return signature
# Return ECDSA signature.
# return self.private_key.sign_deterministic(msg.serialize())

def _construct_basic_reconfiguration_request(self, command):
reconf_msg = cmf_msgs.ReconfigurationRequest()
Expand All @@ -49,10 +62,10 @@ def _construct_basic_reconfiguration_request(self, command):
return reconf_msg

def _construct_reconfiguration_wedge_command(self):
wedge_cmd = cmf_msgs.WedgeCommand()
wedge_cmd.sender = 1000
wedge_cmd.noop = False
return self._construct_basic_reconfiguration_request(wedge_cmd)
wedge_cmd = cmf_msgs.WedgeCommand()
wedge_cmd.sender = 1000
wedge_cmd.noop = False
return self._construct_basic_reconfiguration_request(wedge_cmd)

def _construct_reconfiguration_latest_prunebale_block_command(self):
lpab_cmd = cmf_msgs.LatestPrunableBlockRequest()
Expand Down

0 comments on commit 6c81258

Please sign in to comment.