Permalink
Browse files

Key exchange patches.

  • Loading branch information...
emsquared committed Mar 9, 2013
1 parent 4ea0ccd commit 21016a9598f9eea2d652fd290771d33e5dce67f8
@@ -36,6 +36,6 @@
*********************************************************************** */
@interface CFDH1080 : NSObject
-- (NSString *)generatePublicKey:(BOOL)enforceKeyLength;
+- (NSString *)generatePublicKey;
- (NSString *)secretKeyFromPublicKey:(NSString *)publicKey;
@end
@@ -64,40 +64,11 @@ - (void)dealloc
#pragma mark -
-- (NSString *)generatePublicKey:(BOOL)enforceKeyLength
+- (NSString *)generatePublicKey
{
NSString *publicKeyRaw = [self.keyExchanger rawPublicKey];
- /* During development there were times when the generated key were not the
- correct length making key exchange fail on each end. If the length of the
- public key is not correct, then we will reset and create it again several
- times until we have one that is. The loop is limited to prevent it from
- ending up being infinitely ran. */
-
- if ((publicKeyRaw.length == DH1080RequiredKeyLength) == NO && enforceKeyLength) {
- NSInteger loopIndex = 0;
-
- while (1 == 1) {
- if (loopIndex > 10) {
- break;
- }
-
- [self.keyExchanger resetStatus];
- [self.keyExchanger resetPublicInformation];
-
- [self.keyExchanger initalizeKeyExchange];
-
- publicKeyRaw = [self.keyExchanger rawPublicKey];
-
- if (publicKeyRaw.length == DH1080RequiredKeyLength) {
- break;
- }
-
- loopIndex += 1;
- }
- }
-
- if (publicKeyRaw.length == DH1080RequiredKeyLength) {
+ if (publicKeyRaw.length >= 1) {
return [self.keyExchanger publicKeyValue:publicKeyRaw];
}
@@ -48,7 +48,6 @@
// Please see License.txt for further information.
#define DH1080RequiredKeyLength 135
-#define DH1080SecretValueReturnLength 42
@interface DH1080Base : NSObject
- (void)initalizeKeyExchange; // Do not call.
@@ -226,13 +226,7 @@ - (NSString *)secretStringValue
DHAssertNO(secretHash.length >= 1);
- secretHash = [self base64Encode:secretHash];
-
- if (secretHash.length > DH1080SecretValueReturnLength) {
- secretHash = [secretHash substringToIndex:DH1080SecretValueReturnLength];
- }
-
- return secretHash;
+ return [self base64Encode:secretHash];
}
- (NSString *)publicKeyValue:(NSString *)publicInput
View
@@ -48,8 +48,8 @@
<key>TXBundleBuildCodeName</key>
<string>Mud Pie</string>
<key>TXBundleBuildNumber</key>
- <string>15257</string>
+ <string>15260</string>
<key>TXBundleBuildReference</key>
- <string>3.0.0b3-262-ge93f16e-trial</string>
+ <string>3.0.0b3-263-g4ea0ccd-stdbuild</string>
</dict>
</plist>
@@ -167,7 +167,7 @@ - (void)messageSentByUser:(IRCClient *)client
} else {
CFDH1080 *keyRequest = [CFDH1080 new];
- NSString *publicKey = [keyRequest generatePublicKey:YES];
+ NSString *publicKey = [keyRequest generatePublicKey];
if (NSObjectIsEmpty(publicKey)) {
[client printDebugInformation:TPILS(@"BlowfishKeyExchangeErrorOccurred_1") channel:c];
@@ -217,12 +217,7 @@ - (NSDictionary *)pluginOutputDisplayRules
#pragma mark -
#pragma mark Key Exchange.
-- (void)keyExchangeRequestReceived:(NSString *)requestData on:(IRCClient *)client from:(NSString *)requestSender
-{
- [self keyExchangeRequestReceived:requestData on:client from:requestSender withRecursion:0];
-}
-
-- (void)keyExchangeRequestReceived:(NSString *)requestDataRaw on:(IRCClient *)client from:(NSString *)requestSender withRecursion:(NSInteger)recursionCount
+- (void)keyExchangeRequestReceived:(NSString *)requestDataRaw on:(IRCClient *)client from:(NSString *)requestSender
{
IRCChannel *channel = [client findChannelOrCreate:requestSender isPrivateMessage:YES];
@@ -249,31 +244,17 @@ - (void)keyExchangeRequestReceived:(NSString *)requestDataRaw on:(IRCClient *)cl
NSString *theSecret = [keyRequest secretKeyFromPublicKey:requestData];
if (NSObjectIsEmpty(theSecret)) {
- if (recursionCount >= 0 && recursionCount <= 5) {
- return [self keyExchangeRequestReceived:requestDataRaw on:client from:requestSender withRecursion:(recursionCount + 1)];
- }
-
- [client printDebugInformation:TPIFLS(@"BlowfishKeyExchangeRequestReceived", channel.name) channel:channel];
- [client printDebugInformation:TPILS(@"BlowfishKeyExchangeErrorOccurred_2") channel:channel];
+ [client printDebugInformation:TPILS(@"BlowfishKeyExchangeErrorOccurred_2") channel:channel];
return;
}
/* Generate our own public key. If everything has gone correctly up to here,
then when the user that sent the request computes our public key, we both
should have the same secret. */
- NSString *publicKey = [keyRequest generatePublicKey:NO];
+ NSString *publicKey = [keyRequest generatePublicKey];
if (NSObjectIsEmpty(publicKey)) {
- /* If we failed to generate our public key, then let us try running this request one more
- time by creating a brand new instance of CFDH1080 to make up for any possible error that
- may have unexpectedly resulted in a bad public key. */
-
- if (recursionCount >= 0 && recursionCount <= 5) {
- return [self keyExchangeRequestReceived:requestDataRaw on:client from:requestSender withRecursion:(recursionCount + 1)];
- }
-
- [client printDebugInformation:TPIFLS(@"BlowfishKeyExchangeRequestReceived", channel.name) channel:channel];
[client printDebugInformation:TPILS(@"BlowfishKeyExchangeErrorOccurred_1") channel:channel];
return;

0 comments on commit 21016a9

Please sign in to comment.