William Bowling is sharing code with you
Bitbucket is a code hosting site. Unlimited public and private repositories. Free for small teams.
Don't show this again1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 | /*
* Adium is the legal property of its developers, whose names are listed in the copyright file included
* with this source distribution.
*
* This program is free software; you can redistribute it and/or modify it under the terms of the GNU
* General Public License as published by the Free Software Foundation; either version 2 of the License,
* or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program; if not,
* write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#import "ESOTRUnknownFingerprintController.h"
#import "ESTextAndButtonsWindowController.h"
#import <Adium/AIAccount.h>
#import <Adium/AIService.h>
#import "AIHTMLDecoder.h"
#import <Adium/AIServiceIcons.h>
#import <Adium/AIAccountControllerProtocol.h>
#import "AdiumOTREncryption.h"
@interface ESOTRUnknownFingerprintController ()
+ (void)showFingerprintPromptWithMessageString:(NSString *)messageString
acceptButton:(NSString *)acceptButton
denyButton:(NSString *)denyButton
responseInfo:(NSDictionary *)responseInfo;
+ (void)unknownFingerprintResponseInfo:(NSDictionary *)responseInfo wasAccepted:(BOOL)fingerprintAccepted;
@end
@implementation ESOTRUnknownFingerprintController
+ (void)showUnknownFingerprintPromptWithResponseInfo:(NSDictionary *)responseInfo
{
NSString *messageString;
AIAccount *account = [responseInfo objectForKey:@"AIAccount"];
NSString *who = [responseInfo objectForKey:@"who"];
NSString *ourHash = [responseInfo objectForKey:@"Our Fingerprint"];
NSString *theirHash = [responseInfo objectForKey:@"Their Fingerprint"];
messageString = [NSString stringWithFormat:
AILocalizedString(@"%@ has sent you (%@) an unknown encryption fingerprint.\n\n"
"Fingerprint for you: %@\n\n"
"Purported fingerprint for %@: %@\n\n"
"Accept this fingerprint as verified?",nil),
who,
account.formattedUID,
ourHash,
who,
theirHash];
[self showFingerprintPromptWithMessageString:messageString
acceptButton:AILocalizedString(@"Accept",nil)
denyButton:AILocalizedString(@"Verify Later",nil)
responseInfo:responseInfo];
}
+ (void)showVerifyFingerprintPromptWithResponseInfo:(NSDictionary *)responseInfo
{
NSString *messageString;
AIAccount *account = [responseInfo objectForKey:@"AIAccount"];
NSString *who = [responseInfo objectForKey:@"who"];
NSString *ourHash = [responseInfo objectForKey:@"Our Fingerprint"];
NSString *theirHash = [responseInfo objectForKey:@"Their Fingerprint"];
messageString = [NSString stringWithFormat:
AILocalizedString(@"Fingerprint for you (%@): %@\n\n"
"Purported fingerprint for %@: %@\n\n"
"Is this the verifiably correct fingerprint for %@?",nil),
account.formattedUID,
ourHash,
who,
theirHash,
who];
[self showFingerprintPromptWithMessageString:messageString
acceptButton:AILocalizedString(@"Yes",nil)
denyButton:AILocalizedString(@"No",nil)
responseInfo:responseInfo];
}
+ (void)showFingerprintPromptWithMessageString:(NSString *)messageString
acceptButton:(NSString *)acceptButton
denyButton:(NSString *)denyButton
responseInfo:(NSDictionary *)responseInfo
{
ESTextAndButtonsWindowController *windowController;
AIAccount *account = [responseInfo objectForKey:@"AIAccount"];
NSImage *serviceImage = nil;
if (account) {
serviceImage = [AIServiceIcons serviceIconForObject:account
type:AIServiceIconLarge
direction:AIIconNormal];
}
windowController = [ESTextAndButtonsWindowController showTextAndButtonsWindowWithTitle:AILocalizedString(@"OTR Fingerprint Verification",nil)
defaultButton:acceptButton
alternateButton:denyButton
otherButton:AILocalizedString(@"Help", nil)
suppression:nil
onWindow:nil
withMessageHeader:nil
andMessage:[AIHTMLDecoder decodeHTML:messageString]
image:serviceImage
target:self
userInfo:responseInfo];
}
/*!
* @brief Window was closed, either by a button being clicked or the user closing it
*/
+ (BOOL)textAndButtonsWindowDidEnd:(NSWindow *)window returnCode:(AITextAndButtonsReturnCode)returnCode suppression:(BOOL)suppression userInfo:(id)userInfo
{
BOOL shouldCloseWindow = YES;
if (userInfo && [userInfo objectForKey:@"Their Fingerprint"]) {
BOOL fingerprintAccepted;
if (returnCode == AITextAndButtonsOtherReturn) {
NSString *who = [userInfo objectForKey:@"who"];
NSString *message = [NSString stringWithFormat:AILocalizedString(@"A fingerprint is a unique identifier "
"that you should use to verify the identity of %@.\n\nTo verify the fingerprint, contact %@ via some "
"other authenticated channel such as the telephone or GPG-signed email. "
"Each of you should tell your fingerprint to the other.", nil),
who,
who];
[ESTextAndButtonsWindowController showTextAndButtonsWindowWithTitle:nil
defaultButton:nil
alternateButton:nil
otherButton:nil
onWindow:window
withMessageHeader:AILocalizedString(@"Fingerprint Help", nil)
andMessage:[[[NSAttributedString alloc] initWithString:message] autorelease]
target:self
userInfo:nil];
//Don't close the original window if the help button is pressed
shouldCloseWindow = NO;
} else {
fingerprintAccepted = ((returnCode == AITextAndButtonsDefaultReturn) ? YES : NO);
[self unknownFingerprintResponseInfo:userInfo
wasAccepted:fingerprintAccepted];
}
}
return shouldCloseWindow;
}
+ (void)unknownFingerprintResponseInfo:(NSDictionary *)responseInfo wasAccepted:(BOOL)fingerprintAccepted
{
AIAccount *account = [responseInfo objectForKey:@"AIAccount"];
NSString *who = [responseInfo objectForKey:@"who"];
ConnContext *context = otrl_context_find(otrg_get_userstate(),
[who UTF8String], [account.internalObjectID UTF8String],
[account.service.serviceCodeUniqueID UTF8String],
0, NULL, NULL, NULL);
Fingerprint *fprint;
BOOL oldtrust;
if (context == NULL) {
AILog(@"Warning: ESOTRUnknownFingerprintController: NULL context for %@",responseInfo);
return;
}
fprint = context->active_fingerprint;
if (fprint == NULL) {
AILog(@"Warning: ESOTRUnknownFingerprintController: NULL fprint for %@",responseInfo);
return;
}
oldtrust = (fprint->trust && fprint->trust[0]);
/* See if anything's changed */
if (fingerprintAccepted != oldtrust) {
otrl_context_set_trust(fprint, fingerprintAccepted ? "verified" : "");
//Write the new info to disk, redraw the UI
otrg_plugin_write_fingerprints();
otrg_ui_update_keylist();
}
}
@end
|