Skip to content

Commit

Permalink
#1254 add pwd param to composeEmail
Browse files Browse the repository at this point in the history
  • Loading branch information
sosnovsky committed Jan 3, 2022
1 parent e9ad15f commit c7a2515
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Core/source/mobile-interface/endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export class Endpoints {
encryptedAtts.push(new Att({ name: `${att.name}.pgp`, type: 'application/pgp-encrypted', data: encryptedAtt.message.packets.write() }))
}
const signingPrv = await getSigningPrv(req);
const encrypted = await PgpMsg.encrypt({ pubkeys: req.pubKeys, signingPrv, data: Buf.fromUtfStr(req.text), armor: true }) as OpenPGP.EncryptArmorResult;
const encrypted = await PgpMsg.encrypt({ pubkeys: req.pubKeys, signingPrv, pwd: req.pwd, data: Buf.fromUtfStr(req.text), armor: true }) as OpenPGP.EncryptArmorResult;
return fmtRes({}, Buf.fromUtfStr(await Mime.encode({ 'text/plain': encrypted.data }, mimeHeaders, encryptedAtts)));
} else {
throw new Error(`Unknown format: ${req.format}`);
Expand Down
4 changes: 2 additions & 2 deletions Core/source/mobile-interface/validate-input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export namespace NodeRequest {
type Attachment = { name: string; type: string; base64: string };
interface composeEmailBase { text: string, to: string[], cc: string[], bcc: string[], from: string, subject: string, replyToMimeMsg: string, atts?: Attachment[] };
export interface composeEmailPlain extends composeEmailBase { format: 'plain' };
export interface composeEmailEncrypted extends composeEmailBase { format: 'encrypt-inline' | 'encrypt-pgpmime', pubKeys: string[], signingPrv: PrvKeyInfo | undefined };
export interface composeEmailEncrypted extends composeEmailBase { format: 'encrypt-inline' | 'encrypt-pgpmime', pubKeys: string[], signingPrv: PrvKeyInfo | undefined, pwd?: string };

export type generateKey = { passphrase: string, variant: 'rsa2048' | 'rsa4096' | 'curve25519', userIds: { name: string, email: string }[] };
export type composeEmail = composeEmailPlain | composeEmailEncrypted;
Expand Down Expand Up @@ -50,7 +50,7 @@ export class ValidateInput {
if (!hasProp(v, 'atts', 'Attachment[]?')) {
throw new Error('Wrong atts structure for NodeRequest.composeEmail, need: {name, type, base64}');
}
if (hasProp(v, 'pubKeys', 'string[]') && hasProp(v, 'signingPrv', 'PrvKeyInfo?') && v.pubKeys.length && (v.format === 'encrypt-inline' || v.format === 'encrypt-pgpmime')) {
if ((hasProp(v, 'pwd', 'string' || (hasProp(v, 'pubKeys', 'string[]') && hasProp(v, 'signingPrv', 'PrvKeyInfo?')) && v.pubKeys.length)) && (v.format === 'encrypt-inline' || v.format === 'encrypt-pgpmime')) {
return v as NodeRequest.composeEmailEncrypted;
}
if (!v.pubKeys && v.format === 'plain') {
Expand Down
16 changes: 8 additions & 8 deletions FlowCrypt.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
21C7DF09266C0D8F00C44800 /* EnterpriseServerApi.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21C7DF08266C0D8F00C44800 /* EnterpriseServerApi.swift */; };
21CE25E62650070300ADFF4B /* WkdUrlConstructor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21CE25E52650070300ADFF4B /* WkdUrlConstructor.swift */; };
21EA3B592656611D00691848 /* ClientConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21EA3B15265647C400691848 /* ClientConfiguration.swift */; };
21F836B62652A26B00B2448C /* DataExntensions+ZBase32Encoding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21F836B52652A26B00B2448C /* DataExntensions+ZBase32Encoding.swift */; };
21F836B62652A26B00B2448C /* DataExtensions+ZBase32Encoding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21F836B52652A26B00B2448C /* DataExtensions+ZBase32Encoding.swift */; };
2C03CC16275BB53400887EEB /* EnterpriseServerApiTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2C03CC15275BB53400887EEB /* EnterpriseServerApiTests.swift */; };
2C08F6BE273FA7B900EE1610 /* Version5SchemaMigration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2C08F6BD273FA7B900EE1610 /* Version5SchemaMigration.swift */; };
2C124DB42728809100A2EFA6 /* ApiCall.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2C124DB32728809100A2EFA6 /* ApiCall.swift */; };
Expand Down Expand Up @@ -341,7 +341,7 @@
D2CDC3CD2402CCD7002B045F /* UIImageExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9F8277952373732000E19C07 /* UIImageExtensions.swift */; };
D2CDC3CE2402CDB4002B045F /* DispatchTimeExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 32DCABF1508B0C08DEDE2059 /* DispatchTimeExtensions.swift */; };
D2CDC3D32402D4FE002B045F /* DataExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 32DCAEFF16F5D91A35791730 /* DataExtensions.swift */; };
D2CDC3D42402D50A002B045F /* CodableExntensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 32DCA38E87F2B7196E0E1F1F /* CodableExntensions.swift */; };
D2CDC3D42402D50A002B045F /* CodableExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 32DCA38E87F2B7196E0E1F1F /* CodableExtensions.swift */; };
D2CDC3D72404704D002B045F /* RecipientEmailsCellNode.swift in Sources */ = {isa = PBXBuildFile; fileRef = D24ABA6223FDB4FF002EE9DD /* RecipientEmailsCellNode.swift */; };
D2CDC3D824047066002B045F /* RecipientEmailNode.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2531F3523FFEDA2007E5198 /* RecipientEmailNode.swift */; };
D2CDC3DD24052D50002B045F /* FlowCryptUI.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D204DB9E23FB35700083B9D6 /* FlowCryptUI.framework */; };
Expand Down Expand Up @@ -444,7 +444,7 @@
21EA3B2E26565B7400691848 /* client_configuraion.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = client_configuraion.json; sourceTree = "<group>"; };
21EA3B3526565B8100691848 /* client_configuraion_empty.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = client_configuraion_empty.json; sourceTree = "<group>"; };
21EA3B3C26565B9800691848 /* client_configuraion_partly_empty.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = client_configuraion_partly_empty.json; sourceTree = "<group>"; };
21F836B52652A26B00B2448C /* DataExntensions+ZBase32Encoding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "DataExntensions+ZBase32Encoding.swift"; sourceTree = "<group>"; };
21F836B52652A26B00B2448C /* DataExtensions+ZBase32Encoding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "DataExtensions+ZBase32Encoding.swift"; sourceTree = "<group>"; };
21F836CB2652A38700B2448C /* ZBase32EncodingTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ZBase32EncodingTests.swift; sourceTree = "<group>"; };
21F836D22652A46E00B2448C /* WKDURLsConstructorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WKDURLsConstructorTests.swift; sourceTree = "<group>"; };
2C03CC15275BB53400887EEB /* EnterpriseServerApiTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EnterpriseServerApiTests.swift; sourceTree = "<group>"; };
Expand All @@ -466,7 +466,7 @@
32DCA0C3D34A69851A238E87 /* Core.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Core.swift; sourceTree = "<group>"; };
32DCA0E63F2F0473D0A8EDB0 /* StringExtensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StringExtensions.swift; sourceTree = "<group>"; };
32DCA377D22F4D67A8FA05EB /* Imap.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Imap.swift; sourceTree = "<group>"; };
32DCA38E87F2B7196E0E1F1F /* CodableExntensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CodableExntensions.swift; sourceTree = "<group>"; };
32DCA38E87F2B7196E0E1F1F /* CodableExtensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CodableExtensions.swift; sourceTree = "<group>"; };
32DCA4B11D4531B3B04D01D1 /* AppErr.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppErr.swift; sourceTree = "<group>"; };
32DCA55C094E9745AA1FD210 /* Imap+msg.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Imap+msg.swift"; sourceTree = "<group>"; };
32DCA63656CB3323C26BC084 /* UIVIewExtensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UIVIewExtensions.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -949,7 +949,7 @@
isa = PBXGroup;
children = (
32DCAEFF16F5D91A35791730 /* DataExtensions.swift */,
21F836B52652A26B00B2448C /* DataExntensions+ZBase32Encoding.swift */,
21F836B52652A26B00B2448C /* DataExtensions+ZBase32Encoding.swift */,
);
path = Data;
sourceTree = "<group>";
Expand Down Expand Up @@ -1871,7 +1871,7 @@
D2D27B78248A8694007346FA /* BigIntExtensions.swift */,
E26D5E20275AA417007B8802 /* BundleExtensions.swift */,
21C7DEFB26669A3700C44800 /* CalendarExtensions.swift */,
32DCA38E87F2B7196E0E1F1F /* CodableExntensions.swift */,
32DCA38E87F2B7196E0E1F1F /* CodableExtensions.swift */,
D2531F452402C62D007E5198 /* CollectionExtensions.swift */,
E26D5E1E275AA295007B8802 /* CommandLineExtensions.swift */,
9F0C3C2723194E8500299985 /* CommonExtensions.swift */,
Expand Down Expand Up @@ -2833,7 +2833,7 @@
9F67998D277B3E4D00AFE5BE /* CommandLineExtensions.swift in Sources */,
9F67998C277B3E4000AFE5BE /* BundleExtensions.swift in Sources */,
D2CDC3CD2402CCD7002B045F /* UIImageExtensions.swift in Sources */,
21F836B62652A26B00B2448C /* DataExntensions+ZBase32Encoding.swift in Sources */,
21F836B62652A26B00B2448C /* DataExtensions+ZBase32Encoding.swift in Sources */,
D29AFFF6240939AE00C1387D /* Then.swift in Sources */,
9FBD69EE27775086002FC602 /* ErrorExtensions.swift in Sources */,
9F6F5F6C26A2F66B00C625C7 /* Logger.swift in Sources */,
Expand All @@ -2849,7 +2849,7 @@
21C7DEFE26669CE100C44800 /* DateFormattingExtensions.swift in Sources */,
9F8076D927762515008E5874 /* BigIntExtensions.swift in Sources */,
9FBD69EC27775086002FC602 /* UIApplicationExtensions.swift in Sources */,
D2CDC3D42402D50A002B045F /* CodableExntensions.swift in Sources */,
D2CDC3D42402D50A002B045F /* CodableExtensions.swift in Sources */,
D2531F3D24000E37007E5198 /* UIVIewExtensions.swift in Sources */,
D2531F3723FFF043007E5198 /* CommonExtensions.swift in Sources */,
D2CDC3D32402D4FE002B045F /* DataExtensions.swift in Sources */,
Expand Down
2 changes: 1 addition & 1 deletion FlowCrypt/Core/CoreTypes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ struct UserId: Encodable {
}

struct SendableMsg: Equatable {
struct Attachment: Equatable {
struct Attachment: Equatable, Encodable {
let name: String
let type: String
let base64: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,10 @@ class EnterpriseServerApi: EnterpriseServerApiType {
throw EnterpriseServerApiError.noActiveFesUrl
}

var headers = headers
if withAuthorization {
let idToken = try await getIdToken(email: email)
let authorizationHeader = URLHeader(value: "Bearer \(idToken)", httpHeaderField: "Authorization")
var headers = headers
headers.append(authorizationHeader)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,15 @@ public extension Encodable {
}

func toJsonEncodedDict() throws -> [String: Any] {
let data = try JSONEncoder().encode(self)
let data = try self.toJsonData()
guard let dictionary = try JSONSerialization.jsonObject(with: data, options: .allowFragments) as? [String: Any] else {
throw NSError()
}
return dictionary
}

func toJsonString() throws -> String? {
let data = try self.toJsonData()
return String(data: data, encoding: .utf8)
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// DataExntensions+Encoding.swift
// DataExtensions+Encoding.swift
// FlowCryptCommon
//
// Created by Yevhen Kyivskyi on 17.05.2021.
Expand Down

0 comments on commit c7a2515

Please sign in to comment.