Skip to content

Commit

Permalink
Merge branch 'master' of github.com:twardokus/v2verifier
Browse files Browse the repository at this point in the history
  • Loading branch information
twardokus committed Nov 13, 2020
2 parents 907618b + 4c33dbf commit 588554c
Show file tree
Hide file tree
Showing 17 changed files with 7,307 additions and 101 deletions.
2 changes: 1 addition & 1 deletion .idea/UltimateGUI.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 13 additions & 14 deletions Receiver.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,43 +11,43 @@ def __init__(self):
self.verifier = Verifier()
self.messageCounter = 1

def runReceiver(self, socketToGUI, guiLock):
listener = Thread(target=self.listenForWSMs(socketToGUI, guiLock))
def runReceiver(self, s, lock):
listener = Thread(target=self.listenForWSMs(s, lock))
listener.start()

def listenForWSMs(self, s, lock):
# print a console message to confirm the network connection is active

print("Listening on localhost:4444 for WSMs")

# listen on localhost:4444 which is the UDP sink from GNURadio in wifi_rx.py
# received packets are passed to processPacket() for data extraction
sniff(iface="lo", filter="dst port 4444", prn=lambda x: self.filterDuplicatePackets(str(binascii.hexlify(x.load))[130:],s,lock))
# port 4444 corresponds to UDP interface in wifi_rx.grc
sniff(iface="lo", filter="dst port 4444", prn=lambda x:
self.filterDuplicatePackets(str(binascii.hexlify(x.load))[130:], s, lock))

def filterDuplicatePackets(self, payload, s, lock):
if self.messageCounter % 2 == 1:
self.processPacket(payload, s, lock)
self.messageCounter += 1

# uses returned tuple from parseWSM to verify message and send to GUI
def processPacket(self, payload, s, lock):

# extract the elements "(unsecuredData,r,s,time)" from the 1609.2 structure
data = self.parseWSM(payload)

#BSMData = data[0].decode('hex').replace("\n","").split(",")
BSMData = bytes.fromhex(data[0]).decode('ascii').replace("\n","").split(",")

# create a dictionary to pack and send
decodedData = {}

decodedData['id'] = BSMData[0]
decodedData['x'] = BSMData[1]
decodedData['y'] = BSMData[2]
decodedData['heading'] = BSMData[3]
decodedData['speed'] = BSMData[4]

publicKey = keys.import_key("keys/" + decodedData['id'] + "/p256.pub",curve=curve.P256, public=True)


# publicKey = keys.import_key("keys/" + decodedData['id'] + "/p256.pub",curve=curve.P256, public=True)
publicKey = keys.import_key("keys/0/p256.pub",curve=curve.P256, public=True)


# verify the signature
isValidSig = self.verifier.verifySignature(data[1],data[2],data[0],publicKey)

Expand All @@ -57,15 +57,14 @@ def processPacket(self, payload, s, lock):
decodedData['elapsed'] = elapsed
decodedData['recent'] = isRecent
decodedData['receiver'] = False

vehicleDataJSON = json.dumps(decodedData)

with lock:
s.send(vehicleDataJSON.encode())

# takes the hex payload from an 802.11p frame as an argument, returns tuple of extracted bytestrings
def parseWSM(self, WSM):

# The first 8 bytes are WSMP N/T headers that do not change in size and can be discarded
ieee1609Dot2Data = WSM[8:]

Expand Down
2 changes: 1 addition & 1 deletion RemoteVehicle.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ def start(self):
print("Sending BSM")
loader = subprocess.Popen(("echo","-n","-e",BSM), stdout=subprocess.PIPE)
sender = subprocess.check_output(("nc","-w0","-u","localhost","52001"),stdin=loader.stdout)
time.sleep(0.1)
time.sleep(0.1)
95 changes: 89 additions & 6 deletions WavePacketBuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import math

class WAVEPacketBuilder():

def getWSMPayload(self, bsmString, key):

payload = self.getLLCBytestring() + self.getWSMHeaders() + self.getIeee1609Dot2Data(bsmString,key)
Expand Down Expand Up @@ -87,12 +87,95 @@ def getIeee1609Dot2Data(self, message, key):
# this is a placeholder byte pattern that is unlikely to occur in practice, used to inject actual time
# when packet is transmitted
bytestring += "F0E0F0E0F0E0F0E0"

# signer
bytestring += "80"


# Digest (8 bytes) - this is a dummy value as we have not used certificates, which would be involved here
bytestring += "2122232425262728"
# NOT NEEDED, for if signerIdentifier = "digest"
# bytestring += "80"
# bytestring += "2122232425262728"

# signerIdentifier = "certificate"
#Assuming digest is 80, set to 81
bytestring += "81"

#START CERTIFICATE BASE

#version = 3
bytestring += "03"

# Number of items
bytestring += "000006"

#CertificateType = "explicit"
#@TODO implement ExplicitCertificate structure here

#for i in range(0, 6):
# Filler?
bytestring += "00"

# version
bytestring += "03"

# type
bytestring += "00"

#Issuer = "sha256AndDigest"
#dummy value here for issuerID
bytestring += "002122232425262728"

#toBeSigned
# - START ToBeSignedCertificate HERE -

#id = linkageData
#this data is used to compare/add certificates to a CRL
#START linkageData HERE


#buffer
bytestring += "0000"

# certificateID choice
bytestring += "00"


#iCert DUMMY VALUE
bytestring += "0100"

#linkage-value(size = 9) DUMMY VALUE
#bytestring += "0fa12245f4c3c1cd54"
bytestring += "414243444546474849"
#END linkageData HERE

#cracaID(size = 3) DUMMY VALUE
bytestring += "52641c"

#crlSeries DUMMY VALUE
bytestring += "2000"

#START validityPeriod HERE
#start(time32)
bytestring += "24c34587"

#duration
bytestring += "030005"

# VerificationKeyIndicator
bytestring += "01"

# EccP256CurvePoint
bytestring += "04"
bytestring += "00"*64

#END validityPeriod HERE

# - OPTIONAL FIELDS CAN GO HERE -
# IN ORDER:
# region, assuranceLevel, appPermissions, certIssuePermissions, certRequestPermissions,
# canRequestRollover, encryptionKey

#verifyKeyIndicator
#@TODO get more information on KeyIndicator

# - END ToBeSignedCertificate HERE -

# signature (ecdsaNistP256Signature = 80)
bytestring += "80"
Expand Down
Loading

0 comments on commit 588554c

Please sign in to comment.