Skip to content
Snippets Groups Projects
Commit 33fc476c authored by Oliver Wiese's avatar Oliver Wiese
Browse files

update setup message

parent c9aadebd
No related branches found
No related tags found
No related merge requests found
......@@ -48,13 +48,13 @@ class ExportViewController: UITableViewController {
if let message = pgp.exportKey(id: keyId, isSecretkey: true, autocrypt: true, newPasscode: true) {
passcode = pgp.loadExportPasscode(id: keyId)!
let mailHandler = AppDelegate.getAppDelegate().mailHandler
mailHandler.sendSecretKey(key: message, passcode: passcode, callback: mailSend)
mailHandler.sendSecretKey(keyID: keyId, key: message, passcode: passcode, callback: mailSend)
}
} else {
if let message = pgp.exportKey(id: keyId, isSecretkey: true, autocrypt: true, newPasscode: false) {
passcode = pgp.loadExportPasscode(id: keyId)!
let mailHandler = AppDelegate.getAppDelegate().mailHandler
mailHandler.sendSecretKey(key: message, passcode: passcode, callback: mailSend)
mailHandler.sendSecretKey(keyID: keyId, key: message, passcode: passcode, callback: mailSend)
}
alreadySent = true
}
......@@ -105,8 +105,9 @@ class ExportViewController: UITableViewController {
} else if indexPath.row == 1 {
let cell = tableView.dequeueReusableCell(withIdentifier: "ExportSendButtonCell") as! ExportSendButtonCell
if alreadySent {
cell.sendButton.setTitle(NSLocalizedString("DeleteCode", comment: "delete (pass-)code, which was used to symmetrically encrypt the secret key"), for: UIControlState.normal) //geht besser...
cell.sendButton.setTitle(NSLocalizedString("DeleteCode", comment: "delete (pass-)code, which was used to symmetrically encrypt the secret key"), for: UIControlState.normal)
cell.sendButton.setTitleColor(UIColor.red, for: .normal)
//TODO: delete code from keychain
} else {
cell.sendButton.setTitle(NSLocalizedString("Send", comment: "send mail with secret key attached"), for: .normal)
......
......@@ -34,7 +34,8 @@ public protocol Mail: Comparable {
}
public func == <T: Mail> (lhs: T, rhs: T) -> Bool {
return lhs.date == rhs.date && lhs.uid == rhs.uid //TODO: update see: https://www.limilabs.com/blog/unique-id-in-imap-protocol
return lhs.date == rhs.date && lhs.uid == rhs.uid
//TODO: update see: https://www.limilabs.com/blog/unique-id-in-imap-protocol
}
public func << T: Mail > (lhs: T, rhs: T) -> Bool {
......
......@@ -236,26 +236,52 @@ class MailHandler {
return ids
}
func sendSecretKey(key: String, passcode: String, callback: @escaping (Error?) -> Void) {
func sendSecretKey(keyID: String, key: String, passcode: String, callback: @escaping (Error?) -> Void) {
let useraddr = (UserManager.loadUserValue(Attribute.userAddr) as! String)
let session = createSMTPSession()
let builder = MCOMessageBuilder()
let userID: MCOAddress = MCOAddress(displayName: useraddr, mailbox: useraddr)
createHeader(builder, toEntrys: [useraddr], ccEntrys: [], bccEntrys: [], subject: "Autocrypt Setup Message")
builder.header.setExtraHeaderValue("v0", forName: SETUPMESSAGE)
builder.header.setExtraHeaderValue("v1", forName: SETUPMESSAGE)
builder.addAttachment(MCOAttachment.init(text: "This message contains a secret for reading secure mails on other devices. \n 1) Input the passcode from your smartphone to unlock the message on your other device. \n 2) Import the secret key into your pgp program on the device. \n\n For more information visit:https://userpage.fu-berlin.de/letterbox/faq.html#otherDevices \n\n"))
// See: https://autocrypt.org/level1.html#autocrypt-setup-message
let keyAttachment = MCOAttachment.init(text: key)
let filename = keyID+".asc.asc"
if let keyAttachment = MCOAttachment.init(contentsOfFile: filename){
keyAttachment.mimeType = "application/autocrypt-setup"
keyAttachment.setContentTypeParameterValue("UTF-8", forName: "charset")
keyAttachment.setContentTypeParameterValue(filename, forName: "name")
keyAttachment.filename = filename
keyAttachment.data = key.data(using: .utf8)
builder.addAttachment(keyAttachment)
}
/*
if let keyAttachment = MCOAttachment.init(contentsOfFile: filename){
keyAttachment.mimeType = "text/plain"
keyAttachment.setContentTypeParameterValue("UTF-8", forName: "charset")
keyAttachment.setContentTypeParameterValue(filename, forName: "name")
keyAttachment.data = key.data(using: .utf8)
keyAttachment.filename = filename
builder.addAttachment(keyAttachment)
}
*/
if let keyAttachment = MCOAttachment.init(text: key){
builder.addAttachment(keyAttachment)
}
let sendOperation = session.sendOperation(with: builder.data(), from: userID, recipients: [userID])
sendOperation?.start({ error in
guard error == nil else {
self.errorhandling(error: error, originalCall: {self.sendSecretKey(key: key, passcode: passcode, callback: callback)}, completionCallback: nil)
self.errorhandling(error: error, originalCall: {self.sendSecretKey(keyID: keyID, key: key, passcode: passcode, callback: callback)}, completionCallback: nil)
return
}
callback(nil)
......
......@@ -566,7 +566,7 @@ class ReadViewController: UITableViewController {
let answerTo = sender as? String ?? "" // TODO: Convert String into MailAddress(?)
let answerMail = EphemeralMail(to: NSSet.init(array: [answerTo]), cc: NSSet.init(array: []), bcc: [], date: Date(), subject: "", body: "", uid: 0, predecessor: nil) // TODO: are these the best values?
let answerMail = EphemeralMail(to: NSSet.init(array: [answerTo]), cc: NSSet.init(array: []), bcc: [], date: Date(), subject: "", body: "", uid: 0, predecessor: nil)
controller.sendViewDelegate = self
controller.prefilledMail = answerMail
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment