2 * Adium is the legal property of its developers, whose names are listed in the copyright file included
3 * with this source distribution.
5 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
6 * General Public License as published by the Free Software Foundation; either version 2 of the License,
7 * or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
10 * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
11 * Public License for more details.
13 * You should have received a copy of the GNU General Public License along with this program; if not,
14 * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 #import "ESOTRUnknownFingerprintController.h"
18 #import "ESTextAndButtonsWindowController.h"
19 #import <Adium/AIAccount.h>
20 #import <Adium/AIService.h>
21 #import "AIHTMLDecoder.h"
22 #import <Adium/AIServiceIcons.h>
23 #import <Adium/AIAccountControllerProtocol.h>
25 #import "AdiumOTREncryption.h"
27 @interface ESOTRUnknownFingerprintController (PRIVATE)
28 + (void)showFingerprintPromptWithMessageString:(NSString *)messageString
29 acceptButton:(NSString *)acceptButton
30 denyButton:(NSString *)denyButton
31 responseInfo:(NSDictionary *)responseInfo;
32 + (void)unknownFingerprintResponseInfo:(NSDictionary *)responseInfo wasAccepted:(BOOL)fingerprintAccepted;
35 @implementation ESOTRUnknownFingerprintController
37 + (void)showUnknownFingerprintPromptWithResponseInfo:(NSDictionary *)responseInfo
39 NSString *messageString;
40 AIAccount *account = [responseInfo objectForKey:@"AIAccount"];
41 NSString *who = [responseInfo objectForKey:@"who"];
42 NSString *ourHash = [responseInfo objectForKey:@"Outgoing SessionID"];
43 NSString *theirHash = [responseInfo objectForKey:@"Incoming SessionID"];
45 messageString = [NSString stringWithFormat:
46 AILocalizedString(@"%@ has sent you (%@) an unknown encryption fingerprint.\n\n"
47 "Fingerprint for you: %@\n\n"
48 "Purported fingerprint for %@: %@\n\n"
49 "Accept this fingerprint as verified?",nil),
51 [account formattedUID],
56 [self showFingerprintPromptWithMessageString:messageString
57 acceptButton:AILocalizedString(@"Accept",nil)
58 denyButton:AILocalizedString(@"Verify Later",nil)
59 responseInfo:responseInfo];
62 + (void)showVerifyFingerprintPromptWithResponseInfo:(NSDictionary *)responseInfo
64 NSString *messageString;
65 AIAccount *account = [responseInfo objectForKey:@"AIAccount"];
66 NSString *who = [responseInfo objectForKey:@"who"];
67 NSString *ourHash = [responseInfo objectForKey:@"Outgoing SessionID"];
68 NSString *theirHash = [responseInfo objectForKey:@"Incoming SessionID"];
70 messageString = [NSString stringWithFormat:
71 AILocalizedString(@"Fingerprint for you (%@): %@\n\n"
72 "Purported fingerprint for %@: %@\n\n"
73 "Is this the verifiably correct fingerprint for %@?",nil),
74 [account formattedUID],
80 [self showFingerprintPromptWithMessageString:messageString
81 acceptButton:AILocalizedString(@"Yes",nil)
82 denyButton:AILocalizedString(@"No",nil)
83 responseInfo:responseInfo];
86 + (void)showFingerprintPromptWithMessageString:(NSString *)messageString
87 acceptButton:(NSString *)acceptButton
88 denyButton:(NSString *)denyButton
89 responseInfo:(NSDictionary *)responseInfo
91 ESTextAndButtonsWindowController *windowController;
93 AIAccount *account = [responseInfo objectForKey:@"AIAccount"];
95 NSImage *serviceImage = nil;
98 serviceImage = [AIServiceIcons serviceIconForObject:account
99 type:AIServiceIconLarge
100 direction:AIIconNormal];
103 windowController = [ESTextAndButtonsWindowController showTextAndButtonsWindowWithTitle:AILocalizedString(@"OTR Fingerprint Verification",nil)
104 defaultButton:acceptButton
105 alternateButton:denyButton
106 otherButton:AILocalizedString(@"Help", nil)
108 withMessageHeader:nil
109 andMessage:[AIHTMLDecoder decodeHTML:messageString]
112 userInfo:responseInfo];
116 * @brief Window was closed, either by a button being clicked or the user closing it
118 + (BOOL)textAndButtonsWindowDidEnd:(NSWindow *)window returnCode:(AITextAndButtonsReturnCode)returnCode userInfo:(id)userInfo
120 BOOL shouldCloseWindow = YES;
122 if (userInfo && [userInfo objectForKey:@"Fingerprint"]) {
123 BOOL fingerprintAccepted;
125 if (returnCode == AITextAndButtonsOtherReturn) {
126 NSString *who = [userInfo objectForKey:@"who"];
128 NSString *message = [NSString stringWithFormat:AILocalizedString(@"A fingerprint is a unique identifier "
129 "that you should use to verify the identity of %@.\n\nTo verify the fingerprint, contact %@ via some "
130 "other authenticated channel such as the telephone or GPG-signed email. "
131 "Each of you should tell your fingerprint to the other.", nil),
135 [ESTextAndButtonsWindowController showTextAndButtonsWindowWithTitle:nil
140 withMessageHeader:AILocalizedString(@"Fingerprint Help", nil)
141 andMessage:[[[NSAttributedString alloc] initWithString:message] autorelease]
145 //Don't close the original window if the help button is pressed
146 shouldCloseWindow = NO;
149 fingerprintAccepted = ((returnCode == AITextAndButtonsDefaultReturn) ? YES : NO);
151 [self unknownFingerprintResponseInfo:userInfo
152 wasAccepted:fingerprintAccepted];
156 return shouldCloseWindow;
159 + (void)unknownFingerprintResponseInfo:(NSDictionary *)responseInfo wasAccepted:(BOOL)fingerprintAccepted
161 AIAccount *account = [responseInfo objectForKey:@"AIAccount"];
162 NSString *who = [responseInfo objectForKey:@"who"];
164 ConnContext *context = otrl_context_find(otrg_get_userstate(),
165 [who UTF8String], [[account internalObjectID] UTF8String],
166 [[[account service] serviceCodeUniqueID] UTF8String],
167 0, NULL, NULL, NULL);
171 if (context == NULL) {
172 AILog(@"Warning: ESOTRUnknownFingerprintController: NULL context for %@",responseInfo);
176 fprint = context->active_fingerprint;
178 if (fprint == NULL) {
179 AILog(@"Warning: ESOTRUnknownFingerprintController: NULL fprint for %@",responseInfo);
183 oldtrust = (fprint->trust && fprint->trust[0]);
185 /* See if anything's changed */
186 if (fingerprintAccepted != oldtrust) {
187 otrl_context_set_trust(fprint, fingerprintAccepted ? "verified" : "");
188 //Write the new info to disk, redraw the UI
189 otrg_plugin_write_fingerprints();
190 otrg_ui_update_keylist();