signalapp / libsignal

Home to the Signal Protocol as well as other cryptographic primitives which make Signal possible.
GNU Affero General Public License v3.0
3.52k stars 410 forks source link

Documentation error codes #507

Closed Invariant0x closed 1 year ago

Invariant0x commented 1 year ago

Where I can find code errors? I sometimes get LibSignalClient.SignalError, error 22 In group decrypt What is it mean? Please help

jrose-signal commented 1 year ago

There should be no numeric error codes visible in libsignal's Swift interface. How are you using this code and where are you seeing the error?

Invariant0x commented 1 year ago

here is an example of my code Moreover, I often get error 18, but it is not in the Signal description

private func initProtocolStore() throws {
    print("initProtocolStore", "remoteAddress", remoteAddress?.name)
    guard let remoteAddress else { return }
    print("initProtocolStore", "remoteAddress", remoteAddress.name)

    print("initProtocolStore", "senderSKDM", senderSkdm)
//    let skdm_r = try SenderKeyDistributionMessage(from: remoteAddress,
//                                                  distributionId: groupId,
//                                                  store: store,
//                                                  context: NullContext())

    guard let dataSkdm = Data(base64Encoded: senderSkdm) else { return }
    let skdm_r = try SenderKeyDistributionMessage(bytes: [UInt8](dataSkdm))

    print("initProtocolStore", "skdm_r", skdm_r)
    try processSenderKeyDistributionMessage(
      skdm_r,
      from: remoteAddress,
      store: store,
      context: NullContext()
    )
    print("initProtocolStore", "processSenderKeyDistributionMessage", "Ok")
  }

  func encrypt(message : String) throws -> Data? {
    let buf = [UInt8](message.utf8)

    let cipherTextMessage =  try groupEncrypt(
      buf,
      from: localAddress,
      distributionId: groupId,
      store: store,
      context: NullContext()
    )

    print("encryped type message = \(cipherTextMessage.messageType)")

    return Data(cipherTextMessage.serialize())
  }

  /// Расшифровка сообщений в группе
  func decrypt(message : Data) throws -> String? {
    guard let remoteAddress else { return nil }
    print("decrypt", "remoteAddress", remoteAddress)
    try self.initProtocolStore()

    print("decrypt", "initProtocolStore")
    let b_ptext = try groupDecrypt(
      message,
      from: remoteAddress,
      store: store,
      context: NullContext()
    )
    print("decrypt", "b_ptext", b_ptext)

    return String(bytes: b_ptext, encoding: String.Encoding.utf8)
  }
jrose-signal commented 1 year ago

Hm, this code seems reasonable at first glance. Where are you seeing the number, though? Is it just print(error) in a catch block? None of the errors should have numbers printed.

Invariant0x commented 1 year ago
let b_ptext = try groupDecrypt(
     message,
     from: remoteAddress,
     store: store,
     context: NullContext()
   )

Error 18 In this function

Maybe Can I use this function try processSenderKeyDistributionMessage only once? Now I call it in decrypt function every time Is it correct?

jrose-signal commented 1 year ago

The distribution message should be sent over a separate encrypted channel and processed once, yes, but I wouldn't expect an error for processing it repeatedly…though perhaps the error you're seeing is "duplicatedMessage", which you can get if the sender side isn't preserving their session state across multiple messages.

Where are the error numbers printed? None of these errors have numbers.