OLD | NEW |
1 # Authors: | 1 # Authors: |
2 # Trevor Perrin | 2 # Trevor Perrin |
3 # Dave Baggett (Arcode Corporation) - MD5 support for MAC_SSL | 3 # Dave Baggett (Arcode Corporation) - MD5 support for MAC_SSL |
4 # Yngve Pettersen (ported by Paul Sokolovsky) - TLS 1.2 | 4 # Yngve Pettersen (ported by Paul Sokolovsky) - TLS 1.2 |
5 # | 5 # |
6 # See the LICENSE file for legal information regarding use of this file. | 6 # See the LICENSE file for legal information regarding use of this file. |
7 | 7 |
8 """Miscellaneous helper functions.""" | 8 """Miscellaneous helper functions.""" |
9 | 9 |
10 from .utils.compat import * | 10 from .utils.compat import * |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 A = bytearray([ord('A')+x] * (x+1)) # 'A', 'BB', 'CCC', etc.. | 60 A = bytearray([ord('A')+x] * (x+1)) # 'A', 'BB', 'CCC', etc.. |
61 input = secret + SHA1(A + secret + seed) | 61 input = secret + SHA1(A + secret + seed) |
62 output = MD5(input) | 62 output = MD5(input) |
63 for c in output: | 63 for c in output: |
64 if index >= length: | 64 if index >= length: |
65 return bytes | 65 return bytes |
66 bytes[index] = c | 66 bytes[index] = c |
67 index += 1 | 67 index += 1 |
68 return bytes | 68 return bytes |
69 | 69 |
70 def calcMasterSecret(version, premasterSecret, clientRandom, serverRandom, | 70 def calcMasterSecret(version, premasterSecret, clientRandom, serverRandom): |
71 handshakeHash, useExtendedMasterSecret): | |
72 label = b"master secret" | |
73 seed = clientRandom + serverRandom | |
74 if useExtendedMasterSecret: | |
75 label = b"extended master secret" | |
76 seed = handshakeHash | |
77 | |
78 if version == (3,0): | 71 if version == (3,0): |
79 masterSecret = PRF_SSL(premasterSecret, seed, 48) | 72 masterSecret = PRF_SSL(premasterSecret, |
| 73 clientRandom + serverRandom, 48) |
80 elif version in ((3,1), (3,2)): | 74 elif version in ((3,1), (3,2)): |
81 masterSecret = PRF(premasterSecret, label, seed, 48) | 75 masterSecret = PRF(premasterSecret, b"master secret", |
| 76 clientRandom + serverRandom, 48) |
82 elif version == (3,3): | 77 elif version == (3,3): |
83 masterSecret = PRF_1_2(premasterSecret, label, seed, 48) | 78 masterSecret = PRF_1_2(premasterSecret, b"master secret", |
| 79 clientRandom + serverRandom, 48) |
84 else: | 80 else: |
85 raise AssertionError() | 81 raise AssertionError() |
86 return masterSecret | 82 return masterSecret |
87 | 83 |
88 | 84 |
89 def makeX(salt, username, password): | 85 def makeX(salt, username, password): |
90 if len(username)>=256: | 86 if len(username)>=256: |
91 raise ValueError("username too long") | 87 raise ValueError("username too long") |
92 if len(salt)>=256: | 88 if len(salt)>=256: |
93 raise ValueError("salt too long") | 89 raise ValueError("salt too long") |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 new.ihash = self.ihash.copy() | 142 new.ihash = self.ihash.copy() |
147 new.ohash = self.ohash.copy() | 143 new.ohash = self.ohash.copy() |
148 new.digestmod = self.digestmod | 144 new.digestmod = self.digestmod |
149 new.digest_size = self.digest_size | 145 new.digest_size = self.digest_size |
150 return new | 146 return new |
151 | 147 |
152 def digest(self): | 148 def digest(self): |
153 ohash2 = self.ohash.copy() | 149 ohash2 = self.ohash.copy() |
154 ohash2.update(self.ihash.digest()) | 150 ohash2.update(self.ihash.digest()) |
155 return bytearray(ohash2.digest()) | 151 return bytearray(ohash2.digest()) |
OLD | NEW |