Browse Source

add ability to select snip auth method on the command line

Chelsea H. Komlo 4 years ago
parent
commit
e4e2717291
2 changed files with 32 additions and 7 deletions
  1. 20 7
      client.py
  2. 12 0
      network.py

+ 20 - 7
client.py

@@ -450,8 +450,10 @@ if __name__ == '__main__':
     clisent = 0
     clirecv = 0
 
-    if len(sys.argv) < 2:
-        print("must pass in network mode: options are vanilla, telescoping, or single-pass.")
+    if len(sys.argv) < 3:
+        print("Must pass in network mode and snip auth mode!")
+        print("Network options are vanilla, telescoping, or single-pass.")
+        print("SNIP auth options are merkle or threshold.")
         sys.exit(0)
 
     logging.basicConfig(level=logging.DEBUG)
@@ -461,7 +463,10 @@ if __name__ == '__main__':
         print("Not a valid network mode: " + network_mode)
         sys.exit(0)
 
-    #TODO Add a command-line switch to set Merkle or Threshold
+    snipauth_mode = network.SNIPAuthMode.string_to_type(sys.argv[2])
+    if network_mode == -1:
+        print("Not a valid SNIP authentication mode: " + snipauth_mode)
+        sys.exit(0)
 
     # Initialize the (non-cryptographic) random seed
     random.seed(1)
@@ -470,11 +475,19 @@ if __name__ == '__main__':
         network.thenetwork.set_wo_style(network.WOMode.VANILLA,
             network.SNIPAuthMode.NONE)
     elif network_mode == network.WOMode.TELESCOPING:
-        network.thenetwork.set_wo_style(network.WOMode.TELESCOPING,
-            network.SNIPAuthMode.MERKLE)
+        if snipauth_mode == network.SNIPAuthMode.MERKLE:
+            network.thenetwork.set_wo_style(network.WOMode.TELESCOPING,
+                network.SNIPAuthMode.MERKLE)
+        else:
+            network.thenetwork.set_wo_style(network.WOMode.TELESCOPING,
+                network.SNIPAuthMode.THRESHSIG)
     elif network_mode == network.WOMode.SINGLEPASS:
-        network.thenetwork.set_wo_style(network.WOMode.SINGLEPASS,
-            network.SNIPAuthMode.MERKLE)
+        if snipauth_mode == network.SNIPAuthMode.MERKLE:
+            network.thenetwork.set_wo_style(network.WOMode.SINGLEPASS,
+                network.SNIPAuthMode.MERKLE)
+        else:
+            network.thenetwork.set_wo_style(network.WOMode.SINGLEPASS,
+                network.SNIPAuthMode.THRESHSIG)
     else:
         sys.exit("Received unsupported network mode, exiting.")
 

+ 12 - 0
network.py

@@ -41,6 +41,18 @@ class SNIPAuthMode(Enum):
     MERKLE      = 1  # Merkle trees
     THRESHSIG   = 2  # Threshold signatures
 
+    # We only need to differentiate between merkle and telescoping on the
+    # command line input, Vanilla always takes a NONE type but nothing else
+    # does.
+    def string_to_type(type_input):
+        reprs = {'merkle': SNIPAuthMode.MERKLE,
+                'telesocping': SNIPAuthMode.THRESHSIG }
+
+        if type_input in reprs.keys():
+            return reprs[type_input]
+
+        return -1
+
 
 class EntType(Enum):
     """The different types of entities in the system."""