~ubuntu-branches/debian/jessie/armory/jessie

« back to all changes in this revision

Viewing changes to extras/verify_dl_list.py

  • Committer: Package Import Robot
  • Author(s): Joseph Bisch
  • Date: 2014-10-07 10:22:45 UTC
  • Revision ID: package-import@ubuntu.com-20141007102245-2s3x3rhjxg689hek
Tags: upstream-0.92.3
ImportĀ upstreamĀ versionĀ 0.92.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import sys
 
2
sys.path.append('..')
 
3
sys.path.append('/usr/share/armory')
 
4
 
 
5
import os
 
6
from armoryengine import *
 
7
 
 
8
 
 
9
def extractSignedDataFromVersionsDotTxt(wholeFile, doVerify=True):
 
10
   """
 
11
   This method returns a pair: a dictionary to lookup link by OS, and 
 
12
   a formatted string that is sorted by OS, and re-formatted list that 
 
13
   will hash the same regardless of original format or ordering
 
14
   """
 
15
 
 
16
   msgBegin = wholeFile.find('# -----BEGIN-SIGNED-DATA-')
 
17
   msgBegin = wholeFile.find('\n', msgBegin+1) + 1
 
18
   msgEnd   = wholeFile.find('# -----SIGNATURE---------')
 
19
   sigBegin = wholeFile.find('\n', msgEnd+1) + 3
 
20
   sigEnd   = wholeFile.find('# -----END-SIGNED-DATA---')
 
21
 
 
22
   MSGRAW = wholeFile[msgBegin:msgEnd]
 
23
   SIGHEX = wholeFile[sigBegin:sigEnd].strip()
 
24
 
 
25
   if -1 in [msgBegin,msgEnd,sigBegin,sigEnd]:
 
26
      LOGERROR('No signed data block found')
 
27
      return ''
 
28
 
 
29
   print 'MESSAGE:  '
 
30
   print MSGRAW
 
31
   print 'SIGNATURE:'
 
32
   print SIGHEX
 
33
 
 
34
   
 
35
   if doVerify:
 
36
      Pub = SecureBinaryData(hex_to_binary(ARMORY_INFO_SIGN_PUBLICKEY))
 
37
      Msg = SecureBinaryData(MSGRAW)
 
38
      Sig = SecureBinaryData(hex_to_binary(SIGHEX))
 
39
      isVerified = CryptoECDSA().VerifyData(Msg, Sig, Pub)
 
40
   
 
41
      if not isVerified:
 
42
         LOGERROR('Signed data block failed verification!')
 
43
         return ''
 
44
      else:
 
45
         print 'SIGNATURE IS GOOD!'
 
46
 
 
47
 
 
48
   return MSGRAW
 
49
 
 
50
 
 
51
def parseLinkList(theData):
 
52
   """ 
 
53
   Plug the verified data into here...
 
54
   """
 
55
   DLDICT,VERDICT = {},{}
 
56
   sectStr = None
 
57
   for line in theData.split('\n'): 
 
58
      pcs = line[1:].split()
 
59
      if line.startswith('# SECTION-') and 'INSTALLERS' in line:
 
60
         sectStr = pcs[0].split('-')[-1].lower()
 
61
         if not sectStr in DLDICT:
 
62
            DLDICT[sectStr] = {}
 
63
            VERDICT[sectStr] = ''
 
64
         if len(pcs)>1:
 
65
            VERDICT[sectStr] = pcs[-1]
 
66
         continue
 
67
      
 
68
      if len(pcs)==3 and pcs[1].startswith('http'):
 
69
         DLDICT[sectStr][pcs[0]] = pcs[1:]
 
70
 
 
71
   return DLDICT,VERDICT
 
72
 
 
73
 
 
74
if __name__=='__main__':
 
75
   fn = 'versions.txt'
 
76
   if not os.path.exists(fn):
 
77
      print 'File does not exist!'
 
78
      fn = '../versions.txt'
 
79
      if not os.path.exists(fn):
 
80
         print 'Really does not exist. Aborting.' 
 
81
         exit(1)
 
82
 
 
83
   f = open(fn, 'r')
 
84
   allData = f.read()
 
85
 
 
86
   msgVerified = extractSignedDataFromVersionsDotTxt(allData, doVerify=False)
 
87
   DICT,VER = parseLinkList(msgVerified)
 
88
         
 
89
   print DICT
 
90
   for dl in DICT:
 
91
      print dl.upper(), VER[dl]
 
92
      for theOS in DICT[dl]:
 
93
         print '   ' + dl + '-' + theOS
 
94
         print '      ', DICT[dl][theOS][0]
 
95
         print '      ', DICT[dl][theOS][1]
 
96
 
 
97
   msgVerified = extractSignedDataFromVersionsDotTxt(allData)
 
98
      
 
99
   
 
100
 
 
101
 
 
102